Commit 3b2614c6 authored by con's avatar con
Browse files

Fix closing and restoring editors in presence of temporary editors.

* Editor manager should abort closing core, if there's a ICoreListener
that aborts closing of a editor.
* Don't save state of temporary editors, and don't save them as open in
  a splitter. So restoring the editor manager state won't try to reopen
  temporary editors.

Task-number: QTCREATORBUG-2845
Task-number: QTCREATORBUG-2841
Reviewed-by: Tobias Hunger
parent 83255c08
......@@ -768,7 +768,7 @@ bool EditorManager::closeEditors(const QList<IEditor*> &editorsToClose, bool ask
foreach (ICoreListener *listener, listeners) {
if (!listener->editorAboutToClose(editor)) {
editorAccepted = false;
closingFailed = false;
closingFailed = true;
break;
}
}
......@@ -802,7 +802,8 @@ bool EditorManager::closeEditors(const QList<IEditor*> &editorsToClose, bool ask
// remove the editors
foreach (IEditor *editor, acceptedEditors) {
emit editorAboutToClose(editor);
if (!editor->file()->fileName().isEmpty()) {
if (!editor->file()->fileName().isEmpty()
&& !editor->isTemporary()) {
QByteArray state = editor->saveState();
if (!state.isEmpty())
m_d->m_editorStates.insert(editor->file()->fileName(), QVariant(state));
......
......@@ -803,14 +803,26 @@ QByteArray SplitterOrView::saveState() const
IEditor* e = editor();
EditorManager *em = CoreImpl::instance()->editorManager();
if (e && e == em->currentEditor()) {
// don't save state of temporary or ad-hoc editors
if (e && (e->isTemporary() || e->file()->fileName().isEmpty())) {
// look for another editor that is more suited
e = 0;
foreach (IEditor *otherEditor, editors()) {
if (!otherEditor->isTemporary() && !otherEditor->file()->fileName().isEmpty()) {
e = otherEditor;
break;
}
}
}
if (!e) {
stream << QByteArray("empty");
} else if (e == em->currentEditor()) {
stream << QByteArray("currenteditor")
<< e->file()->fileName() << e->id() << e->saveState();
} else if (e) {
} else {
stream << QByteArray("editor")
<< e->file()->fileName() << e->id() << e->saveState();
} else {
stream << QByteArray("empty");
}
}
return bytes;
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment