@Override
    public final void actionPerformed(final AnActionEvent event) {
      final DataContext dataContext = event.getDataContext();
      final HierarchyBrowserBaseEx browser =
          (HierarchyBrowserBaseEx) dataContext.getData(myBrowserDataKey);
      if (browser == null) return;

      final PsiElement selectedElement = browser.getSelectedElement();
      if (selectedElement == null || !browser.isApplicableElement(selectedElement)) return;

      final String currentViewType = browser.myCurrentViewType;
      Disposer.dispose(browser);
      final HierarchyProvider provider =
          BrowseHierarchyActionBase.findProvider(
              myProviderLanguageExtension,
              selectedElement,
              selectedElement.getContainingFile(),
              event.getDataContext());
      final HierarchyBrowser newBrowser =
          BrowseHierarchyActionBase.createAndAddToPanel(
              selectedElement.getProject(), provider, selectedElement);
      ApplicationManager.getApplication()
          .invokeLater(
              () ->
                  ((HierarchyBrowserBaseEx) newBrowser)
                      .changeView(correctViewType(browser, currentViewType)));
    }
  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;
  }
    @Override
    public final void update(final AnActionEvent event) {
      final Presentation presentation = event.getPresentation();

      final DataContext dataContext = event.getDataContext();
      final HierarchyBrowserBaseEx browser =
          (HierarchyBrowserBaseEx) dataContext.getData(myBrowserDataKey);
      if (browser == null) {
        presentation.setVisible(false);
        presentation.setEnabled(false);
        return;
      }

      presentation.setVisible(true);

      final PsiElement selectedElement = browser.getSelectedElement();
      if (selectedElement == null || !browser.isApplicableElement(selectedElement)) {
        presentation.setEnabled(false);
        presentation.setVisible(false);
        return;
      }

      presentation.setEnabled(isEnabled(browser, selectedElement));
      String nonDefaultText = getNonDefaultText(browser, selectedElement);
      if (nonDefaultText != null) {
        presentation.setText(nonDefaultText);
      }
    }
 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());
   }
 }
Esempio n. 5
0
  @Nullable
  private ToolWindow getWindow(AnActionEvent event) {
    if (myWindow != null) return myWindow;

    Project project = CommonDataKeys.PROJECT.getData(event.getDataContext());
    if (project == null) return null;

    ToolWindowManager manager = ToolWindowManager.getInstance(project);

    final ToolWindow window = manager.getToolWindow(manager.getActiveToolWindowId());
    if (window == null) return null;

    final Component context = PlatformDataKeys.CONTEXT_COMPONENT.getData(event.getDataContext());
    if (context == null) return null;

    return SwingUtilities.isDescendingFrom(window.getComponent(), context) ? window : null;
  }
 @Override
 public void actionPerformed(@NotNull AnActionEvent e) {
   PrevNextDifferenceIterable iterable =
       DiffDataKeys.PREV_NEXT_DIFFERENCE_ITERABLE.getData(e.getDataContext());
   if (iterable != null && iterable.canGoPrev()) {
     iterable.goPrev();
   }
 }
  public void update(final AnActionEvent e) {
    final DataContext dataContext = e.getDataContext();
    final Presentation presentation = e.getPresentation();

    final boolean enabled = isAvailable(dataContext);

    presentation.setVisible(enabled);
    presentation.setEnabled(enabled);
  }
  @Override
  public void update(final AnActionEvent e) {
    final DataContext dataContext = e.getDataContext();
    final Project project = PlatformDataKeys.PROJECT.getData(dataContext);
    final Change[] changes = e.getData(getChangesKey());

    final Presentation presentation = e.getPresentation();
    presentation.setVisible(VcsDataKeys.CHANGES.getData(dataContext) != null);
    presentation.setEnabled(enabled(project, changes));
  }
 @Override
 public void actionPerformed(AnActionEvent e) {
   DataContext dataContext = e.getDataContext();
   DeleteProvider provider = getDeleteProvider(dataContext);
   if (provider == null) return;
   try {
     provider.deleteElement(dataContext);
   } catch (Throwable t) {
     LOG.error(t);
   }
 }
