1 14 package org.eclipse.ui.internal.ide.actions; 15 16 import org.eclipse.core.resources.ResourcesPlugin; 17 import org.eclipse.jface.action.ActionContributionItem; 18 import org.eclipse.jface.action.ContributionItem; 19 import org.eclipse.jface.action.IAction; 20 import org.eclipse.jface.action.IMenuListener; 21 import org.eclipse.jface.action.IMenuManager; 22 import org.eclipse.jface.action.MenuManager; 23 import org.eclipse.jface.action.Separator; 24 import org.eclipse.swt.widgets.Menu; 25 import org.eclipse.ui.IWorkbenchWindow; 26 import org.eclipse.ui.IWorkingSet; 27 import org.eclipse.ui.application.IActionBarConfigurer; 28 29 34 public class BuildSetMenu extends ContributionItem { 35 private IActionBarConfigurer actionBars; 36 37 boolean dirty = true; 38 39 private IMenuListener menuListener = new IMenuListener() { 40 public void menuAboutToShow(IMenuManager manager) { 41 manager.markDirty(); 42 dirty = true; 43 } 44 }; 45 46 private IAction selectBuildWorkingSetAction; 47 48 private IWorkbenchWindow window; 49 50 55 public BuildSetMenu(IWorkbenchWindow window, IActionBarConfigurer actionBars) { 56 this.window = window; 57 this.actionBars = actionBars; 58 selectBuildWorkingSetAction = new SelectBuildWorkingSetAction(window, 59 actionBars); 60 } 61 62 68 private void addMnemonic(BuildSetAction action, int index) { 69 StringBuffer label = new StringBuffer (); 70 if (index < 9) { 72 label.append('&'); 73 label.append(index); 74 label.append(' '); 75 } 76 label.append(action.getWorkingSet().getLabel()); 77 action.setText(label.toString()); 78 } 79 80 83 public void fill(Menu menu, int index) { 84 if (getParent() instanceof MenuManager) { 85 ((MenuManager) getParent()).addMenuListener(menuListener); 86 } 87 if (!dirty) { 88 return; 89 } 90 fillMenu(menu); 91 dirty = false; 92 } 93 94 98 private void fillMenu(Menu menu) { 99 boolean isAutoBuilding = ResourcesPlugin.getWorkspace() 100 .isAutoBuilding(); 101 102 IWorkingSet[] sets = window.getWorkbench().getWorkingSetManager() 104 .getRecentWorkingSets(); 105 BuildSetAction last = BuildSetAction.lastBuilt; 106 IWorkingSet lastSet = null; 107 int accel = 1; 109 if (last != null) { 110 boolean found = false; 112 for (int i = 0; i < sets.length; i++) { 113 if (sets[i].equals(last.getWorkingSet())){ 114 found = true; 115 break; 116 } 117 } 118 if (found) { 119 last.setChecked(true); 120 last.setEnabled(!isAutoBuilding); 121 last.setActionDefinitionId("org.eclipse.ui.project.buildLast"); addMnemonic(last, accel++); 123 new ActionContributionItem(last).fill(menu, -1); 124 lastSet = last.getWorkingSet(); 125 } else { 126 BuildSetAction.lastBuilt = null; 127 } 128 } 129 for (int i = 0; i < sets.length; i++) { 131 if (lastSet != null && lastSet.equals(sets[i])) { 132 continue; 133 } 134 BuildSetAction action = new BuildSetAction(sets[i], window, 135 actionBars); 136 addMnemonic(action, accel++); 137 action.setEnabled(!isAutoBuilding); 138 new ActionContributionItem(action).fill(menu, -1); 139 } 140 if (sets.length > 0) { 142 new Separator().fill(menu, -1); 143 } 144 selectBuildWorkingSetAction.setEnabled(!isAutoBuilding); 145 new ActionContributionItem(selectBuildWorkingSetAction).fill(menu, -1); 146 } 147 148 public boolean isDirty() { 149 return dirty; 150 } 151 152 155 public boolean isDynamic() { 156 return true; 157 } 158 } 159 | Popular Tags |