~ubuntu-branches/debian/sid/eclipse-cdt/sid

« back to all changes in this revision

Viewing changes to results/plugins/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/editor/CEditorActionContributor.java

  • Committer: Package Import Robot
  • Author(s): Jakub Adam
  • Date: 2011-10-06 21:15:04 UTC
  • mfrom: (1.1.4)
  • Revision ID: package-import@ubuntu.com-20111006211504-8dutmljjih0zikfv
Tags: 8.0.1-1
* New upstream release.
* Split the JNI packages into a separate architecture dependent
  package and made eclipse-cdt architecture independent.
* Install JNI libraries into multiarch aware location
* Bumped Standards-Version to 3.9.2.

Show diffs side-by-side

added added

removed removed

Lines of Context:
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
7
 
 *
8
 
 * Contributors:
9
 
 *     IBM Corporation - initial API and implementation
10
 
 *     QNX Software System
11
 
 *     Markus Schorn (Wind River Systems)
12
 
 *     Anton Leherbauer (Wind River Systems)
13
 
 *******************************************************************************/
14
 
package org.eclipse.cdt.internal.ui.editor;
15
 
 
16
 
import java.util.ResourceBundle;
17
 
 
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;
30
 
 
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;
36
 
 
37
 
public class CEditorActionContributor extends TextEditorActionContributor {
38
 
        
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;
57
 
        
58
 
        public CEditorActionContributor() {
59
 
                super();
60
 
                
61
 
                ResourceBundle bundle = ConstructedCEditorMessages.getResourceBundle();
62
 
        
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);
66
 
 
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);
70
 
                
71
 
                fContentAssist = new RetargetTextEditorAction(bundle, "ContentAssistProposal."); //$NON-NLS-1$
72
 
                fContentAssist.setActionDefinitionId(ITextEditorActionDefinitionIds.CONTENT_ASSIST_PROPOSALS);
73
 
 
74
 
                fContextInformation = new RetargetTextEditorAction(bundle, "ContentAssistContextInformation."); //$NON-NLS-1$
75
 
                fContextInformation.setActionDefinitionId(ITextEditorActionDefinitionIds.CONTENT_ASSIST_CONTEXT_INFORMATION);
76
 
 
77
 
                fFormatter = new RetargetTextEditorAction(bundle, "Format."); //$NON-NLS-1$
78
 
                fFormatter.setActionDefinitionId(ICEditorActionDefinitionIds.FORMAT);
79
 
                
80
 
                fAddInclude = new RetargetTextEditorAction(bundle, "AddIncludeOnSelection."); //$NON-NLS-1$
81
 
                fAddInclude.setActionDefinitionId(ICEditorActionDefinitionIds.ADD_INCLUDE);
82
 
 
83
 
                // actions that are "contributed" to editors, they are considered belonging to the active editor
84
 
                fTogglePresentation= new TogglePresentationAction();
85
 
 
86
 
                fToggleMarkOccurrencesAction= new ToggleMarkOccurrencesAction();
87
 
 
88
 
                fPreviousAnnotation= new GotoAnnotationAction("PreviousAnnotation.", false); //$NON-NLS-1$
89
 
                fNextAnnotation= new GotoAnnotationAction("NextAnnotation.", true); //$NON-NLS-1$
90
 
 
91
 
                fGotoMatchingBracket= new RetargetTextEditorAction(bundle, "GotoMatchingBracket."); //$NON-NLS-1$
92
 
                fGotoMatchingBracket.setActionDefinitionId(ICEditorActionDefinitionIds.GOTO_MATCHING_BRACKET);
93
 
 
94
 
                fGotoNextBookmark = new RetargetTextEditorAction(bundle, "GotoNextBookmark."); //$NON-NLS-1$
95
 
                fGotoNextBookmark.setActionDefinitionId(ICEditorActionDefinitionIds.GOTO_NEXT_BOOKMARK);
96
 
 
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);
101
 
 
102
 
                fToggleInsertModeAction= new RetargetTextEditorAction(bundle, "ToggleInsertMode.", IAction.AS_CHECK_BOX); //$NON-NLS-1$
103
 
                fToggleInsertModeAction.setActionDefinitionId(ITextEditorActionDefinitionIds.TOGGLE_INSERT_MODE);
