1
0
Fork 0
mirror of https://github.com/eclipse-cdt/cdt synced 2025-04-29 19:45:01 +02:00

Bug 177018 - Move actions to new top level Source menu

This commit is contained in:
Anton Leherbauer 2009-11-06 13:58:49 +00:00
parent e80914811e
commit fcbf489459
6 changed files with 356 additions and 103 deletions

View file

@ -74,6 +74,9 @@ cEditor.description=Editor for C/C++ Source Files
category.source.name=C/C++ Source
category.source.description= C/C++ Source Actions
ActionDefinition.sourceQuickMenu.name= Show Source Quick Menu
ActionDefinition.sourceQuickMenu.description= Shows the source quick menu
ActionDefinition.comment.name= Comment
ActionDefinition.comment.description= Turn the selected lines into // style comments
@ -543,7 +546,19 @@ preferenceKeywords.templates=editor templates snippet macros
preferenceKeywords.folding=editor folding section comment header function method statement preprocessor
preferenceKeywords.markoccurrences=editor occurrence mark highlight
preferenceKeywords.smarttyping=editor typing type close comment tabs indentation indent imports wrap escape semicolons braces brackets parenthesis parentheses strings literals paste pasting tabulator automatically
historyAction.label = History...
createScriptAction.label = Create Script...
applyScriptAction.label = Apply Script...
renameParticipant.name = Source Folder Rename
renameParticipant.name = Source Folder Rename
FormatAction.label= &Format
IndentAction.label= Correct &Indentation
AddIncludeAction.label= A&dd Include
CommentAction.label= Co&mment
UncommentAction.label= &Uncomment
ToggleCommentAction.label= Togg&le Comment
AddBlockCommentAction.label= Add &Block Comment
RemoveBlockCommentAction.label= Remove Bloc&k Comment
ShiftRightAction.label= &Shift Right
ShiftLeftAction.label= S&hift Left

View file

