void (ToolbarDecorator decorator) { final Consumer<BaseInjection> consumer = this::addInjection; final Factory<BaseInjection> producer = (NullableFactory<BaseInjection>)() -> { final InjInfo info = getSelectedInjection(); return info == null? null : info.injection; }; for (LanguageInjectionSupport support : InjectorUtils.getActiveInjectionSupports()) { ContainerUtil.addAll(myAddActions, support.createAddActions(myProject, consumer)); final AnAction action = support.createEditAction(myProject, producer); myEditActions .put(support.getId(), action == null ? AbstractLanguageInjectionSupport.createDefaultEditAction(myProject, producer) : action); mySupports.put(support.getId(), support); } myAddActions.sort((o1, o2) -> Comparing.compare(o1.getTemplatePresentation().getText(), o2.getTemplatePresentation().getText())); decorator.disableUpDownActions(); decorator.setAddActionUpdater(e -> !myAddActions.isEmpty()); decorator.setAddAction(this::performAdd); decorator.setAddIcon(LayeredIcon.ADD_WITH_DROPDOWN); decorator.setRemoveActionUpdater(e -> { boolean enabled = false; for (InjInfo info : getSelectedInjections()) { if (!info.bundled) { enabled = true; break; } } return enabled; }); decorator.setRemoveAction(button -> performRemove()); decorator.setEditActionUpdater(e -> { AnAction edit = getEditAction(); if (edit != null) edit.update(e); return edit != null && e.getPresentation().isEnabled(); }); decorator.setEditAction(button -> performEditAction()); decorator.addExtraAction(new DumbAwareEDTUActionButton(IntelliLangBundle.messagePointer("action.AnActionButton.text.duplicate"), IntelliLangBundle.messagePointer("action.AnActionButton.description.duplicate"), IconManager.getInstance().getPlatformIcon(PlatformIcons.Copy)) { @Override public boolean isEnabled() { return getEditAction() != null; } @Override public void actionPerformed(@NotNull AnActionEvent e) { final InjInfo injection = getSelectedInjection(); if (injection != null) { addInjection(injection.injection.copy()); //performEditAction(e); } } }); decorator.addExtraAction( new DumbAwareEDTUActionButton(IntelliLangBundle.messagePointer("action.AnActionButton.text.enable.selected.injections"), IntelliLangBundle.messagePointer("action.AnActionButton.description.enable.selected.injections"), com.intellij.util.PlatformIcons.SELECT_ALL_ICON) { @Override public void actionPerformed(@NotNull final AnActionEvent e) { performSelectedInjectionsEnabled(true); } }); decorator.addExtraAction( new DumbAwareEDTUActionButton(IntelliLangBundle.messagePointer("action.AnActionButton.text.disable.selected.injections"), IntelliLangBundle.messagePointer("action.AnActionButton.description.disable.selected.injections"), com.intellij.util.PlatformIcons.UNSELECT_ALL_ICON) { @Override public void actionPerformed(@NotNull final AnActionEvent e) { performSelectedInjectionsEnabled(false); } }); new DumbAwareAction(IdeBundle.messagePointer("action.Anonymous.text.toggle")) { @Override public void update(@NotNull AnActionEvent e) { SpeedSearchSupply supply = SpeedSearchSupply.getSupply(myInjectionsTable); e.getPresentation().setEnabled(supply == null || !supply.isPopupActive()); } @Override public @NotNull ActionUpdateThread getActionUpdateThread() { return ActionUpdateThread.EDT; } @Override public void actionPerformed(@NotNull final AnActionEvent e) { performToggleAction(); } }.registerCustomShortcutSet(new CustomShortcutSet(KeyStroke.getKeyStroke(KeyEvent.VK_SPACE, 0)), myInjectionsTable); if (myInfos.length > 1) { AnActionButton shareAction = new DumbAwareEDTUActionButton(IntelliLangBundle.messagePointer("action.AnActionButton.text.move.to.ide.scope"), com.intellij.util.PlatformIcons.IMPORT_ICON) { { addCustomUpdater(e -> { CfgInfo cfg = getTargetCfgInfo(getSelectedInjections()); e.getPresentation().setText(cfg == getDefaultCfgInfo() ? IntelliLangBundle.message("label.text.move.to.ide.scope") : IntelliLangBundle.message("label.text.move.to.project.scope")); return cfg != null; }); } @Override public void actionPerformed(@NotNull final AnActionEvent e) { final List<InjInfo> injections = getSelectedInjections(); final CfgInfo cfg = getTargetCfgInfo(injections); if (cfg == null) return; for (InjInfo info : injections) { if (info.cfgInfo == cfg) continue; if (info.bundled) continue; info.cfgInfo.injectionInfos.remove(info); cfg.addInjection(info.injection); } final int[] selectedRows = myInjectionsTable.getSelectedRows(); myInjectionsTable.getListTableModel().setItems(getInjInfoList(myInfos)); TableUtil.selectRows(myInjectionsTable, selectedRows); } @Nullable private CfgInfo getTargetCfgInfo(final List<InjInfo> injections) { CfgInfo cfg = null; for (InjInfo info : injections) { if (info.bundled) { continue; } if (cfg == null) cfg = info.cfgInfo; else if (cfg != info.cfgInfo) return info.cfgInfo; } if (cfg == null) return null; for (CfgInfo info : myInfos) { if (info != cfg) return info; } throw new AssertionError(); } }; shareAction.setShortcut(new CustomShortcutSet(KeyStroke.getKeyStroke(KeyEvent.VK_SPACE, InputEvent.SHIFT_DOWN_MASK))); decorator.addExtraAction(shareAction); } decorator.addExtraAction(new DumbAwareEDTUActionButton(IntelliLangBundle.messagePointer("action.AnActionButton.text.import"), IntelliLangBundle.messagePointer("action.AnActionButton.description.import"), AllIcons.Actions.Install) { @Override public void actionPerformed(@NotNull final AnActionEvent e) { doImportAction(e.getDataContext()); updateCountLabel(); } }); decorator.addExtraAction(new DumbAwareEDTUActionButton(IntelliLangBundle.messagePointer("action.AnActionButton.text.export"), IntelliLangBundle.messagePointer("action.AnActionButton.description.export"), AllIcons.ToolbarDecorator.Export) { @Override public void actionPerformed(@NotNull final AnActionEvent e) { List<BaseInjection> injections = getInjectionList(getSelectedInjections()); VirtualFileWrapper wrapper = FileChooserFactory.getInstance() .createSaveFileDialog(new FileSaverDescriptor(IntelliLangBundle.message("dialog.title.export.selected.injections.to.file"), "", "xml"), myProject) .save((Path)null, null); if (wrapper == null) { return; } Configuration configuration = new Configuration(); configuration.setInjections(injections); try { JDOMUtil.write(configuration.getState(), wrapper.getFile().toPath()); } catch (IOException ex) { final String msg = ex.getLocalizedMessage(); Messages.showErrorDialog(myProject, msg != null && msg.length() > 0 ? msg : ex.toString(), IntelliLangBundle.message("dialog.title.export.failed")); } } @Override public boolean isEnabled() { return !getSelectedInjections().isEmpty(); } }); }