예제 #1
0
  public final void update(final AnActionEvent e) {
    super.update(e);

    ActionPlace place = e.getData(MPSDataKeys.PLACE);

    if (e.getInputEvent() instanceof KeyEvent) {
      if (!getPlaces().contains(null)) {
        if (!getPlaces().contains(place)) {
          disable(e.getPresentation());
          return;
        }
      }
    }

    // TODO rewrite! do not start read action in EDT directly (to avoid UI freeze)
    ModelAccess.instance()
        .runReadAction(
            new Runnable() {
              public void run() {
                if (myDisableOnNoProject && e.getData(PlatformDataKeys.PROJECT) == null) {
                  disable(e.getPresentation());
                  return;
                }
                THashMap<String, Object> params = new THashMap<String, Object>();
                if (!collectActionData(e, params)) {
                  disable(e.getPresentation());
                  return;
                }
                doUpdate(e, params);
              }
            });
  }
예제 #2
0
 private void mousePressedInIconsArea(MouseEvent e) {
   EditorMessageIconRenderer iconRenderer = getIconRendererUnderMouse(e);
   if (iconRenderer != null) {
     if (e.getButton() == MouseEvent.BUTTON3) {
       JPopupMenu popupMenu = iconRenderer.getPopupMenu();
       if (popupMenu != null && e.getID() == MouseEvent.MOUSE_PRESSED) {
         e.consume();
         Component component = e.getComponent();
         popupMenu.show(component == null ? myEditorComponent : component, e.getX(), e.getY());
       }
       return;
     }
     AnAction action = iconRenderer.getClickAction();
     if (e.getButton() == MouseEvent.BUTTON1 && action != null) {
       if (e.getID() == MouseEvent.MOUSE_CLICKED) {
         AnActionEvent actionEvent =
             new AnActionEvent(
                 e,
                 new LeftEditorHighlighterDataContext(myEditorComponent, iconRenderer.getNode()),
                 ICON_AREA,
                 action.getTemplatePresentation(),
                 ActionManager.getInstance(),
                 e.getModifiers());
         action.update(actionEvent);
         action.actionPerformed(actionEvent);
       }
       e.consume();
     }
   }
 }
예제 #3
0
  public void update(AnActionEvent e) {
    super.update(e);

    final Project project = e.getData(DataKeys.PROJECT);
    final VirtualFile file = e.getData(DataKeys.VIRTUAL_FILE);

    boolean visible =
        project != null
            && file != null
            && !file.isDirectory()
            && file.getFileType() == CppSupportLoader.CPP_FILETYPE
            && !Communicator.isHeaderFile(file);
    boolean enabled = visible;

    if (!visible) {
      visible = ActionPlaces.MAIN_MENU.equals(e.getPlace());
    }

    e.getPresentation().setEnabled(enabled);
    e.getPresentation().setVisible(visible);

    if (visible) {
      final String s =
          "Do c&ompile for " + (file != null ? file.getName() : "selected c/c++ fileToCompile");
      e.getPresentation().setText(s);
      e.getPresentation().setDescription(s);
    }
  }
  @Override
  public void update(AnActionEvent e) {
    super.update(e);

    boolean visible = isActionAvailable(e);

    final Presentation presentation = e.getPresentation();
    presentation.setVisible(visible);
    presentation.setEnabled(visible);
  }
 @Override
 public void update(@NotNull AnActionEvent e) {
   AnAction action = getAction(e);
   if (action != null) {
     e.getPresentation().setVisible(true);
     action.update(e);
   } else {
     e.getPresentation().setVisible(false);
   }
 }
 public static void invokeNamedAction(final String actionId) {
   final AnAction action = ActionManager.getInstance().getAction(actionId);
   assertNotNull(action);
   final Presentation presentation = new Presentation();
   @SuppressWarnings("deprecation")
   final DataContext context = DataManager.getInstance().getDataContext();
   final AnActionEvent event =
       new AnActionEvent(null, context, "", presentation, ActionManager.getInstance(), 0);
   action.update(event);
   Assert.assertTrue(presentation.isEnabled());
   action.actionPerformed(event);
 }
 public static void performReferenceCopy(DataContext dataContext) {
   ActionManager actionManager = ActionManager.getInstance();
   AnAction action = actionManager.getAction(IdeActions.ACTION_COPY_REFERENCE);
   AnActionEvent event =
       new AnActionEvent(
           null,
           dataContext,
           "",
           action.getTemplatePresentation(),
           ActionManager.getInstance(),
           0);
   action.update(event);
   Assert.assertTrue(event.getPresentation().isEnabled());
   action.actionPerformed(event);
 }
    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 JComponent createSettingsAndDocs() {
      JPanel panel = new NonOpaquePanel(new BorderLayout());
      NonOpaquePanel toolbar = new NonOpaquePanel();
      AnAction register = ActionManager.getInstance().getAction("Register");
      boolean registeredVisible = false;
      if (register != null) {
        AnActionEvent e =
            AnActionEvent.createFromAnAction(
                register,
                null,
                ActionPlaces.WELCOME_SCREEN,
                DataManager.getInstance().getDataContext(this));
        register.update(e);
        Presentation presentation = e.getPresentation();
        if (presentation.isEnabled()) {
          ActionLink registerLink = new ActionLink("Register", register);
          registerLink.setNormalColor(getLinkNormalColor());
          NonOpaquePanel button = new NonOpaquePanel(new BorderLayout());
          button.setBorder(JBUI.Borders.empty(4, 10));
          button.add(registerLink);
          installFocusable(button, register, KeyEvent.VK_UP, KeyEvent.VK_RIGHT, true);
          NonOpaquePanel wrap = new NonOpaquePanel();
          wrap.setBorder(JBUI.Borders.emptyLeft(10));
          wrap.add(button);
          panel.add(wrap, BorderLayout.WEST);
          registeredVisible = true;
        }
      }

      toolbar.setLayout(new BoxLayout(toolbar, BoxLayout.X_AXIS));
      toolbar.add(
          createActionLink(
              "Configure",
              IdeActions.GROUP_WELCOME_SCREEN_CONFIGURE,
              AllIcons.General.GearPlain,
              !registeredVisible));
      toolbar.add(createActionLink("Get Help", IdeActions.GROUP_WELCOME_SCREEN_DOC, null, false));

      panel.add(toolbar, BorderLayout.EAST);

      panel.setBorder(JBUI.Borders.empty(0, 0, 8, 11));
      return panel;
    }