Esempio n. 10
0
  @Override
  public void update(final AnActionEvent e) {
    if (!e.getPresentation().isVisible()) {
      return;
    }
    final DataContext dataContext = e.getDataContext();
    final Presentation presentation = e.getPresentation();

    final boolean enabled = isAvailable(dataContext);

    presentation.setVisible(enabled);
    presentation.setEnabled(enabled);
  }
 @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());
   }
 }
  public void actionPerformed(final AnActionEvent e) {
    final DataContext dataContext = e.getDataContext();
    final Project project = PlatformDataKeys.PROJECT.getData(dataContext);
    final Change[] changes = e.getData(getChangesKey());

    if (!enabled(project, changes)) {
      return;
    }

    final Change change = changes[0];

    final CalculateAndShow worker =
        new CalculateAndShow(project, change, e.getPresentation().getText());
    ProgressManager.getInstance().run(worker);
  }
    @Override
    public void update(@NotNull AnActionEvent e) {
      if (!ActionPlaces.DIFF_TOOLBAR.equals(e.getPlace())) {
        e.getPresentation().setEnabled(true);
        return;
      }

      PrevNextDifferenceIterable iterable =
          DiffDataKeys.PREV_NEXT_DIFFERENCE_ITERABLE.getData(e.getDataContext());
      if (iterable != null && iterable.canGoPrev()) {
        e.getPresentation().setEnabled(true);
        return;
      }

      e.getPresentation().setEnabled(false);
    }
  @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);
    }
  }
Esempio n. 16
0
  @Override
  public final void actionPerformed(final AnActionEvent e) {
    final DataContext dataContext = e.getDataContext();

    final IdeView view = LangDataKeys.IDE_VIEW.getData(dataContext);
    if (view == null) {
      return;
    }

    final Project project = CommonDataKeys.PROJECT.getData(dataContext);

    final PsiDirectory dir = view.getOrChooseDirectory();
    if (dir == null) return;
    final PsiElement[] createdElements = invokeDialog(project, dir);

    for (PsiElement createdElement : createdElements) {
      view.selectElement(createdElement);
    }
  }
  @Override
  public void actionPerformed(AnActionEvent e) {

    DataContext context = e.getDataContext();
    Editor editor = PlatformDataKeys.EDITOR.getData(context);
    PsiFile psiFile = LangDataKeys.PSI_FILE.getData(context);
    if (psiFile == null) return;

    List<GotoRelatedItem> items = getItems(psiFile, editor, context);
    if (items.isEmpty()) return;
    if (items.size() == 1 && items.get(0).getElement() != null) {
      items.get(0).navigate();
      return;
    }
    if (ApplicationManager.getApplication().isUnitTestMode()) {
      System.out.println(items);
    }
    createPopup(items, "Go to Related Files").showInBestPositionFor(context);
  }
