com.intellij.openapi.actionSystem.AnActionEvent Java Examples

The following examples show how to use com.intellij.openapi.actionSystem.AnActionEvent. 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 Project: consulo   Author: consulo   File: EditFavoritesAction.java    License: Apache License 2.0 6 votes vote down vote up
@Override
public void actionPerformed(AnActionEvent e) {
  Project project = e.getProject();
  FavoritesViewTreeBuilder treeBuilder = e.getDataContext().getData(FavoritesTreeViewPanel.FAVORITES_TREE_BUILDER_KEY);
  String listName = e.getDataContext().getData(FavoritesTreeViewPanel.FAVORITES_LIST_NAME_DATA_KEY);
  if (project == null || treeBuilder == null || listName == null) {
    return;
  }
  FavoritesManager favoritesManager = FavoritesManager.getInstance(project);
  FavoritesListProvider provider = favoritesManager.getListProvider(listName);
  Set<Object> selection = treeBuilder.getSelectedElements();
  if (provider != null && provider.willHandle(CommonActionsPanel.Buttons.EDIT, project, selection)) {
    provider.handle(CommonActionsPanel.Buttons.EDIT, project, selection, treeBuilder.getTree());
    return;
  }
  favoritesManager.renameList(project, listName);
}
 
Example #2
Source Project: buck   Author: facebook   File: BuckUninstallAction.java    License: Apache License 2.0 6 votes vote down vote up
@Override
public void executeOnPooledThread(final AnActionEvent e) {
  Project project = e.getProject();
  BuckBuildManager buildManager = BuckBuildManager.getInstance(project);
  String target = buildManager.getCurrentSavedTarget(project);
  BuckModule buckModule = project.getComponent(BuckModule.class);
  buckModule.attach(target);

  if (target == null) {
    buildManager.showNoTargetMessage(project);
    return;
  }

  // Initiate a buck uninstall
  BuckBuildCommandHandler handler = new BuckBuildCommandHandler(project, BuckCommand.UNINSTALL);
  handler.command().addParameter(target);
  buildManager.runBuckCommandWhileConnectedToBuck(handler, ACTION_TITLE, buckModule);
}
 
Example #3
Source Project: consulo   Author: consulo   File: CreateElementActionBase.java    License: Apache License 2.0 6 votes vote down vote up
@RequiredUIAccess
@Override
public final void actionPerformed(@Nonnull final AnActionEvent e) {
  final IdeView view = e.getData(LangDataKeys.IDE_VIEW);
  if (view == null) {
    return;
  }

  final Project project = e.getProject();

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

  invokeDialog(project, dir, elements -> {

    for (PsiElement createdElement : elements) {
      view.selectElement(createdElement);
    }
  });
}
 
Example #4
Source Project: consulo   Author: consulo   File: ContentEntryEditingAction.java    License: 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 #5
Source Project: leetcode-editor   Author: shuzijun   File: ClearOneAction.java    License: Apache License 2.0 6 votes vote down vote up
@Override
public void actionPerformed(AnActionEvent anActionEvent, Config config, JTree tree, Question question) {

    String codeType = config.getCodeType();
    CodeTypeEnum codeTypeEnum = CodeTypeEnum.getCodeTypeEnum(codeType);
    if (codeTypeEnum == null) {
        MessageUtils.getInstance(anActionEvent.getProject()).showWarnMsg("info", PropertiesUtils.getInfo("config.code"));
        return;
    }

    String filePath = PersistentConfig.getInstance().getTempFilePath() + VelocityUtils.convert(config.getCustomFileName(), question) + codeTypeEnum.getSuffix();

    File file = new File(filePath);
    if (file.exists()) {
        ApplicationManager.getApplication().invokeAndWait(() -> {
            VirtualFile vf = LocalFileSystem.getInstance().refreshAndFindFileByIoFile(file);
            if (FileEditorManager.getInstance(anActionEvent.getProject()).isFileOpen(vf)) {
                FileEditorManager.getInstance(anActionEvent.getProject()).closeFile(vf);
            }
            file.delete();
        });
    }
    MessageUtils.getInstance(anActionEvent.getProject()).showInfoMsg(question.getFormTitle(), PropertiesUtils.getInfo("clear.success"));

}
 
