Outline: Double click should jump to text even in non-sync mode

This commit is contained in:
Kai Koehne
2010-12-20 09:44:54 +01:00
parent 32f69b9b77
commit 94fc750a45
4 changed files with 51 additions and 34 deletions

View File

@@ -89,6 +89,8 @@ CppOutlineWidget::CppOutlineWidget(CPPEditor *editor) :
this, SLOT(updateSelectionInTree(QModelIndex))); this, SLOT(updateSelectionInTree(QModelIndex)));
connect(m_treeView->selectionModel(), SIGNAL(selectionChanged(QItemSelection,QItemSelection)), connect(m_treeView->selectionModel(), SIGNAL(selectionChanged(QItemSelection,QItemSelection)),
this, SLOT(updateSelectionInText(QItemSelection))); this, SLOT(updateSelectionInText(QItemSelection)));
connect(m_treeView, SIGNAL(doubleClicked(QModelIndex)),
this, SLOT(updateTextCursor(QModelIndex)));
} }
QList<QAction*> CppOutlineWidget::filterMenuActions() const QList<QAction*> CppOutlineWidget::filterMenuActions() const
@@ -131,6 +133,12 @@ void CppOutlineWidget::updateSelectionInText(const QItemSelection &selection)
if (!selection.indexes().isEmpty()) { if (!selection.indexes().isEmpty()) {
QModelIndex proxyIndex = selection.indexes().first(); QModelIndex proxyIndex = selection.indexes().first();
updateTextCursor(proxyIndex);
}
}
void CppOutlineWidget::updateTextCursor(const QModelIndex &proxyIndex)
{
QModelIndex index = m_proxyModel->mapToSource(proxyIndex); QModelIndex index = m_proxyModel->mapToSource(proxyIndex);
CPlusPlus::Symbol *symbol = m_model->symbolFromIndex(index); CPlusPlus::Symbol *symbol = m_model->symbolFromIndex(index);
if (symbol) { if (symbol) {
@@ -147,7 +155,6 @@ void CppOutlineWidget::updateSelectionInText(const QItemSelection &selection)
m_editor->gotoLine(symbol->line(), symbol->column() - 1); m_editor->gotoLine(symbol->line(), symbol->column() - 1);
m_blockCursorSync = false; m_blockCursorSync = false;
} }
}
} }
bool CppOutlineWidget::syncCursor() bool CppOutlineWidget::syncCursor()

View File

@@ -47,6 +47,7 @@ private slots:
void modelUpdated(); void modelUpdated();
void updateSelectionInTree(const QModelIndex &index); void updateSelectionInTree(const QModelIndex &index);
void updateSelectionInText(const QItemSelection &selection); void updateSelectionInText(const QItemSelection &selection);
void updateTextCursor(const QModelIndex &index);
private: private:
bool syncCursor(); bool syncCursor();

View File

@@ -102,6 +102,9 @@ void QmlJSOutlineWidget::setEditor(QmlJSTextEditor *editor)
connect(m_treeView->selectionModel(), SIGNAL(selectionChanged(QItemSelection,QItemSelection)), connect(m_treeView->selectionModel(), SIGNAL(selectionChanged(QItemSelection,QItemSelection)),
this, SLOT(updateSelectionInText(QItemSelection))); this, SLOT(updateSelectionInText(QItemSelection)));
connect(m_treeView, SIGNAL(doubleClicked(QModelIndex)),
this, SLOT(updateTextCursor(QModelIndex)));
connect(m_editor, SIGNAL(outlineModelIndexChanged(QModelIndex)), connect(m_editor, SIGNAL(outlineModelIndexChanged(QModelIndex)),
this, SLOT(updateSelectionInTree(QModelIndex))); this, SLOT(updateSelectionInTree(QModelIndex)));
connect(m_editor->outlineModel(), SIGNAL(updated()), connect(m_editor->outlineModel(), SIGNAL(updated()),
@@ -167,8 +170,14 @@ void QmlJSOutlineWidget::updateSelectionInText(const QItemSelection &selection)
if (!selection.indexes().isEmpty()) { if (!selection.indexes().isEmpty()) {
QModelIndex index = selection.indexes().first(); QModelIndex index = selection.indexes().first();
QModelIndex sourceIndex = m_filterModel->mapToSource(index);
updateTextCursor(index);
}
}
void QmlJSOutlineWidget::updateTextCursor(const QModelIndex &index)
{
QModelIndex sourceIndex = m_filterModel->mapToSource(index);
AST::SourceLocation location = m_editor->outlineModel()->sourceLocation(sourceIndex); AST::SourceLocation location = m_editor->outlineModel()->sourceLocation(sourceIndex);
if (!location.isValid()) if (!location.isValid())
@@ -189,7 +198,6 @@ void QmlJSOutlineWidget::updateSelectionInText(const QItemSelection &selection)
m_editor->setTextCursor(textCursor); m_editor->setTextCursor(textCursor);
m_editor->centerCursor(); m_editor->centerCursor();
m_blockCursorSync = false; m_blockCursorSync = false;
}
} }
void QmlJSOutlineWidget::setShowBindings(bool showBindings) void QmlJSOutlineWidget::setShowBindings(bool showBindings)

View File

@@ -54,6 +54,7 @@ private slots:
void modelUpdated(); void modelUpdated();
void updateSelectionInTree(const QModelIndex &index); void updateSelectionInTree(const QModelIndex &index);
void updateSelectionInText(const QItemSelection &selection); void updateSelectionInText(const QItemSelection &selection);
void updateTextCursor(const QModelIndex &index);
void setShowBindings(bool showBindings); void setShowBindings(bool showBindings);
private: private: