1 12 13 package org.eclipse.search.internal.ui; 14 15 import java.util.Iterator ; 16 import java.util.List ; 17 18 import org.eclipse.swt.widgets.Control; 19 import org.eclipse.swt.widgets.Menu; 20 21 import org.eclipse.jface.action.Action; 22 import org.eclipse.jface.action.ActionContributionItem; 23 import org.eclipse.jface.action.IAction; 24 import org.eclipse.jface.resource.ImageDescriptor; 25 import org.eclipse.jface.viewers.ISelection; 26 27 import org.eclipse.ui.IWorkbenchWindow; 28 import org.eclipse.ui.IWorkbenchWindowPulldownDelegate2; 29 import org.eclipse.ui.activities.WorkbenchActivityHelper; 30 31 public class OpenSearchDialogPageAction implements IWorkbenchWindowPulldownDelegate2 { 32 33 private IWorkbenchWindow fWorkbenchWindow; 34 private Menu fMenu; 35 private OpenSearchDialogAction fOpenSearchDialogAction; 36 37 40 public Menu getMenu(Menu parent) { 41 fMenu= new Menu(parent); 42 fillMenu(fMenu); 43 return fMenu; 44 } 45 46 49 public Menu getMenu(Control parent) { 50 fMenu= new Menu(parent); 51 fillMenu(fMenu); 52 return fMenu; 53 } 54 55 58 public void dispose() { 59 fMenu= null; 60 if (fOpenSearchDialogAction != null) { 61 fOpenSearchDialogAction.dispose(); 62 } 63 } 64 65 68 public void init(IWorkbenchWindow window) { 69 fWorkbenchWindow= window; 70 } 71 72 75 public void run(IAction action) { 76 if (fOpenSearchDialogAction == null) { 77 fOpenSearchDialogAction= new OpenSearchDialogAction(); 78 } 79 fOpenSearchDialogAction.run(action); 80 } 81 82 85 public void selectionChanged(IAction action, ISelection sel) { 86 } 88 89 protected void fillMenu(Menu localMenu) { 90 List pageDescriptors= SearchPlugin.getDefault().getSearchPageDescriptors(); 91 int accelerator= 1; 92 for (Iterator iter= pageDescriptors.iterator(); iter.hasNext();) { 93 SearchPageDescriptor desc= (SearchPageDescriptor) iter.next(); 94 if (!WorkbenchActivityHelper.filterItem(desc)) { 95 SearchPageAction action= new SearchPageAction(fWorkbenchWindow, desc); 96 addToMenu(localMenu, action, accelerator++); 97 } 98 } 99 } 100 101 protected void addToMenu(Menu localMenu, IAction action, int accelerator) { 102 StringBuffer label= new StringBuffer (); 103 if (accelerator >= 0 && accelerator < 10) { 104 label.append('&'); 106 label.append(accelerator); 107 label.append(' '); 108 } 109 label.append(action.getText()); 110 action.setText(label.toString()); 111 ActionContributionItem item= new ActionContributionItem(action); 112 item.fill(localMenu, -1); 113 } 114 115 private static final class SearchPageAction extends Action { 116 private final OpenSearchDialogAction fOpenSearchDialogAction; 117 118 public SearchPageAction(IWorkbenchWindow workbenchWindow, SearchPageDescriptor pageDescriptor) { 119 super(); 120 fOpenSearchDialogAction= new OpenSearchDialogAction(workbenchWindow, pageDescriptor.getId()); 121 init(pageDescriptor); 122 } 123 124 private void init(SearchPageDescriptor pageDesc) { 125 setText(pageDesc.getLabel()); 126 setToolTipText(pageDesc.getLabel()); 127 ImageDescriptor imageDescriptor= pageDesc.getImage(); 128 if (imageDescriptor != null) { 129 setImageDescriptor(imageDescriptor); 130 } 131 } 132 133 public void run() { 134 fOpenSearchDialogAction.run(this); 135 } 136 137 } 138 } 139 | Popular Tags |