1 11 package org.eclipse.search.internal.ui; 12 13 import java.util.Iterator ; 14 15 import org.eclipse.swt.SWT; 16 import org.eclipse.swt.widgets.Control; 17 import org.eclipse.swt.widgets.Menu; 18 import org.eclipse.swt.widgets.MenuItem; 19 20 import org.eclipse.jface.action.Action; 21 import org.eclipse.jface.action.ActionContributionItem; 22 import org.eclipse.jface.action.IMenuCreator; 23 24 27 class SearchDropDownAction extends Action implements IMenuCreator { 28 29 30 public static final int RESULTS_IN_DROP_DOWN= 10; 31 32 private Menu fMenu; 33 34 public SearchDropDownAction() { 35 setText(SearchMessages.SearchResultView_previousSearches_text); 36 setToolTipText(SearchMessages.SearchResultView_previousSearches_tooltip); 37 SearchPluginImages.setImageDescriptors(this, SearchPluginImages.T_LCL, SearchPluginImages.IMG_LCL_SEARCH_HISTORY); 38 setMenuCreator(this); 39 } 40 41 public void dispose() { 42 if (fMenu != null) { 43 fMenu.dispose(); 44 fMenu= null; 45 } 46 } 47 48 public Menu getMenu(Menu parent) { 49 return null; 50 } 51 52 public Menu getMenu(Control parent) { 53 if (fMenu != null) 54 fMenu.dispose(); 55 56 fMenu= new Menu(parent); 57 boolean checkedOne= false; 58 Iterator iter= SearchManager.getDefault().getPreviousSearches().iterator(); 59 Search selected= SearchManager.getDefault().getCurrentSearch(); 60 int i= 0; 61 while (iter.hasNext() && i++ < RESULTS_IN_DROP_DOWN) { 62 Search search= (Search)iter.next(); 63 ShowSearchAction action= new ShowSearchAction(search); 64 action.setChecked(search.equals(selected)); 65 if (search.equals(selected)) 66 checkedOne= true; 67 addActionToMenu(fMenu, action); 68 } 69 new MenuItem(fMenu, SWT.SEPARATOR); 70 if (iter.hasNext()) { 71 Action others= new ShowSearchesAction(); 72 others.setChecked(!checkedOne); 73 addActionToMenu(fMenu, others); 74 } 75 addActionToMenu(fMenu, new RemoveAllSearchesAction()); 76 return fMenu; 77 } 78 79 protected void addActionToMenu(Menu parent, Action action) { 80 ActionContributionItem item= new ActionContributionItem(action); 81 item.fill(parent, -1); 82 } 83 84 public void run() { 85 new ShowSearchesAction().run(true); 86 } 87 88 92 void clear() { 93 dispose(); 94 } 95 } 96 | Popular Tags |