Example #6
Source Project: intellij-commit-message-template-plugin   Author: myheritage   File: CommitMessageTemplateAction.java    License: MIT License 6 votes vote down vote up
public void actionPerformed(AnActionEvent e) {
    final CommitMessageI checkinPanel = getCheckinPanel(e);
    if (checkinPanel == null) {
        return;
    }

    Project project = e.getRequiredData(CommonDataKeys.PROJECT);
    CommitMessageTemplateConfig config = CommitMessageTemplateConfig.getInstance(project);

    if (config != null) {
        String commitMessage = config.getCommitMessage();
        if (!commitMessage.isEmpty()) {
            checkinPanel.setCommitMessage(commitMessage);
        }
    }
}
 
Example #7
Source Project: consulo   Author: consulo   File: RefreshLogAction.java    License: Apache License 2.0 6 votes vote down vote up
@Override
public void actionPerformed(AnActionEvent e) {
  VcsLogUtil.triggerUsage(e);

  VcsLogManager logManager = e.getRequiredData(VcsLogInternalDataKeys.LOG_MANAGER);

  // diagnostic for possible refresh problems
  VcsLogUi ui = e.getRequiredData(VcsLogDataKeys.VCS_LOG_UI);
  if (ui instanceof VcsLogUiImpl) {
    VcsLogFilterer filterer = ((VcsLogUiImpl)ui).getFilterer();
    if (!filterer.isValid()) {
      String message = "Trying to refresh invalid log tab.";
      if (!logManager.getDataManager().getProgress().isRunning()) {
        LOG.error(message);
      } else {
        LOG.warn(message);
      }
      filterer.setValid(true);
    }
  }

  logManager.getDataManager().refreshSoftly();
}
 
Example #8
Source Project: leetcode-editor   Author: shuzijun   File: OpenSolutionAction.java    License: Apache License 2.0 6 votes vote down vote up
@Override
public void update(@NotNull AnActionEvent anActionEvent) {
    JTree tree = WindowFactory.getDataContext(anActionEvent.getProject()).getData(DataKeys.LEETCODE_PROJECTS_TREE);
    if (tree == null) {
        anActionEvent.getPresentation().setEnabled(false);
        return;
    }
    Question question = ViewManager.getTreeQuestion(tree, anActionEvent.getProject());
    if (question == null) {
        anActionEvent.getPresentation().setEnabled(false);
        return;
    }
    if (Constant.ARTICLE_LIVE_NONE.equals(question.getArticleLive())) {
        anActionEvent.getPresentation().setEnabled(false);
    } else {
        anActionEvent.getPresentation().setEnabled(true);
    }
}
 
Example #9
Source Project: react-templates-plugin   Author: idok   File: AbstractCreateFormAction.java    License: MIT License 6 votes vote down vote up
public void update(final AnActionEvent e) {
        super.update(e);
//        final Project project = e.getData(CommonDataKeys.PROJECT);
//        final Presentation presentation = e.getPresentation();
//        if (presentation.isEnabled()) {
//            final IdeView view = e.getData(LangDataKeys.IDE_VIEW);
//            if (view != null) {
//                final ProjectFileIndex projectFileIndex = ProjectRootManager.getInstance(project).getFileIndex();
//                final PsiDirectory[] dirs = view.getDirectories();
//                for (final PsiDirectory dir : dirs) {
//                    if (projectFileIndex.isUnderSourceRootOfType(dir.getVirtualFile(), JavaModuleSourceRootTypes.SOURCES) && JavaDirectoryService.getInstance().getPackage(dir) != null) {
//                        return;
//                    }
//                }
//            }
//
//            presentation.setEnabled(false);
//            presentation.setVisible(false);
//        }
    }
 
Example #10
Source Project: consulo   Author: consulo   File: CopyRevisionNumberAction.java    License: Apache License 2.0 6 votes vote down vote up
@Override
public void actionPerformed(AnActionEvent e) {
  VcsRevisionNumber revision = e.getData(VcsDataKeys.VCS_REVISION_NUMBER);
  if (revision == null) {
    VcsFileRevision fileRevision = e.getData(VcsDataKeys.VCS_FILE_REVISION);
    if (fileRevision != null) {
      revision = fileRevision.getRevisionNumber();
    }
  }
  if (revision == null) {
    return;
  }

  String rev = revision instanceof ShortVcsRevisionNumber ? ((ShortVcsRevisionNumber)revision).toShortString() : revision.asString();
  CopyPasteManager.getInstance().setContents(new StringSelection(rev));
}
 
