mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-03-22 15:19:59 +07:00
84 lines
2.6 KiB
Java
84 lines
2.6 KiB
Java
package com.intellij.tools;
|
|
|
|
import com.intellij.openapi.actionSystem.*;
|
|
import com.intellij.openapi.project.Project;
|
|
|
|
/**
|
|
* @author Eugene Belyaev
|
|
*/
|
|
public class ExternalToolsGroup extends SimpleActionGroup {
|
|
public void update(AnActionEvent event){
|
|
Presentation presentation = event.getPresentation();
|
|
removeAll();
|
|
String context = event.getPlace();
|
|
Project project = (Project)event.getDataContext().getData(DataConstants.PROJECT);
|
|
if (project == null) {
|
|
presentation.setVisible(false);
|
|
presentation.setEnabled(false);
|
|
return;
|
|
}
|
|
presentation.setEnabled(true);
|
|
String[] groups = ToolManager.getInstance().getGroups();
|
|
for (int i = 0; i < groups.length; i++) {
|
|
String groupName = groups[i];
|
|
if (groupName != null && groupName.trim().length() > 0) {
|
|
SimpleActionGroup subgroup = new SimpleActionGroup();
|
|
subgroup.getTemplatePresentation().setText(groupName, false);
|
|
subgroup.setPopup(true);
|
|
fillGroup(context, groupName, subgroup);
|
|
if (subgroup.getChildrenCount() > 0) {
|
|
add(subgroup);
|
|
}
|
|
}
|
|
else {
|
|
fillGroup(context, null, this);
|
|
}
|
|
}
|
|
presentation.setVisible(getChildrenCount() > 0);
|
|
}
|
|
|
|
private void fillGroup(String context, String groupName, SimpleActionGroup group) {
|
|
Tool[] tools = ToolManager.getInstance().getTools(groupName);
|
|
for (int i = 0; i < tools.length; i++) {
|
|
Tool tool = tools[i];
|
|
if (isToolVisible(tool, context)) {
|
|
addToolToGroup(tool, group);
|
|
}
|
|
}
|
|
}
|
|
|
|
private void addToolToGroup(Tool tool, SimpleActionGroup group) {
|
|
String id = tool.getActionId();
|
|
AnAction action = ActionManager.getInstance().getAction(id);
|
|
if (action == null) {
|
|
action = new ToolAction(tool);
|
|
}
|
|
|
|
group.add(action);
|
|
}
|
|
|
|
private boolean isToolVisible(Tool tool, String context) {
|
|
if (!tool.isEnabled()) return false;
|
|
if (ActionPlaces.EDITOR_POPUP.equals(context)) {
|
|
return tool.isShownInEditor();
|
|
}
|
|
else if (
|
|
ActionPlaces.PROJECT_VIEW_POPUP.equals(context) ||
|
|
ActionPlaces.COMMANDER_POPUP.equals(context) ||
|
|
ActionPlaces.J2EE_VIEW_POPUP.equals(context) ||
|
|
ActionPlaces.TYPE_HIERARCHY_VIEW_POPUP.equals(context) ||
|
|
ActionPlaces.CALL_HIERARCHY_VIEW_POPUP.equals(context) ||
|
|
ActionPlaces.METHOD_HIERARCHY_VIEW_POPUP.equals(context)
|
|
){
|
|
return tool.isShownInProjectViews();
|
|
}
|
|
else if (ActionPlaces.MAIN_MENU.equals(context)) {
|
|
return tool.isShownInMainMenu();
|
|
}
|
|
else if (ActionPlaces.USAGE_VIEW_POPUP.equals(context)) {
|
|
return tool.isShownInSearchResultsPopup();
|
|
}
|
|
return false;
|
|
}
|
|
|
|
} |