forked from qt-creator/qt-creator
Separate session saving from project manager
Move the generic parts to session manager and let the project manager save its parts separately via SessionManager::setSessionValue. Change-Id: Iec2e81ea2488a15efc7333adb2b327761afdf274 Reviewed-by: hjk <hjk@qt.io> Reviewed-by: Christian Kandeler <christian.kandeler@qt.io> Reviewed-by: Qt CI Bot <qt_ci_bot@qt-project.org>
This commit is contained in:
@@ -1633,7 +1633,7 @@ bool ProjectExplorerPlugin::initialize(const QStringList &arguments, QString *er
|
||||
dd, &ProjectExplorerPluginPrivate::savePersistentSettings);
|
||||
connect(EditorManager::instance(), &EditorManager::autoSaved, this, [] {
|
||||
if (!dd->m_shuttingDown && !SessionManager::loadingSession())
|
||||
ProjectManager::save();
|
||||
SessionManager::saveSession();
|
||||
});
|
||||
connect(qApp, &QApplication::applicationStateChanged, this, [](Qt::ApplicationState state) {
|
||||
if (!dd->m_shuttingDown && state == Qt::ApplicationActive)
|
||||
@@ -2212,7 +2212,7 @@ void ProjectExplorerPlugin::openNewProjectDialog()
|
||||
|
||||
void ProjectExplorerPluginPrivate::showSessionManager()
|
||||
{
|
||||
ProjectManager::save();
|
||||
SessionManager::saveSession();
|
||||
SessionDialog sessionDialog(ICore::dialogParent());
|
||||
sessionDialog.setAutoLoadSession(sb_d->isAutoRestoreLastSession());
|
||||
sessionDialog.exec();
|
||||
@@ -2258,7 +2258,7 @@ void ProjectExplorerPluginPrivate::savePersistentSettings()
|
||||
for (Project *pro : ProjectManager::projects())
|
||||
pro->saveSettings();
|
||||
|
||||
ProjectManager::save();
|
||||
SessionManager::saveSession();
|
||||
}
|
||||
|
||||
QtcSettings *s = ICore::settings();
|
||||
|
||||
@@ -53,6 +53,7 @@ class ProjectManagerPrivate
|
||||
{
|
||||
public:
|
||||
void loadSession();
|
||||
void saveSession();
|
||||
void restoreDependencies();
|
||||
void restoreStartupProject();
|
||||
void restoreProjects(const FilePaths &fileList);
|
||||
@@ -109,6 +110,9 @@ ProjectManager::ProjectManager()
|
||||
connect(SessionManager::instance(), &SessionManager::aboutToLoadSession, this, [] {
|
||||
d->loadSession();
|
||||
});
|
||||
connect(SessionManager::instance(), &SessionManager::aboutToSaveSession, this, [] {
|
||||
d->saveSession();
|
||||
});
|
||||
}
|
||||
|
||||
ProjectManager::~ProjectManager()
|
||||
@@ -315,53 +319,29 @@ void ProjectManager::removeProject(Project *project)
|
||||
removeProjects({project});
|
||||
}
|
||||
|
||||
bool ProjectManager::save()
|
||||
void ProjectManagerPrivate::saveSession()
|
||||
{
|
||||
emit SessionManager::instance()->aboutToSaveSession();
|
||||
|
||||
const FilePath filePath = SessionManager::sessionNameToFileName(sb_d->m_sessionName);
|
||||
QVariantMap data;
|
||||
|
||||
// See the explanation at loadSession() for how we handle the implicit default session.
|
||||
if (SessionManager::isDefaultVirgin()) {
|
||||
if (filePath.exists()) {
|
||||
PersistentSettingsReader reader;
|
||||
if (!reader.load(filePath)) {
|
||||
QMessageBox::warning(ICore::dialogParent(), Tr::tr("Error while saving session"),
|
||||
Tr::tr("Could not save session %1").arg(filePath.toUserOutput()));
|
||||
return false;
|
||||
}
|
||||
data = reader.restoreValues();
|
||||
}
|
||||
} else {
|
||||
// save the startup project
|
||||
if (d->m_startupProject)
|
||||
data.insert("StartupProject", d->m_startupProject->projectFilePath().toSettings());
|
||||
SessionManager::setSessionValue("StartupProject",
|
||||
m_startupProject->projectFilePath().toSettings());
|
||||
|
||||
const QColor c = StyleHelper::requestedBaseColor();
|
||||
if (c.isValid()) {
|
||||
QString tmp = QString::fromLatin1("#%1%2%3")
|
||||
.arg(c.red(), 2, 16, QLatin1Char('0'))
|
||||
.arg(c.green(), 2, 16, QLatin1Char('0'))
|
||||
.arg(c.blue(), 2, 16, QLatin1Char('0'));
|
||||
data.insert(QLatin1String("Color"), tmp);
|
||||
}
|
||||
|
||||
FilePaths projectFiles = Utils::transform(projects(), &Project::projectFilePath);
|
||||
FilePaths projectFiles = Utils::transform(m_projects, &Project::projectFilePath);
|
||||
// Restore information on projects that failed to load:
|
||||
// don't read projects to the list, which the user loaded
|
||||
for (const FilePath &failed : std::as_const(d->m_failedProjects)) {
|
||||
for (const FilePath &failed : std::as_const(m_failedProjects)) {
|
||||
if (!projectFiles.contains(failed))
|
||||
projectFiles << failed;
|
||||
}
|
||||
|
||||
data.insert("ProjectList", Utils::transform<QStringList>(projectFiles,
|
||||
SessionManager::setSessionValue("ProjectList",
|
||||
Utils::transform<QStringList>(projectFiles,
|
||||
&FilePath::toString));
|
||||
data.insert("CascadeSetActive", d->m_casadeSetActive);
|
||||
SessionManager::setSessionValue("CascadeSetActive", m_casadeSetActive);
|
||||
|
||||
QVariantMap depMap;
|
||||
auto i = d->m_depMap.constBegin();
|
||||
while (i != d->m_depMap.constEnd()) {
|
||||
auto i = m_depMap.constBegin();
|
||||
while (i != m_depMap.constEnd()) {
|
||||
QString key = i.key().toString();
|
||||
QStringList values;
|
||||
const FilePaths valueList = i.value();
|
||||
@@ -370,32 +350,7 @@ bool ProjectManager::save()
|
||||
depMap.insert(key, values);
|
||||
++i;
|
||||
}
|
||||
data.insert(QLatin1String("ProjectDependencies"), QVariant(depMap));
|
||||
data.insert(QLatin1String("EditorSettings"), EditorManager::saveState().toBase64());
|
||||
}
|
||||
|
||||
const auto end = sb_d->m_values.constEnd();
|
||||
QStringList keys;
|
||||
for (auto it = sb_d->m_values.constBegin(); it != end; ++it) {
|
||||
data.insert(QLatin1String("value-") + it.key(), it.value());
|
||||
keys << it.key();
|
||||
}
|
||||
data.insert(QLatin1String("valueKeys"), keys);
|
||||
|
||||
if (!sb_d->m_writer || sb_d->m_writer->fileName() != filePath) {
|
||||
delete sb_d->m_writer;
|
||||
sb_d->m_writer = new PersistentSettingsWriter(filePath, "QtCreatorSession");
|
||||
}
|
||||
const bool result = sb_d->m_writer->save(data, ICore::dialogParent());
|
||||
if (result) {
|
||||
if (!SessionManager::isDefaultVirgin())
|
||||
sb_d->m_sessionDateTimes.insert(SessionManager::activeSession(), QDateTime::currentDateTime());
|
||||
} else {
|
||||
QMessageBox::warning(ICore::dialogParent(), Tr::tr("Error while saving session"),
|
||||
Tr::tr("Could not save session to file %1").arg(sb_d->m_writer->fileName().toUserOutput()));
|
||||
}
|
||||
|
||||
return result;
|
||||
SessionManager::setSessionValue(QLatin1String("ProjectDependencies"), QVariant(depMap));
|
||||
}
|
||||
|
||||
/*!
|
||||
|
||||
@@ -47,7 +47,6 @@ public:
|
||||
});
|
||||
}
|
||||
|
||||
static bool save();
|
||||
static void closeAllProjects();
|
||||
|
||||
static void addProject(Project *project);
|
||||
|
||||
@@ -7,7 +7,6 @@
|
||||
|
||||
#include "projectexplorer.h"
|
||||
#include "projectexplorertr.h"
|
||||
#include "projectmanager.h"
|
||||
|
||||
#include <extensionsystem/pluginmanager.h>
|
||||
#include <extensionsystem/pluginspec.h>
|
||||
@@ -514,7 +513,7 @@ bool SessionManager::loadSession(const QString &session, bool initial)
|
||||
// Allow everyone to set something in the session and before saving
|
||||
emit SessionManager::instance()->aboutToUnloadSession(sb_d->m_sessionName);
|
||||
|
||||
if (!ProjectManager::save()) {
|
||||
if (!saveSession()) {
|
||||
sb_d->m_loadingSession = false;
|
||||
return false;
|
||||
}
|
||||
@@ -571,4 +570,67 @@ bool SessionManager::loadSession(const QString &session, bool initial)
|
||||
return true;
|
||||
}
|
||||
|
||||
bool SessionManager::saveSession()
|
||||
{
|
||||
emit SessionManager::instance()->aboutToSaveSession();
|
||||
|
||||
const FilePath filePath = SessionManager::sessionNameToFileName(sb_d->m_sessionName);
|
||||
QVariantMap data;
|
||||
|
||||
// See the explanation at loadSession() for how we handle the implicit default session.
|
||||
if (SessionManager::isDefaultVirgin()) {
|
||||
if (filePath.exists()) {
|
||||
PersistentSettingsReader reader;
|
||||
if (!reader.load(filePath)) {
|
||||
QMessageBox::warning(ICore::dialogParent(),
|
||||
Tr::tr("Error while saving session"),
|
||||
Tr::tr("Could not save session %1")
|
||||
.arg(filePath.toUserOutput()));
|
||||
return false;
|
||||
}
|
||||
data = reader.restoreValues();
|
||||
}
|
||||
} else {
|
||||
const QColor c = StyleHelper::requestedBaseColor();
|
||||
if (c.isValid()) {
|
||||
QString tmp = QString::fromLatin1("#%1%2%3")
|
||||
.arg(c.red(), 2, 16, QLatin1Char('0'))
|
||||
.arg(c.green(), 2, 16, QLatin1Char('0'))
|
||||
.arg(c.blue(), 2, 16, QLatin1Char('0'));
|
||||
setSessionValue("Color", tmp);
|
||||
}
|
||||
setSessionValue("EditorSettings", EditorManager::saveState().toBase64());
|
||||
|
||||
const auto end = sb_d->m_sessionValues.constEnd();
|
||||
for (auto it = sb_d->m_sessionValues.constBegin(); it != end; ++it)
|
||||
data.insert(it.key(), it.value());
|
||||
}
|
||||
|
||||
const auto end = sb_d->m_values.constEnd();
|
||||
QStringList keys;
|
||||
for (auto it = sb_d->m_values.constBegin(); it != end; ++it) {
|
||||
data.insert("value-" + it.key(), it.value());
|
||||
keys << it.key();
|
||||
}
|
||||
data.insert("valueKeys", keys);
|
||||
|
||||
if (!sb_d->m_writer || sb_d->m_writer->fileName() != filePath) {
|
||||
delete sb_d->m_writer;
|
||||
sb_d->m_writer = new PersistentSettingsWriter(filePath, "QtCreatorSession");
|
||||
}
|
||||
const bool result = sb_d->m_writer->save(data, ICore::dialogParent());
|
||||
if (result) {
|
||||
if (!SessionManager::isDefaultVirgin())
|
||||
sb_d->m_sessionDateTimes.insert(SessionManager::activeSession(),
|
||||
QDateTime::currentDateTime());
|
||||
} else {
|
||||
QMessageBox::warning(ICore::dialogParent(),
|
||||
Tr::tr("Error while saving session"),
|
||||
Tr::tr("Could not save session to file %1")
|
||||
.arg(sb_d->m_writer->fileName().toUserOutput()));
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
} // namespace ProjectExplorer
|
||||
|
||||
@@ -64,6 +64,7 @@ public:
|
||||
static void addSessionLoadingSteps(int steps);
|
||||
|
||||
static bool loadSession(const QString &session, bool initial = false);
|
||||
static bool saveSession();
|
||||
|
||||
signals:
|
||||
void startupSessionRestored();
|
||||
|
||||
Reference in New Issue
Block a user