예제 #10
0
 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));
       }
     }
   }
 }
예제 #12
0
  private List<Button> buildButtons(ActionGroup group, String parentId) {
    AnAction[] actions = group.getChildren(null);

    List<Button> buttons = new ArrayList<Button>();

    for (AnAction action : actions) {
      Presentation presentation = action.getTemplatePresentation();
      if (!USE_ICONS) {
        presentation.setIcon(null);
      }
      if (action instanceof ActionGroup) {
        ActionGroup childGroup = (ActionGroup) action;
        if (childGroup.isPopup()) {
          final String id = String.valueOf(++nCards);
          createCardForGroup(childGroup, id, parentId);

          buttons.add(new Button(new ActivateCard(id), presentation));
        } else {
          buttons.addAll(buildButtons(childGroup, parentId));
        }
      } else {
        action.update(
            new AnActionEvent(
                null,
                DataManager.getInstance().getDataContext(this),
                ActionPlaces.WELCOME_SCREEN,
                presentation,
                ActionManager.getInstance(),
                0));
        if (presentation.isVisible()) {
          buttons.add(new Button(action, presentation));
        }
      }
    }
    return buttons;
  }
 public void update(AnActionEvent e) {
   super.update(e);
   Object data = ErrorTreeView.CURRENT_EXCEPTION_DATA_KEY.getData(e.getDataContext());
   e.getPresentation().setEnabled(data instanceof CvsException);
 }
 @Override
 public void update(AnActionEvent e) {
   super.update(e);
   myDataContext = e.getDataContext();
 }
예제 #15
0
 @Override
 public void update(AnActionEvent e) {
   super.update(e);
   e.getPresentation().setEnabled(myTextToCopy != null);
 }
 public void update(final AnActionEvent e) {
   super.update(e);
   e.getPresentation().setEnabled(!getSelectedScope(myLeftTree).isEmpty());
 }
 public void update(final AnActionEvent e) {
   super.update(e);
   e.getPresentation().setEnabled(getScope() != null);
 }
 @Override
 public void update(AnActionEvent e) {
   super.update(e);
   final Presentation presentation = e.getPresentation();
   presentation.setEnabled(allTargetsAreValid());
 }