Remove usage of SessionManagerPrivate from project explorer

Change-Id: Ia12a9ba2d9e65605715110ea0330d5c1e1cae7c6
Reviewed-by: <github-actions-qt-creator@cristianadam.eu>
Reviewed-by: hjk <hjk@qt.io>
This commit is contained in:
Eike Ziller
2023-05-22 13:45:27 +02:00
parent 2726f7716f
commit 5ac582a9b6
5 changed files with 39 additions and 42 deletions

View File

@@ -69,7 +69,6 @@
#include "sanitizerparser.h" #include "sanitizerparser.h"
#include "selectablefilesmodel.h" #include "selectablefilesmodel.h"
#include "session.h" #include "session.h"
#include "session_p.h"
#include "sessiondialog.h" #include "sessiondialog.h"
#include "showineditortaskhandler.h" #include "showineditortaskhandler.h"
#include "simpleprojectwizard.h" #include "simpleprojectwizard.h"
@@ -1633,10 +1632,6 @@ bool ProjectExplorerPlugin::initialize(const QStringList &arguments, QString *er
connect(ICore::instance(), &ICore::saveSettingsRequested, connect(ICore::instance(), &ICore::saveSettingsRequested,
dd, &ProjectExplorerPluginPrivate::savePersistentSettings); dd, &ProjectExplorerPluginPrivate::savePersistentSettings);
connect(EditorManager::instance(), &EditorManager::autoSaved, this, [] {
if (!PluginManager::isShuttingDown() && !SessionManager::loadingSession())
SessionManager::saveSession();
});
connect(qApp, &QApplication::applicationStateChanged, this, [](Qt::ApplicationState state) { connect(qApp, &QApplication::applicationStateChanged, this, [](Qt::ApplicationState state) {
if (!PluginManager::isShuttingDown() && state == Qt::ApplicationActive) if (!PluginManager::isShuttingDown() && state == Qt::ApplicationActive)
dd->updateWelcomePage(); dd->updateWelcomePage();
@@ -1714,7 +1709,6 @@ bool ProjectExplorerPlugin::initialize(const QStringList &arguments, QString *er
.toBool(); .toBool();
dd->m_buildPropertiesSettings.readSettings(s); dd->m_buildPropertiesSettings.readSettings(s);
sb_d->restoreSettings();
const int customParserCount = s->value(Constants::CUSTOM_PARSER_COUNT_KEY).toInt(); const int customParserCount = s->value(Constants::CUSTOM_PARSER_COUNT_KEY).toInt();
for (int i = 0; i < customParserCount; ++i) { for (int i = 0; i < customParserCount; ++i) {
@@ -2169,7 +2163,7 @@ void ProjectExplorerPlugin::restoreKits()
KitManager::restoreKits(); KitManager::restoreKits();
// restoring startup session is supposed to be done as a result of ICore::coreOpened, // restoring startup session is supposed to be done as a result of ICore::coreOpened,
// and that is supposed to happen after restoring kits: // and that is supposed to happen after restoring kits:
QTC_CHECK(!sb_d->isStartupSessionRestored()); QTC_CHECK(!SessionManager::isStartupSessionRestored());
} }
void ProjectExplorerPluginPrivate::updateRunWithoutDeployMenu() void ProjectExplorerPluginPrivate::updateRunWithoutDeployMenu()
@@ -2304,7 +2298,6 @@ void ProjectExplorerPluginPrivate::savePersistentSettings()
int(defaultSettings.stopBeforeBuild)); int(defaultSettings.stopBeforeBuild));
dd->m_buildPropertiesSettings.writeSettings(s); dd->m_buildPropertiesSettings.writeSettings(s);
sb_d->saveSettings();
s->setValueWithDefault(Constants::CUSTOM_PARSER_COUNT_KEY, int(dd->m_customParsers.count()), 0); s->setValueWithDefault(Constants::CUSTOM_PARSER_COUNT_KEY, int(dd->m_customParsers.count()), 0);
for (int i = 0; i < dd->m_customParsers.count(); ++i) { for (int i = 0; i < dd->m_customParsers.count(); ++i) {

View File

@@ -3,7 +3,6 @@
#include "projectmanager.h" #include "projectmanager.h"
#include "session_p.h"
#include "session.h" #include "session.h"
#include "buildconfiguration.h" #include "buildconfiguration.h"
@@ -280,7 +279,7 @@ void ProjectManager::addProject(Project *pro)
QTC_CHECK(!pro->displayName().isEmpty()); QTC_CHECK(!pro->displayName().isEmpty());
QTC_CHECK(pro->id().isValid()); QTC_CHECK(pro->id().isValid());
sb_d->m_virginSession = false; SessionManager::markSessionFileDirty();
QTC_ASSERT(!d->m_projects.contains(pro), return); QTC_ASSERT(!d->m_projects.contains(pro), return);
d->m_projects.append(pro); d->m_projects.append(pro);
@@ -314,7 +313,7 @@ void ProjectManager::addProject(Project *pro)
void ProjectManager::removeProject(Project *project) void ProjectManager::removeProject(Project *project)
{ {
sb_d->m_virginSession = false; SessionManager::markSessionFileDirty();
QTC_ASSERT(project, return); QTC_ASSERT(project, return);
removeProjects({project}); removeProjects({project});
} }
@@ -396,7 +395,8 @@ void ProjectManagerPrivate::dependencies(const FilePath &proName, FilePaths &res
QString ProjectManagerPrivate::sessionTitle(const FilePath &filePath) QString ProjectManagerPrivate::sessionTitle(const FilePath &filePath)
{ {
if (SessionManager::isDefaultSession(sb_d->m_sessionName)) { const QString sessionName = SessionManager::activeSession();
if (SessionManager::isDefaultSession(sessionName)) {
if (filePath.isEmpty()) { if (filePath.isEmpty()) {
// use single project's name if there is only one loaded. // use single project's name if there is only one loaded.
const QList<Project *> projects = ProjectManager::projects(); const QList<Project *> projects = ProjectManager::projects();
@@ -404,10 +404,7 @@ QString ProjectManagerPrivate::sessionTitle(const FilePath &filePath)
return projects.first()->displayName(); return projects.first()->displayName();
} }
} else { } else {
QString sessionName = sb_d->m_sessionName; return sessionName.isEmpty() ? Tr::tr("Untitled") : sessionName;
if (sessionName.isEmpty())
sessionName = Tr::tr("Untitled");
return sessionName;
} }
return QString(); return QString();
} }

View File

@@ -35,6 +35,7 @@
#include <QTimer> #include <QTimer>
using namespace Core; using namespace Core;
using namespace ExtensionSystem;
using namespace Utils; using namespace Utils;
namespace ProjectExplorer { namespace ProjectExplorer {
@@ -70,24 +71,18 @@ SessionManager::SessionManager()
connect(ModeManager::instance(), &ModeManager::currentModeChanged, connect(ModeManager::instance(), &ModeManager::currentModeChanged,
this, &SessionManager::saveActiveMode); this, &SessionManager::saveActiveMode);
connect(ICore::instance(), &ICore::saveSettingsRequested, this, [] { connect(ICore::instance(), &ICore::saveSettingsRequested, this, [] { sb_d->saveSettings(); });
QtcSettings *s = ICore::settings();
QVariantMap times;
for (auto it = sb_d->m_lastActiveTimes.cbegin(); it != sb_d->m_lastActiveTimes.cend(); ++it)
times.insert(it.key(), it.value());
s->setValue(LAST_ACTIVE_TIMES_KEY, times);
if (SessionManager::isDefaultVirgin()) {
s->remove(STARTUPSESSION_KEY);
} else {
s->setValue(STARTUPSESSION_KEY, SessionManager::activeSession());
s->setValue(LASTSESSION_KEY, SessionManager::activeSession());
}
});
connect(EditorManager::instance(), &EditorManager::editorOpened, connect(EditorManager::instance(), &EditorManager::editorOpened,
this, &SessionManager::markSessionFileDirty); this, &SessionManager::markSessionFileDirty);
connect(EditorManager::instance(), &EditorManager::editorsClosed, connect(EditorManager::instance(), &EditorManager::editorsClosed,
this, &SessionManager::markSessionFileDirty); this, &SessionManager::markSessionFileDirty);
connect(EditorManager::instance(), &EditorManager::autoSaved, this, [] {
if (!PluginManager::isShuttingDown() && !SessionManager::loadingSession())
SessionManager::saveSession();
});
sb_d->restoreSettings();
} }
SessionManager::~SessionManager() SessionManager::~SessionManager()
@@ -286,13 +281,12 @@ static QString determineSessionToRestoreAtStartup()
{ {
// TODO (session) move argument to core // TODO (session) move argument to core
// Process command line arguments first: // Process command line arguments first:
const bool lastSessionArg = ExtensionSystem::PluginManager::specForPlugin( const bool lastSessionArg = PluginManager::specForPlugin(ProjectExplorerPlugin::instance())
ProjectExplorerPlugin::instance())
->arguments() ->arguments()
.contains("-lastsession"); .contains("-lastsession");
if (lastSessionArg && !SessionManager::startupSession().isEmpty()) if (lastSessionArg && !SessionManager::startupSession().isEmpty())
return SessionManager::startupSession(); return SessionManager::startupSession();
const QStringList arguments = ExtensionSystem::PluginManager::arguments(); const QStringList arguments = PluginManager::arguments();
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
@@ -316,7 +310,7 @@ void SessionManagerPrivate::restoreStartupSession()
ModeManager::activateMode(Core::Constants::MODE_EDIT); ModeManager::activateMode(Core::Constants::MODE_EDIT);
// We have command line arguments, try to find a session in them // We have command line arguments, try to find a session in them
QStringList arguments = ExtensionSystem::PluginManager::arguments(); QStringList arguments = PluginManager::arguments();
if (!sessionToRestoreAtStartup.isEmpty() && !arguments.isEmpty()) if (!sessionToRestoreAtStartup.isEmpty() && !arguments.isEmpty())
arguments.removeOne(sessionToRestoreAtStartup); arguments.removeOne(sessionToRestoreAtStartup);
@@ -365,16 +359,22 @@ void SessionManagerPrivate::restoreStartupSession()
}); });
} }
bool SessionManagerPrivate::isStartupSessionRestored()
{
return sb_d->m_isStartupSessionRestored;
}
void SessionManagerPrivate::saveSettings() void SessionManagerPrivate::saveSettings()
{ {
ICore::settings()->setValueWithDefault(AUTO_RESTORE_SESSION_SETTINGS_KEY, QtcSettings *s = ICore::settings();
sb_d->m_isAutoRestoreLastSession, QVariantMap times;
kIsAutoRestoreLastSessionDefault); for (auto it = sb_d->m_lastActiveTimes.cbegin(); it != sb_d->m_lastActiveTimes.cend(); ++it)
times.insert(it.key(), it.value());
s->setValue(LAST_ACTIVE_TIMES_KEY, times);
if (SessionManager::isDefaultVirgin()) {
s->remove(STARTUPSESSION_KEY);
} else {
s->setValue(STARTUPSESSION_KEY, SessionManager::activeSession());
s->setValue(LASTSESSION_KEY, SessionManager::activeSession());
}
s->setValueWithDefault(AUTO_RESTORE_SESSION_SETTINGS_KEY,
sb_d->m_isAutoRestoreLastSession,
kIsAutoRestoreLastSessionDefault);
} }
void SessionManagerPrivate::restoreSettings() void SessionManagerPrivate::restoreSettings()
@@ -645,4 +645,9 @@ bool SessionManager::saveSession()
return result; return result;
} }
bool SessionManager::isStartupSessionRestored()
{
return sb_d->m_isStartupSessionRestored;
}
} // namespace ProjectExplorer } // namespace ProjectExplorer

View File

@@ -80,6 +80,9 @@ signals:
void sessionRenamed(const QString &oldName, const QString &newName); void sessionRenamed(const QString &oldName, const QString &newName);
void sessionRemoved(const QString &name); void sessionRemoved(const QString &name);
public: // internal
static bool isStartupSessionRestored();
private: private:
static void saveActiveMode(Utils::Id mode); static void saveActiveMode(Utils::Id mode);
}; };

View File

@@ -18,7 +18,6 @@ public:
void restoreSessionValues(const PersistentSettingsReader &reader); void restoreSessionValues(const PersistentSettingsReader &reader);
void restoreEditors(); void restoreEditors();
bool isStartupSessionRestored();
void saveSettings(); void saveSettings();
void restoreSettings(); void restoreSettings();
bool isAutoRestoreLastSession(); bool isAutoRestoreLastSession();