com.intellij.openapi.actionSystem.Presentation Java Examples

The following examples show how to use com.intellij.openapi.actionSystem.Presentation. 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: PresentationFactory.java    From consulo with Apache License 2.0 6 votes vote down vote up
@Nonnull
public final Presentation getPresentation(@Nonnull AnAction action){
  UIAccess.assertIsUIThread();
  Presentation presentation = myAction2Presentation.get(action);
  if (presentation == null || !action.isDefaultIcon()){
    Presentation templatePresentation = action.getTemplatePresentation();
    if (presentation == null) {
      presentation = templatePresentation.clone();
      myAction2Presentation.put(action, presentation);
    }
    if (!action.isDefaultIcon()) {
      presentation.setIcon(templatePresentation.getIcon());
      presentation.setDisabledIcon(templatePresentation.getDisabledIcon());
    }
    processPresentation(presentation);
  }
  return presentation;
}
 
Example #2
Source File: GraphQLCreateConfigFileAction.java    From js-graphql-intellij-plugin with MIT License 6 votes vote down vote up
@Override
public void update(AnActionEvent e) {

    boolean isAvailable = false;

    if (e.getProject() != null) {
        final DataContext dataContext = e.getDataContext();
        final IdeView view = LangDataKeys.IDE_VIEW.getData(dataContext);
        if (view != null && view.getDirectories().length > 0) {
            final Module module = LangDataKeys.MODULE.getData(dataContext);
            if (module != null) {
                final VirtualFile actionDirectory = getActionDirectory(e);
                if (actionDirectory != null) {
                    isAvailable = (actionDirectory.findChild(GraphQLConfigManager.GRAPHQLCONFIG) == null);
                }
            }
        }
    }

    final Presentation presentation = e.getPresentation();
    presentation.setVisible(isAvailable);
    presentation.setEnabled(isAvailable);
}
 
Example #3
Source File: StopProcessAction.java    From consulo with Apache License 2.0 6 votes vote down vote up
public static void update(@Nonnull Presentation presentation,
                          @Nonnull Presentation templatePresentation,
                          @Nullable ProcessHandler processHandler) {
  boolean enable = false;
  Icon icon = templatePresentation.getIcon();
  String description = templatePresentation.getDescription();
  if (processHandler != null && !processHandler.isProcessTerminated()) {
    enable = true;
    if (processHandler.isProcessTerminating() && processHandler instanceof KillableProcess) {
      KillableProcess killableProcess = (KillableProcess) processHandler;
      if (killableProcess.canKillProcess()) {
        // 'force quite' action presentation
        icon = AllIcons.Debugger.KillProcess;
        description = "Kill process";
      }
    }
  }
  presentation.setEnabled(enable);
  presentation.setIcon(icon);
  presentation.setDescription(description);
}
 
Example #4
Source File: OpenInAndroidStudioAction.java    From flutter-intellij with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
private static void updatePresentation(AnActionEvent event, Presentation state) {
  if (findProjectFile(event) == null) {
    state.setVisible(false);
  }
  else {
    VirtualFile file = event.getData(CommonDataKeys.VIRTUAL_FILE);
    String label, descr;
    if (file != null && !file.isDirectory()) {
      // The file will be opened in an editor in the new IDE window.
      label = LABEL_FILE;
      descr = DESCR_FILE;
    }
    else {
      // The new IDE window will be opened on the Android module but there is no file selected for editing.
      label = LABEL_MODULE;
      descr = DESCR_MODULE;
    }
    state.setVisible(true);
    state.setText(label);
    state.setDescription(descr);
  }
}
 
Example #5
Source File: GenerateLexerRulesForLiteralsAction.java    From intellij-plugin-v4 with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
/** Only show if selection is a literal */
@Override
public void update(AnActionEvent e) {
	Presentation presentation = e.getPresentation();
	VirtualFile grammarFile = MyActionUtils.getGrammarFileFromEvent(e);
	if ( grammarFile==null ) {
		presentation.setEnabled(false);
		return;
	}
	PsiFile file = e.getData(LangDataKeys.PSI_FILE);
	Editor editor = e.getData(PlatformDataKeys.EDITOR);
	PsiElement selectedElement = BaseRefactoringAction.getElementAtCaret(editor, file);
	if ( selectedElement==null ) { // we clicked somewhere outside text
		presentation.setEnabled(false);
		return;
	}
}
 
