Search in sources :

Example 1 with XPathProjectComponent

use of org.intellij.plugins.xpathView.XPathProjectComponent in project intellij-community by JetBrains.

the class FindByXPathAction method executeSearch.

private void executeSearch(@NotNull final Project project, final Module module) {
    final Config settings = XPathAppComponent.getInstance().getConfig();
    final XPathProjectComponent projectComponent = XPathProjectComponent.getInstance(project);
    final FindByExpressionDialog dlg = new FindByExpressionDialog(project, settings, projectComponent.getFindHistory(), module);
    if (!dlg.show(null)) {
        return;
    }
    final SearchScope scope = dlg.getScope();
    settings.MATCH_RECURSIVELY = dlg.isMatchRecursively();
    settings.SEARCH_SCOPE = dlg.getScope();
    final InputExpressionDialog.Context context = dlg.getContext();
    projectComponent.addFindHistory(context.input);
    final String expression = context.input.expression;
    if (!validateExpression(project, expression)) {
        return;
    }
    final UsageViewPresentation presentation = new UsageViewPresentation();
    presentation.setTargetsNodeText(settings.MATCH_RECURSIVELY ? "XPath Pattern" : "XPath Expression");
    presentation.setCodeUsages(false);
    presentation.setCodeUsagesString("Found Matches in " + scope.getName());
    presentation.setNonCodeUsagesString("Result");
    presentation.setUsagesString("results matching '" + expression + '\'');
    presentation.setUsagesWord("match");
    presentation.setTabText(StringUtil.shortenTextWithEllipsis("XPath '" + expression + '\'', 60, 0, true));
    presentation.setScopeText(scope.getName());
    presentation.setOpenInNewTab(FindSettings.getInstance().isShowResultsInSeparateView());
    final FindUsagesProcessPresentation processPresentation = new FindUsagesProcessPresentation(presentation);
    processPresentation.setProgressIndicatorFactory(() -> new FindProgressIndicator(project, scope.getName()));
    processPresentation.setShowPanelIfOnlyOneUsage(true);
    processPresentation.setShowNotFoundMessage(true);
    final XPathEvalAction.MyUsageTarget usageTarget = new XPathEvalAction.MyUsageTarget(context.input.expression, null);
    final UsageTarget[] usageTargets = new UsageTarget[] { usageTarget };
    final Factory<UsageSearcher> searcherFactory = () -> new XPathUsageSearcher(project, context.input, scope, settings.MATCH_RECURSIVELY);
    final UsageViewManager.UsageViewStateListener stateListener = new UsageViewManager.UsageViewStateListener() {

        public void usageViewCreated(@NotNull UsageView usageView) {
            usageView.addButtonToLowerPane(new MyEditExpressionAction(project, module), "&Edit Expression");
        }

        public void findingUsagesFinished(UsageView usageView) {
        }
    };
    UsageViewManager.getInstance(project).searchAndShowUsages(usageTargets, searcherFactory, processPresentation, presentation, stateListener);
}
Also used : Config(org.intellij.plugins.xpathView.Config) XPathEvalAction(org.intellij.plugins.xpathView.XPathEvalAction) NotNull(org.jetbrains.annotations.NotNull) FindProgressIndicator(com.intellij.find.FindProgressIndicator) XPathProjectComponent(org.intellij.plugins.xpathView.XPathProjectComponent) InputExpressionDialog(org.intellij.plugins.xpathView.ui.InputExpressionDialog)

Aggregations

FindProgressIndicator (com.intellij.find.FindProgressIndicator)1 Config (org.intellij.plugins.xpathView.Config)1 XPathEvalAction (org.intellij.plugins.xpathView.XPathEvalAction)1 XPathProjectComponent (org.intellij.plugins.xpathView.XPathProjectComponent)1 InputExpressionDialog (org.intellij.plugins.xpathView.ui.InputExpressionDialog)1 NotNull (org.jetbrains.annotations.NotNull)1