@Override @NotNull public AnAction[] getChildren(@Nullable AnActionEvent e) { if (e == null) { return EMPTY_ARRAY; } final Project project = CommonDataKeys.PROJECT.getData(e.getDataContext()); 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 SendToNewFavoritesListAction()}; } List<AnAction> actions = new ArrayList<AnAction>(); for (String list : availableFavoritesLists) { actions.add(new SendToFavoritesAction(list)); } actions.add(AnSeparator.getInstance()); actions.add(new SendToNewFavoritesListAction()); return actions.toArray(new AnAction[actions.size()]); }
@Override @NotNull public AnAction[] getChildren(@Nullable AnActionEvent e) { FileTemplateManager manager = FileTemplateManager.getInstance(); FileTemplate[] templates = manager.getAllTemplates(); boolean showAll = templates.length <= FileTemplateManager.RECENT_TEMPLATES_SIZE; if (!showAll) { Collection<String> recentNames = manager.getRecentNames(); templates = new FileTemplate[recentNames.size()]; int i = 0; for (String name : recentNames) { templates[i] = FileTemplateManager.getInstance().getTemplate(name); i++; } } Arrays.sort( templates, new Comparator<FileTemplate>() { @Override public int compare(FileTemplate template1, FileTemplate template2) { // java first if (template1.isTemplateOfType(InternalStdFileTypes.JAVA) && !template2.isTemplateOfType(InternalStdFileTypes.JAVA)) { return -1; } if (template2.isTemplateOfType(InternalStdFileTypes.JAVA) && !template1.isTemplateOfType(InternalStdFileTypes.JAVA)) { return 1; } // group by type int i = template1.getExtension().compareTo(template2.getExtension()); if (i != 0) { return i; } // group by name if same type return template1.getName().compareTo(template2.getName()); } }); List<AnAction> result = new ArrayList<AnAction>(); for (FileTemplate template : templates) { if (canCreateFromTemplate(e, template)) { AnAction action = replaceAction(template); if (action == null) { action = new CreateFromTemplateAction(template); } result.add(action); } } if (!result.isEmpty()) { if (!showAll) { result.add(new CreateFromTemplatesAction(IdeBundle.message("action.from.file.template"))); } result.add(AnSeparator.getInstance()); result.add(new EditFileTemplatesAction(IdeBundle.message("action.edit.file.templates"))); } return result.toArray(new AnAction[result.size()]); }