public boolean processAction(final InputEvent e, ActionProcessor processor) {
    ActionManagerEx actionManager = ActionManagerEx.getInstanceEx();
    final Project project = PlatformDataKeys.PROJECT.getData(myContext.getDataContext());
    final boolean dumb = project != null && DumbService.getInstance(project).isDumb();
    List<AnActionEvent> nonDumbAwareAction = new ArrayList<AnActionEvent>();
    for (final AnAction action : myContext.getActions()) {
      final Presentation presentation = myPresentationFactory.getPresentation(action);

      // Mouse modifiers are 0 because they have no any sense when action is invoked via keyboard
      final AnActionEvent actionEvent =
          processor.createEvent(
              e,
              myContext.getDataContext(),
              ActionPlaces.MAIN_MENU,
              presentation,
              ActionManager.getInstance());

      ActionUtil.performDumbAwareUpdate(action, actionEvent, true);

      if (dumb && !action.isDumbAware()) {
        if (Boolean.FALSE.equals(
            presentation.getClientProperty(ActionUtil.WOULD_BE_ENABLED_IF_NOT_DUMB_MODE))) {
          continue;
        }

        nonDumbAwareAction.add(actionEvent);
        continue;
      }

      if (!presentation.isEnabled()) {
        continue;
      }

      processor.onUpdatePassed(e, action, actionEvent);

      ((DataManagerImpl.MyDataContext) myContext.getDataContext())
          .setEventCount(IdeEventQueue.getInstance().getEventCount(), this);
      actionManager.fireBeforeActionPerformed(action, actionEvent.getDataContext(), actionEvent);
      Component component =
          PlatformDataKeys.CONTEXT_COMPONENT.getData(actionEvent.getDataContext());
      if (component != null && !component.isShowing()) {
        return true;
      }

      processor.performAction(e, action, actionEvent);
      actionManager.fireAfterActionPerformed(action, actionEvent.getDataContext(), actionEvent);
      return true;
    }

    if (!nonDumbAwareAction.isEmpty()) {
      showDumbModeWarningLaterIfNobodyConsumesEvent(
          e, nonDumbAwareAction.toArray(new AnActionEvent[nonDumbAwareAction.size()]));
    }

    return false;
  }
Esempio n. 2
0
  /**
   * Called when change happens
   *
   * @param change is an object holding info about the change
   */
  public void changePerformed(final ProjectDiagramChange change) {
    if (ProjectDiagramChange.ChangeType.CHANGE_FLAG.equals(change.getChangeType())
        && change.getChangeValue() instanceof Boolean
        && Boolean.FALSE.equals(change.getChangeValue())) {

      actions.get(UCNotationModel.SAVE_ACTION_KEY).setEnabled(false);

      return;
    }

    actions.get(UCNotationModel.SAVE_ACTION_KEY).setEnabled(true);
  }
  /** Bases on presence of notifications! */
  public ThreeState isAuthenticatedFor(final VirtualFile vf) {
    final WorkingCopy wcCopy = myRootsToWorkingCopies.getWcRoot(vf);
    if (wcCopy == null) return ThreeState.UNSURE;

    // check there's no cancellation yet
    final boolean haveCancellation = getStateFor(wcCopy.getUrl());
    if (haveCancellation) return ThreeState.NO;

    final Boolean keptResult = myCopiesPassiveResults.get(wcCopy.getUrl());
    if (Boolean.TRUE.equals(keptResult)) return ThreeState.YES;
    if (Boolean.FALSE.equals(keptResult)) return ThreeState.NO;

    // check have credentials
    final boolean calculatedResult = passiveValidation(myVcs.getProject(), wcCopy.getUrl());
    myCopiesPassiveResults.put(wcCopy.getUrl(), calculatedResult);
    return calculatedResult ? ThreeState.YES : ThreeState.NO;
  }
