@Override
  public void update(@NotNull AnActionEvent e) {
    super.update(e);

    Presentation presentation = e.getPresentation();
    DataContext context = e.getDataContext();
    EditorWindow window = getEditorWindow(context);
    if (window == null || window.getOwner().isPreview()) {
      presentation.setEnabledAndVisible(false);
    } else {
      if (getFile(context) != null) {
        presentation.setEnabledAndVisible(true);
      } else {
        Content content = getContent(context);
        presentation.setEnabledAndVisible(content != null && content.isPinnable());
      }
    }

    if (ActionPlaces.EDITOR_TAB_POPUP.equals(e.getPlace())
        || ViewContext.CELL_POPUP_PLACE.equals(e.getPlace())) {
      presentation.setText(
          isSelected(e)
              ? IdeBundle.message("action.unpin.tab")
              : IdeBundle.message("action.pin.tab"));
    } else {
      presentation.setText(
          isSelected(e)
              ? IdeBundle.message("action.unpin.active.tab")
              : IdeBundle.message("action.pin.active.tab"));
    }
  }
 @Override
 public void update(AnActionEvent e) {
   final Presentation presentation = e.getPresentation();
   presentation.setVisible(false);
   final DataContext dataContext = e.getDataContext();
   final Project project = CommonDataKeys.PROJECT.getData(dataContext);
   if (project != null) {
     final RunConfiguration configuration = RunConfiguration.DATA_KEY.getData(dataContext);
     if (isPatternBasedConfiguration(configuration)) {
       final AbstractTestProxy testProxy = AbstractTestProxy.DATA_KEY.getData(dataContext);
       if (testProxy != null) {
         final Location location =
             testProxy.getLocation(
                 project, ((T) configuration).getConfigurationModule().getSearchScope());
         if (location != null) {
           final PsiElement psiElement = location.getPsiElement();
           if (psiElement instanceof PsiClass
               && getPattern((T) configuration)
                   .contains(((PsiClass) psiElement).getQualifiedName())) {
             presentation.setVisible(true);
           }
         }
       }
     }
   }
 }
 public static void updateFindUsagesAction(AnActionEvent event) {
   Presentation presentation = event.getPresentation();
   DataContext dataContext = event.getDataContext();
   boolean enabled = isEnabled(dataContext);
   presentation.setVisible(enabled || !ActionPlaces.isPopupPlace(event.getPlace()));
   presentation.setEnabled(enabled);
 }
  @NotNull
  private static AnAction[] findActions(@NotNull AnActionEvent e) {
    PsiFile psiFile = e.getData(CommonDataKeys.PSI_FILE);
    Project project = e.getData(CommonDataKeys.PROJECT);
    Editor editor = e.getData(LangDataKeys.EDITOR);
    if (psiFile != null && project != null && editor != null) {
      List<HighlightInfo.IntentionActionDescriptor> quickFixes =
          ShowIntentionsPass.getAvailableActions(editor, psiFile, -1);
      Map<Anchor, List<AnAction>> children = new HashMap<Anchor, List<AnAction>>();
      ArrayList<AnAction> first = new ArrayList<AnAction>();
      children.put(Anchor.FIRST, first);
      ArrayList<AnAction> last = new ArrayList<AnAction>();
      children.put(Anchor.LAST, last);
      extractActions(quickFixes, children);
      if (first.size() > 0 && last.size() > 0) {
        first.add(new AnSeparator());
      }
      first.addAll(last);
      if (first.size() > 0) {
        return first.toArray(new AnAction[first.size()]);
      }
    }

    return AnAction.EMPTY_ARRAY;
  }
 @Override
 public void update(final AnActionEvent e) {
   e.getPresentation().setIcon(myTabs.isEditorTabs() ? myNewIcon : myIcon);
   e.getPresentation().setHoveredIcon(myTabs.isEditorTabs() ? myNewHoveredIcon : myHoveredIcon);
   e.getPresentation().setVisible(UISettings.getInstance().SHOW_CLOSE_BUTTON);
   e.getPresentation().setText("Close. Alt-click to close others.");
 }
