From 6d15080b1e434d28668bef368029ebcfc615a06e Mon Sep 17 00:00:00 2001 From: Eike Ziller Date: Tue, 7 Jan 2020 12:34:31 +0100 Subject: [PATCH] Fix semantics of "-lastsession" Opening Qt Creator, closing it again, and then opening Qt Creator with "-lastsession" opened some session - the last session that was opened in Qt Creator at some earlier time. The intention of "-lastsession" was more to re-open Qt Creator in the state it was last closed from, so in this case it makes more sense to not open a session at all. Change-Id: Ia33ac5b79d93c7c97865186c56db2ef0b33b9f7c Reviewed-by: Christian Kandeler --- .../projectexplorer/projectexplorer.cpp | 21 +++++++++++-------- .../projectexplorerconstants.h | 3 +++ src/plugins/projectexplorer/session.cpp | 7 ++++++- src/plugins/projectexplorer/session.h | 1 + 4 files changed, 22 insertions(+), 10 deletions(-) diff --git a/src/plugins/projectexplorer/projectexplorer.cpp b/src/plugins/projectexplorer/projectexplorer.cpp index b94110d871d..08f9a0eb795 100644 --- a/src/plugins/projectexplorer/projectexplorer.cpp +++ b/src/plugins/projectexplorer/projectexplorer.cpp @@ -2031,8 +2031,12 @@ void ProjectExplorerPluginPrivate::savePersistentSettings() } QSettings *s = ICore::settings(); - if (!SessionManager::isDefaultVirgin()) - s->setValue(QLatin1String("ProjectExplorer/StartupSession"), SessionManager::activeSession()); + if (SessionManager::isDefaultVirgin()) { + s->remove(Constants::STARTUPSESSION_KEY); + } else { + s->setValue(Constants::STARTUPSESSION_KEY, SessionManager::activeSession()); + s->setValue(Constants::LASTSESSION_KEY, SessionManager::activeSession()); + } s->remove(QLatin1String("ProjectExplorer/RecentProjects/Files")); QStringList fileNames; @@ -2217,10 +2221,10 @@ void ProjectExplorerPluginPrivate::currentModeChanged(Id mode, Id oldMode) void ProjectExplorerPluginPrivate::determineSessionToRestoreAtStartup() { // Process command line arguments first: - if (m_instance->pluginSpec()->arguments().contains(QLatin1String("-lastsession"))) - m_sessionToRestoreAtStartup = SessionManager::lastSession(); + const bool lastSessionArg = m_instance->pluginSpec()->arguments().contains("-lastsession"); + m_sessionToRestoreAtStartup = lastSessionArg ? SessionManager::startupSession() : QString(); QStringList arguments = ExtensionSystem::PluginManager::arguments(); - if (m_sessionToRestoreAtStartup.isNull()) { + if (!lastSessionArg) { QStringList sessions = SessionManager::sessions(); // We have command line arguments, try to find a session in them // Default to no session loading @@ -2233,11 +2237,10 @@ void ProjectExplorerPluginPrivate::determineSessionToRestoreAtStartup() } } // Handle settings only after command line arguments: - if (m_sessionToRestoreAtStartup.isNull() - && m_projectExplorerSettings.autorestoreLastSession) - m_sessionToRestoreAtStartup = SessionManager::lastSession(); + if (m_sessionToRestoreAtStartup.isEmpty() && m_projectExplorerSettings.autorestoreLastSession) + m_sessionToRestoreAtStartup = SessionManager::startupSession(); - if (!m_sessionToRestoreAtStartup.isNull()) + if (!m_sessionToRestoreAtStartup.isEmpty()) ModeManager::activateMode(Core::Constants::MODE_EDIT); } diff --git a/src/plugins/projectexplorer/projectexplorerconstants.h b/src/plugins/projectexplorer/projectexplorerconstants.h index cc115322829..ddac904c2db 100644 --- a/src/plugins/projectexplorer/projectexplorerconstants.h +++ b/src/plugins/projectexplorer/projectexplorerconstants.h @@ -221,8 +221,11 @@ const char FILEOVERLAY_SCXML[]=":/projectexplorer/images/fileoverlay_scxml.png"; const char FILEOVERLAY_PY[]=":/projectexplorer/images/fileoverlay_py.png"; const char FILEOVERLAY_UNKNOWN[]=":/projectexplorer/images/fileoverlay_unknown.png"; +// Settings const char ADD_FILES_DIALOG_FILTER_HISTORY_KEY[] = "ProjectExplorer.AddFilesFilterKey"; const char PROJECT_ROOT_PATH_KEY[] = "ProjectExplorer.Project.RootPath"; +const char STARTUPSESSION_KEY[] = "ProjectExplorer/SessionToRestore"; +const char LASTSESSION_KEY[] = "ProjectExplorer/StartupSession"; } // namespace Constants } // namespace ProjectExplorer diff --git a/src/plugins/projectexplorer/session.cpp b/src/plugins/projectexplorer/session.cpp index 040ccc6af09..b386a459342 100644 --- a/src/plugins/projectexplorer/session.cpp +++ b/src/plugins/projectexplorer/session.cpp @@ -1137,7 +1137,12 @@ bool SessionManager::loadSession(const QString &session, bool initial) QString SessionManager::lastSession() { - return ICore::settings()->value(QLatin1String("ProjectExplorer/StartupSession")).toString(); + return ICore::settings()->value(Constants::LASTSESSION_KEY).toString(); +} + +QString SessionManager::startupSession() +{ + return ICore::settings()->value(Constants::STARTUPSESSION_KEY).toString(); } void SessionManager::reportProjectLoadingProgress() diff --git a/src/plugins/projectexplorer/session.h b/src/plugins/projectexplorer/session.h index 3bd0b48c54e..290946f9d72 100644 --- a/src/plugins/projectexplorer/session.h +++ b/src/plugins/projectexplorer/session.h @@ -61,6 +61,7 @@ public: // higher level session management static QString activeSession(); static QString lastSession(); + static QString startupSession(); static QStringList sessions(); static QDateTime sessionDateTime(const QString &session);