From 4b51064b45812af0d5bd2196bc21e1f123ddba9a Mon Sep 17 00:00:00 2001 From: David Schulz Date: Mon, 15 Dec 2014 12:39:49 +0100 Subject: [PATCH] Editor: Don't change the focus when setting a new view. Move the focus logic to activateView. Use activateView when it makes sense. Change-Id: I79ad11eea629fc1aaa194ecdd8995f5965d1b806 Reviewed-by: Eike Ziller --- .../editormanager/editormanager.cpp | 33 ++++++------------- .../editormanager/editormanager_p.h | 2 +- .../coreplugin/editormanager/editorview.cpp | 10 +++--- 3 files changed, 16 insertions(+), 29 deletions(-) diff --git a/src/plugins/coreplugin/editormanager/editormanager.cpp b/src/plugins/coreplugin/editormanager/editormanager.cpp index d640bdab7dc..eab09cd7a07 100644 --- a/src/plugins/coreplugin/editormanager/editormanager.cpp +++ b/src/plugins/coreplugin/editormanager/editormanager.cpp @@ -1070,13 +1070,16 @@ void EditorManagerPrivate::closeEditorOrDocument(IEditor *editor) void EditorManagerPrivate::activateView(EditorView *view) { QTC_ASSERT(view, return); + QWidget *focusWidget; if (IEditor *editor = view->currentEditor()) { setCurrentEditor(editor, true); - editor->widget()->setFocus(); - ICore::raiseWindow(editor->widget()); + focusWidget = editor->widget(); } else { setCurrentView(view); + focusWidget = view; } + focusWidget->setFocus(); + ICore::raiseWindow(focusWidget); } void EditorManagerPrivate::restoreEditorState(IEditor *editor) @@ -1134,11 +1137,6 @@ void EditorManagerPrivate::setCurrentView(EditorView *view) old->update(); if (view) view->update(); - - if (view && !view->currentEditor()) { - view->setFocus(); - ICore::raiseWindow(view); - } } EditorArea *EditorManagerPrivate::findEditorArea(const EditorView *view, int *areaIndex) @@ -1176,12 +1174,8 @@ void EditorManagerPrivate::closeView(EditorView *view) splitter->unsplit(); EditorView *newCurrent = splitter->findFirstView(); - if (newCurrent) { - if (IEditor *e = newCurrent->currentEditor()) - EditorManagerPrivate::activateEditor(newCurrent, e); - else - EditorManagerPrivate::setCurrentView(newCurrent); - } + if (newCurrent) + EditorManagerPrivate::activateView(newCurrent); } void EditorManagerPrivate::emptyView(EditorView *view) @@ -1552,10 +1546,7 @@ void EditorManagerPrivate::editorAreaDestroyed(QObject *area) EditorView *focusView = focusSplitterOrView->findFirstView(); // can be just focusSplitterOrView QTC_ASSERT(focusView, focusView = newActiveArea->findFirstView()); QTC_ASSERT(focusView, return); - if (focusView->currentEditor()) - setCurrentEditor(focusView->currentEditor()); - else - setCurrentView(focusView); + EditorManagerPrivate::activateView(focusView); } void EditorManagerPrivate::autoSave() @@ -2168,12 +2159,8 @@ bool EditorManager::closeEditors(const QList &editorsToClose, bool ask foreach (IEditor *editor, acceptedEditors) delete editor; - if (currentView && !currentViewHandled) { - if (IEditor *editor = currentView->currentEditor()) - EditorManagerPrivate::activateEditor(currentView, editor); - else - EditorManagerPrivate::setCurrentView(currentView); - } + if (currentView && !currentViewHandled) + EditorManagerPrivate::activateView(currentView); if (!currentEditor()) { emit m_instance->currentEditorChanged(0); diff --git a/src/plugins/coreplugin/editormanager/editormanager_p.h b/src/plugins/coreplugin/editormanager/editormanager_p.h index f40a85afe80..0144c85c328 100644 --- a/src/plugins/coreplugin/editormanager/editormanager_p.h +++ b/src/plugins/coreplugin/editormanager/editormanager_p.h @@ -97,6 +97,7 @@ public: static EditorView *viewForEditor(IEditor *editor); static void setCurrentView(EditorView *view); + static void activateView(EditorView *view); static MakeWritableResult makeFileWritable(IDocument *document); static void doEscapeKeyFocusMoveMagic(); @@ -177,7 +178,6 @@ private: static void addEditor(IEditor *editor); static void removeEditor(IEditor *editor); static IEditor *placeEditor(EditorView *view, IEditor *editor); - static void activateView(EditorView *view); static void restoreEditorState(IEditor *editor); static int visibleDocumentsCount(); static EditorArea *findEditorArea(const EditorView *view, int *areaIndex = 0); diff --git a/src/plugins/coreplugin/editormanager/editorview.cpp b/src/plugins/coreplugin/editormanager/editorview.cpp index 748df48f402..15afa6e69da 100644 --- a/src/plugins/coreplugin/editormanager/editorview.cpp +++ b/src/plugins/coreplugin/editormanager/editorview.cpp @@ -681,10 +681,7 @@ void SplitterOrView::split(Qt::Orientation orientation) otherView->view()->setCloseSplitIcon(QIcon(QLatin1String(Constants::ICON_CLOSE_SPLIT_BOTTOM))); } - if (e) - EditorManagerPrivate::activateEditor(otherView->view(), e); - else - EditorManagerPrivate::setCurrentView(otherView->view()); + EditorManagerPrivate::activateView(otherView->view()); emit splitStateChanged(); } @@ -785,7 +782,10 @@ void SplitterOrView::unsplit() m_layout->setCurrentWidget(m_view); } delete oldSplitter; - EditorManagerPrivate::setCurrentView(findFirstView()); + if (EditorView *newCurrent = findFirstView()) + EditorManagerPrivate::activateView(newCurrent); + else + EditorManagerPrivate::setCurrentView(0); emit splitStateChanged(); }