示例#6
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);
              }
            });
  }
    @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 void actionPerformed(final AnActionEvent e) {
    final Project project = CommonDataKeys.PROJECT.getData(e.getDataContext());
    if (project == null) return;

    final PsiFile file = LangDataKeys.PSI_FILE.getData(e.getDataContext());
    FileAssociationsConfigurable.editAssociations(project, file);
  }
  public void update(final AnActionEvent event) {
    super.update(event);

    final Presentation presentation = event.getPresentation();
    final DataContext context = event.getDataContext();
    Module module = (Module) context.getData(LangDataKeys.MODULE.getName());
    PsiFile currentFile = (PsiFile) context.getData(LangDataKeys.PSI_FILE.getName());
    Editor editor = (Editor) context.getData(PlatformDataKeys.EDITOR.getName());
    // VirtualFile currentFile = (VirtualFile)
    // context.getData(PlatformDataKeys.VIRTUAL_FILE.getName());
    if (currentFile != null && editor != null) {
      boolean isSSFile =
          currentFile
              .getFileType()
              .getDefaultExtension()
              .equals(SilverStripeFileType.DEFAULT_EXTENSION);
      SelectionModel selectionModel = editor.getSelectionModel();
      String selectedText = selectionModel.getSelectedText();
      this.selectedText = selectedText;
      this.selectonModel = selectionModel;
      this.editor = editor;
      this.currentFile = currentFile;
      if (selectedText == null) {
        presentation.setEnabled(false);
      }
      if (!isSSFile) {
        presentation.setEnabled(false);
        presentation.setVisible(false);
      }
    } else {
      presentation.setEnabled(false);
      presentation.setVisible(false);
    }
  }
示例#10
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);
    }
  }
 public void actionPerformed(final AnActionEvent e) {
   final PsiFile psiFile = e.getData(CommonDataKeys.PSI_FILE);
   final Project project = e.getData(CommonDataKeys.PROJECT);
   final Editor editor = e.getData(LangDataKeys.EDITOR);
   if (psiFile != null && project != null && editor != null) {
     ApplicationManager.getApplication()
         .runWriteAction(
             new Runnable() {
               public void run() {
                 CommandProcessor.getInstance()
                     .executeCommand(
                         project,
                         new Runnable() {
                           public void run() {
                             try {
                               intention.invoke(project, editor, psiFile);
                             } catch (IncorrectOperationException ex) {
                               LOGGER.error(ex);
                             }
                           }
                         },
                         e.getPresentation().getText(),
                         e.getActionManager().getId(SpellCheckerIntentionAction.this));
               }
             });
   }
 }
  @Override
  public void actionPerformed(AnActionEvent event) {
    Presentation presentation = event.getPresentation();
    DataContext dataContext = event.getDataContext();
    Project project = CommonDataKeys.PROJECT.getData(dataContext);
    Editor editor = CommonDataKeys.EDITOR.getData(dataContext);
    if (project == null || editor == null) {
      presentation.setEnabled(false);
      return;
    }

    PsiFile file = PsiDocumentManager.getInstance(project).getPsiFile(editor.getDocument());
    if (file == null || file.getVirtualFile() == null) {
      presentation.setEnabled(false);
      return;
    }

    boolean hasSelection = editor.getSelectionModel().hasSelection();
    LayoutCodeDialog dialog = new LayoutCodeDialog(project, file, hasSelection, HELP_ID);
    dialog.show();

    if (dialog.isOK()) {
      new FileInEditorProcessor(file, editor, dialog.getRunOptions()).processCode();
    }
  }
    @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)));
    }
  @Override
  public void update(AnActionEvent e) {
    Presentation presentation = e.getPresentation();

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

    final DataContext dataContext = e.getDataContext();
    Editor editor = getEditor(dataContext, project, true);
    if (editor == null) {
      presentation.setEnabled(false);
      return;
    }

    final PsiFile file = PsiUtilBase.getPsiFileInEditor(editor, project);
    if (file == null) {
      presentation.setEnabled(false);
      return;
    }

    update(presentation, project, editor, file, dataContext, e.getPlace());
  }
 public void update(AnActionEvent e) {
   if (!running) {
     e.getPresentation().setEnabled(true);
     e.getPresentation().setIcon(RESOLVEIcons.CHECKMARK);
   } else {
     e.getPresentation().setEnabled(false);
   }
 }
