private DefaultActionGroup createGearPopupGroup() {
    final DefaultActionGroup group = new DefaultActionGroup();

    if (myAdditionalGearActions != null) {
      addSorted(group, myAdditionalGearActions);
      group.addSeparator();
    }
    group.addAction(myToggleToolbarGroup).setAsSecondary(true);
    if (myInfo.isDocked()) {
      group.add(myToggleAutoHideModeAction);
      group.add(myToggleDockModeAction);
      group.add(myToggleFloatingModeAction);
      group.add(myToggleWindowedModeAction);
      group.add(myToggleSideModeAction);
    } else if (myInfo.isFloating()) {
      group.add(myToggleAutoHideModeAction);
      group.add(myToggleFloatingModeAction);
      group.add(myToggleWindowedModeAction);
    } else if (myInfo.isWindowed()) {
      group.add(myToggleFloatingModeAction);
      group.add(myToggleWindowedModeAction);
    } else if (myInfo.isSliding()) {
      if (!ToolWindowId.PREVIEW.equals(myInfo.getId())) {
        group.add(myToggleDockModeAction);
      }
      group.add(myToggleFloatingModeAction);
      group.add(myToggleWindowedModeAction);
      group.add(myToggleSideModeAction);
    }
    return group;
  }
  public final ActionGroup createPopupGroup(boolean skipHideAction) {
    final DefaultActionGroup group = createGearPopupGroup();
    if (!ToolWindowId.PREVIEW.equals(myInfo.getId())) {
      group.add(myToggleContentUiTypeAction);
    }

    final DefaultActionGroup moveGroup =
        new DefaultActionGroup(UIBundle.message("tool.window.move.to.action.group.name"), true);
    final ToolWindowAnchor anchor = myInfo.getAnchor();
    if (anchor != ToolWindowAnchor.TOP) {
      final AnAction topAction =
          new ChangeAnchorAction(
              UIBundle.message("tool.window.move.to.top.action.name"), ToolWindowAnchor.TOP);
      moveGroup.add(topAction);
    }
    if (anchor != ToolWindowAnchor.LEFT) {
      final AnAction leftAction =
          new ChangeAnchorAction(
              UIBundle.message("tool.window.move.to.left.action.name"), ToolWindowAnchor.LEFT);
      moveGroup.add(leftAction);
    }
    if (anchor != ToolWindowAnchor.BOTTOM) {
      final AnAction bottomAction =
          new ChangeAnchorAction(
              UIBundle.message("tool.window.move.to.bottom.action.name"), ToolWindowAnchor.BOTTOM);
      moveGroup.add(bottomAction);
    }
    if (anchor != ToolWindowAnchor.RIGHT) {
      final AnAction rightAction =
          new ChangeAnchorAction(
              UIBundle.message("tool.window.move.to.right.action.name"), ToolWindowAnchor.RIGHT);
      moveGroup.add(rightAction);
    }
    group.add(moveGroup);

    DefaultActionGroup resize =
        new DefaultActionGroup(ActionsBundle.groupText("ResizeToolWindowGroup"), true);
    resize.add(new ResizeToolWindowAction.Left(myToolWindow, this));
    resize.add(new ResizeToolWindowAction.Right(myToolWindow, this));
    resize.add(new ResizeToolWindowAction.Up(myToolWindow, this));
    resize.add(new ResizeToolWindowAction.Down(myToolWindow, this));
    resize.add(ActionManager.getInstance().getAction("MaximizeToolWindow"));

    group.add(resize);
    if (!skipHideAction) {
      group.addSeparator();
      group.add(new HideAction());
    }
    return group;
  }
  @Override
  protected JComponent createCenterPanel() {
    JPanel panel = new JPanel(new BorderLayout());

    // Toolbar

    DefaultActionGroup group = new DefaultActionGroup();

    fillToolbarActions(group);

    group.addSeparator();

    ExpandAllAction expandAllAction = new ExpandAllAction();
    expandAllAction.registerCustomShortcutSet(
        new CustomShortcutSet(
            KeymapManager.getInstance()
                .getActiveKeymap()
                .getShortcuts(IdeActions.ACTION_EXPAND_ALL)),
        myTree);
    group.add(expandAllAction);

    CollapseAllAction collapseAllAction = new CollapseAllAction();
    collapseAllAction.registerCustomShortcutSet(
        new CustomShortcutSet(
            KeymapManager.getInstance()
                .getActiveKeymap()
                .getShortcuts(IdeActions.ACTION_COLLAPSE_ALL)),
        myTree);
    group.add(collapseAllAction);

    panel.add(
        ActionManager.getInstance()
            .createActionToolbar(ActionPlaces.UNKNOWN, group, true)
            .getComponent(),
        BorderLayout.NORTH);

    // Tree
    expandFirst();
    defaultExpandTree();
    installSpeedSearch();

    JScrollPane scrollPane = ScrollPaneFactory.createScrollPane(myTree);
    scrollPane.setPreferredSize(new Dimension(350, 450));
    panel.add(scrollPane, BorderLayout.CENTER);

    return panel;
  }
 private static void addSorted(DefaultActionGroup main, ActionGroup group) {
   final AnAction[] children = group.getChildren(null);
   boolean hadSecondary = false;
   for (AnAction action : children) {
     if (group.isPrimary(action)) {
       main.add(action);
     } else {
       hadSecondary = true;
     }
   }
   if (hadSecondary) {
     main.addSeparator();
     for (AnAction action : children) {
       if (!group.isPrimary(action)) {
         main.addAction(action).setAsSecondary(true);
       }
     }
   }
   String separatorText = group.getTemplatePresentation().getText();
   if (children.length > 0 && !StringUtil.isEmpty(separatorText)) {
     main.addAction(new Separator(separatorText), Constraints.FIRST);
   }
 }
示例#5
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);
  }