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

View File

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

View File

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

View File

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

View File

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