Example #6
Source File: FlutterViewLocalToggleableAction.java    From flutter-intellij with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
@Override
public final void update(@NotNull AnActionEvent e) {
  // selected
  final boolean selected = this.isSelected();
  final Presentation presentation = e.getPresentation();
  presentation.putClientProperty("selected", selected);

  if (!app.isSessionActive()) {
    if (subscription != null) {
      subscription.dispose();
      subscription = null;
    }
    e.getPresentation().setEnabled(false);
    return;
  }

  if (subscription == null) {
    subscription = stream.listen((value) -> {
      this.setSelected(e, value);
    }, true);
  }
}
 
Example #7
Source File: AbstractCommitChangesAction.java    From consulo with Apache License 2.0 6 votes vote down vote up
@Override
protected void update(final VcsContext vcsContext, final Presentation presentation) {
  super.update(vcsContext, presentation);
  if (presentation.isVisible() && presentation.isEnabled()) {
    final ChangeList[] selectedChangeLists = vcsContext.getSelectedChangeLists();
    final Change[] selectedChanges = vcsContext.getSelectedChanges();
    if (vcsContext.getPlace().equals(ActionPlaces.CHANGES_VIEW_POPUP)) {
      if (selectedChangeLists != null && selectedChangeLists.length > 0) {
        presentation.setEnabled(selectedChangeLists.length == 1);
      }
      else {
        presentation.setEnabled (selectedChanges != null && selectedChanges.length > 0);
      }
    }
    if (presentation.isEnabled() && selectedChanges != null) {
      final ChangeListManager changeListManager = ChangeListManager.getInstance(vcsContext.getProject());
      for(Change c: selectedChanges) {
        if (c.getFileStatus() == FileStatus.HIJACKED && changeListManager.getChangeList(c) == null) {
          presentation.setEnabled(false);
          break;
        }
      }
    }
  }
}
 
Example #8
Source File: CommonCheckinProjectAction.java    From consulo with Apache License 2.0 6 votes vote down vote up
protected void update(VcsContext vcsContext, Presentation presentation) {
  Project project = vcsContext.getProject();
  if (project == null) {
    presentation.setEnabled(false);
    presentation.setVisible(false);
    return;
  }
  final ProjectLevelVcsManager plVcsManager = ProjectLevelVcsManager.getInstance(project);
  if (! plVcsManager.hasActiveVcss()) {
    presentation.setEnabled(false);
    presentation.setVisible(false);
    return;
  }

  String actionName = getActionName(vcsContext) + "...";
  presentation.setText(actionName);

  presentation.setEnabled(! plVcsManager.isBackgroundVcsOperationRunning());
  presentation.setVisible(true);
}
 
Example #9
Source File: ComboBoxButtonImpl.java    From consulo with Apache License 2.0 6 votes vote down vote up
@Override
public void propertyChange(PropertyChangeEvent evt) {
  String propertyName = evt.getPropertyName();
  if (Presentation.PROP_TEXT.equals(propertyName)) {
    updateSize();
  }
  else if (Presentation.PROP_DESCRIPTION.equals(propertyName)) {
    updateTooltipText((String)evt.getNewValue());
  }
  else if (Presentation.PROP_ICON.equals(propertyName)) {
    updateSize();
  }
  else if (Presentation.PROP_ENABLED.equals(propertyName)) {
    setEnabled(((Boolean)evt.getNewValue()).booleanValue());
  }
  else if (ComboBoxButton.LIKE_BUTTON.equals(propertyName)) {
    setLikeButton((Runnable)evt.getNewValue());
  }
}
 
