Java Code Examples for com.intellij.openapi.actionSystem.Presentation#setEnabled()

The following examples show how to use com.intellij.openapi.actionSystem.Presentation#setEnabled() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: OpenCorrespondingBuildFile.java    From intellij with Apache License 2.0 6 votes vote down vote up
@Override
protected void updateForBlazeProject(Project project, AnActionEvent e) {
  Presentation presentation = e.getPresentation();

  DataContext dataContext = e.getDataContext();
  VirtualFile virtualFile = CommonDataKeys.VIRTUAL_FILE.getData(dataContext);
  BlazePackage blazePackage = BuildFileUtils.getBuildFile(project, virtualFile);
  if (blazePackage != null && virtualFile.equals(blazePackage.buildFile.getVirtualFile())) {
    presentation.setEnabledAndVisible(false);
    return;
  }

  boolean enabled = blazePackage != null;
  presentation.setVisible(enabled || !ActionPlaces.isPopupPlace(e.getPlace()));
  presentation.setEnabled(enabled);
}
 
Example 2
Source File: BaseRefactorAction.java    From lombok-intellij-plugin with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
@Override
public void update(AnActionEvent e) {
  super.update(e);

  boolean visible = isActionAvailable(e);

  final Presentation presentation = e.getPresentation();
  presentation.setVisible(visible);
  presentation.setEnabled(visible);
}
 
Example 3
Source File: ChangeViewTypeActionBase.java    From consulo with Apache License 2.0 5 votes vote down vote up
@Override
public void update(final AnActionEvent event) {
  // its important to assign the myTypeHierarchyBrowser first
  super.update(event);
  final Presentation presentation = event.getPresentation();
  final TypeHierarchyBrowserBase browser = getTypeHierarchyBrowser(event.getDataContext());
  presentation.setEnabled(browser != null && browser.isValidBase());
}
 
Example 4
Source File: BaseShowDiffAction.java    From consulo with Apache License 2.0 5 votes vote down vote up
@RequiredUIAccess
@Override
public void update(@Nonnull AnActionEvent e) {
  Presentation presentation = e.getPresentation();
  boolean canShow = isAvailable(e);
  presentation.setEnabled(canShow);
  if (ActionPlaces.isPopupPlace(e.getPlace())) {
    presentation.setVisible(canShow);
  }
}
 
Example 5
Source File: CreateSwarmReviewAction.java    From p4ic4idea with Apache License 2.0 5 votes vote down vote up
@Override
protected void update(@NotNull final VcsContext event, @NotNull final Presentation presentation) {
    Project project = event.getProject();
    if (project == null) {
        presentation.setEnabled(false);
        presentation.setVisible(false);
        return;
    }
    ProjectConfigRegistry registry = ProjectConfigRegistry.getInstance(project);
    if (registry == null) {
        presentation.setEnabled(false);
        presentation.setVisible(false);
        return;
    }
    List<ChangeList> changeLists = getSelectedChangeLists(event);
    if (changeLists.isEmpty()) {
        presentation.setEnabled(false);
        presentation.setVisible(false);
        return;
    }
    // Restrict to just 1 changelist to create a review.
    if (changeLists.size() != 1) {
        presentation.setEnabled(false);
        presentation.setVisible(true);
        return;
    }
    boolean hasChanges = false;
    for (ChangeList changeList : changeLists) {
        if (!changeList.getChanges().isEmpty()) {
            hasChanges = true;
            break;
        }
    }
    presentation.setEnabled(hasChanges);
    presentation.setVisible(true);
}
 
Example 6
Source File: DescribeLibraryAction.java    From intellij with Apache License 2.0 5 votes vote down vote up
@Override
protected void updateForBlazeProject(Project project, AnActionEvent e) {
  Presentation presentation = e.getPresentation();
  boolean enabled = LibraryActionHelper.findLibraryForAction(e) != null;
  presentation.setVisible(enabled);
  presentation.setEnabled(enabled);
}
 
Example 7
Source File: PantsConsoleViewPanel.java    From intellij-pants-plugin with Apache License 2.0 5 votes vote down vote up
@Override
public void update(AnActionEvent event) {
  // Make the action only clickable when there is an active Pants process.
  Presentation presentation = event.getPresentation();
  Project project = event.getProject();
  if (project == null) {
    return;
  }
  presentation.setEnabled(PantsMakeBeforeRun.hasActivePantsProcess(project));
}
 
Example 8
Source File: GotoHomeAction.java    From consulo with Apache License 2.0 5 votes vote down vote up
protected void update(final FileSystemTree fileSystemTree, final AnActionEvent e) {
  final Presentation presentation = e.getPresentation();
  if (!presentation.isEnabled()) return;

  final VirtualFile userHomeDir = VfsUtil.getUserHomeDir();
  presentation.setEnabled(userHomeDir != null && fileSystemTree.isUnderRoots(userHomeDir));
}
 
Example 9
Source File: MyActionUtils.java    From intellij-plugin-v4 with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
/** Only show if selection is a lexer or parser rule */
public static void showOnlyIfSelectionIsRule(AnActionEvent e, String title) {
	Presentation presentation = e.getPresentation();
	VirtualFile grammarFile = getGrammarFileFromEvent(e);
	if ( grammarFile==null ) {
		presentation.setEnabled(false);
		return;
	}

	PsiElement el = getSelectedPsiElement(e);
	if ( el==null ) {
		presentation.setEnabled(false);
		return;
	}

	ParserRuleRefNode parserRule = getParserRuleSurroundingRef(e);
	LexerRuleRefNode lexerRule = getLexerRuleSurroundingRef(e);

	if ( (lexerRule!=null && el instanceof LexerRuleRefNode) ||
		 (parserRule!=null && el instanceof ParserRuleRefNode) )
	{
		String ruleName = el.getText();
		presentation.setText(String.format(title,ruleName));
	}
	else {
		presentation.setEnabled(false);
	}
}
 