@ -1262,28 +1262,6 @@
id="org.eclipse.cdt.ui.actions.ExtractLocalVariable"
retarget="true">
</action>
<action
definitionId="org.eclipse.cdt.ui.refactor.getters.and.setters"
label="%Refactoring.gettersAndSetters.label"
menubarPath="org.eclipse.jdt.ui.source.menu/generateGroup"
id="org.eclipse.cdt.ui.actions.GettersAndSetters"
retarget="true">
</action>
<action
definitionId="org.eclipse.cdt.ui.refactor.implement.method"
label="%Refactoring.implementMethod.label"
menubarPath="org.eclipse.jdt.ui.source.menu/generateGroup"
id="org.eclipse.cdt.ui.actions.ImplementMethod"
retarget="true">
</action>
<action
class="org.eclipse.cdt.internal.ui.actions.SurroundWithTemplateMenuAction"
definitionId="org.eclipse.cdt.ui.edit.text.c.surround.with.quickMenu"
label="%SurroundWithTemplateAction.label"
menubarPath="org.eclipse.jdt.ui.source.menu/codeGroup"
id="org.eclipse.cdt.internal.ui.actions.SurroundWithTemplateMenuAction"
style="pulldown">
</action>
<action
class="org.eclipse.ltk.ui.refactoring.actions.ShowRefactoringHistoryAction"
definitionId="org.eclipse.ltk.ui.refactor.show.refactoring.history"
@ -1308,17 +1286,135 @@
menubarPath="org.eclipse.jdt.ui.refactoring.menu/historyGroup"
retarget="false">
</action>
<!-- =========================================================================== -->
<!-- Source Menu -->
<!-- =========================================================================== -->
<!-- Note: This menu layout must match the definition in org.eclipse.jdt.ui -->
<menu
id="org.eclipse.jdt.ui.source.menu"
label="%Source.menu.label"
path="edit">
<separator
name="commentGroup">
</separator>
<separator
name="editGroup">
</separator>
<separator
name="importGroup">
</separator>
<separator
name="generateGroup">
</separator>
<separator
name="codeGroup">
</separator>
<separator
name="externalizeGroup">
</separator>
<separator
name="convertGroup">
</separator>
</menu>
<!-- Code Group -->
<action
class="org.eclipse.cdt.internal.ui.actions.SurroundWithTemplateMenuAction"
definitionId="org.eclipse.cdt.ui.edit.text.c.surround.with.quickMenu"
label="%SurroundWithTemplateAction.label"
menubarPath="org.eclipse.jdt.ui.source.menu/codeGroup"
id="org.eclipse.cdt.internal.ui.actions.SurroundWithTemplateMenuAction"
style="pulldown">
</action>
<!-- Generate Group -->
<action
definitionId="org.eclipse.cdt.ui.refactor.getters.and.setters"
label="%Refactoring.gettersAndSetters.label"
menubarPath="org.eclipse.jdt.ui.source.menu/generateGroup"
id="org.eclipse.cdt.ui.actions.GettersAndSetters"
retarget="true">
</action>
<action
definitionId="org.eclipse.cdt.ui.refactor.implement.method"
label="%Refactoring.implementMethod.label"
menubarPath="org.eclipse.jdt.ui.source.menu/generateGroup"
id="org.eclipse.cdt.ui.actions.ImplementMethod"
retarget="true">
</action>
<!-- Import Group -->
<action
definitionId="org.eclipse.cdt.ui.edit.text.c.add.include"
label="%AddIncludeAction.label"
retarget="true"
menubarPath="org.eclipse.jdt.ui.source.menu/importGroup"
id="org.eclipse.cdt.ui.actions.AddInclude">
</action>
<!-- Edit group -->
<action
definitionId="org.eclipse.cdt.ui.edit.text.c.format"
label="%FormatAction.label"
retarget="true"
menubarPath="org.eclipse.jdt.ui.source.menu/editGroup"
id="org.eclipse.cdt.ui.actions.Format">
</action>
<action
definitionId="org.eclipse.cdt.ui.edit.text.c.indent"
label="%IndentAction.label"
retarget="true"
menubarPath="org.eclipse.jdt.ui.source.menu/editGroup"
id="org.eclipse.cdt.ui.actions.Indent">
</action>
<action
definitionId="org.eclipse.ui.edit.text.shiftLeft"
disabledIcon="icons/dlcl16/shift_l_edit.gif"
icon="icons/elcl16/shift_l_edit.gif"
id="org.eclipse.cdt.ui.actions.ShiftLeft"
label="%ShiftLeftAction.label"
menubarPath="org.eclipse.jdt.ui.source.menu/editGroup"
retarget="true">
</action>
<action
definitionId="org.eclipse.ui.edit.text.shiftRight"
disabledIcon="icons/dlcl16/shift_r_edit.gif"
icon="icons/elcl16/shift_r_edit.gif"
id="org.eclipse.cdt.ui.actions.ShiftRight"
label="%ShiftRightAction.label"
menubarPath="org.eclipse.jdt.ui.source.menu/editGroup"
retarget="true">
</action>
<!-- Comment Group -->
<action
definitionId="org.eclipse.cdt.ui.edit.text.c.uncomment"
label="%UncommentAction.label"
retarget="true"
id="org.eclipse.cdt.ui.actions.Uncomment">
</action>
<action
definitionId="org.eclipse.cdt.ui.edit.text.c.comment"
label="%CommentAction.label"
retarget="true"
id="org.eclipse.cdt.ui.actions.Comment">
</action>
<action
definitionId="org.eclipse.cdt.ui.edit.text.c.remove.block.comment"
label="%RemoveBlockCommentAction.label"
retarget="true"
menubarPath="org.eclipse.jdt.ui.source.menu/commentGroup"
id="org.eclipse.cdt.ui.actions.RemoveBlockComment">
</action>
<action
definitionId="org.eclipse.cdt.ui.edit.text.c.add.block.comment"
label="%AddBlockCommentAction.label"
retarget="true"
menubarPath="org.eclipse.jdt.ui.source.menu/commentGroup"
id="org.eclipse.cdt.ui.actions.AddBlockComment">
</action>
<action
definitionId="org.eclipse.cdt.ui.edit.text.c.toggle.comment"
label="%ToggleCommentAction.label"
retarget="true"
menubarPath="org.eclipse.jdt.ui.source.menu/commentGroup"
id="org.eclipse.cdt.ui.actions.ToggleComment">
</action>
</actionSet>
<actionSet
label="%CSearchActionSet.label"
@ -1569,6 +1665,23 @@
<!-- win32: M1=CTRL, M2=SHIFT, M3=ALT, M4=-
carbon: M1=COMMAND, M2=SHIFT, M3=ALT, M4=CTRL -->
<key
sequence="M2+M3+S"
commandId="org.eclipse.cdt.ui.edit.text.c.source.quickMenu"
schemeId="org.eclipse.ui.defaultAcceleratorConfiguration"
contextId="org.eclipse.cdt.ui.cEditorScope"/>
<key
platform="carbon"
sequence="M2+M3+S"
commandId=""
schemeId="org.eclipse.ui.defaultAcceleratorConfiguration"
contextId="org.eclipse.cdt.ui.cEditorScope"/>
<key
platform="carbon"
sequence="COMMAND+ALT+S"
commandId="org.eclipse.cdt.ui.edit.text.c.source.quickMenu"
schemeId="org.eclipse.ui.defaultAcceleratorConfiguration"
contextId="org.eclipse.cdt.ui.cEditorScope"/>
<key
sequence="M1+M2+F"
schemeId="org.eclipse.ui.defaultAcceleratorConfiguration"
@ -1984,6 +2097,24 @@
categoryId="org.eclipse.cdt.ui.category.source"
id="org.eclipse.cdt.ui.edit.text.c.format">
</command>
<command
name="%ActionDefinition.sourceQuickMenu.name"
description="%ActionDefinition.sourceQuickMenu.description"
categoryId="org.eclipse.cdt.ui.category.source"
id="org.eclipse.cdt.ui.edit.text.c.source.quickMenu">
</command>
<command
name="%ActionDefinition.comment.name"
description="%ActionDefinition.comment.description"
categoryId="org.eclipse.cdt.ui.category.source"
id="org.eclipse.cdt.ui.edit.text.c.comment">
</command>
<command
name="%ActionDefinition.uncomment.name"
description="%ActionDefinition.uncomment.description"
categoryId="org.eclipse.cdt.ui.category.source"
id="org.eclipse.cdt.ui.edit.text.c.uncomment">
</command>
<command
name="%ActionDefinition.toggleComment.name"
description="%ActionDefinition.toggleComment.description"

