Пример #1
0
  private void initReplaceToolBars() {
    DefaultActionGroup actionGroup1 = new DefaultActionGroup("replace bar 1", false);
    myReplaceActionsToolbar1 =
        (ActionToolbarImpl)
            ActionManager.getInstance()
                .createActionToolbar(ActionPlaces.EDITOR_TOOLBAR, actionGroup1, true);
    myReplaceActionsToolbar1.setForceMinimumSize(true);
    final JButton myReplaceButton = new JButton("Replace");
    myReplaceButton.setFocusable(false);
    myReplaceButton.addActionListener(
        new ActionListener() {
          @Override
          public void actionPerformed(ActionEvent actionEvent) {
            replaceCurrent();
          }
        });

    final JButton myReplaceAllButton = new JButton("Replace all");
    myReplaceAllButton.setFocusable(false);
    myReplaceAllButton.addActionListener(
        new ActionListener() {
          @Override
          public void actionPerformed(ActionEvent actionEvent) {
            myLivePreviewController.performReplaceAll();
          }
        });

    final JButton myExcludeButton = new JButton("");
    myExcludeButton.setFocusable(false);
    myExcludeButton.addActionListener(
        new ActionListener() {
          @Override
          public void actionPerformed(ActionEvent actionEvent) {
            myLivePreviewController.exclude();
            moveCursor(SearchResults.Direction.DOWN);
          }
        });

    if (!UISettings.getInstance().DISABLE_MNEMONICS_IN_CONTROLS) {
      myReplaceButton.setMnemonic('p');
      myReplaceAllButton.setMnemonic('a');
      myExcludeButton.setMnemonic('l');
    }

    actionGroup1.addAction(
        new DefaultCustomComponentAction(myReplaceButton) {
          @Override
          public void update(AnActionEvent e) {
            myReplaceButton.setEnabled(canReplaceCurrent());
          }
        });
    actionGroup1.addAction(
        new DefaultCustomComponentAction(myReplaceAllButton) {
          @Override
          public void update(AnActionEvent e) {
            myReplaceAllButton.setEnabled(mySearchResults != null && mySearchResults.hasMatches());
          }
        });
    actionGroup1.addAction(
        new DefaultCustomComponentAction(myExcludeButton) {
          @Override
          public void update(AnActionEvent e) {
            FindResult cursor = mySearchResults != null ? mySearchResults.getCursor() : null;
            myExcludeButton.setEnabled(cursor != null);
            myExcludeButton.setText(
                cursor != null && mySearchResults.isExcluded(cursor) ? "Include" : "Exclude");
          }
        });

    myReplaceActionsToolbar1.setLayoutPolicy(ActionToolbar.AUTO_LAYOUT_POLICY);
    myReplaceActionsToolbar1.setBorder(null);
    myReplaceActionsToolbar1.setOpaque(false);
    DefaultActionGroup actionGroup2 = new DefaultActionGroup("replace bar 2", false);
    myReplaceActionsToolbar2 =
        (ActionToolbarImpl)
            ActionManager.getInstance()
                .createActionToolbar(ActionPlaces.EDITOR_TOOLBAR, actionGroup2, true);
    actionGroup2.addAction(new TogglePreserveCaseAction(this));
    actionGroup2.addAction(new ToggleSelectionOnlyAction(this));
    myReplaceActionsToolbar2.setLayoutPolicy(ActionToolbar.AUTO_LAYOUT_POLICY);
    myReplaceActionsToolbar2.setBorder(null);
    myReplaceActionsToolbar2.setOpaque(false);
    Utils.setSmallerFontForChildren(myReplaceActionsToolbar1);
    Utils.setSmallerFontForChildren(myReplaceActionsToolbar2);
  }
