com.intellij.openapi.options.SearchableConfigurable Java Examples

The following examples show how to use com.intellij.openapi.options.SearchableConfigurable. 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: VcsUpdateInfoScopeFilterConfigurable.java    From consulo with Apache License 2.0 6 votes vote down vote up
@javax.annotation.Nullable
@Override
public JComponent createComponent() {
  final JPanel panel = new JPanel(new FlowLayout(FlowLayout.LEFT, 0, 0));
  panel.add(myCheckbox);
  panel.add(myComboBox);
  panel.add(Box.createHorizontalStrut(UIUtil.DEFAULT_HGAP));
  panel.add(new LinkLabel("Edit scopes", null, new LinkListener() {
    @Override
    public void linkSelected(LinkLabel aSource, Object aLinkData) {
      final OptionsEditor optionsEditor = DataManager.getInstance().getDataContext(panel).getData(OptionsEditor.KEY);
      if (optionsEditor != null) {
        SearchableConfigurable configurable = optionsEditor.findConfigurableById(new ScopeChooserConfigurable(myProject).getId());
        if (configurable != null) {
          optionsEditor.select(configurable);
        }
      }
    }
  }));
  return panel;
}
 
Example #2
Source File: SearchUtil.java    From consulo with Apache License 2.0 6 votes vote down vote up
public static boolean isComponentHighlighted(String text, String option, final boolean force, final SearchableConfigurable configurable) {
  if (text == null || option == null || option.length() == 0) return false;
  final SearchableOptionsRegistrar searchableOptionsRegistrar = SearchableOptionsRegistrar.getInstance();
  final Set<String> words = searchableOptionsRegistrar.getProcessedWords(option);
  final Set<String> options =
    configurable != null ? searchableOptionsRegistrar.replaceSynonyms(words, configurable) : words;
  if (options == null || options.isEmpty()) {
    return text.toLowerCase().indexOf(option.toLowerCase()) != -1;
  }
  final Set<String> tokens = searchableOptionsRegistrar.getProcessedWords(text);
  if (!force) {
    options.retainAll(tokens);
    final boolean highlight = !options.isEmpty();
    return highlight || text.toLowerCase().indexOf(option.toLowerCase()) != -1;
  }
  else {
    options.removeAll(tokens);
    return options.isEmpty();
  }
}
 
Example #3
Source File: SearchUtil.java    From consulo with Apache License 2.0 6 votes vote down vote up
public static List<Configurable> expandGroup(final Configurable[] configurables) {
  List<Configurable> result = new ArrayList<Configurable>();
  ContainerUtil.addAll(result, configurables);
  for (Configurable each : configurables) {
    addChildren(each, result);
  }
  
  result = ContainerUtil.filter(result, new Condition<Configurable>() {
    @Override
    public boolean value(Configurable configurable) {
      return !(configurable instanceof SearchableConfigurable.Parent) || ((SearchableConfigurable.Parent)configurable).isVisible();
    }
  });
 
  return result;
}
 
Example #4
Source File: DebuggerConfigurable.java    From consulo with Apache License 2.0 5 votes vote down vote up
@Nonnull
@Override
public Configurable[] getConfigurables() {
  compute();

  if (myChildren.length == 0 && myRootConfigurable instanceof SearchableConfigurable.Parent) {
    return ((Parent)myRootConfigurable).getConfigurables();
  }
  else {
    return myChildren;
  }
}
 
Example #5
Source File: SearchUtil.java    From consulo with Apache License 2.0 5 votes vote down vote up
private static void processConfigurables(final Configurable[] configurables,
                                         final HashMap<SearchableConfigurable, TreeSet<OptionDescription>> options) {
  for (Configurable configurable : configurables) {
    if (configurable instanceof SearchableConfigurable) {
      TreeSet<OptionDescription> configurableOptions = new TreeSet<OptionDescription>();

      if (configurable instanceof Configurable.Composite) {
        final Configurable[] children = ((Configurable.Composite)configurable).getConfigurables();
        processConfigurables(children, options);
      }

      //ignore invisible root nodes
      if (configurable instanceof SearchableConfigurable.Parent && !((SearchableConfigurable.Parent)configurable).isVisible()) {
        continue;
      }

      options.put((SearchableConfigurable)configurable, configurableOptions);

      if (configurable instanceof MasterDetails) {
        final MasterDetails md = (MasterDetails)configurable;
        md.initUi();
        _processComponent(configurable, configurableOptions, md.getMaster());
        _processComponent(configurable, configurableOptions, md.getDetails().getComponent());
      }
      else {
        _processComponent(configurable, configurableOptions, configurable.createComponent());
      }
    }
  }
}
 
