Changeset View
Changeset View
Standalone View
Standalone View
plugins/contextbrowser/contextbrowser.cpp
Show First 20 Lines • Show All 583 Lines • ▼ Show 20 Line(s) | 582 | for (const auto language : languages) { | |||
---|---|---|---|---|---|
584 | auto navigationWidget = qobject_cast<AbstractNavigationWidget*>(widget.first); | 584 | auto navigationWidget = qobject_cast<AbstractNavigationWidget*>(widget.first); | ||
585 | if (navigationWidget) { | 585 | if (navigationWidget) { | ||
586 | itemRange = widget.second; | 586 | itemRange = widget.second; | ||
587 | return navigationWidget; | 587 | return navigationWidget; | ||
588 | } | 588 | } | ||
589 | } | 589 | } | ||
590 | 590 | | |||
591 | TopDUContext* topContext = DUChainUtils::standardContextForUrl(view->document()->url()); | 591 | TopDUContext* topContext = DUChainUtils::standardContextForUrl(view->document()->url()); | ||
592 | QVector<KDevelop::IProblem::Ptr> problems; | ||||
592 | if (topContext) { | 593 | if (topContext) { | ||
593 | // first pass: find problems under the cursor | 594 | // first pass: find problems under the cursor | ||
594 | const auto problems = findProblemsUnderCursor(topContext, position, itemRange); | 595 | problems = findProblemsUnderCursor(topContext, position, itemRange); | ||
595 | if (!problems.isEmpty()) { | | |||
596 | if (problems == m_currentToolTipProblems && m_currentToolTip) { | | |||
597 | return nullptr; | | |||
598 | } | | |||
599 | | ||||
600 | m_currentToolTipProblems = problems; | | |||
601 | | ||||
602 | auto widget = new AbstractNavigationWidget; | | |||
603 | auto context = new ProblemNavigationContext(problems); | | |||
604 | context->setTopContext(TopDUContextPointer(topContext)); | | |||
605 | widget->setContext(NavigationContextPointer(context)); | | |||
606 | return widget; | | |||
607 | } | | |||
608 | } | 596 | } | ||
609 | 597 | | |||
610 | const auto itemUnderCursor = DUChainUtils::itemUnderCursor(viewUrl, position); | 598 | const auto itemUnderCursor = DUChainUtils::itemUnderCursor(viewUrl, position); | ||
611 | auto declUnderCursor = itemUnderCursor.declaration; | 599 | auto declUnderCursor = itemUnderCursor.declaration; | ||
612 | Declaration* decl = DUChainUtils::declarationForDefinition(declUnderCursor); | 600 | Declaration* decl = DUChainUtils::declarationForDefinition(declUnderCursor); | ||
613 | if (decl && decl->kind() == Declaration::Alias) { | 601 | if (decl && decl->kind() == Declaration::Alias) { | ||
614 | auto* alias = dynamic_cast<AliasDeclaration*>(decl); | 602 | auto* alias = dynamic_cast<AliasDeclaration*>(decl); | ||
615 | Q_ASSERT(alias); | 603 | Q_ASSERT(alias); | ||
616 | decl = alias->aliasedDeclaration().declaration(); | 604 | decl = alias->aliasedDeclaration().declaration(); | ||
617 | } | 605 | } | ||
618 | if (decl) { | 606 | | ||
619 | if (m_currentToolTipDeclaration == IndexedDeclaration(decl) && m_currentToolTip) | 607 | // Return nullptr if the correct contents are already shown. | ||
608 | if (m_currentToolTip && | ||||
609 | problems == m_currentToolTipProblems && | ||||
610 | (!decl || IndexedDeclaration(decl) == m_currentToolTipDeclaration)) { | ||||
620 | return nullptr; | 611 | return nullptr; | ||
612 | } | ||||
621 | 613 | | |||
614 | // Remember current state. | ||||
615 | m_currentToolTipProblems = problems; | ||||
616 | if (decl) { | ||||
622 | m_currentToolTipDeclaration = IndexedDeclaration(decl); | 617 | m_currentToolTipDeclaration = IndexedDeclaration(decl); | ||
618 | } | ||||
619 | | ||||
620 | AbstractNavigationWidget* problemWidget = nullptr; | ||||
621 | if (!problems.isEmpty()) { | ||||
622 | problemWidget = new AbstractNavigationWidget; | ||||
623 | auto context = new ProblemNavigationContext(problems); | ||||
624 | context->setTopContext(TopDUContextPointer(topContext)); | ||||
625 | problemWidget->setContext(NavigationContextPointer(context)); | ||||
626 | } | ||||
627 | | ||||
628 | QWidget* declWidget = nullptr; | ||||
629 | if (decl) { | ||||
630 | if (itemRange.isValid()) { | ||||
631 | itemRange.expandToRange(itemUnderCursor.range); | ||||
632 | } else { | ||||
623 | itemRange = itemUnderCursor.range; | 633 | itemRange = itemUnderCursor.range; | ||
624 | return decl->context()->createNavigationWidget(decl, DUChainUtils::standardContextForUrl(viewUrl)); | 634 | } | ||
635 | declWidget = decl->context()->createNavigationWidget(decl, DUChainUtils::standardContextForUrl(viewUrl)); | ||||
636 | } | ||||
637 | | ||||
638 | if (problemWidget && declWidget) { | ||||
639 | QWidget* combinedWidget = new QWidget(); | ||||
640 | QVBoxLayout* layout = new QVBoxLayout(); | ||||
641 | layout->setContentsMargins(2, 2, 2, 2); | ||||
642 | layout->setSpacing(0); | ||||
643 | layout->addWidget(problemWidget); | ||||
644 | layout->addWidget(declWidget); | ||||
645 | combinedWidget->setLayout(layout); | ||||
646 | return combinedWidget; | ||||
647 | } else if (problemWidget) { | ||||
648 | return problemWidget; | ||||
649 | } else if (declWidget) { | ||||
650 | return declWidget; | ||||
625 | } | 651 | } | ||
626 | 652 | | |||
627 | if (topContext) { | 653 | if (topContext) { | ||
628 | // second pass: find closest problem to the cursor | 654 | // second pass: find closest problem to the cursor | ||
629 | const auto problems = findProblemsCloseToCursor(topContext, position, view, itemRange); | 655 | problems = findProblemsCloseToCursor(topContext, position, view, itemRange); | ||
630 | if (!problems.isEmpty()) { | 656 | if (!problems.isEmpty()) { | ||
631 | if (problems == m_currentToolTipProblems && m_currentToolTip) { | 657 | if (problems == m_currentToolTipProblems && m_currentToolTip) { | ||
632 | return nullptr; | 658 | return nullptr; | ||
633 | } | 659 | } | ||
634 | 660 | | |||
635 | m_currentToolTipProblems = problems; | 661 | m_currentToolTipProblems = problems; | ||
636 | 662 | | |||
637 | auto widget = new AbstractNavigationWidget; | 663 | auto widget = new AbstractNavigationWidget; | ||
▲ Show 20 Lines • Show All 951 Lines • Show Last 20 Lines |