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

The following examples show how to use com.intellij.openapi.actionSystem.Presentation#setEnabledAndVisible() . 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: ToggleWindowedModeAction.java    From consulo with Apache License 2.0 6 votes vote down vote up
@Override
public void update(AnActionEvent event) {
  super.update(event);
  Presentation presentation = event.getPresentation();
  if (SystemInfo.isMac) {
    presentation.setEnabledAndVisible(false);
    return;
  }
  Project project = event.getData(CommonDataKeys.PROJECT);
  if (project == null) {
    presentation.setEnabled(false);
    return;
  }
  ToolWindowManager mgr = ToolWindowManager.getInstance(project);
  String id = mgr.getActiveToolWindowId();
  presentation.setEnabled(id != null && mgr.getToolWindow(id).isAvailable());
}
 
Example 2
Source File: Action.java    From GitLink with MIT License 6 votes vote down vote up
@Override
public void update(@NotNull final AnActionEvent event)
{
    super.update(event);

    if (event.getProject() == null) {
        event.getPresentation().setEnabled(false);
        return;
    }

    Presentation presentation = event.getPresentation();
    Preferences preferences   = Preferences.getInstance(event.getProject());

    if (!preferences.isEnabled()) {
        presentation.setEnabledAndVisible(false);
        return;
    }

    RemoteHost remoteHost = preferences.getRemoteHost();

    presentation.setText(this.displayName(remoteHost));
    presentation.setIcon(remoteHost.icon());

    presentation.setEnabledAndVisible(this.shouldActionBeEnabled(event));
}
 
Example 3
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 4
Source File: ShowGraphHistoryAction.java    From consulo with Apache License 2.0 6 votes vote down vote up
@Override
public void update(AnActionEvent e) {
  Presentation presentation = e.getPresentation();
  if (!Registry.is("vcs.log.graph.history")) {
    presentation.setEnabledAndVisible(false);
  }
  else {
    VirtualFile file = e.getData(CommonDataKeys.VIRTUAL_FILE);
    Project project = e.getProject();
    if (file == null || project == null) {
      presentation.setEnabledAndVisible(false);
    }
    else {
      VirtualFile root = ProjectLevelVcsManager.getInstance(project).getVcsRootFor(file);
      VcsLogData dataManager = VcsProjectLog.getInstance(project).getDataManager();
      if (root == null || dataManager == null) {
        presentation.setEnabledAndVisible(false);
      }
      else {
        presentation.setVisible(dataManager.getRoots().contains(root));
        presentation.setEnabled(dataManager.getIndex().isIndexed(root));
      }
    }
  }
}
 
Example 5
Source File: AttachSourceJarAction.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();
  BlazeProjectData projectData =
      BlazeProjectDataManager.getInstance(project).getBlazeProjectData();
  if (projectData == null) {
    hideAction(presentation);
    return;
  }
  BlazeJarLibrary library = LibraryActionHelper.findBlazeLibraryForAction(project, e);
  if (library == null || library.libraryArtifact.getSourceJars().isEmpty()) {
    hideAction(presentation);
    return;
  }
  presentation.setEnabledAndVisible(true);
  boolean attached =
      AttachedSourceJarManager.getInstance(project).hasSourceJarAttached(library.key);
  presentation.setText(attached ? "Detach Source Jar" : "Attach Source Jar");
}
 
Example 6
Source File: AbstractBuckTestAction.java    From buck with Apache License 2.0 6 votes vote down vote up
/** Updates the given presentation based on the given class/method. */
protected void updatePresentation(
    Presentation presentation, @Nullable PsiClass psiClass, @Nullable PsiMethod psiMethod) {
  String verb;
  if (isDebug()) {
    verb = "Debug";
    presentation.setIcon(BuckIcons.DEBUG_BUCK_TEST);
  } else {
    verb = "Run";
    presentation.setIcon(BuckIcons.RUN_BUCK_TEST);
  }
  if (psiMethod != null) {
    presentation.setText(verb + " '" + truncateName(psiMethod.getName()) + "()' with Buck");
    presentation.setEnabledAndVisible(true);
  } else if (psiClass != null) {
    presentation.setText(verb + " '" + psiClass.getName() + "' with Buck");
    presentation.setEnabledAndVisible(true);
  } else {
    presentation.setText(verb + " test with Buck");
    presentation.setEnabledAndVisible(false);
  }
}
 
