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);
|
dd, &ProjectExplorerPluginPrivate::savePersistentSettings);
|
||||||
connect(EditorManager::instance(), &EditorManager::autoSaved, this, [] {
|
connect(EditorManager::instance(), &EditorManager::autoSaved, this, [] {
|
||||||
if (!dd->m_shuttingDown && !SessionManager::loadingSession())
|
if (!dd->m_shuttingDown && !SessionManager::loadingSession())
|
||||||
ProjectManager::save();
|
SessionManager::saveSession();
|
||||||
});
|
});
|
||||||
connect(qApp, &QApplication::applicationStateChanged, this, [](Qt::ApplicationState state) {
|
connect(qApp, &QApplication::applicationStateChanged, this, [](Qt::ApplicationState state) {
|
||||||
if (!dd->m_shuttingDown && state == Qt::ApplicationActive)
|
if (!dd->m_shuttingDown && state == Qt::ApplicationActive)
|
||||||
@@ -2212,7 +2212,7 @@ void ProjectExplorerPlugin::openNewProjectDialog()
|
|||||||
|
|
||||||
void ProjectExplorerPluginPrivate::showSessionManager()
|
void ProjectExplorerPluginPrivate::showSessionManager()
|
||||||
{
|
{
|
||||||
ProjectManager::save();
|
SessionManager::saveSession();
|
||||||
SessionDialog sessionDialog(ICore::dialogParent());
|
SessionDialog sessionDialog(ICore::dialogParent());
|
||||||
sessionDialog.setAutoLoadSession(sb_d->isAutoRestoreLastSession());
|
sessionDialog.setAutoLoadSession(sb_d->isAutoRestoreLastSession());
|
||||||
sessionDialog.exec();
|
sessionDialog.exec();
|
||||||
@@ -2258,7 +2258,7 @@ void ProjectExplorerPluginPrivate::savePersistentSettings()
|
|||||||
for (Project *pro : ProjectManager::projects())
|
for (Project *pro : ProjectManager::projects())
|
||||||
pro->saveSettings();
|
pro->saveSettings();
|
||||||
|
|
||||||
ProjectManager::save();
|
SessionManager::saveSession();
|
||||||
}
|
}
|
||||||
|
|
||||||
QtcSettings *s = ICore::settings();
|
QtcSettings *s = ICore::settings();
|
||||||
|
|||||||
@@ -53,6 +53,7 @@ class ProjectManagerPrivate
|
|||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
void loadSession();
|
void loadSession();
|
||||||
|
void saveSession();
|
||||||
void restoreDependencies();
|
void restoreDependencies();
|
||||||
void restoreStartupProject();
|
void restoreStartupProject();
|
||||||
void restoreProjects(const FilePaths &fileList);
|
void restoreProjects(const FilePaths &fileList);
|
||||||
@@ -109,6 +110,9 @@ ProjectManager::ProjectManager()
|
|||||||
connect(SessionManager::instance(), &SessionManager::aboutToLoadSession, this, [] {
|
connect(SessionManager::instance(), &SessionManager::aboutToLoadSession, this, [] {
|
||||||
d->loadSession();
|
d->loadSession();
|
||||||
});
|
});
|
||||||
|
connect(SessionManager::instance(), &SessionManager::aboutToSaveSession, this, [] {
|
||||||
|
d->saveSession();
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
ProjectManager::~ProjectManager()
|
ProjectManager::~ProjectManager()
|
||||||
@@ -315,87 +319,38 @@ void ProjectManager::removeProject(Project *project)
|
|||||||
removeProjects({project});
|
removeProjects({project});
|
||||||
}
|
}
|
||||||
|
|
||||||
bool ProjectManager::save()
|
void ProjectManagerPrivate::saveSession()
|
||||||
{
|
{
|
||||||
emit SessionManager::instance()->aboutToSaveSession();
|
// save the startup project
|
||||||
|
if (d->m_startupProject)
|
||||||
|
SessionManager::setSessionValue("StartupProject",
|
||||||
|
m_startupProject->projectFilePath().toSettings());
|
||||||
|
|
||||||
const FilePath filePath = SessionManager::sessionNameToFileName(sb_d->m_sessionName);
|
FilePaths projectFiles = Utils::transform(m_projects, &Project::projectFilePath);
|
||||||
QVariantMap data;
|
// Restore information on projects that failed to load:
|
||||||
|
// don't read projects to the list, which the user loaded
|
||||||
// See the explanation at loadSession() for how we handle the implicit default session.
|
for (const FilePath &failed : std::as_const(m_failedProjects)) {
|
||||||
if (SessionManager::isDefaultVirgin()) {
|
if (!projectFiles.contains(failed))
|
||||||
if (filePath.exists()) {
|
projectFiles << failed;
|
||||||
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());
|
|
||||||
|
|
||||||
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);
|
|
||||||
// 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)) {
|
|
||||||
if (!projectFiles.contains(failed))
|
|
||||||
projectFiles << failed;
|
|
||||||
}
|
|
||||||
|
|
||||||
data.insert("ProjectList", Utils::transform<QStringList>(projectFiles,
|
|
||||||
&FilePath::toString));
|
|
||||||
data.insert("CascadeSetActive", d->m_casadeSetActive);
|
|
||||||
|
|
||||||
QVariantMap depMap;
|
|
||||||
auto i = d->m_depMap.constBegin();
|
|
||||||
while (i != d->m_depMap.constEnd()) {
|
|
||||||
QString key = i.key().toString();
|
|
||||||
QStringList values;
|
|
||||||
const FilePaths valueList = i.value();
|
|
||||||
for (const FilePath &value : valueList)
|
|
||||||
values << value.toString();
|
|
||||||
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();
|
SessionManager::setSessionValue("ProjectList",
|
||||||
QStringList keys;
|
Utils::transform<QStringList>(projectFiles,
|
||||||
for (auto it = sb_d->m_values.constBegin(); it != end; ++it) {
|
&FilePath::toString));
|
||||||
data.insert(QLatin1String("value-") + it.key(), it.value());
|
SessionManager::setSessionValue("CascadeSetActive", m_casadeSetActive);
|
||||||
keys << it.key();
|
|
||||||
}
|
|
||||||
data.insert(QLatin1String("valueKeys"), keys);
|
|
||||||
|
|
||||||
if (!sb_d->m_writer || sb_d->m_writer->fileName() != filePath) {
|
QVariantMap depMap;
|
||||||
delete sb_d->m_writer;
|
auto i = m_depMap.constBegin();
|
||||||
sb_d->m_writer = new PersistentSettingsWriter(filePath, "QtCreatorSession");
|
while (i != m_depMap.constEnd()) {
|
||||||
|
QString key = i.key().toString();
|
||||||
|
QStringList values;
|
||||||
|
const FilePaths valueList = i.value();
|
||||||
|
for (const FilePath &value : valueList)
|
||||||
|
values << value.toString();
|
||||||
|
depMap.insert(key, values);
|
||||||
|
++i;
|
||||||
}
|
}
|
||||||
const bool result = sb_d->m_writer->save(data, ICore::dialogParent());
|
SessionManager::setSessionValue(QLatin1String("ProjectDependencies"), QVariant(depMap));
|
||||||
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;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/*!
|
/*!
|
||||||
|
|||||||
@@ -47,7 +47,6 @@ public:
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
static bool save();
|
|
||||||
static void closeAllProjects();
|
static void closeAllProjects();
|
||||||
|
|
||||||
static void addProject(Project *project);
|
static void addProject(Project *project);
|
||||||
|
|||||||
@@ -7,7 +7,6 @@
|
|||||||
|
|
||||||
#include "projectexplorer.h"
|
#include "projectexplorer.h"
|
||||||
#include "projectexplorertr.h"
|
#include "projectexplorertr.h"
|
||||||
#include "projectmanager.h"
|
|
||||||
|
|
||||||
#include <extensionsystem/pluginmanager.h>
|
#include <extensionsystem/pluginmanager.h>
|
||||||
#include <extensionsystem/pluginspec.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
|
// Allow everyone to set something in the session and before saving
|
||||||
emit SessionManager::instance()->aboutToUnloadSession(sb_d->m_sessionName);
|
emit SessionManager::instance()->aboutToUnloadSession(sb_d->m_sessionName);
|
||||||
|
|
||||||
if (!ProjectManager::save()) {
|
if (!saveSession()) {
|
||||||
sb_d->m_loadingSession = false;
|
sb_d->m_loadingSession = false;
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
@@ -571,4 +570,67 @@ bool SessionManager::loadSession(const QString &session, bool initial)
|
|||||||
return true;
|
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
|
} // namespace ProjectExplorer
|
||||||
|
|||||||
@@ -64,6 +64,7 @@ public:
|
|||||||
static void addSessionLoadingSteps(int steps);
|
static void addSessionLoadingSteps(int steps);
|
||||||
|
|
||||||
static bool loadSession(const QString &session, bool initial = false);
|
static bool loadSession(const QString &session, bool initial = false);
|
||||||
|
static bool saveSession();
|
||||||
|
|
||||||
signals:
|
signals:
|
||||||
void startupSessionRestored();
|
void startupSessionRestored();
|
||||||
|
|||||||
Reference in New Issue
Block a user