Example #11
Source Project: intellij-plugin-v4   Author: antlr   File: MyActionUtils.java    License: BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
public static PsiElement getSelectedPsiElement(AnActionEvent e) {
	Editor editor = e.getData(PlatformDataKeys.EDITOR);

	if ( editor==null ) { // not in editor
		PsiElement selectedNavElement = e.getData(LangDataKeys.PSI_ELEMENT);
		// in nav bar?
		if ( selectedNavElement==null || !(selectedNavElement instanceof ParserRuleRefNode) ) {
			return null;
		}
		return selectedNavElement;
	}

	// in editor
	PsiFile file = e.getData(LangDataKeys.PSI_FILE);
	if ( file==null ) {
		return null;
	}

	int offset = editor.getCaretModel().getOffset();
	PsiElement el = file.findElementAt(offset);
	return el;
}
 
Example #12
Source Project: azure-devops-intellij   Author: microsoft   File: AddAction.java    License: MIT License 6 votes vote down vote up
@Override
public void actionPerformed(final AnActionEvent anActionEvent) {
    final Project project = anActionEvent.getData(CommonDataKeys.PROJECT);
    final VirtualFile[] files = VcsUtil.getVirtualFiles(anActionEvent);

    final List<VcsException> errors = new ArrayList<VcsException>();
    ProgressManager.getInstance().runProcessWithProgressSynchronously(new Runnable() {
        public void run() {
            ProgressManager.getInstance().getProgressIndicator().setIndeterminate(true);
            errors.addAll(TFSVcs.getInstance(project).getCheckinEnvironment().scheduleUnversionedFilesForAddition(Arrays.asList(files)));
        }
    }, TfPluginBundle.message(TfPluginBundle.KEY_TFVC_ADD_SCHEDULING), false, project);

    if (!errors.isEmpty()) {
        AbstractVcsHelper.getInstance(project).showErrors(errors, TFSVcs.TFVC_NAME);
    }
}
 
Example #13
Source Project: idea-php-symfony2-plugin   Author: Haehnchen   File: SymfonySymbolSearchAction.java    License: MIT License 5 votes vote down vote up
@Override
protected void gotoActionPerformed(AnActionEvent paramAnActionEvent) {
    FeatureUsageTracker.getInstance().triggerFeatureUsed("navigation.popup.file");
    Project localProject = paramAnActionEvent.getData(CommonDataKeys.PROJECT);
    if (localProject != null) {
        SymfonySymbolSearchModel searchModel = new SymfonySymbolSearchModel(localProject, new ChooseByNameContributor[] { new Symfony2NavigationContributor(localProject) });
        showNavigationPopup(paramAnActionEvent, searchModel, new MyGotoCallback(), null, true);
    }
}
 
Example #14
Source Project: data-mediator   Author: LightSun   File: DataMediatorAction.java    License: Apache License 2.0 5 votes vote down vote up
@Override
public void actionPerformed(AnActionEvent e) {
    Project project = getEventProject(e);
    if(project == null){
        return;
    }
    //PsiJavaFile javaFile = (PsiJavaFile) psiClass.getContaningFile();
    //PsiPackage pkg = JavaPsiFacade.getInstance(project).findPackage(javaFile.getPackageName());
    PsiClass psiClass = getPsiClassFromContext(e);
    if(psiClass == null){
        Util.logError("psiClass == null");
        return;
    }
   // final PsiElement parent = psiClass.getParent();
   // Util.logError("parent == " + parent.getClass().getName());

    final PropertyGenerator pmGenerator = new PropertyGenerator(psiClass);

    //parse current
    if (!parseProperties(project, psiClass, pmGenerator, pmGenerator.getProperties())) {
        return;
    }
    if(pmGenerator.isEnableChain()){
        //parse super and sub fields.
        parseSuperProperties(project, psiClass, pmGenerator, true);
    }
    //indicate if super has ISelectable or nor.
    boolean superHasSelectable = false;
    for(PsiClass pc : PsiUtils.getExtendsClasses(psiClass)){
        if(NAME_SELECTABLE.equals(pc.getQualifiedName())){
            superHasSelectable = true;
            break;
        }
    }
    pmGenerator.setHasSelectable(PsiUtils.hasSelectable(psiClass) && !superHasSelectable);
    //do generate
    generateDataMediator(psiClass, pmGenerator);
    //change subclass's generate methods  when chain call enabled and super property changed.
    //but we don't manual change all sub PsiClass. Note this.
}
 