Example #6
Source File: SearchUtil.java    From consulo with Apache License 2.0 5 votes vote down vote up
public static Runnable lightOptions(final SearchableConfigurable configurable,
                                    final JComponent component,
                                    final String option,
                                    final GlassPanel glassPanel) {
  return new Runnable() {
    public void run() {
      if (!traverseComponentsTree(configurable, glassPanel, component, option, true)) {
        traverseComponentsTree(configurable, glassPanel, component, option, false);
      }
    }
  };
}
 
Example #7
Source File: SearchableOptionsRegistrarImpl.java    From consulo with Apache License 2.0 5 votes vote down vote up
@Override
public Set<String> replaceSynonyms(Set<String> options, SearchableConfigurable configurable) {
  final Set<String> result = new HashSet<>(options);
  for (String option : options) {
    final Set<String> synonyms = getSynonym(option, configurable);
    if (synonyms != null) {
      result.addAll(synonyms);
    }
    else {
      result.add(option);
    }
  }
  return result;
}
 
Example #8
Source File: SearchUtil.java    From consulo with Apache License 2.0 5 votes vote down vote up
public static Runnable lightOptions(final SearchableConfigurable configurable,
                                    final JComponent component,
                                    final String option,
                                    final GlassPanel glassPanel,
                                    final boolean forceSelect) {
  return new Runnable() {
    public void run() {
      traverseComponentsTree(configurable, glassPanel, component, option, forceSelect);
    }
  };
}
 
Example #9
Source File: OptionsTree.java    From consulo with Apache License 2.0 5 votes vote down vote up
@Nullable
public SearchableConfigurable findConfigurableById(@Nonnull String configurableId) {
  for (Configurable configurable : myConfigurable2Node.keySet()) {
    if (configurable instanceof SearchableConfigurable) {
      SearchableConfigurable searchableConfigurable = (SearchableConfigurable)configurable;
      if (configurableId.equals(searchableConfigurable.getId())) {
        return searchableConfigurable;
      }
    }
  }
  return null;
}
 
Example #10
Source File: DebuggerConfigurable.java    From consulo with Apache License 2.0 5 votes vote down vote up
private void compute() {
  if (myChildren != null) {
    return;
  }

  List<Configurable> configurables = new SmartList<>();
  configurables.add(new DataViewsConfigurable());

  computeMergedConfigurables(configurables);

  configurables.addAll(XDebuggerConfigurableProvider.getConfigurables(DebuggerSettingsCategory.ROOT));

  MergedCompositeConfigurable mergedGeneralConfigurable = computeGeneralConfigurables();
  if (configurables.isEmpty() && mergedGeneralConfigurable == null) {
    myRootConfigurable = null;
    myChildren = EMPTY_CONFIGURABLES;
  }
  else if (configurables.size() == 1) {
    Configurable firstConfigurable = configurables.get(0);
    if (mergedGeneralConfigurable == null) {
      myRootConfigurable = firstConfigurable;
      myChildren = EMPTY_CONFIGURABLES;
    }
    else {
      Configurable[] generalConfigurables = mergedGeneralConfigurable.children;
      Configurable[] mergedArray = new Configurable[generalConfigurables.length + 1];
      System.arraycopy(generalConfigurables, 0, mergedArray, 0, generalConfigurables.length);
      mergedArray[generalConfigurables.length] = firstConfigurable;
      myRootConfigurable = new MergedCompositeConfigurable("", "", mergedArray);
      myChildren = firstConfigurable instanceof SearchableConfigurable.Parent ? ((Parent)firstConfigurable).getConfigurables() : EMPTY_CONFIGURABLES;
    }
  }
  else {
    myChildren = configurables.toArray(new Configurable[configurables.size()]);
    myRootConfigurable = mergedGeneralConfigurable;
  }
}
 
Example #11
Source File: DesktopSettingsDialog.java    From consulo with Apache License 2.0 5 votes vote down vote up
private void saveCurrentConfigurable() {
  final Configurable current = myEditor.getContext().getCurrentConfigurable();
  if (current == null) return;

  final PropertiesComponent props = PropertiesComponent.getInstance(myProject);

  if (current instanceof SearchableConfigurable) {
    props.setValue(LAST_SELECTED_CONFIGURABLE, ((SearchableConfigurable)current).getId());
  }
  else {
    props.setValue(LAST_SELECTED_CONFIGURABLE, current.getClass().getName());
  }
}
 
