diff options
Diffstat (limited to 'src/plugins')
| -rw-r--r-- | src/plugins/coreplugin/documentmanager.cpp | 42 | ||||
| -rw-r--r-- | src/plugins/coreplugin/editormanager/editormanager.h | 9 |
2 files changed, 38 insertions, 13 deletions
diff --git a/src/plugins/coreplugin/documentmanager.cpp b/src/plugins/coreplugin/documentmanager.cpp index 4a7a6e0f4b..8fd1605f76 100644 --- a/src/plugins/coreplugin/documentmanager.cpp +++ b/src/plugins/coreplugin/documentmanager.cpp @@ -37,6 +37,7 @@ #include <coreplugin/dialogs/readonlyfilesdialog.h> #include <coreplugin/dialogs/saveitemsdialog.h> #include <coreplugin/editormanager/editormanager.h> +#include <coreplugin/editormanager/editorview.h> #include <coreplugin/editormanager/ieditor.h> #include <coreplugin/editormanager/ieditorfactory.h> #include <coreplugin/editormanager/iexternaleditor.h> @@ -1414,19 +1415,42 @@ void DocumentManager::executeOpenWithMenuAction(QAction *action) const QVariant data = action->data(); OpenWithEntry entry = qvariant_cast<OpenWithEntry>(data); if (entry.editorFactory) { - // close any open editors that have this file open, but have a different type. + // close any open editors that have this file open + // remember the views to open new editors in there + QList<Internal::EditorView *> views; QList<IEditor *> editorsOpenForFile = DocumentModel::editorsForFilePath(entry.fileName); - if (!editorsOpenForFile.isEmpty()) { - foreach (IEditor *openEditor, editorsOpenForFile) { - if (entry.editorFactory->id() == openEditor->document()->id()) - editorsOpenForFile.removeAll(openEditor); - } - if (!EditorManager::closeEditors(editorsOpenForFile)) // don't open if cancel was pressed - return; + foreach (IEditor *openEditor, editorsOpenForFile) { + Internal::EditorView *view = EditorManager::viewForEditor(openEditor); + if (view && view->currentEditor() == openEditor) // visible + views.append(view); } + if (!EditorManager::closeEditors(editorsOpenForFile)) // don't open if cancel was pressed + return; - EditorManager::openEditor(entry.fileName, entry.editorFactory->id()); + if (views.isEmpty()) { + EditorManager::openEditor(entry.fileName, entry.editorFactory->id()); + } else { + if (Internal::EditorView *currentView = EditorManager::currentEditorView()) { + if (views.removeOne(currentView)) + views.prepend(currentView); // open editor in current view first + } + EditorManager::OpenEditorFlags flags; + foreach (Internal::EditorView *view, views) { + IEditor *editor = + EditorManager::openEditor(view, entry.fileName, entry.editorFactory->id(), + flags); + // Do not change the current editor after opening the first one. That + // * prevents multiple updates of focus etc which are not necessary + // * lets us control which editor is made current by putting the current editor view + // to the front (if that was in the list in the first place + flags |= EditorManager::DoNotChangeCurrentEditor; + // do not try to open more editors if this one failed, or editor type does not + // support duplication anyhow + if (!editor || !editor->duplicateSupported()) + break; + } + } return; } if (entry.externalEditor) diff --git a/src/plugins/coreplugin/editormanager/editormanager.h b/src/plugins/coreplugin/editormanager/editormanager.h index 27a408068b..01a233b1de 100644 --- a/src/plugins/coreplugin/editormanager/editormanager.h +++ b/src/plugins/coreplugin/editormanager/editormanager.h @@ -117,6 +117,8 @@ public: static IEditor *openEditorWithContents(Id editorId, QString *titlePattern = 0, const QByteArray &contents = QByteArray(), OpenEditorFlags flags = NoFlags); + static IEditor *openEditor(Internal::EditorView *view, const QString &fileName, + Id id = Id(), OpenEditorFlags flags = NoFlags, bool *newEditor = 0); static bool openExternalEditor(const QString &fileName, Id editorId); @@ -125,6 +127,7 @@ public: static IDocument *currentDocument(); static IEditor *currentEditor(); + static Internal::EditorView *currentEditorView(); static QList<IEditor *> visibleEditors(); static void activateEditor(IEditor *editor, OpenEditorFlags flags = 0); @@ -136,6 +139,8 @@ public: static void closeEditor(DocumentModel::Entry *entry); static void closeOtherEditors(IDocument *document); + static Internal::EditorView *viewForEditor(IEditor *editor); + static void addCurrentPositionToNavigationHistory(IEditor *editor = 0, const QByteArray &saveState = QByteArray()); static void cutForwardNavigationHistory(); @@ -264,14 +269,10 @@ private: static void activateEditorForEntry(Internal::EditorView *view, DocumentModel::Entry *entry, OpenEditorFlags flags = NoFlags); static void activateView(Internal::EditorView *view); - static IEditor *openEditor(Internal::EditorView *view, const QString &fileName, - Id id = Id(), OpenEditorFlags flags = NoFlags, bool *newEditor = 0); static int visibleDocumentsCount(); static void setCurrentEditor(IEditor *editor, bool ignoreNavigationHistory = false); static void setCurrentView(Internal::EditorView *view); - static Internal::EditorView *currentEditorView(); - static Internal::EditorView *viewForEditor(IEditor *editor); static Internal::SplitterOrView *findRoot(const Internal::EditorView *view, int *rootIndex = 0); static void closeView(Internal::EditorView *view); |