Example #10
Source File: ExportRunConfigurationDialog.java    From intellij with Apache License 2.0 6 votes vote down vote up
@Override
public synchronized void actionPerformed(AnActionEvent anActionEvent) {
  boolean newState = !allSelected;
  for (int i = 0; i < tableModel.enabled.length; i++) {
    table.setValueAt(newState, i, 0);
  }
  allSelected = newState;
  Presentation presentation = anActionEvent.getPresentation();
  if (allSelected) {
    presentation.setText("Deselect All");
    presentation.setIcon(AllIcons.Actions.Unselectall);
  } else {
    presentation.setText("Select All");
    presentation.setIcon(AllIcons.Actions.Selectall);
  }
  tableModel.fireTableDataChanged();
  table.revalidate();
  table.repaint();
}
 
Example #11
Source File: ContentEntryEditingAction.java    From consulo with Apache License 2.0 6 votes vote down vote up
@Override
public void update(AnActionEvent e) {
  super.update(e);
  final Presentation presentation = e.getPresentation();
  presentation.setEnabled(true);
  final VirtualFile[] files = getSelectedFiles();
  if (files.length == 0) {
    presentation.setEnabled(false);
    return;
  }
  for (VirtualFile file : files) {
    if (file == null || !file.isDirectory()) {
      presentation.setEnabled(false);
      break;
    }
  }
}
 
Example #12
Source File: AddOrRemoveCppFileFromAnalysisScopeAction.java    From CppTools with Apache License 2.0 6 votes vote down vote up
public void update(AnActionEvent anActionEvent) {
  final VirtualFile file = (VirtualFile) anActionEvent.getDataContext().getData(DataConstants.VIRTUAL_FILE);
  final Project project = (Project) anActionEvent.getDataContext().getData(DataConstants.PROJECT);
  final Presentation presentation = anActionEvent.getPresentation();

  if (project == null ||
      file == null ||
      file.getFileType() != CppSupportLoader.CPP_FILETYPE ||
      Communicator.isHeaderFile(file)
     ) {
    presentation.setVisible(false);
  } else {
    String url = file.getPresentableUrl().replace(File.separatorChar,'/');
    final Set<String> ignoredFiles = CppSupportLoader.getInstance(project).getIgnoredFilesSet();
    presentation.setVisible(true);

    final String fileName = file.getName();
    final String term = "Cpp Support Analysis Scope";
    presentation.setText(ignoredFiles.contains(url) ? "Add " + fileName + " to "+ term :"Remove " + fileName + " from " + term);
  }
}
 
Example #13
Source File: OpenInAndroidStudioAction.java    From flutter-intellij with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
private static void updatePresentation(AnActionEvent event, Presentation state) {
  if (findProjectFile(event) == null) {
    state.setVisible(false);
  }
  else {
    VirtualFile file = event.getData(CommonDataKeys.VIRTUAL_FILE);
    String label, descr;
    if (file != null && !file.isDirectory()) {
      // The file will be opened in an editor in the new IDE window.
      label = LABEL_FILE;
      descr = DESCR_FILE;
    }
    else {
      // The new IDE window will be opened on the Android module but there is no file selected for editing.
      label = LABEL_MODULE;
      descr = DESCR_MODULE;
    }
    state.setVisible(true);
    state.setText(label);
    state.setDescription(descr);
  }
}
 
Example #14
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 #15
Source File: HideIgnoredFilesAction.java    From idea-gitignore with MIT License 5 votes vote down vote up
/**
 * Toggles {@link IgnoreSettings#hideIgnoredFiles} value.
 *
 * @param e action event
 */
@Override
public void actionPerformed(@NotNull AnActionEvent e) {
    SETTINGS.setHideIgnoredFiles(!SETTINGS.isHideIgnoredFiles());

    final Presentation presentation = this.getTemplatePresentation();
    presentation.setText(getText());
}
 