Example #12
Source File: AvailablePluginsDialog.java    From consulo with Apache License 2.0 5 votes vote down vote up
public AvailablePluginsDialog(Component parent, SearchableConfigurable configurable, FilterComponent myFilter) {
  super(parent, configurable, BaseShowSettingsUtil.createDimensionKey(configurable), false);

  setOKButtonText(CommonBundle.message("close.action.name"));
  setOKButtonMnemonic('C');
  final String filter = myFilter.getFilter();

  if (!StringUtil.isEmptyOrSpaces(filter)) {
    final Runnable searchRunnable = configurable.enableSearch(filter);
    LOGGER.assertTrue(searchRunnable != null);
    searchRunnable.run();
  }
}
 
Example #13
Source File: IntentionSettingsPanel.java    From consulo with Apache License 2.0 5 votes vote down vote up
public Runnable showOption(final SearchableConfigurable configurable, final String option) {
  return new Runnable() {
    @Override
    public void run() {
      myIntentionSettingsTree.filter(myIntentionSettingsTree.filterModel(option, true));
      myIntentionSettingsTree.setFilter(option);
    }
  };
}
 
Example #14
Source File: CoverageLineMarkerRenderer.java    From consulo with Apache License 2.0 5 votes vote down vote up
@Override
public void actionPerformed(AnActionEvent e) {
  final ColorAndFontOptions colorAndFontOptions = new ColorAndFontOptions(){
    @Override
    protected List<ColorAndFontPanelFactory> createPanelFactories() {
      final GeneralColorsPage colorsPage = new GeneralColorsPage();
      final ColorAndFontPanelFactory panelFactory = new ColorAndFontPanelFactory() {
        @Nonnull
        @Override
        public NewColorAndFontPanel createPanel(@Nonnull ColorAndFontOptions options) {
          final SimpleEditorPreview preview = new SimpleEditorPreview(options, colorsPage);
          return NewColorAndFontPanel.create(preview, colorsPage.getDisplayName(), options, null, colorsPage);
        }

        @Nonnull
        @Override
        public String getPanelDisplayName() {
          return "Editor | " + getDisplayName() + " | " + colorsPage.getDisplayName();
        }
      };
      return Collections.singletonList(panelFactory);
    }
  };
  final Configurable[] configurables = colorAndFontOptions.buildConfigurables();
  try {
    final SearchableConfigurable general = colorAndFontOptions.findSubConfigurable(GeneralColorsPage.class);
    if (general != null) {
      final LineData lineData = getLineData(myLineNumber);
      ShowSettingsUtil.getInstance().editConfigurable(myEditor.getProject(), general,
                                                      general.enableSearch(getAttributesKey(lineData).getExternalName()));
    }
  }
  finally {
    for (Configurable configurable : configurables) {
      configurable.disposeUIResources();
    }
    colorAndFontOptions.disposeUIResources();
  }
}
 
Example #15
Source File: DesktopShowSettingsUtilImpl.java    From consulo with Apache License 2.0 5 votes vote down vote up
@Nullable
private static Configurable containsId(String id2Select, Configurable configurable) {
  if (configurable instanceof SearchableConfigurable && id2Select.equals(((SearchableConfigurable)configurable).getId())) {
    return configurable;
  }
  if (configurable instanceof SearchableConfigurable.Parent) {
    for (Configurable subConfigurable : ((SearchableConfigurable.Parent)configurable).getConfigurables()) {
      final Configurable config = containsId(id2Select, subConfigurable);
      if (config != null) return config;
    }
  }
  return null;
}
 
Example #16
Source File: SearchableOptionsRegistrarImpl.java    From consulo with Apache License 2.0 4 votes vote down vote up
@Override
public Set<String> getSynonym(final String option, @Nonnull final SearchableConfigurable configurable) {
  loadHugeFilesIfNecessary();
  return myHighlightOption2Synonym.get(Pair.create(option, configurable.getId()));
}
 
Example #17
Source File: VcsManagerConfigurable.java    From consulo with Apache License 2.0 4 votes vote down vote up
private Configurable createVcsConfigurableWrapper(final VcsDescriptor vcs) {
  final NotNullLazyValue<Configurable> delegate = new NotNullLazyValue<Configurable>() {
    @Nonnull
    @Override
    protected Configurable compute() {
      return ProjectLevelVcsManager.getInstance(myProject).findVcsByName(vcs.getName()).getConfigurable();
    }
  };
  return new SearchableConfigurable(){

    @Override
    @Nls
    public String getDisplayName() {
      return vcs.getDisplayName();
    }

    @Override
    public String getHelpTopic() {
      return delegate.getValue().getHelpTopic();
    }

    @Override
    public JComponent createComponent() {
      return delegate.getValue().createComponent();
    }

    @Override
    public boolean isModified() {
      return delegate.getValue().isModified();
    }

    @Override
    public void apply() throws ConfigurationException {
      delegate.getValue().apply();
    }

    @Override
    public void reset() {
      delegate.getValue().reset();
    }

    @Override
    public void disposeUIResources() {
      delegate.getValue().disposeUIResources();
    }

    @Override
    @Nonnull
    public String getId() {
      return "vcs." + getDisplayName();
    }

    @Override
    public Runnable enableSearch(String option) {
      return null;
    }

    @Override
    public String toString() {
      return "VcsConfigurable for "+vcs.getDisplayName();
    }
  };
}
 