Esempio n. 4
0
  /**
   * @param aEvent
   * @param aStartPoint
   */
  protected void handleZoomRegion(final MouseEvent aEvent, final Point aStartPoint) {
    // For now, disabled by default as it isn't 100% working yet...
    if (Boolean.FALSE.equals(Boolean.valueOf(System.getProperty("zoomregionenabled", "false")))) {
      return;
    }

    final JComponent source = (JComponent) aEvent.getComponent();
    final boolean dragging = (aEvent.getID() == MouseEvent.MOUSE_DRAGGED);

    final GhostGlassPane glassPane =
        (GhostGlassPane) SwingUtilities.getRootPane(source).getGlassPane();

    Rectangle viewRect;
    final JScrollPane scrollPane =
        SwingComponentUtils.getAncestorOfClass(JScrollPane.class, source);
    if (scrollPane != null) {
      final JViewport viewport = scrollPane.getViewport();
      viewRect = SwingUtilities.convertRectangle(viewport, viewport.getVisibleRect(), glassPane);
    } else {
      viewRect = SwingUtilities.convertRectangle(source, source.getVisibleRect(), glassPane);
    }

    final Point start = SwingUtilities.convertPoint(source, aStartPoint, glassPane);
    final Point current = SwingUtilities.convertPoint(source, aEvent.getPoint(), glassPane);

    if (dragging) {
      if (!glassPane.isVisible()) {
        glassPane.setVisible(true);
        glassPane.setRenderer(new RubberBandRenderer(), start, current, viewRect);
      } else {
        glassPane.updateRenderer(start, current, viewRect);
      }

      glassPane.repaintPartially();
    } else
    /* if ( !dragging ) */
    {
      // Fire off a signal to the zoom controller to do its job...
      this.controller.getZoomController().zoomRegion(aStartPoint, aEvent.getPoint());

      glassPane.setVisible(false);
    }
  }
    @Nullable
    public List<IntentionAction> getOptions(@NotNull PsiElement element, @Nullable Editor editor) {
      if (editor != null
          && Boolean.FALSE.equals(
              editor.getUserData(IntentionManager.SHOW_INTENTION_OPTIONS_KEY))) {
        return null;
      }
      List<IntentionAction> options = myOptions;
      HighlightDisplayKey key = myKey;
      if (myProblemGroup != null) {
        String problemName = myProblemGroup.getProblemName();
        HighlightDisplayKey problemGroupKey =
            problemName != null ? HighlightDisplayKey.findById(problemName) : null;
        if (problemGroupKey != null) {
          key = problemGroupKey;
        }
      }
      if (options != null || key == null) {
        return options;
      }
      IntentionManager intentionManager = IntentionManager.getInstance();
      List<IntentionAction> newOptions = intentionManager.getStandardIntentionOptions(key, element);
      InspectionProfile profile =
          InspectionProjectProfileManager.getInstance(element.getProject()).getInspectionProfile();
      InspectionToolWrapper toolWrapper = profile.getInspectionTool(key.toString(), element);
      if (!(toolWrapper instanceof LocalInspectionToolWrapper)) {
        HighlightDisplayKey idkey = HighlightDisplayKey.findById(key.toString());
        if (idkey != null) {
          toolWrapper = profile.getInspectionTool(idkey.toString(), element);
        }
      }
      if (toolWrapper != null) {

        myCanCleanup = toolWrapper.isCleanupTool();

        ContainerUtil.addIfNotNull(
            newOptions, intentionManager.createFixAllIntention(toolWrapper, myAction));
        InspectionProfileEntry wrappedTool =
            toolWrapper instanceof LocalInspectionToolWrapper
                ? ((LocalInspectionToolWrapper) toolWrapper).getTool()
                : ((GlobalInspectionToolWrapper) toolWrapper).getTool();
        if (wrappedTool instanceof CustomSuppressableInspectionTool) {
          final IntentionAction[] suppressActions =
              ((CustomSuppressableInspectionTool) wrappedTool).getSuppressActions(element);
          if (suppressActions != null) {
            ContainerUtil.addAll(newOptions, suppressActions);
          }
        } else {
          SuppressQuickFix[] suppressFixes = wrappedTool.getBatchSuppressActions(element);
          if (suppressFixes.length > 0) {
            ContainerUtil.addAll(
                newOptions,
                ContainerUtil.map(
                    suppressFixes,
                    new Function<SuppressQuickFix, IntentionAction>() {
                      @Override
                      public IntentionAction fun(SuppressQuickFix fix) {
                        return SuppressIntentionActionFromFix.convertBatchToSuppressIntentionAction(
                            fix);
                      }
                    }));
          }
        }
      }
      if (myProblemGroup instanceof SuppressableProblemGroup) {
        final IntentionAction[] suppressActions =
            ((SuppressableProblemGroup) myProblemGroup).getSuppressActions(element);
        ContainerUtil.addAll(newOptions, suppressActions);
      }

      synchronized (this) {
        options = myOptions;
        if (options == null) {
          myOptions = options = newOptions;
        }
        myKey = null;
      }
      return options;
    }
    @Nullable
    public List<IntentionAction> getOptions(@NotNull PsiElement element, @Nullable Editor editor) {
      if (editor != null
          && Boolean.FALSE.equals(
              editor.getUserData(IntentionManager.SHOW_INTENTION_OPTIONS_KEY))) {
        return null;
      }
      List<IntentionAction> options = myOptions;
      HighlightDisplayKey key = myKey;
      if (options != null || key == null) {
        return options;
      }
      List<IntentionAction> newOptions =
          IntentionManager.getInstance().getStandardIntentionOptions(key, element);
      InspectionProfile profile =
          InspectionProjectProfileManager.getInstance(element.getProject()).getInspectionProfile();
      InspectionProfileEntry tool = profile.getInspectionTool(key.toString(), element);
      if (!(tool instanceof LocalInspectionToolWrapper)) {
        HighlightDisplayKey idkey = HighlightDisplayKey.findById(key.toString());
        if (idkey != null) {
          tool = profile.getInspectionTool(idkey.toString(), element);
        }
      }
      InspectionProfileEntry wrappedTool = tool;
      if (tool instanceof LocalInspectionToolWrapper) {
        wrappedTool = ((LocalInspectionToolWrapper) tool).getTool();
        Class aClass = myAction.getClass();
        if (myAction instanceof QuickFixWrapper) {
          aClass = ((QuickFixWrapper) myAction).getFix().getClass();
        }
        newOptions.add(new CleanupInspectionIntention((LocalInspectionToolWrapper) tool, aClass));
      } else if (tool instanceof GlobalInspectionToolWrapper) {
        wrappedTool = ((GlobalInspectionToolWrapper) tool).getTool();
        if (wrappedTool instanceof GlobalSimpleInspectionTool
            && (myAction instanceof LocalQuickFix || myAction instanceof QuickFixWrapper)) {
          Class aClass = myAction.getClass();
          if (myAction instanceof QuickFixWrapper) {
            aClass = ((QuickFixWrapper) myAction).getFix().getClass();
          }
          newOptions.add(
              new CleanupInspectionIntention((GlobalInspectionToolWrapper) tool, aClass));
        }
      }

      if (wrappedTool instanceof CustomSuppressableInspectionTool) {
        final IntentionAction[] suppressActions =
            ((CustomSuppressableInspectionTool) wrappedTool).getSuppressActions(element);
        if (suppressActions != null) {
          ContainerUtil.addAll(newOptions, suppressActions);
        }
      }
      if (wrappedTool instanceof BatchSuppressableTool) {
        final SuppressQuickFix[] suppressActions =
            ((BatchSuppressableTool) wrappedTool).getBatchSuppressActions(element);
        ContainerUtil.addAll(
            newOptions,
            ContainerUtil.map(
                suppressActions,
                new Function<SuppressQuickFix, IntentionAction>() {
                  @Override
                  public IntentionAction fun(SuppressQuickFix fix) {
                    return InspectionManagerEx.convertBatchToSuppressIntentionAction(fix);
                  }
                }));
      }

      synchronized (this) {
        options = myOptions;
        if (options == null) {
          myOptions = options = newOptions;
        }
        myKey = null;
      }
      return options;
    }