Example #16
Source File: HideIgnoredFilesActionTest.java    From idea-gitignore with MIT License 5 votes vote down vote up
public void testHideIgnoredFilesActionInvocation() {
    final HideIgnoredFilesAction action = new HideIgnoredFilesAction();
    Presentation presentation;

    presentation = myFixture.testAction(action);
    Assert.assertEquals(IgnoreBundle.message("action.hideIgnoredVisibility"), presentation.getText());
}
 
Example #17
Source File: Unity3dShowMetaFileProjectViewPaneOptionProvider.java    From consulo-unity3d with Apache License 2.0 5 votes vote down vote up
@Override
@RequiredUIAccess
public void update(AnActionEvent e)
{
	super.update(e);
	final Presentation presentation = e.getPresentation();
	final ProjectView projectView = ProjectView.getInstance(e.getProject());
	presentation.setVisible(projectView.getCurrentProjectViewPane() == myPane && Unity3dModuleExtensionUtil.getRootModuleExtension(myPane.getProject()) != null);
}
 
Example #18
Source File: LabeledComboBoxAction.java    From consulo with Apache License 2.0 5 votes vote down vote up
public JComponent createCustomComponent(Presentation presentation) {
  if (myPanel == null) {
    myPanel = new JPanel(new BorderLayout());
    myPanel.setBorder(BorderFactory.createEmptyBorder(0, 4, 0, 4));
    myPanel.add(myLabel, BorderLayout.WEST);
    myComboBox.addActionListener(new ActionListener() {
      public void actionPerformed(final ActionEvent e) {
        selectionChanged(myComboBox.getSelectedItem());
      }
    });
    myComboBox.setModel(createModel());
    myPanel.add(myComboBox, BorderLayout.CENTER);
  }
  return myPanel;
}
 
Example #19
Source File: NewVueActionBase.java    From vue-for-idea with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
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());


    final boolean hasModule = module != null;
    presentation.setEnabled(hasModule);
    presentation.setVisible(hasModule);
}
 
Example #20
Source File: DumpLookupElementWeights.java    From consulo with Apache License 2.0 5 votes vote down vote up
@RequiredUIAccess
@Override
public void update(@Nonnull final AnActionEvent e) {
  final Presentation presentation = e.getPresentation();
  final Editor editor = e.getData(CommonDataKeys.EDITOR);
  presentation.setEnabled(editor != null && LookupManager.getActiveLookup(editor) != null);
}
 
Example #21
Source File: IgnoreFileGroupAction.java    From idea-gitignore with MIT License 5 votes vote down vote up
/**
 * Presents a list of suitable Gitignore files that can cover currently selected {@link VirtualFile}.
 * Shows a subgroup with available files or one option if only one Gitignore file is available.
 *
 * @param e action event
 */
@Override
public void update(@NotNull AnActionEvent e) {
    final VirtualFile file = e.getData(CommonDataKeys.VIRTUAL_FILE);
    final Project project = e.getData(CommonDataKeys.PROJECT);
    final Presentation presentation = e.getPresentation();
    files.clear();

    if (project != null && file != null) {
        try {
            presentation.setVisible(true);
            baseDir = Utils.getModuleRootForFile(file, project);

            for (IgnoreLanguage language : IgnoreBundle.LANGUAGES) {
                //skip already bundled languages for ignore action
                if (!(this instanceof UnignoreFileGroupAction)
                        && (language instanceof GitLanguage || language instanceof MercurialLanguage)) {
                    continue;
                }

                final IgnoreFileType fileType = language.getFileType();
                List<VirtualFile> list = Utils.getSuitableIgnoreFiles(project, fileType, file);
                Collections.reverse(list);
                files.put(fileType, list);
            }
        } catch (ExternalFileException e1) {
            presentation.setVisible(false);
        }
    }

    setPopup(countFiles() > 1);
}
 
Example #22
Source File: AddReplAction.java    From BashSupport with Apache License 2.0 5 votes vote down vote up
@Override
public void update(AnActionEvent e) {
    super.update(e);

    Presentation presentation = e.getPresentation();
    presentation.setEnabled(getModule(e) != null);
}
 
