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();
}
}
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()]);
}
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);
}
};
}
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;
}
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()));
}
}
}
}
}
Aggregations