View file

@ -0,0 +1,109 @@
/*******************************************************************************
* 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
* Anton Leherbauer (Wind River Systems) - Ported to CDT
*******************************************************************************/
package org.eclipse.cdt.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.cdt.internal.ui.editor.CEditor;
import org.eclipse.cdt.internal.ui.text.CWordFinder;
/**
* C/C++ editor aware quick menu creator. In the given editor, the menu will be aligned with the word
* at the current offset.
*
* @since 5.2
*/
public abstract class CDTQuickMenuCreator extends QuickMenuCreator {
private final CEditor fEditor;
/**
* Create a CDT quick menu creator
* @param editor a Java editor, or <code>null</code> if none
*/
public CDTQuickMenuCreator(CEditor editor) {
fEditor= editor;
}
@Override
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= CWordFinder.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);
}
/**
* Returns a handler that can create and open the quick menu.
*
* @return a handler that can create and open the quick menu
*/
public IHandler createHandler() {
return new AbstractHandler() {
public Object execute(ExecutionEvent event) throws ExecutionException {
createMenu();
return null;
}
};
}
}

View file

@ -18,17 +18,18 @@ import java.util.ResourceBundle;
import org.eclipse.jface.action.IAction;
import org.eclipse.jface.action.IMenuManager;
import org.eclipse.jface.action.Separator;
import org.eclipse.jface.text.ITextOperationTarget;
import org.eclipse.ui.IActionBars;
import org.eclipse.ui.IEditorPart;
import org.eclipse.ui.IWorkbenchActionConstants;
import org.eclipse.ui.editors.text.TextEditorActionContributor;
import org.eclipse.ui.ide.IDEActionFactory;
import org.eclipse.ui.texteditor.ITextEditor;
import org.eclipse.ui.texteditor.ITextEditorActionConstants;
import org.eclipse.ui.texteditor.ITextEditorActionDefinitionIds;
import org.eclipse.ui.texteditor.RetargetTextEditorAction;
import org.eclipse.cdt.internal.ui.CPluginImages;
import org.eclipse.cdt.ui.actions.CdtActionConstants;
import org.eclipse.cdt.internal.ui.IContextMenuConstants;
import org.eclipse.cdt.internal.ui.actions.FindWordAction;
import org.eclipse.cdt.internal.ui.actions.GoToNextPreviousMemberAction;
@ -38,10 +39,6 @@ public class CEditorActionContributor extends TextEditorActionContributor {
private RetargetTextEditorAction fContentAssist;
private RetargetTextEditorAction fContextInformation;
private RetargetTextEditorAction fFormatter;
private RetargetTextEditorAction fAddInclude;
private RetargetTextEditorAction fShiftLeft;
private RetargetTextEditorAction fShiftRight;
private TogglePresentationAction fTogglePresentation;
private GotoAnnotationAction fPreviousAnnotation;
private GotoAnnotationAction fNextAnnotation;
@ -60,26 +57,12 @@ public class CEditorActionContributor extends TextEditorActionContributor {
ResourceBundle bundle = ConstructedCEditorMessages.getResourceBundle();
fShiftRight= new RetargetTextEditorAction(bundle, "ShiftRight.", ITextOperationTarget.SHIFT_RIGHT); //$NON-NLS-1$
fShiftRight.setActionDefinitionId(ITextEditorActionDefinitionIds.SHIFT_RIGHT);
CPluginImages.setImageDescriptors(fShiftRight, CPluginImages.T_LCL, CPluginImages.IMG_MENU_SHIFT_RIGHT);
fShiftLeft= new RetargetTextEditorAction(bundle, "ShiftLeft.", ITextOperationTarget.SHIFT_LEFT); //$NON-NLS-1$
fShiftLeft.setActionDefinitionId(ITextEditorActionDefinitionIds.SHIFT_LEFT);
CPluginImages.setImageDescriptors(fShiftLeft, CPluginImages.T_LCL, CPluginImages.IMG_MENU_SHIFT_LEFT);
fContentAssist = new RetargetTextEditorAction(bundle, "ContentAssistProposal."); //$NON-NLS-1$
fContentAssist.setActionDefinitionId(ITextEditorActionDefinitionIds.CONTENT_ASSIST_PROPOSALS);
fContextInformation = new RetargetTextEditorAction(bundle, "ContentAssistContextInformation."); //$NON-NLS-1$
fContextInformation.setActionDefinitionId(ITextEditorActionDefinitionIds.CONTENT_ASSIST_CONTEXT_INFORMATION);
fFormatter = new RetargetTextEditorAction(bundle, "Format."); //$NON-NLS-1$
fFormatter.setActionDefinitionId(ICEditorActionDefinitionIds.FORMAT);
fAddInclude = new RetargetTextEditorAction(bundle, "AddIncludeOnSelection."); //$NON-NLS-1$
fAddInclude.setActionDefinitionId(ICEditorActionDefinitionIds.ADD_INCLUDE);
// actions that are "contributed" to editors, they are considered belonging to the active editor
fTogglePresentation= new TogglePresentationAction();
@ -127,12 +110,12 @@ public class CEditorActionContributor extends TextEditorActionContributor {
editMenu.prependToGroup(IWorkbenchActionConstants.FIND_EXT, fFindWord);
editMenu.appendToGroup(ITextEditorActionConstants.GROUP_GENERATE, fShiftRight);
editMenu.appendToGroup(ITextEditorActionConstants.GROUP_GENERATE, fShiftLeft);
editMenu.appendToGroup(ITextEditorActionConstants.GROUP_GENERATE, fFormatter);
editMenu.appendToGroup(ITextEditorActionConstants.GROUP_GENERATE, new Separator());
editMenu.appendToGroup(ITextEditorActionConstants.GROUP_GENERATE, fAddInclude);
editMenu.appendToGroup(ITextEditorActionConstants.GROUP_GENERATE, new Separator());
// editMenu.appendToGroup(ITextEditorActionConstants.GROUP_GENERATE, fShiftRight);
// editMenu.appendToGroup(ITextEditorActionConstants.GROUP_GENERATE, fShiftLeft);
// editMenu.appendToGroup(ITextEditorActionConstants.GROUP_GENERATE, fFormatter);
// editMenu.appendToGroup(ITextEditorActionConstants.GROUP_GENERATE, new Separator());
// editMenu.appendToGroup(ITextEditorActionConstants.GROUP_GENERATE, fAddInclude);
// editMenu.appendToGroup(ITextEditorActionConstants.GROUP_GENERATE, new Separator());
editMenu.appendToGroup(IContextMenuConstants.GROUP_ADDITIONS, fToggleInsertModeAction);
}
@ -183,9 +166,6 @@ public class CEditorActionContributor extends TextEditorActionContributor {
if (part instanceof ITextEditor)
textEditor= (ITextEditor) part;
fShiftRight.setAction(getAction(textEditor, ITextEditorActionConstants.SHIFT_RIGHT));
fShiftLeft.setAction(getAction(textEditor, ITextEditorActionConstants.SHIFT_LEFT));
fTogglePresentation.setEditor(textEditor);
fToggleMarkOccurrencesAction.setEditor(textEditor);
fPreviousAnnotation.setEditor(textEditor);
@ -193,8 +173,6 @@ public class CEditorActionContributor extends TextEditorActionContributor {
fContentAssist.setAction(getAction(textEditor, "ContentAssistProposal")); //$NON-NLS-1$
fContextInformation.setAction(getAction(textEditor, "ContentAssistContextInformation")); //$NON-NLS-1$
fAddInclude.setAction(getAction(textEditor, "AddIncludeOnSelection")); //$NON-NLS-1$
fFormatter.setAction(getAction(textEditor, "Format")); //$NON-NLS-1$
fGotoMatchingBracket.setAction(getAction(textEditor, GotoMatchingBracketAction.GOTO_MATCHING_BRACKET));
fGotoNextBookmark.setAction(getAction(textEditor, GotoNextBookmarkAction.NEXT_BOOKMARK));
@ -206,9 +184,32 @@ public class CEditorActionContributor extends TextEditorActionContributor {
fToggleInsertModeAction.setAction(getAction(textEditor, ITextEditorActionConstants.TOGGLE_INSERT_MODE));
fFindWord.setAction(getAction(textEditor, FindWordAction.FIND_WORD));
// Source menu.
IActionBars bars= getActionBars();
bars.setGlobalActionHandler(CdtActionConstants.SHIFT_RIGHT, getAction(textEditor, "ShiftRight")); //$NON-NLS-1$
bars.setGlobalActionHandler(CdtActionConstants.SHIFT_LEFT, getAction(textEditor, "ShiftLeft")); //$NON-NLS-1$
bars.setGlobalActionHandler(CdtActionConstants.COMMENT, getAction(textEditor, "Comment")); //$NON-NLS-1$
bars.setGlobalActionHandler(CdtActionConstants.UNCOMMENT, getAction(textEditor, "Uncomment")); //$NON-NLS-1$
bars.setGlobalActionHandler(CdtActionConstants.TOGGLE_COMMENT, getAction(textEditor, "ToggleComment")); //$NON-NLS-1$
bars.setGlobalActionHandler(CdtActionConstants.FORMAT, getAction(textEditor, "Format")); //$NON-NLS-1$
bars.setGlobalActionHandler(CdtActionConstants.ADD_BLOCK_COMMENT, getAction(textEditor, "AddBlockComment")); //$NON-NLS-1$
bars.setGlobalActionHandler(CdtActionConstants.REMOVE_BLOCK_COMMENT, getAction(textEditor, "RemoveBlockComment")); //$NON-NLS-1$
bars.setGlobalActionHandler(CdtActionConstants.INDENT, getAction(textEditor, "Indent")); //$NON-NLS-1$
bars.setGlobalActionHandler(CdtActionConstants.ADD_INCLUDE, getAction(textEditor, "AddIncludeOnSelection")); //$NON-NLS-1$
IAction action= getAction(textEditor, ITextEditorActionConstants.REFRESH);
bars.setGlobalActionHandler(ITextEditorActionConstants.REFRESH, action);
bars.setGlobalActionHandler(IDEActionFactory.ADD_TASK.getId(), getAction(textEditor, IDEActionFactory.ADD_TASK.getId()));
bars.setGlobalActionHandler(IDEActionFactory.BOOKMARK.getId(), getAction(textEditor, IDEActionFactory.BOOKMARK.getId()));
bars.setGlobalActionHandler(IDEActionFactory.OPEN_PROJECT.getId(), getAction(textEditor, IDEActionFactory.OPEN_PROJECT.getId()));
bars.setGlobalActionHandler(IDEActionFactory.CLOSE_PROJECT.getId(), getAction(textEditor, IDEActionFactory.CLOSE_PROJECT.getId()));
bars.setGlobalActionHandler(IDEActionFactory.CLOSE_UNRELATED_PROJECTS.getId(), getAction(textEditor, IDEActionFactory.CLOSE_UNRELATED_PROJECTS.getId()));
if (part instanceof CEditor) {
CEditor cEditor= (CEditor) part;
cEditor.fillActionBars(getActionBars());
cEditor.fillActionBars(bars);
}
}

View file

@ -44,9 +44,9 @@ ContentAssistContextInformation.label=Parameter &Hints
ContentAssistContextInformation.tooltip=Show Parameter Hints
ContentAssistContextInformation.description=Show Method Parameter Hints
ToggleComment.label=Comment/Uncomment
ToggleComment.tooltip=Comment/Uncomment For the Selected Lines
ToggleComment.description=Comment/Uncomment for the selected lines
ToggleComment.label=Togg&le Comment
ToggleComment.tooltip=Toggle Comment For the Selected Lines
ToggleComment.description=Toggle Comment for the selected lines
AddBlockComment.label=Add &Block Comment
AddBlockComment.tooltip=Enclose the Selection in a Block Comment

View file

@ -15,6 +15,7 @@ import java.util.ArrayList;
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;
@ -26,22 +27,23 @@ import org.eclipse.jface.viewers.ISelectionProvider;
import org.eclipse.jface.viewers.IStructuredSelection;
import org.eclipse.ui.IActionBars;
import org.eclipse.ui.IViewPart;
import org.eclipse.ui.IWorkbenchCommandConstants;
import org.eclipse.ui.IWorkbenchSite;
import org.eclipse.ui.actions.ActionGroup;
import org.eclipse.ui.actions.AddBookmarkAction;
import org.eclipse.ui.actions.AddTaskAction;
import org.eclipse.ui.handlers.IHandlerActivation;
import org.eclipse.ui.handlers.IHandlerService;
import org.eclipse.ui.ide.IDEActionFactory;
import org.eclipse.ui.part.Page;
import org.eclipse.ui.texteditor.ITextEditorActionConstants;
import org.eclipse.ui.texteditor.IUpdate;
import org.eclipse.ui.texteditor.IWorkbenchActionDefinitionIds;
import org.eclipse.cdt.ui.refactoring.actions.GettersAndSettersAction;
import org.eclipse.cdt.ui.refactoring.actions.ImplementMethodAction;
import org.eclipse.cdt.internal.ui.IContextMenuConstants;
import org.eclipse.cdt.internal.ui.actions.ActionMessages;
import org.eclipse.cdt.internal.ui.actions.CDTQuickMenuCreator;
import org.eclipse.cdt.internal.ui.editor.AddIncludeOnSelectionAction;
import org.eclipse.cdt.internal.ui.editor.CEditor;
import org.eclipse.cdt.internal.ui.editor.ICEditorActionDefinitionIds;
@ -124,19 +126,11 @@ public class GenerateActionGroup extends ActionGroup {
// private FormatAllAction fFormatAll;
// private CopyQualifiedNameAction fCopyQualifiedNameAction;
//
// private static final String QUICK_MENU_ID= "org.eclipse.cdt.ui.edit.text.c.source.quickMenu"; //$NON-NLS-1$
//
// private class RefactorQuickAccessAction extends CDTQuickMenuAction {
// public RefactorQuickAccessAction(CEditor editor) {
// super(editor, QUICK_MENU_ID);
// }
// protected void fillMenu(IMenuManager menu) {
// fillQuickMenu(menu);
// }
// }
//
// private RefactorQuickAccessAction fQuickAccessAction;
// private IKeyBindingService fKeyBindingService;
private static final String QUICK_MENU_ID= "org.eclipse.cdt.ui.edit.text.c.source.quickMenu"; //$NON-NLS-1$
private IHandlerActivation fQuickAccessHandlerActivation;
private IHandlerService fHandlerService;
/**
* Note: This constructor is for internal use only. Clients should not call this constructor.
@ -149,7 +143,7 @@ public class GenerateActionGroup extends ActionGroup {
fSite= editor.getSite();
fEditor= editor;
fGroupName= groupName;
fAddInclude= new AddIncludeOnSelectionAction(editor);
fAddInclude.setActionDefinitionId(ICEditorActionDefinitionIds.ADD_INCLUDE);
editor.setAction("AddIncludeOnSelection", fAddInclude); //$NON-NLS-1$
@ -207,9 +201,7 @@ public class GenerateActionGroup extends ActionGroup {
// fExternalizeStrings.setActionDefinitionId(ICEditorActionDefinitionIds.EXTERNALIZE_STRINGS);
// editor.setAction("ExternalizeStrings", fExternalizeStrings); //$NON-NLS-1$
//
// fQuickAccessAction= new RefactorQuickAccessAction(editor);
// fKeyBindingService= editor.getEditorSite().getKeyBindingService();
// fKeyBindingService.registerAction(fQuickAccessAction);
installQuickAccessAction();
}
/**
@ -220,7 +212,7 @@ public class GenerateActionGroup extends ActionGroup {
* @param page the page that owns this action group
*/
public GenerateActionGroup(Page page) {
this(page.getSite(), null);
this(page.getSite());
}
/**
@ -231,10 +223,10 @@ public class GenerateActionGroup extends ActionGroup {
* @param part the view part that owns this action group
*/
public GenerateActionGroup(IViewPart part) {
this(part.getSite(), (IHandlerService)part.getSite().getService(IHandlerService.class));
this(part.getSite());
}
private GenerateActionGroup(IWorkbenchSite site, IHandlerService handlerService) {
private GenerateActionGroup(IWorkbenchSite site) {
fSite= site;
ISelectionProvider provider= fSite.getSelectionProvider();
ISelection selection= provider.getSelection();
@ -261,10 +253,10 @@ public class GenerateActionGroup extends ActionGroup {
// fAddCppDocStub.setActionDefinitionId(ICEditorActionDefinitionIds.ADD_JAVADOC_COMMENT);
fAddBookmark= new AddBookmarkAction(site, true);
fAddBookmark.setActionDefinitionId(IWorkbenchActionDefinitionIds.ADD_BOOKMARK);
fAddBookmark.setActionDefinitionId(IWorkbenchCommandConstants.EDIT_ADD_BOOKMARK);
fAddTaskAction= new AddTaskAction(site);
fAddTaskAction.setActionDefinitionId(IWorkbenchActionDefinitionIds.ADD_TASK);
fAddTaskAction.setActionDefinitionId(IWorkbenchCommandConstants.EDIT_ADD_TASK);
// fExternalizeStrings= new ExternalizeStringsAction(site);
// fExternalizeStrings.setActionDefinitionId(ICEditorActionDefinitionIds.EXTERNALIZE_STRINGS);
@ -320,13 +312,22 @@ public class GenerateActionGroup extends ActionGroup {
registerSelectionListener(provider, fAddTaskAction);
// registerSelectionListener(provider, fCleanUp);
// fKeyBindingService= keyBindingService;
// if (fKeyBindingService != null) {
// fQuickAccessAction= new RefactorQuickAccessAction(null);
// fKeyBindingService.registerAction(fQuickAccessAction);
// }
installQuickAccessAction();
}
private void installQuickAccessAction() {
fHandlerService= (IHandlerService)fSite.getService(IHandlerService.class);
if (fHandlerService != null) {
IHandler handler= new CDTQuickMenuCreator(fEditor) {
@Override
protected void fillMenu(IMenuManager menu) {
fillQuickMenu(menu);
}
}.createHandler();
fQuickAccessHandlerActivation= fHandlerService.activateHandler(QUICK_MENU_ID, handler);
}
}
private void registerSelectionListener(ISelectionProvider provider, ISelectionChangedListener listener) {
if (fRegisteredSelectionListeners == null)
fRegisteredSelectionListeners= new ArrayList<ISelectionChangedListener>(10);
@ -361,11 +362,8 @@ public class GenerateActionGroup extends ActionGroup {
@Override
public void fillContextMenu(IMenuManager menu) {
super.fillContextMenu(menu);
String menuText= ActionMessages.getString("SourceMenu_label"); //$NON-NLS-1$
// if (fQuickAccessAction != null) {
// menuText= fQuickAccessAction.addShortcut(menuText);
// }
IMenuManager subMenu= new MenuManager(menuText, MENU_ID);
MenuManager subMenu= new MenuManager(ActionMessages.getString("SourceMenu_label"), MENU_ID); //$NON-NLS-1$
subMenu.setActionDefinitionId(QUICK_MENU_ID);
int added= 0;
if (isEditorOwner()) {
added= fillEditorSubMenu(subMenu);
@ -376,13 +374,13 @@ public class GenerateActionGroup extends ActionGroup {
menu.appendToGroup(fGroupName, subMenu);
}
// private void fillQuickMenu(IMenuManager menu) {
// if (isEditorOwner()) {
// fillEditorSubMenu(menu);
// } else {
// fillViewSubMenu(menu);
// }
// }
private void fillQuickMenu(IMenuManager menu) {
if (isEditorOwner()) {
fillEditorSubMenu(menu);
} else {
fillViewSubMenu(menu);
}
}
private int fillEditorSubMenu(IMenuManager source) {
int added= 0;
@ -402,7 +400,6 @@ public class GenerateActionGroup extends ActionGroup {
// added+= addAction(source, fSortMembers);
// added+= addAction(source, fCleanUp);
source.add(new Separator(GROUP_GENERATE));
added+= addEditorAction(source, "ContentAssistProposal"); //$NON-NLS-1$
// added+= addAction(source, fOverrideMethods);
added+= addAction(source, fAddGetterSetter);
added+= addAction(source, fImplementMethod);
@ -454,9 +451,9 @@ public class GenerateActionGroup extends ActionGroup {
provider.removeSelectionChangedListener(listener);
}
}
// if (fQuickAccessAction != null && fKeyBindingService != null) {
// fKeyBindingService.unregisterAction(fQuickAccessAction);
// }
if (fQuickAccessHandlerActivation != null && fHandlerService != null) {
fHandlerService.deactivateHandler(fQuickAccessHandlerActivation);
}
fEditor= null;
super.dispose();
}