diff --git a/src/plugins/cppeditor/cppoutline.cpp b/src/plugins/cppeditor/cppoutline.cpp index 2bc7916e9f9..641e5779955 100644 --- a/src/plugins/cppeditor/cppoutline.cpp +++ b/src/plugins/cppeditor/cppoutline.cpp @@ -46,8 +46,6 @@ enum { CppOutlineTreeView::CppOutlineTreeView(QWidget *parent) : Utils::NavigationTreeView(parent) { - // see also QmlJSOutlineTreeView - setFocusPolicy(Qt::NoFocus); setExpandsOnDoubleClick(false); } @@ -105,6 +103,7 @@ CppOutlineWidget::CppOutlineWidget(CPPEditorWidget *editor) : setLayout(layout); m_treeView->setModel(m_proxyModel); + setFocusProxy(m_treeView); connect(m_model, SIGNAL(modelReset()), this, SLOT(modelUpdated())); modelUpdated(); @@ -113,8 +112,8 @@ CppOutlineWidget::CppOutlineWidget(CPPEditorWidget *editor) : this, SLOT(updateSelectionInTree(QModelIndex))); connect(m_treeView->selectionModel(), SIGNAL(selectionChanged(QItemSelection,QItemSelection)), this, SLOT(updateSelectionInText(QItemSelection))); - connect(m_treeView, SIGNAL(doubleClicked(QModelIndex)), - this, SLOT(updateTextCursor(QModelIndex))); + connect(m_treeView, SIGNAL(activated(QModelIndex)), + this, SLOT(focusEditor())); } QList CppOutlineWidget::filterMenuActions() const @@ -145,7 +144,7 @@ void CppOutlineWidget::updateSelectionInTree(const QModelIndex &index) if (debug) qDebug() << "CppOutline - updating selection due to cursor move"; - m_treeView->selectionModel()->select(proxyIndex, QItemSelectionModel::ClearAndSelect); + m_treeView->setCurrentIndex(proxyIndex); m_treeView->scrollTo(proxyIndex); m_blockCursorSync = false; } @@ -176,11 +175,15 @@ void CppOutlineWidget::updateTextCursor(const QModelIndex &proxyIndex) // line has to be 1 based, column 0 based! m_editor->gotoLine(symbol->line(), symbol->column() - 1); - m_editor->setFocus(); m_blockCursorSync = false; } } +void CppOutlineWidget::focusEditor() +{ + m_editor->setFocus(); +} + bool CppOutlineWidget::syncCursor() { return m_enableCursorSync && !m_blockCursorSync; diff --git a/src/plugins/cppeditor/cppoutline.h b/src/plugins/cppeditor/cppoutline.h index a4322ce6537..29969dc1972 100644 --- a/src/plugins/cppeditor/cppoutline.h +++ b/src/plugins/cppeditor/cppoutline.h @@ -77,6 +77,7 @@ private slots: void updateSelectionInTree(const QModelIndex &index); void updateSelectionInText(const QItemSelection &selection); void updateTextCursor(const QModelIndex &index); + void focusEditor(); private: bool syncCursor(); diff --git a/src/plugins/qmljseditor/qmljsoutline.cpp b/src/plugins/qmljseditor/qmljsoutline.cpp index e42a617d78b..fe6953ae7b0 100644 --- a/src/plugins/qmljseditor/qmljsoutline.cpp +++ b/src/plugins/qmljseditor/qmljsoutline.cpp @@ -104,6 +104,7 @@ QmlJSOutlineWidget::QmlJSOutlineWidget(QWidget *parent) : m_filterModel->setFilterBindings(false); m_treeView->setModel(m_filterModel); + setFocusProxy(m_treeView); QVBoxLayout *layout = new QVBoxLayout; @@ -130,8 +131,8 @@ void QmlJSOutlineWidget::setEditor(QmlJSTextEditorWidget *editor) connect(m_treeView->selectionModel(), SIGNAL(selectionChanged(QItemSelection,QItemSelection)), this, SLOT(updateSelectionInText(QItemSelection))); - connect(m_treeView, SIGNAL(doubleClicked(QModelIndex)), - this, SLOT(updateTextCursor(QModelIndex))); + connect(m_treeView, SIGNAL(activated(QModelIndex)), + this, SLOT(focusEditor())); connect(m_editor, SIGNAL(outlineModelIndexChanged(QModelIndex)), this, SLOT(updateSelectionInTree(QModelIndex))); @@ -187,7 +188,7 @@ void QmlJSOutlineWidget::updateSelectionInTree(const QModelIndex &index) filterIndex = m_filterModel->mapFromSource(baseIndex); } - m_treeView->selectionModel()->select(filterIndex, QItemSelectionModel::ClearAndSelect); + m_treeView->setCurrentIndex(filterIndex); m_treeView->scrollTo(filterIndex); m_blockCursorSync = false; } @@ -226,10 +227,14 @@ void QmlJSOutlineWidget::updateTextCursor(const QModelIndex &index) textCursor.setPosition(location.offset); m_editor->setTextCursor(textCursor); m_editor->centerCursor(); - m_editor->setFocus(); m_blockCursorSync = false; } +void QmlJSOutlineWidget::focusEditor() +{ + m_editor->setFocus(); +} + void QmlJSOutlineWidget::setShowBindings(bool showBindings) { m_filterModel->setFilterBindings(!showBindings); diff --git a/src/plugins/qmljseditor/qmljsoutline.h b/src/plugins/qmljseditor/qmljsoutline.h index 668b697c728..39cf78be984 100644 --- a/src/plugins/qmljseditor/qmljsoutline.h +++ b/src/plugins/qmljseditor/qmljsoutline.h @@ -80,6 +80,7 @@ private slots: void updateSelectionInTree(const QModelIndex &index); void updateSelectionInText(const QItemSelection &selection); void updateTextCursor(const QModelIndex &index); + void focusEditor(); void setShowBindings(bool showBindings); private: diff --git a/src/plugins/qmljseditor/qmljsoutlinetreeview.cpp b/src/plugins/qmljseditor/qmljsoutlinetreeview.cpp index 808726bffee..6a883155c58 100644 --- a/src/plugins/qmljseditor/qmljsoutlinetreeview.cpp +++ b/src/plugins/qmljseditor/qmljsoutlinetreeview.cpp @@ -39,8 +39,6 @@ namespace Internal { QmlJSOutlineTreeView::QmlJSOutlineTreeView(QWidget *parent) : Utils::NavigationTreeView(parent) { - // see also CppOutlineTreeView - setFocusPolicy(Qt::NoFocus); setExpandsOnDoubleClick(false); setDragEnabled(true); diff --git a/src/plugins/texteditor/outlinefactory.cpp b/src/plugins/texteditor/outlinefactory.cpp index 9ad3d0aa853..a1b53767826 100644 --- a/src/plugins/texteditor/outlinefactory.cpp +++ b/src/plugins/texteditor/outlinefactory.cpp @@ -168,6 +168,7 @@ void OutlineWidgetStack::updateCurrentEditor(Core::IEditor *editor) newWidget->setCursorSynchronization(m_syncWithEditor); addWidget(newWidget); setCurrentWidget(newWidget); + setFocusProxy(newWidget); } updateFilterMenu();