com.intellij.ide.util.gotoByName.ChooseByNamePopup Java Examples

The following examples show how to use com.intellij.ide.util.gotoByName.ChooseByNamePopup. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: GoToClassTest.java    From protobuf-jetbrains-plugin with Apache License 2.0 6 votes vote down vote up
private List<Object> calcPopupElements(ChooseByNamePopup popup, String text, boolean checkboxState) {
    List<Object> elements = new ArrayList<>();
    CountDownLatch latch = new CountDownLatch(1);
    //noinspection KotlinInternalInJava
    SwingUtilities.invokeLater(() ->
            popup.scheduleCalcElements(text, checkboxState, ModalityState.NON_MODAL, SelectMostRelevant.INSTANCE,
                    set -> {
                        elements.addAll(set);
                        latch.countDown();
                    }));
    try {
        if (!latch.await(10, TimeUnit.SECONDS)) {
            Assert.fail();
        }
    } catch (InterruptedException e) {
        Thread.currentThread().interrupt();
    }
    return elements;
}
 
Example #2
Source File: ChooseTargetContributor.java    From buck with Apache License 2.0 6 votes vote down vote up
CurrentInputText(Project project) {
  ChooseByNamePopup chooseByNamePopup =
      project.getUserData(ChooseByNamePopup.CHOOSE_BY_NAME_POPUP_IN_PROJECT_KEY);
  if (chooseByNamePopup == null) {
    buildDir = null;
    hasBuildRule = false;
    return;
  }
  String currentText =
      chooseByNamePopup
          .getEnteredText()
          // Remove the begining //
          .replaceFirst("^/*", "");

  // check if we have as input a proper target
  int targetSeparatorIndex = currentText.lastIndexOf(TARGET_NAME_SEPARATOR);
  if (targetSeparatorIndex != -1) {
    hasBuildRule = true;
    buildDir = currentText.substring(0, targetSeparatorIndex);
  } else {
    hasBuildRule = false;
    buildDir = currentText;
  }
}
 
Example #3
Source File: GotoActionAction.java    From consulo with Apache License 2.0 6 votes vote down vote up
@Override
public void gotoActionPerformed(@Nonnull AnActionEvent e) {
  Project project = e.getProject();
  Component component = e.getData(PlatformDataKeys.CONTEXT_COMPONENT);
  Editor editor = e.getData(CommonDataKeys.EDITOR);

  FeatureUsageTracker.getInstance().triggerFeatureUsed("navigation.popup.action");
  GotoActionModel model = new GotoActionModel(project, component, editor);
  GotoActionCallback<Object> callback = new GotoActionCallback<Object>() {
    @Override
    public void elementChosen(@Nonnull ChooseByNamePopup popup, @Nonnull Object element) {
      if (project != null) {
        // if the chosen action displays another popup, don't populate it automatically with the text from this popup
        project.putUserData(ChooseByNamePopup.CHOOSE_BY_NAME_POPUP_IN_PROJECT_KEY, null);
      }
      String enteredText = popup.getTrimmedText();
      int modifiers = popup.isClosedByShiftEnter() ? InputEvent.SHIFT_MASK : 0;
      openOptionOrPerformAction(((GotoActionModel.MatchedValue)element).value, enteredText, project, component, modifiers);
    }
  };

  Pair<String, Integer> start = getInitialText(false, e);
  showNavigationPopup(callback, null, createPopup(project, model, start.first, start.second, component, e), false);
}
 
Example #4
Source File: GotoActionAction.java    From consulo with Apache License 2.0 6 votes vote down vote up
private static boolean processOptionInplace(Object value, ChooseByNamePopup popup, Component component, AnActionEvent e) {
  if (value instanceof BooleanOptionDescription) {
    BooleanOptionDescription option = (BooleanOptionDescription)value;
    option.setOptionState(!option.isOptionEnabled());
    repaint(popup);
    return true;
  }
  else if (value instanceof GotoActionModel.ActionWrapper) {
    AnAction action = ((GotoActionModel.ActionWrapper)value).getAction();
    if (action instanceof ToggleAction) {
      performAction(action, component, e, 0, () -> repaint(popup));
      return true;
    }
  }
  return false;
}
 
Example #5
Source File: GotoBaseAction.java    From CppTools with Apache License 2.0 6 votes vote down vote up
protected void gotoActionPerformed(AnActionEvent anActionEvent) {
  final Project project = (Project) anActionEvent.getDataContext().getData(DataConstants.PROJECT);

  final ChooseByNamePopup byNamePopup = ChooseByNamePopup.createPopup(
    project,
    new MyContributorsBasedGotoByModel(project, getNameContributor()),
    (PsiElement)null
  );

  byNamePopup.invoke(new ChooseByNamePopupComponent.Callback() {
    public void elementChosen(Object element) {
      ((NavigationItem)element).navigate(true);
    }
    public void onClose() {
      if (GotoBaseAction.this.getClass().equals(myInAction)) myInAction = null;
    }
  }, ModalityState.current(), false);
}
 
Example #6
Source File: LSPSymbolContributor.java    From lsp4intellij with Apache License 2.0 5 votes vote down vote up
@Override
public void processNames(@NotNull Processor<? super String> processor, @NotNull GlobalSearchScope globalSearchScope, @Nullable IdFilter idFilter) {
    String queryString = Optional.ofNullable(globalSearchScope.getProject())
        .map(p -> p.getUserData(ChooseByNamePopup.CURRENT_SEARCH_PATTERN)).orElse("");

    workspaceSymbolProvider.workspaceSymbols(queryString, globalSearchScope.getProject()).stream()
        .filter(ni -> globalSearchScope.accept(ni.getFile()))
        .map(NavigationItem::getName)
        .forEach(processor::process);
}
 