104
 
 
105
 
                fShowOutline= new RetargetTextEditorAction(bundle, "OpenOutline."); //$NON-NLS-1$
106
 
                fShowOutline.setActionDefinitionId(ICEditorActionDefinitionIds.OPEN_OUTLINE);
107
 
 
108
 
                fToggleSourceHeader= new RetargetTextEditorAction(bundle, "ToggleSourceHeader."); //$NON-NLS-1$
109
 
                fToggleSourceHeader.setActionDefinitionId(ICEditorActionDefinitionIds.TOGGLE_SOURCE_HEADER);
110
 
 
111
 
                fFindWord = new RetargetTextEditorAction(bundle, "FindWord."); //$NON-NLS-1$
112
 
                fFindWord.setActionDefinitionId(ICEditorActionDefinitionIds.FIND_WORD);
113
 
        }       
114
 
 
115
 
        /*
116
 
         * @see org.eclipse.ui.texteditor.BasicTextEditorActionContributor#contributeToMenu(org.eclipse.jface.action.IMenuManager)
117
 
         */
118
 
        @Override
119
 
        public void contributeToMenu(IMenuManager menu) {
120
 
                
121
 
                super.contributeToMenu(menu);
122
 
                
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);
127
 
 
128
 
                        editMenu.prependToGroup(IWorkbenchActionConstants.FIND_EXT, fFindWord);
129
 
 
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());
136
 
 
137
 
                        editMenu.appendToGroup(IContextMenuConstants.GROUP_ADDITIONS, fToggleInsertModeAction);
138
 
                }
139
 
                
140
 
                IMenuManager navigateMenu= menu.findMenuUsingPath(IWorkbenchActionConstants.M_NAVIGATE);
141
 
                if (navigateMenu != null) {
142
 
                        navigateMenu.appendToGroup(IWorkbenchActionConstants.OPEN_EXT, fToggleSourceHeader);
143
 
 
144
 
                        navigateMenu.appendToGroup(IWorkbenchActionConstants.SHOW_EXT, fShowOutline);
145
 
 
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$
153
 
                        }
154
 
                }
155
 
 
156
 
        }
157
 
        
158
 
        /**
159
 
         * @see org.eclipse.ui.part.EditorActionBarContributor#init(IActionBars)
160
 
         */
161
 
        @Override
162
 
        public void init(IActionBars bars) {
163
 
                super.init(bars);
164
 
 
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);
172
 
        }
173
 
 
174
 
        /*
175
 
         * @see org.eclipse.ui.editors.text.TextEditorActionContributor#setActiveEditor(org.eclipse.ui.IEditorPart)
176
 
         */
177
 
        @Override
178
 
        public void setActiveEditor(IEditorPart part) {
179
 
                
180
 
                super.setActiveEditor(part);
181
 
                
182
 
                ITextEditor textEditor= null;
183
 
                if (part instanceof ITextEditor)
184
 
                        textEditor= (ITextEditor) part;
185
 
                
186
 
                fShiftRight.setAction(getAction(textEditor, ITextEditorActionConstants.SHIFT_RIGHT));
187
 
                fShiftLeft.setAction(getAction(textEditor, ITextEditorActionConstants.SHIFT_LEFT));
188
 
 
189
 
                fTogglePresentation.setEditor(textEditor);
190
 
                fToggleMarkOccurrencesAction.setEditor(textEditor);
191
 
                fPreviousAnnotation.setEditor(textEditor);
192
 
                fNextAnnotation.setEditor(textEditor);
193
 
 
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$
198
 
 
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));
203
 
 
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));
208
 
 
209
 
                if (part instanceof CEditor) {
210
 
                        CEditor cEditor= (CEditor) part;
211
 
                        cEditor.fillActionBars(getActionBars());
212
 
                }
213
 
 
214
 
        }
215
 
        
216
 
        /* (non-Javadoc)
217
 
         * @see org.eclipse.ui.IEditorActionBarContributor#dispose()
218
 
         */
219
 
        @Override
220
 
        public void dispose() {
221
 
                setActiveEditor(null);
222
 
                super.dispose();
223
 
        }
224
 
}