Search in sources :

Example 86 with AnAction

use of com.intellij.openapi.actionSystem.AnAction in project intellij-community by JetBrains.

the class JavaFileTemplatesTest method testManyTemplates.

public void testManyTemplates() {
    FileTemplateManagerImpl templateManager = (FileTemplateManagerImpl) FileTemplateManager.getInstance(getProject());
    templateManager.getState().RECENT_TEMPLATES.clear();
    FileTemplate[] before = templateManager.getAllTemplates();
    try {
        for (int i = 0; i < 30; i++) {
            templateManager.addTemplate("foo" + i, "java");
        }
        AnAction[] children = new CreateFromTemplateGroup().getChildren(new TestActionEvent(new TestDataProvider(getProject())));
        assertEquals(3, children.length);
        assertTrue(IdeBundle.message("action.from.file.template").equals(children[0].getTemplatePresentation().getText()));
    } finally {
        templateManager.setTemplates(FileTemplateManager.DEFAULT_TEMPLATES_CATEGORY, Arrays.asList(before));
        templateManager.getState().RECENT_TEMPLATES.clear();
    }
}
Also used : TestDataProvider(com.intellij.testFramework.TestDataProvider) FileTemplateManagerImpl(com.intellij.ide.fileTemplates.impl.FileTemplateManagerImpl) AnAction(com.intellij.openapi.actionSystem.AnAction) TestActionEvent(com.intellij.testFramework.TestActionEvent) CreateFromTemplateGroup(com.intellij.ide.fileTemplates.actions.CreateFromTemplateGroup)

Example 87 with AnAction

use of com.intellij.openapi.actionSystem.AnAction in project intellij-community by JetBrains.

the class AddFacetOfTypeAction method createAddFacetActions.

public static AnAction[] createAddFacetActions(FacetStructureConfigurable configurable) {
    final List<AnAction> result = new ArrayList<>();
    final StructureConfigurableContext context = configurable.myContext;
    for (FacetType type : FacetTypeRegistry.getInstance().getSortedFacetTypes()) {
        if (hasSuitableModules(context, type)) {
            result.add(new AddFacetOfTypeAction(type, context));
        }
    }
    return result.toArray(new AnAction[result.size()]);
}
Also used : FacetType(com.intellij.facet.FacetType) ArrayList(java.util.ArrayList) AnAction(com.intellij.openapi.actionSystem.AnAction)

Example 88 with AnAction

use of com.intellij.openapi.actionSystem.AnAction in project intellij-community by JetBrains.

the class JdkListConfigurable method createAddAction.

@Override
public AbstractAddGroup createAddAction() {
    return new AbstractAddGroup(ProjectBundle.message("add.new.jdk.text")) {

        @NotNull
        @Override
        public AnAction[] getChildren(@Nullable final AnActionEvent e) {
            DefaultActionGroup group = new DefaultActionGroup(ProjectBundle.message("add.new.jdk.text"), true);
            myJdksTreeModel.createAddActions(group, myTree, projectJdk -> addJdkNode(projectJdk, true));
            return group.getChildren(null);
        }
    };
}
Also used : AnActionEvent(com.intellij.openapi.actionSystem.AnActionEvent) AnAction(com.intellij.openapi.actionSystem.AnAction) DefaultActionGroup(com.intellij.openapi.actionSystem.DefaultActionGroup) Nullable(org.jetbrains.annotations.Nullable)

Example 89 with AnAction

use of com.intellij.openapi.actionSystem.AnAction in project intellij-community by JetBrains.

the class AddAllToFavoritesActionGroup method getChildren.

@Override
@NotNull
public AnAction[] getChildren(@Nullable AnActionEvent e) {
    if (e == null)
        return AnAction.EMPTY_ARRAY;
    final Project project = e.getProject();
    if (project == null) {
        return AnAction.EMPTY_ARRAY;
    }
    final List<String> listNames = FavoritesManager.getInstance(project).getAvailableFavoritesListNames();
    final List<String> availableFavoritesLists = FavoritesManager.getInstance(project).getAvailableFavoritesListNames();
    availableFavoritesLists.remove(FavoritesTreeViewPanel.FAVORITES_LIST_NAME_DATA_KEY.getData(e.getDataContext()));
    if (availableFavoritesLists.isEmpty()) {
        return new AnAction[] { new AddAllOpenFilesToNewFavoritesListAction() };
    }
    AnAction[] actions = new AnAction[listNames.size() + 2];
    int idx = 0;
    for (String favoritesList : listNames) {
        actions[idx++] = new AddAllOpenFilesToFavorites(favoritesList);
    }
    actions[idx++] = Separator.getInstance();
    actions[idx] = new AddAllOpenFilesToNewFavoritesListAction();
    return actions;
}
Also used : Project(com.intellij.openapi.project.Project) AnAction(com.intellij.openapi.actionSystem.AnAction) NotNull(org.jetbrains.annotations.NotNull)