Example #7
Source File: SendProjectFileAction2.java    From SmartIM4IntelliJ with Apache License 2.0 5 votes vote down vote up
@Override public void elementChosen(ChooseByNamePopup chooseByNamePopup, Object o) {
    if (o != null && o instanceof PsiFile) {
        PsiFile file = (PsiFile)o;
        VirtualFile vf = file.getVirtualFile();
        if (vf != null) {
            File f = new File(vf.getCanonicalPath());
            if (f.exists()) {
                console.sendFile(f.getAbsolutePath());
            } else {
                console.send(vf.getCanonicalPath());
            }
        }
    }
}
 
Example #8
Source File: GoToNutzAtMappingAction.java    From NutzCodeInsight with Apache License 2.0 5 votes vote down vote up
@Override
public void elementChosen(ChooseByNamePopup popup, Object element) {
    if (element instanceof AtMappingNavigationItem) {
        AtMappingNavigationItem el = (AtMappingNavigationItem) element;
        if (el.canNavigate()) {
            el.navigate(true);
        }
    }
}
 
Example #9
Source File: ChooseTargetAction.java    From Buck-IntelliJ-Plugin with Apache License 2.0 5 votes vote down vote up
@Override
protected void gotoActionPerformed(AnActionEvent e) {
  final Project project = e.getData(CommonDataKeys.PROJECT);
  if (project == null) {
    return;
  }

  final ChooseTargetModel model = new ChooseTargetModel(project);
  GotoActionCallback<BuckBuildTarget> callback = new GotoActionCallback<BuckBuildTarget>() {
    @Override
    public void elementChosen(ChooseByNamePopup chooseByNamePopup, Object element) {
      if (element == null) {
        return;
      }

      BuckSettingsProvider buckSettingsProvider = BuckSettingsProvider.getInstance();
      if (buckSettingsProvider == null || buckSettingsProvider.getState() == null) {
        return;
      }

      ChooseTargetItem item = (ChooseTargetItem) element;
      if (buckSettingsProvider.getState().lastAlias != null) {
        buckSettingsProvider.getState().lastAlias.put(
            project.getBasePath(), item.getBuildTarget());
      }
      BuckToolWindowFactory.updateBuckToolWindowTitle(project);
    }
  };

  DefaultChooseByNameItemProvider provider =
      new DefaultChooseByNameItemProvider(getPsiContext(e));
  showNavigationPopup(e, model, callback, "Choose Build Target", true, false, provider);
}
 
Example #10
Source File: ChooseTargetContributor.java    From buck with Apache License 2.0 5 votes vote down vote up
private List<String> getBuildTargetFromBuildProjectFile(Project project, String buildDir) {
  List<String> names = new ArrayList<>();
  names.add(getAllBuildTargetsInSameDirectory(buildDir));
  names.addAll(
      BuckQueryAction.customExecuteForTargetCompletion(
          project,
          "//" + buildDir + TARGET_NAME_SEPARATOR,
          new Function<List<String>, Void>() {
            @Nullable
            @Override
            public Void apply(@Nullable List<String> strings) {
              ApplicationManager.getApplication()
                  .invokeLater(
                      new Runnable() {
                        @Override
                        public void run() {
                          ChooseByNamePopup chooseByNamePopup =
                              project.getUserData(
                                  ChooseByNamePopup.CHOOSE_BY_NAME_POPUP_IN_PROJECT_KEY);
                          // the user might have closed the window
                          if (chooseByNamePopup != null) {
                            // if we don't have them, just refresh the view when we do, if the
                            // window is still open
                            chooseByNamePopup.rebuildList(true);
                          }
                        }
                      });
              return null;
            }
          }));
  return names;
}
 
Example #11
Source File: SearchStringFilterFactory.java    From android-strings-search-plugin with Apache License 2.0 4 votes vote down vote up
public SearchStringFilter create(ChooseByNamePopup popup, SearchStringModel model) {
    return new SearchStringFilter(popup, model, project);
}
 
Example #12
Source File: SearchStringFilterFactory.java    From android-strings-search-plugin with Apache License 2.0 4 votes vote down vote up
private SearchStringFilter(ChooseByNamePopup popup, SearchStringModel model, Project project) {
    super(popup, model, SearchStringConfiguration.getInstance(project), project);
}
 
Example #13
Source File: SymfonySymbolSearchAction.java    From idea-php-symfony2-plugin with MIT License 4 votes vote down vote up
@Override
public void elementChosen(ChooseByNamePopup popup, Object element) {
    if(element instanceof NavigationItem) {
        ((NavigationItem) element).navigate(true);
    }
}
 
Example #14
Source File: GotoFileAction.java    From consulo with Apache License 2.0 4 votes vote down vote up
GotoFileFilter(final ChooseByNamePopup popup, GotoFileModel model, final Project project) {
  super(popup, model, GotoFileConfiguration.getInstance(project), project);
}
 
Example #15
Source File: GotoActionAction.java    From consulo with Apache License 2.0 4 votes vote down vote up
private static void repaint(@Nullable ChooseByNamePopup popup) {
  if (popup != null) {
    popup.repaintListImmediate();
  }
}
 
Example #16
Source File: ChooseByRouteNameFilter.java    From railways with MIT License 3 votes vote down vote up
/**
 * A constructor
 *
 * @param popup               a parent popup
 * @param model               a model for popup
 * @param filterConfiguration storage for selected filter values
 * @param project             a context project
 */
public ChooseByRouteNameFilter(@NotNull ChooseByNamePopup popup,
                               @NotNull FilteringGotoByModel<RequestMethod> model,
                               @NotNull ChooseByNameFilterConfiguration<RequestMethod> filterConfiguration,
                               @NotNull Project project) {
    super(popup, model, filterConfiguration, project);
}