Make default virgin session check more robust.

Task-Nr: QTCREATORBUG-572
This commit is contained in:
dt
2010-03-18 13:42:09 +01:00
parent 336cb97089
commit 272e76409d
2 changed files with 15 additions and 8 deletions

View File

@@ -370,7 +370,8 @@ SessionManager::SessionManager(QObject *parent)
m_core(Core::ICore::instance()), m_core(Core::ICore::instance()),
m_file(new SessionFile), m_file(new SessionFile),
m_sessionNode(new Internal::SessionNodeImpl(this)), m_sessionNode(new Internal::SessionNodeImpl(this)),
m_currentEditor(0) m_currentEditor(0),
m_defaultVirginSession(true)
{ {
// Create qtcreator dir if it doesn't yet exist // Create qtcreator dir if it doesn't yet exist
QString configDir = QFileInfo(m_core->settings()->fileName()).path(); QString configDir = QFileInfo(m_core->settings()->fileName()).path();
@@ -424,9 +425,7 @@ SessionManager::~SessionManager()
bool SessionManager::isDefaultVirgin() const bool SessionManager::isDefaultVirgin() const
{ {
return isDefaultSession(m_sessionName) return m_defaultVirginSession;
&& projects().isEmpty()
&& m_core->editorManager()->openedEditors().isEmpty();
} }
bool SessionManager::isDefaultSession(const QString &session) const bool SessionManager::isDefaultSession(const QString &session) const
@@ -564,6 +563,7 @@ void SessionManager::addProject(Project *project)
void SessionManager::addProjects(const QList<Project*> &projects) void SessionManager::addProjects(const QList<Project*> &projects)
{ {
m_defaultVirginSession = false;
QList<Project*> clearedList; QList<Project*> clearedList;
foreach (Project *pro, projects) { foreach (Project *pro, projects) {
if (!m_file->m_projects.contains(pro)) { if (!m_file->m_projects.contains(pro)) {
@@ -594,6 +594,7 @@ void SessionManager::addProjects(const QList<Project*> &projects)
void SessionManager::removeProject(Project *project) void SessionManager::removeProject(Project *project)
{ {
m_defaultVirginSession = false;
if (project == 0) { if (project == 0) {
qDebug() << "SessionManager::removeProject(0) ... THIS SHOULD NOT HAPPEN"; qDebug() << "SessionManager::removeProject(0) ... THIS SHOULD NOT HAPPEN";
return; return;
@@ -623,6 +624,8 @@ bool SessionManager::createImpl(const QString &fileName)
setStartupProject(defaultStartupProject()); setStartupProject(defaultStartupProject());
} }
m_defaultVirginSession = false;
if (debug) if (debug)
qDebug() << "SessionManager - creating new session returns " << success; qDebug() << "SessionManager - creating new session returns " << success;
@@ -642,7 +645,6 @@ bool SessionManager::loadImpl(const QString &fileName)
bool success = true; bool success = true;
if (!m_file->fileName().isEmpty()) { if (!m_file->fileName().isEmpty()) {
if (isDefaultVirgin()) { if (isDefaultVirgin()) {
// do not save initial and virgin default session // do not save initial and virgin default session
} else if (!save() || !clear()) { } else if (!save() || !clear()) {
@@ -650,6 +652,8 @@ bool SessionManager::loadImpl(const QString &fileName)
} }
} }
m_defaultVirginSession = false;
if (success) { if (success) {
emit aboutToUnloadSession(); emit aboutToUnloadSession();
delete m_file; delete m_file;
@@ -1008,7 +1012,7 @@ void SessionManager::setValue(const QString &name, const QVariant &value)
if (m_file->m_values.value(name) == value) if (m_file->m_values.value(name) == value)
return; return;
m_file->m_values.insert(name, value); m_file->m_values.insert(name, value);
markSessionFileDirty(); markSessionFileDirty(false);
} }
QVariant SessionManager::value(const QString &name) QVariant SessionManager::value(const QString &name)
@@ -1135,10 +1139,12 @@ void SessionManager::reportProjectLoadingProgress()
m_file->sessionLoadingProgress(); m_file->sessionLoadingProgress();
} }
void SessionManager::markSessionFileDirty() void SessionManager::markSessionFileDirty(bool makeDefaultVirginDirty)
{ {
if (m_file && !m_file->fileName().isEmpty()) if (m_file && !m_file->fileName().isEmpty())
m_autoSaveSessionTimer->start(); m_autoSaveSessionTimer->start();
if (makeDefaultVirginDirty)
m_defaultVirginSession = false;
} }
#include "session.moc" #include "session.moc"

View File

@@ -173,7 +173,7 @@ private slots:
void handleCurrentEditorChange(Core::IEditor *editor); void handleCurrentEditorChange(Core::IEditor *editor);
void updateWindowTitle(); void updateWindowTitle();
void markSessionFileDirty(); void markSessionFileDirty(bool makeDefaultVirginDirty = true);
private: private:
bool loadImpl(const QString &fileName); bool loadImpl(const QString &fileName);
@@ -195,6 +195,7 @@ private:
QPointer<Core::IEditor> m_currentEditor; QPointer<Core::IEditor> m_currentEditor;
QString m_displayName; QString m_displayName;
QString m_sessionName; QString m_sessionName;
bool m_defaultVirginSession;
mutable QStringList m_sessions; mutable QStringList m_sessions;