Example 90 with AnAction

use of com.intellij.openapi.actionSystem.AnAction in project intellij-community by JetBrains.

the class CreateFromTemplateActionBase method actionPerformed.

@Override
public final void actionPerformed(AnActionEvent e) {
    DataContext dataContext = e.getDataContext();
    IdeView view = LangDataKeys.IDE_VIEW.getData(dataContext);
    if (view == null)
        return;
    PsiDirectory dir = getTargetDirectory(dataContext, view);
    if (dir == null)
        return;
    Project project = dir.getProject();
    FileTemplate selectedTemplate = getTemplate(project, dir);
    if (selectedTemplate != null) {
        AnAction action = getReplacedAction(selectedTemplate);
        if (action != null) {
            action.actionPerformed(e);
        } else {
            FileTemplateManager.getInstance(project).addRecentName(selectedTemplate.getName());
            AttributesDefaults defaults = getAttributesDefaults(dataContext);
            Properties properties = defaults != null ? defaults.getDefaultProperties() : null;
            CreateFromTemplateDialog dialog = new CreateFromTemplateDialog(project, dir, selectedTemplate, defaults, properties);
            PsiElement createdElement = dialog.create();
            if (createdElement != null) {
                elementCreated(dialog, createdElement);
                view.selectElement(createdElement);
                if (selectedTemplate.isLiveTemplateEnabled() && createdElement instanceof PsiFile) {
                    Map<String, String> defaultValues = getLiveTemplateDefaults(dataContext, ((PsiFile) createdElement));
                    startLiveTemplate((PsiFile) createdElement, notNull(defaultValues, Collections.emptyMap()));
                }
            }
        }
    }
}
Also used : FileTemplate(com.intellij.ide.fileTemplates.FileTemplate) IdeView(com.intellij.ide.IdeView) AnAction(com.intellij.openapi.actionSystem.AnAction) CreateFromTemplateDialog(com.intellij.ide.fileTemplates.ui.CreateFromTemplateDialog) Project(com.intellij.openapi.project.Project) DataContext(com.intellij.openapi.actionSystem.DataContext) PsiDirectory(com.intellij.psi.PsiDirectory) PsiFile(com.intellij.psi.PsiFile) PsiElement(com.intellij.psi.PsiElement)

Aggregations

AnAction (com.intellij.openapi.actionSystem.AnAction)184 AnActionEvent (com.intellij.openapi.actionSystem.AnActionEvent)62 NotNull (org.jetbrains.annotations.NotNull)31 Project (com.intellij.openapi.project.Project)24 Nullable (org.jetbrains.annotations.Nullable)22 ActionManager (com.intellij.openapi.actionSystem.ActionManager)21 DefaultActionGroup (com.intellij.openapi.actionSystem.DefaultActionGroup)21 CustomShortcutSet (com.intellij.openapi.actionSystem.CustomShortcutSet)13 ArrayList (java.util.ArrayList)13 DumbAwareAction (com.intellij.openapi.project.DumbAwareAction)8 VirtualFile (com.intellij.openapi.vfs.VirtualFile)8 ActionGroup (com.intellij.openapi.actionSystem.ActionGroup)7 Presentation (com.intellij.openapi.actionSystem.Presentation)7 PsiFile (com.intellij.psi.PsiFile)7 ReopenProjectAction (com.intellij.ide.ReopenProjectAction)6 Editor (com.intellij.openapi.editor.Editor)6 Keymap (com.intellij.openapi.keymap.Keymap)6 Ref (com.intellij.openapi.util.Ref)6 List (java.util.List)6 DataContext (com.intellij.openapi.actionSystem.DataContext)5