Example 7
Source File: AbstractCommonCheckinAction.java    From consulo with Apache License 2.0 6 votes vote down vote up
@Override
protected void update(@Nonnull VcsContext vcsContext, @Nonnull Presentation presentation) {
  Project project = vcsContext.getProject();

  if (project == null || !ProjectLevelVcsManager.getInstance(project).hasActiveVcss()) {
    presentation.setEnabledAndVisible(false);
  }
  else if (!approximatelyHasRoots(vcsContext)) {
    presentation.setEnabled(false);
  }
  else {
    presentation.setText(getActionName(vcsContext) + "...");
    presentation.setEnabled(!ProjectLevelVcsManager.getInstance(project).isBackgroundVcsOperationRunning());
    presentation.setVisible(true);
  }
}
 
Example 8
Source File: SyncUnity3dProjectAction.java    From consulo-unity3d with Apache License 2.0 6 votes vote down vote up
@RequiredUIAccess
@Override
public void update(@Nonnull AnActionEvent e)
{
	Presentation presentation = e.getPresentation();
	Project project = e.getProject();
	if(project == null || Unity3dModuleExtensionUtil.getRootModuleExtension(project) == null)
	{
		presentation.setEnabledAndVisible(false);
		return;
	}

	VirtualFile virtualFile = e.getData(CommonDataKeys.VIRTUAL_FILE);
	if(virtualFile == null || !virtualFile.equals(project.getBaseDir()))
	{
		presentation.setEnabledAndVisible(false);
		return;
	}

	if(project.getUserData(Unity3dProjectImportUtil.ourInProgressFlag) == Boolean.TRUE)
	{
		presentation.setEnabled(false);
		presentation.setVisible(true);
	}
}
 
Example 9
Source File: ProjectFilesViewPane.java    From intellij-pants-plugin with Apache License 2.0 5 votes vote down vote up
@Override
public void update(@NotNull AnActionEvent e) {
  super.update(e);
  final Presentation presentation = e.getPresentation();
  final ProjectView projectView = ProjectView.getInstance(myProject);
  presentation.setEnabledAndVisible(projectView.getCurrentProjectViewPane() == ProjectFilesViewPane.this);
}
 
Example 10
Source File: CleanUnshelvedAction.java    From consulo with Apache License 2.0 5 votes vote down vote up
@Override
public void update(@Nonnull final AnActionEvent e) {
  super.update(e);
  final Project project = getEventProject(e);
  final Presentation presentation = e.getPresentation();
  if (project == null) {
    presentation.setEnabledAndVisible(false);
    return;
  }
  presentation.setVisible(true);
  presentation.setEnabled(!ShelveChangesManager.getInstance(project).getRecycledShelvedChangeLists().isEmpty());
}
 
Example 11
Source File: ToggleFullScreenAction.java    From consulo with Apache License 2.0 5 votes vote down vote up
@RequiredUIAccess
@Override
public void update(@Nonnull AnActionEvent e) {
  Presentation p = e.getPresentation();

  IdeFrameEx frame = null;
  boolean isApplicable = WindowManager.getInstance().isFullScreenSupportedInCurrentOS() && (frame = getFrame()) != null;

  p.setEnabledAndVisible(isApplicable);

  if (isApplicable) {
    p.setText(frame.isInFullScreen() ? TEXT_EXIT_FULL_SCREEN : TEXT_ENTER_FULL_SCREEN);
  }
}
 
Example 12
Source File: GoToBuckFile.java    From buck with Apache License 2.0 5 votes vote down vote up
@Override
public void update(AnActionEvent e) {
  Presentation presentation = e.getPresentation();
  VirtualFile buckFile = findBuckFile(e.getProject());
  if (buckFile == null) {
    presentation.setEnabledAndVisible(false);
  } else {
    presentation.setText("Go to " + buckFile.getName() + " file");
    presentation.setEnabledAndVisible(true);
  }
}
 