Example #18
Source File: SearchUtil.java    From consulo with Apache License 2.0 4 votes vote down vote up
private static boolean traverseComponentsTree(final SearchableConfigurable configurable,
                                              GlassPanel glassPanel,
                                              JComponent rootComponent,
                                              String option,
                                              boolean force) {

  rootComponent.putClientProperty(HIGHLIGHT_WITH_BORDER, null);

  if (option == null || option.trim().length() == 0) return false;
  boolean highlight = false;
  if (rootComponent instanceof JCheckBox) {
    final JCheckBox checkBox = ((JCheckBox)rootComponent);
    if (isComponentHighlighted(checkBox.getText(), option, force, configurable)) {
      highlight = true;
      glassPanel.addSpotlight(checkBox);
    }
  }
  else if (rootComponent instanceof JRadioButton) {
    final JRadioButton radioButton = ((JRadioButton)rootComponent);
    if (isComponentHighlighted(radioButton.getText(), option, force, configurable)) {
      highlight = true;
      glassPanel.addSpotlight(radioButton);
    }
  }
  else if (rootComponent instanceof JLabel) {
    final JLabel label = ((JLabel)rootComponent);
    if (isComponentHighlighted(label.getText(), option, force, configurable)) {
      highlight = true;
      glassPanel.addSpotlight(label);
    }
  }
  else if (rootComponent instanceof JButton) {
    final JButton button = ((JButton)rootComponent);
    if (isComponentHighlighted(button.getText(), option, force, configurable)) {
      highlight = true;
      glassPanel.addSpotlight(button);
    }
  }
  else if (rootComponent instanceof JTabbedPane) {
    final JTabbedPane tabbedPane = (JTabbedPane)rootComponent;
    final String path = SearchableOptionsRegistrar.getInstance().getInnerPath(configurable, option);
    if (path != null) {
      final int index = getSelection(path, tabbedPane);
      if (index > -1 && index < tabbedPane.getTabCount()) {
        if (tabbedPane.getTabComponentAt(index) instanceof JComponent) {
          glassPanel.addSpotlight((JComponent)tabbedPane.getTabComponentAt(index));
        }
      }
    }
  }


  final Component[] components = rootComponent.getComponents();
  for (Component component : components) {
    if (component instanceof JComponent) {
      final boolean innerHighlight = traverseComponentsTree(configurable, glassPanel, (JComponent)component, option, force);

      if (!highlight && !innerHighlight) {
        final Border border = rootComponent.getBorder();
        if (border instanceof TitledBorder) {
          final String title = ((TitledBorder)border).getTitle();
          if (isComponentHighlighted(title, option, force, configurable)) {
            highlight = true;
            glassPanel.addSpotlight(rootComponent);
            rootComponent.putClientProperty(HIGHLIGHT_WITH_BORDER, Boolean.TRUE);
          }
        }
      }


      if (innerHighlight) {
        highlight = true;
      }
    }
  }
  return highlight;
}
 
Example #19
Source File: SearchUtil.java    From consulo with Apache License 2.0 4 votes vote down vote up
public static void processProjectConfigurables(Project project, HashMap<SearchableConfigurable, TreeSet<OptionDescription>> options) {
  Configurable[] configurables = BaseShowSettingsUtil.buildConfigurables(project);
  processConfigurables(configurables, options);
}
 
Example #20
Source File: SearchableOptionsHelper.java    From intellij with Apache License 2.0 4 votes vote down vote up
public SearchableOptionsHelper(SearchableConfigurable configurable) {
  this.registrar = SearchableOptionsRegistrar.getInstance();
  this.displayName = configurable.getDisplayName();
  this.configurableId = configurable.getId();
}
 
