2022-08-19 15:59:36 +02:00
|
|
|
// Copyright (C) 2016 The Qt Company Ltd.
|
2022-12-21 10:12:09 +01:00
|
|
|
// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only WITH Qt-GPL-exception-1.0
|
2009-01-13 17:03:14 +01:00
|
|
|
|
2009-01-12 14:41:24 +01:00
|
|
|
#include "icore.h"
|
2018-02-01 17:44:27 +01:00
|
|
|
|
2022-07-05 13:56:04 +02:00
|
|
|
#include "coreplugintr.h"
|
2018-02-01 17:44:27 +01:00
|
|
|
#include "dialogs/settingsdialog.h"
|
2022-07-05 13:56:04 +02:00
|
|
|
#include "windowsupport.h"
|
2009-01-12 14:41:24 +01:00
|
|
|
|
2012-08-17 09:09:15 +02:00
|
|
|
#include <extensionsystem/pluginmanager.h>
|
|
|
|
|
|
2021-11-09 18:58:15 +02:00
|
|
|
#include <utils/algorithm.h>
|
2023-06-21 15:12:46 +02:00
|
|
|
#include <utils/appinfo.h>
|
2022-08-24 14:55:41 +02:00
|
|
|
#include <utils/environment.h>
|
2022-07-22 13:07:53 +02:00
|
|
|
#include <utils/fileutils.h>
|
2022-08-24 14:55:41 +02:00
|
|
|
#include <utils/qtcassert.h>
|
2015-05-29 13:24:02 +02:00
|
|
|
|
2014-11-20 16:00:06 +01:00
|
|
|
#include <QApplication>
|
2019-03-13 14:38:07 +01:00
|
|
|
#include <QDebug>
|
2022-08-30 13:29:36 +02:00
|
|
|
#include <QLibraryInfo>
|
2019-02-20 17:26:36 +01:00
|
|
|
#include <QStandardPaths>
|
2019-03-13 14:38:07 +01:00
|
|
|
#include <QSysInfo>
|
2013-05-24 16:45:49 +02:00
|
|
|
|
2009-01-12 14:41:24 +01:00
|
|
|
/*!
|
|
|
|
|
\namespace Core
|
2020-03-18 13:32:02 +01:00
|
|
|
\inmodule QtCreator
|
2009-01-12 14:41:24 +01:00
|
|
|
\brief The Core namespace contains all classes that make up the Core plugin
|
2013-09-06 16:38:53 +02:00
|
|
|
which constitute the basic functionality of \QC.
|
2009-01-12 14:41:24 +01:00
|
|
|
*/
|
|
|
|
|
|
2020-02-13 16:14:56 +01:00
|
|
|
/*!
|
2023-05-22 13:56:37 +02:00
|
|
|
\enum Utils::FindFlag
|
2020-02-13 16:14:56 +01:00
|
|
|
This enum holds the find flags.
|
|
|
|
|
|
|
|
|
|
\value FindBackward
|
|
|
|
|
Searches backwards.
|
|
|
|
|
\value FindCaseSensitively
|
|
|
|
|
Considers case when searching.
|
|
|
|
|
\value FindWholeWords
|
|
|
|
|
Finds only whole words.
|
|
|
|
|
\value FindRegularExpression
|
|
|
|
|
Uses a regular epression as a search term.
|
|
|
|
|
\value FindPreserveCase
|
|
|
|
|
Preserves the case when replacing search terms.
|
|
|
|
|
*/
|
|
|
|
|
|
2020-05-28 16:26:01 +02:00
|
|
|
/*!
|
|
|
|
|
\enum Core::ICore::ContextPriority
|
|
|
|
|
|
|
|
|
|
This enum defines the priority of additional contexts.
|
|
|
|
|
|
|
|
|
|
\value High
|
|
|
|
|
Additional contexts that have higher priority than contexts from
|
|
|
|
|
Core::IContext instances.
|
|
|
|
|
\value Low
|
|
|
|
|
Additional contexts that have lower priority than contexts from
|
|
|
|
|
Core::IContext instances.
|
|
|
|
|
|
|
|
|
|
\sa Core::ICore::updateAdditionalContexts()
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
/*!
|
|
|
|
|
\enum Core::SaveSettingsReason
|
|
|
|
|
\internal
|
|
|
|
|
*/
|
|
|
|
|
|
2009-01-12 14:41:24 +01:00
|
|
|
/*!
|
|
|
|
|
\namespace Core::Internal
|
|
|
|
|
\internal
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
/*!
|
|
|
|
|
\class Core::ICore
|
2020-06-12 16:04:30 +02:00
|
|
|
\inheaderfile coreplugin/icore.h
|
2020-02-13 16:14:56 +01:00
|
|
|
\inmodule QtCreator
|
2020-03-18 13:32:02 +01:00
|
|
|
\ingroup mainclasses
|
2020-06-12 16:04:30 +02:00
|
|
|
|
2013-06-05 14:29:24 +02:00
|
|
|
\brief The ICore class allows access to the different parts that make up
|
|
|
|
|
the basic functionality of \QC.
|
2009-01-12 14:41:24 +01:00
|
|
|
|
|
|
|
|
You should never create a subclass of this interface. The one and only
|
|
|
|
|
instance is created by the Core plugin. You can access this instance
|
2020-03-18 13:32:02 +01:00
|
|
|
from your plugin through instance().
|
2009-01-12 14:41:24 +01:00
|
|
|
*/
|
|
|
|
|
|
2020-05-28 16:26:01 +02:00
|
|
|
/*!
|
|
|
|
|
\fn void Core::ICore::coreAboutToOpen()
|
|
|
|
|
|
|
|
|
|
Indicates that all plugins have been loaded and the main window is about to
|
|
|
|
|
be shown.
|
|
|
|
|
*/
|
|
|
|
|
|
2009-01-12 14:41:24 +01:00
|
|
|
/*!
|
2020-03-18 13:32:02 +01:00
|
|
|
\fn void Core::ICore::coreOpened()
|
2013-09-06 16:38:53 +02:00
|
|
|
Indicates that all plugins have been loaded and the main window is shown.
|
2009-01-12 14:41:24 +01:00
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
/*!
|
2020-03-18 13:32:02 +01:00
|
|
|
\fn void Core::ICore::saveSettingsRequested(Core::ICore::SaveSettingsReason reason)
|
2013-09-06 16:38:53 +02:00
|
|
|
Signals that the user has requested that the global settings
|
2020-03-18 13:32:02 +01:00
|
|
|
should be saved to disk for a \a reason.
|
2009-01-12 14:41:24 +01:00
|
|
|
|
2020-02-13 16:14:56 +01:00
|
|
|
At the moment that happens when the application is closed, and on \uicontrol{Save All}.
|
2009-01-12 14:41:24 +01:00
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
/*!
|
2020-03-18 13:32:02 +01:00
|
|
|
\fn void Core::ICore::coreAboutToClose()
|
2013-09-06 16:38:53 +02:00
|
|
|
Enables plugins to perform some pre-end-of-life actions.
|
2009-01-12 14:41:24 +01:00
|
|
|
|
|
|
|
|
The application is guaranteed to shut down after this signal is emitted.
|
2013-10-07 13:34:40 +02:00
|
|
|
It is there as an addition to the usual plugin lifecycle functions, namely
|
2013-09-06 16:38:53 +02:00
|
|
|
\c IPlugin::aboutToShutdown(), just for convenience.
|
2009-01-12 14:41:24 +01:00
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
/*!
|
2020-03-18 13:32:02 +01:00
|
|
|
\fn void Core::ICore::contextAboutToChange(const QList<Core::IContext *> &context)
|
2013-09-06 16:38:53 +02:00
|
|
|
Indicates that a new \a context will shortly become the current context
|
|
|
|
|
(meaning that its widget got focus).
|
2009-01-12 14:41:24 +01:00
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
/*!
|
2020-03-18 13:32:02 +01:00
|
|
|
\fn void Core::ICore::contextChanged(const Core::Context &context)
|
2015-09-22 09:17:59 +02:00
|
|
|
Indicates that a new \a context just became the current context. This includes the context
|
|
|
|
|
from the focus object as well as the additional context.
|
2009-01-12 14:41:24 +01:00
|
|
|
*/
|
2012-01-18 23:25:34 +01:00
|
|
|
|
2021-08-26 20:02:55 +03:00
|
|
|
#include "dialogs/newdialogwidget.h"
|
2015-05-29 13:24:02 +02:00
|
|
|
#include "dialogs/newdialog.h"
|
2015-05-29 15:55:49 +02:00
|
|
|
#include "iwizardfactory.h"
|
2012-01-18 23:25:34 +01:00
|
|
|
#include "mainwindow.h"
|
2012-02-14 16:43:51 +01:00
|
|
|
#include "documentmanager.h"
|
2012-01-18 23:25:34 +01:00
|
|
|
|
2013-03-14 10:44:46 +01:00
|
|
|
#include <utils/hostosinfo.h>
|
|
|
|
|
|
2012-02-15 10:42:41 +01:00
|
|
|
#include <QCoreApplication>
|
|
|
|
|
#include <QDebug>
|
2013-09-20 23:17:22 +02:00
|
|
|
#include <QDir>
|
2018-01-29 11:46:23 +01:00
|
|
|
#include <QMessageBox>
|
|
|
|
|
#include <QPushButton>
|
2012-02-15 10:42:41 +01:00
|
|
|
#include <QStatusBar>
|
2012-01-18 23:25:34 +01:00
|
|
|
|
2013-09-20 23:17:22 +02:00
|
|
|
using namespace Core::Internal;
|
2014-03-04 16:07:44 +01:00
|
|
|
using namespace ExtensionSystem;
|
2020-06-26 13:59:38 +02:00
|
|
|
using namespace Utils;
|
2013-09-20 23:17:22 +02:00
|
|
|
|
2012-01-18 23:25:34 +01:00
|
|
|
namespace Core {
|
|
|
|
|
|
|
|
|
|
// The Core Singleton
|
2016-09-26 15:13:44 +02:00
|
|
|
static ICore *m_instance = nullptr;
|
|
|
|
|
static MainWindow *m_mainwindow = nullptr;
|
2021-11-09 18:58:15 +02:00
|
|
|
|
|
|
|
|
static NewDialog *defaultDialogFactory(QWidget *parent)
|
|
|
|
|
{
|
2021-08-26 20:02:55 +03:00
|
|
|
return new NewDialogWidget(parent);
|
2021-11-09 18:58:15 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static std::function<NewDialog *(QWidget *)> m_newDialogFactory = defaultDialogFactory;
|
2012-01-18 23:25:34 +01:00
|
|
|
|
2020-05-28 16:26:01 +02:00
|
|
|
/*!
|
|
|
|
|
Returns the pointer to the instance. Only use for connecting to signals.
|
|
|
|
|
*/
|
2012-01-18 23:25:34 +01:00
|
|
|
ICore *ICore::instance()
|
|
|
|
|
{
|
|
|
|
|
return m_instance;
|
|
|
|
|
}
|
|
|
|
|
|
2020-05-28 16:26:01 +02:00
|
|
|
/*!
|
|
|
|
|
Returns whether the new item dialog is currently open.
|
|
|
|
|
*/
|
2014-06-27 15:15:09 +02:00
|
|
|
bool ICore::isNewItemDialogRunning()
|
|
|
|
|
{
|
2016-09-26 16:39:49 +02:00
|
|
|
return NewDialog::currentDialog() || IWizardFactory::isWizardRunning();
|
|
|
|
|
}
|
|
|
|
|
|
2020-05-28 16:26:01 +02:00
|
|
|
/*!
|
|
|
|
|
Returns the currently open new item dialog widget, or \c nullptr if there is none.
|
|
|
|
|
|
|
|
|
|
\sa isNewItemDialogRunning()
|
|
|
|
|
\sa showNewItemDialog()
|
|
|
|
|
*/
|
2016-09-26 16:39:49 +02:00
|
|
|
QWidget *ICore::newItemDialog()
|
|
|
|
|
{
|
|
|
|
|
if (NewDialog::currentDialog())
|
|
|
|
|
return NewDialog::currentDialog();
|
|
|
|
|
return IWizardFactory::currentWizard();
|
2014-06-27 15:15:09 +02:00
|
|
|
}
|
|
|
|
|
|
2020-03-18 13:32:02 +01:00
|
|
|
/*!
|
|
|
|
|
\internal
|
|
|
|
|
*/
|
2012-01-18 23:25:34 +01:00
|
|
|
ICore::ICore(MainWindow *mainwindow)
|
|
|
|
|
{
|
|
|
|
|
m_instance = this;
|
|
|
|
|
m_mainwindow = mainwindow;
|
2023-06-28 15:35:47 +02:00
|
|
|
|
2022-12-07 16:25:11 +01:00
|
|
|
connect(PluginManager::instance(), &PluginManager::testsFinished,
|
|
|
|
|
this, [this](int failedTests) {
|
2015-07-14 10:35:49 +02:00
|
|
|
emit coreAboutToClose();
|
2019-03-13 14:38:07 +01:00
|
|
|
if (failedTests != 0)
|
|
|
|
|
qWarning("Test run was not successful: %d test(s) failed.", failedTests);
|
2015-07-14 10:35:49 +02:00
|
|
|
QCoreApplication::exit(failedTests);
|
|
|
|
|
});
|
2022-12-07 16:25:11 +01:00
|
|
|
connect(PluginManager::instance(), &PluginManager::scenarioFinished,
|
|
|
|
|
this, [this](int exitCode) {
|
2021-04-28 15:59:18 +02:00
|
|
|
emit coreAboutToClose();
|
|
|
|
|
QCoreApplication::exit(exitCode);
|
|
|
|
|
});
|
2021-07-16 15:24:26 +02:00
|
|
|
|
|
|
|
|
FileUtils::setDialogParentGetter(&ICore::dialogParent);
|
2012-01-18 23:25:34 +01:00
|
|
|
}
|
|
|
|
|
|
2020-03-18 13:32:02 +01:00
|
|
|
/*!
|
|
|
|
|
\internal
|
|
|
|
|
*/
|
2012-01-18 23:25:34 +01:00
|
|
|
ICore::~ICore()
|
|
|
|
|
{
|
2018-07-21 21:11:46 +02:00
|
|
|
m_instance = nullptr;
|
|
|
|
|
m_mainwindow = nullptr;
|
2012-01-18 23:25:34 +01:00
|
|
|
}
|
|
|
|
|
|
2020-03-18 13:32:02 +01:00
|
|
|
/*!
|
|
|
|
|
Opens a dialog where the user can choose from a set of \a factories that
|
|
|
|
|
create new files or projects.
|
|
|
|
|
|
|
|
|
|
The \a title argument is shown as the dialog title. The path where the
|
|
|
|
|
files will be created (if the user does not change it) is set
|
|
|
|
|
in \a defaultLocation. Defaults to DocumentManager::projectsDirectory()
|
|
|
|
|
or DocumentManager::fileDialogLastVisitedDirectory(), depending on wizard
|
|
|
|
|
kind.
|
|
|
|
|
|
|
|
|
|
Additional variables for the wizards are set in \a extraVariables.
|
|
|
|
|
|
|
|
|
|
\sa Core::DocumentManager
|
2020-05-28 16:26:01 +02:00
|
|
|
\sa isNewItemDialogRunning()
|
|
|
|
|
\sa newItemDialog()
|
2020-03-18 13:32:02 +01:00
|
|
|
*/
|
2012-01-18 23:25:34 +01:00
|
|
|
void ICore::showNewItemDialog(const QString &title,
|
2014-05-02 17:38:42 +02:00
|
|
|
const QList<IWizardFactory *> &factories,
|
2021-07-26 17:20:03 +02:00
|
|
|
const FilePath &defaultLocation,
|
2012-04-02 14:55:56 +02:00
|
|
|
const QVariantMap &extraVariables)
|
2012-01-18 23:25:34 +01:00
|
|
|
{
|
2015-05-29 14:23:59 +02:00
|
|
|
QTC_ASSERT(!isNewItemDialogRunning(), return);
|
2021-11-09 18:58:15 +02:00
|
|
|
|
|
|
|
|
/* This is a workaround for QDS: In QDS, we currently have a "New Project" dialog box but we do
|
|
|
|
|
* not also have a "New file" dialog box (yet). Therefore, when requested to add a new file, we
|
|
|
|
|
* need to use QtCreator's dialog box. In QDS, if `factories` contains project wizard factories
|
|
|
|
|
* (even though it may contain file wizard factories as well), then we consider it to be a
|
|
|
|
|
* request for "New Project". Otherwise, if we only have file wizard factories, we defer to
|
|
|
|
|
* QtCreator's dialog and request "New File"
|
|
|
|
|
*/
|
|
|
|
|
auto dialogFactory = m_newDialogFactory;
|
|
|
|
|
bool haveProjectWizards = Utils::anyOf(factories, [](IWizardFactory *f) {
|
|
|
|
|
return f->kind() == IWizardFactory::ProjectWizard;
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
if (!haveProjectWizards)
|
|
|
|
|
dialogFactory = defaultDialogFactory;
|
|
|
|
|
|
|
|
|
|
NewDialog *newDialog = dialogFactory(dialogParent());
|
2021-08-26 20:02:55 +03:00
|
|
|
connect(newDialog->widget(), &QObject::destroyed, m_instance, &ICore::updateNewItemDialogState);
|
2015-05-29 13:24:02 +02:00
|
|
|
newDialog->setWizardFactories(factories, defaultLocation, extraVariables);
|
|
|
|
|
newDialog->setWindowTitle(title);
|
|
|
|
|
newDialog->showDialog();
|
|
|
|
|
|
2016-09-26 16:39:49 +02:00
|
|
|
updateNewItemDialogState();
|
2012-01-18 23:25:34 +01:00
|
|
|
}
|
|
|
|
|
|
2020-05-28 16:26:01 +02:00
|
|
|
/*!
|
|
|
|
|
Opens the options dialog on the specified \a page. The dialog's \a parent
|
|
|
|
|
defaults to dialogParent(). If the dialog is already shown when this method
|
|
|
|
|
is called, it is just switched to the specified \a page.
|
|
|
|
|
|
|
|
|
|
Returns whether the user accepted the dialog.
|
|
|
|
|
|
|
|
|
|
\sa msgShowOptionsDialog()
|
|
|
|
|
\sa msgShowOptionsDialogToolTip()
|
|
|
|
|
*/
|
2015-02-23 11:07:38 +01:00
|
|
|
bool ICore::showOptionsDialog(const Id page, QWidget *parent)
|
2012-01-18 23:25:34 +01:00
|
|
|
{
|
2018-02-01 15:20:16 +01:00
|
|
|
return executeSettingsDialog(parent ? parent : dialogParent(), page);
|
2012-01-18 23:25:34 +01:00
|
|
|
}
|
|
|
|
|
|
2020-05-28 16:26:01 +02:00
|
|
|
/*!
|
|
|
|
|
Returns the text to use on buttons that open the options dialog.
|
|
|
|
|
|
|
|
|
|
\sa showOptionsDialog()
|
|
|
|
|
\sa msgShowOptionsDialogToolTip()
|
|
|
|
|
*/
|
2014-02-20 14:52:10 +01:00
|
|
|
QString ICore::msgShowOptionsDialog()
|
|
|
|
|
{
|
2022-07-05 13:56:04 +02:00
|
|
|
return Tr::tr("Configure...", "msgShowOptionsDialog");
|
2014-02-20 14:52:10 +01:00
|
|
|
}
|
|
|
|
|
|
2020-05-28 16:26:01 +02:00
|
|
|
/*!
|
|
|
|
|
Returns the tool tip to use on buttons that open the options dialog.
|
|
|
|
|
|
|
|
|
|
\sa showOptionsDialog()
|
|
|
|
|
\sa msgShowOptionsDialog()
|
|
|
|
|
*/
|
2014-06-23 10:39:01 +02:00
|
|
|
QString ICore::msgShowOptionsDialogToolTip()
|
|
|
|
|
{
|
|
|
|
|
if (Utils::HostOsInfo::isMacHost())
|
2022-07-05 13:56:04 +02:00
|
|
|
return Tr::tr("Open Preferences dialog.", "msgShowOptionsDialogToolTip (mac version)");
|
2014-06-23 10:39:01 +02:00
|
|
|
else
|
2022-07-05 13:56:04 +02:00
|
|
|
return Tr::tr("Open Options dialog.", "msgShowOptionsDialogToolTip (non-mac version)");
|
2014-06-23 10:39:01 +02:00
|
|
|
}
|
|
|
|
|
|
2020-03-18 13:32:02 +01:00
|
|
|
/*!
|
2020-05-28 16:26:01 +02:00
|
|
|
Creates a message box with \a parent that contains a \uicontrol Configure
|
2020-03-18 13:32:02 +01:00
|
|
|
button for opening the settings page specified by \a settingsId.
|
|
|
|
|
|
|
|
|
|
The dialog has \a title and displays the message \a text and detailed
|
|
|
|
|
information specified by \a details.
|
|
|
|
|
|
|
|
|
|
Use this function to display configuration errors and to point users to the
|
|
|
|
|
setting they should fix.
|
|
|
|
|
|
|
|
|
|
Returns \c true if the user accepted the settings dialog.
|
2020-05-28 16:26:01 +02:00
|
|
|
|
|
|
|
|
\sa showOptionsDialog()
|
2020-03-18 13:32:02 +01:00
|
|
|
*/
|
2012-01-18 23:25:34 +01:00
|
|
|
bool ICore::showWarningWithOptions(const QString &title, const QString &text,
|
2015-02-23 11:07:38 +01:00
|
|
|
const QString &details, Id settingsId, QWidget *parent)
|
2012-01-18 23:25:34 +01:00
|
|
|
{
|
2018-01-29 11:46:23 +01:00
|
|
|
if (!parent)
|
|
|
|
|
parent = m_mainwindow;
|
|
|
|
|
QMessageBox msgBox(QMessageBox::Warning, title, text,
|
|
|
|
|
QMessageBox::Ok, parent);
|
2022-07-11 12:42:45 +03:00
|
|
|
msgBox.setEscapeButton(QMessageBox::Ok);
|
2018-01-29 11:46:23 +01:00
|
|
|
if (!details.isEmpty())
|
|
|
|
|
msgBox.setDetailedText(details);
|
|
|
|
|
QAbstractButton *settingsButton = nullptr;
|
|
|
|
|
if (settingsId.isValid())
|
2020-05-28 16:26:01 +02:00
|
|
|
settingsButton = msgBox.addButton(msgShowOptionsDialog(), QMessageBox::AcceptRole);
|
2018-01-29 11:46:23 +01:00
|
|
|
msgBox.exec();
|
|
|
|
|
if (settingsButton && msgBox.clickedButton() == settingsButton)
|
|
|
|
|
return showOptionsDialog(settingsId);
|
|
|
|
|
return false;
|
2012-01-18 23:25:34 +01:00
|
|
|
}
|
|
|
|
|
|
2020-03-18 13:32:02 +01:00
|
|
|
/*!
|
|
|
|
|
Returns the application's main settings object.
|
|
|
|
|
|
|
|
|
|
You can use it to retrieve or set application-wide settings
|
|
|
|
|
(in contrast to session or project specific settings).
|
|
|
|
|
|
|
|
|
|
If \a scope is \c QSettings::UserScope (the default), the
|
|
|
|
|
settings will be read from the user's settings, with
|
|
|
|
|
a fallback to global settings provided with \QC.
|
|
|
|
|
|
2020-05-28 16:26:01 +02:00
|
|
|
If \a scope is \c QSettings::SystemScope, only the installation settings
|
2020-03-18 13:32:02 +01:00
|
|
|
shipped with the current version of \QC will be read. This
|
|
|
|
|
functionality exists for internal purposes only.
|
|
|
|
|
|
2020-05-28 16:26:01 +02:00
|
|
|
\sa settingsDatabase()
|
2020-03-18 13:32:02 +01:00
|
|
|
*/
|
2020-11-19 15:34:59 +01:00
|
|
|
QtcSettings *ICore::settings(QSettings::Scope scope)
|
2012-01-18 23:25:34 +01:00
|
|
|
{
|
2014-03-04 16:07:44 +01:00
|
|
|
if (scope == QSettings::UserScope)
|
|
|
|
|
return PluginManager::settings();
|
|
|
|
|
else
|
|
|
|
|
return PluginManager::globalSettings();
|
2012-01-18 23:25:34 +01:00
|
|
|
}
|
|
|
|
|
|
2020-03-18 13:32:02 +01:00
|
|
|
/*!
|
|
|
|
|
Returns the application's printer object.
|
|
|
|
|
|
|
|
|
|
Always use this printer object for printing, so the different parts of the
|
|
|
|
|
application re-use its settings.
|
|
|
|
|
*/
|
2012-01-18 23:25:34 +01:00
|
|
|
QPrinter *ICore::printer()
|
|
|
|
|
{
|
|
|
|
|
return m_mainwindow->printer();
|
|
|
|
|
}
|
|
|
|
|
|
2020-05-28 16:26:01 +02:00
|
|
|
/*!
|
|
|
|
|
Returns the locale string for the user interface language that is currently
|
|
|
|
|
configured in \QC. Use this to install your plugin's translation file with
|
|
|
|
|
QTranslator.
|
|
|
|
|
*/
|
2012-01-18 23:25:34 +01:00
|
|
|
QString ICore::userInterfaceLanguage()
|
|
|
|
|
{
|
|
|
|
|
return qApp->property("qtc_locale").toString();
|
|
|
|
|
}
|
|
|
|
|
|
2021-04-26 15:46:09 +02:00
|
|
|
static QString pathHelper(const QString &rel)
|
|
|
|
|
{
|
|
|
|
|
if (rel.isEmpty())
|
|
|
|
|
return rel;
|
|
|
|
|
if (rel.startsWith('/'))
|
|
|
|
|
return rel;
|
|
|
|
|
return '/' + rel;
|
|
|
|
|
}
|
2020-03-18 13:32:02 +01:00
|
|
|
/*!
|
2021-11-25 16:11:53 +01:00
|
|
|
Returns the absolute path for the relative path \a rel that is used for resources like
|
2020-03-18 13:32:02 +01:00
|
|
|
project templates and the debugger macros.
|
|
|
|
|
|
|
|
|
|
This abstraction is needed to avoid platform-specific code all over
|
|
|
|
|
the place, since on \macos, for example, the resources are part of the
|
|
|
|
|
application bundle.
|
2020-05-28 16:26:01 +02:00
|
|
|
|
|
|
|
|
\sa userResourcePath()
|
2020-03-18 13:32:02 +01:00
|
|
|
*/
|
2021-04-26 15:46:09 +02:00
|
|
|
FilePath ICore::resourcePath(const QString &rel)
|
2012-01-18 23:25:34 +01:00
|
|
|
{
|
2021-04-22 16:15:26 +02:00
|
|
|
return FilePath::fromString(
|
2021-05-26 10:12:58 +02:00
|
|
|
QDir::cleanPath(QCoreApplication::applicationDirPath() + '/' + RELATIVE_DATA_PATH))
|
|
|
|
|
/ rel;
|
2012-01-18 23:25:34 +01:00
|
|
|
}
|
|
|
|
|
|
2020-03-18 13:32:02 +01:00
|
|
|
/*!
|
2021-11-25 16:11:53 +01:00
|
|
|
Returns the absolute path for the relative path \a rel in the users directory that is used for
|
2020-03-18 13:32:02 +01:00
|
|
|
resources like project templates.
|
|
|
|
|
|
|
|
|
|
Use this function for finding the place for resources that the user may
|
|
|
|
|
write to, for example, to allow for custom palettes or templates.
|
2020-05-28 16:26:01 +02:00
|
|
|
|
|
|
|
|
\sa resourcePath()
|
2020-03-18 13:32:02 +01:00
|
|
|
*/
|
|
|
|
|
|
2021-04-26 15:46:09 +02:00
|
|
|
FilePath ICore::userResourcePath(const QString &rel)
|
2012-01-18 23:25:34 +01:00
|
|
|
{
|
|
|
|
|
// Create qtcreator dir if it doesn't yet exist
|
|
|
|
|
const QString configDir = QFileInfo(settings(QSettings::UserScope)->fileName()).path();
|
2023-06-21 15:12:46 +02:00
|
|
|
const QString urp = configDir + '/' + appInfo().id;
|
2012-01-18 23:25:34 +01:00
|
|
|
|
2014-10-24 10:28:28 +02:00
|
|
|
if (!QFileInfo::exists(urp + QLatin1Char('/'))) {
|
2012-01-18 23:25:34 +01:00
|
|
|
QDir dir;
|
|
|
|
|
if (!dir.mkpath(urp))
|
|
|
|
|
qWarning() << "could not create" << urp;
|
|
|
|
|
}
|
|
|
|
|
|
2021-04-26 15:46:09 +02:00
|
|
|
return FilePath::fromString(urp + pathHelper(rel));
|
2012-01-18 23:25:34 +01:00
|
|
|
}
|
|
|
|
|
|
2020-05-28 16:26:01 +02:00
|
|
|
/*!
|
2021-11-25 16:11:53 +01:00
|
|
|
Returns a writable path for the relative path \a rel that can be used for persistent cache files.
|
2020-05-28 16:26:01 +02:00
|
|
|
*/
|
2021-04-26 15:46:09 +02:00
|
|
|
FilePath ICore::cacheResourcePath(const QString &rel)
|
2019-02-20 17:26:36 +01:00
|
|
|
{
|
2021-04-26 15:46:09 +02:00
|
|
|
return FilePath::fromString(QStandardPaths::writableLocation(QStandardPaths::CacheLocation)
|
|
|
|
|
+ pathHelper(rel));
|
2019-02-20 17:26:36 +01:00
|
|
|
}
|
|
|
|
|
|
2020-05-28 16:26:01 +02:00
|
|
|
/*!
|
2021-11-25 16:11:53 +01:00
|
|
|
Returns the path, based on the relative path \a rel, to resources written by the installer,
|
|
|
|
|
for example pre-defined kits and toolchains.
|
2020-05-28 16:26:01 +02:00
|
|
|
*/
|
2021-04-26 15:46:09 +02:00
|
|
|
FilePath ICore::installerResourcePath(const QString &rel)
|
2018-01-10 17:29:27 +01:00
|
|
|
{
|
2021-04-22 16:15:26 +02:00
|
|
|
return FilePath::fromString(settings(QSettings::SystemScope)->fileName()).parentDir()
|
2023-06-21 15:12:46 +02:00
|
|
|
/ appInfo().id / rel;
|
2020-01-21 14:17:05 +01:00
|
|
|
}
|
|
|
|
|
|
2020-05-28 16:26:01 +02:00
|
|
|
/*!
|
|
|
|
|
Returns the path to the plugins that are included in the \QC installation.
|
|
|
|
|
|
|
|
|
|
\internal
|
|
|
|
|
*/
|
2020-01-21 14:17:05 +01:00
|
|
|
QString ICore::pluginPath()
|
|
|
|
|
{
|
|
|
|
|
return QDir::cleanPath(QCoreApplication::applicationDirPath() + '/' + RELATIVE_PLUGIN_PATH);
|
|
|
|
|
}
|
|
|
|
|
|
2020-05-28 16:26:01 +02:00
|
|
|
/*!
|
|
|
|
|
Returns the path where user-specific plugins should be written.
|
|
|
|
|
|
|
|
|
|
\internal
|
|
|
|
|
*/
|
2020-01-21 14:17:05 +01:00
|
|
|
QString ICore::userPluginPath()
|
|
|
|
|
{
|
2023-06-21 15:12:46 +02:00
|
|
|
const QVersionNumber appVersion = QVersionNumber::fromString(
|
|
|
|
|
QCoreApplication::applicationVersion());
|
2020-01-21 14:17:05 +01:00
|
|
|
QString pluginPath = QStandardPaths::writableLocation(QStandardPaths::GenericDataLocation);
|
|
|
|
|
if (Utils::HostOsInfo::isAnyUnixHost() && !Utils::HostOsInfo::isMacHost())
|
|
|
|
|
pluginPath += "/data";
|
2023-06-21 15:12:46 +02:00
|
|
|
pluginPath += '/' + QCoreApplication::organizationName() + '/';
|
|
|
|
|
pluginPath += Utils::HostOsInfo::isMacHost() ? QGuiApplication::applicationDisplayName()
|
|
|
|
|
: appInfo().id;
|
2020-01-21 14:17:05 +01:00
|
|
|
pluginPath += "/plugins/";
|
2023-06-21 15:12:46 +02:00
|
|
|
pluginPath += QString::number(appVersion.majorVersion()) + '.'
|
|
|
|
|
+ QString::number(appVersion.minorVersion()) + '.'
|
|
|
|
|
+ QString::number(appVersion.microVersion());
|
2020-01-21 14:17:05 +01:00
|
|
|
return pluginPath;
|
2018-01-10 17:29:27 +01:00
|
|
|
}
|
|
|
|
|
|
2013-10-02 16:09:23 +02:00
|
|
|
/*!
|
2021-11-25 16:11:53 +01:00
|
|
|
Returns the path, based on the relative path \a rel, to the command line tools that are
|
|
|
|
|
included in the \QC installation.
|
2013-10-02 16:09:23 +02:00
|
|
|
*/
|
2021-04-26 15:46:09 +02:00
|
|
|
FilePath ICore::libexecPath(const QString &rel)
|
2013-10-02 16:09:23 +02:00
|
|
|
{
|
2021-05-26 10:12:58 +02:00
|
|
|
return FilePath::fromString(QDir::cleanPath(QApplication::applicationDirPath()
|
|
|
|
|
+ pathHelper(RELATIVE_LIBEXEC_PATH)))
|
|
|
|
|
/ rel;
|
2013-10-02 16:09:23 +02:00
|
|
|
}
|
|
|
|
|
|
2021-04-22 16:15:26 +02:00
|
|
|
FilePath ICore::crashReportsPath()
|
2020-09-21 12:58:35 +03:00
|
|
|
{
|
|
|
|
|
if (Utils::HostOsInfo::isMacHost())
|
2023-03-03 18:13:30 +01:00
|
|
|
return Core::ICore::userResourcePath("crashpad_reports/completed");
|
2020-09-21 12:58:35 +03:00
|
|
|
else
|
2021-04-26 15:46:09 +02:00
|
|
|
return libexecPath("crashpad_reports/reports");
|
2020-09-21 12:58:35 +03:00
|
|
|
}
|
|
|
|
|
|
2018-08-06 11:32:32 +02:00
|
|
|
static QString clangIncludePath(const QString &clangVersion)
|
|
|
|
|
{
|
|
|
|
|
return "/lib/clang/" + clangVersion + "/include";
|
|
|
|
|
}
|
|
|
|
|
|
2020-05-28 16:26:01 +02:00
|
|
|
/*!
|
|
|
|
|
\internal
|
|
|
|
|
*/
|
2021-08-12 09:19:55 +02:00
|
|
|
FilePath ICore::clangIncludeDirectory(const QString &clangVersion,
|
|
|
|
|
const FilePath &clangFallbackIncludeDir)
|
2018-08-06 11:32:32 +02:00
|
|
|
{
|
2021-04-26 15:46:09 +02:00
|
|
|
FilePath dir = libexecPath("clang" + clangIncludePath(clangVersion));
|
2021-04-22 16:15:26 +02:00
|
|
|
if (!dir.exists() || !dir.pathAppended("stdint.h").exists())
|
2021-08-12 09:19:55 +02:00
|
|
|
dir = clangFallbackIncludeDir;
|
|
|
|
|
return dir.canonicalPath();
|
2018-08-06 11:32:32 +02:00
|
|
|
}
|
|
|
|
|
|
2020-05-28 16:26:01 +02:00
|
|
|
/*!
|
|
|
|
|
\internal
|
|
|
|
|
*/
|
2021-08-12 09:19:55 +02:00
|
|
|
static FilePath clangBinary(const QString &binaryBaseName, const FilePath &clangBinDirectory)
|
2018-08-06 11:32:32 +02:00
|
|
|
{
|
2021-08-12 09:19:55 +02:00
|
|
|
FilePath executable =
|
|
|
|
|
ICore::libexecPath("clang/bin").pathAppended(binaryBaseName).withExecutableSuffix();
|
2018-08-06 11:32:32 +02:00
|
|
|
if (!executable.exists())
|
2021-08-12 09:19:55 +02:00
|
|
|
executable = clangBinDirectory.pathAppended(binaryBaseName).withExecutableSuffix();
|
|
|
|
|
return executable.canonicalPath();
|
2018-08-06 11:32:32 +02:00
|
|
|
}
|
|
|
|
|
|
2020-05-28 16:26:01 +02:00
|
|
|
/*!
|
|
|
|
|
\internal
|
|
|
|
|
*/
|
2021-08-12 09:19:55 +02:00
|
|
|
FilePath ICore::clangExecutable(const FilePath &clangBinDirectory)
|
2019-08-01 16:08:40 +02:00
|
|
|
{
|
|
|
|
|
return clangBinary("clang", clangBinDirectory);
|
|
|
|
|
}
|
|
|
|
|
|
2021-02-23 13:51:41 +01:00
|
|
|
/*!
|
|
|
|
|
\internal
|
|
|
|
|
*/
|
2021-08-12 09:19:55 +02:00
|
|
|
FilePath ICore::clangdExecutable(const FilePath &clangBinDirectory)
|
2021-02-23 13:51:41 +01:00
|
|
|
{
|
|
|
|
|
return clangBinary("clangd", clangBinDirectory);
|
|
|
|
|
}
|
|
|
|
|
|
2020-05-28 16:26:01 +02:00
|
|
|
/*!
|
|
|
|
|
\internal
|
|
|
|
|
*/
|
2021-08-12 09:19:55 +02:00
|
|
|
FilePath ICore::clangTidyExecutable(const FilePath &clangBinDirectory)
|
2019-08-01 16:08:40 +02:00
|
|
|
{
|
|
|
|
|
return clangBinary("clang-tidy", clangBinDirectory);
|
|
|
|
|
}
|
|
|
|
|
|
2020-05-28 16:26:01 +02:00
|
|
|
/*!
|
|
|
|
|
\internal
|
|
|
|
|
*/
|
2021-08-12 09:19:55 +02:00
|
|
|
FilePath ICore::clazyStandaloneExecutable(const FilePath &clangBinDirectory)
|
2019-08-28 08:56:22 +02:00
|
|
|
{
|
|
|
|
|
return clangBinary("clazy-standalone", clangBinDirectory);
|
|
|
|
|
}
|
|
|
|
|
|
2013-05-24 16:45:49 +02:00
|
|
|
static QString compilerString()
|
|
|
|
|
{
|
|
|
|
|
#if defined(Q_CC_CLANG) // must be before GNU, because clang claims to be GNU too
|
2021-06-03 18:12:54 +02:00
|
|
|
QString platformSpecific;
|
2013-05-24 16:45:49 +02:00
|
|
|
#if defined(__apple_build_version__) // Apple clang has other version numbers
|
2021-06-03 18:12:54 +02:00
|
|
|
platformSpecific = QLatin1String(" (Apple)");
|
|
|
|
|
#elif defined(Q_CC_MSVC)
|
|
|
|
|
platformSpecific = QLatin1String(" (clang-cl)");
|
2013-05-24 16:45:49 +02:00
|
|
|
#endif
|
|
|
|
|
return QLatin1String("Clang " ) + QString::number(__clang_major__) + QLatin1Char('.')
|
2021-06-03 18:12:54 +02:00
|
|
|
+ QString::number(__clang_minor__) + platformSpecific;
|
2013-05-24 16:45:49 +02:00
|
|
|
#elif defined(Q_CC_GNU)
|
|
|
|
|
return QLatin1String("GCC " ) + QLatin1String(__VERSION__);
|
|
|
|
|
#elif defined(Q_CC_MSVC)
|
2016-01-19 15:21:11 +01:00
|
|
|
if (_MSC_VER > 1999)
|
|
|
|
|
return QLatin1String("MSVC <unknown>");
|
2022-04-14 12:23:32 +02:00
|
|
|
if (_MSC_VER >= 1930)
|
|
|
|
|
return QLatin1String("MSVC 2022");
|
2020-05-28 16:40:39 +02:00
|
|
|
if (_MSC_VER >= 1920)
|
|
|
|
|
return QLatin1String("MSVC 2019");
|
2017-04-14 16:25:21 +03:00
|
|
|
if (_MSC_VER >= 1910)
|
|
|
|
|
return QLatin1String("MSVC 2017");
|
|
|
|
|
if (_MSC_VER >= 1900)
|
2016-01-19 15:21:11 +01:00
|
|
|
return QLatin1String("MSVC 2015");
|
2013-05-24 16:45:49 +02:00
|
|
|
#endif
|
|
|
|
|
return QLatin1String("<unknown compiler>");
|
|
|
|
|
}
|
|
|
|
|
|
2020-05-28 16:26:01 +02:00
|
|
|
/*!
|
|
|
|
|
Returns a string with the IDE's name and version, in the form "\QC X.Y.Z".
|
|
|
|
|
Use this for "Generated by" strings and similar tasks.
|
|
|
|
|
*/
|
2013-05-24 16:45:49 +02:00
|
|
|
QString ICore::versionString()
|
|
|
|
|
{
|
|
|
|
|
QString ideVersionDescription;
|
2023-06-21 15:12:46 +02:00
|
|
|
if (QCoreApplication::applicationVersion() != appInfo().displayVersion)
|
|
|
|
|
ideVersionDescription = Tr::tr(" (%1)").arg(QCoreApplication::applicationVersion());
|
|
|
|
|
return Tr::tr("%1 %2%3").arg(QGuiApplication::applicationDisplayName(),
|
|
|
|
|
appInfo().displayVersion,
|
2023-01-16 17:20:07 +01:00
|
|
|
ideVersionDescription);
|
2013-05-24 16:45:49 +02:00
|
|
|
}
|
|
|
|
|
|
2020-05-28 16:26:01 +02:00
|
|
|
/*!
|
|
|
|
|
\internal
|
|
|
|
|
*/
|
2013-05-24 16:45:49 +02:00
|
|
|
QString ICore::buildCompatibilityString()
|
|
|
|
|
{
|
2023-01-16 17:20:07 +01:00
|
|
|
return Tr::tr("Based on Qt %1 (%2, %3)").arg(QLatin1String(qVersion()),
|
2014-11-20 16:00:06 +01:00
|
|
|
compilerString(),
|
2022-04-14 11:09:09 +02:00
|
|
|
QSysInfo::buildCpuArchitecture());
|
2013-05-24 16:45:49 +02:00
|
|
|
}
|
|
|
|
|
|
2020-03-18 13:32:02 +01:00
|
|
|
/*!
|
2020-05-28 16:26:01 +02:00
|
|
|
Returns the top level IContext of the current context, or \c nullptr if
|
|
|
|
|
there is none.
|
2020-03-18 13:32:02 +01:00
|
|
|
|
2020-05-28 16:26:01 +02:00
|
|
|
\sa updateAdditionalContexts()
|
|
|
|
|
\sa addContextObject()
|
|
|
|
|
\sa {The Action Manager and Commands}
|
2020-03-18 13:32:02 +01:00
|
|
|
*/
|
2012-01-18 23:25:34 +01:00
|
|
|
IContext *ICore::currentContextObject()
|
|
|
|
|
{
|
|
|
|
|
return m_mainwindow->currentContextObject();
|
|
|
|
|
}
|
|
|
|
|
|
2020-05-28 16:26:01 +02:00
|
|
|
/*!
|
|
|
|
|
Returns the widget of the top level IContext of the current context, or \c
|
|
|
|
|
nullptr if there is none.
|
|
|
|
|
|
|
|
|
|
\sa currentContextObject()
|
|
|
|
|
*/
|
2017-11-30 16:32:55 +01:00
|
|
|
QWidget *ICore::currentContextWidget()
|
|
|
|
|
{
|
|
|
|
|
IContext *context = currentContextObject();
|
|
|
|
|
return context ? context->widget() : nullptr;
|
|
|
|
|
}
|
|
|
|
|
|
2020-05-28 16:26:01 +02:00
|
|
|
/*!
|
|
|
|
|
Returns the registered IContext instance for the specified \a widget,
|
|
|
|
|
if any.
|
|
|
|
|
*/
|
2018-07-10 15:49:50 +02:00
|
|
|
IContext *ICore::contextObject(QWidget *widget)
|
|
|
|
|
{
|
|
|
|
|
return m_mainwindow->contextObject(widget);
|
|
|
|
|
}
|
|
|
|
|
|
2020-03-18 13:32:02 +01:00
|
|
|
/*!
|
|
|
|
|
Returns the main window of the application.
|
2012-01-18 23:25:34 +01:00
|
|
|
|
2020-03-18 13:32:02 +01:00
|
|
|
For dialog parents use dialogParent().
|
2020-05-28 16:26:01 +02:00
|
|
|
|
|
|
|
|
\sa dialogParent()
|
2020-03-18 13:32:02 +01:00
|
|
|
*/
|
2018-01-10 10:23:18 +01:00
|
|
|
QMainWindow *ICore::mainWindow()
|
2012-01-18 23:25:34 +01:00
|
|
|
{
|
|
|
|
|
return m_mainwindow;
|
|
|
|
|
}
|
|
|
|
|
|
2020-03-18 13:32:02 +01:00
|
|
|
/*!
|
|
|
|
|
Returns a widget pointer suitable to use as parent for QDialogs.
|
2020-05-28 16:26:01 +02:00
|
|
|
*/
|
2014-01-06 10:36:40 +01:00
|
|
|
QWidget *ICore::dialogParent()
|
|
|
|
|
{
|
|
|
|
|
QWidget *active = QApplication::activeModalWidget();
|
2015-06-03 12:20:13 +02:00
|
|
|
if (!active)
|
|
|
|
|
active = QApplication::activeWindow();
|
2022-09-14 09:22:45 +02:00
|
|
|
if (!active || (active && active->windowFlags().testAnyFlags(Qt::SplashScreen | Qt::Popup)))
|
2015-06-03 12:20:13 +02:00
|
|
|
active = m_mainwindow;
|
|
|
|
|
return active;
|
2014-01-06 10:36:40 +01:00
|
|
|
}
|
|
|
|
|
|
2020-05-28 16:26:01 +02:00
|
|
|
/*!
|
|
|
|
|
\internal
|
|
|
|
|
*/
|
2012-01-18 23:25:34 +01:00
|
|
|
QStatusBar *ICore::statusBar()
|
|
|
|
|
{
|
|
|
|
|
return m_mainwindow->statusBar();
|
|
|
|
|
}
|
|
|
|
|
|
2020-05-28 16:26:01 +02:00
|
|
|
/*!
|
|
|
|
|
Returns a central InfoBar that is shown in \QC's main window.
|
|
|
|
|
Use for notifying the user of something without interrupting with
|
|
|
|
|
dialog. Use sparingly.
|
|
|
|
|
*/
|
2020-06-17 12:23:44 +02:00
|
|
|
Utils::InfoBar *ICore::infoBar()
|
2019-08-07 12:44:40 +02:00
|
|
|
{
|
|
|
|
|
return m_mainwindow->infoBar();
|
|
|
|
|
}
|
|
|
|
|
|
2020-05-28 16:26:01 +02:00
|
|
|
/*!
|
|
|
|
|
Raises and activates the window for \a widget. This contains workarounds
|
|
|
|
|
for X11.
|
|
|
|
|
*/
|
2013-04-15 12:53:34 +02:00
|
|
|
void ICore::raiseWindow(QWidget *widget)
|
|
|
|
|
{
|
|
|
|
|
if (!widget)
|
|
|
|
|
return;
|
|
|
|
|
QWidget *window = widget->window();
|
2022-11-30 14:47:49 +01:00
|
|
|
if (!window)
|
|
|
|
|
return;
|
|
|
|
|
if (window == m_mainwindow) {
|
2013-04-15 12:53:34 +02:00
|
|
|
m_mainwindow->raiseWindow();
|
|
|
|
|
} else {
|
|
|
|
|
window->raise();
|
|
|
|
|
window->activateWindow();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2020-03-18 13:32:02 +01:00
|
|
|
/*!
|
2020-05-28 16:26:01 +02:00
|
|
|
Removes the contexts specified by \a remove from the list of active
|
|
|
|
|
additional contexts, and adds the contexts specified by \a add with \a
|
|
|
|
|
priority.
|
2020-03-18 13:32:02 +01:00
|
|
|
|
2020-05-28 16:26:01 +02:00
|
|
|
The additional contexts are not associated with an IContext instance.
|
|
|
|
|
|
|
|
|
|
High priority additional contexts have higher priority than the contexts
|
|
|
|
|
added by IContext instances, low priority additional contexts have lower
|
|
|
|
|
priority than the contexts added by IContext instances.
|
|
|
|
|
|
|
|
|
|
\sa addContextObject()
|
|
|
|
|
\sa {The Action Manager and Commands}
|
2020-03-18 13:32:02 +01:00
|
|
|
*/
|
2015-08-07 17:21:38 +02:00
|
|
|
void ICore::updateAdditionalContexts(const Context &remove, const Context &add,
|
|
|
|
|
ContextPriority priority)
|
2012-01-18 23:25:34 +01:00
|
|
|
{
|
2015-08-07 17:21:38 +02:00
|
|
|
m_mainwindow->updateAdditionalContexts(remove, add, priority);
|
2012-01-18 23:25:34 +01:00
|
|
|
}
|
|
|
|
|
|
2020-03-18 13:32:02 +01:00
|
|
|
/*!
|
2020-05-28 16:26:01 +02:00
|
|
|
Adds \a context with \a priority to the list of active additional contexts.
|
|
|
|
|
|
|
|
|
|
\sa updateAdditionalContexts()
|
2020-03-18 13:32:02 +01:00
|
|
|
*/
|
2015-08-07 17:21:38 +02:00
|
|
|
void ICore::addAdditionalContext(const Context &context, ContextPriority priority)
|
2014-11-16 11:47:18 +02:00
|
|
|
{
|
2015-08-07 17:21:38 +02:00
|
|
|
m_mainwindow->updateAdditionalContexts(Context(), context, priority);
|
2014-11-16 11:47:18 +02:00
|
|
|
}
|
|
|
|
|
|
2020-05-28 16:26:01 +02:00
|
|
|
/*!
|
|
|
|
|
Removes \a context from the list of active additional contexts.
|
|
|
|
|
|
|
|
|
|
\sa updateAdditionalContexts()
|
|
|
|
|
*/
|
2014-11-16 11:47:18 +02:00
|
|
|
void ICore::removeAdditionalContext(const Context &context)
|
|
|
|
|
{
|
2015-08-07 17:21:38 +02:00
|
|
|
m_mainwindow->updateAdditionalContexts(context, Context(), ContextPriority::Low);
|
2014-11-16 11:47:18 +02:00
|
|
|
}
|
|
|
|
|
|
2020-03-18 13:32:02 +01:00
|
|
|
/*!
|
2020-05-28 16:26:01 +02:00
|
|
|
Adds \a context to the list of registered IContext instances.
|
|
|
|
|
Whenever the IContext's \l{IContext::widget()}{widget} is in the application
|
|
|
|
|
focus widget's parent hierarchy, its \l{IContext::context()}{context} is
|
|
|
|
|
added to the list of active contexts.
|
|
|
|
|
|
|
|
|
|
\sa removeContextObject()
|
|
|
|
|
\sa updateAdditionalContexts()
|
|
|
|
|
\sa currentContextObject()
|
|
|
|
|
\sa {The Action Manager and Commands}
|
2020-03-18 13:32:02 +01:00
|
|
|
*/
|
2012-01-18 23:25:34 +01:00
|
|
|
void ICore::addContextObject(IContext *context)
|
|
|
|
|
{
|
|
|
|
|
m_mainwindow->addContextObject(context);
|
|
|
|
|
}
|
|
|
|
|
|
2020-03-18 13:32:02 +01:00
|
|
|
/*!
|
2020-05-28 16:26:01 +02:00
|
|
|
Unregisters a \a context object from the list of registered IContext
|
|
|
|
|
instances. IContext instances are automatically removed when they are
|
|
|
|
|
deleted.
|
2020-03-18 13:32:02 +01:00
|
|
|
|
2020-05-28 16:26:01 +02:00
|
|
|
\sa addContextObject()
|
|
|
|
|
\sa updateAdditionalContexts()
|
|
|
|
|
\sa currentContextObject()
|
2020-03-18 13:32:02 +01:00
|
|
|
*/
|
2012-01-18 23:25:34 +01:00
|
|
|
void ICore::removeContextObject(IContext *context)
|
|
|
|
|
{
|
|
|
|
|
m_mainwindow->removeContextObject(context);
|
|
|
|
|
}
|
|
|
|
|
|
2020-05-28 16:26:01 +02:00
|
|
|
/*!
|
|
|
|
|
Registers a \a window with the specified \a context. Registered windows are
|
|
|
|
|
shown in the \uicontrol Window menu and get registered for the various
|
|
|
|
|
window related actions, like the minimize, zoom, fullscreen and close
|
|
|
|
|
actions.
|
|
|
|
|
|
|
|
|
|
Whenever the application focus is in \a window, its \a context is made
|
|
|
|
|
active.
|
|
|
|
|
*/
|
2014-07-17 17:04:02 +02:00
|
|
|
void ICore::registerWindow(QWidget *window, const Context &context)
|
|
|
|
|
{
|
|
|
|
|
new WindowSupport(window, context); // deletes itself when widget is destroyed
|
|
|
|
|
}
|
|
|
|
|
|
2022-08-02 11:04:10 +02:00
|
|
|
void ICore::restartTrimmer()
|
|
|
|
|
{
|
|
|
|
|
m_mainwindow->restartTrimmer();
|
|
|
|
|
}
|
|
|
|
|
|
2020-03-18 13:32:02 +01:00
|
|
|
/*!
|
2021-07-23 10:33:02 +02:00
|
|
|
Opens files using \a filePaths and \a flags like it would be
|
2020-03-18 13:32:02 +01:00
|
|
|
done if they were given to \QC on the command line, or
|
|
|
|
|
they were opened via \uicontrol File > \uicontrol Open.
|
|
|
|
|
*/
|
|
|
|
|
|
2021-07-23 10:33:02 +02:00
|
|
|
void ICore::openFiles(const FilePaths &filePaths, ICore::OpenFilesFlags flags)
|
2012-01-18 23:25:34 +01:00
|
|
|
{
|
2021-07-23 10:33:02 +02:00
|
|
|
MainWindow::openFiles(filePaths, flags);
|
2012-01-18 23:25:34 +01:00
|
|
|
}
|
|
|
|
|
|
2015-08-26 14:39:15 +02:00
|
|
|
/*!
|
2020-03-18 13:32:02 +01:00
|
|
|
Provides a hook for plugins to veto on closing the application.
|
2015-08-26 14:39:15 +02:00
|
|
|
|
2020-03-18 13:32:02 +01:00
|
|
|
When the application window requests a close, all listeners are called. If
|
|
|
|
|
one of the \a listener calls returns \c false, the process is aborted and
|
|
|
|
|
the event is ignored. If all calls return \c true, coreAboutToClose()
|
|
|
|
|
is emitted and the event is accepted or performed.
|
2015-08-26 14:39:15 +02:00
|
|
|
*/
|
|
|
|
|
void ICore::addPreCloseListener(const std::function<bool ()> &listener)
|
|
|
|
|
{
|
|
|
|
|
m_mainwindow->addPreCloseListener(listener);
|
|
|
|
|
}
|
|
|
|
|
|
2020-05-28 16:26:01 +02:00
|
|
|
/*!
|
|
|
|
|
\internal
|
|
|
|
|
*/
|
2016-08-31 15:39:52 +02:00
|
|
|
QString ICore::systemInformation()
|
|
|
|
|
{
|
2020-11-21 01:04:56 +01:00
|
|
|
QString result = PluginManager::systemInformation() + '\n';
|
2016-08-31 15:39:52 +02:00
|
|
|
result += versionString() + '\n';
|
|
|
|
|
result += buildCompatibilityString() + '\n';
|
|
|
|
|
#ifdef IDE_REVISION
|
2016-09-06 09:54:19 +02:00
|
|
|
result += QString("From revision %1\n").arg(QString::fromLatin1(Constants::IDE_REVISION_STR).left(10));
|
2016-08-31 15:39:52 +02:00
|
|
|
#endif
|
|
|
|
|
#ifdef QTC_SHOW_BUILD_DATE
|
2016-09-06 09:54:19 +02:00
|
|
|
result += QString("Built on %1 %2\n").arg(QLatin1String(__DATE__), QLatin1String(__TIME__));
|
2016-08-31 15:39:52 +02:00
|
|
|
#endif
|
|
|
|
|
return result;
|
|
|
|
|
}
|
|
|
|
|
|
2022-08-24 14:55:41 +02:00
|
|
|
static const QString &screenShotsPath()
|
2016-12-20 11:19:22 +01:00
|
|
|
{
|
2022-08-24 14:55:41 +02:00
|
|
|
static const QString path = qtcEnvironmentVariable("QTC_SCREENSHOTS_PATH");
|
2016-12-20 11:19:22 +01:00
|
|
|
return path;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
class ScreenShooter : public QObject
|
|
|
|
|
{
|
|
|
|
|
public:
|
|
|
|
|
ScreenShooter(QWidget *widget, const QString &name, const QRect &rc)
|
|
|
|
|
: m_widget(widget), m_name(name), m_rc(rc)
|
|
|
|
|
{
|
|
|
|
|
m_widget->installEventFilter(this);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
bool eventFilter(QObject *watched, QEvent *event) override
|
|
|
|
|
{
|
|
|
|
|
QTC_ASSERT(watched == m_widget, return false);
|
|
|
|
|
if (event->type() == QEvent::Show)
|
2021-01-28 11:29:14 +01:00
|
|
|
QMetaObject::invokeMethod(this, &ScreenShooter::helper, Qt::QueuedConnection);
|
2016-12-20 11:19:22 +01:00
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void helper()
|
|
|
|
|
{
|
|
|
|
|
if (m_widget) {
|
|
|
|
|
QRect rc = m_rc.isValid() ? m_rc : m_widget->rect();
|
|
|
|
|
QPixmap pm = m_widget->grab(rc);
|
|
|
|
|
for (int i = 0; ; ++i) {
|
|
|
|
|
QString fileName = screenShotsPath() + '/' + m_name + QString("-%1.png").arg(i);
|
|
|
|
|
if (!QFileInfo::exists(fileName)) {
|
|
|
|
|
pm.save(fileName);
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
deleteLater();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
QPointer<QWidget> m_widget;
|
|
|
|
|
QString m_name;
|
|
|
|
|
QRect m_rc;
|
|
|
|
|
};
|
|
|
|
|
|
2020-05-28 16:26:01 +02:00
|
|
|
/*!
|
|
|
|
|
\internal
|
|
|
|
|
*/
|
2016-12-20 11:19:22 +01:00
|
|
|
void ICore::setupScreenShooter(const QString &name, QWidget *w, const QRect &rc)
|
|
|
|
|
{
|
|
|
|
|
if (!screenShotsPath().isEmpty())
|
|
|
|
|
new ScreenShooter(w, name, rc);
|
|
|
|
|
}
|
|
|
|
|
|
2020-05-28 16:26:01 +02:00
|
|
|
/*!
|
|
|
|
|
Restarts \QC and restores the last session.
|
|
|
|
|
*/
|
2020-01-03 16:47:15 +01:00
|
|
|
void ICore::restart()
|
|
|
|
|
{
|
|
|
|
|
m_mainwindow->restart();
|
|
|
|
|
}
|
|
|
|
|
|
2020-05-28 16:26:01 +02:00
|
|
|
/*!
|
|
|
|
|
\internal
|
|
|
|
|
*/
|
2019-06-03 09:32:15 +02:00
|
|
|
void ICore::saveSettings(SaveSettingsReason reason)
|
2012-08-17 09:09:15 +02:00
|
|
|
{
|
2019-06-03 09:32:15 +02:00
|
|
|
emit m_instance->saveSettingsRequested(reason);
|
2016-09-06 09:06:56 +02:00
|
|
|
m_mainwindow->saveSettings();
|
2012-08-17 09:09:15 +02:00
|
|
|
|
|
|
|
|
ICore::settings(QSettings::SystemScope)->sync();
|
|
|
|
|
ICore::settings(QSettings::UserScope)->sync();
|
|
|
|
|
}
|
|
|
|
|
|
2020-05-28 16:26:01 +02:00
|
|
|
/*!
|
|
|
|
|
\internal
|
|
|
|
|
*/
|
2015-10-02 15:15:38 +02:00
|
|
|
QStringList ICore::additionalAboutInformation()
|
|
|
|
|
{
|
|
|
|
|
return m_mainwindow->additionalAboutInformation();
|
|
|
|
|
}
|
|
|
|
|
|
2023-09-07 14:06:37 +02:00
|
|
|
/*!
|
|
|
|
|
\internal
|
|
|
|
|
*/
|
|
|
|
|
void ICore::clearAboutInformation()
|
|
|
|
|
{
|
|
|
|
|
m_mainwindow->clearAboutInformation();
|
|
|
|
|
}
|
|
|
|
|
|
2020-05-28 16:26:01 +02:00
|
|
|
/*!
|
|
|
|
|
\internal
|
|
|
|
|
*/
|
2015-10-02 15:15:38 +02:00
|
|
|
void ICore::appendAboutInformation(const QString &line)
|
|
|
|
|
{
|
|
|
|
|
m_mainwindow->appendAboutInformation(line);
|
|
|
|
|
}
|
|
|
|
|
|
2016-09-26 16:39:49 +02:00
|
|
|
void ICore::updateNewItemDialogState()
|
2015-05-29 13:24:02 +02:00
|
|
|
{
|
2015-05-29 14:23:59 +02:00
|
|
|
static bool wasRunning = false;
|
2016-09-26 16:39:49 +02:00
|
|
|
static QWidget *previousDialog = nullptr;
|
|
|
|
|
if (wasRunning == isNewItemDialogRunning() && previousDialog == newItemDialog())
|
2015-05-29 14:23:59 +02:00
|
|
|
return;
|
|
|
|
|
wasRunning = isNewItemDialogRunning();
|
2016-09-26 16:39:49 +02:00
|
|
|
previousDialog = newItemDialog();
|
|
|
|
|
emit instance()->newItemDialogStateChanged();
|
2015-05-29 13:24:02 +02:00
|
|
|
}
|
|
|
|
|
|
2021-08-26 20:02:55 +03:00
|
|
|
/*!
|
|
|
|
|
\internal
|
|
|
|
|
*/
|
|
|
|
|
void ICore::setNewDialogFactory(const std::function<NewDialog *(QWidget *)> &newFactory)
|
|
|
|
|
{
|
|
|
|
|
m_newDialogFactory = newFactory;
|
|
|
|
|
}
|
|
|
|
|
|
2012-01-18 23:25:34 +01:00
|
|
|
} // namespace Core
|