Example 10
Source File: ToggleDumbModeAction.java    From consulo with Apache License 2.0 5 votes vote down vote up
@Override
public void update(final AnActionEvent e) {
  final Presentation presentation = e.getPresentation();
  final Project project = e.getData(CommonDataKeys.PROJECT);
  presentation.setEnabled(project != null && myDumb == DumbServiceImpl.getInstance(project).isDumb());
  if (myDumb) {
    presentation.setText("Exit Dumb Mode");
  }
  else {
    presentation.setText("Enter Dumb Mode");
  }
}
 
Example 11
Source File: GenerateAction.java    From RIBs with Apache License 2.0 5 votes vote down vote up
@Override
public final void update(AnActionEvent e) {
  this.dataContext = e.getDataContext();
  final Presentation presentation = e.getPresentation();

  final boolean enabled = isAvailable(dataContext);

  presentation.setVisible(enabled);
  presentation.setEnabled(enabled);
}
 
Example 12
Source File: FileDeleteAction.java    From consulo with Apache License 2.0 5 votes vote down vote up
@Override
public void update(AnActionEvent event) {
  Presentation presentation = event.getPresentation();
  final Boolean available = event.getData(FileChooserKeys.DELETE_ACTION_AVAILABLE);
  if (available != null && !available) {
    presentation.setEnabled(false);
    presentation.setVisible(false);
    return;
  }

  super.update(event);
}
 
Example 13
Source File: XSetValueAction.java    From consulo with Apache License 2.0 5 votes vote down vote up
@Override
public void update(final AnActionEvent e) {
  super.update(e);
  XValueNodeImpl node = getSelectedNode(e.getDataContext());
  Presentation presentation = e.getPresentation();
  if (node instanceof WatchNode) {
    presentation.setVisible(false);
    presentation.setEnabled(false);
  }
  else {
    presentation.setVisible(true);
  }
}
 
Example 14
Source File: FlutterBuildActionGroup.java    From flutter-intellij with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
@Override
public void update(AnActionEvent event) {
  final Presentation presentation = event.getPresentation();
  final boolean enabled = isInFlutterModule(event);
  presentation.setEnabled(enabled);
  presentation.setVisible(enabled);
}
 
Example 15
Source File: MarkObjectAction.java    From consulo with Apache License 2.0 5 votes vote down vote up
@Override
public void update(AnActionEvent event) {
  Project project = event.getData(CommonDataKeys.PROJECT);
  boolean enabled = false;
  Presentation presentation = event.getPresentation();
  boolean hidden = true;
  if (project != null) {
    for (DebuggerSupport support : DebuggerSupport.getDebuggerSupports()) {
      MarkObjectActionHandler handler = support.getMarkObjectHandler();
      hidden &= handler.isHidden(project, event);
      if (handler.isEnabled(project, event)) {
        enabled = true;
        String text;
        if (handler.isMarked(project, event)) {
          text = ActionsBundle.message("action.Debugger.MarkObject.unmark.text");
        }
        else {
          text = ActionsBundle.message("action.Debugger.MarkObject.text");
        }
        presentation.setText(text);
        break;
      }
    }
  }
  presentation.setVisible(!hidden && (!ActionPlaces.isPopupPlace(event.getPlace()) || enabled));
  presentation.setEnabled(enabled);
}
 
Example 16
Source File: SplitAction.java    From consulo with Apache License 2.0 5 votes vote down vote up
public void update(final AnActionEvent event) {
  final Project project = event.getData(CommonDataKeys.PROJECT);
  final Presentation presentation = event.getPresentation();
  presentation.setText (myOrientation == SwingConstants.VERTICAL
                        ? IdeBundle.message("action.split.vertically")
                        : IdeBundle.message("action.split.horizontally"));
  if (project == null) {
    presentation.setEnabled(false);
    return;
  }
  final FileEditorManagerEx fileEditorManager = FileEditorManagerEx.getInstanceEx(project);
  presentation.setEnabled(fileEditorManager.hasOpenedFile ());
}
 
Example 17
Source File: RecentProjectsGroup.java    From consulo with Apache License 2.0 4 votes vote down vote up
public void update(AnActionEvent event) {
  Presentation presentation = event.getPresentation();
  presentation.setEnabled(RecentProjectsManagerBase.getInstance().getRecentProjectsActions(true).length > 0);
}
 
Example 18
Source File: AbstractShowDiffAction.java    From consulo with Apache License 2.0 4 votes vote down vote up
protected static void updateDiffAction(final Presentation presentation, final VcsContext vcsContext,
                                       final VcsBackgroundableActions actionKey) {
  presentation.setEnabled(isEnabled(vcsContext, actionKey) != null);
  presentation.setVisible(isVisible(vcsContext));
}
 
Example 19
Source File: ShowBaseRevisionAction.java    From consulo with Apache License 2.0 4 votes vote down vote up
@Override
protected void update(VcsContext vcsContext, Presentation presentation) {
  final AbstractVcs vcs = AbstractShowDiffAction.isEnabled(vcsContext, null);
  presentation.setEnabled(vcs != null);
}
 
Example 20
Source File: TreeExpandAllActionBase.java    From consulo with Apache License 2.0 4 votes vote down vote up
public final void update(AnActionEvent event) {
  Presentation presentation = event.getPresentation();
  TreeExpander expander = getExpander(event.getDataContext());
  presentation.setEnabled(expander != null && expander.canExpand());
}