Download
Getting Started
Members
Projects
Community
Marketplace
Events
Planet Eclipse
Newsletter
Videos
Participate
Report a Bug
Forums
Mailing Lists
Wiki
IRC
How to Contribute
Working Groups
Automotive
Internet of Things
LocationTech
Long-Term Support
PolarSys
Science
OpenMDM
More
Community
Marketplace
Events
Planet Eclipse
Newsletter
Videos
Participate
Report a Bug
Forums
Mailing Lists
Wiki
IRC
How to Contribute
Working Groups
Automotive
Internet of Things
LocationTech
Long-Term Support
PolarSys
Science
OpenMDM
Toggle navigation
Bugzilla – Attachment 127393 Details for
Bug 266938
Replace (JDT)QuickMenuAction with QuickMenuCreator
Home
|
New
|
Browse
|
Search
|
[?]
|
Reports
|
Requests
|
Help
|
Log In
[x]
|
Terms of Use
|
Copyright Agent
Some Eclipse Foundation services are deprecated, or will be soon. Please ensure you've read
this important communication.
[patch]
Fix
quickMenu_patch.txt (text/plain), 33.96 KB, created by
Markus Keller
on 2009-03-03 16:45:26 EST
(
hide
)
Description:
Fix
Filename:
MIME Type:
Creator:
Markus Keller
Created:
2009-03-03 16:45:26 EST
Size:
33.96 KB
patch
obsolete
>### Eclipse Workspace Patch 1.0 >#P org.eclipse.jdt.ui >Index: ui/org/eclipse/jdt/internal/ui/actions/QuickMenuAction.java >=================================================================== >RCS file: ui/org/eclipse/jdt/internal/ui/actions/QuickMenuAction.java >diff -N ui/org/eclipse/jdt/internal/ui/actions/QuickMenuAction.java >--- ui/org/eclipse/jdt/internal/ui/actions/QuickMenuAction.java 31 Dec 2008 21:13:10 -0000 1.16 >+++ /dev/null 1 Jan 1970 00:00:00 -0000 >@@ -1,302 +0,0 @@ >-/******************************************************************************* >- * Copyright (c) 2000, 2008 IBM Corporation and others. >- * All rights reserved. This program and the accompanying materials >- * are made available under the terms of the Eclipse Public License v1.0 >- * which accompanies this distribution, and is available at >- * http://www.eclipse.org/legal/epl-v10.html >- * >- * Contributors: >- * IBM Corporation - initial API and implementation >- *******************************************************************************/ >-package org.eclipse.jdt.internal.ui.actions; >- >-import java.util.ArrayList; >-import java.util.List; >- >-import org.eclipse.swt.custom.StyledText; >-import org.eclipse.swt.graphics.GC; >-import org.eclipse.swt.graphics.Point; >-import org.eclipse.swt.graphics.Rectangle; >-import org.eclipse.swt.widgets.Control; >-import org.eclipse.swt.widgets.Display; >-import org.eclipse.swt.widgets.Menu; >-import org.eclipse.swt.widgets.Table; >-import org.eclipse.swt.widgets.TableItem; >-import org.eclipse.swt.widgets.Tree; >-import org.eclipse.swt.widgets.TreeItem; >- >-import org.eclipse.jface.action.Action; >-import org.eclipse.jface.action.IMenuManager; >-import org.eclipse.jface.action.MenuManager; >- >-import org.eclipse.ui.PlatformUI; >-import org.eclipse.ui.keys.IBindingService; >- >-/** >- * A quick menu actions provides support to assign short cuts >- * to sub menus. >- * >- * @since 3.0 >- */ >-public abstract class QuickMenuAction extends Action { >- >- private static final int CHAR_INDENT= 3; >- >- /** >- * Creates a new quick menu action with the given command id. >- * >- * @param commandId the command id of the short cut used to open >- * the sub menu >- */ >- public QuickMenuAction(String commandId) { >- setActionDefinitionId(commandId); >- } >- >- /** >- * {@inheritDoc} >- */ >- public void run() { >- Display display= Display.getCurrent(); >- if (display == null) >- return; >- Control focus= display.getFocusControl(); >- if (focus == null || focus.isDisposed()) >- return; >- >- MenuManager menu= new MenuManager(); >- fillMenu(menu); >- final Menu widget= menu.createContextMenu(focus.getShell()); >- Point location= computeMenuLocation(focus, widget); >- if (location == null) >- return; >- widget.setLocation(location); >- widget.setVisible(true); >- while (!widget.isDisposed() && widget.isVisible()) { >- if (!display.readAndDispatch()) >- display.sleep(); >- } >- if (!widget.isDisposed()) { >- widget.dispose(); >- } >- } >- >- /** >- * Hook to fill a menu manager with the items of the sub menu. >- * >- * @param menu the sub menu to fill >- */ >- protected abstract void fillMenu(IMenuManager menu); >- >- /** >- * Adds the shortcut to the given menu text and returns it. >- * >- * @param menuText the menu text >- * @return the menu text with the shortcut >- * @since 3.1 >- */ >- public String addShortcut(String menuText) { >- String shortcut= getShortcutString(); >- if (menuText == null || shortcut == null) >- return menuText; >- >- return menuText + '\t' + shortcut; >- } >- >- /** >- * Returns the shortcut assigned to the sub menu or <code>null</code> if >- * no short cut is assigned. >- * >- * @return the shortcut as a human readable string or <code>null</code> >- */ >- private String getShortcutString() { >- IBindingService bindingService= (IBindingService)PlatformUI.getWorkbench().getAdapter(IBindingService.class); >- if (bindingService == null) >- return null; >- return bindingService.getBestActiveBindingFormattedFor(getActionDefinitionId()); >- } >- >- private Point computeMenuLocation(Control focus, Menu menu) { >- Point cursorLocation= focus.getDisplay().getCursorLocation(); >- Rectangle clientArea= null; >- Point result= null; >- if (focus instanceof StyledText) { >- StyledText styledText= (StyledText)focus; >- clientArea= styledText.getClientArea(); >- result= computeMenuLocation(styledText); >- } else if (focus instanceof Tree) { >- Tree tree= (Tree)focus; >- clientArea= tree.getClientArea(); >- result= computeMenuLocation(tree); >- } else if (focus instanceof Table) { >- Table table= (Table)focus; >- clientArea= table.getClientArea(); >- result= computeMenuLocation(table); >- } >- if (result == null) { >- result= focus.toControl(cursorLocation); >- } >- if (clientArea != null && !clientArea.contains(result)) { >- result= new Point( >- clientArea.x + clientArea.width / 2, >- clientArea.y + clientArea.height / 2); >- } >- Rectangle shellArea= focus.getShell().getClientArea(); >- if (!shellArea.contains(focus.getShell().toControl(focus.toDisplay(result)))) { >- result= new Point( >- shellArea.x + shellArea.width / 2, >- shellArea.y + shellArea.height / 2); >- } >- return focus.toDisplay(result); >- } >- >- /** >- * Hook to compute the menu location if the focus widget is >- * a styled text widget. >- * >- * @param text the styled text widget that has the focus >- * >- * @return a widget relative position of the menu to pop up or >- * <code>null</code> if now position inside the widget can >- * be computed >- */ >- protected Point computeMenuLocation(StyledText text) { >- int offset= text.getCaretOffset(); >- Point result= text.getLocationAtOffset(offset); >- result.y+= text.getLineHeight(offset); >- if (!text.getClientArea().contains(result)) >- return null; >- return result; >- } >- >- /** >- * Hook to compute the menu location if the focus widget is >- * a tree widget. >- * >- * @param tree the tree widget that has the focus >- * >- * @return a widget relative position of the menu to pop up or >- * <code>null</code> if now position inside the widget can >- * be computed >- */ >- protected Point computeMenuLocation(Tree tree) { >- TreeItem[] items= tree.getSelection(); >- Rectangle clientArea= tree.getClientArea(); >- switch (items.length) { >- case 0: >- return null; >- case 1: >- Rectangle bounds= items[0].getBounds(); >- Rectangle intersect= clientArea.intersection(bounds); >- if (intersect != null && intersect.height == bounds.height) { >- return new Point( >- Math.max(0, bounds.x + getAvarageCharWith(tree) * CHAR_INDENT), >- bounds.y + bounds.height); >- } else { >- return null; >- } >- default: >- Rectangle[] rectangles= new Rectangle[items.length]; >- for (int i= 0; i < rectangles.length; i++) { >- rectangles[i]= items[i].getBounds(); >- } >- Point cursorLocation= tree.getDisplay().getCursorLocation(); >- Point result= findBestLocation(getIncludedPositions(rectangles, clientArea), >- tree.toControl(cursorLocation)); >- if (result != null) >- result.x= result.x + getAvarageCharWith(tree) * CHAR_INDENT; >- return result; >- } >- } >- >- /** >- * Hook to compute the menu location if the focus widget is >- * a table widget. >- * >- * @param table the table widget that has the focus >- * >- * @return a widget relative position of the menu to pop up or >- * <code>null</code> if now position inside the widget can >- * be computed >- */ >- protected Point computeMenuLocation(Table table) { >- TableItem[] items= table.getSelection(); >- Rectangle clientArea= table.getClientArea(); >- switch (items.length) { >- case 0: { >- return null; >- } case 1: { >- Rectangle bounds= items[0].getBounds(0); >- Rectangle iBounds= items[0].getImageBounds(0); >- Rectangle intersect= clientArea.intersection(bounds); >- if (intersect != null && intersect.height == bounds.height) { >- return new Point( >- Math.max(0, bounds.x + iBounds.width + getAvarageCharWith(table) * CHAR_INDENT), >- bounds.y + bounds.height); >- } else { >- return null; >- } >- } default: { >- Rectangle[] rectangles= new Rectangle[items.length]; >- for (int i= 0; i < rectangles.length; i++) { >- rectangles[i]= items[i].getBounds(0); >- } >- Rectangle iBounds= items[0].getImageBounds(0); >- Point cursorLocation= table.getDisplay().getCursorLocation(); >- Point result= findBestLocation(getIncludedPositions(rectangles, clientArea), >- table.toControl(cursorLocation)); >- if (result != null) >- result.x= result.x + iBounds.width + getAvarageCharWith(table) * CHAR_INDENT; >- return result; >- } >- } >- } >- >- private Point[] getIncludedPositions(Rectangle[] rectangles, Rectangle widgetBounds) { >- List result= new ArrayList(); >- for (int i= 0; i < rectangles.length; i++) { >- Rectangle rectangle= rectangles[i]; >- Rectangle intersect= widgetBounds.intersection(rectangle); >- if (intersect != null && intersect.height == rectangle.height) { >- result.add(new Point(intersect.x, intersect.y + intersect.height)); >- } >- } >- return (Point[]) result.toArray(new Point[result.size()]); >- } >- >- private Point findBestLocation(Point[] points, Point relativeCursor) { >- Point result= null; >- double bestDist= Double.MAX_VALUE; >- for (int i= 0; i < points.length; i++) { >- Point point= points[i]; >- int a= 0; >- int b= 0; >- if (point.x > relativeCursor.x) { >- a= point.x - relativeCursor.x; >- } else { >- a= relativeCursor.x - point.x; >- } >- if (point.y > relativeCursor.y) { >- b= point.y - relativeCursor.y; >- } else { >- b= relativeCursor.y - point.y; >- } >- double dist= Math.sqrt(a * a + b * b); >- if (dist < bestDist) { >- result= point; >- bestDist= dist; >- } >- } >- return result; >- } >- >- private int getAvarageCharWith(Control control) { >- GC gc= null; >- try { >- gc= new GC(control); >- return gc.getFontMetrics().getAverageCharWidth(); >- } finally { >- if (gc != null) >- gc.dispose(); >- } >- } >-} >Index: ui/org/eclipse/jdt/internal/ui/actions/WorkbenchRunnableAdapter.java >=================================================================== >RCS file: /cvsroot/eclipse/org.eclipse.jdt.ui/ui/org/eclipse/jdt/internal/ui/actions/WorkbenchRunnableAdapter.java,v >retrieving revision 1.21 >diff -u -r1.21 WorkbenchRunnableAdapter.java >--- ui/org/eclipse/jdt/internal/ui/actions/WorkbenchRunnableAdapter.java 23 Feb 2009 16:21:52 -0000 1.21 >+++ ui/org/eclipse/jdt/internal/ui/actions/WorkbenchRunnableAdapter.java 3 Mar 2009 21:44:28 -0000 >@@ -33,7 +33,8 @@ > > /** > * An {@link IRunnableWithProgress} that adapts an {@link IWorkspaceRunnable} so that is can be >- * executed inside an {@link IRunnableContext}. >+ * executed inside an {@link IRunnableContext}. The runnable is run as an >+ * {@linkplain JavaCore#run(IWorkspaceRunnable, ISchedulingRule, IProgressMonitor) atomic Java model operation}. > * <p> > * {@link OperationCanceledException}s thrown by the > * adapted runnable are caught and re-thrown as {@link InterruptedException}s. >@@ -71,7 +72,7 @@ > * > * @param runnable the runnable > * @param rule the scheduling rule, or <code>null</code> >- * @param transfer <code>true</code> iff the rule is to be transfered to the model context >+ * @param transfer <code>true</code> iff the rule is to be transfered to the modal context > * thread > */ > public WorkbenchRunnableAdapter(IWorkspaceRunnable runnable, ISchedulingRule rule, boolean transfer) { >@@ -80,6 +81,12 @@ > fTransfer= transfer; > } > >+ /** >+ * Returns the scheduling rule, or <code>null</code> if none. >+ * >+ * @return the scheduling rule, or <code>null</code> if none >+ * @since 3.5 >+ */ > public ISchedulingRule getSchedulingRule() { > return fRule; > } >Index: ui/org/eclipse/jdt/internal/ui/actions/JDTQuickMenuAction.java >=================================================================== >RCS file: ui/org/eclipse/jdt/internal/ui/actions/JDTQuickMenuAction.java >diff -N ui/org/eclipse/jdt/internal/ui/actions/JDTQuickMenuAction.java >--- ui/org/eclipse/jdt/internal/ui/actions/JDTQuickMenuAction.java 31 Dec 2008 21:13:09 -0000 1.11 >+++ /dev/null 1 Jan 1970 00:00:00 -0000 >@@ -1,85 +0,0 @@ >-/******************************************************************************* >- * Copyright (c) 2000, 2008 IBM Corporation and others. >- * All rights reserved. This program and the accompanying materials >- * are made available under the terms of the Eclipse Public License v1.0 >- * which accompanies this distribution, and is available at >- * http://www.eclipse.org/legal/epl-v10.html >- * >- * Contributors: >- * IBM Corporation - initial API and implementation >- *******************************************************************************/ >-package org.eclipse.jdt.internal.ui.actions; >- >-import org.eclipse.swt.custom.StyledText; >-import org.eclipse.swt.graphics.Point; >- >-import org.eclipse.jface.text.IRegion; >-import org.eclipse.jface.text.ITextSelection; >-import org.eclipse.jface.text.ITextViewerExtension5; >-import org.eclipse.jface.text.Region; >-import org.eclipse.jface.text.source.ISourceViewer; >- >-import org.eclipse.jdt.internal.ui.javaeditor.JavaEditor; >-import org.eclipse.jdt.internal.ui.text.JavaWordFinder; >- >- >-public abstract class JDTQuickMenuAction extends QuickMenuAction { >- >- private JavaEditor fEditor; >- >- public JDTQuickMenuAction(String commandId) { >- super(commandId); >- } >- >- public JDTQuickMenuAction(JavaEditor editor, String commandId) { >- super(commandId); >- fEditor= editor; >- } >- >- protected JavaEditor getJavaEditor() { >- return fEditor; >- } >- >- protected Point computeMenuLocation(StyledText text) { >- if (fEditor == null || text != fEditor.getViewer().getTextWidget()) >- return null; >- return computeWordStart(); >- } >- >- private Point computeWordStart() { >- ITextSelection selection= (ITextSelection)fEditor.getSelectionProvider().getSelection(); >- IRegion textRegion= JavaWordFinder.findWord(fEditor.getViewer().getDocument(), selection.getOffset()); >- if (textRegion == null) >- return null; >- >- IRegion widgetRegion= modelRange2WidgetRange(textRegion); >- if (widgetRegion == null) >- return null; >- >- int start= widgetRegion.getOffset(); >- >- StyledText styledText= fEditor.getViewer().getTextWidget(); >- Point result= styledText.getLocationAtOffset(start); >- result.y+= styledText.getLineHeight(start); >- >- if (!styledText.getClientArea().contains(result)) >- return null; >- return result; >- } >- >- private IRegion modelRange2WidgetRange(IRegion region) { >- ISourceViewer viewer= fEditor.getViewer(); >- if (viewer instanceof ITextViewerExtension5) { >- ITextViewerExtension5 extension= (ITextViewerExtension5)viewer; >- return extension.modelRange2WidgetRange(region); >- } >- >- IRegion visibleRegion= viewer.getVisibleRegion(); >- int start= region.getOffset() - visibleRegion.getOffset(); >- int end= start + region.getLength(); >- if (end > visibleRegion.getLength()) >- end= visibleRegion.getLength(); >- >- return new Region(start, end - start); >- } >-} >Index: ui/org/eclipse/jdt/internal/ui/actions/OccurrencesSearchMenuAction.java >=================================================================== >RCS file: /cvsroot/eclipse/org.eclipse.jdt.ui/ui/org/eclipse/jdt/internal/ui/actions/OccurrencesSearchMenuAction.java,v >retrieving revision 1.9 >diff -u -r1.9 OccurrencesSearchMenuAction.java >--- ui/org/eclipse/jdt/internal/ui/actions/OccurrencesSearchMenuAction.java 11 Sep 2008 11:59:06 -0000 1.9 >+++ ui/org/eclipse/jdt/internal/ui/actions/OccurrencesSearchMenuAction.java 3 Mar 2009 21:44:28 -0000 >@@ -1,5 +1,5 @@ > /******************************************************************************* >- * Copyright (c) 2000, 2008 IBM Corporation and others. >+ * Copyright (c) 2000, 2009 IBM Corporation and others. > * All rights reserved. This program and the accompanying materials > * are made available under the terms of the Eclipse Public License v1.0 > * which accompanies this distribution, and is available at >@@ -189,11 +189,11 @@ > if (activeActions.size() == 1) { > ((IAction) activeActions.get(0)).run(); > } else { >- (new JDTQuickMenuAction(editor, IJavaEditorActionDefinitionIds.SEARCH_OCCURRENCES_IN_FILE_QUICK_MENU) { >+ new JDTQuickMenuCreator(editor) { > protected void fillMenu(IMenuManager menu) { > fillQuickMenu(menu, activeActions); > } >- }).run(); >+ }.createMenu(); > } > } > >Index: ui/org/eclipse/jdt/internal/ui/actions/SurroundWithTemplateMenuAction.java >=================================================================== >RCS file: /cvsroot/eclipse/org.eclipse.jdt.ui/ui/org/eclipse/jdt/internal/ui/actions/SurroundWithTemplateMenuAction.java,v >retrieving revision 1.13 >diff -u -r1.13 SurroundWithTemplateMenuAction.java >--- ui/org/eclipse/jdt/internal/ui/actions/SurroundWithTemplateMenuAction.java 11 Sep 2008 11:59:06 -0000 1.13 >+++ ui/org/eclipse/jdt/internal/ui/actions/SurroundWithTemplateMenuAction.java 3 Mar 2009 21:44:28 -0000 >@@ -1,5 +1,5 @@ > /******************************************************************************* >- * Copyright (c) 2000, 2008 IBM Corporation and others. >+ * Copyright (c) 2000, 2009 IBM Corporation and others. > * All rights reserved. This program and the accompanying materials > * are made available under the terms of the Eclipse Public License v1.0 > * which accompanies this distribution, and is available at >@@ -220,12 +220,12 @@ > > final CompilationUnitEditor editor= (CompilationUnitEditor)activePart; > >- (new JDTQuickMenuAction(editor, SURROUND_WITH_QUICK_MENU_ACTION_ID) { >+ new JDTQuickMenuCreator(editor) { > protected void fillMenu(IMenuManager menu) { > SurroundWithTryCatchAction surroundWithTryCatch= createSurroundWithTryCatchAction(editor); > SurroundWithTemplateMenuAction.fillMenu(menu, editor, surroundWithTryCatch); > } >- }).run(); >+ }.createMenu(); > } > > /** >Index: ui/org/eclipse/jdt/internal/ui/actions/SurroundWithActionGroup.java >=================================================================== >RCS file: /cvsroot/eclipse/org.eclipse.jdt.ui/ui/org/eclipse/jdt/internal/ui/actions/SurroundWithActionGroup.java,v >retrieving revision 1.8 >diff -u -r1.8 SurroundWithActionGroup.java >--- ui/org/eclipse/jdt/internal/ui/actions/SurroundWithActionGroup.java 31 Dec 2008 21:13:09 -0000 1.8 >+++ ui/org/eclipse/jdt/internal/ui/actions/SurroundWithActionGroup.java 3 Mar 2009 21:44:28 -0000 >@@ -1,5 +1,5 @@ > /******************************************************************************* >- * Copyright (c) 2000, 2008 IBM Corporation and others. >+ * Copyright (c) 2000, 2009 IBM Corporation and others. > * All rights reserved. This program and the accompanying materials > * are made available under the terms of the Eclipse Public License v1.0 > * which accompanies this distribution, and is available at >@@ -20,9 +20,7 @@ > import org.eclipse.jface.text.ITextSelection; > > import org.eclipse.ui.IActionBars; >-import org.eclipse.ui.PlatformUI; > import org.eclipse.ui.actions.ActionGroup; >-import org.eclipse.ui.keys.IBindingService; > > import org.eclipse.jdt.ui.actions.IJavaEditorActionDefinitionIds; > import org.eclipse.jdt.ui.actions.JdtActionConstants; >@@ -65,12 +63,8 @@ > > String menuText= ActionMessages.SurroundWithTemplateMenuAction_SurroundWithTemplateSubMenuName; > >- String shortcutString= getShortcutString(); >- if (shortcutString != null) { >- menuText= menuText + '\t' + shortcutString; >- } >- > MenuManager subMenu = new MenuManager(menuText, SurroundWithTemplateMenuAction.SURROUND_WITH_QUICK_MENU_ACTION_ID); >+ subMenu.setActionDefinitionId(SurroundWithTemplateMenuAction.SURROUND_WITH_QUICK_MENU_ACTION_ID); > menu.appendToGroup(fGroup, subMenu); > subMenu.add(new Action() {}); > subMenu.addMenuListener(new IMenuListener() { >@@ -81,13 +75,6 @@ > }); > } > >- private String getShortcutString() { >- IBindingService bindingService= (IBindingService)PlatformUI.getWorkbench().getAdapter(IBindingService.class); >- if (bindingService == null) >- return null; >- return bindingService.getBestActiveBindingFormattedFor(SurroundWithTemplateMenuAction.SURROUND_WITH_QUICK_MENU_ACTION_ID); >- } >- > private static SurroundWithTryCatchAction createSurroundWithTryCatchAction(CompilationUnitEditor editor) { > SurroundWithTryCatchAction result= new SurroundWithTryCatchAction(editor); > result.setText(ActionMessages.SurroundWithTemplateMenuAction_SurroundWithTryCatchActionName); >Index: ui/org/eclipse/jdt/ui/actions/OccurrencesSearchGroup.java >=================================================================== >RCS file: /cvsroot/eclipse/org.eclipse.jdt.ui/ui/org/eclipse/jdt/ui/actions/OccurrencesSearchGroup.java,v >retrieving revision 1.16 >diff -u -r1.16 OccurrencesSearchGroup.java >--- ui/org/eclipse/jdt/ui/actions/OccurrencesSearchGroup.java 11 Sep 2008 11:59:16 -0000 1.16 >+++ ui/org/eclipse/jdt/ui/actions/OccurrencesSearchGroup.java 3 Mar 2009 21:44:28 -0000 >@@ -1,5 +1,5 @@ > /******************************************************************************* >- * Copyright (c) 2000, 2008 IBM Corporation and others. >+ * Copyright (c) 2000, 2009 IBM Corporation and others. > * All rights reserved. This program and the accompanying materials > * are made available under the terms of the Eclipse Public License v1.0 > * which accompanies this distribution, and is available at >@@ -26,9 +26,7 @@ > > import org.eclipse.ui.IActionBars; > import org.eclipse.ui.IWorkbenchSite; >-import org.eclipse.ui.PlatformUI; > import org.eclipse.ui.actions.ActionGroup; >-import org.eclipse.ui.keys.IBindingService; > > import org.eclipse.ui.texteditor.ITextEditorActionConstants; > >@@ -177,12 +175,8 @@ > */ > public void fillContextMenu(IMenuManager manager) { > String menuText= SearchMessages.group_occurrences; >- String shortcut= getShortcutString(); >- if (shortcut != null) { >- menuText= menuText + '\t' + shortcut; >- } >- > MenuManager javaSearchMM= new MenuManager(menuText, IContextMenuConstants.GROUP_SEARCH); >+ javaSearchMM.setActionDefinitionId(IJavaEditorActionDefinitionIds.SEARCH_OCCURRENCES_IN_FILE_QUICK_MENU); > javaSearchMM.add(new Action() { > }); > javaSearchMM.addMenuListener(new IMenuListener() { >@@ -230,13 +224,6 @@ > fMethodExitOccurrencesAction.update(javaSelection); > } > >- private String getShortcutString() { >- IBindingService bindingService= (IBindingService)PlatformUI.getWorkbench().getAdapter(IBindingService.class); >- if (bindingService == null) >- return null; >- return bindingService.getBestActiveBindingFormattedFor(IJavaEditorActionDefinitionIds.SEARCH_OCCURRENCES_IN_FILE_QUICK_MENU); >- } >- > /* > * Method declared on ActionGroup. > */ >Index: ui/org/eclipse/jdt/ui/actions/RefactorActionGroup.java >=================================================================== >RCS file: /cvsroot/eclipse/org.eclipse.jdt.ui/ui/org/eclipse/jdt/ui/actions/RefactorActionGroup.java,v >retrieving revision 1.92 >diff -u -r1.92 RefactorActionGroup.java >--- ui/org/eclipse/jdt/ui/actions/RefactorActionGroup.java 11 Sep 2008 11:59:16 -0000 1.92 >+++ ui/org/eclipse/jdt/ui/actions/RefactorActionGroup.java 3 Mar 2009 21:44:28 -0000 >@@ -1,5 +1,5 @@ > /******************************************************************************* >- * Copyright (c) 2000, 2008 IBM Corporation and others. >+ * Copyright (c) 2000, 2009 IBM Corporation and others. > * All rights reserved. This program and the accompanying materials > * are made available under the terms of the Eclipse Public License v1.0 > * which accompanies this distribution, and is available at >@@ -18,6 +18,7 @@ > import org.eclipse.swt.events.MenuEvent; > import org.eclipse.swt.widgets.Menu; > >+import org.eclipse.core.commands.IHandler; > import org.eclipse.core.commands.operations.IUndoContext; > > import org.eclipse.core.runtime.PerformanceStats; >@@ -30,7 +31,6 @@ > import org.eclipse.jface.action.IMenuManager; > import org.eclipse.jface.action.MenuManager; > import org.eclipse.jface.action.Separator; >-import org.eclipse.jface.commands.ActionHandler; > import org.eclipse.jface.viewers.ISelection; > import org.eclipse.jface.viewers.ISelectionChangedListener; > import org.eclipse.jface.viewers.ISelectionProvider; >@@ -58,7 +58,7 @@ > import org.eclipse.jdt.internal.ui.actions.ActionUtil; > import org.eclipse.jdt.internal.ui.actions.ExtractSuperClassAction; > import org.eclipse.jdt.internal.ui.actions.IntroduceParameterObjectAction; >-import org.eclipse.jdt.internal.ui.actions.JDTQuickMenuAction; >+import org.eclipse.jdt.internal.ui.actions.JDTQuickMenuCreator; > import org.eclipse.jdt.internal.ui.javaeditor.JavaEditor; > import org.eclipse.jdt.internal.ui.javaeditor.JavaTextSelection; > import org.eclipse.jdt.internal.ui.refactoring.RefactoringMessages; >@@ -180,16 +180,6 @@ > > private static final String QUICK_MENU_ID= "org.eclipse.jdt.ui.edit.text.java.refactor.quickMenu"; //$NON-NLS-1$ > >- private class RefactorQuickAccessAction extends JDTQuickMenuAction { >- public RefactorQuickAccessAction(JavaEditor editor) { >- super(editor, QUICK_MENU_ID); >- } >- protected void fillMenu(IMenuManager menu) { >- fillQuickMenu(menu); >- } >- } >- >- private JDTQuickMenuAction fQuickAccessAction; > private IHandlerActivation fQuickAccessHandlerActivation; > private IHandlerService fHandlerService; > >@@ -438,8 +428,12 @@ > private void installQuickAccessAction() { > fHandlerService= (IHandlerService)fSite.getService(IHandlerService.class); > if (fHandlerService != null) { >- fQuickAccessAction= new RefactorQuickAccessAction(fEditor); >- fQuickAccessHandlerActivation= fHandlerService.activateHandler(fQuickAccessAction.getActionDefinitionId(), new ActionHandler(fQuickAccessAction)); >+ IHandler handler= new JDTQuickMenuCreator(fEditor) { >+ protected void fillMenu(IMenuManager menu) { >+ fillQuickMenu(menu); >+ } >+ }.createHandler(); >+ fQuickAccessHandlerActivation= fHandlerService.activateHandler(QUICK_MENU_ID, handler); > } > } > >@@ -566,11 +560,8 @@ > } > > private void addRefactorSubmenu(IMenuManager menu) { >- String menuText= ActionMessages.RefactorMenu_label; >- if (fQuickAccessAction != null) { >- menuText= fQuickAccessAction.addShortcut(menuText); >- } >- IMenuManager refactorSubmenu= new MenuManager(menuText, MENU_ID); >+ MenuManager refactorSubmenu= new MenuManager(ActionMessages.RefactorMenu_label, MENU_ID); >+ refactorSubmenu.setActionDefinitionId(QUICK_MENU_ID); > if (fEditor != null) { > final ITypeRoot element= getEditorInput(); > if (element != null && ActionUtil.isOnBuildPath(element)) { >Index: ui/org/eclipse/jdt/ui/actions/GenerateActionGroup.java >=================================================================== >RCS file: /cvsroot/eclipse/org.eclipse.jdt.ui/ui/org/eclipse/jdt/ui/actions/GenerateActionGroup.java,v >retrieving revision 1.103 >diff -u -r1.103 GenerateActionGroup.java >--- ui/org/eclipse/jdt/ui/actions/GenerateActionGroup.java 16 Dec 2008 14:51:29 -0000 1.103 >+++ ui/org/eclipse/jdt/ui/actions/GenerateActionGroup.java 3 Mar 2009 21:44:28 -0000 >@@ -1,5 +1,5 @@ > /******************************************************************************* >- * Copyright (c) 2000, 2008 IBM Corporation and others. >+ * Copyright (c) 2000, 2009 IBM Corporation and others. > * All rights reserved. This program and the accompanying materials > * are made available under the terms of the Eclipse Public License v1.0 > * which accompanies this distribution, and is available at >@@ -14,13 +14,14 @@ > import java.util.Iterator; > import java.util.List; > >+import org.eclipse.core.commands.IHandler; >+ > import org.eclipse.core.runtime.Assert; > > import org.eclipse.jface.action.IAction; > import org.eclipse.jface.action.IMenuManager; > import org.eclipse.jface.action.MenuManager; > import org.eclipse.jface.action.Separator; >-import org.eclipse.jface.commands.ActionHandler; > import org.eclipse.jface.viewers.ISelection; > import org.eclipse.jface.viewers.ISelectionChangedListener; > import org.eclipse.jface.viewers.ISelectionProvider; >@@ -45,7 +46,7 @@ > import org.eclipse.jdt.internal.ui.actions.AddTaskAction; > import org.eclipse.jdt.internal.ui.actions.AllCleanUpsAction; > import org.eclipse.jdt.internal.ui.actions.FindBrokenNLSKeysAction; >-import org.eclipse.jdt.internal.ui.actions.JDTQuickMenuAction; >+import org.eclipse.jdt.internal.ui.actions.JDTQuickMenuCreator; > import org.eclipse.jdt.internal.ui.actions.MultiSortMembersAction; > import org.eclipse.jdt.internal.ui.javaeditor.AddImportOnSelectionAction; > import org.eclipse.jdt.internal.ui.javaeditor.CompilationUnitEditor; >@@ -144,16 +145,6 @@ > > private static final String QUICK_MENU_ID= "org.eclipse.jdt.ui.edit.text.java.source.quickMenu"; //$NON-NLS-1$ > >- private class SourceQuickAccessAction extends JDTQuickMenuAction { >- public SourceQuickAccessAction(CompilationUnitEditor editor) { >- super(editor, QUICK_MENU_ID); >- } >- protected void fillMenu(IMenuManager menu) { >- fillQuickMenu(menu); >- } >- } >- >- private JDTQuickMenuAction fQuickAccessAction; > private IHandlerActivation fQuickAccessHandlerActivation; > private IHandlerService fHandlerService; > >@@ -368,8 +359,12 @@ > private void installQuickAccessAction() { > fHandlerService= (IHandlerService)fSite.getService(IHandlerService.class); > if (fHandlerService != null) { >- fQuickAccessAction= new SourceQuickAccessAction(fEditor); >- fQuickAccessHandlerActivation= fHandlerService.activateHandler(fQuickAccessAction.getActionDefinitionId(), new ActionHandler(fQuickAccessAction)); >+ IHandler handler= new JDTQuickMenuCreator(fEditor) { >+ protected void fillMenu(IMenuManager menu) { >+ fillQuickMenu(menu); >+ } >+ }.createHandler(); >+ fQuickAccessHandlerActivation= fHandlerService.activateHandler(QUICK_MENU_ID, handler); > } > } > >@@ -408,11 +403,8 @@ > */ > public void fillContextMenu(IMenuManager menu) { > super.fillContextMenu(menu); >- String menuText= ActionMessages.SourceMenu_label; >- if (fQuickAccessAction != null) { >- menuText= fQuickAccessAction.addShortcut(menuText); >- } >- IMenuManager subMenu= new MenuManager(menuText, MENU_ID); >+ MenuManager subMenu= new MenuManager(ActionMessages.SourceMenu_label, MENU_ID); >+ subMenu.setActionDefinitionId(QUICK_MENU_ID); > int added= 0; > if (isEditorOwner()) { > added= fillEditorSubMenu(subMenu); >Index: ui/org/eclipse/jdt/internal/ui/actions/JDTQuickMenuCreator.java >=================================================================== >RCS file: ui/org/eclipse/jdt/internal/ui/actions/JDTQuickMenuCreator.java >diff -N ui/org/eclipse/jdt/internal/ui/actions/JDTQuickMenuCreator.java >--- /dev/null 1 Jan 1970 00:00:00 -0000 >+++ ui/org/eclipse/jdt/internal/ui/actions/JDTQuickMenuCreator.java 1 Jan 1970 00:00:00 -0000 >@@ -0,0 +1,98 @@ >+/******************************************************************************* >+ * Copyright (c) 2009 IBM Corporation and others. >+ * All rights reserved. This program and the accompanying materials >+ * are made available under the terms of the Eclipse Public License v1.0 >+ * which accompanies this distribution, and is available at >+ * http://www.eclipse.org/legal/epl-v10.html >+ * >+ * Contributors: >+ * IBM Corporation - initial API and implementation >+ *******************************************************************************/ >+package org.eclipse.jdt.internal.ui.actions; >+ >+import org.eclipse.swt.custom.StyledText; >+import org.eclipse.swt.graphics.Point; >+ >+import org.eclipse.core.commands.AbstractHandler; >+import org.eclipse.core.commands.ExecutionEvent; >+import org.eclipse.core.commands.ExecutionException; >+import org.eclipse.core.commands.IHandler; >+ >+import org.eclipse.jface.text.IRegion; >+import org.eclipse.jface.text.ITextSelection; >+import org.eclipse.jface.text.ITextViewerExtension5; >+import org.eclipse.jface.text.Region; >+import org.eclipse.jface.text.source.ISourceViewer; >+ >+import org.eclipse.ui.actions.QuickMenuCreator; >+ >+import org.eclipse.jdt.internal.ui.javaeditor.JavaEditor; >+import org.eclipse.jdt.internal.ui.text.JavaWordFinder; >+ >+/** >+ * Java editor aware quick menu creator. In the given editor, the menu will be aligned with the word >+ * at the current offset. >+ * >+ * @since 3.5 >+ */ >+public abstract class JDTQuickMenuCreator extends QuickMenuCreator { >+ >+ private final JavaEditor fEditor; >+ >+ public JDTQuickMenuCreator(JavaEditor editor) { >+ fEditor= editor; >+ } >+ >+ protected Point computeMenuLocation(StyledText text) { >+ if (fEditor == null || text != fEditor.getViewer().getTextWidget()) >+ return super.computeMenuLocation(text); >+ return computeWordStart(); >+ } >+ >+ private Point computeWordStart() { >+ ITextSelection selection= (ITextSelection)fEditor.getSelectionProvider().getSelection(); >+ IRegion textRegion= JavaWordFinder.findWord(fEditor.getViewer().getDocument(), selection.getOffset()); >+ if (textRegion == null) >+ return null; >+ >+ IRegion widgetRegion= modelRange2WidgetRange(textRegion); >+ if (widgetRegion == null) >+ return null; >+ >+ int start= widgetRegion.getOffset(); >+ >+ StyledText styledText= fEditor.getViewer().getTextWidget(); >+ Point result= styledText.getLocationAtOffset(start); >+ result.y+= styledText.getLineHeight(start); >+ >+ if (!styledText.getClientArea().contains(result)) >+ return null; >+ return result; >+ } >+ >+ private IRegion modelRange2WidgetRange(IRegion region) { >+ ISourceViewer viewer= fEditor.getViewer(); >+ if (viewer instanceof ITextViewerExtension5) { >+ ITextViewerExtension5 extension= (ITextViewerExtension5)viewer; >+ return extension.modelRange2WidgetRange(region); >+ } >+ >+ IRegion visibleRegion= viewer.getVisibleRegion(); >+ int start= region.getOffset() - visibleRegion.getOffset(); >+ int end= start + region.getLength(); >+ if (end > visibleRegion.getLength()) >+ end= visibleRegion.getLength(); >+ >+ return new Region(start, end - start); >+ } >+ >+ public IHandler createHandler() { >+ return new AbstractHandler() { >+ public Object execute(ExecutionEvent event) throws ExecutionException { >+ createMenu(); >+ return null; >+ } >+ }; >+ } >+ >+}
You cannot view the attachment while viewing its details because your browser does not support IFRAMEs.
View the attachment on a separate page
.
View Attachment As Diff
View Attachment As Raw
Actions:
View
|
Diff
Attachments on
bug 266938
: 127393