From 2726f7716f0e419ac75cb18e4ab5d7a5298be62e Mon Sep 17 00:00:00 2001 From: Eike Ziller Date: Mon, 22 May 2023 14:56:33 +0200 Subject: [PATCH] Move function to show session manager to SessionManager Change-Id: Ibcaae8c4fb68fe6b43759c11b77bfaab73d41745 Reviewed-by: hjk Reviewed-by: --- .../projectexplorer/projectexplorer.cpp | 35 ++++++------------- src/plugins/projectexplorer/projectexplorer.h | 1 - .../projectexplorer/projectwelcomepage.cpp | 2 +- .../projectexplorer/projectwelcomepage.h | 1 - src/plugins/projectexplorer/session.cpp | 12 +++++++ src/plugins/projectexplorer/session.h | 2 ++ 6 files changed, 25 insertions(+), 28 deletions(-) diff --git a/src/plugins/projectexplorer/projectexplorer.cpp b/src/plugins/projectexplorer/projectexplorer.cpp index d1ad20fe57c..d6379488fa9 100644 --- a/src/plugins/projectexplorer/projectexplorer.cpp +++ b/src/plugins/projectexplorer/projectexplorer.cpp @@ -454,7 +454,6 @@ public: void unloadProjectContextMenu(); void unloadOtherProjectsContextMenu(); void closeAllProjects(); - void showSessionManager(); void updateSessionMenu(); void setSession(QAction *action); @@ -815,9 +814,6 @@ bool ProjectExplorerPlugin::initialize(const QStringList &arguments, QString *er IWizardFactory::registerFeatureProvider(new KitFeatureProvider); IWizardFactory::registerFactoryCreator([] { return new SimpleProjectWizard; }); - connect(&dd->m_welcomePage, &ProjectWelcomePage::manageSessions, - dd, &ProjectExplorerPluginPrivate::showSessionManager); - ProjectManager *sessionManager = &dd->m_sessionManager; connect(sessionManager, &ProjectManager::projectAdded, this, &ProjectExplorerPlugin::fileListChanged); @@ -839,6 +835,12 @@ bool ProjectExplorerPlugin::initialize(const QStringList &arguments, QString *er dd, &ProjectExplorerPluginPrivate::updateWelcomePage); connect(SessionManager::instance(), &SessionManager::sessionLoaded, dd, &ProjectExplorerPluginPrivate::loadSesssionTasks); + connect(SessionManager::instance(), &SessionManager::sessionCreated, + dd, &ProjectExplorerPluginPrivate::updateWelcomePage); + connect(SessionManager::instance(), &SessionManager::sessionRenamed, + dd, &ProjectExplorerPluginPrivate::updateWelcomePage); + connect(SessionManager::instance(), &SessionManager::sessionRemoved, + dd, &ProjectExplorerPluginPrivate::updateWelcomePage); ProjectTree *tree = &dd->m_projectTree; connect(tree, &ProjectTree::currentProjectChanged, dd, [] { @@ -1728,8 +1730,10 @@ bool ProjectExplorerPlugin::initialize(const QStringList &arguments, QString *er connect(buildManager, &BuildManager::buildQueueFinished, dd, &ProjectExplorerPluginPrivate::buildQueueFinished, Qt::QueuedConnection); - connect(dd->m_sessionManagerAction, &QAction::triggered, - dd, &ProjectExplorerPluginPrivate::showSessionManager); + connect(dd->m_sessionManagerAction, + &QAction::triggered, + SessionManager::instance(), + &SessionManager::showSessionManager); connect(dd->m_newAction, &QAction::triggered, dd, &ProjectExplorerPlugin::openNewProjectDialog); connect(dd->m_loadAction, &QAction::triggered, @@ -2192,11 +2196,6 @@ IPlugin::ShutdownFlag ProjectExplorerPlugin::aboutToShutdown() return AsynchronousShutdown; } -void ProjectExplorerPlugin::showSessionManager() -{ - dd->showSessionManager(); -} - void ProjectExplorerPlugin::openNewProjectDialog() { if (!ICore::isNewItemDialogRunning()) { @@ -2208,20 +2207,6 @@ void ProjectExplorerPlugin::openNewProjectDialog() } } -void ProjectExplorerPluginPrivate::showSessionManager() -{ - SessionManager::saveSession(); - SessionDialog sessionDialog(ICore::dialogParent()); - sessionDialog.setAutoLoadSession(sb_d->isAutoRestoreLastSession()); - sessionDialog.exec(); - sb_d->setAutoRestoreLastSession(sessionDialog.autoLoadSession()); - - updateActions(); - - if (ModeManager::currentModeId() == Core::Constants::MODE_WELCOME) - updateWelcomePage(); -} - void ProjectExplorerPluginPrivate::setStartupProject(Project *project) { if (!project) diff --git a/src/plugins/projectexplorer/projectexplorer.h b/src/plugins/projectexplorer/projectexplorer.h index e5f91bd334d..0b87f53310b 100644 --- a/src/plugins/projectexplorer/projectexplorer.h +++ b/src/plugins/projectexplorer/projectexplorer.h @@ -155,7 +155,6 @@ public: static QThreadPool *sharedThreadPool(); static Internal::MiniProjectTargetSelector *targetSelector(); - static void showSessionManager(); static void openNewProjectDialog(); static void openOpenProjectDialog(); diff --git a/src/plugins/projectexplorer/projectwelcomepage.cpp b/src/plugins/projectexplorer/projectwelcomepage.cpp index 5b392ea7a15..d3f5733461b 100644 --- a/src/plugins/projectexplorer/projectwelcomepage.cpp +++ b/src/plugins/projectexplorer/projectwelcomepage.cpp @@ -580,7 +580,7 @@ public: auto manageSessionsButton = new WelcomePageButton(this); manageSessionsButton->setText(Tr::tr("Manage...")); manageSessionsButton->setWithAccentColor(true); - manageSessionsButton->setOnClicked([] { ProjectExplorerPlugin::showSessionManager(); }); + manageSessionsButton->setOnClicked([] { SessionManager::showSessionManager(); }); auto sessionsLabel = new QLabel(this); sessionsLabel->setFont(brandFont()); diff --git a/src/plugins/projectexplorer/projectwelcomepage.h b/src/plugins/projectexplorer/projectwelcomepage.h index a9c81459635..2585ef09d54 100644 --- a/src/plugins/projectexplorer/projectwelcomepage.h +++ b/src/plugins/projectexplorer/projectwelcomepage.h @@ -56,7 +56,6 @@ public slots: signals: void requestProject(const Utils::FilePath &project); - void manageSessions(); private: void openSessionAt(int index); diff --git a/src/plugins/projectexplorer/session.cpp b/src/plugins/projectexplorer/session.cpp index ccedbb885fe..9933ff070fa 100644 --- a/src/plugins/projectexplorer/session.cpp +++ b/src/plugins/projectexplorer/session.cpp @@ -4,6 +4,7 @@ #include "session.h" #include "session_p.h" +#include "sessiondialog.h" #include "projectexplorer.h" #include "projectexplorertr.h" @@ -204,6 +205,7 @@ bool SessionManager::createSession(const QString &session) Q_ASSERT(sb_d->m_sessions.size() > 0); sb_d->m_sessions.insert(1, session); sb_d->m_lastActiveTimes.insert(session, QDateTime::currentDateTime()); + emit instance()->sessionCreated(session); return true; } @@ -217,6 +219,14 @@ bool SessionManager::renameSession(const QString &original, const QString &newNa return deleteSession(original); } +void SessionManager::showSessionManager() +{ + saveSession(); + Internal::SessionDialog sessionDialog(ICore::dialogParent()); + sessionDialog.setAutoLoadSession(sb_d->isAutoRestoreLastSession()); + sessionDialog.exec(); + sb_d->setAutoRestoreLastSession(sessionDialog.autoLoadSession()); +} /*! \brief Shows a dialog asking the user to confirm deleting the session \p session @@ -265,6 +275,8 @@ bool SessionManager::cloneSession(const QString &original, const QString &clone) if (!sessionFile.exists() || sessionFile.copyFile(sessionNameToFileName(clone))) { sb_d->m_sessions.insert(1, clone); sb_d->m_sessionDateTimes.insert(clone, sessionNameToFileName(clone).lastModified()); + emit instance()->sessionCreated(clone); + return true; } return false; diff --git a/src/plugins/projectexplorer/session.h b/src/plugins/projectexplorer/session.h index 8f2da70bd24..a19e74a6711 100644 --- a/src/plugins/projectexplorer/session.h +++ b/src/plugins/projectexplorer/session.h @@ -40,6 +40,7 @@ public: static bool cloneSession(const QString &original, const QString &clone); static bool renameSession(const QString &original, const QString &newName); + static void showSessionManager(); static Utils::FilePath sessionNameToFileName(const QString &session); @@ -75,6 +76,7 @@ signals: void sessionLoaded(QString sessionName); void aboutToSaveSession(); + void sessionCreated(const QString &name); void sessionRenamed(const QString &oldName, const QString &newName); void sessionRemoved(const QString &name);