Commit db918592 authored by Eike Ziller's avatar Eike Ziller

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: default avatarDavid Schulz <david.schulz@digia.com>
parent 4971de7c
......@@ -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)
......
......@@ -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);
......
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