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 <christian.kandeler@qt.io>
This commit is contained in:
Eike Ziller
2020-01-07 12:34:31 +01:00
parent c832f61e36
commit 6d15080b1e
4 changed files with 22 additions and 10 deletions

View File

@@ -2031,8 +2031,12 @@ void ProjectExplorerPluginPrivate::savePersistentSettings()
} }
QSettings *s = ICore::settings(); QSettings *s = ICore::settings();
if (!SessionManager::isDefaultVirgin()) if (SessionManager::isDefaultVirgin()) {
s->setValue(QLatin1String("ProjectExplorer/StartupSession"), SessionManager::activeSession()); 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")); s->remove(QLatin1String("ProjectExplorer/RecentProjects/Files"));
QStringList fileNames; QStringList fileNames;
@@ -2217,10 +2221,10 @@ void ProjectExplorerPluginPrivate::currentModeChanged(Id mode, Id oldMode)
void ProjectExplorerPluginPrivate::determineSessionToRestoreAtStartup() void ProjectExplorerPluginPrivate::determineSessionToRestoreAtStartup()
{ {
// Process command line arguments first: // Process command line arguments first:
if (m_instance->pluginSpec()->arguments().contains(QLatin1String("-lastsession"))) const bool lastSessionArg = m_instance->pluginSpec()->arguments().contains("-lastsession");
m_sessionToRestoreAtStartup = SessionManager::lastSession(); m_sessionToRestoreAtStartup = lastSessionArg ? SessionManager::startupSession() : QString();
QStringList arguments = ExtensionSystem::PluginManager::arguments(); QStringList arguments = ExtensionSystem::PluginManager::arguments();
if (m_sessionToRestoreAtStartup.isNull()) { if (!lastSessionArg) {
QStringList sessions = SessionManager::sessions(); QStringList sessions = SessionManager::sessions();
// We have command line arguments, try to find a session in them // We have command line arguments, try to find a session in them
// Default to no session loading // Default to no session loading
@@ -2233,11 +2237,10 @@ void ProjectExplorerPluginPrivate::determineSessionToRestoreAtStartup()
} }
} }
// Handle settings only after command line arguments: // Handle settings only after command line arguments:
if (m_sessionToRestoreAtStartup.isNull() if (m_sessionToRestoreAtStartup.isEmpty() && m_projectExplorerSettings.autorestoreLastSession)
&& m_projectExplorerSettings.autorestoreLastSession) m_sessionToRestoreAtStartup = SessionManager::startupSession();
m_sessionToRestoreAtStartup = SessionManager::lastSession();
if (!m_sessionToRestoreAtStartup.isNull()) if (!m_sessionToRestoreAtStartup.isEmpty())
ModeManager::activateMode(Core::Constants::MODE_EDIT); ModeManager::activateMode(Core::Constants::MODE_EDIT);
} }

View File

@@ -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_PY[]=":/projectexplorer/images/fileoverlay_py.png";
const char FILEOVERLAY_UNKNOWN[]=":/projectexplorer/images/fileoverlay_unknown.png"; const char FILEOVERLAY_UNKNOWN[]=":/projectexplorer/images/fileoverlay_unknown.png";
// Settings
const char ADD_FILES_DIALOG_FILTER_HISTORY_KEY[] = "ProjectExplorer.AddFilesFilterKey"; const char ADD_FILES_DIALOG_FILTER_HISTORY_KEY[] = "ProjectExplorer.AddFilesFilterKey";
const char PROJECT_ROOT_PATH_KEY[] = "ProjectExplorer.Project.RootPath"; const char PROJECT_ROOT_PATH_KEY[] = "ProjectExplorer.Project.RootPath";
const char STARTUPSESSION_KEY[] = "ProjectExplorer/SessionToRestore";
const char LASTSESSION_KEY[] = "ProjectExplorer/StartupSession";
} // namespace Constants } // namespace Constants
} // namespace ProjectExplorer } // namespace ProjectExplorer

View File

@@ -1137,7 +1137,12 @@ bool SessionManager::loadSession(const QString &session, bool initial)
QString SessionManager::lastSession() 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() void SessionManager::reportProjectLoadingProgress()

View File

@@ -61,6 +61,7 @@ public:
// higher level session management // higher level session management
static QString activeSession(); static QString activeSession();
static QString lastSession(); static QString lastSession();
static QString startupSession();
static QStringList sessions(); static QStringList sessions();
static QDateTime sessionDateTime(const QString &session); static QDateTime sessionDateTime(const QString &session);