diff --git a/language/duchain/navigation/useswidget.h b/language/duchain/navigation/useswidget.h --- a/language/duchain/navigation/useswidget.h +++ b/language/duchain/navigation/useswidget.h @@ -48,6 +48,10 @@ OneUseWidget(IndexedDeclaration declaration, IndexedString document, KTextEditor::Range range, const CodeRepresentation& code); ~OneUseWidget() override; + void setHighlighted(bool highlight); + bool isHighlighted(); + void activateLink(); + private: void mousePressEvent(QMouseEvent * event) override; void resizeEvent ( QResizeEvent * event ) override; @@ -60,6 +64,7 @@ QLabel* m_label; QLabel* m_icon; QHBoxLayout* m_layout; + bool m_isHighlighted = false; }; diff --git a/language/duchain/navigation/useswidget.cpp b/language/duchain/navigation/useswidget.cpp --- a/language/duchain/navigation/useswidget.cpp +++ b/language/duchain/navigation/useswidget.cpp @@ -154,10 +154,32 @@ m_layout->setAlignment(Qt::AlignLeft); } +void OneUseWidget::setHighlighted(bool highlight) +{ + if (highlight) { + m_label->setText(m_label->text().replace("background-color:#fbfa96", "background-color:#fb96f2")); + m_isHighlighted = true; + } + else { + m_label->setText(m_label->text().replace("background-color:#fb96f2", "background-color:#fbfa96")); + m_isHighlighted = false; + } +} + +bool OneUseWidget::isHighlighted() +{ + return m_isHighlighted; +} + +void OneUseWidget::activateLink() +{ + ICore::self()->documentController()->openDocument(m_document.toUrl(), m_range->range().start()); +} + void OneUseWidget::mousePressEvent(QMouseEvent* event) { if (event->button() == Qt::LeftButton && !event->modifiers()) { - ICore::self()->documentController()->openDocument(m_document.toUrl(), m_range->range().start()); + activateLink(); event->accept(); } } diff --git a/plugins/contextbrowser/contextbrowserview.h b/plugins/contextbrowser/contextbrowserview.h --- a/plugins/contextbrowser/contextbrowserview.h +++ b/plugins/contextbrowser/contextbrowserview.h @@ -29,6 +29,7 @@ #include #include #include +#include class ContextBrowserPlugin; class QVBoxLayout; @@ -42,8 +43,9 @@ class IDocument; } -class ContextBrowserView : public QWidget { +class ContextBrowserView : public QWidget, public KDevelop::IToolViewActionListener { Q_OBJECT + Q_INTERFACES(KDevelop::IToolViewActionListener) public: ContextBrowserView( ContextBrowserPlugin*, QWidget* parent ); ~ContextBrowserView() override; @@ -82,6 +84,8 @@ void updateLockIcon(bool); void declarationMenu(); void navigationContextChanged(bool wasInitial, bool isInitial); + void selectNextItem() override; + void selectPreviousItem() override; private: void showEvent(QShowEvent* event) override; @@ -90,6 +94,8 @@ void focusInEvent(QFocusEvent* event) override; void focusOutEvent(QFocusEvent* event) override; void resetWidget(); + QList allUses(); + int selectedUseIndex(QList uses); private: diff --git a/plugins/contextbrowser/contextbrowserview.cpp b/plugins/contextbrowser/contextbrowserview.cpp --- a/plugins/contextbrowser/contextbrowserview.cpp +++ b/plugins/contextbrowser/contextbrowserview.cpp @@ -241,6 +241,107 @@ } } +void ContextBrowserView::selectNextItem() +{ + QList uses = allUses(); + + if (uses.count() == 0) { + return; + } + + int index = selectedUseIndex(uses); + QPointer use; + + if (index == -1 && (use = dynamic_cast(uses.at(0)))) { + use->setHighlighted(true); + } + else { + use = dynamic_cast(uses.at(index)); + use->setHighlighted(false); + if (index + 1 < uses.count()) { + use = dynamic_cast(uses.at(index + 1)); + } + else { + use = dynamic_cast(uses.at(0)); + } + use->setHighlighted(true); + use->activateLink(); + } +} + +void ContextBrowserView::selectPreviousItem() +{ + QList uses = allUses(); + + if (uses.count() == 0) { + return; + } + + int index = selectedUseIndex(uses); + QPointer use; + + if (index == -1 && (use = dynamic_cast(uses.at(uses.count() - 1)))) { + use->setHighlighted(true); + } + else { + use = dynamic_cast(uses.at(index)); + use->setHighlighted(false); + if (index - 1 >= 0) { + use = dynamic_cast(uses.at(index - 1)); + } + else { + use = dynamic_cast(uses.at(uses.count() - 1)); + } + use->setHighlighted(true); + use->activateLink(); + } +} + +QList ContextBrowserView::allUses() +{ + QList uses; + + QPointer abstractNaviWidget = dynamic_cast(this->navigationWidget()); + if (!abstractNaviWidget) { + return uses; + } + + QPointer usesWidget = dynamic_cast(abstractNaviWidget->context()->widget()); + if (!usesWidget) { + return uses; + } + + foreach (QWidget* uw, usesWidget->items()) { + QPointer topContext = dynamic_cast(uw); + if (topContext) { + foreach (QWidget* nl, topContext->items()) { + QPointer list = dynamic_cast(nl); + if (list) { + foreach (QWidget* ou, list->items()) { + QPointer oneUse = dynamic_cast(ou); + if(oneUse) + uses.append( oneUse ); + } + } + + } + } + } + return uses; +} + +int ContextBrowserView::selectedUseIndex(QList uses) +{ + for(int i = 0; i < uses.count(); i++) { + QPointer use = dynamic_cast(uses.at(i)); + if (use && use->isHighlighted()) { + return i; + } + } + + return -1; +} + void ContextBrowserView::setDeclaration(KDevelop::Declaration* decl, KDevelop::TopDUContext* topContext, bool force) { m_lastUsedTopContext = IndexedTopDUContext(topContext);