forked from qt-creator/qt-creator
Make creator auto-save the session state when something changed
Currently the 10second auto-save timer is started when an editor is opened or close, or when a bookmark or breakpoint is set or removed. The change ensures that users do not lose their session state should creator crash (e.g. when a laptop runs out of battery) Task-number: QTCREATORBUG-188 Reviewed-by: con
This commit is contained in:
@@ -54,6 +54,7 @@
|
|||||||
#include <QtCore/QFileInfo>
|
#include <QtCore/QFileInfo>
|
||||||
#include <QtCore/QFuture>
|
#include <QtCore/QFuture>
|
||||||
#include <QtCore/QSettings>
|
#include <QtCore/QSettings>
|
||||||
|
#include <QtCore/QTimer>
|
||||||
|
|
||||||
#include <QtGui/QApplication>
|
#include <QtGui/QApplication>
|
||||||
#include <QtGui/QMainWindow>
|
#include <QtGui/QMainWindow>
|
||||||
@@ -390,12 +391,28 @@ SessionManager::SessionManager(QObject *parent)
|
|||||||
|
|
||||||
connect(m_core->modeManager(), SIGNAL(currentModeChanged(Core::IMode*)),
|
connect(m_core->modeManager(), SIGNAL(currentModeChanged(Core::IMode*)),
|
||||||
this, SLOT(saveActiveMode(Core::IMode*)));
|
this, SLOT(saveActiveMode(Core::IMode*)));
|
||||||
connect(m_core->editorManager(), SIGNAL(editorCreated(Core::IEditor *, QString)),
|
|
||||||
|
Core::EditorManager *em = m_core->editorManager();
|
||||||
|
|
||||||
|
connect(em, SIGNAL(editorCreated(Core::IEditor *, QString)),
|
||||||
this, SLOT(setEditorCodec(Core::IEditor *, QString)));
|
this, SLOT(setEditorCodec(Core::IEditor *, QString)));
|
||||||
connect(ProjectExplorerPlugin::instance(), SIGNAL(currentProjectChanged(ProjectExplorer::Project *)),
|
connect(ProjectExplorerPlugin::instance(), SIGNAL(currentProjectChanged(ProjectExplorer::Project *)),
|
||||||
this, SLOT(updateWindowTitle()));
|
this, SLOT(updateWindowTitle()));
|
||||||
connect(m_core->editorManager(), SIGNAL(currentEditorChanged(Core::IEditor*)),
|
connect(em, SIGNAL(currentEditorChanged(Core::IEditor*)),
|
||||||
this, SLOT(handleCurrentEditorChange(Core::IEditor*)));
|
this, SLOT(handleCurrentEditorChange(Core::IEditor*)));
|
||||||
|
connect(em, SIGNAL(currentEditorChanged(Core::IEditor*)),
|
||||||
|
this, SLOT(handleCurrentEditorChange(Core::IEditor*)));
|
||||||
|
connect(em, SIGNAL(editorOpened(Core::IEditor*)),
|
||||||
|
this, SLOT(markSessionFileDirty()));
|
||||||
|
connect(em, SIGNAL(editorsClosed(QList<Core::IEditor*>)),
|
||||||
|
this, SLOT(markSessionFileDirty()));
|
||||||
|
|
||||||
|
|
||||||
|
m_autoSaveSessionTimer = new QTimer(this);
|
||||||
|
m_autoSaveSessionTimer->setSingleShot(true);
|
||||||
|
m_autoSaveSessionTimer->setInterval(10000);
|
||||||
|
connect(m_autoSaveSessionTimer, SIGNAL(timeout()),
|
||||||
|
m_core, SIGNAL(saveSettingsRequested()));
|
||||||
}
|
}
|
||||||
|
|
||||||
SessionManager::~SessionManager()
|
SessionManager::~SessionManager()
|
||||||
@@ -985,8 +1002,13 @@ void SessionManager::removeProjects(QList<Project *> remove)
|
|||||||
|
|
||||||
void SessionManager::setValue(const QString &name, const QVariant &value)
|
void SessionManager::setValue(const QString &name, const QVariant &value)
|
||||||
{
|
{
|
||||||
if (m_file)
|
if (!m_file)
|
||||||
|
return;
|
||||||
|
|
||||||
|
if (m_file->m_values.value(name) == value)
|
||||||
|
return;
|
||||||
m_file->m_values.insert(name, value);
|
m_file->m_values.insert(name, value);
|
||||||
|
markSessionFileDirty();
|
||||||
}
|
}
|
||||||
|
|
||||||
QVariant SessionManager::value(const QString &name)
|
QVariant SessionManager::value(const QString &name)
|
||||||
@@ -1113,5 +1135,9 @@ void SessionManager::reportProjectLoadingProgress()
|
|||||||
m_file->sessionLoadingProgress();
|
m_file->sessionLoadingProgress();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void SessionManager::markSessionFileDirty()
|
||||||
|
{
|
||||||
|
m_autoSaveSessionTimer->start();
|
||||||
|
}
|
||||||
|
|
||||||
#include "session.moc"
|
#include "session.moc"
|
||||||
|
|||||||
@@ -173,6 +173,8 @@ private slots:
|
|||||||
void handleCurrentEditorChange(Core::IEditor *editor);
|
void handleCurrentEditorChange(Core::IEditor *editor);
|
||||||
void updateWindowTitle();
|
void updateWindowTitle();
|
||||||
|
|
||||||
|
void markSessionFileDirty();
|
||||||
|
|
||||||
private:
|
private:
|
||||||
bool loadImpl(const QString &fileName);
|
bool loadImpl(const QString &fileName);
|
||||||
bool createImpl(const QString &fileName);
|
bool createImpl(const QString &fileName);
|
||||||
@@ -197,6 +199,7 @@ private:
|
|||||||
mutable QStringList m_sessions;
|
mutable QStringList m_sessions;
|
||||||
|
|
||||||
mutable QHash<Project *, QStringList> m_projectFileCache;
|
mutable QHash<Project *, QStringList> m_projectFileCache;
|
||||||
|
QTimer *m_autoSaveSessionTimer;
|
||||||
};
|
};
|
||||||
|
|
||||||
} // namespace ProjectExplorer
|
} // namespace ProjectExplorer
|
||||||
|
|||||||
Reference in New Issue
Block a user