Example #15
Source Project: needsmoredojo   Author: cefolger   File: JavaScriptAction.java    License: Apache License 2.0 5 votes vote down vote up
@Override
public void update(AnActionEvent e)
{
    if(e.getProject() == null)
    {
        e.getPresentation().setEnabled(false);
        return;
    }

    if(!ServiceManager.getService(e.getProject(), DojoSettings.class).isNeedsMoreDojoEnabled())
    {
        e.getPresentation().setEnabled(false);
        return;
    }
    else
    {
        e.getPresentation().setEnabled(true);
    }

    if(fileAgnostic())
    {
        e.getPresentation().setEnabled(true);
        return;
    }

    final PsiFile psiFile = PsiFileUtil.getPsiFileInCurrentEditor(e.getProject());
    if(psiFile == null)
    {
        e.getPresentation().setEnabled(false);
        return;
    }

    if(!supportsFileType(psiFile))
    {
        e.getPresentation().setEnabled(false);
        return;
    }

    e.getPresentation().setEnabled(true);
}
 
Example #16
Source Project: consulo   Author: consulo   File: BaseShowDiffAction.java    License: 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 #17
Source Project: consulo   Author: consulo   File: ProxyUndoRedoAction.java    License: Apache License 2.0 5 votes vote down vote up
@Override
public void actionPerformed(AnActionEvent e) {
  if (myUndo) {
    myUndoManager.undo(myEditor);
  }
  else {
    myUndoManager.redo(myEditor);
  }
}
 
Example #18
Source Project: nosql4idea   Author: dboissier   File: SetSeparatorAction.java    License: Apache License 2.0 5 votes vote down vote up
@Override
public void update(AnActionEvent event) {
    String currentSeparator = redisPanel.getGroupSeparator();
    String textToDisplay = String.format("Group by '%s'", (currentSeparator == null ? "Nothing" : currentSeparator));
    event.getPresentation().setText(textToDisplay);
    event.getPresentation().setDescription(textToDisplay);
    event.getPresentation().setEnabled(redisPanel.isGroupDataEnabled());
}
 
Example #19
@Override
public void actionPerformed(AnActionEvent event) {
  FlutterInitializer.sendAnalyticsAction(this);

  final Project project = event.getProject();
  if (project == null) {
    return;
  }

  DeviceService.getInstance(project).restart();
}
 
Example #20
Source Project: consulo   Author: consulo   File: GoToChangePopupBuilder.java    License: Apache License 2.0 5 votes vote down vote up
@RequiredUIAccess
@Override
public void update(@Nonnull AnActionEvent e) {
  if (myChain.getRequests().size() <= 1) {
    e.getPresentation().setEnabledAndVisible(false);
    return;
  }

  e.getPresentation().setEnabledAndVisible(true);
}
 
Example #21
@Override
public void actionPerformed(AnActionEvent event) {
  FlutterInitializer.sendAnalyticsAction(this);

  final Project project = event.getProject();
  if (project == null) {
    return;
  }

  DeviceService.getInstance(project).restart();
}
 
Example #22
Source Project: azure-devops-intellij   Author: microsoft   File: ToolbarToggleButton.java    License: MIT License 5 votes vote down vote up
@Override
public void setSelected(final AnActionEvent e, final boolean state) {
    if (checked != state) {
        checked = state;
        listenerContainer.triggerEvent(this, actionCommand);
    }
}
 
Example #23
Source Project: dummytext-plugin   Author: kstenschke   File: Action.java    License: Apache License 2.0 5 votes vote down vote up
/**
 * Insert or replace selection with random dummy text
 *
 * @param event ActionSystem event
 */
public void actionPerformed(final AnActionEvent event) {
    Project currentProject = event.getData(PlatformDataKeys.PROJECT);

    CommandProcessor.getInstance().executeCommand(currentProject, () -> ApplicationManager.getApplication().runWriteAction(() -> {
        String genreCode  = PluginPreferences.getGenreCode();
        new ActionPerformer(genreCode).write(event);
    }), StaticTexts.HISTORY_INSERT_DUMMY_TEXT, UndoConfirmationPolicy.DO_NOT_REQUEST_CONFIRMATION);
}
 
