Lines 22-31
Link Here
|
22 |
import java.util.List; |
22 |
import java.util.List; |
23 |
import java.util.Map; |
23 |
import java.util.Map; |
24 |
import java.util.Set; |
24 |
import java.util.Set; |
25 |
|
|
|
26 |
import org.eclipse.core.commands.Command; |
25 |
import org.eclipse.core.commands.Command; |
27 |
import org.eclipse.core.commands.ParameterizedCommand; |
26 |
import org.eclipse.core.commands.ParameterizedCommand; |
|
|
27 |
import org.eclipse.core.expressions.ExpressionTagNames; |
28 |
import org.eclipse.core.runtime.CoreException; |
28 |
import org.eclipse.core.runtime.CoreException; |
|
|
29 |
import org.eclipse.core.runtime.IConfigurationElement; |
29 |
import org.eclipse.jface.action.ActionContributionItem; |
30 |
import org.eclipse.jface.action.ActionContributionItem; |
30 |
import org.eclipse.jface.action.ContributionManager; |
31 |
import org.eclipse.jface.action.ContributionManager; |
31 |
import org.eclipse.jface.action.CoolBarManager; |
32 |
import org.eclipse.jface.action.CoolBarManager; |
Lines 112-117
Link Here
|
112 |
import org.eclipse.ui.IActionBars2; |
113 |
import org.eclipse.ui.IActionBars2; |
113 |
import org.eclipse.ui.IPerspectiveDescriptor; |
114 |
import org.eclipse.ui.IPerspectiveDescriptor; |
114 |
import org.eclipse.ui.IPerspectiveRegistry; |
115 |
import org.eclipse.ui.IPerspectiveRegistry; |
|
|
116 |
import org.eclipse.ui.ISources; |
115 |
import org.eclipse.ui.IWorkbenchCommandConstants; |
117 |
import org.eclipse.ui.IWorkbenchCommandConstants; |
116 |
import org.eclipse.ui.IWorkbenchWindow; |
118 |
import org.eclipse.ui.IWorkbenchWindow; |
117 |
import org.eclipse.ui.PlatformUI; |
119 |
import org.eclipse.ui.PlatformUI; |
Lines 143-148
Link Here
|
143 |
import org.eclipse.ui.internal.registry.ActionSetDescriptor; |
145 |
import org.eclipse.ui.internal.registry.ActionSetDescriptor; |
144 |
import org.eclipse.ui.internal.registry.ActionSetRegistry; |
146 |
import org.eclipse.ui.internal.registry.ActionSetRegistry; |
145 |
import org.eclipse.ui.internal.registry.IActionSetDescriptor; |
147 |
import org.eclipse.ui.internal.registry.IActionSetDescriptor; |
|
|
148 |
import org.eclipse.ui.internal.registry.IWorkbenchRegistryConstants; |
146 |
import org.eclipse.ui.internal.util.BundleUtility; |
149 |
import org.eclipse.ui.internal.util.BundleUtility; |
147 |
import org.eclipse.ui.internal.util.Util; |
150 |
import org.eclipse.ui.internal.util.Util; |
148 |
import org.eclipse.ui.keys.IBindingService; |
151 |
import org.eclipse.ui.keys.IBindingService; |
Lines 559-564
Link Here
|
559 |
|
562 |
|
560 |
wasChanged = true; |
563 |
wasChanged = true; |
561 |
} |
564 |
} |
|
|
565 |
|
566 |
public String getId() { |
567 |
return descriptor.getId(); |
568 |
} |
562 |
} |
569 |
} |
563 |
|
570 |
|
564 |
/** |
571 |
/** |
Lines 2846-2860
Link Here
|
2846 |
} |
2853 |
} |
2847 |
|
2854 |
|
2848 |
private static String getActionSetID(IContributionItem item) { |
2855 |
private static String getActionSetID(IContributionItem item) { |
|
|
2856 |
String actionSetID = null; |
2849 |
if (item instanceof ActionSetContributionItem) { |
2857 |
if (item instanceof ActionSetContributionItem) { |
2850 |
ActionSetContributionItem asci = (ActionSetContributionItem) item; |
2858 |
ActionSetContributionItem asci = (ActionSetContributionItem) item; |
2851 |
return asci.getActionSetId(); |
2859 |
actionSetID = asci.getActionSetId(); |
2852 |
} |
2860 |
} else if (item instanceof PluginActionCoolBarContributionItem) { |
2853 |
if (item instanceof PluginActionCoolBarContributionItem) { |
|
|
2854 |
PluginActionCoolBarContributionItem pacbci = (PluginActionCoolBarContributionItem) item; |
2861 |
PluginActionCoolBarContributionItem pacbci = (PluginActionCoolBarContributionItem) item; |
2855 |
return pacbci.getActionSetId(); |
2862 |
actionSetID = pacbci.getActionSetId(); |
|
|
2863 |
} else if (item instanceof CommandContributionItem) { |
2864 |
CommandContributionItem commandContributionItem = (CommandContributionItem) item; |
2865 |
actionSetID = getActionSetID(commandContributionItem); |
2866 |
} else if (item instanceof ToolBarContributionItem2) { |
2867 |
actionSetID = ((ToolBarContributionItem2) item).getId(); |
2868 |
} |
2869 |
return actionSetID; |
2870 |
} |
2871 |
|
2872 |
private static String getActionSetID(CommandContributionItem item) { |
2873 |
|
2874 |
String actionSetID = null; |
2875 |
IConfigurationElement element = item.configurationElement; |
2876 |
if (element != null) { |
2877 |
IConfigurationElement[] visibleConfig = element.getChildren(IWorkbenchRegistryConstants.TAG_VISIBLE_WHEN); |
2878 |
if (visibleConfig.length > 0 && visibleConfig.length < 2) { |
2879 |
actionSetID = getActionSetID(visibleConfig[0]); |
2880 |
} else { |
2881 |
IConfigurationElement[] children = element.getChildren(); |
2882 |
for (int i = 0; i < children.length; i++) { |
2883 |
actionSetID = getActionSetID(children[i]); |
2884 |
if (actionSetID != null) |
2885 |
break; |
2886 |
} |
2887 |
} |
2856 |
} |
2888 |
} |
2857 |
return null; |
2889 |
return actionSetID; |
|
|
2890 |
} |
2891 |
|
2892 |
private static String getActionSetID(IConfigurationElement element) { |
2893 |
|
2894 |
if(element == null || element.getChildren().length == 0) |
2895 |
return null; |
2896 |
String actionSetID = null; |
2897 |
IConfigurationElement[] withTag = element.getChildren(ExpressionTagNames.WITH); |
2898 |
outer: |
2899 |
for (int i = 0; i < withTag.length; i++) { |
2900 |
if (!ISources.ACTIVE_CONTEXT_NAME.equals(withTag[i].getAttribute("variable"))) //$NON-NLS-1$ |
2901 |
continue; |
2902 |
IConfigurationElement[] iterateTag = withTag[i].getChildren(ExpressionTagNames.ITERATE); |
2903 |
for (int j = 0; j < iterateTag.length; j++) { |
2904 |
IConfigurationElement[] equalsTag = iterateTag[j].getChildren(ExpressionTagNames.EQUALS); |
2905 |
for (int k = 0; k < equalsTag.length; k++) { |
2906 |
actionSetID = equalsTag[k].getAttribute("value"); //$NON-NLS-1$ |
2907 |
if (actionSetID != null) |
2908 |
break outer; |
2909 |
} |
2910 |
} |
2911 |
} |
2912 |
return actionSetID; |
2858 |
} |
2913 |
} |
2859 |
|
2914 |
|
2860 |
/** |
2915 |
/** |
Lines 3022-3029
Link Here
|
3022 |
} |
3077 |
} |
3023 |
|
3078 |
|
3024 |
private DisplayItem createToolBarStructure(CoolBar coolbar) { |
3079 |
private DisplayItem createToolBarStructure(CoolBar coolbar) { |
3025 |
DisplayItem root = new DisplayItem(null, null); // Create a |
3080 |
DisplayItem root = new DisplayItem(null, null); |
3026 |
// root |
3081 |
// Create a root |
3027 |
createToolbarEntries(coolbar, root); |
3082 |
createToolbarEntries(coolbar, root); |
3028 |
return root; |
3083 |
return root; |
3029 |
} |
3084 |
} |
Lines 3052-3074
Link Here
|
3052 |
if (items[i].getImage() == null) { |
3107 |
if (items[i].getImage() == null) { |
3053 |
toolBarEntry.setImageDescriptor(toolbarImageDescriptor); |
3108 |
toolBarEntry.setImageDescriptor(toolbarImageDescriptor); |
3054 |
} |
3109 |
} |
|
|
3110 |
String actionSetId = getActionSetID(contributionItem); |
3055 |
toolBarEntry.setActionSet((ActionSet) idToActionSet |
3111 |
toolBarEntry.setActionSet((ActionSet) idToActionSet |
3056 |
.get(getActionSetID(contributionItem))); |
3112 |
.get(actionSetId)); |
3057 |
parent.addChild(toolBarEntry); |
|
|
3058 |
|
3113 |
|
3059 |
Control control = items[i].getControl(); |
3114 |
Control control = items[i].getControl(); |
3060 |
|
3115 |
|
3061 |
if (control instanceof ToolBar) { |
3116 |
if (control instanceof ToolBar) { |
3062 |
ToolItem[] toolitems = ((ToolBar) control).getItems(); |
3117 |
ToolItem[] toolitems = ((ToolBar) control).getItems(); |
3063 |
createToolbarEntries(toolitems, toolBarEntry); |
3118 |
createToolbarEntries(toolitems, toolBarEntry, parent); |
3064 |
} |
3119 |
} |
3065 |
|
3120 |
|
3066 |
entries.add(toolBarEntry); |
3121 |
if (toolBarEntry.getChildren().size() != 0) { |
|
|
3122 |
entries.add(toolBarEntry); |
3123 |
parent.addChild(toolBarEntry); |
3124 |
} |
3067 |
} |
3125 |
} |
3068 |
} |
3126 |
} |
3069 |
|
3127 |
|
3070 |
private void createToolbarEntries(ToolItem[] toolitems, |
3128 |
private void createToolbarEntries(ToolItem[] toolitems, DisplayItem parent, DisplayItem root) { |
3071 |
DisplayItem parent) { |
|
|
3072 |
if (toolitems == null) |
3129 |
if (toolitems == null) |
3073 |
return; |
3130 |
return; |
3074 |
|
3131 |
|
Lines 3082-3093
Link Here
|
3082 |
toolBarEntry.setImageDescriptor(ImageDescriptor |
3139 |
toolBarEntry.setImageDescriptor(ImageDescriptor |
3083 |
.createFromImage(image)); |
3140 |
.createFromImage(image)); |
3084 |
} |
3141 |
} |
3085 |
toolBarEntry.setActionSet((ActionSet) idToActionSet |
|
|
3086 |
.get(getActionSetID(contributionItem))); |
3087 |
contributionItem.setVisible(true);// force parents to update |
3142 |
contributionItem.setVisible(true);// force parents to update |
3088 |
toolBarEntry.setCheckState(getToolbarItemIsVisible(toolBarEntry)); |
3143 |
toolBarEntry.setCheckState(getToolbarItemIsVisible(toolBarEntry)); |
3089 |
parent.addChild(toolBarEntry); |
3144 |
|
|
|
3145 |
String actionSetID = getActionSetID(contributionItem); |
3146 |
toolBarEntry.setActionSet((ActionSet) idToActionSet.get(actionSetID)); |
3147 |
ActionSet parentActionSet = parent.getActionSet(); |
3148 |
if (actionSetID != null && parentActionSet != null && parent.getActionSet().getId().equals(actionSetID)) { |
3149 |
parent.addChild(toolBarEntry); |
3150 |
} else { |
3151 |
DisplayItem displayItem = findDisplayItem(root, actionSetID); |
3152 |
if (displayItem != null) |
3153 |
displayItem.addChild(toolBarEntry); |
3154 |
else |
3155 |
parent.addChild(toolBarEntry); |
3156 |
|
3157 |
} |
3158 |
} |
3159 |
} |
3160 |
|
3161 |
public DisplayItem findDisplayItem(DisplayItem parent, String actionSetId) { |
3162 |
|
3163 |
DisplayItem actionSetItem = null; |
3164 |
for (Iterator i = parent.getChildren().iterator(); i.hasNext();) { |
3165 |
DisplayItem item = (DisplayItem) i.next(); |
3166 |
if (item.getActionSet() != null && item.getActionSet().getId().equals(actionSetId)) { |
3167 |
actionSetItem = item; |
3168 |
break; |
3169 |
} |
3090 |
} |
3170 |
} |
|
|
3171 |
return actionSetItem; |
3091 |
} |
3172 |
} |
3092 |
|
3173 |
|
3093 |
/** |
3174 |
/** |