Commit 783d6ebb authored by Eike Ziller's avatar Eike Ziller

Avoid duplicating editors too often.

It was duplicating editors even if an editor for a document was already
available in the view, if that editor wasn't currently on top.

Task-number: QTCREATORBUG-11395
Change-Id: I89a2d5ef0285d8aa34642567fbf122a98e87e75e
Reviewed-by: default avatarEike Ziller <eike.ziller@digia.com>
parent 58af02f0
......@@ -1230,34 +1230,35 @@ Core::IEditor *EditorManager::placeEditor(Core::Internal::EditorView *view, Core
{
Q_ASSERT(view && editor);
if (view->currentEditor() && view->currentEditor()->document() == editor->document())
editor = view->currentEditor();
if (!view->hasEditor(editor)) {
bool duplicateSupported = editor->duplicateSupported();
if (EditorView *sourceView = viewForEditor(editor)) {
if (editor != sourceView->currentEditor() || !duplicateSupported) {
// pull the IEditor over to the new view
sourceView->removeEditor(editor);
view->addEditor(editor);
view->setCurrentEditor(editor);
if (!sourceView->currentEditor()) {
EditorView *replacementView = 0;
if (IEditor *replacement = pickUnusedEditor(&replacementView)) {
if (replacementView)
replacementView->removeEditor(replacement);
sourceView->addEditor(replacement);
sourceView->setCurrentEditor(replacement);
}
if (view->hasEditor(editor))
return editor;
if (IEditor *e = view->editorForDocument(editor->document()))
return e;
// try duplication or pull editor over to new view
bool duplicateSupported = editor->duplicateSupported();
if (EditorView *sourceView = viewForEditor(editor)) {
if (editor != sourceView->currentEditor() || !duplicateSupported) {
// pull the IEditor over to the new view
sourceView->removeEditor(editor);
view->addEditor(editor);
view->setCurrentEditor(editor);
if (!sourceView->currentEditor()) {
EditorView *replacementView = 0;
if (IEditor *replacement = pickUnusedEditor(&replacementView)) {
if (replacementView)
replacementView->removeEditor(replacement);
sourceView->addEditor(replacement);
sourceView->setCurrentEditor(replacement);
}
return editor;
} else if (duplicateSupported) {
editor = duplicateEditor(editor);
Q_ASSERT(editor);
}
return editor;
} else if (duplicateSupported) {
editor = duplicateEditor(editor);
Q_ASSERT(editor);
}
view->addEditor(editor);
}
view->addEditor(editor);
return editor;
}
......@@ -1314,11 +1315,14 @@ IEditor *EditorManager::activateEditorForDocument(IDocument *document, OpenEdito
Core::IEditor *EditorManager::activateEditorForDocument(Core::Internal::EditorView *view, Core::IDocument *document, OpenEditorFlags flags)
{
Q_ASSERT(view);
const QList<IEditor*> editors = d->m_documentModel->editorsForDocument(document);
if (editors.isEmpty())
return 0;
return activateEditor(view, editors.first(), flags);
IEditor *editor = view->editorForDocument(document);
if (!editor) {
const QList<IEditor*> editors = d->m_documentModel->editorsForDocument(document);
if (editors.isEmpty())
return 0;
editor = editors.first();
}
return activateEditor(view, editor, flags);
}
/* For something that has a 'QStringList mimeTypes' (IEditorFactory
......
......@@ -369,6 +369,14 @@ QList<IEditor *> EditorView::editors() const
return m_editors;
}
IEditor *EditorView::editorForDocument(const IDocument *document) const
{
foreach (IEditor *editor, m_editors)
if (editor->document() == document)
return editor;
return 0;
}
void EditorView::updateEditorHistory(IEditor *editor)
{
updateEditorHistory(editor, m_editorHistory);
......
......@@ -91,6 +91,7 @@ public:
bool hasEditor(IEditor *editor) const;
QList<IEditor *> editors() const;
IEditor *editorForDocument(const IDocument *document) const;
void showEditorStatusBar(const QString &id,
const QString &infoText,
......
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