Fix double-clicking in Projects view to open file in extra window

When you have an external editor window open (Window > Open in New
Window):

- make sure that the editor has focus in the main window
- switch to the external window
- double-click a file in Projects, Open Documents, or File System view

The file is supposed to open in the external window.
The problem is that clicking into e.g. Projects view activates the main
window, which changes focus, and the current editor.
Something changed in the event order in Qt (also Qt 5), so the existing
workaround that delayed setting the current editor view in that case by
just one event loop cycle doesn't work anymore. Delay be the double-
click interval instead, so the double-click can be processed before the
main window's editor view is made current.

Fixes: QTCREATORBUG-26773
Change-Id: I56efd5a50a8bb986563c8c15d340756dace06494
Reviewed-by: <github-actions-qt-creator@cristianadam.eu>
Reviewed-by: Christian Stenger <christian.stenger@qt.io>
This commit is contained in:
Eike Ziller
2022-03-21 15:52:35 +01:00
parent 70c44acdd8
commit 22c67db406

View File

@@ -2395,8 +2395,9 @@ void EditorManagerPrivate::handleContextChange(const QList<IContext *> &context)
// the locator line edit) first activates the window and sets focus to its focus widget.
// Only afterwards the focus is shifted to the widget that received the click.
d->m_scheduledCurrentEditor = editor;
QMetaObject::invokeMethod(d, &EditorManagerPrivate::setCurrentEditorFromContextChange,
Qt::QueuedConnection);
QTimer::singleShot(QApplication::doubleClickInterval() + 10,
d,
&EditorManagerPrivate::setCurrentEditorFromContextChange);
} else {
updateActions();
}