Esempio n. 18
0
 public void actionPerformed(AnActionEvent e) {
   final JBPopupFactory popupFactory = JBPopupFactory.getInstance();
   final ListPopupStep step =
       popupFactory.createActionsStep(
           myActionGroup,
           e.getDataContext(),
           false,
           false,
           myActionGroup.getTemplatePresentation().getText(),
           myTree,
           true,
           myPreselection != null ? myPreselection.getDefaultIndex() : 0,
           true);
   final ListPopup listPopup = popupFactory.createListPopup(step);
   listPopup.setHandleAutoSelectionBeforeShow(true);
   if (e instanceof AnActionButton.AnActionEventWrapper) {
     ((AnActionButton.AnActionEventWrapper) e).showPopup(listPopup);
   } else {
     listPopup.showUnderneathOf(myNorthPanel);
   }
 }
  @Override
  public void actionPerformed(AnActionEvent e) {
    final Project project = e.getData(PlatformDataKeys.PROJECT);
    if (project == null) return;

    Runnable searchEverywhere = mySearchEverywhereRunnable;
    mySearchEverywhereRunnable = null;
    hideHints();

    if (searchEverywhere != null) {
      searchEverywhere.run();
      return;
    }

    final RelativePoint popupPosition =
        JBPopupFactory.getInstance().guessBestPopupLocation(e.getDataContext());
    PsiDocumentManager.getInstance(project).commitAllDocuments();
    FeatureUsageTracker.getInstance().triggerFeatureUsed("navigation.goto.usages");

    UsageTarget[] usageTargets = e.getData(UsageView.USAGE_TARGETS_KEY);
    final Editor editor = e.getData(PlatformDataKeys.EDITOR);
    if (usageTargets == null) {
      chooseAmbiguousTargetAndPerform(
          project,
          editor,
          new PsiElementProcessor<PsiElement>() {
            @Override
            public boolean execute(@NotNull final PsiElement element) {
              startFindUsages(element, popupPosition, editor, USAGES_PAGE_SIZE);
              return false;
            }
          });
    } else {
      PsiElement element = ((PsiElementUsageTarget) usageTargets[0]).getElement();
      if (element != null) {
        startFindUsages(element, popupPosition, editor, USAGES_PAGE_SIZE);
      }
    }
  }
  public final void actionPerformed(final AnActionEvent e) {
    final DataContext dataContext = e.getDataContext();

    final IdeView view = LangDataKeys.IDE_VIEW.getData(dataContext);
    if (view == null) {
      return;
    }

    final Project project = PlatformDataKeys.PROJECT.getData(dataContext);

    final PsiDirectory dir = view.getOrChooseDirectory();
    if (dir == null || project == null) return;

    final CreateFileFromTemplateDialog.Builder builder =
        CreateFileFromTemplateDialog.createDialog(project);
    buildDialog(project, dir, builder);

    final Ref<String> selectedTemplateName = Ref.create(null);
    final T createdElement =
        builder.show(
            getErrorTitle(),
            getDefaultTemplateName(dir),
            new CreateFileFromTemplateDialog.FileCreator<T>() {

              public T createFile(@NotNull String name, @NotNull String templateName) {
                selectedTemplateName.set(templateName);
                return CreateFromTemplateAction.this.createFile(name, templateName, dir);
              }

              @NotNull
              public String getActionName(@NotNull String name, @NotNull String templateName) {
                return CreateFromTemplateAction.this.getActionName(dir, name, templateName);
              }
            });
    if (createdElement != null) {
      view.selectElement(createdElement);
      postProcess(createdElement, selectedTemplateName.get(), builder.getCustomProperties());
    }
  }
 public void actionPerformed(final AnActionEvent e) {
   @NonNls final String delim = "&nbsp;-&gt;&nbsp;";
   final StringBuffer buf = new StringBuffer();
   processDependencies(
       getSelectedScope(myLeftTree),
       getSelectedScope(myRightTree),
       new Processor<List<PsiFile>>() {
         public boolean process(final List<PsiFile> path) {
           if (buf.length() > 0) buf.append("<br>");
           buf.append(
               StringUtil.join(
                   path,
                   new Function<PsiFile, String>() {
                     public String fun(final PsiFile psiFile) {
                       return psiFile.getName();
                     }
                   },
                   delim));
           return true;
         }
       });
   final JEditorPane pane =
       new JEditorPane(UIUtil.HTML_MIME, "<html>" + buf.toString() + "</html>");
   pane.setForeground(Color.black);
   pane.setBackground(HintUtil.INFORMATION_COLOR);
   pane.setOpaque(true);
   final JScrollPane scrollPane = ScrollPaneFactory.createScrollPane(pane);
   final Dimension dimension = pane.getPreferredSize();
   scrollPane.setMinimumSize(new Dimension(dimension.width, dimension.height + 20));
   scrollPane.setPreferredSize(new Dimension(dimension.width, dimension.height + 20));
   JBPopupFactory.getInstance()
       .createComponentPopupBuilder(scrollPane, pane)
       .setTitle("Dependencies")
       .setMovable(true)
       .createPopup()
       .showInBestPositionFor(e.getDataContext());
 }
Esempio n. 22
0
 @Override
 public void actionPerformed(AnActionEvent e) {
   final DataContext dataContext = e.getDataContext();
   final Project project = DataKeys.PROJECT.getData(dataContext);
   if (project == null) {
     return;
   }
   final TreeClassChooserFactory chooserFactory = TreeClassChooserFactory.getInstance(project);
   final TreeClassChooser classChooser =
       chooserFactory.createWithInnerClassesScopeChooser(
           chooserTitle, GlobalSearchScope.allScope(project), myFilter, null);
   classChooser.showDialog();
   final PsiClass selectedClass = classChooser.getSelected();
   if (selectedClass == null) {
     return;
   }
   final String qualifiedName = selectedClass.getQualifiedName();
   final ListWrappingTableModel tableModel = table.getModel();
   final int index = tableModel.indexOf(qualifiedName, 0);
   final int rowIndex;
   if (index < 0) {
     tableModel.addRow(qualifiedName);
     rowIndex = tableModel.getRowCount() - 1;
   } else {
     rowIndex = index;
   }
   final ListSelectionModel selectionModel = table.getSelectionModel();
   selectionModel.setSelectionInterval(rowIndex, rowIndex);
   EventQueue.invokeLater(
       new Runnable() {
         public void run() {
           final Rectangle rectangle = table.getCellRect(rowIndex, 0, true);
           table.scrollRectToVisible(rectangle);
         }
       });
 }
 public void actionPerformed(AnActionEvent e) {
   Object data = ErrorTreeView.CURRENT_EXCEPTION_DATA_KEY.getData(e.getDataContext());
   CvsConfigurationsListEditor.reconfigureCvsRoot(((CvsException) data).getCvsRoot(), myProject);
 }
 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();
 }
 @Override
 public void update(AnActionEvent e) {
   e.getPresentation().setEnabled(LangDataKeys.PSI_FILE.getData(e.getDataContext()) != null);
 }