Example #21
Source File: SearchableOptionsRegistrarImpl.java    From consulo with Apache License 2.0 4 votes vote down vote up
@Override
@Nonnull
public ConfigurableHit getConfigurables(Configurable[] allConfigurables, final DocumentEvent.EventType type, Set<Configurable> configurables, String option, Project project) {

  final ConfigurableHit hits = new ConfigurableHit();
  final Set<Configurable> contentHits = hits.getContentHits();

  Set<String> options = getProcessedWordsWithoutStemming(option);
  if (configurables == null) {
    contentHits.addAll(SearchUtil.expandGroup(allConfigurables));
  }
  else {
    contentHits.addAll(configurables);
  }

  String optionToCheck = option.trim().toLowerCase();
  for (Configurable each : contentHits) {
    if (each.getDisplayName() == null) continue;
    final String displayName = each.getDisplayName().toLowerCase();
    final List<String> allWords = StringUtil.getWordsIn(displayName);
    if (displayName.contains(optionToCheck)) {
      hits.getNameFullHits().add(each);
      hits.getNameHits().add(each);
    }
    for (String eachWord : allWords) {
      if (eachWord.startsWith(optionToCheck)) {
        hits.getNameHits().add(each);
        break;
      }
    }

    if (options.isEmpty()) {
      hits.getNameHits().add(each);
      hits.getNameFullHits().add(each);
    }
  }

  final Set<Configurable> currentConfigurables = new HashSet<>(contentHits);
  if (options.isEmpty()) { //operate with substring
    String[] components = REG_EXP.split(optionToCheck);
    if (components.length > 0) {
      Collections.addAll(options, components);
    }
    else {
      options.add(option);
    }
  }
  Set<String> helpIds = null;
  for (String opt : options) {
    final Set<OptionDescription> optionIds = getAcceptableDescriptions(opt);
    if (optionIds == null) {
      contentHits.clear();
      return hits;
    }
    final Set<String> ids = new HashSet<>();
    for (OptionDescription id : optionIds) {
      ids.add(id.getConfigurableId());
    }
    if (helpIds == null) {
      helpIds = ids;
    }
    helpIds.retainAll(ids);
  }
  if (helpIds != null) {
    for (Iterator<Configurable> it = contentHits.iterator(); it.hasNext(); ) {
      Configurable configurable = it.next();
      if (CodeStyleFacade.getInstance(project).isUnsuitableCodeStyleConfigurable(configurable)) {
        it.remove();
        continue;
      }
      if (!(configurable instanceof SearchableConfigurable && helpIds.contains(((SearchableConfigurable)configurable).getId()))) {
        it.remove();
      }
    }
  }
  if (currentConfigurables.equals(contentHits) && !(configurables == null && type == DocumentEvent.EventType.CHANGE)) {
    return getConfigurables(allConfigurables, DocumentEvent.EventType.CHANGE, null, option, project);
  }
  return hits;
}
 
Example #22
Source File: DefaultSearchableConfigurable.java    From consulo with Apache License 2.0 4 votes vote down vote up
public DefaultSearchableConfigurable(final SearchableConfigurable delegate) {
  myDelegate = delegate;
}
 
Example #23
Source File: OptionsTree.java    From consulo with Apache License 2.0 4 votes vote down vote up
private static boolean isInvisibleNode(final Configurable child) {
  return child instanceof SearchableConfigurable.Parent && !((SearchableConfigurable.Parent)child).isVisible();
}
 
Example #24
Source File: OptionsEditor.java    From consulo with Apache License 2.0 4 votes vote down vote up
@Nullable
public SearchableConfigurable findConfigurableById(@Nonnull String configurableId) {
  return myTree.findConfigurableById(configurableId);
}
 
Example #25
Source File: OptionsEditor.java    From consulo with Apache License 2.0 4 votes vote down vote up
private boolean isEmptyParent(Configurable configurable) {
  return configurable instanceof SearchableConfigurable.Parent && !((SearchableConfigurable.Parent)configurable).hasOwnContent();
}
 
Example #26
Source File: SearchableOptionsRegistrar.java    From consulo with Apache License 2.0 4 votes vote down vote up
@Nullable
public abstract String getInnerPath(SearchableConfigurable configurable, String option);
 
Example #27
Source File: SearchableTextHelper.java    From intellij with Apache License 2.0 4 votes vote down vote up
public SearchableTextHelper(SearchableConfigurable configurable) {
  this(configurable.getId(), configurable.getDisplayName());
}
 
Example #28
Source File: SearchableOptionsRegistrar.java    From consulo with Apache License 2.0 votes vote down vote up
public abstract Set<String> replaceSynonyms(Set<String> options, SearchableConfigurable configurable); 
Example #29
Source File: SearchableOptionsRegistrar.java    From consulo with Apache License 2.0 votes vote down vote up
public abstract Set<String> getSynonym(final String option, @Nonnull final SearchableConfigurable configurable);