Example #23
Source File: DvcsCompareWithBranchAction.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();
  Project project = e.getProject();
  VirtualFile file = VcsUtil.getIfSingle(e.getData(VcsDataKeys.VIRTUAL_FILE_STREAM));

  presentation.setVisible(project != null);
  presentation.setEnabled(project != null && file != null && isEnabled(getRepositoryManager(project).getRepositoryForFile(file)));
}
 
Example #24
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 #25
Source File: StatusTextAction.java    From consulo with Apache License 2.0 5 votes vote down vote up
@Override
public JComponent createCustomComponent(Presentation presentation, String place) {
  JLabel label = new JLabel();
  //noinspection HardCodedStringLiteral
  label.setText("9888 results");
  Dimension size = label.getPreferredSize();
  size.height = Math.max(size.height, JBUIScale.scale(ActionToolbar.DEFAULT_MINIMUM_BUTTON_SIZE.getHeight()));
  label.setPreferredSize(size);
  label.setText(null);
  label.setHorizontalAlignment(SwingConstants.CENTER);
  return label;
}
 
Example #26
Source File: AddLibraryTargetDirectoryToProjectViewAction.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 visible = false;
  boolean enabled = false;
  Library library = LibraryActionHelper.findLibraryForAction(e);
  if (library != null) {
    visible = true;
    if (getDirectoryToAddForLibrary(project, library) != null) {
      enabled = true;
    }
  }
  presentation.setVisible(visible);
  presentation.setEnabled(enabled);
}
 
Example #27
Source File: GotoTestOrCodeAction.java    From consulo with Apache License 2.0 5 votes vote down vote up
@RequiredUIAccess
@Override
public void update(AnActionEvent event) {
  Presentation p = event.getPresentation();
  if (TestFinderHelper.getFinders().length == 0) {
    p.setVisible(false);
    return;
  }
  p.setEnabled(false);
  Project project = event.getData(CommonDataKeys.PROJECT);
  Editor editor = event.getData(PlatformDataKeys.EDITOR);
  if (editor == null || project == null) return;

  PsiFile psiFile = PsiUtilBase.getPsiFileInEditor(editor, project);
  if (psiFile == null) return;

  PsiElement element = GotoTestOrCodeHandler.getSelectedElement(editor, psiFile);

  if (TestFinderHelper.findSourceElement(element) == null) return;

  p.setEnabled(true);
  if (TestFinderHelper.isTest(element)) {
    p.setText(ActionsBundle.message("action.GotoTestSubject.text"));
    p.setDescription(ActionsBundle.message("action.GotoTestSubject.description"));
  } else {
    p.setText(ActionsBundle.message("action.GotoTest.text"));
    p.setDescription(ActionsBundle.message("action.GotoTest.description"));
  }
}
 
Example #28
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 #29
Source File: IncrementalSyncProjectAction.java    From intellij with Apache License 2.0 5 votes vote down vote up
private static void updateIcon(AnActionEvent e) {
  Project project = e.getProject();
  Presentation presentation = e.getPresentation();
  BlazeSyncStatus statusHelper = BlazeSyncStatus.getInstance(project);
  BlazeSyncStatus.SyncStatus status = statusHelper.getStatus();
  presentation.setIcon(getIcon(status));
  presentation.setEnabled(!statusHelper.syncInProgress());

  if (status == BlazeSyncStatus.SyncStatus.DIRTY
      && !BlazeUserSettings.getInstance().getSyncStatusPopupShown()) {
    BlazeUserSettings.getInstance().setSyncStatusPopupShown(true);
    showPopupNotification(project);
  }
}
 
Example #30
Source File: CreateAction.java    From consulo with Apache License 2.0 5 votes vote down vote up
@Override
protected void updateIcon(final Presentation presentation, final ConfigurationContext context) {
  final RunnerAndConfigurationSettings configuration = context.findExisting();
  if (configuration != null) {
    presentation.setIcon(configuration.getType().getIcon());
  } else {
    super.updateIcon(presentation, context);
  }
}