forked from qt-creator/qt-creator
Use editor manager standard closing facilities for session switching
This commit is contained in:
@@ -112,7 +112,7 @@ private:
|
|||||||
} // namespace ProjectExplorer
|
} // namespace ProjectExplorer
|
||||||
|
|
||||||
using namespace ProjectExplorer;
|
using namespace ProjectExplorer;
|
||||||
using Internal::SessionFile;
|
using namespace ProjectExplorer::Internal;
|
||||||
|
|
||||||
|
|
||||||
void SessionFile::sessionLoadingProgress()
|
void SessionFile::sessionLoadingProgress()
|
||||||
@@ -215,7 +215,6 @@ bool SessionFile::load(const QString &fileName)
|
|||||||
qWarning() << "Could not find startup project" << startupProjectPath;
|
qWarning() << "Could not find startup project" << startupProjectPath;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
const QVariant &editorsettings = reader.restoreValue(QLatin1String("EditorSettings"));
|
const QVariant &editorsettings = reader.restoreValue(QLatin1String("EditorSettings"));
|
||||||
if (editorsettings.isValid()) {
|
if (editorsettings.isValid()) {
|
||||||
connect(m_core->editorManager(), SIGNAL(editorOpened(Core::IEditor *)),
|
connect(m_core->editorManager(), SIGNAL(editorOpened(Core::IEditor *)),
|
||||||
@@ -272,6 +271,7 @@ bool SessionFile::save(const QString &fileName)
|
|||||||
}
|
}
|
||||||
writer.saveValue(QLatin1String("ProjectDependencies"), QVariant(depMap));
|
writer.saveValue(QLatin1String("ProjectDependencies"), QVariant(depMap));
|
||||||
|
|
||||||
|
|
||||||
writer.saveValue(QLatin1String("OpenEditors"),
|
writer.saveValue(QLatin1String("OpenEditors"),
|
||||||
m_core->editorManager()->openedEditors().count());
|
m_core->editorManager()->openedEditors().count());
|
||||||
writer.saveValue(QLatin1String("EditorSettings"),
|
writer.saveValue(QLatin1String("EditorSettings"),
|
||||||
@@ -694,28 +694,16 @@ bool SessionManager::clear()
|
|||||||
if (debug)
|
if (debug)
|
||||||
qDebug() << "SessionManager - clearing session ...";
|
qDebug() << "SessionManager - clearing session ...";
|
||||||
|
|
||||||
bool cancelled;
|
bool success = m_core->editorManager()->closeAllEditors();
|
||||||
QList<Project *> notClosed = requestCloseOfAllFiles(&cancelled);
|
|
||||||
|
|
||||||
bool success = !cancelled;
|
|
||||||
|
|
||||||
if (success) {
|
if (success) {
|
||||||
if (debug)
|
if (debug)
|
||||||
qDebug() << "SessionManager - Removing projects ...";
|
qDebug() << "SessionManager - Removing projects ...";
|
||||||
|
|
||||||
QList<Project *> toClose;
|
|
||||||
foreach (Project *pro, projects()) {
|
|
||||||
if (!notClosed.contains(pro))
|
|
||||||
toClose << pro;
|
|
||||||
}
|
|
||||||
|
|
||||||
setStartupProject(0);
|
setStartupProject(0);
|
||||||
removeProjects(toClose);
|
removeProjects(projects());
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!notClosed.isEmpty())
|
|
||||||
success = false;
|
|
||||||
|
|
||||||
if (debug)
|
if (debug)
|
||||||
qDebug() << "SessionManager - clearing session result is " << success;
|
qDebug() << "SessionManager - clearing session result is " << success;
|
||||||
|
|
||||||
@@ -883,29 +871,6 @@ void SessionManager::setEditorCodec(Core::IEditor *editor, const QString &fileNa
|
|||||||
textEditor->setTextCodec(project->editorConfiguration()->defaultTextCodec());
|
textEditor->setTextCodec(project->editorConfiguration()->defaultTextCodec());
|
||||||
}
|
}
|
||||||
|
|
||||||
QList<Project *> SessionManager::requestCloseOfAllFiles(bool *cancelled)
|
|
||||||
{
|
|
||||||
*cancelled = false;
|
|
||||||
QList<Core::IFile*> filesToClose;
|
|
||||||
foreach (Project *pro, projects())
|
|
||||||
filesToClose << pro->file();
|
|
||||||
foreach (Core::IEditor *editor, m_core->editorManager()->openedEditors())
|
|
||||||
filesToClose << editor->file();
|
|
||||||
QList<Core::IFile*> notClosed;
|
|
||||||
if (!filesToClose.isEmpty())
|
|
||||||
notClosed = m_core->fileManager()->saveModifiedFiles(filesToClose, cancelled);
|
|
||||||
// close editors here by hand
|
|
||||||
if (!*cancelled) {
|
|
||||||
QList<Core::IEditor*> editorsToClose;
|
|
||||||
foreach (Core::IEditor *editor, m_core->editorManager()->openedEditors())
|
|
||||||
if (!notClosed.contains(editor->file()))
|
|
||||||
editorsToClose << editor;
|
|
||||||
m_core->editorManager()->closeEditors(editorsToClose, false);
|
|
||||||
// project files are closed/removed later (in this::clear)
|
|
||||||
}
|
|
||||||
return Core::Utils::qwConvertList<Project*>(notClosed);
|
|
||||||
}
|
|
||||||
|
|
||||||
Core::IFile *SessionManager::file() const
|
Core::IFile *SessionManager::file() const
|
||||||
{
|
{
|
||||||
return m_file;
|
return m_file;
|
||||||
|
|||||||
@@ -180,8 +180,6 @@ private:
|
|||||||
QStringList dependenciesOrder() const;
|
QStringList dependenciesOrder() const;
|
||||||
Project *defaultStartupProject() const;
|
Project *defaultStartupProject() const;
|
||||||
|
|
||||||
QList<Project *> requestCloseOfAllFiles(bool *cancelled);
|
|
||||||
|
|
||||||
void updateName(const QString &session);
|
void updateName(const QString &session);
|
||||||
|
|
||||||
Core::ICore *m_core;
|
Core::ICore *m_core;
|
||||||
|
|||||||
Reference in New Issue
Block a user