1
/*******************************************************************************
2
* Copyright (c) 2005, 2008 IBM Corporation and others.
3
* All rights reserved. This program and the accompanying materials
4
* are made available under the terms of the Eclipse Public License v1.0
5
* which accompanies this distribution, and is available at
6
* http://www.eclipse.org/legal/epl-v10.html
9
* IBM Corporation - initial API and implementation
11
* Markus Schorn (Wind River Systems)
12
* Anton Leherbauer (Wind River Systems)
13
*******************************************************************************/
14
package org.eclipse.cdt.internal.ui.editor;
16
import java.util.ResourceBundle;
18
import org.eclipse.jface.action.IAction;
19
import org.eclipse.jface.action.IMenuManager;
20
import org.eclipse.jface.action.Separator;
21
import org.eclipse.jface.text.ITextOperationTarget;
22
import org.eclipse.ui.IActionBars;
23
import org.eclipse.ui.IEditorPart;
24
import org.eclipse.ui.IWorkbenchActionConstants;
25
import org.eclipse.ui.editors.text.TextEditorActionContributor;
26
import org.eclipse.ui.texteditor.ITextEditor;
27
import org.eclipse.ui.texteditor.ITextEditorActionConstants;
28
import org.eclipse.ui.texteditor.ITextEditorActionDefinitionIds;
29
import org.eclipse.ui.texteditor.RetargetTextEditorAction;
31
import org.eclipse.cdt.internal.ui.CPluginImages;
32
import org.eclipse.cdt.internal.ui.IContextMenuConstants;
33
import org.eclipse.cdt.internal.ui.actions.FindWordAction;
34
import org.eclipse.cdt.internal.ui.actions.GoToNextPreviousMemberAction;
35
import org.eclipse.cdt.internal.ui.actions.GotoNextBookmarkAction;
37
public class CEditorActionContributor extends TextEditorActionContributor {
39
private RetargetTextEditorAction fContentAssist;
40
private RetargetTextEditorAction fContextInformation;
41
private RetargetTextEditorAction fFormatter;
42
private RetargetTextEditorAction fAddInclude;
43
private RetargetTextEditorAction fShiftLeft;
44
private RetargetTextEditorAction fShiftRight;
45
private TogglePresentationAction fTogglePresentation;
46
private GotoAnnotationAction fPreviousAnnotation;
47
private GotoAnnotationAction fNextAnnotation;
48
private RetargetTextEditorAction fGotoMatchingBracket;
49
private RetargetTextEditorAction fGotoNextBookmark;
50
private RetargetTextEditorAction fGotoNextMemberAction;
51
private RetargetTextEditorAction fGotoPreviousMemberAction;
52
private RetargetTextEditorAction fToggleInsertModeAction;
53
private RetargetTextEditorAction fShowOutline;
54
private RetargetTextEditorAction fToggleSourceHeader;
55
private ToggleMarkOccurrencesAction fToggleMarkOccurrencesAction;
56
private RetargetTextEditorAction fFindWord;
58
public CEditorActionContributor() {
61
ResourceBundle bundle = ConstructedCEditorMessages.getResourceBundle();
63
fShiftRight= new RetargetTextEditorAction(bundle, "ShiftRight.", ITextOperationTarget.SHIFT_RIGHT); //$NON-NLS-1$
64
fShiftRight.setActionDefinitionId(ITextEditorActionDefinitionIds.SHIFT_RIGHT);
65
CPluginImages.setImageDescriptors(fShiftRight, CPluginImages.T_LCL, CPluginImages.IMG_MENU_SHIFT_RIGHT);
67
fShiftLeft= new RetargetTextEditorAction(bundle, "ShiftLeft.", ITextOperationTarget.SHIFT_LEFT); //$NON-NLS-1$
68
fShiftLeft.setActionDefinitionId(ITextEditorActionDefinitionIds.SHIFT_LEFT);
69
CPluginImages.setImageDescriptors(fShiftLeft, CPluginImages.T_LCL, CPluginImages.IMG_MENU_SHIFT_LEFT);
71
fContentAssist = new RetargetTextEditorAction(bundle, "ContentAssistProposal."); //$NON-NLS-1$
72
fContentAssist.setActionDefinitionId(ITextEditorActionDefinitionIds.CONTENT_ASSIST_PROPOSALS);
74
fContextInformation = new RetargetTextEditorAction(bundle, "ContentAssistContextInformation."); //$NON-NLS-1$
75
fContextInformation.setActionDefinitionId(ITextEditorActionDefinitionIds.CONTENT_ASSIST_CONTEXT_INFORMATION);
77
fFormatter = new RetargetTextEditorAction(bundle, "Format."); //$NON-NLS-1$
78
fFormatter.setActionDefinitionId(ICEditorActionDefinitionIds.FORMAT);
80
fAddInclude = new RetargetTextEditorAction(bundle, "AddIncludeOnSelection."); //$NON-NLS-1$
81
fAddInclude.setActionDefinitionId(ICEditorActionDefinitionIds.ADD_INCLUDE);
83
// actions that are "contributed" to editors, they are considered belonging to the active editor
84
fTogglePresentation= new TogglePresentationAction();
86
fToggleMarkOccurrencesAction= new ToggleMarkOccurrencesAction();
88
fPreviousAnnotation= new GotoAnnotationAction("PreviousAnnotation.", false); //$NON-NLS-1$
89
fNextAnnotation= new GotoAnnotationAction("NextAnnotation.", true); //$NON-NLS-1$
91
fGotoMatchingBracket= new RetargetTextEditorAction(bundle, "GotoMatchingBracket."); //$NON-NLS-1$
92
fGotoMatchingBracket.setActionDefinitionId(ICEditorActionDefinitionIds.GOTO_MATCHING_BRACKET);
94
fGotoNextBookmark = new RetargetTextEditorAction(bundle, "GotoNextBookmark."); //$NON-NLS-1$
95
fGotoNextBookmark.setActionDefinitionId(ICEditorActionDefinitionIds.GOTO_NEXT_BOOKMARK);
97
fGotoNextMemberAction= new RetargetTextEditorAction(bundle, "GotoNextMember."); //$NON-NLS-1$
98
fGotoNextMemberAction.setActionDefinitionId(ICEditorActionDefinitionIds.GOTO_NEXT_MEMBER);
99
fGotoPreviousMemberAction= new RetargetTextEditorAction(bundle, "GotoPreviousMember."); //$NON-NLS-1$
100
fGotoPreviousMemberAction.setActionDefinitionId(ICEditorActionDefinitionIds.GOTO_PREVIOUS_MEMBER);
102
fToggleInsertModeAction= new RetargetTextEditorAction(bundle, "ToggleInsertMode.", IAction.AS_CHECK_BOX); //$NON-NLS-1$
103
fToggleInsertModeAction.setActionDefinitionId(ITextEditorActionDefinitionIds.TOGGLE_INSERT_MODE);
105
fShowOutline= new RetargetTextEditorAction(bundle, "OpenOutline."); //$NON-NLS-1$
106
fShowOutline.setActionDefinitionId(ICEditorActionDefinitionIds.OPEN_OUTLINE);
108
fToggleSourceHeader= new RetargetTextEditorAction(bundle, "ToggleSourceHeader."); //$NON-NLS-1$
109
fToggleSourceHeader.setActionDefinitionId(ICEditorActionDefinitionIds.TOGGLE_SOURCE_HEADER);
111
fFindWord = new RetargetTextEditorAction(bundle, "FindWord."); //$NON-NLS-1$
112
fFindWord.setActionDefinitionId(ICEditorActionDefinitionIds.FIND_WORD);
116
* @see org.eclipse.ui.texteditor.BasicTextEditorActionContributor#contributeToMenu(org.eclipse.jface.action.IMenuManager)
119
public void contributeToMenu(IMenuManager menu) {
121
super.contributeToMenu(menu);
123
IMenuManager editMenu= menu.findMenuUsingPath(IWorkbenchActionConstants.M_EDIT);
124
if (editMenu != null) {
125
editMenu.appendToGroup(ITextEditorActionConstants.GROUP_ASSIST, fContentAssist);
126
editMenu.appendToGroup(ITextEditorActionConstants.GROUP_ASSIST, fContextInformation);
128
editMenu.prependToGroup(IWorkbenchActionConstants.FIND_EXT, fFindWord);
130
editMenu.appendToGroup(ITextEditorActionConstants.GROUP_GENERATE, fShiftRight);
131
editMenu.appendToGroup(ITextEditorActionConstants.GROUP_GENERATE, fShiftLeft);
132
editMenu.appendToGroup(ITextEditorActionConstants.GROUP_GENERATE, fFormatter);
133
editMenu.appendToGroup(ITextEditorActionConstants.GROUP_GENERATE, new Separator());
134
editMenu.appendToGroup(ITextEditorActionConstants.GROUP_GENERATE, fAddInclude);
135
editMenu.appendToGroup(ITextEditorActionConstants.GROUP_GENERATE, new Separator());
137
editMenu.appendToGroup(IContextMenuConstants.GROUP_ADDITIONS, fToggleInsertModeAction);
140
IMenuManager navigateMenu= menu.findMenuUsingPath(IWorkbenchActionConstants.M_NAVIGATE);
141
if (navigateMenu != null) {
142
navigateMenu.appendToGroup(IWorkbenchActionConstants.OPEN_EXT, fToggleSourceHeader);
144
navigateMenu.appendToGroup(IWorkbenchActionConstants.SHOW_EXT, fShowOutline);
146
IMenuManager gotoMenu= navigateMenu.findMenuUsingPath(IWorkbenchActionConstants.GO_TO);
147
if (gotoMenu != null) {
148
gotoMenu.add(new Separator("additions2")); //$NON-NLS-1$
149
gotoMenu.appendToGroup("additions2", fGotoPreviousMemberAction); //$NON-NLS-1$
150
gotoMenu.appendToGroup("additions2", fGotoNextMemberAction); //$NON-NLS-1$
151
gotoMenu.appendToGroup("additions2", fGotoMatchingBracket); //$NON-NLS-1$
152
gotoMenu.appendToGroup("additions2", fGotoNextBookmark); //$NON-NLS-1$
159
* @see org.eclipse.ui.part.EditorActionBarContributor#init(IActionBars)
162
public void init(IActionBars bars) {
165
// register actions that have a dynamic editor.
166
bars.setGlobalActionHandler(ITextEditorActionDefinitionIds.GOTO_NEXT_ANNOTATION, fNextAnnotation);
167
bars.setGlobalActionHandler(ITextEditorActionDefinitionIds.GOTO_PREVIOUS_ANNOTATION, fPreviousAnnotation);
168
bars.setGlobalActionHandler(ITextEditorActionConstants.NEXT, fNextAnnotation);
169
bars.setGlobalActionHandler(ITextEditorActionConstants.PREVIOUS, fPreviousAnnotation);
170
bars.setGlobalActionHandler(ITextEditorActionDefinitionIds.TOGGLE_SHOW_SELECTED_ELEMENT_ONLY, fTogglePresentation);
171
bars.setGlobalActionHandler(ICEditorActionDefinitionIds.TOGGLE_MARK_OCCURRENCES, fToggleMarkOccurrencesAction);
175
* @see org.eclipse.ui.editors.text.TextEditorActionContributor#setActiveEditor(org.eclipse.ui.IEditorPart)
178
public void setActiveEditor(IEditorPart part) {
180
super.setActiveEditor(part);
182
ITextEditor textEditor= null;
183
if (part instanceof ITextEditor)
184
textEditor= (ITextEditor) part;
186
fShiftRight.setAction(getAction(textEditor, ITextEditorActionConstants.SHIFT_RIGHT));
187
fShiftLeft.setAction(getAction(textEditor, ITextEditorActionConstants.SHIFT_LEFT));
189
fTogglePresentation.setEditor(textEditor);
190
fToggleMarkOccurrencesAction.setEditor(textEditor);
191
fPreviousAnnotation.setEditor(textEditor);
192
fNextAnnotation.setEditor(textEditor);
194
fContentAssist.setAction(getAction(textEditor, "ContentAssistProposal")); //$NON-NLS-1$
195
fContextInformation.setAction(getAction(textEditor, "ContentAssistContextInformation")); //$NON-NLS-1$
196
fAddInclude.setAction(getAction(textEditor, "AddIncludeOnSelection")); //$NON-NLS-1$
197
fFormatter.setAction(getAction(textEditor, "Format")); //$NON-NLS-1$
199
fGotoMatchingBracket.setAction(getAction(textEditor, GotoMatchingBracketAction.GOTO_MATCHING_BRACKET));
200
fGotoNextBookmark.setAction(getAction(textEditor, GotoNextBookmarkAction.NEXT_BOOKMARK));
201
fGotoNextMemberAction.setAction(getAction(textEditor, GoToNextPreviousMemberAction.NEXT_MEMBER));
202
fGotoPreviousMemberAction.setAction(getAction(textEditor, GoToNextPreviousMemberAction.PREVIOUS_MEMBER));
204
fShowOutline.setAction(getAction(textEditor, "OpenOutline")); //$NON-NLS-1$
205
fToggleSourceHeader.setAction(getAction(textEditor, "ToggleSourceHeader")); //$NON-NLS-1$
206
fToggleInsertModeAction.setAction(getAction(textEditor, ITextEditorActionConstants.TOGGLE_INSERT_MODE));
207
fFindWord.setAction(getAction(textEditor, FindWordAction.FIND_WORD));
209
if (part instanceof CEditor) {
210
CEditor cEditor= (CEditor) part;
211
cEditor.fillActionBars(getActionBars());
217
* @see org.eclipse.ui.IEditorActionBarContributor#dispose()
220
public void dispose() {
221
setActiveEditor(null);