Example #24
Source Project: consulo   Author: consulo   File: CloseAction.java    License: Apache License 2.0 5 votes vote down vote up
@RequiredUIAccess
@Override
public void update(@Nonnull AnActionEvent e) {
  e.getPresentation().setIcon(ActionPlaces.isToolbarPlace(e.getPlace()) ? AllIcons.Actions.Cancel : null);

  CloseTarget closeTarget = e.getData(CloseTarget.KEY);
  e.getPresentation().setEnabled(closeTarget != null);
}
 
Example #25
public boolean isSelected(AnActionEvent event) {
    AEMPluginConfiguration pluginConfiguration = ComponentProvider.getComponent(event.getProject(), AEMPluginConfiguration.class);
    if(pluginConfiguration != null) {
        return pluginConfiguration.isListenToFileSystemEvents();
    } else {
        return true;
    }
}
 
Example #26
Source Project: reasonml-idea-plugin   Author: reasonml-editor   File: ConvertAction.java    License: MIT License 5 votes vote down vote up
@Override
public void actionPerformed(@NotNull AnActionEvent e) {
    PsiFile file = e.getData(PSI_FILE);
    Project project = e.getProject();

    if (project != null && file != null) {
        apply(project, file, false);
    }
}
 
Example #27
Source Project: azure-devops-intellij   Author: microsoft   File: WorkItemQueryDropDown.java    License: MIT License 5 votes vote down vote up
@Override
public void actionPerformed(final AnActionEvent anActionEvent) {
    if (!this.equals(selectedQuery)) {
        // when new query is selected, the label needs to be updated and the listener has to be made aware of the action
        selectedQuery = this;
        pickerLabel.revalidate();
        pickerLabel.repaint();

        if (listener != null) {
            listener.actionPerformed(new ActionEvent(this, 0, CMD_QUERY_COMBO_BOX_CHANGED));
        }
    }
}
 
Example #28
Source Project: consulo   Author: consulo   File: ToggleBookmarkAction.java    License: Apache License 2.0 5 votes vote down vote up
@Override
public void actionPerformed(AnActionEvent e) {
  DataContext dataContext = e.getDataContext();
  Project project = dataContext.getData(CommonDataKeys.PROJECT);
  if (project == null) return;
  BookmarkInContextInfo info = new BookmarkInContextInfo(dataContext, project).invoke();
  if (info.getFile() == null) return;

  if (info.getBookmarkAtPlace() != null) {
    BookmarkManager.getInstance(project).removeBookmark(info.getBookmarkAtPlace());
  }
  else {
    BookmarkManager.getInstance(project).addTextBookmark(info.getFile(), info.getLine(), "");
  }
}
 
Example #29
Source Project: consulo   Author: consulo   File: ScheduleForAdditionAction.java    License: Apache License 2.0 5 votes vote down vote up
public void update(@Nonnull AnActionEvent e) {
  boolean enabled = e.getProject() != null && !isEmpty(getUnversionedFiles(e, e.getProject()));

  e.getPresentation().setEnabled(enabled);
  if (ActionPlaces.ACTION_PLACE_VCS_QUICK_LIST_POPUP_ACTION.equals(e.getPlace()) || ActionPlaces.CHANGES_VIEW_POPUP.equals(e.getPlace())) {
    e.getPresentation().setVisible(enabled);
  }
}
 
Example #30
Source Project: idea-php-symfony2-plugin   Author: Haehnchen   File: NewBundleCompilerPass.java    License: MIT License 5 votes vote down vote up
@Override
public void actionPerformed(@NotNull AnActionEvent event) {

    Project project = getEventProject(event);
    if(project == null) {
        this.setStatus(event, false);
        return;
    }

    PsiDirectory bundleDirContext = BundleClassGeneratorUtil.getBundleDirContext(event);
    if(bundleDirContext == null) {
        return;
    }

    final PhpClass phpClass = BundleClassGeneratorUtil.getBundleClassInDirectory(bundleDirContext);
    if(phpClass == null) {
        return;
    }

    new WriteCommandAction(project) {
        @Override
        protected void run(@NotNull Result result) throws Throwable {
            PsiElement psiFile = PhpBundleFileFactory.invokeCreateCompilerPass(phpClass, null);
            if(psiFile != null) {
                new OpenFileDescriptor(getProject(), psiFile.getContainingFile().getVirtualFile(), 0).navigate(true);
            }
        }

        @Override
        public String getGroupID() {
            return "Create CompilerClass";
        }
    }.execute();

}