示例#16
0
 public void update(AnActionEvent e) {
   boolean active = getHandler(e) != null;
   if (ActionPlaces.isPopupPlace(e.getPlace())) {
     e.getPresentation().setVisible(active);
   } else {
     e.getPresentation().setEnabled(active);
   }
 }
 @Override
 public void update(AnActionEvent event) {
   final Presentation presentation = event.getPresentation();
   final Project project = event.getData(CommonDataKeys.PROJECT);
   presentation.setEnabled(project != null);
   presentation.setVisible(
       ActionPlaces.isMainMenuOrActionSearch(event.getPlace()) && !PlatformUtils.isCidr());
 }
  @Override
  public void update(@NotNull AnActionEvent e) {
    Presentation p = e.getPresentation();

    boolean visible = findPomXml(e.getDataContext()) != null;

    p.setVisible(visible);
  }
 @Override
 public final void update(final AnActionEvent e) {
   final Presentation presentation = e.getPresentation();
   final Project project = e.getProject();
   if (project == null) return;
   presentation.setEnabled(isEnabled());
   presentation.setText(getCurrentScopeType());
 }
 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 beforeActionPerformedUpdate(@NotNull AnActionEvent e) {
   Project project = e.getProject();
   if (project != null) {
     getEditor(e.getDataContext(), project, false); // ensure documents are committed
   }
   super.beforeActionPerformedUpdate(e);
 }
 @Override
 public void actionPerformed(AnActionEvent e) {
   Project project = e.getProject();
   if (project != null) {
     Editor editor = getEditor(e.getDataContext(), project, false);
     actionPerformedImpl(project, editor);
   }
 }
  public static boolean isFirstStart(final AnActionEvent event) {
    //noinspection HardCodedStringLiteral
    String key = "initalized";
    if (event.getPresentation().getClientProperty(key) != null) return false;

    event.getPresentation().putClientProperty(key, key);
    return true;
  }
 @Override
 public void update(AnActionEvent e) {
   if (mySession != null) {
     e.getPresentation().setEnabled(false);
   } else {
     e.getPresentation().setEnabled(true);
   }
 }
 public void update(AnActionEvent e) {
   super.update(e);
   if (e != null) {
     if (e.getPresentation().isVisible() && findActions(e).length == 0) {
       e.getPresentation().setVisible(false);
     }
   }
 }
  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);
  }
示例#27
0
  public void update(final AnActionEvent e) {
    final FileGroupInfo fileGroupInfo = new FileGroupInfo();

    myHelperAction.setFileIterationListener(fileGroupInfo);
    myHelperAction.update(e);

    myGetterStub.setDelegate(fileGroupInfo);

    if ((e.getPresentation().isEnabled())) {
      removeAll();
      if (myHelperAction.allAreIgnored()) {
        final DataContext dataContext = e.getDataContext();
        final Project project = CommonDataKeys.PROJECT.getData(dataContext);
        SvnVcs vcs = SvnVcs.getInstance(project);

        final Ref<Boolean> filesOk = new Ref<Boolean>(Boolean.FALSE);
        final Ref<Boolean> extensionOk = new Ref<Boolean>(Boolean.FALSE);

        // virtual files parameter is not used -> can pass null
        SvnPropertyService.doCheckIgnoreProperty(
            vcs,
            project,
            null,
            fileGroupInfo,
            fileGroupInfo.getExtensionMask(),
            filesOk,
            extensionOk);

        if (Boolean.TRUE.equals(filesOk.get())) {
          myRemoveExactAction.setActionText(
              fileGroupInfo.oneFileSelected()
                  ? fileGroupInfo.getFileName()
                  : SvnBundle.message("action.Subversion.UndoIgnore.text"));
          add(myRemoveExactAction);
        }

        if (Boolean.TRUE.equals(extensionOk.get())) {
          myRemoveExtensionAction.setActionText(fileGroupInfo.getExtensionMask());
          add(myRemoveExtensionAction);
        }

        e.getPresentation().setText(SvnBundle.message("group.RevertIgnoreChoicesGroup.text"));
      } else if (myHelperAction.allCanBeIgnored()) {
        final String ignoreExactlyName =
            (fileGroupInfo.oneFileSelected())
                ? fileGroupInfo.getFileName()
                : SvnBundle.message("action.Subversion.Ignore.ExactMatch.text");
        myAddExactAction.setActionText(ignoreExactlyName);
        add(myAddExactAction);
        if (fileGroupInfo.sameExtension()) {
          myAddExtensionAction.setActionText(fileGroupInfo.getExtensionMask());
          add(myAddExtensionAction);
        }
        e.getPresentation().setText(SvnBundle.message("group.IgnoreChoicesGroup.text"));
      }
    }
  }
  @Override
  public void update(AnActionEvent e) {
    final DataContext dc = e.getDataContext();

    final Presentation presentation = e.getPresentation();

    // presentation.setVisible(isVisible(dc));
    presentation.setEnabled(isVisible(dc) && isEnabled(dc));
  }
示例#29
0
 @Override
 public void update(AnActionEvent e) {
   super.update(e);
   e.getPresentation()
       .setVisible(
           SendToFavoritesAction.isEnabled(e)
               && FavoritesTreeViewPanel.FAVORITES_LIST_NAME_DATA_KEY.getData(e.getDataContext())
                   != null);
 }
  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;
  }