private static void showPopupInBestPosition(
     @NotNull ListPopup popup, @NotNull AnActionEvent event, @NotNull DataContext dataContext) {
   if (event.getInputEvent() instanceof MouseEvent) {
     if (!event.getPlace().equals(ActionPlaces.UPDATE_POPUP)) {
       popup.show(new RelativePoint((MouseEvent) event.getInputEvent()));
     } else { // quick fix for invoking from the context menu: coordinates are calculated
       // incorrectly there.
       popup.showInBestPositionFor(dataContext);
     }
   } else {
     popup.showInBestPositionFor(dataContext);
   }
 }
Exemplo n.º 2
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);
              }
            });
  }
 public static void showPopup(AnActionEvent e, JBPopup popup) {
   final InputEvent event = e.getInputEvent();
   if (event instanceof MouseEvent) {
     popup.showUnderneathOf(event.getComponent());
   } else {
     popup.showInBestPositionFor(e.getDataContext());
   }
 }
  @Override
  public void update(AnActionEvent e) {
    Presentation presentation = e.getPresentation();

    if (ActionPlaces.PROJECT_VIEW_POPUP.equals(e.getPlace())
        || ActionPlaces.COMMANDER_POPUP.equals(e.getPlace())) {
      presentation.setText(IdeBundle.message("action.delete.ellipsis"));
    } else {
      presentation.setText(IdeBundle.message("action.delete"));
    }

    if (e.getProject() == null) {
      presentation.setEnabled(false);
      return;
    }

    DataContext dataContext = e.getDataContext();
    DeleteProvider provider = getDeleteProvider(dataContext);
    if (e.getInputEvent() instanceof KeyEvent) {
      KeyEvent keyEvent = (KeyEvent) e.getInputEvent();
      Object component = PlatformDataKeys.CONTEXT_COMPONENT.getData(dataContext);
      if (component instanceof JTextComponent) provider = null; // Do not override text deletion
      if (keyEvent.getKeyCode() == KeyEvent.VK_BACK_SPACE) {
        // Do not override text deletion in speed search
        if (component instanceof JComponent) {
          SpeedSearchSupply searchSupply = SpeedSearchSupply.getSupply((JComponent) component);
          if (searchSupply != null) provider = null;
        }

        String activeSpeedSearchFilter =
            SpeedSearchSupply.SPEED_SEARCH_CURRENT_QUERY.getData(dataContext);
        if (!StringUtil.isEmpty(activeSpeedSearchFilter)) {
          provider = null;
        }
      }
    }
    if (provider instanceof TitledHandler) {
      presentation.setText(((TitledHandler) provider).getActionTitle());
    }
    boolean canDelete = provider != null && provider.canDeleteElement(dataContext);
    if (ActionPlaces.isPopupPlace(e.getPlace())) {
      presentation.setVisible(canDelete);
    } else {
      presentation.setEnabled(canDelete);
    }
  }
 @Override
 public void actionPerformed(AnActionEvent e) {
   JPanel result = new JPanel(new BorderLayout());
   JLabel label = new JLabel("Lines around:");
   label.setBorder(BorderFactory.createEmptyBorder(4, 4, 0, 0));
   JPanel wrapper = new JPanel(new BorderLayout());
   wrapper.add(label, BorderLayout.NORTH);
   result.add(wrapper, BorderLayout.WEST);
   final JSlider slider = new JSlider(JSlider.HORIZONTAL, 1, 5, 1);
   slider.setMinorTickSpacing(1);
   slider.setPaintTicks(true);
   slider.setPaintTrack(true);
   slider.setSnapToTicks(true);
   UIUtil.setSliderIsFilled(slider, true);
   slider.setPaintLabels(true);
   slider.setLabelTable(LABELS);
   result.add(slider, BorderLayout.CENTER);
   final VcsConfiguration configuration = VcsConfiguration.getInstance(myProject);
   for (int i = 0; i < ourMarks.length; i++) {
     int mark = ourMarks[i];
     if (mark == configuration.SHORT_DIFF_EXTRA_LINES) {
       slider.setValue(i + 1);
     }
   }
   JBPopup popup =
       JBPopupFactory.getInstance().createComponentPopupBuilder(result, slider).createPopup();
   popup.setFinalRunnable(
       new Runnable() {
         @Override
         public void run() {
           int value = slider.getModel().getValue();
           if (configuration.SHORT_DIFF_EXTRA_LINES != ourMarks[value - 1]) {
             configuration.SHORT_DIFF_EXTRA_LINES = ourMarks[value - 1];
             myFragmentedContent.recalculate();
             refreshData(myFragmentedContent);
           }
         }
       });
   InputEvent inputEvent = e.getInputEvent();
   if (inputEvent instanceof MouseEvent) {
     int width = result.getPreferredSize().width;
     MouseEvent inputEvent1 = (MouseEvent) inputEvent;
     Point point1 = new Point(inputEvent1.getX() - width / 2, inputEvent1.getY());
     RelativePoint point = new RelativePoint(inputEvent1.getComponent(), point1);
     popup.show(point);
   } else {
     popup.showInBestPositionFor(e.getDataContext());
   }
 }
 @Override
 public void actionPerformed(AnActionEvent e) {
   final DefaultActionGroup dag = new DefaultActionGroup();
   dag.add(myUsual);
   dag.add(myNumbered);
   dag.add(mySoftWrapsAction);
   final ListPopup popup =
       JBPopupFactory.getInstance()
           .createActionGroupPopup(
               null,
               dag,
               e.getDataContext(),
               JBPopupFactory.ActionSelectionAid.SPEEDSEARCH,
               false);
   if (e.getInputEvent() instanceof MouseEvent) {
     popup.show(new RelativePoint((MouseEvent) e.getInputEvent()));
   } else {
     // todo correct
     /*final Dimension dimension = popup.getContent().getPreferredSize();
     final Point at = new Point(-dimension.width / 2, 0);
     popup.show(new RelativePoint(myParent, at));*/
     popup.showInBestPositionFor(e.getDataContext());
   }
 }
 private AnActionEvent stopConsole(AnActionEvent e) {
   if (myPydevConsoleCommunication != null) {
     e =
         new AnActionEvent(
             e.getInputEvent(),
             e.getDataContext(),
             e.getPlace(),
             e.getPresentation(),
             e.getActionManager(),
             e.getModifiers());
     try {
       closeCommunication();
       // waiting for REPL communication before destroying process handler
       Thread.sleep(300);
     } catch (Exception ignored) {
       // Ignore
     }
   }
   return e;
 }
Exemplo n.º 8
0
 @Override
 public void actionPerformed(AnActionEvent e) {
   getWindow(e).showContentPopup(e.getInputEvent());
 }
Exemplo n.º 9
0
 @Override
 public void actionPerformed(AnActionEvent e) {
   myWrapper.doCancelAction(e.getInputEvent());
 }