CorePlugin: Switch split if remote command tries to open an already opened file

It seems more natural that remote commands
don't change current editor of active view if file
is already opened in another view.

Change-Id: Ie27de0d159cae6e63fa1d477fab59887a0e6d198
Reviewed-by: Eike Ziller <eike.ziller@qt.io>
This commit is contained in:
Razi Alavizadeh
2018-06-14 13:37:09 +04:30
parent ffc651d54e
commit f009d5f151
5 changed files with 18 additions and 3 deletions

View File

@@ -247,7 +247,7 @@ QObject *CorePlugin::remoteCommand(const QStringList & /* options */,
return nullptr;
}
IDocument *res = m_mainWindow->openFiles(
args, ICore::OpenFilesFlags(ICore::SwitchMode | ICore::CanContainLineAndColumnNumbers),
args, ICore::OpenFilesFlags(ICore::SwitchMode | ICore::CanContainLineAndColumnNumbers | ICore::SwitchSplitIfAlreadyVisible),
workingDirectory);
m_mainWindow->raiseWindow();
return res;

View File

@@ -576,6 +576,17 @@ IEditor *EditorManagerPrivate::openEditor(EditorView *view, const QString &fileN
const QList<IEditor *> editors = DocumentModel::editorsForFilePath(fn);
if (!editors.isEmpty()) {
IEditor *editor = editors.first();
if (flags & EditorManager::SwitchSplitIfAlreadyVisible) {
for (IEditor *ed : editors) {
EditorView *v = viewForEditor(ed);
// Don't switch to a view where editor is not its current editor
if (v && v->currentEditor() == ed) {
editor = ed;
view = v;
break;
}
}
}
editor = activateEditor(view, editor, flags);
if (editor && flags & EditorManager::CanContainLineAndColumnNumber)
editor->gotoLine(lineNumber, columnNumber);

View File

@@ -89,7 +89,8 @@ public:
CanContainLineAndColumnNumber = 8,
OpenInOtherSplit = 16,
DoNotSwitchToDesignMode = 32,
DoNotSwitchToEditMode = 64
DoNotSwitchToEditMode = 64,
SwitchSplitIfAlreadyVisible = 128
};
Q_DECLARE_FLAGS(OpenEditorFlags, OpenEditorFlag)

View File

@@ -127,7 +127,8 @@ public:
SwitchMode = 1,
CanContainLineAndColumnNumbers = 2,
/// Stop loading once the first file fails to load
StopOnLoadFail = 4
StopOnLoadFail = 4,
SwitchSplitIfAlreadyVisible = 8
};
static void openFiles(const QStringList &fileNames, OpenFilesFlags flags = None);

View File

@@ -845,6 +845,8 @@ IDocument *MainWindow::openFiles(const QStringList &fileNames,
QFlags<EditorManager::OpenEditorFlag> emFlags;
if (flags & ICore::CanContainLineAndColumnNumbers)
emFlags |= EditorManager::CanContainLineAndColumnNumber;
if (flags & ICore::SwitchSplitIfAlreadyVisible)
emFlags |= EditorManager::SwitchSplitIfAlreadyVisible;
IEditor *editor = EditorManager::openEditor(absoluteFilePath, Id(), emFlags);
if (!editor) {
if (flags & ICore::StopOnLoadFail)