private void initButton() {
   setIcon(myPresentation.getIcon());
   setEnabled(myPresentation.isEnabled());
   setText(myPresentation.getText());
   updateTooltipText(myPresentation.getDescription());
   updateButtonSize();
 }
Beispiel #2
0
 private static Presentation wrapIcon(Presentation presentation) {
   Icon original = presentation.getIcon();
   CenteredIcon centered =
       new CenteredIcon(original != null ? original : DEFAULT_ICON, 40, 40, false);
   presentation.setIcon(centered);
   return presentation;
 }
 private void updateIcon(AnAction action) {
   if (action instanceof Toggleable && myPresentation.getIcon() == null) {
     action.update(myEvent);
     if (Boolean.TRUE.equals(
         myEvent.getPresentation().getClientProperty(Toggleable.SELECTED_PROPERTY))) {
       setIcon(ourCheckedIcon);
       setDisabledIcon(IconLoader.getDisabledIcon(ourCheckedIcon));
     } else {
       setIcon(ourUncheckedIcon);
       setDisabledIcon(IconLoader.getDisabledIcon(ourUncheckedIcon));
     }
   } else {
     if (!SystemInfo.isMac || UISettings.getInstance().SHOW_ICONS_IN_MENUS) {
       Icon icon = myPresentation.getIcon();
       setIcon(icon);
       if (myPresentation.getDisabledIcon() != null) {
         setDisabledIcon(myPresentation.getDisabledIcon());
       } else {
         setDisabledIcon(IconLoader.getDisabledIcon(icon));
       }
     }
   }
 }
 private void updateIcon(AnAction action) {
   if (isToggleable()
       && (myPresentation.getIcon() == null
           || myInsideCheckedGroup
           || !UISettings.getInstance().SHOW_ICONS_IN_MENUS)) {
     action.update(myEvent);
     myToggled =
         Boolean.TRUE.equals(
             myEvent.getPresentation().getClientProperty(Toggleable.SELECTED_PROPERTY));
     if (ActionPlaces.MAIN_MENU.equals(myPlace) && SystemInfo.isMacSystemMenu
         || UIUtil.isUnderNimbusLookAndFeel()
         || UIUtil.isUnderWindowsLookAndFeel() && SystemInfo.isWin7OrNewer) {
       setState(myToggled);
     } else if (!(getUI() instanceof GtkMenuItemUI)) {
       if (myToggled) {
         setIcon(ourCheckedIcon);
         setDisabledIcon(IconLoader.getDisabledIcon(ourCheckedIcon));
       } else {
         setIcon(ourUncheckedIcon);
         setDisabledIcon(IconLoader.getDisabledIcon(ourUncheckedIcon));
       }
     }
   } else {
     if (UISettings.getInstance().SHOW_ICONS_IN_MENUS) {
       Icon icon = myPresentation.getIcon();
       if (action instanceof ToggleAction && ((ToggleAction) action).isSelected(myEvent)) {
         icon = new PoppedIcon(icon, 16, 16);
       }
       setIcon(icon);
       if (myPresentation.getDisabledIcon() != null) {
         setDisabledIcon(myPresentation.getDisabledIcon());
       } else {
         setDisabledIcon(IconLoader.getDisabledIcon(icon));
       }
     }
   }
 }
    private JComponent createActionPanel() {
      JPanel actions = new NonOpaquePanel();
      actions.setBorder(JBUI.Borders.emptyLeft(10));
      actions.setLayout(new BoxLayout(actions, BoxLayout.Y_AXIS));
      ActionManager actionManager = ActionManager.getInstance();
      ActionGroup quickStart =
          (ActionGroup) actionManager.getAction(IdeActions.GROUP_WELCOME_SCREEN_QUICKSTART);
      DefaultActionGroup group = new DefaultActionGroup();
      collectAllActions(group, quickStart);

      for (AnAction action : group.getChildren(null)) {
        JPanel button = new JPanel(new BorderLayout());
        button.setOpaque(false);
        button.setBorder(JBUI.Borders.empty(8, 20));
        AnActionEvent e =
            AnActionEvent.createFromAnAction(
                action,
                null,
                ActionPlaces.WELCOME_SCREEN,
                DataManager.getInstance().getDataContext(this));
        action.update(e);
        Presentation presentation = e.getPresentation();
        if (presentation.isVisible()) {
          String text = presentation.getText();
          if (text != null && text.endsWith("...")) {
            text = text.substring(0, text.length() - 3);
          }
          Icon icon = presentation.getIcon();
          if (icon.getIconHeight() != JBUI.scale(16) || icon.getIconWidth() != JBUI.scale(16)) {
            icon = JBUI.emptyIcon(16);
          }
          action = wrapGroups(action);
          ActionLink link = new ActionLink(text, icon, action, createUsageTracker(action));
          link.setPaintUnderline(false);
          link.setNormalColor(getLinkNormalColor());
          button.add(link);
          if (action instanceof WelcomePopupAction) {
            button.add(createArrow(link), BorderLayout.EAST);
          }
          installFocusable(button, action, KeyEvent.VK_UP, KeyEvent.VK_DOWN, true);
          actions.add(button);
        }
      }

      WelcomeScreenActionsPanel panel = new WelcomeScreenActionsPanel();
      panel.actions.add(actions);
      return panel.root;
    }
    private void appendAction(@NotNull AnAction action) {
      Presentation presentation = getPresentation(action);
      AnActionEvent event = createActionEvent(action);

      ActionUtil.performDumbAwareUpdate(action, event, true);
      if ((myShowDisabled || presentation.isEnabled()) && presentation.isVisible()) {
        String text = presentation.getText();
        if (myShowNumbers) {
          if (myCurrentNumber < 9) {
            text = "&" + (myCurrentNumber + 1) + ". " + text;
          } else if (myCurrentNumber == 9) {
            text = "&" + 0 + ". " + text;
          } else if (myUseAlphaAsNumbers) {
            text = "&" + (char) ('A' + myCurrentNumber - 10) + ". " + text;
          }
          myCurrentNumber++;
        } else if (myHonorActionMnemonics) {
          text =
              Presentation.restoreTextWithMnemonic(
                  text, action.getTemplatePresentation().getMnemonic());
        }

        Icon icon = presentation.getIcon();
        if (icon == null) {
          @NonNls final String actionId = ActionManager.getInstance().getId(action);
          if (actionId != null && actionId.startsWith("QuickList.")) {
            icon = AllIcons.Actions.QuickList;
          } else if (action instanceof Toggleable) {
            boolean toggled =
                Boolean.TRUE.equals(presentation.getClientProperty(Toggleable.SELECTED_PROPERTY));
            icon = toggled ? new IconWrapper(PlatformIcons.CHECK_ICON) : myEmptyIcon;
          } else {
            icon = myEmptyIcon;
          }
        } else {
          icon = new IconWrapper(icon);
        }
        boolean prependSeparator =
            (!myListModel.isEmpty() || mySeparatorText != null) && myPrependWithSeparator;
        assert text != null : action + " has no presentation";
        myListModel.add(
            new ActionItem(
                action, text, presentation.isEnabled(), icon, prependSeparator, mySeparatorText));
        myPrependWithSeparator = false;
        mySeparatorText = null;
      }
    }
    private AnAction wrapGroups(AnAction action) {
      if (action instanceof ActionGroup && ((ActionGroup) action).isPopup()) {
        final Pair<JPanel, JBList> panel =
            createActionGroupPanel(
                (ActionGroup) action,
                mySlidingPanel,
                new Runnable() {
                  @Override
                  public void run() {
                    goBack();
                  }
                });
        final Runnable onDone =
            new Runnable() {
              @Override
              public void run() {
                final JBList list = panel.second;
                ScrollingUtil.ensureSelectionExists(list);
                final ListSelectionListener[] listeners =
                    ((DefaultListSelectionModel) list.getSelectionModel())
                        .getListeners(ListSelectionListener.class);

                // avoid component cashing. This helps in case of LaF change
                for (ListSelectionListener listener : listeners) {
                  listener.valueChanged(
                      new ListSelectionEvent(
                          list, list.getSelectedIndex(), list.getSelectedIndex(), true));
                }
                list.requestFocus();
              }
            };
        final String name = action.getClass().getName();
        mySlidingPanel.add(name, panel.first);
        final Presentation p = action.getTemplatePresentation();
        return new DumbAwareAction(p.getText(), p.getDescription(), p.getIcon()) {
          @Override
          public void actionPerformed(@NotNull AnActionEvent e) {
            mySlidingPanel
                .getLayout()
                .swipe(mySlidingPanel, name, JBCardLayout.SwipeDirection.FORWARD, onDone);
          }
        };
      }
      return action;
    }