summaryrefslogtreecommitdiff
path: root/src/plugins/coreplugin/documentmanager.cpp
diff options
context:
space:
mode:
authorEike Ziller <eike.ziller@digia.com>2014-07-02 16:53:17 +0200
committerEike Ziller <eike.ziller@digia.com>2014-07-04 08:50:28 +0200
commitdb918592ecd2b66edbf9f982547ea2563237b9d0 (patch)
tree9c66ee32384ab4ff7f28d3335c130f87053bd614 /src/plugins/coreplugin/documentmanager.cpp
parent4971de7ccfcd972e6ba8944be5392810acf31376 (diff)
downloadqt-creator-db918592ecd2b66edbf9f982547ea2563237b9d0.tar.gz
Fix "Open with" for multiple splits
It was closing all existing editors and opening a single new one in the "current" split. Instead, open new editors in all splits where the file was open and visible. Change-Id: Iac7238077b2e42937ce54eea65fa1b61dcd07df1 Reviewed-by: David Schulz <david.schulz@digia.com>
Diffstat (limited to 'src/plugins/coreplugin/documentmanager.cpp')
-rw-r--r--src/plugins/coreplugin/documentmanager.cpp42
1 files changed, 33 insertions, 9 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)