forked from qt-creator/qt-creator
Core: Rename unusual SessionManager pimpl
Left-over from the PE/Core split. Change-Id: Iea6bffa5487a43eccb04ec677fc558651a8fa997 Reviewed-by: <github-actions-qt-creator@cristianadam.eu> Reviewed-by: Eike Ziller <eike.ziller@qt.io>
This commit is contained in:
@@ -266,7 +266,6 @@ add_qtc_plugin(Core
|
|||||||
rightpane.h
|
rightpane.h
|
||||||
session.cpp
|
session.cpp
|
||||||
session.h
|
session.h
|
||||||
session_p.h
|
|
||||||
sessiondialog.cpp
|
sessiondialog.cpp
|
||||||
sessiondialog.h
|
sessiondialog.h
|
||||||
sessionmodel.cpp
|
sessionmodel.cpp
|
||||||
|
@@ -149,7 +149,6 @@ Project {
|
|||||||
"rightpane.h",
|
"rightpane.h",
|
||||||
"session.cpp",
|
"session.cpp",
|
||||||
"session.h",
|
"session.h",
|
||||||
"session_p.h",
|
|
||||||
"sessiondialog.cpp",
|
"sessiondialog.cpp",
|
||||||
"sessiondialog.h",
|
"sessiondialog.h",
|
||||||
"sessionmodel.cpp",
|
"sessionmodel.cpp",
|
||||||
|
@@ -2,7 +2,6 @@
|
|||||||
// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only WITH Qt-GPL-exception-1.0
|
// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only WITH Qt-GPL-exception-1.0
|
||||||
|
|
||||||
#include "session.h"
|
#include "session.h"
|
||||||
#include "session_p.h"
|
|
||||||
|
|
||||||
#include "sessiondialog.h"
|
#include "sessiondialog.h"
|
||||||
|
|
||||||
@@ -23,12 +22,15 @@
|
|||||||
#include <utils/algorithm.h>
|
#include <utils/algorithm.h>
|
||||||
#include <utils/filepath.h>
|
#include <utils/filepath.h>
|
||||||
#include <utils/macroexpander.h>
|
#include <utils/macroexpander.h>
|
||||||
|
#include <utils/persistentsettings.h>
|
||||||
#include <utils/qtcassert.h>
|
#include <utils/qtcassert.h>
|
||||||
|
#include <utils/store.h>
|
||||||
#include <utils/stringutils.h>
|
#include <utils/stringutils.h>
|
||||||
#include <utils/stylehelper.h>
|
#include <utils/stylehelper.h>
|
||||||
|
|
||||||
#include <QAction>
|
#include <QAction>
|
||||||
#include <QActionGroup>
|
#include <QActionGroup>
|
||||||
|
#include <QFutureInterface>
|
||||||
#include <QDebug>
|
#include <QDebug>
|
||||||
#include <QMenu>
|
#include <QMenu>
|
||||||
#include <QMessageBox>
|
#include <QMessageBox>
|
||||||
@@ -67,15 +69,53 @@ const char M_SESSION[] = "ProjectExplorer.Menu.Session";
|
|||||||
This could be improved.
|
This could be improved.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
class SessionManagerPrivate
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
void restoreStartupSession();
|
||||||
|
|
||||||
|
void restoreValues(const PersistentSettingsReader &reader);
|
||||||
|
void restoreSessionValues(const PersistentSettingsReader &reader);
|
||||||
|
void restoreEditors();
|
||||||
|
|
||||||
|
void saveSettings();
|
||||||
|
void restoreSettings();
|
||||||
|
bool isAutoRestoreLastSession();
|
||||||
|
void setAutoRestoreLastSession(bool restore);
|
||||||
|
|
||||||
|
void updateSessionMenu();
|
||||||
|
|
||||||
|
static QString windowTitleAddition(const FilePath &filePath);
|
||||||
|
static QString sessionTitle(const FilePath &filePath);
|
||||||
|
|
||||||
|
QString m_sessionName = "default";
|
||||||
|
bool m_isStartupSessionRestored = false;
|
||||||
|
bool m_isAutoRestoreLastSession = false;
|
||||||
|
bool m_virginSession = true;
|
||||||
|
bool m_loadingSession = false;
|
||||||
|
|
||||||
|
mutable QStringList m_sessions;
|
||||||
|
mutable QHash<QString, QDateTime> m_sessionDateTimes;
|
||||||
|
QHash<QString, QDateTime> m_lastActiveTimes;
|
||||||
|
|
||||||
|
QMap<Utils::Key, QVariant> m_values;
|
||||||
|
QMap<Utils::Key, QVariant> m_sessionValues;
|
||||||
|
QFutureInterface<void> m_future;
|
||||||
|
PersistentSettingsWriter *m_writer = nullptr;
|
||||||
|
|
||||||
|
QMenu *m_sessionMenu;
|
||||||
|
QAction *m_sessionManagerAction;
|
||||||
|
};
|
||||||
|
|
||||||
static SessionManager *m_instance = nullptr;
|
static SessionManager *m_instance = nullptr;
|
||||||
SessionManagerPrivate *sb_d = nullptr;
|
static SessionManagerPrivate *d = nullptr;
|
||||||
|
|
||||||
SessionManager::SessionManager()
|
SessionManager::SessionManager()
|
||||||
{
|
{
|
||||||
m_instance = this;
|
m_instance = this;
|
||||||
sb_d = new SessionManagerPrivate;
|
d = new SessionManagerPrivate;
|
||||||
|
|
||||||
connect(ICore::instance(), &ICore::coreOpened, this, [] { sb_d->restoreStartupSession(); });
|
connect(ICore::instance(), &ICore::coreOpened, this, [] { d->restoreStartupSession(); });
|
||||||
|
|
||||||
connect(ModeManager::instance(), &ModeManager::currentModeChanged,
|
connect(ModeManager::instance(), &ModeManager::currentModeChanged,
|
||||||
this, &SessionManager::saveActiveMode);
|
this, &SessionManager::saveActiveMode);
|
||||||
@@ -83,7 +123,7 @@ SessionManager::SessionManager()
|
|||||||
connect(ICore::instance(), &ICore::saveSettingsRequested, this, [] {
|
connect(ICore::instance(), &ICore::saveSettingsRequested, this, [] {
|
||||||
if (!SessionManager::isLoadingSession())
|
if (!SessionManager::isLoadingSession())
|
||||||
SessionManager::saveSession();
|
SessionManager::saveSession();
|
||||||
sb_d->saveSettings();
|
d->saveSettings();
|
||||||
});
|
});
|
||||||
|
|
||||||
connect(EditorManager::instance(), &EditorManager::editorOpened,
|
connect(EditorManager::instance(), &EditorManager::editorOpened,
|
||||||
@@ -101,17 +141,17 @@ SessionManager::SessionManager()
|
|||||||
msession->menu()->setTitle(PE::Tr::tr("S&essions"));
|
msession->menu()->setTitle(PE::Tr::tr("S&essions"));
|
||||||
msession->setOnAllDisabledBehavior(ActionContainer::Show);
|
msession->setOnAllDisabledBehavior(ActionContainer::Show);
|
||||||
mfile->addMenu(msession, Core::Constants::G_FILE_SESSION);
|
mfile->addMenu(msession, Core::Constants::G_FILE_SESSION);
|
||||||
sb_d->m_sessionMenu = msession->menu();
|
d->m_sessionMenu = msession->menu();
|
||||||
connect(mfile->menu(), &QMenu::aboutToShow, this, [] { sb_d->updateSessionMenu(); });
|
connect(mfile->menu(), &QMenu::aboutToShow, this, [] { d->updateSessionMenu(); });
|
||||||
|
|
||||||
// session manager action
|
// session manager action
|
||||||
sb_d->m_sessionManagerAction = new QAction(PE::Tr::tr("&Manage..."), this);
|
d->m_sessionManagerAction = new QAction(PE::Tr::tr("&Manage..."), this);
|
||||||
sb_d->m_sessionMenu->addAction(sb_d->m_sessionManagerAction);
|
d->m_sessionMenu->addAction(d->m_sessionManagerAction);
|
||||||
sb_d->m_sessionMenu->addSeparator();
|
d->m_sessionMenu->addSeparator();
|
||||||
Command *cmd = ActionManager::registerAction(sb_d->m_sessionManagerAction,
|
Command *cmd = ActionManager::registerAction(d->m_sessionManagerAction,
|
||||||
"ProjectExplorer.ManageSessions");
|
"ProjectExplorer.ManageSessions");
|
||||||
cmd->setDefaultKeySequence(QKeySequence());
|
cmd->setDefaultKeySequence(QKeySequence());
|
||||||
connect(sb_d->m_sessionManagerAction,
|
connect(d->m_sessionManagerAction,
|
||||||
&QAction::triggered,
|
&QAction::triggered,
|
||||||
SessionManager::instance(),
|
SessionManager::instance(),
|
||||||
&SessionManager::showSessionManager);
|
&SessionManager::showSessionManager);
|
||||||
@@ -127,15 +167,15 @@ SessionManager::SessionManager()
|
|||||||
return SessionManager::activeSession();
|
return SessionManager::activeSession();
|
||||||
});
|
});
|
||||||
|
|
||||||
sb_d->restoreSettings();
|
d->restoreSettings();
|
||||||
}
|
}
|
||||||
|
|
||||||
SessionManager::~SessionManager()
|
SessionManager::~SessionManager()
|
||||||
{
|
{
|
||||||
emit m_instance->aboutToUnloadSession(sb_d->m_sessionName);
|
emit m_instance->aboutToUnloadSession(d->m_sessionName);
|
||||||
delete sb_d->m_writer;
|
delete d->m_writer;
|
||||||
delete sb_d;
|
delete d;
|
||||||
sb_d = nullptr;
|
d = nullptr;
|
||||||
}
|
}
|
||||||
|
|
||||||
SessionManager *SessionManager::instance()
|
SessionManager *SessionManager::instance()
|
||||||
@@ -145,7 +185,7 @@ SessionManager *SessionManager::instance()
|
|||||||
|
|
||||||
bool SessionManager::isDefaultVirgin()
|
bool SessionManager::isDefaultVirgin()
|
||||||
{
|
{
|
||||||
return isDefaultSession(sb_d->m_sessionName) && sb_d->m_virginSession;
|
return isDefaultSession(d->m_sessionName) && d->m_virginSession;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool SessionManager::isDefaultSession(const QString &session)
|
bool SessionManager::isDefaultSession(const QString &session)
|
||||||
@@ -161,7 +201,7 @@ void SessionManager::saveActiveMode(Id mode)
|
|||||||
|
|
||||||
bool SessionManager::isLoadingSession()
|
bool SessionManager::isLoadingSession()
|
||||||
{
|
{
|
||||||
return sb_d->m_loadingSession;
|
return d->m_loadingSession;
|
||||||
}
|
}
|
||||||
|
|
||||||
/*!
|
/*!
|
||||||
@@ -171,63 +211,63 @@ bool SessionManager::isLoadingSession()
|
|||||||
|
|
||||||
void SessionManager::setValue(const Key &name, const QVariant &value)
|
void SessionManager::setValue(const Key &name, const QVariant &value)
|
||||||
{
|
{
|
||||||
if (sb_d->m_values.value(name) == value)
|
if (d->m_values.value(name) == value)
|
||||||
return;
|
return;
|
||||||
sb_d->m_values.insert(name, value);
|
d->m_values.insert(name, value);
|
||||||
}
|
}
|
||||||
|
|
||||||
QVariant SessionManager::value(const Key &name)
|
QVariant SessionManager::value(const Key &name)
|
||||||
{
|
{
|
||||||
auto it = sb_d->m_values.constFind(name);
|
auto it = d->m_values.constFind(name);
|
||||||
return (it == sb_d->m_values.constEnd()) ? QVariant() : *it;
|
return (it == d->m_values.constEnd()) ? QVariant() : *it;
|
||||||
}
|
}
|
||||||
|
|
||||||
void SessionManager::setSessionValue(const Key &name, const QVariant &value)
|
void SessionManager::setSessionValue(const Key &name, const QVariant &value)
|
||||||
{
|
{
|
||||||
sb_d->m_sessionValues.insert(name, value);
|
d->m_sessionValues.insert(name, value);
|
||||||
}
|
}
|
||||||
|
|
||||||
QVariant SessionManager::sessionValue(const Key &name, const QVariant &defaultValue)
|
QVariant SessionManager::sessionValue(const Key &name, const QVariant &defaultValue)
|
||||||
{
|
{
|
||||||
auto it = sb_d->m_sessionValues.constFind(name);
|
auto it = d->m_sessionValues.constFind(name);
|
||||||
return (it == sb_d->m_sessionValues.constEnd()) ? defaultValue : *it;
|
return (it == d->m_sessionValues.constEnd()) ? defaultValue : *it;
|
||||||
}
|
}
|
||||||
|
|
||||||
QString SessionManager::activeSession()
|
QString SessionManager::activeSession()
|
||||||
{
|
{
|
||||||
return sb_d->m_sessionName;
|
return d->m_sessionName;
|
||||||
}
|
}
|
||||||
|
|
||||||
QStringList SessionManager::sessions()
|
QStringList SessionManager::sessions()
|
||||||
{
|
{
|
||||||
if (sb_d->m_sessions.isEmpty()) {
|
if (d->m_sessions.isEmpty()) {
|
||||||
// We are not initialized yet, so do that now
|
// We are not initialized yet, so do that now
|
||||||
const FilePaths sessionFiles =
|
const FilePaths sessionFiles =
|
||||||
ICore::userResourcePath().dirEntries({{"*qws"}}, QDir::Time | QDir::Reversed);
|
ICore::userResourcePath().dirEntries({{"*qws"}}, QDir::Time | QDir::Reversed);
|
||||||
const QVariantMap lastActiveTimes = ICore::settings()->value(LAST_ACTIVE_TIMES_KEY).toMap();
|
const QVariantMap lastActiveTimes = ICore::settings()->value(LAST_ACTIVE_TIMES_KEY).toMap();
|
||||||
for (const FilePath &file : sessionFiles) {
|
for (const FilePath &file : sessionFiles) {
|
||||||
const QString &name = file.completeBaseName();
|
const QString &name = file.completeBaseName();
|
||||||
sb_d->m_sessionDateTimes.insert(name, file.lastModified());
|
d->m_sessionDateTimes.insert(name, file.lastModified());
|
||||||
const auto lastActiveTime = lastActiveTimes.find(name);
|
const auto lastActiveTime = lastActiveTimes.find(name);
|
||||||
sb_d->m_lastActiveTimes.insert(name, lastActiveTime != lastActiveTimes.end()
|
d->m_lastActiveTimes.insert(name, lastActiveTime != lastActiveTimes.end()
|
||||||
? lastActiveTime->toDateTime()
|
? lastActiveTime->toDateTime()
|
||||||
: file.lastModified());
|
: file.lastModified());
|
||||||
if (name != QLatin1String(DEFAULT_SESSION))
|
if (name != QLatin1String(DEFAULT_SESSION))
|
||||||
sb_d->m_sessions << name;
|
d->m_sessions << name;
|
||||||
}
|
}
|
||||||
sb_d->m_sessions.prepend(QLatin1String(DEFAULT_SESSION));
|
d->m_sessions.prepend(QLatin1String(DEFAULT_SESSION));
|
||||||
}
|
}
|
||||||
return sb_d->m_sessions;
|
return d->m_sessions;
|
||||||
}
|
}
|
||||||
|
|
||||||
QDateTime SessionManager::sessionDateTime(const QString &session)
|
QDateTime SessionManager::sessionDateTime(const QString &session)
|
||||||
{
|
{
|
||||||
return sb_d->m_sessionDateTimes.value(session);
|
return d->m_sessionDateTimes.value(session);
|
||||||
}
|
}
|
||||||
|
|
||||||
QDateTime SessionManager::lastActiveTime(const QString &session)
|
QDateTime SessionManager::lastActiveTime(const QString &session)
|
||||||
{
|
{
|
||||||
return sb_d->m_lastActiveTimes.value(session);
|
return d->m_lastActiveTimes.value(session);
|
||||||
}
|
}
|
||||||
|
|
||||||
FilePath SessionManager::sessionNameToFileName(const QString &session)
|
FilePath SessionManager::sessionNameToFileName(const QString &session)
|
||||||
@@ -246,9 +286,9 @@ bool SessionManager::createSession(const QString &session)
|
|||||||
{
|
{
|
||||||
if (sessions().contains(session))
|
if (sessions().contains(session))
|
||||||
return false;
|
return false;
|
||||||
Q_ASSERT(sb_d->m_sessions.size() > 0);
|
Q_ASSERT(d->m_sessions.size() > 0);
|
||||||
sb_d->m_sessions.insert(1, session);
|
d->m_sessions.insert(1, session);
|
||||||
sb_d->m_lastActiveTimes.insert(session, QDateTime::currentDateTime());
|
d->m_lastActiveTimes.insert(session, QDateTime::currentDateTime());
|
||||||
emit instance()->sessionCreated(session);
|
emit instance()->sessionCreated(session);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
@@ -267,9 +307,9 @@ void SessionManager::showSessionManager()
|
|||||||
{
|
{
|
||||||
saveSession();
|
saveSession();
|
||||||
Internal::SessionDialog sessionDialog(ICore::dialogParent());
|
Internal::SessionDialog sessionDialog(ICore::dialogParent());
|
||||||
sessionDialog.setAutoLoadSession(sb_d->isAutoRestoreLastSession());
|
sessionDialog.setAutoLoadSession(d->isAutoRestoreLastSession());
|
||||||
sessionDialog.exec();
|
sessionDialog.exec();
|
||||||
sb_d->setAutoRestoreLastSession(sessionDialog.autoLoadSession());
|
d->setAutoRestoreLastSession(sessionDialog.autoLoadSession());
|
||||||
}
|
}
|
||||||
|
|
||||||
/*!
|
/*!
|
||||||
@@ -299,10 +339,10 @@ bool SessionManager::confirmSessionDelete(const QStringList &sessions)
|
|||||||
*/
|
*/
|
||||||
bool SessionManager::deleteSession(const QString &session)
|
bool SessionManager::deleteSession(const QString &session)
|
||||||
{
|
{
|
||||||
if (!sb_d->m_sessions.contains(session))
|
if (!d->m_sessions.contains(session))
|
||||||
return false;
|
return false;
|
||||||
sb_d->m_sessions.removeOne(session);
|
d->m_sessions.removeOne(session);
|
||||||
sb_d->m_lastActiveTimes.remove(session);
|
d->m_lastActiveTimes.remove(session);
|
||||||
emit instance()->sessionRemoved(session);
|
emit instance()->sessionRemoved(session);
|
||||||
FilePath sessionFile = sessionNameToFileName(session);
|
FilePath sessionFile = sessionNameToFileName(session);
|
||||||
if (sessionFile.exists())
|
if (sessionFile.exists())
|
||||||
@@ -318,14 +358,14 @@ void SessionManager::deleteSessions(const QStringList &sessions)
|
|||||||
|
|
||||||
bool SessionManager::cloneSession(const QString &original, const QString &clone)
|
bool SessionManager::cloneSession(const QString &original, const QString &clone)
|
||||||
{
|
{
|
||||||
if (!sb_d->m_sessions.contains(original))
|
if (!d->m_sessions.contains(original))
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
FilePath sessionFile = sessionNameToFileName(original);
|
FilePath sessionFile = sessionNameToFileName(original);
|
||||||
// If the file does not exist, we can still clone
|
// If the file does not exist, we can still clone
|
||||||
if (!sessionFile.exists() || sessionFile.copyFile(sessionNameToFileName(clone))) {
|
if (!sessionFile.exists() || sessionFile.copyFile(sessionNameToFileName(clone))) {
|
||||||
sb_d->m_sessions.insert(1, clone);
|
d->m_sessions.insert(1, clone);
|
||||||
sb_d->m_sessionDateTimes.insert(clone, sessionNameToFileName(clone).lastModified());
|
d->m_sessionDateTimes.insert(clone, sessionNameToFileName(clone).lastModified());
|
||||||
emit instance()->sessionCreated(clone);
|
emit instance()->sessionCreated(clone);
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
@@ -353,7 +393,7 @@ static QString determineSessionToRestoreAtStartup()
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
// Handle settings only after command line arguments:
|
// Handle settings only after command line arguments:
|
||||||
if (sb_d->m_isAutoRestoreLastSession)
|
if (d->m_isAutoRestoreLastSession)
|
||||||
return SessionManager::startupSession();
|
return SessionManager::startupSession();
|
||||||
return {};
|
return {};
|
||||||
}
|
}
|
||||||
@@ -419,7 +459,7 @@ void SessionManagerPrivate::saveSettings()
|
|||||||
{
|
{
|
||||||
QtcSettings *s = ICore::settings();
|
QtcSettings *s = ICore::settings();
|
||||||
QVariantMap times;
|
QVariantMap times;
|
||||||
for (auto it = sb_d->m_lastActiveTimes.cbegin(); it != sb_d->m_lastActiveTimes.cend(); ++it)
|
for (auto it = d->m_lastActiveTimes.cbegin(); it != d->m_lastActiveTimes.cend(); ++it)
|
||||||
times.insert(it.key(), it.value());
|
times.insert(it.key(), it.value());
|
||||||
s->setValue(LAST_ACTIVE_TIMES_KEY, times);
|
s->setValue(LAST_ACTIVE_TIMES_KEY, times);
|
||||||
if (SessionManager::isDefaultVirgin()) {
|
if (SessionManager::isDefaultVirgin()) {
|
||||||
@@ -429,13 +469,13 @@ void SessionManagerPrivate::saveSettings()
|
|||||||
s->setValue(LASTSESSION_KEY, SessionManager::activeSession());
|
s->setValue(LASTSESSION_KEY, SessionManager::activeSession());
|
||||||
}
|
}
|
||||||
s->setValueWithDefault(AUTO_RESTORE_SESSION_SETTINGS_KEY,
|
s->setValueWithDefault(AUTO_RESTORE_SESSION_SETTINGS_KEY,
|
||||||
sb_d->m_isAutoRestoreLastSession,
|
d->m_isAutoRestoreLastSession,
|
||||||
kIsAutoRestoreLastSessionDefault);
|
kIsAutoRestoreLastSessionDefault);
|
||||||
}
|
}
|
||||||
|
|
||||||
void SessionManagerPrivate::restoreSettings()
|
void SessionManagerPrivate::restoreSettings()
|
||||||
{
|
{
|
||||||
sb_d->m_isAutoRestoreLastSession = ICore::settings()
|
d->m_isAutoRestoreLastSession = ICore::settings()
|
||||||
->value(AUTO_RESTORE_SESSION_SETTINGS_KEY,
|
->value(AUTO_RESTORE_SESSION_SETTINGS_KEY,
|
||||||
kIsAutoRestoreLastSessionDefault)
|
kIsAutoRestoreLastSessionDefault)
|
||||||
.toBool();
|
.toBool();
|
||||||
@@ -443,12 +483,12 @@ void SessionManagerPrivate::restoreSettings()
|
|||||||
|
|
||||||
bool SessionManagerPrivate::isAutoRestoreLastSession()
|
bool SessionManagerPrivate::isAutoRestoreLastSession()
|
||||||
{
|
{
|
||||||
return sb_d->m_isAutoRestoreLastSession;
|
return d->m_isAutoRestoreLastSession;
|
||||||
}
|
}
|
||||||
|
|
||||||
void SessionManagerPrivate::setAutoRestoreLastSession(bool restore)
|
void SessionManagerPrivate::setAutoRestoreLastSession(bool restore)
|
||||||
{
|
{
|
||||||
sb_d->m_isAutoRestoreLastSession = restore;
|
d->m_isAutoRestoreLastSession = restore;
|
||||||
}
|
}
|
||||||
|
|
||||||
void SessionManagerPrivate::updateSessionMenu()
|
void SessionManagerPrivate::updateSessionMenu()
|
||||||
@@ -534,18 +574,18 @@ QString SessionManager::startupSession()
|
|||||||
|
|
||||||
void SessionManager::markSessionFileDirty()
|
void SessionManager::markSessionFileDirty()
|
||||||
{
|
{
|
||||||
sb_d->m_virginSession = false;
|
d->m_virginSession = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
void SessionManager::sessionLoadingProgress()
|
void SessionManager::sessionLoadingProgress()
|
||||||
{
|
{
|
||||||
sb_d->m_future.setProgressValue(sb_d->m_future.progressValue() + 1);
|
d->m_future.setProgressValue(d->m_future.progressValue() + 1);
|
||||||
QCoreApplication::processEvents(QEventLoop::ExcludeUserInputEvents);
|
QCoreApplication::processEvents(QEventLoop::ExcludeUserInputEvents);
|
||||||
}
|
}
|
||||||
|
|
||||||
void SessionManager::addSessionLoadingSteps(int steps)
|
void SessionManager::addSessionLoadingSteps(int steps)
|
||||||
{
|
{
|
||||||
sb_d->m_future.setProgressRange(0, sb_d->m_future.progressMaximum() + steps);
|
d->m_future.setProgressRange(0, d->m_future.progressMaximum() + steps);
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
@@ -577,13 +617,13 @@ bool SessionManager::loadSession(const QString &session, bool initial)
|
|||||||
{
|
{
|
||||||
const bool loadImplicitDefault = session.isEmpty();
|
const bool loadImplicitDefault = session.isEmpty();
|
||||||
const bool switchFromImplicitToExplicitDefault = session == DEFAULT_SESSION
|
const bool switchFromImplicitToExplicitDefault = session == DEFAULT_SESSION
|
||||||
&& sb_d->m_sessionName == DEFAULT_SESSION
|
&& d->m_sessionName == DEFAULT_SESSION
|
||||||
&& !initial;
|
&& !initial;
|
||||||
|
|
||||||
// Do nothing if we have that session already loaded,
|
// Do nothing if we have that session already loaded,
|
||||||
// exception if the session is the default virgin session
|
// exception if the session is the default virgin session
|
||||||
// we still want to be able to load the default session
|
// we still want to be able to load the default session
|
||||||
if (session == sb_d->m_sessionName && !SessionManager::isDefaultVirgin())
|
if (session == d->m_sessionName && !SessionManager::isDefaultVirgin())
|
||||||
return true;
|
return true;
|
||||||
|
|
||||||
if (!loadImplicitDefault && !SessionManager::sessions().contains(session))
|
if (!loadImplicitDefault && !SessionManager::sessions().contains(session))
|
||||||
@@ -604,7 +644,7 @@ bool SessionManager::loadSession(const QString &session, bool initial)
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (loadImplicitDefault) {
|
if (loadImplicitDefault) {
|
||||||
sb_d->restoreValues(reader);
|
d->restoreValues(reader);
|
||||||
emit SessionManager::instance()->sessionLoaded(DEFAULT_SESSION);
|
emit SessionManager::instance()->sessionLoaded(DEFAULT_SESSION);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
@@ -613,44 +653,44 @@ bool SessionManager::loadSession(const QString &session, bool initial)
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
sb_d->m_loadingSession = true;
|
d->m_loadingSession = true;
|
||||||
|
|
||||||
// Allow everyone to set something in the session and before saving
|
// Allow everyone to set something in the session and before saving
|
||||||
emit SessionManager::instance()->aboutToUnloadSession(sb_d->m_sessionName);
|
emit SessionManager::instance()->aboutToUnloadSession(d->m_sessionName);
|
||||||
|
|
||||||
if (!saveSession()) {
|
if (!saveSession()) {
|
||||||
sb_d->m_loadingSession = false;
|
d->m_loadingSession = false;
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Clean up
|
// Clean up
|
||||||
if (!EditorManager::closeAllEditors()) {
|
if (!EditorManager::closeAllEditors()) {
|
||||||
sb_d->m_loadingSession = false;
|
d->m_loadingSession = false;
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!switchFromImplicitToExplicitDefault)
|
if (!switchFromImplicitToExplicitDefault)
|
||||||
sb_d->m_values.clear();
|
d->m_values.clear();
|
||||||
sb_d->m_sessionValues.clear();
|
d->m_sessionValues.clear();
|
||||||
|
|
||||||
sb_d->m_sessionName = session;
|
d->m_sessionName = session;
|
||||||
delete sb_d->m_writer;
|
delete d->m_writer;
|
||||||
sb_d->m_writer = nullptr;
|
d->m_writer = nullptr;
|
||||||
EditorManager::updateWindowTitles();
|
EditorManager::updateWindowTitles();
|
||||||
|
|
||||||
sb_d->m_virginSession = false;
|
d->m_virginSession = false;
|
||||||
|
|
||||||
ProgressManager::addTask(sb_d->m_future.future(),
|
ProgressManager::addTask(d->m_future.future(),
|
||||||
PE::Tr::tr("Loading Session"),
|
PE::Tr::tr("Loading Session"),
|
||||||
"ProjectExplorer.SessionFile.Load");
|
"ProjectExplorer.SessionFile.Load");
|
||||||
|
|
||||||
sb_d->m_future.setProgressRange(0, 1 /*initialization*/ + 1 /*editors*/);
|
d->m_future.setProgressRange(0, 1 /*initialization*/ + 1 /*editors*/);
|
||||||
sb_d->m_future.setProgressValue(0);
|
d->m_future.setProgressValue(0);
|
||||||
|
|
||||||
if (fileName.exists()) {
|
if (fileName.exists()) {
|
||||||
if (!switchFromImplicitToExplicitDefault)
|
if (!switchFromImplicitToExplicitDefault)
|
||||||
sb_d->restoreValues(reader);
|
d->restoreValues(reader);
|
||||||
sb_d->restoreSessionValues(reader);
|
d->restoreSessionValues(reader);
|
||||||
}
|
}
|
||||||
|
|
||||||
QColor c = QColor(SessionManager::sessionValue("Color").toString());
|
QColor c = QColor(SessionManager::sessionValue("Color").toString());
|
||||||
@@ -659,19 +699,19 @@ bool SessionManager::loadSession(const QString &session, bool initial)
|
|||||||
|
|
||||||
SessionManager::sessionLoadingProgress();
|
SessionManager::sessionLoadingProgress();
|
||||||
|
|
||||||
sb_d->restoreEditors();
|
d->restoreEditors();
|
||||||
|
|
||||||
// let other code restore the session
|
// let other code restore the session
|
||||||
emit SessionManager::instance()->aboutToLoadSession(session);
|
emit SessionManager::instance()->aboutToLoadSession(session);
|
||||||
|
|
||||||
sb_d->m_future.reportFinished();
|
d->m_future.reportFinished();
|
||||||
sb_d->m_future = QFutureInterface<void>();
|
d->m_future = QFutureInterface<void>();
|
||||||
|
|
||||||
sb_d->m_lastActiveTimes.insert(session, QDateTime::currentDateTime());
|
d->m_lastActiveTimes.insert(session, QDateTime::currentDateTime());
|
||||||
|
|
||||||
emit SessionManager::instance()->sessionLoaded(session);
|
emit SessionManager::instance()->sessionLoaded(session);
|
||||||
|
|
||||||
sb_d->m_loadingSession = false;
|
d->m_loadingSession = false;
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -679,7 +719,7 @@ bool SessionManager::saveSession()
|
|||||||
{
|
{
|
||||||
emit SessionManager::instance()->aboutToSaveSession();
|
emit SessionManager::instance()->aboutToSaveSession();
|
||||||
|
|
||||||
const FilePath filePath = SessionManager::sessionNameToFileName(sb_d->m_sessionName);
|
const FilePath filePath = SessionManager::sessionNameToFileName(d->m_sessionName);
|
||||||
Store data;
|
Store data;
|
||||||
|
|
||||||
// See the explanation at loadSession() for how we handle the implicit default session.
|
// See the explanation at loadSession() for how we handle the implicit default session.
|
||||||
@@ -706,33 +746,33 @@ bool SessionManager::saveSession()
|
|||||||
}
|
}
|
||||||
setSessionValue("EditorSettings", EditorManager::saveState().toBase64());
|
setSessionValue("EditorSettings", EditorManager::saveState().toBase64());
|
||||||
|
|
||||||
const auto end = sb_d->m_sessionValues.constEnd();
|
const auto end = d->m_sessionValues.constEnd();
|
||||||
for (auto it = sb_d->m_sessionValues.constBegin(); it != end; ++it)
|
for (auto it = d->m_sessionValues.constBegin(); it != end; ++it)
|
||||||
data.insert(it.key(), it.value());
|
data.insert(it.key(), it.value());
|
||||||
}
|
}
|
||||||
|
|
||||||
const auto end = sb_d->m_values.constEnd();
|
const auto end = d->m_values.constEnd();
|
||||||
KeyList keys;
|
KeyList keys;
|
||||||
for (auto it = sb_d->m_values.constBegin(); it != end; ++it) {
|
for (auto it = d->m_values.constBegin(); it != end; ++it) {
|
||||||
data.insert("value-" + it.key(), it.value());
|
data.insert("value-" + it.key(), it.value());
|
||||||
keys << it.key();
|
keys << it.key();
|
||||||
}
|
}
|
||||||
data.insert("valueKeys", QVariant::fromValue(keys));
|
data.insert("valueKeys", QVariant::fromValue(keys));
|
||||||
|
|
||||||
if (!sb_d->m_writer || sb_d->m_writer->fileName() != filePath) {
|
if (!d->m_writer || d->m_writer->fileName() != filePath) {
|
||||||
delete sb_d->m_writer;
|
delete d->m_writer;
|
||||||
sb_d->m_writer = new PersistentSettingsWriter(filePath, "QtCreatorSession");
|
d->m_writer = new PersistentSettingsWriter(filePath, "QtCreatorSession");
|
||||||
}
|
}
|
||||||
const bool result = sb_d->m_writer->save(data, ICore::dialogParent());
|
const bool result = d->m_writer->save(data, ICore::dialogParent());
|
||||||
if (result) {
|
if (result) {
|
||||||
if (!SessionManager::isDefaultVirgin())
|
if (!SessionManager::isDefaultVirgin())
|
||||||
sb_d->m_sessionDateTimes.insert(SessionManager::activeSession(),
|
d->m_sessionDateTimes.insert(SessionManager::activeSession(),
|
||||||
QDateTime::currentDateTime());
|
QDateTime::currentDateTime());
|
||||||
} else {
|
} else {
|
||||||
QMessageBox::warning(ICore::dialogParent(),
|
QMessageBox::warning(ICore::dialogParent(),
|
||||||
PE::Tr::tr("Error while saving session"),
|
PE::Tr::tr("Error while saving session"),
|
||||||
PE::Tr::tr("Could not save session to file \"%1\"")
|
PE::Tr::tr("Could not save session to file \"%1\"")
|
||||||
.arg(sb_d->m_writer->fileName().toUserOutput()));
|
.arg(d->m_writer->fileName().toUserOutput()));
|
||||||
}
|
}
|
||||||
|
|
||||||
return result;
|
return result;
|
||||||
@@ -740,7 +780,7 @@ bool SessionManager::saveSession()
|
|||||||
|
|
||||||
bool SessionManager::isStartupSessionRestored()
|
bool SessionManager::isStartupSessionRestored()
|
||||||
{
|
{
|
||||||
return sb_d->m_isStartupSessionRestored;
|
return d->m_isStartupSessionRestored;
|
||||||
}
|
}
|
||||||
|
|
||||||
} // namespace Core
|
} // namespace Core
|
||||||
|
@@ -1,58 +0,0 @@
|
|||||||
// Copyright (C) 2023 The Qt Company Ltd.
|
|
||||||
// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only WITH Qt-GPL-exception-1.0
|
|
||||||
|
|
||||||
#include <utils/persistentsettings.h>
|
|
||||||
#include <utils/store.h>
|
|
||||||
|
|
||||||
#include <QFutureInterface>
|
|
||||||
|
|
||||||
QT_BEGIN_NAMESPACE
|
|
||||||
class QAction;
|
|
||||||
class QMenu;
|
|
||||||
QT_END_NAMESPACE
|
|
||||||
|
|
||||||
using namespace Utils;
|
|
||||||
|
|
||||||
namespace Core {
|
|
||||||
|
|
||||||
class SessionManagerPrivate
|
|
||||||
{
|
|
||||||
public:
|
|
||||||
void restoreStartupSession();
|
|
||||||
|
|
||||||
void restoreValues(const PersistentSettingsReader &reader);
|
|
||||||
void restoreSessionValues(const PersistentSettingsReader &reader);
|
|
||||||
void restoreEditors();
|
|
||||||
|
|
||||||
void saveSettings();
|
|
||||||
void restoreSettings();
|
|
||||||
bool isAutoRestoreLastSession();
|
|
||||||
void setAutoRestoreLastSession(bool restore);
|
|
||||||
|
|
||||||
void updateSessionMenu();
|
|
||||||
|
|
||||||
static QString windowTitleAddition(const FilePath &filePath);
|
|
||||||
static QString sessionTitle(const FilePath &filePath);
|
|
||||||
|
|
||||||
QString m_sessionName = "default";
|
|
||||||
bool m_isStartupSessionRestored = false;
|
|
||||||
bool m_isAutoRestoreLastSession = false;
|
|
||||||
bool m_virginSession = true;
|
|
||||||
bool m_loadingSession = false;
|
|
||||||
|
|
||||||
mutable QStringList m_sessions;
|
|
||||||
mutable QHash<QString, QDateTime> m_sessionDateTimes;
|
|
||||||
QHash<QString, QDateTime> m_lastActiveTimes;
|
|
||||||
|
|
||||||
QMap<Utils::Key, QVariant> m_values;
|
|
||||||
QMap<Utils::Key, QVariant> m_sessionValues;
|
|
||||||
QFutureInterface<void> m_future;
|
|
||||||
PersistentSettingsWriter *m_writer = nullptr;
|
|
||||||
|
|
||||||
QMenu *m_sessionMenu;
|
|
||||||
QAction *m_sessionManagerAction;
|
|
||||||
};
|
|
||||||
|
|
||||||
extern SessionManagerPrivate *sb_d;
|
|
||||||
|
|
||||||
} // namespace Core
|
|
Reference in New Issue
Block a user