Example 13
Source File: ImportModuleAction.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();

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

  presentation.setEnabledAndVisible(!ModuleImportProviders.getExtensions(true).isEmpty());
}
 
Example 14
Source File: OpenCommitInBrowserAction.java    From azure-devops-intellij with MIT License 5 votes vote down vote up
@Override
public void update(@NotNull final AnActionEvent anActionEvent) {

    final Presentation presentation = anActionEvent.getPresentation();

    final Project project = anActionEvent.getData(CommonDataKeys.PROJECT);
    final VcsLog log = anActionEvent.getData(VcsLogDataKeys.VCS_LOG);
    if (project == null || project.isDisposed() || log == null) {
        presentation.setEnabledAndVisible(false);
        return;
    }

    final List<VcsFullCommitDetails> commits = log.getSelectedDetails();
    if (commits.size() == 0) {
        presentation.setEnabledAndVisible(false);
        return;
    }

    final VcsFullCommitDetails commit = commits.get(0);

    final GitRepository repository = GitUtil.getRepositoryManager(project).getRepositoryForRootQuick(commit.getRoot());

    if (repository == null || !TfGitHelper.isTfGitRepository(repository)) {
        presentation.setEnabledAndVisible(false);
        return;
    } else if (commits.size() > 1) {
        // only one for now, leave it visible as a breadcrumb
        presentation.setVisible(true);
        presentation.setEnabled(false);
        return;
    }

    presentation.setEnabledAndVisible(true);
}
 
Example 15
Source File: AddSourceToProjectAction.java    From intellij with Apache License 2.0 5 votes vote down vote up
@Override
protected void updateForBlazeProject(Project project, AnActionEvent e) {
  VirtualFile file = e.getData(CommonDataKeys.VIRTUAL_FILE);
  String description = actionDescription(project, file);

  Presentation presentation = e.getPresentation();
  presentation.setEnabledAndVisible(description != null);
  if (description != null) {
    presentation.setText(description);
  }
}
 
Example 16
Source File: NewBlazePackageAction.java    From intellij with Apache License 2.0 5 votes vote down vote up
@Override
protected void updateForBlazeProject(Project project, AnActionEvent event) {
  Presentation presentation = event.getPresentation();
  String buildSystem = Blaze.buildSystemName(project);
  presentation.setEnabledAndVisible(isEnabled(event));
  presentation.setText(String.format("%s Package", buildSystem));
  presentation.setDescription(String.format("Create a new %s package", buildSystem));
  presentation.setIcon(PlatformIcons.PACKAGE_ICON);
}
 
Example 17
Source File: PsiViewerAction.java    From consulo with Apache License 2.0 5 votes vote down vote up
@Override
public void update(AnActionEvent e) {
  final Project project = e.getDataContext().getData(CommonDataKeys.PROJECT);
  final Presentation p = e.getPresentation();
  if (project == null) {
    p.setVisible(false);
    p.setEnabled(false);
    return;
  }

  p.setEnabledAndVisible(Application.get().isInternal());
}
 
Example 18
Source File: AttachSourceJarAction.java    From intellij with Apache License 2.0 4 votes vote down vote up
private static void hideAction(Presentation presentation) {
  presentation.setEnabledAndVisible(false);
}
 
Example 19
Source File: BuildifierExternalFormatAction.java    From buck with Apache License 2.0 4 votes vote down vote up
@Override
public void update(@NotNull AnActionEvent anActionEvent) {
  Presentation presentation = anActionEvent.getPresentation();
  Runnable action = selectAction(anActionEvent);
  presentation.setEnabledAndVisible(action != null);
}
 
Example 20
Source File: NewClassAction.java    From json2java4idea with Apache License 2.0 4 votes vote down vote up
@Override
public void update(@Nonnull AnActionEvent event) {
    final boolean isAvailable = isAvailable(event);
    final Presentation presentation = event.getPresentation();
    presentation.setEnabledAndVisible(isAvailable);
}