forked from qt-creator/qt-creator
Core: Give a hint why saving of settings are requested
Not all requests are the same, handling code might want to act differently on different request reasons. Main driver here is the handling of the debugger/analyzer main window state savings which depends on actual visibility of certain windows. Change-Id: I87b2a9149e3d09d27bc14b44aace9f2e0686db04 Reviewed-by: Eike Ziller <eike.ziller@qt.io>
This commit is contained in:
@@ -726,7 +726,7 @@ void SettingsDialog::done(int val)
|
|||||||
QSettings *settings = ICore::settings();
|
QSettings *settings = ICore::settings();
|
||||||
settings->setValue(QLatin1String(pageKeyC), m_currentPage.toSetting());
|
settings->setValue(QLatin1String(pageKeyC), m_currentPage.toSetting());
|
||||||
|
|
||||||
ICore::saveSettings(); // save all settings
|
ICore::saveSettings(ICore::SettingsDialogDone); // save all settings
|
||||||
|
|
||||||
// exit event loops in reverse order of addition
|
// exit event loops in reverse order of addition
|
||||||
for (QEventLoop *eventLoop : m_eventLoops)
|
for (QEventLoop *eventLoop : m_eventLoops)
|
||||||
|
@@ -330,7 +330,7 @@ ICore::ICore(MainWindow *mainwindow)
|
|||||||
m_mainwindow = mainwindow;
|
m_mainwindow = mainwindow;
|
||||||
// Save settings once after all plugins are initialized:
|
// Save settings once after all plugins are initialized:
|
||||||
connect(PluginManager::instance(), &PluginManager::initializationDone,
|
connect(PluginManager::instance(), &PluginManager::initializationDone,
|
||||||
this, &ICore::saveSettings);
|
this, [] { ICore::saveSettings(ICore::InitializationDone); });
|
||||||
connect(PluginManager::instance(), &PluginManager::testsFinished, [this] (int failedTests) {
|
connect(PluginManager::instance(), &PluginManager::testsFinished, [this] (int failedTests) {
|
||||||
emit coreAboutToClose();
|
emit coreAboutToClose();
|
||||||
if (failedTests != 0)
|
if (failedTests != 0)
|
||||||
@@ -690,9 +690,9 @@ void ICore::setupScreenShooter(const QString &name, QWidget *w, const QRect &rc)
|
|||||||
new ScreenShooter(w, name, rc);
|
new ScreenShooter(w, name, rc);
|
||||||
}
|
}
|
||||||
|
|
||||||
void ICore::saveSettings()
|
void ICore::saveSettings(SaveSettingsReason reason)
|
||||||
{
|
{
|
||||||
emit m_instance->saveSettingsRequested();
|
emit m_instance->saveSettingsRequested(reason);
|
||||||
m_mainwindow->saveSettings();
|
m_mainwindow->saveSettings();
|
||||||
|
|
||||||
ICore::settings(QSettings::SystemScope)->sync();
|
ICore::settings(QSettings::SystemScope)->sync();
|
||||||
|
@@ -141,14 +141,21 @@ public:
|
|||||||
static QString systemInformation();
|
static QString systemInformation();
|
||||||
static void setupScreenShooter(const QString &name, QWidget *w, const QRect &rc = QRect());
|
static void setupScreenShooter(const QString &name, QWidget *w, const QRect &rc = QRect());
|
||||||
|
|
||||||
|
enum SaveSettingsReason {
|
||||||
|
InitializationDone,
|
||||||
|
SettingsDialogDone,
|
||||||
|
ModeChanged,
|
||||||
|
MainWindowClosing,
|
||||||
|
};
|
||||||
|
|
||||||
public slots:
|
public slots:
|
||||||
static void saveSettings();
|
static void saveSettings(SaveSettingsReason reason);
|
||||||
|
|
||||||
signals:
|
signals:
|
||||||
void coreAboutToOpen();
|
void coreAboutToOpen();
|
||||||
void coreOpened();
|
void coreOpened();
|
||||||
void newItemDialogStateChanged();
|
void newItemDialogStateChanged();
|
||||||
void saveSettingsRequested();
|
void saveSettingsRequested(SaveSettingsReason reason);
|
||||||
void coreAboutToClose();
|
void coreAboutToClose();
|
||||||
void contextAboutToChange(const QList<Core::IContext *> &context);
|
void contextAboutToChange(const QList<Core::IContext *> &context);
|
||||||
void contextChanged(const Core::Context &context);
|
void contextChanged(const Core::Context &context);
|
||||||
|
@@ -322,7 +322,7 @@ void MainWindow::closeEvent(QCloseEvent *event)
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
ICore::saveSettings();
|
ICore::saveSettings(ICore::MainWindowClosing);
|
||||||
|
|
||||||
// Save opened files
|
// Save opened files
|
||||||
if (!DocumentManager::saveAllModifiedDocuments()) {
|
if (!DocumentManager::saveAllModifiedDocuments()) {
|
||||||
|
@@ -2098,7 +2098,7 @@ void ProjectExplorerPluginPrivate::currentModeChanged(Id mode, Id oldMode)
|
|||||||
// Saving settings directly in a mode change is not a good idea, since the mode change
|
// Saving settings directly in a mode change is not a good idea, since the mode change
|
||||||
// can be part of a bigger change. Save settings after that bigger change had a chance to
|
// can be part of a bigger change. Save settings after that bigger change had a chance to
|
||||||
// complete.
|
// complete.
|
||||||
QTimer::singleShot(0, ICore::instance(), &ICore::saveSettings);
|
QTimer::singleShot(0, ICore::instance(), [] { ICore::saveSettings(ICore::ModeChanged); });
|
||||||
}
|
}
|
||||||
if (mode == Core::Constants::MODE_WELCOME)
|
if (mode == Core::Constants::MODE_WELCOME)
|
||||||
updateWelcomePage();
|
updateWelcomePage();
|
||||||
|
Reference in New Issue
Block a user