Esempio n. 7
0
  /**
   * This calls the other relevant <code>paint...()</code> methods in this object. The layering of
   * the focus varies based on whether it should be painted outside or inside the filled shape, but
   * otherwise the layers are:
   *
   * <ul>
   *   <li>Filling the bounds with <code>button.getBackground()</code> (if <code>button.isOpaque()
   *       </code> is true).
   *   <li>If <code>getShadowHighlight()</code> is non-null, painting the stroke/border 1 pixel
   *       below its usual location.
   *   <li><code>paintBackground(g)</code>
   *   <li><code>paintEffects(g,false)</code>
   *   <li><code>paintIcon(g)</code>
   *   <li><code>paintText(g)</code>
   *   <LI><code>paintForeground(g)</code>
   *   <LI><code>paintEffects(g,true)</code>
   * </ul>
   */
  @Override
  public void paint(Graphics g0, JComponent c) {
    AbstractButton button = (AbstractButton) c;

    if (isLayoutValid(button) == false) updateLayout(button, getButtonInfo(button));

    if (button.isOpaque()) {
      g0.setColor(button.getBackground());
      g0.fillRect(0, 0, button.getWidth(), button.getHeight());
    }

    Graphics2D g = new OptimizedGraphics2D((Graphics2D) g0);

    g.setComposite(getComposite(button));

    ButtonInfo info = getButtonInfo(button);

    Color highlight = fill.getShadowHighlight(button);
    if (highlight != null && isStrokePainted(button)) {
      g.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
      g.translate(0, 1);
      g.setColor(highlight);
      g.draw(info.fill);
      g.translate(0, -1);
    }

    PaintFocus focus = getFocusPainting(button);
    boolean hasFocus = hasFocus(button);
    if (Boolean.FALSE.equals(hasFocus) || button.isFocusPainted() == false) focus = PaintFocus.NONE;

    // this shouldn't be an issue, but just in case:
    if (isEnabled(button) == false) focus = PaintFocus.NONE;

    if (focus == PaintFocus.OUTSIDE) {
      if (isFillOpaque()) {
        // the opaque fill will overwrite the inner part of
        // this stroke...
        PlafPaintUtils.paintFocus(g, info.stroke, focusSize);
      } else {
        // this still has some rendering quirks in
        // Quartz (remove the clipping to study closely)
        // ... but other than the top horizontal & vertical
        // line it's OK.  And even those are ... partly there.
        Graphics2D focusG = (Graphics2D) g.create();
        GeneralPath outsideClip = new GeneralPath(Path2D.WIND_EVEN_ODD);
        outsideClip.append(new Rectangle(0, 0, button.getWidth(), button.getHeight()), false);
        outsideClip.append(info.fill, false);
        focusG.clip(outsideClip);
        PlafPaintUtils.paintFocus(focusG, info.stroke, focusSize);
        focusG.dispose();
      }
    }
    g.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_OFF);

    paintBackground(g, info);
    paintEffects(g, info, true);

    g.setStroke(new BasicStroke(1));
    if (focus == PaintFocus.INSIDE) {
      Graphics2D focusG = (Graphics2D) g.create();
      focusG.clip(info.fill);
      PlafPaintUtils.paintFocus(focusG, info.stroke, focusSize);
      focusG.dispose();
      paintStroke(g, info);
    } else if (focus == PaintFocus.BOTH) {
      paintStroke(g, info);
      PlafPaintUtils.paintFocus(g, info.stroke, focusSize);
    } else {
      paintStroke(g, info);
    }

    g.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);

    paintIcon(g, info);
    paintText(g, info);

    g.setComposite(isEnabled(button) ? AlphaComposite.SrcOver : SRC_OVER_TRANSLUCENT);
    paintForeground(g, info);
    paintEffects(g, info, false);
  }