Пример #2
0
  private void initSearchToolbars() {
    DefaultActionGroup actionGroup1 = new DefaultActionGroup("search bar 1", false);
    mySearchActionsToolbar1 =
        (ActionToolbarImpl)
            ActionManager.getInstance()
                .createActionToolbar(ActionPlaces.EDITOR_TOOLBAR, actionGroup1, true);
    mySearchActionsToolbar1.setForceMinimumSize(true);
    mySearchActionsToolbar1.setReservePlaceAutoPopupIcon(false);
    mySearchActionsToolbar1.setSecondaryButtonPopupStateModifier(
        new ActionToolbarImpl.PopupStateModifier() {
          @Override
          public int getModifiedPopupState() {
            return ActionButtonComponent.PUSHED;
          }

          @Override
          public boolean willModify() {
            return myFindModel.getSearchContext() != FindModel.SearchContext.ANY;
          }
        });
    mySearchActionsToolbar1.setSecondaryActionsTooltip(
        "More Options(" + ShowMoreOptions.SHORT_CUT + ")");

    actionGroup1.add(new PrevOccurrenceAction(this, mySearchFieldWrapper));
    actionGroup1.add(new NextOccurrenceAction(this, mySearchFieldWrapper));
    actionGroup1.add(new FindAllAction(this));
    actionGroup1.addSeparator();
    actionGroup1.add(new AddOccurrenceAction(this));
    actionGroup1.add(new RemoveOccurrenceAction(this));
    actionGroup1.add(new SelectAllAction(this));
    // actionGroup1.addSeparator();
    // actionGroup1.add(new ToggleMultiline(this));//todo get rid of it!
    actionGroup1.addSeparator();

    actionGroup1.addAction(new ToggleInCommentsAction(this)).setAsSecondary(true);
    actionGroup1.addAction(new ToggleInLiteralsOnlyAction(this)).setAsSecondary(true);
    actionGroup1.addAction(new ToggleExceptCommentsAction(this)).setAsSecondary(true);
    actionGroup1.addAction(new ToggleExceptLiteralsAction(this)).setAsSecondary(true);
    actionGroup1.addAction(new ToggleExceptCommentsAndLiteralsAction(this)).setAsSecondary(true);

    DefaultActionGroup actionGroup2 = new DefaultActionGroup("search bar 2", false);
    mySearchActionsToolbar2 =
        (ActionToolbarImpl)
            ActionManager.getInstance()
                .createActionToolbar(ActionPlaces.EDITOR_TOOLBAR, actionGroup2, true);
    actionGroup2.add(new ToggleMatchCase(this));
    actionGroup2.add(new ToggleRegex(this));
    actionGroup2.add(new ToggleWholeWordsOnlyAction(this));

    myMatchInfoLabel =
        new JLabel() {
          @Override
          public Font getFont() {
            Font font = super.getFont();
            return font != null ? font.deriveFont(Font.BOLD) : null;
          }
        };
    myMatchInfoLabel.setBorder(JBUI.Borders.empty(2, 20, 0, 20));

    myClickToHighlightLabel =
        new LinkLabel<Object>(
            "Click to highlight",
            null,
            new LinkListener<Object>() {
              @Override
              public void linkSelected(LinkLabel aSource, Object aLinkData) {
                setMatchesLimit(Integer.MAX_VALUE);
                updateResults(true);
              }
            });
    myClickToHighlightLabel.setVisible(false);

    mySearchActionsToolbar2 =
        (ActionToolbarImpl)
            ActionManager.getInstance()
                .createActionToolbar(ActionPlaces.EDITOR_TOOLBAR, actionGroup2, true);
    actionGroup2.add(new DefaultCustomComponentAction(myMatchInfoLabel));
    actionGroup2.add(new DefaultCustomComponentAction(myClickToHighlightLabel));

    mySearchActionsToolbar1.setLayoutPolicy(ActionToolbar.AUTO_LAYOUT_POLICY);
    mySearchActionsToolbar2.setLayoutPolicy(ActionToolbar.AUTO_LAYOUT_POLICY);
    mySearchActionsToolbar1.setBorder(null);
    mySearchActionsToolbar2.setBorder(null);
    mySearchActionsToolbar1.setOpaque(false);
    mySearchActionsToolbar2.setOpaque(false);

    new ShowMoreOptions(mySearchActionsToolbar1, mySearchFieldWrapper);
    Utils.setSmallerFontForChildren(mySearchActionsToolbar1);
    Utils.setSmallerFontForChildren(mySearchActionsToolbar2);
  }