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,22 +133,27 @@ void CppOutlineWidget::updateSelectionInText(const QItemSelection &selection)
if (!selection.indexes().isEmpty()) { if (!selection.indexes().isEmpty()) {
QModelIndex proxyIndex = selection.indexes().first(); QModelIndex proxyIndex = selection.indexes().first();
QModelIndex index = m_proxyModel->mapToSource(proxyIndex); updateTextCursor(proxyIndex);
CPlusPlus::Symbol *symbol = m_model->symbolFromIndex(index); }
if (symbol) { }
m_blockCursorSync = true;
if (debug) void CppOutlineWidget::updateTextCursor(const QModelIndex &proxyIndex)
qDebug() << "CppOutline - moving cursor to" << symbol->line() << symbol->column() - 1; {
QModelIndex index = m_proxyModel->mapToSource(proxyIndex);
CPlusPlus::Symbol *symbol = m_model->symbolFromIndex(index);
if (symbol) {
m_blockCursorSync = true;
Core::EditorManager *editorManager = Core::EditorManager::instance(); if (debug)
editorManager->cutForwardNavigationHistory(); qDebug() << "CppOutline - moving cursor to" << symbol->line() << symbol->column() - 1;
editorManager->addCurrentPositionToNavigationHistory();
// line has to be 1 based, column 0 based! Core::EditorManager *editorManager = Core::EditorManager::instance();
m_editor->gotoLine(symbol->line(), symbol->column() - 1); editorManager->cutForwardNavigationHistory();
m_blockCursorSync = false; editorManager->addCurrentPositionToNavigationHistory();
}
// line has to be 1 based, column 0 based!
m_editor->gotoLine(symbol->line(), symbol->column() - 1);
m_blockCursorSync = false;
} }
} }

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,31 +170,36 @@ 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);
AST::SourceLocation location = m_editor->outlineModel()->sourceLocation(sourceIndex); updateTextCursor(index);
if (!location.isValid())
return;
const QTextBlock lastBlock = m_editor->document()->lastBlock();
const uint textLength = lastBlock.position() + lastBlock.length();
if (location.offset >= textLength)
return;
Core::EditorManager *editorManager = Core::EditorManager::instance();
editorManager->cutForwardNavigationHistory();
editorManager->addCurrentPositionToNavigationHistory();
QTextCursor textCursor = m_editor->textCursor();
m_blockCursorSync = true;
textCursor.setPosition(location.offset);
m_editor->setTextCursor(textCursor);
m_editor->centerCursor();
m_blockCursorSync = false;
} }
} }
void QmlJSOutlineWidget::updateTextCursor(const QModelIndex &index)
{
QModelIndex sourceIndex = m_filterModel->mapToSource(index);
AST::SourceLocation location = m_editor->outlineModel()->sourceLocation(sourceIndex);
if (!location.isValid())
return;
const QTextBlock lastBlock = m_editor->document()->lastBlock();
const uint textLength = lastBlock.position() + lastBlock.length();
if (location.offset >= textLength)
return;
Core::EditorManager *editorManager = Core::EditorManager::instance();
editorManager->cutForwardNavigationHistory();
editorManager->addCurrentPositionToNavigationHistory();
QTextCursor textCursor = m_editor->textCursor();
m_blockCursorSync = true;
textCursor.setPosition(location.offset);
m_editor->setTextCursor(textCursor);
m_editor->centerCursor();
m_blockCursorSync = false;
}
void QmlJSOutlineWidget::setShowBindings(bool showBindings) void QmlJSOutlineWidget::setShowBindings(bool showBindings)
{ {
m_filterModel->setFilterBindings(!showBindings); m_filterModel->setFilterBindings(!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: