diff --git a/src/plugins/projectexplorer/session.cpp b/src/plugins/projectexplorer/session.cpp index 4511e8f0c4b029023ea6dedc80d801a9cc73fa64..9f7ecb54591d6f489dc4a56b01d50b393c091256 100644 --- a/src/plugins/projectexplorer/session.cpp +++ b/src/plugins/projectexplorer/session.cpp @@ -54,6 +54,7 @@ #include <QtCore/QFileInfo> #include <QtCore/QFuture> #include <QtCore/QSettings> +#include <QtCore/QTimer> #include <QtGui/QApplication> #include <QtGui/QMainWindow> @@ -390,12 +391,28 @@ SessionManager::SessionManager(QObject *parent) connect(m_core->modeManager(), SIGNAL(currentModeChanged(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))); connect(ProjectExplorerPlugin::instance(), SIGNAL(currentProjectChanged(ProjectExplorer::Project *)), this, SLOT(updateWindowTitle())); - connect(m_core->editorManager(), SIGNAL(currentEditorChanged(Core::IEditor*)), + connect(em, SIGNAL(currentEditorChanged(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() @@ -985,8 +1002,13 @@ void SessionManager::removeProjects(QList<Project *> remove) void SessionManager::setValue(const QString &name, const QVariant &value) { - if (m_file) - m_file->m_values.insert(name, value); + if (!m_file) + return; + + if (m_file->m_values.value(name) == value) + return; + m_file->m_values.insert(name, value); + markSessionFileDirty(); } QVariant SessionManager::value(const QString &name) @@ -1113,5 +1135,9 @@ void SessionManager::reportProjectLoadingProgress() m_file->sessionLoadingProgress(); } +void SessionManager::markSessionFileDirty() +{ + m_autoSaveSessionTimer->start(); +} #include "session.moc" diff --git a/src/plugins/projectexplorer/session.h b/src/plugins/projectexplorer/session.h index f158a04e3a8b77a261b2914bd2c7b3732e1d713d..19be9aeda983c9155c72ef54f5dacc22b4269576 100644 --- a/src/plugins/projectexplorer/session.h +++ b/src/plugins/projectexplorer/session.h @@ -173,6 +173,8 @@ private slots: void handleCurrentEditorChange(Core::IEditor *editor); void updateWindowTitle(); + void markSessionFileDirty(); + private: bool loadImpl(const QString &fileName); bool createImpl(const QString &fileName); @@ -197,6 +199,7 @@ private: mutable QStringList m_sessions; mutable QHash<Project *, QStringList> m_projectFileCache; + QTimer *m_autoSaveSessionTimer; }; } // namespace ProjectExplorer