Commit 56bdad14 authored by Eike Ziller's avatar Eike Ziller
Browse files

Fix crash with splitting and non-splittable editors



We may not just add an editor to a view without removing it from the
original view.

Task-number: QTCREATORBUG-9843
Change-Id: I1041ceb1f063bb627b5f0bd16bc3b2973a4dc3b6
Reviewed-by: default avatarEike Ziller <eike.ziller@digia.com>
parent 885520d9
...@@ -1225,12 +1225,15 @@ void EditorManager::closeDuplicate(Core::IEditor *editor) ...@@ -1225,12 +1225,15 @@ void EditorManager::closeDuplicate(Core::IEditor *editor)
} }
} }
Core::IEditor *EditorManager::pickUnusedEditor() const Core::IEditor *EditorManager::pickUnusedEditor(EditorView **foundView) const
{ {
foreach (IEditor *editor, openedEditors()) { foreach (IEditor *editor, openedEditors()) {
EditorView *view = viewForEditor(editor); EditorView *view = viewForEditor(editor);
if (!view || view->currentEditor() != editor) if (!view || view->currentEditor() != editor) {
if (foundView)
*foundView = view;
return editor; return editor;
}
} }
return 0; return 0;
} }
...@@ -1282,8 +1285,12 @@ Core::IEditor *EditorManager::placeEditor(Core::Internal::EditorView *view, Core ...@@ -1282,8 +1285,12 @@ Core::IEditor *EditorManager::placeEditor(Core::Internal::EditorView *view, Core
view->addEditor(editor); view->addEditor(editor);
view->setCurrentEditor(editor); view->setCurrentEditor(editor);
if (!sourceView->currentEditor()) { if (!sourceView->currentEditor()) {
if (IEditor *replacement = pickUnusedEditor()) EditorView *replacementView = 0;
if (IEditor *replacement = pickUnusedEditor(&replacementView)) {
if (replacementView)
replacementView->removeEditor(replacement);
sourceView->addEditor(replacement); sourceView->addEditor(replacement);
}
} }
return editor; return editor;
} else if (duplicateSupported) { } else if (duplicateSupported) {
......
...@@ -277,7 +277,7 @@ private: ...@@ -277,7 +277,7 @@ private:
void closeView(Internal::EditorView *view); void closeView(Internal::EditorView *view);
void emptyView(Internal::EditorView *view); void emptyView(Internal::EditorView *view);
static void splitNewWindow(Internal::EditorView *view); static void splitNewWindow(Internal::EditorView *view);
IEditor *pickUnusedEditor() const; IEditor *pickUnusedEditor(Internal::EditorView **foundView = 0) const;
void addDocumentToRecentFiles(IDocument *document); void addDocumentToRecentFiles(IDocument *document);
void updateAutoSave(); void updateAutoSave();
void setCloseSplitEnabled(Internal::SplitterOrView *splitterOrView, bool enable); void setCloseSplitEnabled(Internal::SplitterOrView *splitterOrView, bool enable);
......
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