1 11 package org.eclipse.ui.internal.cheatsheets.actions; 12 13 import org.eclipse.jface.action.IAction; 14 import org.eclipse.jface.viewers.ISelection; 15 import org.eclipse.swt.events.*; 16 import org.eclipse.swt.widgets.*; 17 import org.eclipse.ui.*; 18 import org.eclipse.ui.internal.cheatsheets.CheatSheetPlugin; 19 20 24 public class CheatSheetMenuAction implements IWorkbenchWindowPulldownDelegate2, IPropertyListener { 25 28 private Menu fMenu; 29 30 34 protected boolean fRecreateMenu = false; 35 36 39 public CheatSheetMenuAction() { 40 CheatSheetPlugin.getPlugin().getCheatSheetHistory().addListener(this); 41 } 42 43 46 public void dispose() { 47 setMenu(null); 48 CheatSheetPlugin.getPlugin().getCheatSheetHistory().removeListener(this); 49 } 50 51 56 protected void fillMenu(Menu menu) { 57 CheatSheetMenu cheatsheetMenuMenuItem = new CheatSheetMenu(); 58 cheatsheetMenuMenuItem.fill(menu, 0); 59 } 60 61 64 public Menu getMenu(Control parent) { 65 return null; 66 } 67 68 71 public Menu getMenu(Menu parent) { 72 setMenu(new Menu(parent)); 73 fillMenu(fMenu); 74 initMenu(); 75 return fMenu; 76 } 77 78 81 public void init(IWorkbenchWindow window) { 82 } 83 84 87 private void initMenu() { 88 fMenu.addMenuListener(new MenuAdapter() { 91 public void menuShown(MenuEvent e) { 92 if (fRecreateMenu) { 93 Menu m = (Menu)e.widget; 94 MenuItem[] items = m.getItems(); 95 for (int i=0; i < items.length; i++) { 96 items[i].dispose(); 97 } 98 fillMenu(m); 99 fRecreateMenu= false; 100 } 101 } 102 }); 103 } 104 105 108 public void propertyChanged(Object source, int propId) { 109 fRecreateMenu = true; 110 } 111 112 115 public void run(IAction action) { 116 } 117 118 121 public void selectionChanged(IAction action, ISelection selection) { 122 } 123 124 129 private void setMenu(Menu menu) { 130 if (fMenu != null) { 131 fMenu.dispose(); 132 } 133 fMenu = menu; 134 } 135 } 136 | Popular Tags |