private void updateRegisteredActions() { final Project project = getProject(); if (project.isDisposed()) { return; } final List<Pair<String, AnAction>> actionList = new ArrayList<Pair<String, AnAction>>(); for (final AntBuildFile buildFile : getBuildFiles()) { final AntBuildModelBase model = (AntBuildModelBase)buildFile.getModel(); String defaultTargetActionId = model.getDefaultTargetActionId(); if (defaultTargetActionId != null) { final TargetAction action = new TargetAction(buildFile, TargetAction.DEFAULT_TARGET_NAME, new String[]{TargetAction.DEFAULT_TARGET_NAME}, null); actionList.add(new Pair<String, AnAction>(defaultTargetActionId, action)); } collectTargetActions(model.getFilteredTargets(), actionList, buildFile); collectTargetActions(getMetaTargets(buildFile), actionList, buildFile); } synchronized (this) { // unregister Ant actions ActionManagerEx actionManager = ActionManagerEx.getInstanceEx(); final String[] oldIds = actionManager.getActionIds(AntConfiguration.getActionIdPrefix(project)); for (String oldId : oldIds) { actionManager.unregisterAction(oldId); } final Set<String> registeredIds = StringSetSpinAllocator.alloc(); try { for (Pair<String, AnAction> pair : actionList) { if (!registeredIds.contains(pair.first)) { registeredIds.add(pair.first); actionManager.registerAction(pair.first, pair.second); } } } finally { StringSetSpinAllocator.dispose(registeredIds); } } }
private static void collectTargetActions(final AntBuildTarget[] targets, final List<Pair<String, AnAction>> actionList, final AntBuildFile buildFile) { for (final AntBuildTarget target : targets) { final String actionId = ((AntBuildTargetBase)target).getActionId(); if (actionId != null) { final TargetAction action = new TargetAction(buildFile, target.getName(), new String[]{target.getName()}, target.getNotEmptyDescription()); actionList.add(new Pair<String, AnAction>(actionId, action)); } } }