Lines 16-23
Link Here
|
16 |
|
16 |
|
17 |
|
17 |
|
18 |
import java.text.CharacterIterator; |
18 |
import java.text.CharacterIterator; |
|
|
19 |
import java.util.ArrayList; |
20 |
import java.util.HashMap; |
19 |
import java.util.Iterator; |
21 |
import java.util.Iterator; |
|
|
22 |
import java.util.List; |
23 |
import java.util.Map; |
20 |
import java.util.ResourceBundle; |
24 |
import java.util.ResourceBundle; |
|
|
25 |
import java.util.Stack; |
21 |
|
26 |
|
22 |
import org.eclipse.core.resources.IFile; |
27 |
import org.eclipse.core.resources.IFile; |
23 |
import org.eclipse.core.runtime.CoreException; |
28 |
import org.eclipse.core.runtime.CoreException; |
Lines 31-65
Link Here
|
31 |
import org.eclipse.jface.preference.IPreferenceStore; |
36 |
import org.eclipse.jface.preference.IPreferenceStore; |
32 |
import org.eclipse.jface.text.AbstractInformationControlManager; |
37 |
import org.eclipse.jface.text.AbstractInformationControlManager; |
33 |
import org.eclipse.jface.text.BadLocationException; |
38 |
import org.eclipse.jface.text.BadLocationException; |
|
|
39 |
import org.eclipse.jface.text.BadPositionCategoryException; |
34 |
import org.eclipse.jface.text.DefaultInformationControl; |
40 |
import org.eclipse.jface.text.DefaultInformationControl; |
35 |
import org.eclipse.jface.text.DefaultLineTracker; |
41 |
import org.eclipse.jface.text.DefaultLineTracker; |
36 |
import org.eclipse.jface.text.DocumentCommand; |
42 |
import org.eclipse.jface.text.DocumentCommand; |
|
|
43 |
import org.eclipse.jface.text.DocumentEvent; |
37 |
import org.eclipse.jface.text.IDocument; |
44 |
import org.eclipse.jface.text.IDocument; |
|
|
45 |
import org.eclipse.jface.text.IDocumentExtension; |
46 |
import org.eclipse.jface.text.IDocumentListener; |
38 |
import org.eclipse.jface.text.IInformationControl; |
47 |
import org.eclipse.jface.text.IInformationControl; |
39 |
import org.eclipse.jface.text.IInformationControlCreator; |
48 |
import org.eclipse.jface.text.IInformationControlCreator; |
40 |
import org.eclipse.jface.text.ILineTracker; |
49 |
import org.eclipse.jface.text.ILineTracker; |
|
|
50 |
import org.eclipse.jface.text.IPositionUpdater; |
41 |
import org.eclipse.jface.text.IRegion; |
51 |
import org.eclipse.jface.text.IRegion; |
42 |
import org.eclipse.jface.text.ITextHover; |
52 |
import org.eclipse.jface.text.ITextHover; |
43 |
import org.eclipse.jface.text.ITextSelection; |
53 |
import org.eclipse.jface.text.ITextSelection; |
44 |
import org.eclipse.jface.text.ITextViewer; |
54 |
import org.eclipse.jface.text.ITextViewer; |
|
|
55 |
import org.eclipse.jface.text.ITextViewerExtension; |
45 |
import org.eclipse.jface.text.ITextViewerExtension2; |
56 |
import org.eclipse.jface.text.ITextViewerExtension2; |
46 |
import org.eclipse.jface.text.ITextViewerExtension4; |
57 |
import org.eclipse.jface.text.ITextViewerExtension4; |
47 |
import org.eclipse.jface.text.ITextViewerExtension5; |
58 |
import org.eclipse.jface.text.ITextViewerExtension5; |
|
|
59 |
import org.eclipse.jface.text.ITypedRegion; |
60 |
import org.eclipse.jface.text.IWidgetTokenKeeper; |
48 |
import org.eclipse.jface.text.Position; |
61 |
import org.eclipse.jface.text.Position; |
49 |
import org.eclipse.jface.text.Region; |
62 |
import org.eclipse.jface.text.Region; |
50 |
import org.eclipse.jface.text.TextUtilities; |
63 |
import org.eclipse.jface.text.TextUtilities; |
51 |
import org.eclipse.jface.text.contentassist.ContentAssistant; |
64 |
import org.eclipse.jface.text.contentassist.ContentAssistant; |
52 |
import org.eclipse.jface.text.contentassist.IContentAssistant; |
65 |
import org.eclipse.jface.text.contentassist.IContentAssistant; |
|
|
66 |
import org.eclipse.jface.text.formatter.FormattingContextProperties; |
67 |
import org.eclipse.jface.text.formatter.IFormattingContext; |
53 |
import org.eclipse.jface.text.information.IInformationProvider; |
68 |
import org.eclipse.jface.text.information.IInformationProvider; |
54 |
import org.eclipse.jface.text.information.IInformationProviderExtension; |
69 |
import org.eclipse.jface.text.information.IInformationProviderExtension; |
55 |
import org.eclipse.jface.text.information.IInformationProviderExtension2; |
70 |
import org.eclipse.jface.text.information.IInformationProviderExtension2; |
56 |
import org.eclipse.jface.text.information.InformationPresenter; |
71 |
import org.eclipse.jface.text.information.InformationPresenter; |
|
|
72 |
import org.eclipse.jface.text.link.ILinkedModeListener; |
73 |
import org.eclipse.jface.text.link.LinkedModeModel; |
74 |
import org.eclipse.jface.text.link.LinkedModeUI; |
75 |
import org.eclipse.jface.text.link.LinkedPosition; |
76 |
import org.eclipse.jface.text.link.LinkedPositionGroup; |
77 |
import org.eclipse.jface.text.link.LinkedModeUI.ExitFlags; |
78 |
import org.eclipse.jface.text.link.LinkedModeUI.IExitPolicy; |
57 |
import org.eclipse.jface.text.source.Annotation; |
79 |
import org.eclipse.jface.text.source.Annotation; |
58 |
import org.eclipse.jface.text.source.IAnnotationHover; |
80 |
import org.eclipse.jface.text.source.IAnnotationHover; |
59 |
import org.eclipse.jface.text.source.IAnnotationHoverExtension; |
81 |
import org.eclipse.jface.text.source.IAnnotationHoverExtension; |
60 |
import org.eclipse.jface.text.source.IAnnotationModel; |
82 |
import org.eclipse.jface.text.source.IAnnotationModel; |
61 |
import org.eclipse.jface.text.source.ICharacterPairMatcher; |
83 |
import org.eclipse.jface.text.source.ICharacterPairMatcher; |
62 |
import org.eclipse.jface.text.source.ILineRange; |
84 |
import org.eclipse.jface.text.source.ILineRange; |
|
|
85 |
import org.eclipse.jface.text.source.IOverviewRuler; |
63 |
import org.eclipse.jface.text.source.ISourceViewer; |
86 |
import org.eclipse.jface.text.source.ISourceViewer; |
64 |
import org.eclipse.jface.text.source.ISourceViewerExtension3; |
87 |
import org.eclipse.jface.text.source.ISourceViewerExtension3; |
65 |
import org.eclipse.jface.text.source.IVerticalRuler; |
88 |
import org.eclipse.jface.text.source.IVerticalRuler; |
Lines 78-89
Link Here
|
78 |
import org.eclipse.swt.SWT; |
101 |
import org.eclipse.swt.SWT; |
79 |
import org.eclipse.swt.custom.ST; |
102 |
import org.eclipse.swt.custom.ST; |
80 |
import org.eclipse.swt.custom.StyledText; |
103 |
import org.eclipse.swt.custom.StyledText; |
|
|
104 |
import org.eclipse.swt.custom.VerifyKeyListener; |
81 |
import org.eclipse.swt.dnd.DND; |
105 |
import org.eclipse.swt.dnd.DND; |
82 |
import org.eclipse.swt.dnd.DragSource; |
106 |
import org.eclipse.swt.dnd.DragSource; |
83 |
import org.eclipse.swt.dnd.DragSourceListener; |
107 |
import org.eclipse.swt.dnd.DragSourceListener; |
84 |
import org.eclipse.swt.dnd.DropTarget; |
108 |
import org.eclipse.swt.dnd.DropTarget; |
85 |
import org.eclipse.swt.dnd.TextTransfer; |
109 |
import org.eclipse.swt.dnd.TextTransfer; |
86 |
import org.eclipse.swt.dnd.Transfer; |
110 |
import org.eclipse.swt.dnd.Transfer; |
|
|
111 |
import org.eclipse.swt.events.VerifyEvent; |
87 |
import org.eclipse.swt.graphics.Image; |
112 |
import org.eclipse.swt.graphics.Image; |
88 |
import org.eclipse.swt.graphics.Point; |
113 |
import org.eclipse.swt.graphics.Point; |
89 |
import org.eclipse.swt.widgets.Composite; |
114 |
import org.eclipse.swt.widgets.Composite; |
Lines 102-108
Link Here
|
102 |
import org.eclipse.ui.part.IShowInSource; |
127 |
import org.eclipse.ui.part.IShowInSource; |
103 |
import org.eclipse.ui.part.IShowInTargetList; |
128 |
import org.eclipse.ui.part.IShowInTargetList; |
104 |
import org.eclipse.ui.part.ShowInContext; |
129 |
import org.eclipse.ui.part.ShowInContext; |
105 |
import org.eclipse.ui.texteditor.AbstractDecoratedTextEditorPreferenceConstants; |
|
|
106 |
import org.eclipse.ui.texteditor.ContentAssistAction; |
130 |
import org.eclipse.ui.texteditor.ContentAssistAction; |
107 |
import org.eclipse.ui.texteditor.IDocumentProvider; |
131 |
import org.eclipse.ui.texteditor.IDocumentProvider; |
108 |
import org.eclipse.ui.texteditor.IEditorStatusLine; |
132 |
import org.eclipse.ui.texteditor.IEditorStatusLine; |
Lines 115-120
Link Here
|
115 |
import org.eclipse.ui.texteditor.TextEditorAction; |
139 |
import org.eclipse.ui.texteditor.TextEditorAction; |
116 |
import org.eclipse.ui.texteditor.TextNavigationAction; |
140 |
import org.eclipse.ui.texteditor.TextNavigationAction; |
117 |
import org.eclipse.ui.texteditor.TextOperationAction; |
141 |
import org.eclipse.ui.texteditor.TextOperationAction; |
|
|
142 |
import org.eclipse.ui.texteditor.link.EditorLinkedModeUI; |
118 |
import org.eclipse.ui.views.contentoutline.IContentOutlinePage; |
143 |
import org.eclipse.ui.views.contentoutline.IContentOutlinePage; |
119 |
|
144 |
|
120 |
import com.ibm.icu.text.BreakIterator; |
145 |
import com.ibm.icu.text.BreakIterator; |
Lines 123-130
Link Here
|
123 |
import org.eclipse.cdt.core.CCorePreferenceConstants; |
148 |
import org.eclipse.cdt.core.CCorePreferenceConstants; |
124 |
import org.eclipse.cdt.core.IPositionConverter; |
149 |
import org.eclipse.cdt.core.IPositionConverter; |
125 |
import org.eclipse.cdt.core.dom.ast.IASTTranslationUnit; |
150 |
import org.eclipse.cdt.core.dom.ast.IASTTranslationUnit; |
|
|
151 |
import org.eclipse.cdt.core.formatter.DefaultCodeFormatterConstants; |
126 |
import org.eclipse.cdt.core.model.CModelException; |
152 |
import org.eclipse.cdt.core.model.CModelException; |
127 |
import org.eclipse.cdt.core.model.ICElement; |
153 |
import org.eclipse.cdt.core.model.ICElement; |
|
|
154 |
import org.eclipse.cdt.core.model.ICProject; |
128 |
import org.eclipse.cdt.core.model.ISourceRange; |
155 |
import org.eclipse.cdt.core.model.ISourceRange; |
129 |
import org.eclipse.cdt.core.model.ISourceReference; |
156 |
import org.eclipse.cdt.core.model.ISourceReference; |
130 |
import org.eclipse.cdt.core.model.ITranslationUnit; |
157 |
import org.eclipse.cdt.core.model.ITranslationUnit; |
Lines 136-141
Link Here
|
136 |
import org.eclipse.cdt.ui.text.ICPartitions; |
163 |
import org.eclipse.cdt.ui.text.ICPartitions; |
137 |
import org.eclipse.cdt.ui.text.folding.ICFoldingStructureProvider; |
164 |
import org.eclipse.cdt.ui.text.folding.ICFoldingStructureProvider; |
138 |
|
165 |
|
|
|
166 |
import org.eclipse.cdt.internal.corext.util.CodeFormatterUtil; |
139 |
import org.eclipse.cdt.internal.corext.util.SimplePositionTracker; |
167 |
import org.eclipse.cdt.internal.corext.util.SimplePositionTracker; |
140 |
|
168 |
|
141 |
import org.eclipse.cdt.internal.ui.ICHelpContextIds; |
169 |
import org.eclipse.cdt.internal.ui.ICHelpContextIds; |
Lines 143-148
Link Here
|
143 |
import org.eclipse.cdt.internal.ui.actions.AddBlockCommentAction; |
171 |
import org.eclipse.cdt.internal.ui.actions.AddBlockCommentAction; |
144 |
import org.eclipse.cdt.internal.ui.actions.FoldingActionGroup; |
172 |
import org.eclipse.cdt.internal.ui.actions.FoldingActionGroup; |
145 |
import org.eclipse.cdt.internal.ui.actions.GoToNextPreviousMemberAction; |
173 |
import org.eclipse.cdt.internal.ui.actions.GoToNextPreviousMemberAction; |
|
|
174 |
import org.eclipse.cdt.internal.ui.actions.IndentAction; |
146 |
import org.eclipse.cdt.internal.ui.actions.JoinLinesAction; |
175 |
import org.eclipse.cdt.internal.ui.actions.JoinLinesAction; |
147 |
import org.eclipse.cdt.internal.ui.actions.RemoveBlockCommentAction; |
176 |
import org.eclipse.cdt.internal.ui.actions.RemoveBlockCommentAction; |
148 |
import org.eclipse.cdt.internal.ui.dnd.TextEditorDropAdapter; |
177 |
import org.eclipse.cdt.internal.ui.dnd.TextEditorDropAdapter; |
Lines 150-155
Link Here
|
150 |
import org.eclipse.cdt.internal.ui.search.actions.OpenDeclarationsAction; |
179 |
import org.eclipse.cdt.internal.ui.search.actions.OpenDeclarationsAction; |
151 |
import org.eclipse.cdt.internal.ui.search.actions.OpenDefinitionAction; |
180 |
import org.eclipse.cdt.internal.ui.search.actions.OpenDefinitionAction; |
152 |
import org.eclipse.cdt.internal.ui.search.actions.SelectionSearchGroup; |
181 |
import org.eclipse.cdt.internal.ui.search.actions.SelectionSearchGroup; |
|
|
182 |
import org.eclipse.cdt.internal.ui.text.CHeuristicScanner; |
153 |
import org.eclipse.cdt.internal.ui.text.CPairMatcher; |
183 |
import org.eclipse.cdt.internal.ui.text.CPairMatcher; |
154 |
import org.eclipse.cdt.internal.ui.text.CSourceViewerConfiguration; |
184 |
import org.eclipse.cdt.internal.ui.text.CSourceViewerConfiguration; |
155 |
import org.eclipse.cdt.internal.ui.text.CTextTools; |
185 |
import org.eclipse.cdt.internal.ui.text.CTextTools; |
Lines 157-163
Link Here
|
157 |
import org.eclipse.cdt.internal.ui.text.DocumentCharacterIterator; |
187 |
import org.eclipse.cdt.internal.ui.text.DocumentCharacterIterator; |
158 |
import org.eclipse.cdt.internal.ui.text.HTMLTextPresenter; |
188 |
import org.eclipse.cdt.internal.ui.text.HTMLTextPresenter; |
159 |
import org.eclipse.cdt.internal.ui.text.ICReconcilingListener; |
189 |
import org.eclipse.cdt.internal.ui.text.ICReconcilingListener; |
|
|
190 |
import org.eclipse.cdt.internal.ui.text.Symbols; |
160 |
import org.eclipse.cdt.internal.ui.text.c.hover.SourceViewerInformationControl; |
191 |
import org.eclipse.cdt.internal.ui.text.c.hover.SourceViewerInformationControl; |
|
|
192 |
import org.eclipse.cdt.internal.ui.text.comment.CommentFormattingContext; |
161 |
import org.eclipse.cdt.internal.ui.text.contentassist.ContentAssistPreference; |
193 |
import org.eclipse.cdt.internal.ui.text.contentassist.ContentAssistPreference; |
162 |
import org.eclipse.cdt.internal.ui.util.CUIHelp; |
194 |
import org.eclipse.cdt.internal.ui.util.CUIHelp; |
163 |
|
195 |
|
Lines 165-180
Link Here
|
165 |
/** |
197 |
/** |
166 |
* C specific text editor. |
198 |
* C specific text editor. |
167 |
*/ |
199 |
*/ |
168 |
public class CEditor extends TextEditor implements ISelectionChangedListener, IShowInSource, IReconcilingParticipant, ICReconcilingListener { |
200 |
public class CEditor extends TextEditor implements ISelectionChangedListener, IShowInSource , IReconcilingParticipant{ |
|
|
201 |
|
202 |
interface ITextConverter { |
203 |
void customizeDocumentCommand(IDocument document, DocumentCommand command); |
204 |
} |
205 |
|
206 |
class AdaptedSourceViewer extends CSourceViewer { |
207 |
|
208 |
private List fTextConverters; |
209 |
private boolean fIgnoreTextConverters= false; |
210 |
|
211 |
public AdaptedSourceViewer(Composite parent, IVerticalRuler verticalRuler, IOverviewRuler overviewRuler, |
212 |
boolean showAnnotationsOverview, int styles) { |
213 |
super(parent, verticalRuler, overviewRuler, showAnnotationsOverview, styles); |
214 |
} |
215 |
|
216 |
public IContentAssistant getContentAssistant() { |
217 |
return fContentAssistant; |
218 |
} |
219 |
|
220 |
/* |
221 |
* @see ITextOperationTarget#doOperation(int) |
222 |
*/ |
223 |
public void doOperation(int operation) { |
224 |
|
225 |
if (getTextWidget() == null) |
226 |
return; |
227 |
|
228 |
switch (operation) { |
229 |
case CONTENTASSIST_PROPOSALS: |
230 |
// long time= CODE_ASSIST_DEBUG ? System.currentTimeMillis() : 0; |
231 |
String msg= fContentAssistant.showPossibleCompletions(); |
232 |
// if (CODE_ASSIST_DEBUG) { |
233 |
// long delta= System.currentTimeMillis() - time; |
234 |
// System.err.println("Code Assist (total): " + delta); //$NON-NLS-1$ |
235 |
// } |
236 |
setStatusLineErrorMessage(msg); |
237 |
return; |
238 |
case QUICK_ASSIST: |
239 |
/* |
240 |
* XXX: We can get rid of this once the SourceViewer has a way to update the status line |
241 |
* https://bugs.eclipse.org/bugs/show_bug.cgi?id=133787 |
242 |
*/ |
243 |
msg= fQuickAssistAssistant.showPossibleQuickAssists(); |
244 |
setStatusLineErrorMessage(msg); |
245 |
return; |
246 |
case UNDO: |
247 |
fIgnoreTextConverters= true; |
248 |
super.doOperation(operation); |
249 |
fIgnoreTextConverters= false; |
250 |
return; |
251 |
case REDO: |
252 |
fIgnoreTextConverters= true; |
253 |
super.doOperation(operation); |
254 |
fIgnoreTextConverters= false; |
255 |
return; |
256 |
} |
257 |
|
258 |
super.doOperation(operation); |
259 |
} |
260 |
|
261 |
public void insertTextConverter(ITextConverter textConverter, int index) { |
262 |
throw new UnsupportedOperationException(); |
263 |
} |
264 |
|
265 |
public void addTextConverter(ITextConverter textConverter) { |
266 |
if (fTextConverters == null) { |
267 |
fTextConverters= new ArrayList(1); |
268 |
fTextConverters.add(textConverter); |
269 |
} else if (!fTextConverters.contains(textConverter)) |
270 |
fTextConverters.add(textConverter); |
271 |
} |
272 |
|
273 |
public void removeTextConverter(ITextConverter textConverter) { |
274 |
if (fTextConverters != null) { |
275 |
fTextConverters.remove(textConverter); |
276 |
if (fTextConverters.size() == 0) |
277 |
fTextConverters= null; |
278 |
} |
279 |
} |
280 |
|
281 |
/* |
282 |
* @see TextViewer#customizeDocumentCommand(DocumentCommand) |
283 |
*/ |
284 |
protected void customizeDocumentCommand(DocumentCommand command) { |
285 |
super.customizeDocumentCommand(command); |
286 |
if (!fIgnoreTextConverters && fTextConverters != null) { |
287 |
for (Iterator e = fTextConverters.iterator(); e.hasNext();) |
288 |
((ITextConverter) e.next()).customizeDocumentCommand(getDocument(), command); |
289 |
} |
290 |
} |
291 |
|
292 |
public void updateIndentationPrefixes() { |
293 |
SourceViewerConfiguration configuration= getSourceViewerConfiguration(); |
294 |
String[] types= configuration.getConfiguredContentTypes(this); |
295 |
for (int i= 0; i < types.length; i++) { |
296 |
String[] prefixes= configuration.getIndentPrefixes(this, types[i]); |
297 |
if (prefixes != null && prefixes.length > 0) |
298 |
setIndentPrefixes(prefixes, types[i]); |
299 |
} |
300 |
|
301 |
StyledText textWidget= getTextWidget(); |
302 |
int tabWidth= configuration.getTabWidth(this); |
303 |
if (textWidget.getTabs() != tabWidth) |
304 |
textWidget.setTabs(tabWidth); |
305 |
} |
306 |
|
307 |
/* |
308 |
* @see IWidgetTokenOwner#requestWidgetToken(IWidgetTokenKeeper) |
309 |
*/ |
310 |
public boolean requestWidgetToken(IWidgetTokenKeeper requester) { |
311 |
if (PlatformUI.getWorkbench().getHelpSystem().isContextHelpDisplayed()) |
312 |
return false; |
313 |
return super.requestWidgetToken(requester); |
314 |
} |
315 |
|
316 |
/* |
317 |
* @see IWidgetTokenOwnerExtension#requestWidgetToken(IWidgetTokenKeeper, int) |
318 |
* @since 3.0 |
319 |
*/ |
320 |
public boolean requestWidgetToken(IWidgetTokenKeeper requester, int priority) { |
321 |
if (PlatformUI.getWorkbench().getHelpSystem().isContextHelpDisplayed()) |
322 |
return false; |
323 |
return super.requestWidgetToken(requester, priority); |
324 |
} |
325 |
|
326 |
/* |
327 |
* @see org.eclipse.jface.text.source.SourceViewer#createFormattingContext() |
328 |
* @since 3.0 |
329 |
*/ |
330 |
public IFormattingContext createFormattingContext() { |
331 |
IFormattingContext context= new CommentFormattingContext(); |
332 |
|
333 |
Map preferences; |
334 |
ICElement inputCElement= getInputCElement(); |
335 |
ICProject cProject= inputCElement != null ? inputCElement.getCProject() : null; |
336 |
if (cProject == null) |
337 |
preferences= new HashMap(CCorePlugin.getOptions()); |
338 |
else |
339 |
preferences= new HashMap(cProject.getOptions(true)); |
340 |
|
341 |
context.setProperty(FormattingContextProperties.CONTEXT_PREFERENCES, preferences); |
342 |
|
343 |
return context; |
344 |
} |
345 |
} |
346 |
|
347 |
static class TabConverter implements ITextConverter { |
348 |
private int fTabRatio; |
349 |
private ILineTracker fLineTracker; |
350 |
|
351 |
public TabConverter() { |
352 |
} |
353 |
|
354 |
public void setNumberOfSpacesPerTab(int ratio) { |
355 |
fTabRatio = ratio; |
356 |
} |
357 |
|
358 |
public void setLineTracker(ILineTracker lineTracker) { |
359 |
fLineTracker = lineTracker; |
360 |
} |
361 |
|
362 |
private int insertTabString(StringBuffer buffer, int offsetInLine) { |
363 |
|
364 |
if (fTabRatio == 0) |
365 |
return 0; |
366 |
|
367 |
int remainder = offsetInLine % fTabRatio; |
368 |
remainder = fTabRatio - remainder; |
369 |
for (int i = 0; i < remainder; i++) |
370 |
buffer.append(' '); |
371 |
return remainder; |
372 |
} |
373 |
|
374 |
public void customizeDocumentCommand(IDocument document, DocumentCommand command) { |
375 |
String text = command.text; |
376 |
if (text == null) |
377 |
return; |
378 |
|
379 |
int index = text.indexOf('\t'); |
380 |
if (index > -1) { |
381 |
StringBuffer buffer = new StringBuffer(); |
382 |
|
383 |
fLineTracker.set(command.text); |
384 |
int lines = fLineTracker.getNumberOfLines(); |
385 |
|
386 |
try { |
387 |
for (int i = 0; i < lines; i++) { |
388 |
int offset = fLineTracker.getLineOffset(i); |
389 |
int endOffset = offset + fLineTracker.getLineLength(i); |
390 |
String line = text.substring(offset, endOffset); |
391 |
|
392 |
int position = 0; |
393 |
if (i == 0) { |
394 |
IRegion firstLine = document.getLineInformationOfOffset(command.offset); |
395 |
position = command.offset - firstLine.getOffset(); |
396 |
} |
397 |
|
398 |
int length = line.length(); |
399 |
for (int j = 0; j < length; j++) { |
400 |
char c = line.charAt(j); |
401 |
if (c == '\t') { |
402 |
int oldPosition = position; |
403 |
position += insertTabString(buffer, position); |
404 |
if (command.caretOffset > command.offset + oldPosition) { |
405 |
command.caretOffset += position - oldPosition - 1; |
406 |
} |
407 |
} else { |
408 |
buffer.append(c); |
409 |
++position; |
410 |
} |
411 |
} |
412 |
} |
413 |
|
414 |
command.text = buffer.toString(); |
415 |
} catch (BadLocationException x) { |
416 |
} |
417 |
} |
418 |
} |
419 |
} |
420 |
|
421 |
private class ExitPolicy implements IExitPolicy { |
422 |
|
423 |
final char fExitCharacter; |
424 |
final char fEscapeCharacter; |
425 |
final Stack fStack; |
426 |
final int fSize; |
427 |
|
428 |
public ExitPolicy(char exitCharacter, char escapeCharacter, Stack stack) { |
429 |
fExitCharacter = exitCharacter; |
430 |
fEscapeCharacter = escapeCharacter; |
431 |
fStack = stack; |
432 |
fSize = fStack.size(); |
433 |
} |
434 |
|
435 |
/* |
436 |
* @see org.eclipse.jface.text.link.LinkedModeUI$IExitPolicy#doExit(org.eclipse.jface.text.link.LinkedModeModel, org.eclipse.swt.events.VerifyEvent, int, int) |
437 |
*/ |
438 |
public ExitFlags doExit(LinkedModeModel model, VerifyEvent event, int offset, int length) { |
439 |
|
440 |
if (fSize == fStack.size() && !isMasked(offset)) { |
441 |
if (event.character == fExitCharacter) { |
442 |
BracketLevel level = (BracketLevel) fStack.peek(); |
443 |
if (level.fFirstPosition.offset > offset || level.fSecondPosition.offset < offset) |
444 |
return null; |
445 |
if (level.fSecondPosition.offset == offset && length == 0) |
446 |
// don't enter the character if if its the closing peer |
447 |
return new ExitFlags(ILinkedModeListener.UPDATE_CARET, false); |
448 |
} |
449 |
// when entering an anonymous class between the parenthesis', we don't want |
450 |
// to jump after the closing parenthesis when return is pressed |
451 |
if (event.character == SWT.CR && offset > 0) { |
452 |
IDocument document = getSourceViewer().getDocument(); |
453 |
try { |
454 |
if (document.getChar(offset - 1) == '{') |
455 |
return new ExitFlags(ILinkedModeListener.EXIT_ALL, true); |
456 |
} catch (BadLocationException e) { |
457 |
} |
458 |
} |
459 |
} |
460 |
return null; |
461 |
} |
462 |
|
463 |
private boolean isMasked(int offset) { |
464 |
IDocument document = getSourceViewer().getDocument(); |
465 |
try { |
466 |
return fEscapeCharacter == document.getChar(offset - 1); |
467 |
} catch (BadLocationException e) { |
468 |
} |
469 |
return false; |
470 |
} |
471 |
} |
472 |
|
473 |
private static class BracketLevel { |
474 |
int fOffset; |
475 |
int fLength; |
476 |
LinkedModeUI fUI; |
477 |
Position fFirstPosition; |
478 |
Position fSecondPosition; |
479 |
} |
169 |
|
480 |
|
170 |
/** |
481 |
/** |
171 |
* The information provider used to present focusable information |
482 |
* Position updater that takes any changes at the borders of a position to not belong to the position. |
172 |
* shells. |
483 |
* |
|
|
484 |
* @since 4.0 |
173 |
*/ |
485 |
*/ |
174 |
private InformationPresenter fInformationPresenter; |
486 |
private static class ExclusivePositionUpdater implements IPositionUpdater { |
175 |
|
487 |
|
|
|
488 |
/** The position category. */ |
489 |
private final String fCategory; |
490 |
|
491 |
/** |
492 |
* Creates a new updater for the given <code>category</code>. |
493 |
* |
494 |
* @param category the new category. |
495 |
*/ |
496 |
public ExclusivePositionUpdater(String category) { |
497 |
fCategory = category; |
498 |
} |
499 |
|
500 |
/* |
501 |
* @see org.eclipse.jface.text.IPositionUpdater#update(org.eclipse.jface.text.DocumentEvent) |
502 |
*/ |
503 |
public void update(DocumentEvent event) { |
504 |
|
505 |
int eventOffset = event.getOffset(); |
506 |
int eventOldLength = event.getLength(); |
507 |
int eventNewLength = event.getText() == null ? 0 : event.getText().length(); |
508 |
int deltaLength = eventNewLength - eventOldLength; |
509 |
|
510 |
try { |
511 |
Position[] positions = event.getDocument().getPositions(fCategory); |
512 |
|
513 |
for (int i = 0; i != positions.length; i++) { |
514 |
|
515 |
Position position = positions[i]; |
516 |
|
517 |
if (position.isDeleted()) |
518 |
continue; |
519 |
|
520 |
int offset = position.getOffset(); |
521 |
int length = position.getLength(); |
522 |
int end = offset + length; |
523 |
|
524 |
if (offset >= eventOffset + eventOldLength) |
525 |
// position comes |
526 |
// after change - shift |
527 |
position.setOffset(offset + deltaLength); |
528 |
else if (end <= eventOffset) { |
529 |
// position comes way before change - |
530 |
// leave alone |
531 |
} else if (offset <= eventOffset && end >= eventOffset + eventOldLength) { |
532 |
// event completely internal to the position - adjust length |
533 |
position.setLength(length + deltaLength); |
534 |
} else if (offset < eventOffset) { |
535 |
// event extends over end of position - adjust length |
536 |
int newEnd = eventOffset; |
537 |
position.setLength(newEnd - offset); |
538 |
} else if (end > eventOffset + eventOldLength) { |
539 |
// event extends from before position into it - adjust offset |
540 |
// and length |
541 |
// offset becomes end of event, length adjusted accordingly |
542 |
int newOffset = eventOffset + eventNewLength; |
543 |
position.setOffset(newOffset); |
544 |
position.setLength(end - newOffset); |
545 |
} else { |
546 |
// event consumes the position - delete it |
547 |
position.delete(); |
548 |
} |
549 |
} |
550 |
} catch (BadPositionCategoryException e) { |
551 |
// ignore and return |
552 |
} |
553 |
} |
554 |
|
555 |
/** |
556 |
* Returns the position category. |
557 |
* |
558 |
* @return the position category |
559 |
*/ |
560 |
public String getCategory() { |
561 |
return fCategory; |
562 |
} |
563 |
} |
564 |
|
565 |
private class BracketInserter implements VerifyKeyListener, ILinkedModeListener { |
566 |
|
567 |
private boolean fCloseBrackets = true; |
568 |
private boolean fCloseStrings = true; |
569 |
private boolean fCloseAngularBrackets = true; |
570 |
private final String CATEGORY = toString(); |
571 |
private IPositionUpdater fUpdater = new ExclusivePositionUpdater(CATEGORY); |
572 |
private Stack fBracketLevelStack = new Stack(); |
573 |
|
574 |
public void setCloseBracketsEnabled(boolean enabled) { |
575 |
fCloseBrackets = enabled; |
576 |
} |
577 |
|
578 |
public void setCloseStringsEnabled(boolean enabled) { |
579 |
fCloseStrings = enabled; |
580 |
} |
581 |
|
582 |
public void setCloseAngularBracketsEnabled(boolean enabled) { |
583 |
fCloseAngularBrackets = enabled; |
584 |
} |
585 |
|
586 |
private boolean isAngularIntroducer(String identifier) { |
587 |
return identifier.length() > 0 |
588 |
&& (Character.isUpperCase(identifier.charAt(0)) |
589 |
|| identifier.equals("template") //$NON-NLS-1$ |
590 |
|| identifier.equals("vector") //$NON-NLS-1$ |
591 |
|| identifier.equals("list") //$NON-NLS-1$ |
592 |
|| identifier.equals("slist") //$NON-NLS-1$ |
593 |
|| identifier.equals("map") //$NON-NLS-1$ |
594 |
|| identifier.equals("set") //$NON-NLS-1$ |
595 |
|| identifier.equals("multimap") //$NON-NLS-1$ |
596 |
|| identifier.equals("multiset") //$NON-NLS-1$ |
597 |
|| identifier.equals("hash_map") //$NON-NLS-1$ |
598 |
|| identifier.equals("hash_set") //$NON-NLS-1$ |
599 |
|| identifier.equals("hash_multimap") //$NON-NLS-1$ |
600 |
|| identifier.equals("hash_multiset") //$NON-NLS-1$ |
601 |
|| identifier.equals("pair") //$NON-NLS-1$ |
602 |
|| identifier.endsWith("_ptr") //$NON-NLS-1$ |
603 |
|| identifier.endsWith("include")); //$NON-NLS-1$ |
604 |
} |
605 |
|
606 |
/* |
607 |
* @see org.eclipse.swt.custom.VerifyKeyListener#verifyKey(org.eclipse.swt.events.VerifyEvent) |
608 |
*/ |
609 |
public void verifyKey(VerifyEvent event) { |
610 |
|
611 |
// early pruning to slow down normal typing as little as possible |
612 |
if (!event.doit || getInsertMode() != SMART_INSERT) |
613 |
return; |
614 |
switch (event.character) { |
615 |
case '(': |
616 |
case '<': |
617 |
case '[': |
618 |
case '\'': |
619 |
case '\"': |
620 |
break; |
621 |
default: |
622 |
return; |
623 |
} |
624 |
|
625 |
final ISourceViewer sourceViewer = getSourceViewer(); |
626 |
IDocument document = sourceViewer.getDocument(); |
627 |
|
628 |
final Point selection = sourceViewer.getSelectedRange(); |
629 |
final int offset = selection.x; |
630 |
final int length = selection.y; |
631 |
|
632 |
try { |
633 |
IRegion startLine = document.getLineInformationOfOffset(offset); |
634 |
IRegion endLine = document.getLineInformationOfOffset(offset + length); |
635 |
|
636 |
CHeuristicScanner scanner = new CHeuristicScanner(document); |
637 |
int nextToken = scanner.nextToken(offset + length, endLine.getOffset() + endLine.getLength()); |
638 |
String next = nextToken == Symbols.TokenEOF ? null : document.get(offset, scanner.getPosition() - offset).trim(); |
639 |
int prevToken = scanner.previousToken(offset - 1, startLine.getOffset()); |
640 |
int prevTokenOffset = scanner.getPosition() + 1; |
641 |
String previous = prevToken == Symbols.TokenEOF ? null : document.get(prevTokenOffset, offset - prevTokenOffset).trim(); |
642 |
|
643 |
switch (event.character) { |
644 |
case '(': |
645 |
if (!fCloseBrackets |
646 |
|| nextToken == Symbols.TokenLPAREN |
647 |
|| nextToken == Symbols.TokenIDENT |
648 |
|| next != null && next.length() > 1) |
649 |
return; |
650 |
break; |
651 |
|
652 |
case '<': |
653 |
if (!(fCloseAngularBrackets && fCloseBrackets) |
654 |
|| nextToken == Symbols.TokenLESSTHAN |
655 |
|| prevToken != Symbols.TokenLBRACE |
656 |
&& prevToken != Symbols.TokenRBRACE |
657 |
&& prevToken != Symbols.TokenSEMICOLON |
658 |
&& prevToken != Symbols.TokenSTATIC |
659 |
&& (prevToken != Symbols.TokenIDENT || !isAngularIntroducer(previous)) |
660 |
&& prevToken != Symbols.TokenEOF) |
661 |
return; |
662 |
break; |
663 |
|
664 |
case '[': |
665 |
if (!fCloseBrackets |
666 |
|| nextToken == Symbols.TokenIDENT |
667 |
|| next != null && next.length() > 1) |
668 |
return; |
669 |
break; |
670 |
|
671 |
case '\'': |
672 |
case '"': |
673 |
if (!fCloseStrings |
674 |
|| nextToken == Symbols.TokenIDENT |
675 |
|| next != null && next.length() > 1 |
676 |
|| (!("include".equals(previous) && event.character == '"') //$NON-NLS-1$ |
677 |
&& (prevToken == Symbols.TokenIDENT |
678 |
|| previous != null && previous.length() > 1))) |
679 |
return; |
680 |
break; |
681 |
|
682 |
default: |
683 |
return; |
684 |
} |
685 |
|
686 |
ITypedRegion partition = TextUtilities.getPartition(document, ICPartitions.C_PARTITIONING, offset, true); |
687 |
if (!IDocument.DEFAULT_CONTENT_TYPE.equals(partition.getType())) |
688 |
return; |
689 |
|
690 |
if (!validateEditorInputState()) |
691 |
return; |
692 |
|
693 |
final char character = event.character; |
694 |
final char closingCharacter = getPeerCharacter(character); |
695 |
final StringBuffer buffer = new StringBuffer(); |
696 |
buffer.append(character); |
697 |
buffer.append(closingCharacter); |
698 |
if (closingCharacter == '>' && nextToken != Symbols.TokenEOF |
699 |
&& document.getChar(offset + length) == '>') { |
700 |
// Insert a space to avoid two consequtive closing angular brackets. |
701 |
buffer.append(' '); |
702 |
} |
703 |
|
704 |
document.replace(offset, length, buffer.toString()); |
705 |
|
706 |
BracketLevel level = new BracketLevel(); |
707 |
fBracketLevelStack.push(level); |
708 |
|
709 |
LinkedPositionGroup group = new LinkedPositionGroup(); |
710 |
group.addPosition(new LinkedPosition(document, offset + 1, 0, LinkedPositionGroup.NO_STOP)); |
711 |
|
712 |
LinkedModeModel model = new LinkedModeModel(); |
713 |
model.addLinkingListener(this); |
714 |
model.addGroup(group); |
715 |
model.forceInstall(); |
716 |
|
717 |
level.fOffset = offset; |
718 |
level.fLength = 2; |
719 |
|
720 |
// set up position tracking for our magic peers |
721 |
if (fBracketLevelStack.size() == 1) { |
722 |
document.addPositionCategory(CATEGORY); |
723 |
document.addPositionUpdater(fUpdater); |
724 |
} |
725 |
level.fFirstPosition = new Position(offset, 1); |
726 |
level.fSecondPosition = new Position(offset + 1, 1); |
727 |
document.addPosition(CATEGORY, level.fFirstPosition); |
728 |
document.addPosition(CATEGORY, level.fSecondPosition); |
729 |
|
730 |
level.fUI = new EditorLinkedModeUI(model, sourceViewer); |
731 |
level.fUI.setSimpleMode(true); |
732 |
level.fUI.setExitPolicy(new ExitPolicy(closingCharacter, getEscapeCharacter(closingCharacter), fBracketLevelStack)); |
733 |
level.fUI.setExitPosition(sourceViewer, offset + 2, 0, Integer.MAX_VALUE); |
734 |
level.fUI.setCyclingMode(LinkedModeUI.CYCLE_NEVER); |
735 |
level.fUI.enter(); |
736 |
|
737 |
IRegion newSelection = level.fUI.getSelectedRegion(); |
738 |
sourceViewer.setSelectedRange(newSelection.getOffset(), newSelection.getLength()); |
739 |
|
740 |
event.doit = false; |
741 |
|
742 |
} catch (BadLocationException e) { |
743 |
CUIPlugin.getDefault().log(e); |
744 |
} catch (BadPositionCategoryException e) { |
745 |
CUIPlugin.getDefault().log(e); |
746 |
} |
747 |
} |
748 |
|
749 |
/* |
750 |
* @see org.eclipse.jface.text.link.ILinkedModeListener#left(org.eclipse.jface.text.link.LinkedModeModel, int) |
751 |
*/ |
752 |
public void left(LinkedModeModel environment, int flags) { |
753 |
|
754 |
final BracketLevel level = (BracketLevel) fBracketLevelStack.pop(); |
755 |
|
756 |
if (flags != ILinkedModeListener.EXTERNAL_MODIFICATION) |
757 |
return; |
758 |
|
759 |
// remove brackets |
760 |
final ISourceViewer sourceViewer = getSourceViewer(); |
761 |
final IDocument document = sourceViewer.getDocument(); |
762 |
if (document instanceof IDocumentExtension) { |
763 |
IDocumentExtension extension = (IDocumentExtension) document; |
764 |
extension.registerPostNotificationReplace(null, new IDocumentExtension.IReplace() { |
765 |
|
766 |
public void perform(IDocument d, IDocumentListener owner) { |
767 |
if ((level.fFirstPosition.isDeleted || level.fFirstPosition.length == 0) |
768 |
&& !level.fSecondPosition.isDeleted |
769 |
&& level.fSecondPosition.offset == level.fFirstPosition.offset) |
770 |
{ |
771 |
try { |
772 |
document.replace(level.fSecondPosition.offset, |
773 |
level.fSecondPosition.length, |
774 |
null); |
775 |
} catch (BadLocationException e) { |
776 |
CUIPlugin.getDefault().log(e); |
777 |
} |
778 |
} |
779 |
|
780 |
if (fBracketLevelStack.size() == 0) { |
781 |
document.removePositionUpdater(fUpdater); |
782 |
try { |
783 |
document.removePositionCategory(CATEGORY); |
784 |
} catch (BadPositionCategoryException e) { |
785 |
CUIPlugin.getDefault().log(e); |
786 |
} |
787 |
} |
788 |
} |
789 |
}); |
790 |
} |
791 |
} |
792 |
|
793 |
/* |
794 |
* @see org.eclipse.jface.text.link.ILinkedModeListener#suspend(org.eclipse.jface.text.link.LinkedModeModel) |
795 |
*/ |
796 |
public void suspend(LinkedModeModel environment) { |
797 |
} |
798 |
|
799 |
/* |
800 |
* @see org.eclipse.jface.text.link.ILinkedModeListener#resume(org.eclipse.jface.text.link.LinkedModeModel, int) |
801 |
*/ |
802 |
public void resume(LinkedModeModel environment, int flags) { |
803 |
} |
804 |
} |
805 |
|
176 |
/** |
806 |
/** |
177 |
* Updates the Java outline page selection and this editor's range indicator. |
807 |
* Updates the C outline page selection and this editor's range indicator. |
178 |
* |
808 |
* |
179 |
* @since 3.0 |
809 |
* @since 3.0 |
180 |
*/ |
810 |
*/ |
Lines 228-234
Link Here
|
228 |
/* |
858 |
/* |
229 |
* @see org.eclipse.jface.text.information.IInformationProviderExtension#getInformation2(org.eclipse.jface.text.ITextViewer, |
859 |
* @see org.eclipse.jface.text.information.IInformationProviderExtension#getInformation2(org.eclipse.jface.text.ITextViewer, |
230 |
* org.eclipse.jface.text.IRegion) |
860 |
* org.eclipse.jface.text.IRegion) |
231 |
* @since 3.2 |
|
|
232 |
*/ |
861 |
*/ |
233 |
public Object getInformation2(ITextViewer textViewer, IRegion subject) { |
862 |
public Object getInformation2(ITextViewer textViewer, IRegion subject) { |
234 |
return fHoverInfo; |
863 |
return fHoverInfo; |
Lines 491-2149
Link Here
|
491 |
} catch (IllegalArgumentException e) { |
1120 |
} catch (IllegalArgumentException e) { |
492 |
return -1; |
1121 |
return -1; |
493 |
} |
1122 |
} |
494 |
|
|
|
495 |
} |
1123 |
} |
496 |
} |
1124 |
} |
497 |
|
1125 |
|
498 |
/** |
1126 |
/** |
499 |
* The editor selection changed listener. |
1127 |
* Text navigation action to navigate to the next sub-word. |
500 |
* |
1128 |
* |
501 |
* @since 3.0 |
1129 |
* @since 4.0 |
502 |
*/ |
1130 |
*/ |
503 |
private EditorSelectionChangedListener fEditorSelectionChangedListener; |
1131 |
protected abstract class NextSubWordAction extends TextNavigationAction { |
504 |
|
|
|
505 |
|
1132 |
|
506 |
/** The outline page */ |
1133 |
protected CWordIterator fIterator = new CWordIterator(); |
507 |
protected CContentOutlinePage fOutlinePage; |
|
|
508 |
|
509 |
/** Search actions **/ |
510 |
private ActionGroup fSelectionSearchGroup; |
511 |
private ActionGroup fTextSearchGroup; |
512 |
private CRefactoringActionGroup fRefactoringActionGroup; |
513 |
|
514 |
/** Action which shows selected element in CView. */ |
515 |
private ShowInCViewAction fShowInCViewAction; |
516 |
|
517 |
/** Activity Listeners **/ |
518 |
protected ISelectionChangedListener fStatusLineClearer; |
519 |
protected ISelectionChangedListener fSelectionUpdateListener; |
520 |
|
521 |
/** Pairs of brackets, used to match. */ |
522 |
protected final static char[] BRACKETS = { '{', '}', '(', ')', '[', ']', '<', '>' }; |
523 |
|
524 |
/** Matches the brackets. */ |
525 |
protected CPairMatcher fBracketMatcher = new CPairMatcher(BRACKETS); |
526 |
|
527 |
/** The editor's tab converter */ |
528 |
private TabConverter fTabConverter; |
529 |
|
1134 |
|
530 |
/** Listener to annotation model changes that updates the error tick in the tab image */ |
1135 |
/** |
531 |
private CEditorErrorTickUpdater fCEditorErrorTickUpdater; |
1136 |
* Creates a new next sub-word action. |
|
|
1137 |
* |
1138 |
* @param code Action code for the default operation. Must be an action code from @see org.eclipse.swt.custom.ST. |
1139 |
*/ |
1140 |
protected NextSubWordAction(int code) { |
1141 |
super(getSourceViewer().getTextWidget(), code); |
1142 |
} |
532 |
|
1143 |
|
533 |
/** Preference key for sub-word navigation, aka smart caret positioning */ |
1144 |
/* |
534 |
public final static String SUB_WORD_NAVIGATION= "subWordNavigation"; //$NON-NLS-1$ |
1145 |
* @see org.eclipse.jface.action.IAction#run() |
535 |
/** Preference key for matching brackets */ |
1146 |
*/ |
536 |
public final static String MATCHING_BRACKETS = "matchingBrackets"; //$NON-NLS-1$ |
1147 |
public void run() { |
537 |
/** Preference key for matching brackets color */ |
1148 |
// Check whether sub word navigation is enabled. |
538 |
public final static String MATCHING_BRACKETS_COLOR = "matchingBracketsColor"; //$NON-NLS-1$ |
1149 |
final IPreferenceStore store = getPreferenceStore(); |
539 |
/** Preference key for inactive code painter enablement */ |
1150 |
if (!store.getBoolean(SUB_WORD_NAVIGATION)) { |
540 |
public static final String INACTIVE_CODE_ENABLE = "inactiveCodeEnable"; //$NON-NLS-1$ |
1151 |
super.run(); |
541 |
/** Preference key for inactive code painter color */ |
1152 |
return; |
542 |
public static final String INACTIVE_CODE_COLOR = "inactiveCodeColor"; //$NON-NLS-1$ |
1153 |
} |
543 |
/** Preference key for inserting spaces rather than tabs */ |
|
|
544 |
public final static String SPACES_FOR_TABS = "spacesForTabs"; //$NON-NLS-1$ |
545 |
|
1154 |
|
546 |
/** Preference key for compiler task tags */ |
1155 |
final ISourceViewer viewer = getSourceViewer(); |
547 |
private final static String TRANSLATION_TASK_TAGS= CCorePreferenceConstants.TRANSLATION_TASK_TAGS; |
1156 |
final IDocument document = viewer.getDocument(); |
|
|
1157 |
fIterator.setText((CharacterIterator) new DocumentCharacterIterator(document)); |
1158 |
int position = widgetOffset2ModelOffset(viewer, viewer.getTextWidget().getCaretOffset()); |
1159 |
if (position == -1) |
1160 |
return; |
548 |
|
1161 |
|
549 |
/** |
1162 |
int next = findNextPosition(position); |
550 |
* This editor's projection support |
1163 |
if (next != BreakIterator.DONE) { |
551 |
*/ |
1164 |
setCaretPosition(next); |
552 |
private ProjectionSupport fProjectionSupport; |
1165 |
getTextWidget().showSelection(); |
553 |
/** |
1166 |
fireSelectionChanged(); |
554 |
* This editor's projection model updater |
1167 |
} |
555 |
*/ |
1168 |
} |
556 |
private ICFoldingStructureProvider fProjectionModelUpdater; |
|
|
557 |
|
1169 |
|
558 |
/** |
1170 |
/** |
559 |
* The action group for folding. |
1171 |
* Finds the next position after the given position. |
560 |
*/ |
1172 |
* |
561 |
private FoldingActionGroup fFoldingGroup; |
1173 |
* @param position the current position |
|
|
1174 |
* @return the next position |
1175 |
*/ |
1176 |
protected int findNextPosition(int position) { |
1177 |
ISourceViewer viewer = getSourceViewer(); |
1178 |
int widget = -1; |
1179 |
while (position != BreakIterator.DONE && widget == -1) { // TODO: optimize |
1180 |
position = fIterator.following(position); |
1181 |
if (position != BreakIterator.DONE) |
1182 |
widget = modelOffset2WidgetOffset(viewer, position); |
1183 |
} |
1184 |
return position; |
1185 |
} |
562 |
|
1186 |
|
563 |
/** |
1187 |
/** |
564 |
* AST reconciling listeners. |
1188 |
* Sets the caret position to the sub-word boundary given with <code>position</code>. |
565 |
* @since 4.0 |
1189 |
* |
566 |
*/ |
1190 |
* @param position Position where the action should move the caret |
567 |
private ListenerList fReconcilingListeners= new ListenerList(ListenerList.IDENTITY); |
1191 |
*/ |
|
|
1192 |
protected abstract void setCaretPosition(int position); |
1193 |
} |
568 |
|
1194 |
|
569 |
/** |
1195 |
/** |
570 |
* Semantic highlighting manager |
1196 |
* Text navigation action to navigate to the next sub-word. |
|
|
1197 |
* |
571 |
* @since 4.0 |
1198 |
* @since 4.0 |
572 |
*/ |
1199 |
*/ |
573 |
private SemanticHighlightingManager fSemanticManager; |
1200 |
protected class NavigateNextSubWordAction extends NextSubWordAction { |
574 |
|
1201 |
|
|
|
1202 |
/** |
1203 |
* Creates a new navigate next sub-word action. |
1204 |
*/ |
1205 |
public NavigateNextSubWordAction() { |
1206 |
super(ST.WORD_NEXT); |
1207 |
} |
575 |
|
1208 |
|
576 |
/** |
1209 |
/* |
577 |
* Default constructor. |
1210 |
* @see org.eclipse.cdt.internal.ui.editor.CEditor.NextSubWordAction#setCaretPosition(int) |
578 |
*/ |
1211 |
*/ |
579 |
public CEditor() { |
1212 |
protected void setCaretPosition(final int position) { |
580 |
super(); |
1213 |
getTextWidget().setCaretOffset(modelOffset2WidgetOffset(getSourceViewer(), position)); |
|
|
1214 |
} |
581 |
} |
1215 |
} |
582 |
|
1216 |
|
583 |
/** |
1217 |
/** |
584 |
* @see org.eclipse.ui.texteditor.AbstractDecoratedTextEditor#initializeEditor() |
1218 |
* Text operation action to delete the next sub-word. |
|
|
1219 |
* |
1220 |
* @since 4.0 |
585 |
*/ |
1221 |
*/ |
586 |
protected void initializeEditor() { |
1222 |
protected class DeleteNextSubWordAction extends NextSubWordAction implements IUpdate { |
587 |
CTextTools textTools = CUIPlugin.getDefault().getTextTools(); |
|
|
588 |
setSourceViewerConfiguration(new CSourceViewerConfiguration(textTools, this)); |
589 |
setDocumentProvider(CUIPlugin.getDefault().getDocumentProvider()); |
590 |
|
591 |
setEditorContextMenuId("#CEditorContext"); //$NON-NLS-1$ |
592 |
setRulerContextMenuId("#CEditorRulerContext"); //$NON-NLS-1$ |
593 |
setOutlinerContextMenuId("#CEditorOutlinerContext"); //$NON-NLS-1$ |
594 |
|
1223 |
|
595 |
setPreferenceStore(CUIPlugin.getDefault().getCombinedPreferenceStore()); |
1224 |
/** |
596 |
fCEditorErrorTickUpdater = new CEditorErrorTickUpdater(this); |
1225 |
* Creates a new delete next sub-word action. |
597 |
} |
1226 |
*/ |
|
|
1227 |
public DeleteNextSubWordAction() { |
1228 |
super(ST.DELETE_WORD_NEXT); |
1229 |
} |
598 |
|
1230 |
|
599 |
/** |
1231 |
/* |
600 |
* @see org.eclipse.ui.texteditor.AbstractTextEditor#doSetInput(org.eclipse.ui.IEditorInput) |
1232 |
* @see org.eclipse.cdt.internal.ui.editor.CEditor.NextSubWordAction#setCaretPosition(int) |
601 |
*/ |
1233 |
*/ |
602 |
protected void doSetInput(IEditorInput input) throws CoreException { |
1234 |
protected void setCaretPosition(final int position) { |
603 |
super.doSetInput(input); |
1235 |
if (!validateEditorInputState()) |
604 |
setOutlinePageInput(fOutlinePage, input); |
1236 |
return; |
605 |
|
1237 |
|
606 |
if (fProjectionModelUpdater != null) { |
1238 |
final ISourceViewer viewer = getSourceViewer(); |
607 |
fProjectionModelUpdater.initialize(); |
1239 |
final int caret, length; |
|
|
1240 |
Point selection = viewer.getSelectedRange(); |
1241 |
if (selection.y != 0) { |
1242 |
caret = selection.x; |
1243 |
length = selection.y; |
1244 |
} else { |
1245 |
caret = widgetOffset2ModelOffset(viewer, viewer.getTextWidget().getCaretOffset()); |
1246 |
length = position - caret; |
1247 |
} |
1248 |
|
1249 |
try { |
1250 |
viewer.getDocument().replace(caret, length, ""); //$NON-NLS-1$ |
1251 |
} catch (BadLocationException exception) { |
1252 |
// Should not happen |
1253 |
} |
608 |
} |
1254 |
} |
609 |
if (fCEditorErrorTickUpdater != null) { |
1255 |
|
610 |
fCEditorErrorTickUpdater.updateEditorImage(getInputCElement()); |
1256 |
/* |
|
|
1257 |
* @see org.eclipse.cdt.internal.ui.editor.CEditor.NextSubWordAction#findNextPosition(int) |
1258 |
*/ |
1259 |
protected int findNextPosition(int position) { |
1260 |
return fIterator.following(position); |
611 |
} |
1261 |
} |
612 |
} |
|
|
613 |
|
1262 |
|
614 |
/** |
1263 |
/* |
615 |
* Update the title image. |
1264 |
* @see org.eclipse.ui.texteditor.IUpdate#update() |
616 |
* @param image Title image. |
1265 |
*/ |
617 |
*/ |
1266 |
public void update() { |
618 |
public void updatedTitleImage(Image image) { |
1267 |
setEnabled(isEditorInputModifiable()); |
619 |
setTitleImage(image); |
1268 |
} |
620 |
} |
1269 |
} |
621 |
|
1270 |
|
622 |
/** |
1271 |
/** |
623 |
* Returns the C element wrapped by this editors input. |
1272 |
* Text operation action to select the next sub-word. |
624 |
* |
1273 |
* |
625 |
* @return the C element wrapped by this editors input. |
1274 |
* @since 4.0 |
626 |
* @since 3.0 |
|
|
627 |
*/ |
1275 |
*/ |
628 |
public ICElement getInputCElement () { |
1276 |
protected class SelectNextSubWordAction extends NextSubWordAction { |
629 |
return CUIPlugin.getDefault().getWorkingCopyManager().getWorkingCopy(getEditorInput()); |
|
|
630 |
} |
631 |
|
1277 |
|
632 |
/** |
1278 |
/** |
633 |
* Gets the current IFile input. |
1279 |
* Creates a new select next sub-word action. |
634 |
* This method will be remove after cdt-3.0. |
1280 |
*/ |
635 |
* We can not guaranty that the input is an IFile, it may |
1281 |
public SelectNextSubWordAction() { |
636 |
* an external file. Clients should test for <code>null<code> or use getInputCElement() |
1282 |
super(ST.SELECT_WORD_NEXT); |
637 |
* @deprecated use <code>CEditor.getInputCElement()</code>. |
1283 |
} |
638 |
* @return IFile Input file or null if input is not and IFileEditorInput. |
1284 |
|
639 |
*/ |
1285 |
/* |
640 |
public IFile getInputFile() { |
1286 |
* @see org.eclipse.cdt.internal.ui.editor.CEditor.NextSubWordAction#setCaretPosition(int) |
641 |
IEditorInput editorInput = getEditorInput(); |
1287 |
*/ |
642 |
if (editorInput != null) { |
1288 |
protected void setCaretPosition(final int position) { |
643 |
if ((editorInput instanceof IFileEditorInput)) { |
1289 |
final ISourceViewer viewer = getSourceViewer(); |
644 |
return ((IFileEditorInput) editorInput).getFile(); |
1290 |
|
|
|
1291 |
final StyledText text = viewer.getTextWidget(); |
1292 |
if (text != null && !text.isDisposed()) { |
1293 |
|
1294 |
final Point selection = text.getSelection(); |
1295 |
final int caret = text.getCaretOffset(); |
1296 |
final int offset = modelOffset2WidgetOffset(viewer, position); |
1297 |
|
1298 |
if (caret == selection.x) |
1299 |
text.setSelectionRange(selection.y, offset - selection.y); |
1300 |
else |
1301 |
text.setSelectionRange(selection.x, offset - selection.x); |
645 |
} |
1302 |
} |
646 |
} |
1303 |
} |
647 |
return null; |
|
|
648 |
} |
1304 |
} |
649 |
|
1305 |
|
650 |
/** |
1306 |
/** |
651 |
* @see org.eclipse.ui.ISaveablePart#isSaveAsAllowed() |
1307 |
* Text navigation action to navigate to the previous sub-word. |
|
|
1308 |
* |
1309 |
* @since 4.0 |
652 |
*/ |
1310 |
*/ |
653 |
public boolean isSaveAsAllowed() { |
1311 |
protected abstract class PreviousSubWordAction extends TextNavigationAction { |
654 |
return true; |
|
|
655 |
} |
656 |
/** |
657 |
* Gets the outline page of the c-editor. |
658 |
* @return Outline page. |
659 |
*/ |
660 |
public CContentOutlinePage getOutlinePage() { |
661 |
if (fOutlinePage == null) { |
662 |
fOutlinePage = new CContentOutlinePage(this); |
663 |
fOutlinePage.addSelectionChangedListener(this); |
664 |
} |
665 |
setOutlinePageInput(fOutlinePage, getEditorInput()); |
666 |
return fOutlinePage; |
667 |
} |
668 |
|
1312 |
|
669 |
/** |
1313 |
protected CWordIterator fIterator = new CWordIterator(); |
670 |
* @see org.eclipse.core.runtime.IAdaptable#getAdapter(java.lang.Class) |
|
|
671 |
*/ |
672 |
public Object getAdapter(Class required) { |
673 |
if (IContentOutlinePage.class.equals(required)) { |
674 |
return getOutlinePage(); |
675 |
} |
676 |
if (required == IShowInTargetList.class) { |
677 |
return new IShowInTargetList() { |
678 |
public String[] getShowInTargetIds() { |
679 |
return new String[] { CUIPlugin.CVIEW_ID, IPageLayout.ID_OUTLINE, IPageLayout.ID_RES_NAV }; |
680 |
} |
681 |
|
1314 |
|
682 |
}; |
1315 |
/** |
683 |
} |
1316 |
* Creates a new previous sub-word action. |
684 |
if (ProjectionAnnotationModel.class.equals(required)) { |
1317 |
* |
685 |
if (fProjectionSupport != null) { |
1318 |
* @param code Action code for the default operation. Must be an action code from @see org.eclipse.swt.custom.ST. |
686 |
Object adapter= fProjectionSupport.getAdapter(getSourceViewer(), required); |
1319 |
*/ |
687 |
if (adapter != null) |
1320 |
protected PreviousSubWordAction(final int code) { |
688 |
return adapter; |
1321 |
super(getSourceViewer().getTextWidget(), code); |
689 |
} |
|
|
690 |
} |
1322 |
} |
691 |
return super.getAdapter(required); |
|
|
692 |
} |
693 |
/** |
694 |
* Handles a property change event describing a change |
695 |
* of the editor's preference store and updates the preference |
696 |
* related editor properties. |
697 |
* |
698 |
* @param event the property change event |
699 |
*/ |
700 |
protected void handlePreferenceStoreChanged(PropertyChangeEvent event) { |
701 |
CSourceViewer asv = (CSourceViewer) getSourceViewer(); |
702 |
|
703 |
try { |
704 |
if (asv != null) { |
705 |
|
706 |
String property = event.getProperty(); |
707 |
|
708 |
if (AbstractDecoratedTextEditorPreferenceConstants.EDITOR_TAB_WIDTH.equals(property)) { |
709 |
SourceViewerConfiguration configuration = getSourceViewerConfiguration(); |
710 |
String[] types = configuration.getConfiguredContentTypes(asv); |
711 |
for (int i = 0; i < types.length; i++) { |
712 |
asv.setIndentPrefixes(configuration.getIndentPrefixes(asv, types[i]), types[i]); |
713 |
} |
714 |
|
715 |
if (fTabConverter != null) { |
716 |
fTabConverter.setNumberOfSpacesPerTab(configuration.getTabWidth(asv)); |
717 |
} |
718 |
// the super class handles the reset of the tabsize. |
719 |
return; |
720 |
} |
721 |
|
722 |
if (SPACES_FOR_TABS.equals(property)) { |
723 |
if (isTabConversionEnabled()) |
724 |
startTabConversion(); |
725 |
else |
726 |
stopTabConversion(); |
727 |
return; |
728 |
} |
729 |
|
730 |
// Not implemented ... for the future. |
731 |
if (TRANSLATION_TASK_TAGS.equals(event.getProperty())) { |
732 |
ISourceViewer sourceViewer= getSourceViewer(); |
733 |
if (sourceViewer != null && affectsTextPresentation(event)) |
734 |
sourceViewer.invalidateTextPresentation(); |
735 |
} |
736 |
|
1323 |
|
737 |
if (PreferenceConstants.EDITOR_FOLDING_PROVIDER.equals(property)) { |
1324 |
/* |
738 |
if (fProjectionModelUpdater != null) { |
1325 |
* @see org.eclipse.jface.action.IAction#run() |
739 |
fProjectionModelUpdater.uninstall(); |
1326 |
*/ |
740 |
} |
1327 |
public void run() { |
741 |
// either freshly enabled or provider changed |
1328 |
// Check whether sub word navigation is enabled. |
742 |
fProjectionModelUpdater= CUIPlugin.getDefault().getFoldingStructureProviderRegistry().getCurrentFoldingProvider(); |
1329 |
final IPreferenceStore store = getPreferenceStore(); |
743 |
if (fProjectionModelUpdater != null) { |
1330 |
if (!store.getBoolean(SUB_WORD_NAVIGATION)) { |
744 |
fProjectionModelUpdater.install(this, asv); |
1331 |
super.run(); |
745 |
} |
1332 |
return; |
746 |
return; |
1333 |
} |
747 |
} |
|
|
748 |
|
1334 |
|
749 |
if (SemanticHighlightings.affectsEnablement(getPreferenceStore(), event)) { |
1335 |
final ISourceViewer viewer = getSourceViewer(); |
750 |
if (isSemanticHighlightingEnabled()) { |
1336 |
final IDocument document = viewer.getDocument(); |
751 |
installSemanticHighlighting(); |
1337 |
fIterator.setText((CharacterIterator) new DocumentCharacterIterator(document)); |
752 |
fSemanticManager.refresh(); |
1338 |
int position = widgetOffset2ModelOffset(viewer, viewer.getTextWidget().getCaretOffset()); |
753 |
} else { |
1339 |
if (position == -1) |
754 |
uninstallSemanticHighlighting(); |
1340 |
return; |
755 |
} |
|
|
756 |
return; |
757 |
} |
758 |
|
1341 |
|
759 |
IContentAssistant c= asv.getContentAssistant(); |
1342 |
int previous = findPreviousPosition(position); |
760 |
if (c instanceof ContentAssistant) { |
1343 |
if (previous != BreakIterator.DONE) { |
761 |
ContentAssistPreference.changeConfiguration((ContentAssistant) c, getPreferenceStore(), event); |
1344 |
setCaretPosition(previous); |
762 |
} |
1345 |
getTextWidget().showSelection(); |
763 |
|
1346 |
fireSelectionChanged(); |
764 |
} |
1347 |
} |
765 |
} finally { |
|
|
766 |
super.handlePreferenceStoreChanged(event); |
767 |
} |
1348 |
} |
768 |
} |
|
|
769 |
|
770 |
/** |
771 |
* React to changed selection. |
772 |
* |
773 |
* @since 3.0 |
774 |
*/ |
775 |
protected void selectionChanged() { |
776 |
if (getSelectionProvider() == null) |
777 |
return; |
778 |
updateStatusLine(); |
779 |
} |
780 |
|
1349 |
|
781 |
/** |
1350 |
/** |
782 |
* @see org.eclipse.jface.viewers.ISelectionChangedListener#selectionChanged(org.eclipse.jface.viewers.SelectionChangedEvent) |
1351 |
* Finds the previous position before the given position. |
783 |
*/ |
1352 |
* |
784 |
public void selectionChanged(SelectionChangedEvent event) { |
1353 |
* @param position the current position |
785 |
ISelection sel = event.getSelection(); |
1354 |
* @return the previous position |
786 |
if (sel instanceof IStructuredSelection) { |
1355 |
*/ |
787 |
IStructuredSelection selection = (IStructuredSelection) sel; |
1356 |
protected int findPreviousPosition(int position) { |
788 |
Object obj = selection.getFirstElement(); |
1357 |
ISourceViewer viewer = getSourceViewer(); |
789 |
if (obj instanceof ISourceReference) { |
1358 |
int widget = -1; |
790 |
try { |
1359 |
while (position != BreakIterator.DONE && widget == -1) { // TODO: optimize |
791 |
ISourceRange range = ((ISourceReference) obj).getSourceRange(); |
1360 |
position = fIterator.preceding(position); |
792 |
if (range != null) { |
1361 |
if (position != BreakIterator.DONE) |
793 |
setSelection(range, !isActivePart()); |
1362 |
widget = modelOffset2WidgetOffset(viewer, position); |
794 |
} |
|
|
795 |
} catch (CModelException e) { |
796 |
// Selection change not applied. |
797 |
} |
798 |
} |
1363 |
} |
|
|
1364 |
return position; |
799 |
} |
1365 |
} |
|
|
1366 |
|
1367 |
/** |
1368 |
* Sets the caret position to the sub-word boundary given with <code>position</code>. |
1369 |
* |
1370 |
* @param position Position where the action should move the caret |
1371 |
*/ |
1372 |
protected abstract void setCaretPosition(int position); |
800 |
} |
1373 |
} |
801 |
|
1374 |
|
802 |
/** |
1375 |
/** |
803 |
* Sets selection for C element. |
1376 |
* Text navigation action to navigate to the previous sub-word. |
804 |
* @param element Element to select. |
1377 |
* |
|
|
1378 |
* @since 4.0 |
805 |
*/ |
1379 |
*/ |
806 |
public void setSelection(ICElement element) { |
1380 |
protected class NavigatePreviousSubWordAction extends PreviousSubWordAction { |
807 |
|
1381 |
|
808 |
if (element == null || element instanceof ITranslationUnit) { |
1382 |
/** |
809 |
/* |
1383 |
* Creates a new navigate previous sub-word action. |
810 |
* If the element is an ITranslationUnit this unit is either the input |
1384 |
*/ |
811 |
* of this editor or not being displayed. In both cases, nothing should |
1385 |
public NavigatePreviousSubWordAction() { |
812 |
* happened. |
1386 |
super(ST.WORD_PREVIOUS); |
813 |
*/ |
|
|
814 |
return; |
815 |
} |
816 |
if (element instanceof ISourceReference) { |
817 |
ISourceReference reference = (ISourceReference) element; |
818 |
// set hightlight range |
819 |
setSelection(reference, true); |
820 |
} |
1387 |
} |
821 |
} |
|
|
822 |
|
823 |
/** |
824 |
* Sets selection for source reference. |
825 |
* @param element Source reference to set. |
826 |
* @param moveCursor Should cursor be moved. |
827 |
*/ |
828 |
public void setSelection(ISourceReference element, boolean moveCursor) { |
829 |
if (element != null) { |
830 |
StyledText textWidget= null; |
831 |
|
832 |
ISourceViewer sourceViewer= getSourceViewer(); |
833 |
if (sourceViewer != null) |
834 |
textWidget= sourceViewer.getTextWidget(); |
835 |
|
836 |
if (textWidget == null) |
837 |
return; |
838 |
|
1388 |
|
839 |
try { |
1389 |
/* |
840 |
setSelection(element.getSourceRange(), moveCursor); |
1390 |
* @see org.eclipse.cdt.internal.ui.editor.CEditor.PreviousSubWordAction#setCaretPosition(int) |
841 |
} catch (CModelException e) { |
1391 |
*/ |
842 |
// Selection not applied. |
1392 |
protected void setCaretPosition(final int position) { |
843 |
} |
1393 |
getTextWidget().setCaretOffset(modelOffset2WidgetOffset(getSourceViewer(), position)); |
844 |
} |
1394 |
} |
845 |
} |
1395 |
} |
846 |
|
1396 |
|
847 |
/** |
1397 |
/** |
848 |
* Sets the current editor selection to the source range. Optionally |
1398 |
* Text operation action to delete the previous sub-word. |
849 |
* sets the current editor position. |
|
|
850 |
* |
1399 |
* |
851 |
* @param element the source range to be shown in the editor, can be null. |
1400 |
* @since 4.0 |
852 |
* @param moveCursor if true the editor is scrolled to show the range. |
|
|
853 |
*/ |
1401 |
*/ |
854 |
public void setSelection(ISourceRange element, boolean moveCursor) { |
1402 |
protected class DeletePreviousSubWordAction extends PreviousSubWordAction implements IUpdate { |
855 |
|
1403 |
|
856 |
if (element == null) { |
1404 |
/** |
857 |
return; |
1405 |
* Creates a new delete previous sub-word action. |
|
|
1406 |
*/ |
1407 |
public DeletePreviousSubWordAction() { |
1408 |
super(ST.DELETE_WORD_PREVIOUS); |
858 |
} |
1409 |
} |
859 |
|
1410 |
|
860 |
try { |
1411 |
/* |
861 |
IRegion alternateRegion = null; |
1412 |
* @see org.eclipse.cdt.internal.ui.editor.CEditor.PreviousSubWordAction#setCaretPosition(int) |
862 |
int start = element.getStartPos(); |
1413 |
*/ |
863 |
int length = element.getLength(); |
1414 |
protected void setCaretPosition(int position) { |
|
|
1415 |
if (!validateEditorInputState()) |
1416 |
return; |
864 |
|
1417 |
|
865 |
// Sanity check sometimes the parser may throw wrong numbers. |
1418 |
final int length; |
866 |
if (start < 0 || length < 0) { |
1419 |
final ISourceViewer viewer = getSourceViewer(); |
867 |
start = 0; |
1420 |
Point selection = viewer.getSelectedRange(); |
868 |
length = 0; |
1421 |
if (selection.y != 0) { |
|
|
1422 |
position = selection.x; |
1423 |
length = selection.y; |
1424 |
} else { |
1425 |
length = widgetOffset2ModelOffset(viewer, viewer.getTextWidget().getCaretOffset()) - position; |
869 |
} |
1426 |
} |
870 |
|
1427 |
|
871 |
// 0 length and start and non-zero start line says we know |
1428 |
try { |
872 |
// the line for some reason, but not the offset. |
1429 |
viewer.getDocument().replace(position, length, ""); //$NON-NLS-1$ |
873 |
if (length == 0 && start == 0 && element.getStartLine() > 0) { |
1430 |
} catch (BadLocationException exception) { |
874 |
// We have the information in term of lines, we can work it out. |
1431 |
// Should not happen |
875 |
// Binary elements return the first executable statement so we have to substract -1 |
|
|
876 |
start = getDocumentProvider().getDocument(getEditorInput()).getLineOffset(element.getStartLine() - 1); |
877 |
if (element.getEndLine() > 0) { |
878 |
length = getDocumentProvider().getDocument(getEditorInput()).getLineOffset(element.getEndLine()) - start; |
879 |
} else { |
880 |
length = start; |
881 |
} |
882 |
// create an alternate region for the keyword highlight. |
883 |
alternateRegion = getDocumentProvider().getDocument(getEditorInput()).getLineInformation(element.getStartLine() - 1); |
884 |
if (start == length || length < 0) { |
885 |
if (alternateRegion != null) { |
886 |
start = alternateRegion.getOffset(); |
887 |
length = alternateRegion.getLength(); |
888 |
} |
889 |
} |
890 |
} |
1432 |
} |
891 |
setHighlightRange(start, length, moveCursor); |
1433 |
} |
892 |
|
1434 |
|
893 |
if (moveCursor) { |
1435 |
/* |
894 |
start = element.getIdStartPos(); |
1436 |
* @see org.eclipse.cdt.internal.ui.editor.CEditor.PreviousSubWordAction#findPreviousPosition(int) |
895 |
length = element.getIdLength(); |
1437 |
*/ |
896 |
if (start == 0 && length == 0 && alternateRegion != null) { |
1438 |
protected int findPreviousPosition(int position) { |
897 |
start = alternateRegion.getOffset(); |
1439 |
return fIterator.preceding(position); |
898 |
length = alternateRegion.getLength(); |
|
|
899 |
} |
900 |
if (start > -1 && getSourceViewer() != null) { |
901 |
getSourceViewer().revealRange(start, length); |
902 |
getSourceViewer().setSelectedRange(start, length); |
903 |
} |
904 |
updateStatusField(CTextEditorActionConstants.STATUS_CURSOR_POS); |
905 |
} |
906 |
return; |
907 |
} catch (IllegalArgumentException x) { |
908 |
// No information to the user |
909 |
} catch (BadLocationException e) { |
910 |
// No information to the user |
911 |
} |
1440 |
} |
912 |
|
1441 |
|
913 |
if (moveCursor) |
1442 |
/* |
914 |
resetHighlightRange(); |
1443 |
* @see org.eclipse.ui.texteditor.IUpdate#update() |
|
|
1444 |
*/ |
1445 |
public void update() { |
1446 |
setEnabled(isEditorInputModifiable()); |
1447 |
} |
915 |
} |
1448 |
} |
916 |
|
1449 |
|
917 |
/** |
1450 |
/** |
918 |
* Checks is the editor active part. |
1451 |
* Text operation action to select the previous sub-word. |
919 |
* @return <code>true</code> if editor is the active part of the workbench. |
1452 |
* |
|
|
1453 |
* @since 4.0 |
920 |
*/ |
1454 |
*/ |
921 |
private boolean isActivePart() { |
1455 |
protected class SelectPreviousSubWordAction extends PreviousSubWordAction { |
922 |
IWorkbenchWindow window = getSite().getWorkbenchWindow(); |
|
|
923 |
IPartService service = window.getPartService(); |
924 |
return (this == service.getActivePart()); |
925 |
} |
926 |
|
927 |
/** |
928 |
* @see org.eclipse.ui.IWorkbenchPart#dispose() |
929 |
*/ |
930 |
public void dispose() { |
931 |
|
1456 |
|
932 |
if (fProjectionModelUpdater != null) { |
1457 |
/** |
933 |
fProjectionModelUpdater.uninstall(); |
1458 |
* Creates a new select previous sub-word action. |
934 |
fProjectionModelUpdater= null; |
1459 |
*/ |
935 |
} |
1460 |
public SelectPreviousSubWordAction() { |
936 |
|
1461 |
super(ST.SELECT_WORD_PREVIOUS); |
937 |
if (fProjectionSupport != null) { |
|
|
938 |
fProjectionSupport.dispose(); |
939 |
fProjectionSupport= null; |
940 |
} |
1462 |
} |
941 |
|
1463 |
|
942 |
if (fCEditorErrorTickUpdater != null) { |
1464 |
/* |
943 |
fCEditorErrorTickUpdater.dispose(); |
1465 |
* @see org.eclipse.cdt.internal.ui.editor.CEditor.PreviousSubWordAction#setCaretPosition(int) |
944 |
fCEditorErrorTickUpdater = null; |
1466 |
*/ |
945 |
} |
1467 |
protected void setCaretPosition(final int position) { |
946 |
|
1468 |
final ISourceViewer viewer = getSourceViewer(); |
947 |
if (fSelectionUpdateListener != null) { |
|
|
948 |
getSelectionProvider().addSelectionChangedListener(fSelectionUpdateListener); |
949 |
fSelectionUpdateListener = null; |
950 |
} |
951 |
|
952 |
if (fStatusLineClearer != null) { |
953 |
ISelectionProvider provider = getSelectionProvider(); |
954 |
provider.removeSelectionChangedListener(fStatusLineClearer); |
955 |
fStatusLineClearer = null; |
956 |
} |
957 |
|
958 |
if (fBracketMatcher != null) { |
959 |
fBracketMatcher.dispose(); |
960 |
fBracketMatcher = null; |
961 |
} |
962 |
|
963 |
if (fOutlinePage != null) { |
964 |
fOutlinePage.dispose(); |
965 |
fOutlinePage = null; |
966 |
} |
967 |
|
968 |
if (fShowInCViewAction != null) { |
969 |
fShowInCViewAction.dispose(); |
970 |
fShowInCViewAction = null; |
971 |
} |
972 |
|
973 |
if (fSelectionSearchGroup != null) { |
974 |
fSelectionSearchGroup.dispose(); |
975 |
fSelectionSearchGroup = null; |
976 |
} |
977 |
|
1469 |
|
978 |
if (fTextSearchGroup != null) { |
1470 |
final StyledText text = viewer.getTextWidget(); |
979 |
fTextSearchGroup.dispose(); |
1471 |
if (text != null && !text.isDisposed()) { |
980 |
fTextSearchGroup = null; |
|
|
981 |
} |
982 |
|
1472 |
|
983 |
if (fRefactoringActionGroup != null) { |
1473 |
final Point selection = text.getSelection(); |
984 |
fRefactoringActionGroup.dispose(); |
1474 |
final int caret = text.getCaretOffset(); |
985 |
fRefactoringActionGroup = null; |
1475 |
final int offset = modelOffset2WidgetOffset(viewer, position); |
986 |
} |
|
|
987 |
|
1476 |
|
988 |
if (fEditorSelectionChangedListener != null) { |
1477 |
if (caret == selection.x) |
989 |
fEditorSelectionChangedListener.uninstall(getSelectionProvider()); |
1478 |
text.setSelectionRange(selection.y, offset - selection.y); |
990 |
fEditorSelectionChangedListener= null; |
1479 |
else |
|
|
1480 |
text.setSelectionRange(selection.x, offset - selection.x); |
1481 |
} |
991 |
} |
1482 |
} |
992 |
|
|
|
993 |
stopTabConversion(); |
994 |
|
995 |
super.dispose(); |
996 |
} |
1483 |
} |
|
|
1484 |
|
997 |
|
1485 |
|
998 |
/** |
1486 |
/** |
999 |
* @see org.eclipse.ui.texteditor.AbstractTextEditor#canHandleMove(org.eclipse.ui.IEditorInput, org.eclipse.ui.IEditorInput) |
1487 |
* The information provider used to present focusable information |
|
|
1488 |
* shells. |
1000 |
*/ |
1489 |
*/ |
1001 |
protected boolean canHandleMove(IEditorInput originalElement, IEditorInput movedElement) { |
1490 |
private InformationPresenter fInformationPresenter; |
1002 |
String oldLanguage = ""; //$NON-NLS-1$ |
1491 |
|
1003 |
if (originalElement instanceof IFileEditorInput) { |
|
|
1004 |
IFile file= ((IFileEditorInput) originalElement).getFile(); |
1005 |
if (file != null) { |
1006 |
IContentType type = CCorePlugin.getContentType(file.getProject(), file.getName()); |
1007 |
if (type != null) { |
1008 |
oldLanguage = type.getId(); |
1009 |
} |
1010 |
if (oldLanguage == null) { |
1011 |
return false; |
1012 |
} |
1013 |
} |
1014 |
} |
1015 |
|
1016 |
String newLanguage = ""; //$NON-NLS-1$ |
1017 |
if (movedElement instanceof IFileEditorInput) { |
1018 |
IFile file = ((IFileEditorInput) movedElement).getFile(); |
1019 |
if (file != null) { |
1020 |
IContentType type = CCorePlugin.getContentType(file.getProject(), file.getName()); |
1021 |
if (type != null) { |
1022 |
newLanguage = type.getId(); |
1023 |
} |
1024 |
if (newLanguage == null) { |
1025 |
return false; |
1026 |
} |
1027 |
} |
1028 |
} |
1029 |
return oldLanguage.equals(newLanguage); |
1030 |
} |
1031 |
|
1032 |
/** |
1492 |
/** |
1033 |
* @see org.eclipse.ui.texteditor.AbstractTextEditor#createActions() |
1493 |
* The editor selection changed listener. |
|
|
1494 |
* |
1495 |
* @since 3.0 |
1034 |
*/ |
1496 |
*/ |
1035 |
protected void createActions() { |
1497 |
private EditorSelectionChangedListener fEditorSelectionChangedListener; |
1036 |
super.createActions(); |
|
|
1037 |
|
1498 |
|
1038 |
fFoldingGroup= new FoldingActionGroup(this, getSourceViewer()); |
1499 |
/** The outline page */ |
|
|
1500 |
protected CContentOutlinePage fOutlinePage; |
1501 |
|
1502 |
/** Search actions **/ |
1503 |
private ActionGroup fSelectionSearchGroup; |
1504 |
private ActionGroup fTextSearchGroup; |
1505 |
private CRefactoringActionGroup fRefactoringActionGroup; |
1039 |
|
1506 |
|
1040 |
// Sticky hover support |
1507 |
/** Action which shows selected element in CView. */ |
1041 |
ResourceAction resAction= new TextOperationAction(CEditorMessages.getResourceBundle(), "ShowToolTip.", this, ISourceViewer.INFORMATION, true); //$NON-NLS-1$ |
1508 |
private ShowInCViewAction fShowInCViewAction; |
1042 |
ResourceAction resAction2= new InformationDispatchAction(CEditorMessages.getResourceBundle(), "ShowToolTip.", (TextOperationAction) resAction); //$NON-NLS-1$ |
1509 |
|
1043 |
resAction2.setActionDefinitionId(ICEditorActionDefinitionIds.SHOW_TOOLTIP); |
1510 |
/** Activity Listeners **/ |
1044 |
setAction("ShowToolTip", resAction2); //$NON-NLS-1$ |
1511 |
protected ISelectionChangedListener fStatusLineClearer; |
1045 |
PlatformUI.getWorkbench().getHelpSystem().setHelp(resAction2, ICHelpContextIds.SHOW_TOOLTIP_ACTION); |
1512 |
protected ISelectionChangedListener fSelectionUpdateListener; |
1046 |
|
1513 |
|
1047 |
// Default text editing menu items |
1514 |
/** Pairs of brackets, used to match. */ |
1048 |
Action action= new GotoMatchingBracketAction(this); |
1515 |
protected final static char[] BRACKETS = { '{', '}', '(', ')', '[', ']', '<', '>' }; |
1049 |
action.setActionDefinitionId(ICEditorActionDefinitionIds.GOTO_MATCHING_BRACKET); |
|
|
1050 |
setAction(GotoMatchingBracketAction.GOTO_MATCHING_BRACKET, action); |
1051 |
|
1052 |
action = new JoinLinesAction(CEditorMessages.getResourceBundle(), "JoinLines.", this); //$NON-NLS-1$ |
1053 |
action.setActionDefinitionId(ICEditorActionDefinitionIds.JOIN_LINES); |
1054 |
setAction("Join Lines", action); //$NON-NLS-1$ |
1055 |
|
1056 |
action= new ToggleCommentAction(CEditorMessages.getResourceBundle(), "ToggleComment.", this); //$NON-NLS-1$ |
1057 |
action.setActionDefinitionId(ICEditorActionDefinitionIds.TOGGLE_COMMENT); |
1058 |
setAction("ToggleComment", action); //$NON-NLS-1$ |
1059 |
markAsStateDependentAction("ToggleComment", true); //$NON-NLS-1$ |
1060 |
configureToggleCommentAction(); |
1061 |
|
1062 |
action= new AddBlockCommentAction(CEditorMessages.getResourceBundle(), "AddBlockComment.", this); //$NON-NLS-1$ |
1063 |
action.setActionDefinitionId(ICEditorActionDefinitionIds.ADD_BLOCK_COMMENT); |
1064 |
setAction("AddBlockComment", action); //$NON-NLS-1$ |
1065 |
markAsStateDependentAction("AddBlockComment", true); //$NON-NLS-1$ |
1066 |
markAsSelectionDependentAction("AddBlockComment", true); //$NON-NLS-1$ |
1067 |
//WorkbenchHelp.setHelp(action, ICHelpContextIds.ADD_BLOCK_COMMENT_ACTION); |
1068 |
|
1516 |
|
1069 |
action= new RemoveBlockCommentAction(CEditorMessages.getResourceBundle(), "RemoveBlockComment.", this); //$NON-NLS-1$ |
1517 |
/** Matches the brackets. */ |
1070 |
action.setActionDefinitionId(ICEditorActionDefinitionIds.REMOVE_BLOCK_COMMENT); |
1518 |
protected CPairMatcher fBracketMatcher = new CPairMatcher(BRACKETS); |
1071 |
setAction("RemoveBlockComment", action); //$NON-NLS-1$ |
|
|
1072 |
markAsStateDependentAction("RemoveBlockComment", true); //$NON-NLS-1$ |
1073 |
markAsSelectionDependentAction("RemoveBlockComment", true); //$NON-NLS-1$ |
1074 |
//WorkbenchHelp.setHelp(action, ICHelpContextIds.REMOVE_BLOCK_COMMENT_ACTION); |
1075 |
|
1519 |
|
1076 |
action = new TextOperationAction(CEditorMessages.getResourceBundle(), "Format.", this, ISourceViewer.FORMAT); //$NON-NLS-1$ |
1520 |
/** The bracket inserter. */ |
1077 |
action.setActionDefinitionId(ICEditorActionDefinitionIds.FORMAT); |
1521 |
private BracketInserter fBracketInserter = new BracketInserter(); |
1078 |
setAction("Format", action); //$NON-NLS-1$ |
|
|
1079 |
markAsStateDependentAction("Format", true); //$NON-NLS-1$ |
1080 |
|
1522 |
|
1081 |
action = new ContentAssistAction(CEditorMessages.getResourceBundle(), "ContentAssistProposal.", this); //$NON-NLS-1$ |
1523 |
/** The editor's tab converter */ |
1082 |
action.setActionDefinitionId(ITextEditorActionDefinitionIds.CONTENT_ASSIST_PROPOSALS); |
1524 |
private TabConverter fTabConverter; |
1083 |
setAction("ContentAssistProposal", action); //$NON-NLS-1$ |
|
|
1084 |
markAsStateDependentAction("ContentAssistProposal", true); //$NON-NLS-1$ |
1085 |
|
1525 |
|
1086 |
action = new TextOperationAction(CEditorMessages.getResourceBundle(), "ContentAssistTip.", this, ISourceViewer.CONTENTASSIST_CONTEXT_INFORMATION); //$NON-NLS-1$ |
1526 |
/** Listener to annotation model changes that updates the error tick in the tab image */ |
1087 |
action.setActionDefinitionId(ITextEditorActionDefinitionIds.CONTENT_ASSIST_CONTEXT_INFORMATION); |
1527 |
private CEditorErrorTickUpdater fCEditorErrorTickUpdater; |
1088 |
setAction("ContentAssistTip", action); //$NON-NLS-1$ |
|
|
1089 |
|
1528 |
|
1090 |
action = new AddIncludeOnSelectionAction(this); |
1529 |
/** Preference key for sub-word navigation, aka smart caret positioning */ |
1091 |
action.setActionDefinitionId(ICEditorActionDefinitionIds.ADD_INCLUDE); |
1530 |
public final static String SUB_WORD_NAVIGATION = "subWordNavigation"; //$NON-NLS-1$ |
1092 |
setAction("AddIncludeOnSelection", action); //$NON-NLS-1$ |
1531 |
/** Preference key for matching brackets */ |
1093 |
|
1532 |
public final static String MATCHING_BRACKETS = "matchingBrackets"; //$NON-NLS-1$ |
1094 |
action = new OpenDeclarationsAction(this); |
1533 |
/** Preference key for matching brackets color */ |
1095 |
action.setActionDefinitionId(ICEditorActionDefinitionIds.OPEN_DECL); |
1534 |
public final static String MATCHING_BRACKETS_COLOR = "matchingBracketsColor"; //$NON-NLS-1$ |
1096 |
setAction("OpenDeclarations", action); //$NON-NLS-1$ |
1535 |
/** Preference key for inactive code painter enablement */ |
1097 |
|
1536 |
public static final String INACTIVE_CODE_ENABLE = "inactiveCodeEnable"; //$NON-NLS-1$ |
1098 |
action = new OpenDefinitionAction(this); |
1537 |
/** Preference key for inactive code painter color */ |
1099 |
action.setActionDefinitionId(ICEditorActionDefinitionIds.OPEN_DEF); |
1538 |
public static final String INACTIVE_CODE_COLOR = "inactiveCodeColor"; //$NON-NLS-1$ |
1100 |
setAction("OpenDefinition", action); //$NON-NLS-1$ |
1539 |
/** Preference key for code formatter tab size */ |
1101 |
|
1540 |
private final static String CODE_FORMATTER_TAB_SIZE = DefaultCodeFormatterConstants.FORMATTER_TAB_SIZE; |
1102 |
// action = new OpenTypeHierarchyAction(this); |
1541 |
/** Preference key for inserting spaces rather than tabs */ |
1103 |
// action.setActionDefinitionId(ICEditorActionDefinitionIds.OPEN_TYPE_HIERARCHY); |
1542 |
public final static String SPACES_FOR_TABS = DefaultCodeFormatterConstants.FORMATTER_TAB_CHAR; |
1104 |
// setAction("OpenTypeHierarchy", action); //$NON-NLS-1$ |
1543 |
/** Preference key for automatically closing strings */ |
1105 |
|
1544 |
private final static String CLOSE_STRINGS = PreferenceConstants.EDITOR_CLOSE_STRINGS; |
1106 |
fShowInCViewAction = new ShowInCViewAction(this); |
1545 |
/** Preference key for automatically closing brackets and parenthesis */ |
1107 |
action = fShowInCViewAction; |
1546 |
private final static String CLOSE_BRACKETS = PreferenceConstants.EDITOR_CLOSE_BRACKETS; |
1108 |
action.setActionDefinitionId(ICEditorActionDefinitionIds.OPEN_CVIEW); |
1547 |
/** Preference key for automatically closing angular brackets */ |
1109 |
setAction("ShowInCView", action); //$NON-NLS-1$ |
1548 |
private final static String CLOSE_ANGULAR_BRACKETS = PreferenceConstants.EDITOR_CLOSE_ANGULAR_BRACKETS; |
1110 |
|
|
|
1111 |
action = new TextOperationAction(CEditorMessages.getResourceBundle(), "OpenOutline.", this, CSourceViewer.SHOW_OUTLINE, true); //$NON-NLS-1$ |
1112 |
action.setActionDefinitionId(ICEditorActionDefinitionIds.OPEN_OUTLINE); |
1113 |
setAction("OpenOutline", action); //$NON-NLS-1$*/ |
1114 |
|
1115 |
action = new GoToNextPreviousMemberAction(CEditorMessages.getResourceBundle(), "GotoNextMember.", this, true); //$NON-NLS-1$ |
1116 |
action.setActionDefinitionId(ICEditorActionDefinitionIds.GOTO_NEXT_MEMBER); |
1117 |
setAction("GotoNextMember", action); //$NON-NLS-1$*/ |
1118 |
|
1549 |
|
1119 |
action = new GoToNextPreviousMemberAction(CEditorMessages.getResourceBundle(), "GotoPrevMember.", this, false); //$NON-NLS-1$ |
1550 |
/** Preference key for compiler task tags */ |
1120 |
action.setActionDefinitionId(ICEditorActionDefinitionIds.GOTO_PREVIOUS_MEMBER); |
1551 |
private final static String TRANSLATION_TASK_TAGS = CCorePreferenceConstants.TRANSLATION_TASK_TAGS; |
1121 |
setAction("GotoPrevMember", action); //$NON-NLS-1$*/ |
|
|
1122 |
|
1552 |
|
1123 |
//Assorted action groupings |
1553 |
/** |
1124 |
fSelectionSearchGroup = new SelectionSearchGroup(this); |
1554 |
* This editor's projection support |
1125 |
fTextSearchGroup= new TextSearchGroup(this); |
1555 |
*/ |
1126 |
fRefactoringActionGroup= new CRefactoringActionGroup(this); |
1556 |
private ProjectionSupport fProjectionSupport; |
1127 |
} |
1557 |
/** |
|
|
1558 |
* This editor's projection model updater |
1559 |
*/ |
1560 |
private ICFoldingStructureProvider fProjectionModelUpdater; |
1128 |
|
1561 |
|
1129 |
/** |
1562 |
/** |
1130 |
* @see org.eclipse.ui.texteditor.AbstractTextEditor#editorContextMenuAboutToShow(org.eclipse.jface.action.IMenuManager) |
1563 |
* The action group for folding. |
1131 |
*/ |
1564 |
*/ |
1132 |
public void editorContextMenuAboutToShow(IMenuManager menu) { |
1565 |
private FoldingActionGroup fFoldingGroup; |
1133 |
super.editorContextMenuAboutToShow(menu); |
|
|
1134 |
|
1135 |
addGroup(menu, ITextEditorActionConstants.GROUP_EDIT, IContextMenuConstants.GROUP_REORGANIZE); |
1136 |
addGroup(menu, ITextEditorActionConstants.GROUP_EDIT, IContextMenuConstants.GROUP_GENERATE); |
1137 |
addGroup(menu, ITextEditorActionConstants.GROUP_EDIT, IContextMenuConstants.GROUP_NEW); |
1138 |
|
1139 |
// Code formatting menu items -- only show in C perspective |
1140 |
addAction(menu, ITextEditorActionConstants.GROUP_EDIT, "ToggleComment"); //$NON-NLS-1$ |
1141 |
addAction(menu, ITextEditorActionConstants.GROUP_EDIT, "AddBlockComment"); //$NON-NLS-1$ |
1142 |
addAction(menu, ITextEditorActionConstants.GROUP_EDIT, "RemoveBlockComment"); //$NON-NLS-1$ |
1143 |
|
1144 |
addAction(menu, ITextEditorActionConstants.GROUP_FIND, "OpenDeclarations"); //$NON-NLS-1$ |
1145 |
addAction(menu, ITextEditorActionConstants.GROUP_FIND, "OpenDefinition"); //$NON-NLS-1$ |
1146 |
|
1147 |
addAction(menu, ITextEditorActionConstants.GROUP_FIND, "OpenTypeHierarchy"); //$NON-NLS-1$ |
1148 |
addAction(menu, ITextEditorActionConstants.GROUP_FIND, "GotoNextMember"); //$NON-NLS-1$ |
1149 |
addAction(menu, ITextEditorActionConstants.GROUP_FIND, "GotoPrevMember"); //$NON-NLS-1$ |
1150 |
|
1151 |
addAction(menu, IContextMenuConstants.GROUP_GENERATE, "ContentAssistProposal"); //$NON-NLS-1$ |
1152 |
addAction(menu, IContextMenuConstants.GROUP_GENERATE, "AddIncludeOnSelection"); //$NON-NLS-1$ |
1153 |
addAction(menu, IContextMenuConstants.GROUP_GENERATE, "Format"); //$NON-NLS-1$ |
1154 |
|
1155 |
addAction(menu, IContextMenuConstants.GROUP_GENERATE, "ShowInCView"); //$NON-NLS-1$ |
1156 |
|
1157 |
fSelectionSearchGroup.fillContextMenu(menu); |
1158 |
fTextSearchGroup.fillContextMenu(menu); |
1159 |
fRefactoringActionGroup.fillContextMenu(menu); |
1160 |
} |
1161 |
|
1566 |
|
1162 |
/** |
1567 |
/** |
1163 |
* Sets an input for the outline page. |
1568 |
* AST reconciling listeners. |
1164 |
* @param page Page to set the input. |
1569 |
* @since 4.0 |
1165 |
* @param input Input to set. |
|
|
1166 |
*/ |
1570 |
*/ |
1167 |
public static void setOutlinePageInput(CContentOutlinePage page, IEditorInput input) { |
1571 |
private ListenerList fReconcilingListeners= new ListenerList(ListenerList.IDENTITY); |
1168 |
if (page != null) { |
|
|
1169 |
IWorkingCopyManager manager = CUIPlugin.getDefault().getWorkingCopyManager(); |
1170 |
page.setInput(manager.getWorkingCopy(input)); |
1171 |
} |
1172 |
} |
1173 |
|
1572 |
|
1174 |
/** |
1573 |
/** |
1175 |
* Determines is folding enabled. |
1574 |
* Semantic highlighting manager |
1176 |
* @return <code>true</code> if folding is enabled, <code>false</code> otherwise. |
1575 |
* @since 4.0 |
1177 |
*/ |
1576 |
*/ |
1178 |
boolean isFoldingEnabled() { |
1577 |
private SemanticHighlightingManager fSemanticManager; |
1179 |
return CUIPlugin.getDefault().getPreferenceStore().getBoolean(PreferenceConstants.EDITOR_FOLDING_ENABLED); |
|
|
1180 |
} |
1181 |
|
1578 |
|
1182 |
|
1579 |
|
1183 |
/** |
1580 |
/** |
1184 |
* The <code>AbstractTextEditor</code> implementation of this |
1581 |
* Default constructor. |
1185 |
* <code>IWorkbenchPart</code> method creates the vertical ruler and |
1582 |
*/ |
1186 |
* source viewer. Subclasses may extend. |
1583 |
public CEditor() { |
1187 |
* |
1584 |
super(); |
1188 |
* We attach our own mouseDown listener on the menu bar, |
1585 |
} |
1189 |
* and our own listener for cursor/key/selection events to update cursor position in |
|
|
1190 |
* status bar. |
1191 |
|
1586 |
|
1192 |
* @param parent Parent composite of the control. |
1587 |
/** |
|
|
1588 |
* @see org.eclipse.ui.texteditor.AbstractDecoratedTextEditor#initializeEditor() |
1193 |
*/ |
1589 |
*/ |
1194 |
public void createPartControl(Composite parent) { |
1590 |
protected void initializeEditor() { |
1195 |
super.createPartControl(parent); |
1591 |
CTextTools textTools = CUIPlugin.getDefault().getTextTools(); |
|
|
1592 |
setSourceViewerConfiguration(new CSourceViewerConfiguration(textTools, this)); |
1593 |
setDocumentProvider(CUIPlugin.getDefault().getDocumentProvider()); |
1196 |
|
1594 |
|
1197 |
// Sticky hover support |
1595 |
setEditorContextMenuId("#CEditorContext"); //$NON-NLS-1$ |
1198 |
IInformationControlCreator informationControlCreator = new IInformationControlCreator() { |
1596 |
setRulerContextMenuId("#CEditorRulerContext"); //$NON-NLS-1$ |
1199 |
public IInformationControl createInformationControl(Shell shell) { |
1597 |
setOutlinerContextMenuId("#CEditorOutlinerContext"); //$NON-NLS-1$ |
1200 |
boolean cutDown = false; |
|
|
1201 |
int style = cutDown ? SWT.NONE : (SWT.V_SCROLL | SWT.H_SCROLL); |
1202 |
return new DefaultInformationControl(shell, SWT.RESIZE |
1203 |
| SWT.TOOL, style, new HTMLTextPresenter(cutDown)); |
1204 |
} |
1205 |
}; |
1206 |
|
1207 |
fInformationPresenter = new InformationPresenter( |
1208 |
informationControlCreator); |
1209 |
fInformationPresenter.setSizeConstraints(60, 10, true, true); |
1210 |
fInformationPresenter.install(getSourceViewer()); |
1211 |
fInformationPresenter |
1212 |
.setDocumentPartitioning(ICPartitions.C_PARTITIONING); |
1213 |
|
1214 |
|
1215 |
ProjectionViewer projectionViewer= (ProjectionViewer) getSourceViewer(); |
1216 |
|
1217 |
fProjectionSupport= new ProjectionSupport(projectionViewer, getAnnotationAccess(), getSharedColors()); |
1218 |
fProjectionSupport.addSummarizableAnnotationType("org.eclipse.ui.workbench.texteditor.error"); //$NON-NLS-1$ |
1219 |
fProjectionSupport.addSummarizableAnnotationType("org.eclipse.ui.workbench.texteditor.warning"); //$NON-NLS-1$ |
1220 |
fProjectionSupport.install(); |
1221 |
|
1222 |
fProjectionModelUpdater= CUIPlugin.getDefault().getFoldingStructureProviderRegistry().getCurrentFoldingProvider(); |
1223 |
if (fProjectionModelUpdater != null) |
1224 |
fProjectionModelUpdater.install(this, projectionViewer); |
1225 |
|
1226 |
if (isFoldingEnabled()) |
1227 |
projectionViewer.doOperation(ProjectionViewer.TOGGLE); |
1228 |
|
1229 |
|
1230 |
PlatformUI.getWorkbench().getHelpSystem().setHelp(parent, ICHelpContextIds.CEDITOR_VIEW); |
1231 |
|
1232 |
fEditorSelectionChangedListener= new EditorSelectionChangedListener(); |
1233 |
fEditorSelectionChangedListener.install(getSelectionProvider()); |
1234 |
|
1235 |
|
1598 |
|
1236 |
if (isTabConversionEnabled()) |
1599 |
setPreferenceStore(CUIPlugin.getDefault().getCombinedPreferenceStore()); |
1237 |
startTabConversion(); |
1600 |
fCEditorErrorTickUpdater = new CEditorErrorTickUpdater(this); |
|
|
1601 |
} |
1238 |
|
1602 |
|
1239 |
if (isSemanticHighlightingEnabled()) |
1603 |
/** |
1240 |
installSemanticHighlighting(); |
1604 |
* @see org.eclipse.ui.texteditor.AbstractTextEditor#doSetInput(org.eclipse.ui.IEditorInput) |
|
|
1605 |
*/ |
1606 |
protected void doSetInput(IEditorInput input) throws CoreException { |
1607 |
super.doSetInput(input); |
1608 |
setOutlinePageInput(fOutlinePage, input); |
1241 |
|
1609 |
|
|
|
1610 |
if (fProjectionModelUpdater != null) { |
1611 |
fProjectionModelUpdater.initialize(); |
1612 |
} |
1613 |
if (fCEditorErrorTickUpdater != null) { |
1614 |
fCEditorErrorTickUpdater.updateEditorImage(getInputCElement()); |
1615 |
} |
1242 |
} |
1616 |
} |
1243 |
|
1617 |
|
1244 |
/* |
1618 |
/** |
1245 |
* @see org.eclipse.ui.texteditor.AbstractTextEditor#initializeDragAndDrop(org.eclipse.jface.text.source.ISourceViewer) |
1619 |
* Update the title image. |
|
|
1620 |
* @param image Title image. |
1246 |
*/ |
1621 |
*/ |
1247 |
protected void initializeDragAndDrop(ISourceViewer viewer) { |
1622 |
public void updatedTitleImage(Image image) { |
1248 |
Control control= viewer.getTextWidget(); |
1623 |
setTitleImage(image); |
1249 |
int operations= DND.DROP_MOVE | DND.DROP_COPY; |
1624 |
} |
1250 |
|
|
|
1251 |
DropTarget dropTarget= new DropTarget(control, operations); |
1252 |
ITextEditorDropTargetListener dropTargetListener= new TextEditorDropAdapter(viewer, this); |
1253 |
dropTarget.setTransfer(dropTargetListener.getTransfers()); |
1254 |
dropTarget.addDropListener(dropTargetListener); |
1255 |
|
1625 |
|
1256 |
DragSource dragSource= new DragSource(control, operations); |
1626 |
/** |
1257 |
Transfer[] dragTypes= new Transfer[] { TextTransfer.getInstance() }; |
1627 |
* Returns the C element wrapped by this editors input. |
1258 |
dragSource.setTransfer(dragTypes); |
1628 |
* |
1259 |
DragSourceListener dragSourceListener= new TextViewerDragAdapter(viewer, this); |
1629 |
* @return the C element wrapped by this editors input. |
1260 |
dragSource.addDragListener(dragSourceListener); |
1630 |
* @since 3.0 |
|
|
1631 |
*/ |
1632 |
public ICElement getInputCElement () { |
1633 |
return CUIPlugin.getDefault().getWorkingCopyManager().getWorkingCopy(getEditorInput()); |
1261 |
} |
1634 |
} |
1262 |
|
1635 |
|
1263 |
/* |
1636 |
/** |
1264 |
* @see org.eclipse.ui.texteditor.AbstractDecoratedTextEditor#getSourceViewerDecorationSupport(ISourceViewer) |
1637 |
* Gets the current IFile input. |
|
|
1638 |
* This method will be remove after cdt-3.0. |
1639 |
* We can not guaranty that the input is an IFile, it may |
1640 |
* an external file. Clients should test for <code>null<code> or use getInputCElement() |
1641 |
* @deprecated use <code>CEditor.getInputCElement()</code>. |
1642 |
* @return IFile Input file or null if input is not and IFileEditorInput. |
1265 |
*/ |
1643 |
*/ |
1266 |
protected SourceViewerDecorationSupport getSourceViewerDecorationSupport( |
1644 |
public IFile getInputFile() { |
1267 |
ISourceViewer viewer) { |
1645 |
IEditorInput editorInput = getEditorInput(); |
1268 |
if (fSourceViewerDecorationSupport == null) { |
1646 |
if (editorInput != null) { |
1269 |
fSourceViewerDecorationSupport= new CSourceViewerDecorationSupport(this, viewer, getOverviewRuler(), getAnnotationAccess(), getSharedColors()); |
1647 |
if ((editorInput instanceof IFileEditorInput)) { |
1270 |
configureSourceViewerDecorationSupport(fSourceViewerDecorationSupport); |
1648 |
return ((IFileEditorInput) editorInput).getFile(); |
|
|
1649 |
} |
1271 |
} |
1650 |
} |
1272 |
return fSourceViewerDecorationSupport; |
1651 |
return null; |
1273 |
} |
1652 |
} |
1274 |
|
1653 |
|
1275 |
/* |
1654 |
/** |
1276 |
* @see org.eclipse.ui.texteditor.AbstractDecoratedTextEditor#configureSourceViewerDecorationSupport(org.eclipse.ui.texteditor.SourceViewerDecorationSupport) |
1655 |
* @see org.eclipse.ui.ISaveablePart#isSaveAsAllowed() |
1277 |
*/ |
1656 |
*/ |
1278 |
protected void configureSourceViewerDecorationSupport(SourceViewerDecorationSupport support) { |
1657 |
public boolean isSaveAsAllowed() { |
1279 |
super.configureSourceViewerDecorationSupport(support); |
1658 |
return true; |
1280 |
//Enhance the stock source viewer decorator with a bracket matcher |
|
|
1281 |
support.setCharacterPairMatcher(fBracketMatcher); |
1282 |
support.setMatchingCharacterPainterPreferenceKeys(MATCHING_BRACKETS, MATCHING_BRACKETS_COLOR); |
1283 |
((CSourceViewerDecorationSupport)support).setInactiveCodePainterPreferenceKeys(INACTIVE_CODE_ENABLE, INACTIVE_CODE_COLOR); |
1284 |
} |
1659 |
} |
1285 |
|
|
|
1286 |
/** |
1660 |
/** |
1287 |
* Jumps to the matching bracket. |
1661 |
* Gets the outline page of the c-editor. |
|
|
1662 |
* @return Outline page. |
1288 |
*/ |
1663 |
*/ |
1289 |
public void gotoMatchingBracket() { |
1664 |
public CContentOutlinePage getOutlinePage() { |
1290 |
|
1665 |
if (fOutlinePage == null) { |
1291 |
ISourceViewer sourceViewer= getSourceViewer(); |
1666 |
fOutlinePage = new CContentOutlinePage(this); |
1292 |
IDocument document= sourceViewer.getDocument(); |
1667 |
fOutlinePage.addSelectionChangedListener(this); |
1293 |
if (document == null) |
|
|
1294 |
return; |
1295 |
|
1296 |
IRegion selection= getSignedSelection(sourceViewer); |
1297 |
|
1298 |
int selectionLength= Math.abs(selection.getLength()); |
1299 |
if (selectionLength > 1) { |
1300 |
setStatusLineErrorMessage(CEditorMessages.getString("GotoMatchingBracket.error.invalidSelection")); //$NON-NLS-1$ |
1301 |
sourceViewer.getTextWidget().getDisplay().beep(); |
1302 |
return; |
1303 |
} |
1668 |
} |
|
|
1669 |
setOutlinePageInput(fOutlinePage, getEditorInput()); |
1670 |
return fOutlinePage; |
1671 |
} |
1304 |
|
1672 |
|
1305 |
// #26314 |
1673 |
/** |
1306 |
int sourceCaretOffset= selection.getOffset() + selection.getLength(); |
1674 |
* @see org.eclipse.core.runtime.IAdaptable#getAdapter(java.lang.Class) |
1307 |
if (isSurroundedByBrackets(document, sourceCaretOffset)) |
1675 |
*/ |
1308 |
sourceCaretOffset -= selection.getLength(); |
1676 |
public Object getAdapter(Class required) { |
1309 |
|
1677 |
if (IContentOutlinePage.class.equals(required)) { |
1310 |
IRegion region= fBracketMatcher.match(document, sourceCaretOffset); |
1678 |
return getOutlinePage(); |
1311 |
if (region == null) { |
|
|
1312 |
setStatusLineErrorMessage(CEditorMessages.getString("GotoMatchingBracket.error.noMatchingBracket")); //$NON-NLS-1$ |
1313 |
sourceViewer.getTextWidget().getDisplay().beep(); |
1314 |
return; |
1315 |
} |
1679 |
} |
1316 |
|
1680 |
if (required == IShowInTargetList.class) { |
1317 |
int offset= region.getOffset(); |
1681 |
return new IShowInTargetList() { |
1318 |
int length= region.getLength(); |
1682 |
public String[] getShowInTargetIds() { |
1319 |
|
1683 |
return new String[] { CUIPlugin.CVIEW_ID, IPageLayout.ID_OUTLINE, IPageLayout.ID_RES_NAV }; |
1320 |
if (length < 1) |
1684 |
} |
1321 |
return; |
1685 |
|
1322 |
|
1686 |
}; |
1323 |
int anchor= fBracketMatcher.getAnchor(); |
|
|
1324 |
// http://dev.eclipse.org/bugs/show_bug.cgi?id=34195 |
1325 |
int targetOffset= (ICharacterPairMatcher.RIGHT == anchor) ? offset + 1: offset + length; |
1326 |
|
1327 |
boolean visible= false; |
1328 |
if (sourceViewer instanceof ITextViewerExtension5) { |
1329 |
ITextViewerExtension5 extension= (ITextViewerExtension5) sourceViewer; |
1330 |
visible= (extension.modelOffset2WidgetOffset(targetOffset) > -1); |
1331 |
} else { |
1332 |
IRegion visibleRegion= sourceViewer.getVisibleRegion(); |
1333 |
// http://dev.eclipse.org/bugs/show_bug.cgi?id=34195 |
1334 |
visible= (targetOffset >= visibleRegion.getOffset() && targetOffset <= visibleRegion.getOffset() + visibleRegion.getLength()); |
1335 |
} |
1687 |
} |
1336 |
|
1688 |
if (ProjectionAnnotationModel.class.equals(required)) { |
1337 |
if (!visible) { |
1689 |
if (fProjectionSupport != null) { |
1338 |
setStatusLineErrorMessage(CEditorMessages.getString("GotoMatchingBracket.error.bracketOutsideSelectedElement")); //$NON-NLS-1$ |
1690 |
Object adapter = fProjectionSupport.getAdapter(getSourceViewer(), required); |
1339 |
sourceViewer.getTextWidget().getDisplay().beep(); |
1691 |
if (adapter != null) |
1340 |
return; |
1692 |
return adapter; |
|
|
1693 |
} |
1341 |
} |
1694 |
} |
1342 |
|
1695 |
return super.getAdapter(required); |
1343 |
if (selection.getLength() < 0) |
|
|
1344 |
targetOffset -= selection.getLength(); |
1345 |
|
1346 |
sourceViewer.setSelectedRange(targetOffset, selection.getLength()); |
1347 |
sourceViewer.revealRange(targetOffset, selection.getLength()); |
1348 |
} |
1696 |
} |
|
|
1697 |
/** |
1698 |
* Handles a property change event describing a change |
1699 |
* of the editor's preference store and updates the preference |
1700 |
* related editor properties. |
1701 |
* |
1702 |
* @param event the property change event |
1703 |
*/ |
1704 |
protected void handlePreferenceStoreChanged(PropertyChangeEvent event) { |
1705 |
try { |
1706 |
AdaptedSourceViewer asv = (AdaptedSourceViewer) getSourceViewer(); |
1349 |
|
1707 |
|
1350 |
protected void updateStatusLine() { |
1708 |
if (asv != null) { |
1351 |
ITextSelection selection= (ITextSelection) getSelectionProvider().getSelection(); |
1709 |
String property = event.getProperty(); |
1352 |
Annotation annotation= getAnnotation(selection.getOffset(), selection.getLength()); |
1710 |
|
1353 |
setStatusLineErrorMessage(null); |
1711 |
if (CLOSE_BRACKETS.equals(property)) { |
1354 |
setStatusLineMessage(null); |
1712 |
fBracketInserter.setCloseBracketsEnabled(getPreferenceStore().getBoolean(property)); |
1355 |
if (annotation != null) { |
1713 |
return; |
1356 |
updateMarkerViews(annotation); |
1714 |
} |
1357 |
if (annotation instanceof ICAnnotation && ((ICAnnotation) annotation).isProblem()) |
1715 |
|
1358 |
setStatusLineMessage(annotation.getText()); |
1716 |
if (CLOSE_ANGULAR_BRACKETS.equals(property)) { |
|
|
1717 |
fBracketInserter.setCloseAngularBracketsEnabled(getPreferenceStore().getBoolean(property)); |
1718 |
return; |
1719 |
} |
1720 |
|
1721 |
if (CLOSE_STRINGS.equals(property)) { |
1722 |
fBracketInserter.setCloseStringsEnabled(getPreferenceStore().getBoolean(property)); |
1723 |
return; |
1724 |
} |
1725 |
|
1726 |
if (SPACES_FOR_TABS.equals(property)) { |
1727 |
if (isTabConversionEnabled()) |
1728 |
startTabConversion(); |
1729 |
else |
1730 |
stopTabConversion(); |
1731 |
return; |
1732 |
} |
1733 |
|
1734 |
if (PreferenceConstants.EDITOR_SMART_TAB.equals(property)) { |
1735 |
if (getPreferenceStore().getBoolean(PreferenceConstants.EDITOR_SMART_TAB)) { |
1736 |
setActionActivationCode("IndentOnTab", '\t', -1, SWT.NONE); //$NON-NLS-1$ |
1737 |
} else { |
1738 |
removeActionActivationCode("IndentOnTab"); //$NON-NLS-1$ |
1739 |
} |
1740 |
} |
1741 |
|
1742 |
if (CODE_FORMATTER_TAB_SIZE.equals(property)) { |
1743 |
asv.updateIndentationPrefixes(); |
1744 |
if (fTabConverter != null) |
1745 |
fTabConverter.setNumberOfSpacesPerTab(getTabSize()); |
1746 |
} |
1747 |
|
1748 |
// Not implemented ... for the future. |
1749 |
if (TRANSLATION_TASK_TAGS.equals(event.getProperty())) { |
1750 |
ISourceViewer sourceViewer = getSourceViewer(); |
1751 |
if (sourceViewer != null && affectsTextPresentation(event)) |
1752 |
sourceViewer.invalidateTextPresentation(); |
1753 |
} |
1754 |
|
1755 |
if (PreferenceConstants.EDITOR_FOLDING_PROVIDER.equals(property)) { |
1756 |
if (fProjectionModelUpdater != null) { |
1757 |
fProjectionModelUpdater.uninstall(); |
1758 |
} |
1759 |
// either freshly enabled or provider changed |
1760 |
fProjectionModelUpdater = CUIPlugin.getDefault().getFoldingStructureProviderRegistry().getCurrentFoldingProvider(); |
1761 |
if (fProjectionModelUpdater != null) { |
1762 |
fProjectionModelUpdater.install(this, asv); |
1763 |
} |
1764 |
return; |
1765 |
} |
1766 |
|
1767 |
if (SemanticHighlightings.affectsEnablement(getPreferenceStore(), event)) { |
1768 |
if (isSemanticHighlightingEnabled()) { |
1769 |
installSemanticHighlighting(); |
1770 |
fSemanticManager.refresh(); |
1771 |
} else { |
1772 |
uninstallSemanticHighlighting(); |
1773 |
} |
1774 |
return; |
1775 |
} |
1776 |
|
1777 |
IContentAssistant c = asv.getContentAssistant(); |
1778 |
if (c instanceof ContentAssistant) { |
1779 |
ContentAssistPreference.changeConfiguration((ContentAssistant) c, getPreferenceStore(), event); |
1780 |
} |
1781 |
} |
1782 |
} finally { |
1783 |
super.handlePreferenceStoreChanged(event); |
1359 |
} |
1784 |
} |
1360 |
} |
1785 |
} |
1361 |
|
1786 |
|
1362 |
/** |
1787 |
/** |
1363 |
* Returns the annotation overlapping with the given range or <code>null</code>. |
1788 |
* React to changed selection. |
1364 |
* |
1789 |
* |
1365 |
* @param offset the region offset |
|
|
1366 |
* @param length the region length |
1367 |
* @return the found annotation or <code>null</code> |
1368 |
* @since 3.0 |
1790 |
* @since 3.0 |
1369 |
*/ |
1791 |
*/ |
1370 |
private Annotation getAnnotation(int offset, int length) { |
1792 |
protected void selectionChanged() { |
1371 |
IAnnotationModel model= getDocumentProvider().getAnnotationModel(getEditorInput()); |
1793 |
if (getSelectionProvider() == null) |
1372 |
Iterator e= new CAnnotationIterator(model, true, true); |
1794 |
return; |
1373 |
while (e.hasNext()) { |
1795 |
updateStatusLine(); |
1374 |
Annotation a= (Annotation) e.next(); |
|
|
1375 |
if (!isNavigationTarget(a)) |
1376 |
continue; |
1377 |
|
1378 |
Position p= model.getPosition(a); |
1379 |
if (p != null && p.overlapsWith(offset, length)) |
1380 |
return a; |
1381 |
} |
1382 |
|
1383 |
return null; |
1384 |
} |
1385 |
/* (non-Javadoc) |
1386 |
* @see org.eclipse.ui.part.IShowInSource#getShowInContext() |
1387 |
* |
1388 |
* This is required by the IShowInSource interface for the "ShowIn" |
1389 |
* navigation menu generalized in Eclipse. |
1390 |
*/ |
1391 |
public ShowInContext getShowInContext() { |
1392 |
return new ShowInContext( getEditorInput(), null ); |
1393 |
} |
1796 |
} |
1394 |
|
1797 |
|
1395 |
/* |
1798 |
/** |
1396 |
* Get the dektop's StatusLineManager |
1799 |
* @see org.eclipse.jface.viewers.ISelectionChangedListener#selectionChanged(org.eclipse.jface.viewers.SelectionChangedEvent) |
1397 |
*/ |
1800 |
*/ |
1398 |
protected IStatusLineManager getStatusLineManager() { |
1801 |
public void selectionChanged(SelectionChangedEvent event) { |
1399 |
IEditorActionBarContributor contributor = getEditorSite().getActionBarContributor(); |
1802 |
ISelection sel = event.getSelection(); |
1400 |
if (contributor instanceof EditorActionBarContributor) { |
1803 |
if (sel instanceof IStructuredSelection) { |
1401 |
return ((EditorActionBarContributor) contributor).getActionBars().getStatusLineManager(); |
1804 |
IStructuredSelection selection = (IStructuredSelection) sel; |
|
|
1805 |
Object obj = selection.getFirstElement(); |
1806 |
if (obj instanceof ISourceReference) { |
1807 |
try { |
1808 |
ISourceRange range = ((ISourceReference) obj).getSourceRange(); |
1809 |
if (range != null) { |
1810 |
setSelection(range, !isActivePart()); |
1811 |
} |
1812 |
} catch (CModelException e) { |
1813 |
// Selection change not applied. |
1814 |
} |
1815 |
} |
1402 |
} |
1816 |
} |
1403 |
return null; |
|
|
1404 |
} |
1817 |
} |
1405 |
|
1818 |
|
1406 |
/** |
1819 |
/** |
1407 |
* Configures the toggle comment action |
1820 |
* Sets selection for C element. |
1408 |
* |
1821 |
* @param element Element to select. |
1409 |
* @since 4.0.0 |
|
|
1410 |
*/ |
1822 |
*/ |
1411 |
private void configureToggleCommentAction() { |
1823 |
public void setSelection(ICElement element) { |
1412 |
IAction action= getAction("ToggleComment"); //$NON-NLS-1$ |
|
|
1413 |
if (action instanceof ToggleCommentAction) { |
1414 |
ISourceViewer sourceViewer= getSourceViewer(); |
1415 |
SourceViewerConfiguration configuration= getSourceViewerConfiguration(); |
1416 |
((ToggleCommentAction)action).configure(sourceViewer, configuration); |
1417 |
} |
1418 |
} |
1419 |
|
1824 |
|
1420 |
private void configureTabConverter() { |
1825 |
if (element == null || element instanceof ITranslationUnit) { |
1421 |
if (fTabConverter != null) { |
1826 |
/* |
1422 |
IDocumentProvider provider= getDocumentProvider(); |
1827 |
* If the element is an ITranslationUnit this unit is either the input |
1423 |
if (provider instanceof CDocumentProvider) { |
1828 |
* of this editor or not being displayed. In both cases, nothing should |
1424 |
CDocumentProvider prov= (CDocumentProvider) provider; |
1829 |
* happened. |
1425 |
fTabConverter.setLineTracker(prov.createLineTracker(getEditorInput())); |
1830 |
*/ |
1426 |
} else { |
1831 |
return; |
1427 |
fTabConverter.setLineTracker(new DefaultLineTracker()); |
|
|
1428 |
} |
1429 |
} |
1832 |
} |
1430 |
} |
1833 |
if (element instanceof ISourceReference) { |
1431 |
|
1834 |
ISourceReference reference = (ISourceReference) element; |
1432 |
private void startTabConversion() { |
1835 |
// set hightlight range |
1433 |
if (fTabConverter == null) { |
1836 |
setSelection(reference, true); |
1434 |
CSourceViewer asv = (CSourceViewer) getSourceViewer(); |
|
|
1435 |
SourceViewerConfiguration configuration = getSourceViewerConfiguration(); |
1436 |
fTabConverter = new TabConverter(); |
1437 |
configureTabConverter(); |
1438 |
fTabConverter.setNumberOfSpacesPerTab(configuration.getTabWidth(asv)); |
1439 |
asv.addTextConverter(fTabConverter); |
1440 |
} |
1837 |
} |
1441 |
} |
1838 |
} |
1442 |
|
1839 |
|
1443 |
private void stopTabConversion() { |
1840 |
/** |
1444 |
if (fTabConverter != null) { |
1841 |
* Sets selection for source reference. |
1445 |
CSourceViewer asv = (CSourceViewer) getSourceViewer(); |
1842 |
* @param element Source reference to set. |
1446 |
asv.removeTextConverter(fTabConverter); |
1843 |
* @param moveCursor Should cursor be moved. |
1447 |
fTabConverter = null; |
1844 |
*/ |
1448 |
} |
1845 |
public void setSelection(ISourceReference element, boolean moveCursor) { |
1449 |
} |
1846 |
if (element != null) { |
|
|
1847 |
StyledText textWidget = null; |
1848 |
|
1849 |
ISourceViewer sourceViewer = getSourceViewer(); |
1850 |
if (sourceViewer != null) |
1851 |
textWidget = sourceViewer.getTextWidget(); |
1852 |
|
1853 |
if (textWidget == null) |
1854 |
return; |
1450 |
|
1855 |
|
1451 |
private boolean isTabConversionEnabled() { |
1856 |
try { |
1452 |
IPreferenceStore store = getPreferenceStore(); |
1857 |
setSelection(element.getSourceRange(), moveCursor); |
1453 |
return store.getBoolean(SPACES_FOR_TABS); |
1858 |
} catch (CModelException e) { |
|
|
1859 |
// Selection not applied. |
1860 |
} |
1861 |
} |
1454 |
} |
1862 |
} |
1455 |
|
1863 |
|
1456 |
/* |
1864 |
/** |
1457 |
* @see org.eclipse.ui.texteditor.AbstractTextEditor#createNavigationActions() |
1865 |
* Sets the current editor selection to the source range. Optionally |
|
|
1866 |
* sets the current editor position. |
1867 |
* |
1868 |
* @param element the source range to be shown in the editor, can be null. |
1869 |
* @param moveCursor if true the editor is scrolled to show the range. |
1458 |
*/ |
1870 |
*/ |
1459 |
protected void createNavigationActions() { |
1871 |
public void setSelection(ISourceRange element, boolean moveCursor) { |
1460 |
super.createNavigationActions(); |
|
|
1461 |
|
1872 |
|
1462 |
final StyledText textWidget = getSourceViewer().getTextWidget(); |
1873 |
if (element == null) { |
|
|
1874 |
return; |
1875 |
} |
1463 |
|
1876 |
|
1464 |
IAction action = new NavigatePreviousSubWordAction(); |
1877 |
try { |
1465 |
action.setActionDefinitionId(ITextEditorActionDefinitionIds.WORD_PREVIOUS); |
1878 |
IRegion alternateRegion = null; |
1466 |
setAction(ITextEditorActionDefinitionIds.WORD_PREVIOUS, action); |
1879 |
int start = element.getStartPos(); |
1467 |
textWidget.setKeyBinding(SWT.CTRL | SWT.ARROW_LEFT, SWT.NULL); |
1880 |
int length = element.getLength(); |
1468 |
|
1881 |
|
1469 |
action = new NavigateNextSubWordAction(); |
1882 |
// Sanity check sometimes the parser may throw wrong numbers. |
1470 |
action.setActionDefinitionId(ITextEditorActionDefinitionIds.WORD_NEXT); |
1883 |
if (start < 0 || length < 0) { |
1471 |
setAction(ITextEditorActionDefinitionIds.WORD_NEXT, action); |
1884 |
start = 0; |
1472 |
textWidget.setKeyBinding(SWT.CTRL | SWT.ARROW_RIGHT, SWT.NULL); |
1885 |
length = 0; |
|
|
1886 |
} |
1473 |
|
1887 |
|
1474 |
action = new SelectPreviousSubWordAction(); |
1888 |
// 0 length and start and non-zero start line says we know |
1475 |
action.setActionDefinitionId(ITextEditorActionDefinitionIds.SELECT_WORD_PREVIOUS); |
1889 |
// the line for some reason, but not the offset. |
1476 |
setAction(ITextEditorActionDefinitionIds.SELECT_WORD_PREVIOUS, action); |
1890 |
if (length == 0 && start == 0 && element.getStartLine() > 0) { |
1477 |
textWidget.setKeyBinding(SWT.CTRL | SWT.SHIFT | SWT.ARROW_LEFT, SWT.NULL); |
1891 |
// We have the information in term of lines, we can work it out. |
|
|
1892 |
// Binary elements return the first executable statement so we have to substract -1 |
1893 |
start = getDocumentProvider().getDocument(getEditorInput()).getLineOffset(element.getStartLine() - 1); |
1894 |
if (element.getEndLine() > 0) { |
1895 |
length = getDocumentProvider().getDocument(getEditorInput()).getLineOffset(element.getEndLine()) - start; |
1896 |
} else { |
1897 |
length = start; |
1898 |
} |
1899 |
// create an alternate region for the keyword highlight. |
1900 |
alternateRegion = getDocumentProvider().getDocument(getEditorInput()).getLineInformation(element.getStartLine() - 1); |
1901 |
if (start == length || length < 0) { |
1902 |
if (alternateRegion != null) { |
1903 |
start = alternateRegion.getOffset(); |
1904 |
length = alternateRegion.getLength(); |
1905 |
} |
1906 |
} |
1907 |
} |
1908 |
setHighlightRange(start, length, moveCursor); |
1478 |
|
1909 |
|
1479 |
action = new SelectNextSubWordAction(); |
1910 |
if (moveCursor) { |
1480 |
action.setActionDefinitionId(ITextEditorActionDefinitionIds.SELECT_WORD_NEXT); |
1911 |
start = element.getIdStartPos(); |
1481 |
setAction(ITextEditorActionDefinitionIds.SELECT_WORD_NEXT, action); |
1912 |
length = element.getIdLength(); |
1482 |
textWidget.setKeyBinding(SWT.CTRL | SWT.SHIFT | SWT.ARROW_RIGHT, SWT.NULL); |
1913 |
if (start == 0 && length == 0 && alternateRegion != null) { |
1483 |
|
1914 |
start = alternateRegion.getOffset(); |
1484 |
action= new DeletePreviousSubWordAction(); |
1915 |
length = alternateRegion.getLength(); |
1485 |
action.setActionDefinitionId(ITextEditorActionDefinitionIds.DELETE_PREVIOUS_WORD); |
1916 |
} |
1486 |
setAction(ITextEditorActionDefinitionIds.DELETE_PREVIOUS_WORD, action); |
1917 |
if (start > -1 && getSourceViewer() != null) { |
1487 |
textWidget.setKeyBinding(SWT.CTRL | SWT.BS, SWT.NULL); |
1918 |
getSourceViewer().revealRange(start, length); |
1488 |
markAsStateDependentAction(ITextEditorActionDefinitionIds.DELETE_PREVIOUS_WORD, true); |
1919 |
getSourceViewer().setSelectedRange(start, length); |
|
|
1920 |
} |
1921 |
updateStatusField(CTextEditorActionConstants.STATUS_CURSOR_POS); |
1922 |
} |
1923 |
return; |
1924 |
} catch (IllegalArgumentException x) { |
1925 |
// No information to the user |
1926 |
} catch (BadLocationException e) { |
1927 |
// No information to the user |
1928 |
} |
1489 |
|
1929 |
|
1490 |
action= new DeleteNextSubWordAction(); |
1930 |
if (moveCursor) |
1491 |
action.setActionDefinitionId(ITextEditorActionDefinitionIds.DELETE_NEXT_WORD); |
1931 |
resetHighlightRange(); |
1492 |
setAction(ITextEditorActionDefinitionIds.DELETE_NEXT_WORD, action); |
|
|
1493 |
textWidget.setKeyBinding(SWT.CTRL | SWT.DEL, SWT.NULL); |
1494 |
markAsStateDependentAction(ITextEditorActionDefinitionIds.DELETE_NEXT_WORD, true); |
1495 |
} |
1932 |
} |
1496 |
|
1933 |
|
1497 |
interface ITextConverter { |
1934 |
/** |
1498 |
void customizeDocumentCommand(IDocument document, DocumentCommand command); |
1935 |
* Checks is the editor active part. |
|
|
1936 |
* @return <code>true</code> if editor is the active part of the workbench. |
1937 |
*/ |
1938 |
private boolean isActivePart() { |
1939 |
IWorkbenchWindow window = getSite().getWorkbenchWindow(); |
1940 |
IPartService service = window.getPartService(); |
1941 |
return (this == service.getActivePart()); |
1499 |
} |
1942 |
} |
1500 |
|
1943 |
|
1501 |
static class TabConverter implements ITextConverter { |
1944 |
/** |
1502 |
private int fTabRatio; |
1945 |
* @see org.eclipse.ui.IWorkbenchPart#dispose() |
1503 |
private ILineTracker fLineTracker; |
1946 |
*/ |
|
|
1947 |
public void dispose() { |
1948 |
|
1949 |
ISourceViewer sourceViewer = getSourceViewer(); |
1950 |
if (sourceViewer instanceof ITextViewerExtension) |
1951 |
((ITextViewerExtension) sourceViewer).removeVerifyKeyListener(fBracketInserter); |
1952 |
|
1953 |
if (fProjectionModelUpdater != null) { |
1954 |
fProjectionModelUpdater.uninstall(); |
1955 |
fProjectionModelUpdater = null; |
1956 |
} |
1504 |
|
1957 |
|
1505 |
public TabConverter() { |
1958 |
if (fProjectionSupport != null) { |
1506 |
} |
1959 |
fProjectionSupport.dispose(); |
|
|
1960 |
fProjectionSupport = null; |
1961 |
} |
1962 |
|
1963 |
if (fCEditorErrorTickUpdater != null) { |
1964 |
fCEditorErrorTickUpdater.dispose(); |
1965 |
fCEditorErrorTickUpdater = null; |
1966 |
} |
1507 |
|
1967 |
|
1508 |
public void setNumberOfSpacesPerTab(int ratio) { |
1968 |
if (fSelectionUpdateListener != null) { |
1509 |
fTabRatio= ratio; |
1969 |
getSelectionProvider().addSelectionChangedListener(fSelectionUpdateListener); |
|
|
1970 |
fSelectionUpdateListener = null; |
1971 |
} |
1972 |
|
1973 |
if (fStatusLineClearer != null) { |
1974 |
ISelectionProvider provider = getSelectionProvider(); |
1975 |
provider.removeSelectionChangedListener(fStatusLineClearer); |
1976 |
fStatusLineClearer = null; |
1977 |
} |
1978 |
|
1979 |
if (fBracketMatcher != null) { |
1980 |
fBracketMatcher.dispose(); |
1981 |
fBracketMatcher = null; |
1510 |
} |
1982 |
} |
1511 |
|
1983 |
|
1512 |
public void setLineTracker(ILineTracker lineTracker) { |
1984 |
if (fOutlinePage != null) { |
1513 |
fLineTracker= lineTracker; |
1985 |
fOutlinePage.dispose(); |
|
|
1986 |
fOutlinePage = null; |
1514 |
} |
1987 |
} |
1515 |
|
1988 |
|
1516 |
private int insertTabString(StringBuffer buffer, int offsetInLine) { |
1989 |
if (fShowInCViewAction != null) { |
1517 |
|
1990 |
fShowInCViewAction.dispose(); |
1518 |
if (fTabRatio == 0) |
1991 |
fShowInCViewAction = null; |
1519 |
return 0; |
|
|
1520 |
|
1521 |
int remainder= offsetInLine % fTabRatio; |
1522 |
remainder= fTabRatio - remainder; |
1523 |
for (int i= 0; i < remainder; i++) |
1524 |
buffer.append(' '); |
1525 |
return remainder; |
1526 |
} |
1992 |
} |
1527 |
|
1993 |
|
1528 |
public void customizeDocumentCommand(IDocument document, DocumentCommand command) { |
1994 |
if (fSelectionSearchGroup != null) { |
1529 |
String text = command.text; |
1995 |
fSelectionSearchGroup.dispose(); |
1530 |
if (text == null) |
1996 |
fSelectionSearchGroup = null; |
1531 |
return; |
|
|
1532 |
|
1533 |
int index = text.indexOf('\t'); |
1534 |
if (index > -1) { |
1535 |
StringBuffer buffer = new StringBuffer(); |
1536 |
|
1537 |
fLineTracker.set(command.text); |
1538 |
int lines = fLineTracker.getNumberOfLines(); |
1539 |
|
1540 |
try { |
1541 |
for (int i = 0; i < lines; i++) { |
1542 |
int offset = fLineTracker.getLineOffset(i); |
1543 |
int endOffset = offset + fLineTracker.getLineLength(i); |
1544 |
String line = text.substring(offset, endOffset); |
1545 |
|
1546 |
int position= 0; |
1547 |
if (i == 0) { |
1548 |
IRegion firstLine = document.getLineInformationOfOffset(command.offset); |
1549 |
position = command.offset - firstLine.getOffset(); |
1550 |
} |
1551 |
|
1552 |
int length = line.length(); |
1553 |
for (int j = 0; j < length; j++) { |
1554 |
char c = line.charAt(j); |
1555 |
if (c == '\t') { |
1556 |
int oldPosition = position; |
1557 |
position += insertTabString(buffer, position); |
1558 |
if (command.caretOffset > command.offset + oldPosition) { |
1559 |
command.caretOffset += position - oldPosition - 1; |
1560 |
} |
1561 |
} else { |
1562 |
buffer.append(c); |
1563 |
++position; |
1564 |
} |
1565 |
} |
1566 |
} |
1567 |
|
1568 |
command.text = buffer.toString(); |
1569 |
} catch (BadLocationException x) { |
1570 |
} |
1571 |
} |
1572 |
} |
1997 |
} |
1573 |
} |
|
|
1574 |
|
1998 |
|
1575 |
/* |
1999 |
if (fTextSearchGroup != null) { |
1576 |
* @see org.eclipse.ui.texteditor.AbstractDecoratedTextEditor#createSourceViewer(org.eclipse.swt.widgets.Composite, org.eclipse.jface.text.source.IVerticalRuler, int) |
2000 |
fTextSearchGroup.dispose(); |
1577 |
*/ |
2001 |
fTextSearchGroup = null; |
1578 |
protected ISourceViewer createSourceViewer(Composite parent, IVerticalRuler ruler, int styles) { |
2002 |
} |
1579 |
ISourceViewer sourceViewer = |
|
|
1580 |
new CSourceViewer( |
1581 |
this, parent, |
1582 |
ruler, |
1583 |
styles, |
1584 |
getOverviewRuler(), |
1585 |
isOverviewRulerVisible()); |
1586 |
|
2003 |
|
1587 |
CUIHelp.setHelp(this, sourceViewer.getTextWidget(), ICHelpContextIds.CEDITOR_VIEW); |
2004 |
if (fRefactoringActionGroup != null) { |
|
|
2005 |
fRefactoringActionGroup.dispose(); |
2006 |
fRefactoringActionGroup = null; |
2007 |
} |
1588 |
|
2008 |
|
1589 |
getSourceViewerDecorationSupport(sourceViewer); |
2009 |
if (fEditorSelectionChangedListener != null) { |
|
|
2010 |
fEditorSelectionChangedListener.uninstall(getSelectionProvider()); |
2011 |
fEditorSelectionChangedListener = null; |
2012 |
} |
2013 |
|
2014 |
stopTabConversion(); |
1590 |
|
2015 |
|
1591 |
return sourceViewer; |
2016 |
super.dispose(); |
1592 |
} |
2017 |
} |
1593 |
|
2018 |
|
1594 |
/** Outliner context menu Id */ |
|
|
1595 |
protected String fOutlinerContextMenuId; |
1596 |
|
1597 |
/** |
2019 |
/** |
1598 |
* Sets the outliner's context menu ID. |
2020 |
* @see org.eclipse.ui.texteditor.AbstractTextEditor#canHandleMove(org.eclipse.ui.IEditorInput, org.eclipse.ui.IEditorInput) |
1599 |
*/ |
|
|
1600 |
protected void setOutlinerContextMenuId(String menuId) { |
1601 |
fOutlinerContextMenuId = menuId; |
1602 |
} |
1603 |
|
1604 |
/* (non-Javadoc) |
1605 |
* @see org.eclipse.ui.editors.text.TextEditor#initializeKeyBindingScopes() |
1606 |
*/ |
2021 |
*/ |
1607 |
protected void initializeKeyBindingScopes() { |
2022 |
protected boolean canHandleMove(IEditorInput originalElement, IEditorInput movedElement) { |
1608 |
setKeyBindingScopes(new String [] { "org.eclipse.cdt.ui.cEditorScope" } ); //$NON-NLS-1$ |
2023 |
String oldLanguage = ""; //$NON-NLS-1$ |
1609 |
} |
2024 |
if (originalElement instanceof IFileEditorInput) { |
|
|
2025 |
IFile file = ((IFileEditorInput) originalElement).getFile(); |
2026 |
if (file != null) { |
2027 |
IContentType type = CCorePlugin.getContentType(file.getProject(), file.getName()); |
2028 |
if (type != null) { |
2029 |
oldLanguage = type.getId(); |
2030 |
} |
2031 |
if (oldLanguage == null) { |
2032 |
return false; |
2033 |
} |
2034 |
} |
2035 |
} |
1610 |
|
2036 |
|
1611 |
/* (non-Javadoc) |
2037 |
String newLanguage = ""; //$NON-NLS-1$ |
1612 |
* @see AbstractTextEditor#affectsTextPresentation(PropertyChangeEvent) |
2038 |
if (movedElement instanceof IFileEditorInput) { |
1613 |
*/ |
2039 |
IFile file = ((IFileEditorInput) movedElement).getFile(); |
1614 |
protected boolean affectsTextPresentation(PropertyChangeEvent event) { |
2040 |
if (file != null) { |
1615 |
SourceViewerConfiguration configuration = getSourceViewerConfiguration(); |
2041 |
IContentType type = CCorePlugin.getContentType(file.getProject(), file.getName()); |
1616 |
if (configuration instanceof CSourceViewerConfiguration) { |
2042 |
if (type != null) { |
1617 |
return ((CSourceViewerConfiguration)configuration).affectsBehavior(event); |
2043 |
newLanguage = type.getId(); |
|
|
2044 |
} |
2045 |
if (newLanguage == null) { |
2046 |
return false; |
2047 |
} |
2048 |
} |
1618 |
} |
2049 |
} |
1619 |
return false; |
2050 |
return oldLanguage.equals(newLanguage); |
1620 |
} |
2051 |
} |
1621 |
|
2052 |
|
1622 |
/** |
2053 |
/** |
1623 |
* Returns the folding action group, or <code>null</code> if there is none. |
2054 |
* @see org.eclipse.ui.texteditor.AbstractTextEditor#createActions() |
1624 |
* |
|
|
1625 |
* @return the folding action group, or <code>null</code> if there is none |
1626 |
*/ |
2055 |
*/ |
1627 |
protected FoldingActionGroup getFoldingActionGroup() { |
2056 |
protected void createActions() { |
1628 |
return fFoldingGroup; |
2057 |
super.createActions(); |
1629 |
} |
|
|
1630 |
|
2058 |
|
1631 |
/* |
2059 |
fFoldingGroup = new FoldingActionGroup(this, getSourceViewer()); |
1632 |
* @see org.eclipse.ui.texteditor.AbstractTextEditor#performRevert() |
2060 |
|
1633 |
*/ |
2061 |
// Sticky hover support |
1634 |
protected void performRevert() { |
2062 |
ResourceAction resAction = new TextOperationAction(CEditorMessages.getResourceBundle(), "ShowToolTip.", this, ISourceViewer.INFORMATION, true); //$NON-NLS-1$ |
1635 |
ProjectionViewer projectionViewer= (ProjectionViewer) getSourceViewer(); |
2063 |
ResourceAction resAction2 = new InformationDispatchAction(CEditorMessages.getResourceBundle(), "ShowToolTip.", (TextOperationAction) resAction); //$NON-NLS-1$ |
1636 |
projectionViewer.setRedraw(false); |
2064 |
resAction2.setActionDefinitionId(ICEditorActionDefinitionIds.SHOW_TOOLTIP); |
1637 |
try { |
2065 |
setAction("ShowToolTip", resAction2); //$NON-NLS-1$ |
1638 |
|
2066 |
PlatformUI.getWorkbench().getHelpSystem().setHelp(resAction2, ICHelpContextIds.SHOW_TOOLTIP_ACTION); |
1639 |
boolean projectionMode= projectionViewer.isProjectionMode(); |
2067 |
|
1640 |
if (projectionMode) { |
2068 |
// Default text editing menu items |
1641 |
projectionViewer.disableProjection(); |
2069 |
Action action = new GotoMatchingBracketAction(this); |
1642 |
if (fProjectionModelUpdater != null) |
2070 |
action.setActionDefinitionId(ICEditorActionDefinitionIds.GOTO_MATCHING_BRACKET); |
1643 |
fProjectionModelUpdater.uninstall(); |
2071 |
setAction(GotoMatchingBracketAction.GOTO_MATCHING_BRACKET, action); |
1644 |
} |
2072 |
|
1645 |
|
2073 |
action = new JoinLinesAction(CEditorMessages.getResourceBundle(), "JoinLines.", this); //$NON-NLS-1$ |
1646 |
super.performRevert(); |
2074 |
action.setActionDefinitionId(ICEditorActionDefinitionIds.JOIN_LINES); |
1647 |
|
2075 |
setAction("Join Lines", action); //$NON-NLS-1$ |
1648 |
if (projectionMode) { |
2076 |
|
1649 |
if (fProjectionModelUpdater != null) |
2077 |
action = new ToggleCommentAction(CEditorMessages.getResourceBundle(), "ToggleComment.", this); //$NON-NLS-1$ |
1650 |
fProjectionModelUpdater.install(this, projectionViewer); |
2078 |
action.setActionDefinitionId(ICEditorActionDefinitionIds.TOGGLE_COMMENT); |
1651 |
projectionViewer.enableProjection(); |
2079 |
setAction("ToggleComment", action); //$NON-NLS-1$ |
1652 |
} |
2080 |
markAsStateDependentAction("ToggleComment", true); //$NON-NLS-1$ |
1653 |
|
2081 |
configureToggleCommentAction(); |
1654 |
} finally { |
2082 |
|
1655 |
projectionViewer.setRedraw(true); |
2083 |
action = new AddBlockCommentAction(CEditorMessages.getResourceBundle(), "AddBlockComment.", this); //$NON-NLS-1$ |
|
|
2084 |
action.setActionDefinitionId(ICEditorActionDefinitionIds.ADD_BLOCK_COMMENT); |
2085 |
setAction("AddBlockComment", action); //$NON-NLS-1$ |
2086 |
markAsStateDependentAction("AddBlockComment", true); //$NON-NLS-1$ |
2087 |
markAsSelectionDependentAction("AddBlockComment", true); //$NON-NLS-1$ |
2088 |
//WorkbenchHelp.setHelp(action, ICHelpContextIds.ADD_BLOCK_COMMENT_ACTION); |
2089 |
|
2090 |
action = new RemoveBlockCommentAction(CEditorMessages.getResourceBundle(), "RemoveBlockComment.", this); //$NON-NLS-1$ |
2091 |
action.setActionDefinitionId(ICEditorActionDefinitionIds.REMOVE_BLOCK_COMMENT); |
2092 |
setAction("RemoveBlockComment", action); //$NON-NLS-1$ |
2093 |
markAsStateDependentAction("RemoveBlockComment", true); //$NON-NLS-1$ |
2094 |
markAsSelectionDependentAction("RemoveBlockComment", true); //$NON-NLS-1$ |
2095 |
//WorkbenchHelp.setHelp(action, ICHelpContextIds.REMOVE_BLOCK_COMMENT_ACTION); |
2096 |
|
2097 |
action = new IndentAction(CEditorMessages.getResourceBundle(), "Indent.", this, false); //$NON-NLS-1$ |
2098 |
action.setActionDefinitionId(ICEditorActionDefinitionIds.INDENT); |
2099 |
setAction("Indent", action); //$NON-NLS-1$ |
2100 |
markAsStateDependentAction("Indent", true); //$NON-NLS-1$ |
2101 |
markAsSelectionDependentAction("Indent", true); //$NON-NLS-1$ |
2102 |
// PlatformUI.getWorkbench().getHelpSystem().setHelp(action, ICHelpContextIds.INDENT_ACTION); |
2103 |
|
2104 |
action = new IndentAction(CEditorMessages.getResourceBundle(), "Indent.", this, true); //$NON-NLS-1$ |
2105 |
setAction("IndentOnTab", action); //$NON-NLS-1$ |
2106 |
markAsStateDependentAction("IndentOnTab", true); //$NON-NLS-1$ |
2107 |
markAsSelectionDependentAction("IndentOnTab", true); //$NON-NLS-1$ |
2108 |
|
2109 |
if (getPreferenceStore().getBoolean(PreferenceConstants.EDITOR_SMART_TAB)) { |
2110 |
setActionActivationCode("IndentOnTab", '\t', -1, SWT.NONE); //$NON-NLS-1$ |
1656 |
} |
2111 |
} |
|
|
2112 |
|
2113 |
action = new TextOperationAction(CEditorMessages.getResourceBundle(), "Format.", this, ISourceViewer.FORMAT); //$NON-NLS-1$ |
2114 |
action.setActionDefinitionId(ICEditorActionDefinitionIds.FORMAT); |
2115 |
setAction("Format", action); //$NON-NLS-1$ |
2116 |
markAsStateDependentAction("Format", true); //$NON-NLS-1$ |
2117 |
|
2118 |
action = new ContentAssistAction(CEditorMessages.getResourceBundle(), "ContentAssistProposal.", this); //$NON-NLS-1$ |
2119 |
action.setActionDefinitionId(ITextEditorActionDefinitionIds.CONTENT_ASSIST_PROPOSALS); |
2120 |
setAction("ContentAssistProposal", action); //$NON-NLS-1$ |
2121 |
markAsStateDependentAction("ContentAssistProposal", true); //$NON-NLS-1$ |
2122 |
|
2123 |
action = new TextOperationAction(CEditorMessages.getResourceBundle(), "ContentAssistTip.", this, ISourceViewer.CONTENTASSIST_CONTEXT_INFORMATION); //$NON-NLS-1$ |
2124 |
action.setActionDefinitionId(ITextEditorActionDefinitionIds.CONTENT_ASSIST_CONTEXT_INFORMATION); |
2125 |
setAction("ContentAssistTip", action); //$NON-NLS-1$ |
2126 |
|
2127 |
action = new AddIncludeOnSelectionAction(this); |
2128 |
action.setActionDefinitionId(ICEditorActionDefinitionIds.ADD_INCLUDE); |
2129 |
setAction("AddIncludeOnSelection", action); //$NON-NLS-1$ |
2130 |
|
2131 |
action = new OpenDeclarationsAction(this); |
2132 |
action.setActionDefinitionId(ICEditorActionDefinitionIds.OPEN_DECL); |
2133 |
setAction("OpenDeclarations", action); //$NON-NLS-1$ |
2134 |
|
2135 |
action = new OpenDefinitionAction(this); |
2136 |
action.setActionDefinitionId(ICEditorActionDefinitionIds.OPEN_DEF); |
2137 |
setAction("OpenDefinition", action); //$NON-NLS-1$ |
2138 |
|
2139 |
// action = new OpenTypeHierarchyAction(this); |
2140 |
// action.setActionDefinitionId(ICEditorActionDefinitionIds.OPEN_TYPE_HIERARCHY); |
2141 |
// setAction("OpenTypeHierarchy", action); //$NON-NLS-1$ |
2142 |
|
2143 |
fShowInCViewAction = new ShowInCViewAction(this); |
2144 |
action = fShowInCViewAction; |
2145 |
action.setActionDefinitionId(ICEditorActionDefinitionIds.OPEN_CVIEW); |
2146 |
setAction("ShowInCView", action); //$NON-NLS-1$ |
2147 |
|
2148 |
action = new TextOperationAction(CEditorMessages.getResourceBundle(), "OpenOutline.", this, CSourceViewer.SHOW_OUTLINE, true); //$NON-NLS-1$ |
2149 |
action.setActionDefinitionId(ICEditorActionDefinitionIds.OPEN_OUTLINE); |
2150 |
setAction("OpenOutline", action); //$NON-NLS-1$*/ |
2151 |
|
2152 |
action = new GoToNextPreviousMemberAction(CEditorMessages.getResourceBundle(), "GotoNextMember.", this, true); //$NON-NLS-1$ |
2153 |
action.setActionDefinitionId(ICEditorActionDefinitionIds.GOTO_NEXT_MEMBER); |
2154 |
setAction("GotoNextMember", action); //$NON-NLS-1$*/ |
2155 |
|
2156 |
action = new GoToNextPreviousMemberAction(CEditorMessages.getResourceBundle(), "GotoPrevMember.", this, false); //$NON-NLS-1$ |
2157 |
action.setActionDefinitionId(ICEditorActionDefinitionIds.GOTO_PREVIOUS_MEMBER); |
2158 |
setAction("GotoPrevMember", action); //$NON-NLS-1$*/ |
2159 |
|
2160 |
//Assorted action groupings |
2161 |
fSelectionSearchGroup = new SelectionSearchGroup(this); |
2162 |
fTextSearchGroup = new TextSearchGroup(this); |
2163 |
fRefactoringActionGroup= new CRefactoringActionGroup(this); |
1657 |
} |
2164 |
} |
1658 |
|
2165 |
|
1659 |
/** |
2166 |
/** |
1660 |
* Sets the given message as error message to this editor's status line. |
2167 |
* @see org.eclipse.ui.texteditor.AbstractTextEditor#editorContextMenuAboutToShow(org.eclipse.jface.action.IMenuManager) |
1661 |
* |
2168 |
*/ |
1662 |
* @param msg message to be set |
2169 |
public void editorContextMenuAboutToShow(IMenuManager menu) { |
1663 |
*/ |
2170 |
super.editorContextMenuAboutToShow(menu); |
1664 |
protected void setStatusLineErrorMessage(String msg) { |
|
|
1665 |
IEditorStatusLine statusLine= (IEditorStatusLine) getAdapter(IEditorStatusLine.class); |
1666 |
if (statusLine != null) |
1667 |
statusLine.setMessage(true, msg, null); |
1668 |
|
2171 |
|
1669 |
} |
2172 |
addGroup(menu, ITextEditorActionConstants.GROUP_EDIT, IContextMenuConstants.GROUP_REORGANIZE); |
|
|
2173 |
addGroup(menu, ITextEditorActionConstants.GROUP_EDIT, IContextMenuConstants.GROUP_GENERATE); |
2174 |
addGroup(menu, ITextEditorActionConstants.GROUP_EDIT, IContextMenuConstants.GROUP_NEW); |
2175 |
|
2176 |
// Code formatting menu items -- only show in C perspective |
2177 |
addAction(menu, ITextEditorActionConstants.GROUP_EDIT, "ToggleComment"); //$NON-NLS-1$ |
2178 |
addAction(menu, ITextEditorActionConstants.GROUP_EDIT, "AddBlockComment"); //$NON-NLS-1$ |
2179 |
addAction(menu, ITextEditorActionConstants.GROUP_EDIT, "RemoveBlockComment"); //$NON-NLS-1$ |
2180 |
|
2181 |
addAction(menu, ITextEditorActionConstants.GROUP_FIND, "OpenDeclarations"); //$NON-NLS-1$ |
2182 |
addAction(menu, ITextEditorActionConstants.GROUP_FIND, "OpenDefinition"); //$NON-NLS-1$ |
2183 |
|
2184 |
addAction(menu, ITextEditorActionConstants.GROUP_FIND, "OpenTypeHierarchy"); //$NON-NLS-1$ |
2185 |
addAction(menu, ITextEditorActionConstants.GROUP_FIND, "GotoNextMember"); //$NON-NLS-1$ |
2186 |
addAction(menu, ITextEditorActionConstants.GROUP_FIND, "GotoPrevMember"); //$NON-NLS-1$ |
2187 |
|
2188 |
addAction(menu, IContextMenuConstants.GROUP_GENERATE, "ContentAssistProposal"); //$NON-NLS-1$ |
2189 |
addAction(menu, IContextMenuConstants.GROUP_GENERATE, "AddIncludeOnSelection"); //$NON-NLS-1$ |
2190 |
addAction(menu, IContextMenuConstants.GROUP_GENERATE, "Format"); //$NON-NLS-1$ |
2191 |
|
2192 |
addAction(menu, IContextMenuConstants.GROUP_GENERATE, "ShowInCView"); //$NON-NLS-1$ |
2193 |
|
2194 |
fSelectionSearchGroup.fillContextMenu(menu); |
2195 |
fTextSearchGroup.fillContextMenu(menu); |
2196 |
fRefactoringActionGroup.fillContextMenu(menu); |
2197 |
} |
2198 |
|
2199 |
/** |
2200 |
* Sets an input for the outline page. |
2201 |
* @param page Page to set the input. |
2202 |
* @param input Input to set. |
2203 |
*/ |
2204 |
public static void setOutlinePageInput(CContentOutlinePage page, IEditorInput input) { |
2205 |
if (page != null) { |
2206 |
IWorkingCopyManager manager = CUIPlugin.getDefault().getWorkingCopyManager(); |
2207 |
page.setInput(manager.getWorkingCopy(input)); |
2208 |
} |
2209 |
} |
1670 |
|
2210 |
|
1671 |
/** |
2211 |
/** |
1672 |
* Sets the given message as message to this editor's status line. |
2212 |
* Determines is folding enabled. |
1673 |
* |
2213 |
* @return <code>true</code> if folding is enabled, <code>false</code> otherwise. |
1674 |
* @param msg message to be set |
|
|
1675 |
* @since 3.0 |
1676 |
*/ |
2214 |
*/ |
1677 |
protected void setStatusLineMessage(String msg) { |
2215 |
boolean isFoldingEnabled() { |
1678 |
IEditorStatusLine statusLine= (IEditorStatusLine) getAdapter(IEditorStatusLine.class); |
2216 |
return CUIPlugin.getDefault().getPreferenceStore().getBoolean(PreferenceConstants.EDITOR_FOLDING_ENABLED); |
1679 |
if (statusLine != null) |
|
|
1680 |
statusLine.setMessage(false, msg, null); |
1681 |
} |
2217 |
} |
1682 |
|
2218 |
|
|
|
2219 |
|
1683 |
/** |
2220 |
/** |
1684 |
* Returns the signed current selection. |
2221 |
* The <code>AbstractTextEditor</code> implementation of this |
1685 |
* The length will be negative if the resulting selection |
2222 |
* <code>IWorkbenchPart</code> method creates the vertical ruler and |
1686 |
* is right-to-left (RtoL). |
2223 |
* source viewer. Subclasses may extend. |
1687 |
* <p> |
|
|
1688 |
* The selection offset is model based. |
1689 |
* </p> |
1690 |
* |
2224 |
* |
1691 |
* @param sourceViewer the source viewer |
2225 |
* We attach our own mouseDown listener on the menu bar, |
1692 |
* @return a region denoting the current signed selection, for a resulting RtoL selections length is < 0 |
2226 |
* and our own listener for cursor/key/selection events to update cursor position in |
|
|
2227 |
* status bar. |
2228 |
|
2229 |
* @param parent Parent composite of the control. |
1693 |
*/ |
2230 |
*/ |
1694 |
protected IRegion getSignedSelection(ISourceViewer sourceViewer) { |
2231 |
public void createPartControl(Composite parent) { |
1695 |
StyledText text= sourceViewer.getTextWidget(); |
2232 |
super.createPartControl(parent); |
1696 |
Point selection= text.getSelectionRange(); |
2233 |
|
|
|
2234 |
// Sticky hover support |
2235 |
IInformationControlCreator informationControlCreator = new IInformationControlCreator() { |
2236 |
public IInformationControl createInformationControl(Shell shell) { |
2237 |
boolean cutDown = false; |
2238 |
int style = cutDown ? SWT.NONE : (SWT.V_SCROLL | SWT.H_SCROLL); |
2239 |
return new DefaultInformationControl(shell, SWT.RESIZE |
2240 |
| SWT.TOOL, style, new HTMLTextPresenter(cutDown)); |
2241 |
} |
2242 |
}; |
2243 |
|
2244 |
fInformationPresenter = new InformationPresenter( |
2245 |
informationControlCreator); |
2246 |
fInformationPresenter.setSizeConstraints(60, 10, true, true); |
2247 |
fInformationPresenter.install(getSourceViewer()); |
2248 |
fInformationPresenter |
2249 |
.setDocumentPartitioning(ICPartitions.C_PARTITIONING); |
2250 |
|
1697 |
|
2251 |
|
1698 |
if (text.getCaretOffset() == selection.x) { |
2252 |
ProjectionViewer projectionViewer = (ProjectionViewer) getSourceViewer(); |
1699 |
selection.x= selection.x + selection.y; |
|
|
1700 |
selection.y= -selection.y; |
1701 |
} |
1702 |
|
2253 |
|
1703 |
selection.x= widgetOffset2ModelOffset(sourceViewer, selection.x); |
2254 |
fProjectionSupport = new ProjectionSupport(projectionViewer, getAnnotationAccess(), getSharedColors()); |
|
|
2255 |
fProjectionSupport.addSummarizableAnnotationType("org.eclipse.ui.workbench.texteditor.error"); //$NON-NLS-1$ |
2256 |
fProjectionSupport.addSummarizableAnnotationType("org.eclipse.ui.workbench.texteditor.warning"); //$NON-NLS-1$ |
2257 |
fProjectionSupport.install(); |
1704 |
|
2258 |
|
1705 |
return new Region(selection.x, selection.y); |
2259 |
fProjectionModelUpdater = CUIPlugin.getDefault().getFoldingStructureProviderRegistry().getCurrentFoldingProvider(); |
1706 |
} |
2260 |
if (fProjectionModelUpdater != null) |
1707 |
|
2261 |
fProjectionModelUpdater.install(this, projectionViewer); |
1708 |
private static boolean isBracket(char character) { |
|
|
1709 |
for (int i= 0; i != BRACKETS.length; ++i) |
1710 |
if (character == BRACKETS[i]) |
1711 |
return true; |
1712 |
return false; |
1713 |
} |
1714 |
|
2262 |
|
1715 |
private static boolean isSurroundedByBrackets(IDocument document, int offset) { |
2263 |
if (isFoldingEnabled()) |
1716 |
if (offset == 0 || offset == document.getLength()) |
2264 |
projectionViewer.doOperation(ProjectionViewer.TOGGLE); |
1717 |
return false; |
2265 |
|
|
|
2266 |
PlatformUI.getWorkbench().getHelpSystem().setHelp(parent, ICHelpContextIds.CEDITOR_VIEW); |
1718 |
|
2267 |
|
1719 |
try { |
2268 |
fEditorSelectionChangedListener = new EditorSelectionChangedListener(); |
1720 |
return |
2269 |
fEditorSelectionChangedListener.install(getSelectionProvider()); |
1721 |
isBracket(document.getChar(offset - 1)) && |
2270 |
|
1722 |
isBracket(document.getChar(offset)); |
2271 |
if (isTabConversionEnabled()) |
|
|
2272 |
startTabConversion(); |
2273 |
|
2274 |
if (isSemanticHighlightingEnabled()) |
2275 |
installSemanticHighlighting(); |
1723 |
|
2276 |
|
1724 |
} catch (BadLocationException e) { |
2277 |
IPreferenceStore preferenceStore = getPreferenceStore(); |
1725 |
return false; |
2278 |
boolean closeBrackets = preferenceStore.getBoolean(CLOSE_BRACKETS); |
1726 |
} |
2279 |
boolean closeAngularBrackets = preferenceStore.getBoolean(CLOSE_ANGULAR_BRACKETS); |
|
|
2280 |
boolean closeStrings = preferenceStore.getBoolean(CLOSE_STRINGS); |
2281 |
|
2282 |
fBracketInserter.setCloseBracketsEnabled(closeBrackets); |
2283 |
fBracketInserter.setCloseStringsEnabled(closeStrings); |
2284 |
fBracketInserter.setCloseAngularBracketsEnabled(closeAngularBrackets); |
2285 |
|
2286 |
ISourceViewer sourceViewer = getSourceViewer(); |
2287 |
if (sourceViewer instanceof ITextViewerExtension) |
2288 |
((ITextViewerExtension) sourceViewer).prependVerifyKeyListener(fBracketInserter); |
1727 |
} |
2289 |
} |
1728 |
|
|
|
1729 |
|
2290 |
|
1730 |
/* |
2291 |
/* |
1731 |
* @see org.eclipse.cdt.internal.ui.editor.IReconcilingParticipant#reconciled() |
2292 |
* @see org.eclipse.ui.texteditor.AbstractTextEditor#initializeDragAndDrop(org.eclipse.jface.text.source.ISourceViewer) |
1732 |
*/ |
2293 |
*/ |
1733 |
public void reconciled(boolean somethingHasChanged) { |
2294 |
protected void initializeDragAndDrop(ISourceViewer viewer) { |
1734 |
if (getSourceViewer() == null) { |
2295 |
Control control = viewer.getTextWidget(); |
1735 |
return; |
2296 |
int operations = DND.DROP_MOVE | DND.DROP_COPY; |
1736 |
} |
|
|
1737 |
// this method must be called in a background thread |
1738 |
assert getSourceViewer().getTextWidget().getDisplay().getThread() != Thread.currentThread(); |
1739 |
|
1740 |
if (fReconcilingListeners.size() > 0) { |
1741 |
// create AST and notify ICReconcilingListeners |
1742 |
ICElement cElement= getInputCElement(); |
1743 |
if (cElement == null) { |
1744 |
return; |
1745 |
} |
1746 |
|
1747 |
aboutToBeReconciled(); |
1748 |
|
2297 |
|
1749 |
// track changes to the document while parsing |
2298 |
DropTarget dropTarget = new DropTarget(control, operations); |
1750 |
IDocument doc= getDocumentProvider().getDocument(getEditorInput()); |
2299 |
ITextEditorDropTargetListener dropTargetListener = new TextEditorDropAdapter(viewer, this); |
1751 |
SimplePositionTracker positionTracker= new SimplePositionTracker(); |
2300 |
dropTarget.setTransfer(dropTargetListener.getTransfers()); |
1752 |
positionTracker.startTracking(doc); |
2301 |
dropTarget.addDropListener(dropTargetListener); |
1753 |
|
2302 |
|
1754 |
try { |
2303 |
DragSource dragSource = new DragSource(control, operations); |
1755 |
IASTTranslationUnit ast= CUIPlugin.getDefault().getASTProvider().createAST(cElement, null); |
2304 |
Transfer[] dragTypes = new Transfer[] { TextTransfer.getInstance() }; |
1756 |
reconciled(ast, positionTracker, null); |
2305 |
dragSource.setTransfer(dragTypes); |
1757 |
} finally { |
2306 |
DragSourceListener dragSourceListener = new TextViewerDragAdapter(viewer, this); |
1758 |
positionTracker.stopTracking(); |
2307 |
dragSource.addDragListener(dragSourceListener); |
1759 |
} |
|
|
1760 |
} |
1761 |
} |
2308 |
} |
1762 |
|
2309 |
|
1763 |
public CSourceViewer getCSourceViewer() { |
2310 |
/* |
1764 |
ISourceViewer viewer = getSourceViewer(); |
2311 |
* @see org.eclipse.ui.texteditor.AbstractDecoratedTextEditor#getSourceViewerDecorationSupport(org.eclipse.jface.text.source.ISourceViewer) |
1765 |
CSourceViewer cViewer = null ; |
2312 |
*/ |
1766 |
if (viewer instanceof CSourceViewer) { |
2313 |
protected SourceViewerDecorationSupport getSourceViewerDecorationSupport( |
1767 |
cViewer = (CSourceViewer) viewer; |
2314 |
ISourceViewer viewer) { |
|
|
2315 |
if (fSourceViewerDecorationSupport == null) { |
2316 |
fSourceViewerDecorationSupport= new CSourceViewerDecorationSupport(this, viewer, getOverviewRuler(), getAnnotationAccess(), getSharedColors()); |
2317 |
configureSourceViewerDecorationSupport(fSourceViewerDecorationSupport); |
1768 |
} |
2318 |
} |
1769 |
return cViewer ; |
2319 |
return fSourceViewerDecorationSupport; |
1770 |
} |
2320 |
} |
1771 |
|
2321 |
|
1772 |
/* |
2322 |
/* |
1773 |
* @see org.eclipse.ui.texteditor.AbstractDecoratedTextEditor#collectContextMenuPreferencePages() |
2323 |
* @see org.eclipse.ui.texteditor.AbstractDecoratedTextEditor#configureSourceViewerDecorationSupport(org.eclipse.ui.texteditor.SourceViewerDecorationSupport) |
1774 |
*/ |
2324 |
*/ |
1775 |
protected String[] collectContextMenuPreferencePages() { |
2325 |
protected void configureSourceViewerDecorationSupport(SourceViewerDecorationSupport support) { |
1776 |
// Add C/C++ Editor relevant pages |
2326 |
super.configureSourceViewerDecorationSupport(support); |
1777 |
String[] parentPrefPageIds = super.collectContextMenuPreferencePages(); |
2327 |
//Enhance the stock source viewer decorator with a bracket matcher |
1778 |
String[] prefPageIds = new String[parentPrefPageIds.length + 4]; |
2328 |
support.setCharacterPairMatcher(fBracketMatcher); |
1779 |
int nIds = 0; |
2329 |
support.setMatchingCharacterPainterPreferenceKeys(MATCHING_BRACKETS, MATCHING_BRACKETS_COLOR); |
1780 |
prefPageIds[nIds++] = "org.eclipse.cdt.ui.preferences.CEditorPreferencePage"; //$NON-NLS-1$ |
2330 |
((CSourceViewerDecorationSupport)support).setInactiveCodePainterPreferenceKeys(INACTIVE_CODE_ENABLE, INACTIVE_CODE_COLOR); |
1781 |
prefPageIds[nIds++] = "org.eclipse.cdt.ui.preferences.CodeAssistPreferencePage"; //$NON-NLS-1$ |
|
|
1782 |
prefPageIds[nIds++] = "org.eclipse.cdt.ui.preferences.TemplatePreferencePage"; //$NON-NLS-1$ |
1783 |
prefPageIds[nIds++] = "org.eclipse.cdt.ui.preferences.CodeFormatterPreferencePage"; //$NON-NLS-1$ |
1784 |
System.arraycopy(parentPrefPageIds, 0, prefPageIds, nIds, parentPrefPageIds.length); |
1785 |
return prefPageIds; |
1786 |
} |
2331 |
} |
1787 |
|
2332 |
|
1788 |
/** |
2333 |
/** |
1789 |
* Text navigation action to navigate to the next sub-word. |
2334 |
* Jumps to the matching bracket. |
1790 |
* |
|
|
1791 |
* @since 4.0 |
1792 |
*/ |
2335 |
*/ |
1793 |
protected abstract class NextSubWordAction extends TextNavigationAction { |
2336 |
public void gotoMatchingBracket() { |
1794 |
|
2337 |
|
1795 |
protected CWordIterator fIterator = new CWordIterator(); |
2338 |
ISourceViewer sourceViewer = getSourceViewer(); |
|
|
2339 |
IDocument document = sourceViewer.getDocument(); |
2340 |
if (document == null) |
2341 |
return; |
2342 |
|
2343 |
IRegion selection = getSignedSelection(sourceViewer); |
1796 |
|
2344 |
|
1797 |
/** |
2345 |
int selectionLength = Math.abs(selection.getLength()); |
1798 |
* Creates a new next sub-word action. |
2346 |
if (selectionLength > 1) { |
1799 |
* |
2347 |
setStatusLineErrorMessage(CEditorMessages.getString("GotoMatchingBracket.error.invalidSelection")); //$NON-NLS-1$ |
1800 |
* @param code Action code for the default operation. Must be an action code from @see org.eclipse.swt.custom.ST. |
2348 |
sourceViewer.getTextWidget().getDisplay().beep(); |
1801 |
*/ |
2349 |
return; |
1802 |
protected NextSubWordAction(int code) { |
|
|
1803 |
super(getSourceViewer().getTextWidget(), code); |
1804 |
} |
2350 |
} |
1805 |
|
2351 |
|
1806 |
/* |
2352 |
// #26314 |
1807 |
* @see org.eclipse.jface.action.IAction#run() |
2353 |
int sourceCaretOffset = selection.getOffset() + selection.getLength(); |
1808 |
*/ |
2354 |
if (isSurroundedByBrackets(document, sourceCaretOffset)) |
1809 |
public void run() { |
2355 |
sourceCaretOffset -= selection.getLength(); |
1810 |
// Check whether sub word navigation is enabled. |
|
|
1811 |
final IPreferenceStore store = getPreferenceStore(); |
1812 |
if (!store.getBoolean(SUB_WORD_NAVIGATION)) { |
1813 |
super.run(); |
1814 |
return; |
1815 |
} |
1816 |
|
1817 |
final ISourceViewer viewer = getSourceViewer(); |
1818 |
final IDocument document = viewer.getDocument(); |
1819 |
fIterator.setText((CharacterIterator) new DocumentCharacterIterator(document)); |
1820 |
int position = widgetOffset2ModelOffset(viewer, viewer.getTextWidget().getCaretOffset()); |
1821 |
if (position == -1) |
1822 |
return; |
1823 |
|
1824 |
int next = findNextPosition(position); |
1825 |
if (next != BreakIterator.DONE) { |
1826 |
setCaretPosition(next); |
1827 |
getTextWidget().showSelection(); |
1828 |
fireSelectionChanged(); |
1829 |
} |
1830 |
|
2356 |
|
|
|
2357 |
IRegion region = fBracketMatcher.match(document, sourceCaretOffset); |
2358 |
if (region == null) { |
2359 |
setStatusLineErrorMessage(CEditorMessages.getString("GotoMatchingBracket.error.noMatchingBracket")); //$NON-NLS-1$ |
2360 |
sourceViewer.getTextWidget().getDisplay().beep(); |
2361 |
return; |
2362 |
} |
2363 |
|
2364 |
int offset = region.getOffset(); |
2365 |
int length = region.getLength(); |
2366 |
|
2367 |
if (length < 1) |
2368 |
return; |
2369 |
|
2370 |
int anchor = fBracketMatcher.getAnchor(); |
2371 |
// http://dev.eclipse.org/bugs/show_bug.cgi?id=34195 |
2372 |
int targetOffset = (ICharacterPairMatcher.RIGHT == anchor) ? offset + 1: offset + length; |
2373 |
|
2374 |
boolean visible = false; |
2375 |
if (sourceViewer instanceof ITextViewerExtension5) { |
2376 |
ITextViewerExtension5 extension = (ITextViewerExtension5) sourceViewer; |
2377 |
visible = (extension.modelOffset2WidgetOffset(targetOffset) > -1); |
2378 |
} else { |
2379 |
IRegion visibleRegion = sourceViewer.getVisibleRegion(); |
2380 |
// http://dev.eclipse.org/bugs/show_bug.cgi?id=34195 |
2381 |
visible = (targetOffset >= visibleRegion.getOffset() && targetOffset <= visibleRegion.getOffset() + visibleRegion.getLength()); |
2382 |
} |
2383 |
|
2384 |
if (!visible) { |
2385 |
setStatusLineErrorMessage(CEditorMessages.getString("GotoMatchingBracket.error.bracketOutsideSelectedElement")); //$NON-NLS-1$ |
2386 |
sourceViewer.getTextWidget().getDisplay().beep(); |
2387 |
return; |
1831 |
} |
2388 |
} |
|
|
2389 |
|
2390 |
if (selection.getLength() < 0) |
2391 |
targetOffset -= selection.getLength(); |
2392 |
|
2393 |
sourceViewer.setSelectedRange(targetOffset, selection.getLength()); |
2394 |
sourceViewer.revealRange(targetOffset, selection.getLength()); |
2395 |
} |
1832 |
|
2396 |
|
1833 |
/** |
2397 |
protected void updateStatusLine() { |
1834 |
* Finds the next position after the given position. |
2398 |
ITextSelection selection = (ITextSelection) getSelectionProvider().getSelection(); |
1835 |
* |
2399 |
Annotation annotation = getAnnotation(selection.getOffset(), selection.getLength()); |
1836 |
* @param position the current position |
2400 |
setStatusLineErrorMessage(null); |
1837 |
* @return the next position |
2401 |
setStatusLineMessage(null); |
1838 |
*/ |
2402 |
if (annotation != null) { |
1839 |
protected int findNextPosition(int position) { |
2403 |
updateMarkerViews(annotation); |
1840 |
ISourceViewer viewer = getSourceViewer(); |
2404 |
if (annotation instanceof ICAnnotation && ((ICAnnotation) annotation).isProblem()) |
1841 |
int widget = -1; |
2405 |
setStatusLineMessage(annotation.getText()); |
1842 |
while (position != BreakIterator.DONE && widget == -1) { // TODO: optimize |
|
|
1843 |
position = fIterator.following(position); |
1844 |
if (position != BreakIterator.DONE) |
1845 |
widget = modelOffset2WidgetOffset(viewer, position); |
1846 |
} |
1847 |
return position; |
1848 |
} |
2406 |
} |
1849 |
|
|
|
1850 |
/** |
1851 |
* Sets the caret position to the sub-word boundary given with <code>position</code>. |
1852 |
* |
1853 |
* @param position Position where the action should move the caret |
1854 |
*/ |
1855 |
protected abstract void setCaretPosition(int position); |
1856 |
} |
2407 |
} |
1857 |
|
2408 |
|
1858 |
/** |
2409 |
/** |
1859 |
* Text navigation action to navigate to the next sub-word. |
2410 |
* Returns the annotation overlapping with the given range or <code>null</code>. |
1860 |
* |
2411 |
* |
1861 |
* @since 4.0 |
2412 |
* @param offset the region offset |
|
|
2413 |
* @param length the region length |
2414 |
* @return the found annotation or <code>null</code> |
2415 |
* @since 3.0 |
1862 |
*/ |
2416 |
*/ |
1863 |
protected class NavigateNextSubWordAction extends NextSubWordAction { |
2417 |
private Annotation getAnnotation(int offset, int length) { |
1864 |
|
2418 |
IAnnotationModel model = getDocumentProvider().getAnnotationModel(getEditorInput()); |
1865 |
/** |
2419 |
Iterator e = new CAnnotationIterator(model, true, true); |
1866 |
* Creates a new navigate next sub-word action. |
2420 |
while (e.hasNext()) { |
1867 |
*/ |
2421 |
Annotation a = (Annotation) e.next(); |
1868 |
public NavigateNextSubWordAction() { |
2422 |
if (!isNavigationTarget(a)) |
1869 |
super(ST.WORD_NEXT); |
2423 |
continue; |
|
|
2424 |
|
2425 |
Position p = model.getPosition(a); |
2426 |
if (p != null && p.overlapsWith(offset, length)) |
2427 |
return a; |
1870 |
} |
2428 |
} |
|
|
2429 |
|
2430 |
return null; |
2431 |
} |
2432 |
/* (non-Javadoc) |
2433 |
* @see org.eclipse.ui.part.IShowInSource#getShowInContext() |
2434 |
* |
2435 |
* This is required by the IShowInSource interface for the "ShowIn" |
2436 |
* navigation menu generalized in Eclipse. |
2437 |
*/ |
2438 |
public ShowInContext getShowInContext() { |
2439 |
return new ShowInContext( getEditorInput(), null ); |
2440 |
} |
1871 |
|
2441 |
|
1872 |
/* |
2442 |
/* |
1873 |
* @see org.eclipse.cdt.internal.ui.editor.CEditor.NextSubWordAction#setCaretPosition(int) |
2443 |
* Get the dektop's StatusLineManager |
1874 |
*/ |
2444 |
*/ |
1875 |
protected void setCaretPosition(final int position) { |
2445 |
protected IStatusLineManager getStatusLineManager() { |
1876 |
getTextWidget().setCaretOffset(modelOffset2WidgetOffset(getSourceViewer(), position)); |
2446 |
IEditorActionBarContributor contributor = getEditorSite().getActionBarContributor(); |
|
|
2447 |
if (contributor instanceof EditorActionBarContributor) { |
2448 |
return ((EditorActionBarContributor) contributor).getActionBars().getStatusLineManager(); |
1877 |
} |
2449 |
} |
|
|
2450 |
return null; |
1878 |
} |
2451 |
} |
1879 |
|
2452 |
|
1880 |
/** |
2453 |
/** |
1881 |
* Text operation action to delete the next sub-word. |
2454 |
* Configures the toggle comment action |
1882 |
* |
2455 |
* |
1883 |
* @since 4.0 |
2456 |
* @since 4.0.0 |
1884 |
*/ |
2457 |
*/ |
1885 |
protected class DeleteNextSubWordAction extends NextSubWordAction implements IUpdate { |
2458 |
private void configureToggleCommentAction() { |
1886 |
|
2459 |
IAction action = getAction("ToggleComment"); //$NON-NLS-1$ |
1887 |
/** |
2460 |
if (action instanceof ToggleCommentAction) { |
1888 |
* Creates a new delete next sub-word action. |
2461 |
ISourceViewer sourceViewer = getSourceViewer(); |
1889 |
*/ |
2462 |
SourceViewerConfiguration configuration = getSourceViewerConfiguration(); |
1890 |
public DeleteNextSubWordAction() { |
2463 |
((ToggleCommentAction)action).configure(sourceViewer, configuration); |
1891 |
super(ST.DELETE_WORD_NEXT); |
|
|
1892 |
} |
2464 |
} |
|
|
2465 |
} |
1893 |
|
2466 |
|
1894 |
/* |
2467 |
private void configureTabConverter() { |
1895 |
* @see org.eclipse.cdt.internal.ui.editor.CEditor.NextSubWordAction#setCaretPosition(int) |
2468 |
if (fTabConverter != null) { |
1896 |
*/ |
2469 |
IDocumentProvider provider = getDocumentProvider(); |
1897 |
protected void setCaretPosition(final int position) { |
2470 |
if (provider instanceof CDocumentProvider) { |
1898 |
if (!validateEditorInputState()) |
2471 |
CDocumentProvider prov = (CDocumentProvider) provider; |
1899 |
return; |
2472 |
fTabConverter.setLineTracker(prov.createLineTracker(getEditorInput())); |
1900 |
|
|
|
1901 |
final ISourceViewer viewer = getSourceViewer(); |
1902 |
final int caret, length; |
1903 |
Point selection = viewer.getSelectedRange(); |
1904 |
if (selection.y != 0) { |
1905 |
caret = selection.x; |
1906 |
length = selection.y; |
1907 |
} else { |
2473 |
} else { |
1908 |
caret = widgetOffset2ModelOffset(viewer, viewer.getTextWidget().getCaretOffset()); |
2474 |
fTabConverter.setLineTracker(new DefaultLineTracker()); |
1909 |
length = position - caret; |
|
|
1910 |
} |
1911 |
|
1912 |
try { |
1913 |
viewer.getDocument().replace(caret, length, ""); //$NON-NLS-1$ |
1914 |
} catch (BadLocationException exception) { |
1915 |
// Should not happen |
1916 |
} |
2475 |
} |
1917 |
} |
2476 |
} |
|
|
2477 |
} |
1918 |
|
2478 |
|
1919 |
/* |
2479 |
private int getTabSize() { |
1920 |
* @see org.eclipse.cdt.internal.ui.editor.CEditor.NextSubWordAction#findNextPosition(int) |
2480 |
ICElement element = getInputCElement(); |
1921 |
*/ |
2481 |
ICProject project = element == null ? null : element.getCProject(); |
1922 |
protected int findNextPosition(int position) { |
2482 |
return CodeFormatterUtil.getTabWidth(project); |
1923 |
return fIterator.following(position); |
2483 |
} |
|
|
2484 |
|
2485 |
private void startTabConversion() { |
2486 |
if (fTabConverter == null) { |
2487 |
fTabConverter= new TabConverter(); |
2488 |
configureTabConverter(); |
2489 |
fTabConverter.setNumberOfSpacesPerTab(getTabSize()); |
2490 |
AdaptedSourceViewer asv= (AdaptedSourceViewer) getSourceViewer(); |
2491 |
asv.addTextConverter(fTabConverter); |
2492 |
asv.updateIndentationPrefixes(); |
1924 |
} |
2493 |
} |
|
|
2494 |
} |
1925 |
|
2495 |
|
1926 |
/* |
2496 |
private void stopTabConversion() { |
1927 |
* @see org.eclipse.ui.texteditor.IUpdate#update() |
2497 |
if (fTabConverter != null) { |
1928 |
*/ |
2498 |
AdaptedSourceViewer asv= (AdaptedSourceViewer) getSourceViewer(); |
1929 |
public void update() { |
2499 |
asv.removeTextConverter(fTabConverter); |
1930 |
setEnabled(isEditorInputModifiable()); |
2500 |
asv.updateIndentationPrefixes(); |
|
|
2501 |
fTabConverter= null; |
1931 |
} |
2502 |
} |
1932 |
} |
2503 |
} |
1933 |
|
2504 |
|
1934 |
/** |
2505 |
private boolean isTabConversionEnabled() { |
1935 |
* Text operation action to select the next sub-word. |
2506 |
ICElement element= getInputCElement(); |
1936 |
* |
2507 |
ICProject project= element == null ? null : element.getCProject(); |
1937 |
* @since 4.0 |
2508 |
String option; |
|
|
2509 |
if (project == null) |
2510 |
option= CCorePlugin.getOption(SPACES_FOR_TABS); |
2511 |
else |
2512 |
option= project.getOption(SPACES_FOR_TABS, true); |
2513 |
return CCorePlugin.SPACE.equals(option); |
2514 |
} |
2515 |
|
2516 |
/* |
2517 |
* @see org.eclipse.ui.texteditor.AbstractTextEditor#createNavigationActions() |
1938 |
*/ |
2518 |
*/ |
1939 |
protected class SelectNextSubWordAction extends NextSubWordAction { |
2519 |
protected void createNavigationActions() { |
|
|
2520 |
super.createNavigationActions(); |
1940 |
|
2521 |
|
1941 |
/** |
2522 |
final StyledText textWidget = getSourceViewer().getTextWidget(); |
1942 |
* Creates a new select next sub-word action. |
|
|
1943 |
*/ |
1944 |
public SelectNextSubWordAction() { |
1945 |
super(ST.SELECT_WORD_NEXT); |
1946 |
} |
1947 |
|
2523 |
|
1948 |
/* |
2524 |
IAction action = new NavigatePreviousSubWordAction(); |
1949 |
* @see org.eclipse.cdt.internal.ui.editor.CEditor.NextSubWordAction#setCaretPosition(int) |
2525 |
action.setActionDefinitionId(ITextEditorActionDefinitionIds.WORD_PREVIOUS); |
1950 |
*/ |
2526 |
setAction(ITextEditorActionDefinitionIds.WORD_PREVIOUS, action); |
1951 |
protected void setCaretPosition(final int position) { |
2527 |
textWidget.setKeyBinding(SWT.CTRL | SWT.ARROW_LEFT, SWT.NULL); |
1952 |
final ISourceViewer viewer = getSourceViewer(); |
|
|
1953 |
|
2528 |
|
1954 |
final StyledText text = viewer.getTextWidget(); |
2529 |
action = new NavigateNextSubWordAction(); |
1955 |
if (text != null && !text.isDisposed()) { |
2530 |
action.setActionDefinitionId(ITextEditorActionDefinitionIds.WORD_NEXT); |
|
|
2531 |
setAction(ITextEditorActionDefinitionIds.WORD_NEXT, action); |
2532 |
textWidget.setKeyBinding(SWT.CTRL | SWT.ARROW_RIGHT, SWT.NULL); |
1956 |
|
2533 |
|
1957 |
final Point selection = text.getSelection(); |
2534 |
action = new SelectPreviousSubWordAction(); |
1958 |
final int caret = text.getCaretOffset(); |
2535 |
action.setActionDefinitionId(ITextEditorActionDefinitionIds.SELECT_WORD_PREVIOUS); |
1959 |
final int offset = modelOffset2WidgetOffset(viewer, position); |
2536 |
setAction(ITextEditorActionDefinitionIds.SELECT_WORD_PREVIOUS, action); |
|
|
2537 |
textWidget.setKeyBinding(SWT.CTRL | SWT.SHIFT | SWT.ARROW_LEFT, SWT.NULL); |
1960 |
|
2538 |
|
1961 |
if (caret == selection.x) |
2539 |
action = new SelectNextSubWordAction(); |
1962 |
text.setSelectionRange(selection.y, offset - selection.y); |
2540 |
action.setActionDefinitionId(ITextEditorActionDefinitionIds.SELECT_WORD_NEXT); |
1963 |
else |
2541 |
setAction(ITextEditorActionDefinitionIds.SELECT_WORD_NEXT, action); |
1964 |
text.setSelectionRange(selection.x, offset - selection.x); |
2542 |
textWidget.setKeyBinding(SWT.CTRL | SWT.SHIFT | SWT.ARROW_RIGHT, SWT.NULL); |
|
|
2543 |
|
2544 |
action = new DeletePreviousSubWordAction(); |
2545 |
action.setActionDefinitionId(ITextEditorActionDefinitionIds.DELETE_PREVIOUS_WORD); |
2546 |
setAction(ITextEditorActionDefinitionIds.DELETE_PREVIOUS_WORD, action); |
2547 |
textWidget.setKeyBinding(SWT.CTRL | SWT.BS, SWT.NULL); |
2548 |
markAsStateDependentAction(ITextEditorActionDefinitionIds.DELETE_PREVIOUS_WORD, true); |
2549 |
|
2550 |
action = new DeleteNextSubWordAction(); |
2551 |
action.setActionDefinitionId(ITextEditorActionDefinitionIds.DELETE_NEXT_WORD); |
2552 |
setAction(ITextEditorActionDefinitionIds.DELETE_NEXT_WORD, action); |
2553 |
textWidget.setKeyBinding(SWT.CTRL | SWT.DEL, SWT.NULL); |
2554 |
markAsStateDependentAction(ITextEditorActionDefinitionIds.DELETE_NEXT_WORD, true); |
2555 |
} |
2556 |
|
2557 |
public final ISourceViewer getViewer() { |
2558 |
return getSourceViewer(); |
2559 |
} |
2560 |
|
2561 |
/* |
2562 |
* @see org.eclipse.ui.texteditor.AbstractDecoratedTextEditor#createSourceViewer(org.eclipse.swt.widgets.Composite, org.eclipse.jface.text.source.IVerticalRuler, int) |
2563 |
*/ |
2564 |
protected ISourceViewer createSourceViewer(Composite parent, IVerticalRuler ruler, int styles) { |
2565 |
ISourceViewer sourceViewer = |
2566 |
new AdaptedSourceViewer(parent, ruler, getOverviewRuler(), isOverviewRulerVisible(), styles); |
2567 |
|
2568 |
CUIHelp.setHelp(this, sourceViewer.getTextWidget(), ICHelpContextIds.CEDITOR_VIEW); |
2569 |
|
2570 |
getSourceViewerDecorationSupport(sourceViewer); |
2571 |
|
2572 |
return sourceViewer; |
2573 |
} |
2574 |
|
2575 |
/** Outliner context menu Id */ |
2576 |
protected String fOutlinerContextMenuId; |
2577 |
|
2578 |
/** |
2579 |
* Sets the outliner's context menu ID. |
2580 |
*/ |
2581 |
protected void setOutlinerContextMenuId(String menuId) { |
2582 |
fOutlinerContextMenuId = menuId; |
2583 |
} |
2584 |
|
2585 |
/* (non-Javadoc) |
2586 |
* @see org.eclipse.ui.editors.text.TextEditor#initializeKeyBindingScopes() |
2587 |
*/ |
2588 |
protected void initializeKeyBindingScopes() { |
2589 |
setKeyBindingScopes(new String [] { "org.eclipse.cdt.ui.cEditorScope" } ); //$NON-NLS-1$ |
2590 |
} |
2591 |
|
2592 |
/* (non-Javadoc) |
2593 |
* @see AbstractTextEditor#affectsTextPresentation(PropertyChangeEvent) |
2594 |
*/ |
2595 |
protected boolean affectsTextPresentation(PropertyChangeEvent event) { |
2596 |
SourceViewerConfiguration configuration = getSourceViewerConfiguration(); |
2597 |
if (configuration instanceof CSourceViewerConfiguration) { |
2598 |
return ((CSourceViewerConfiguration)configuration).affectsBehavior(event); |
2599 |
} |
2600 |
return false; |
2601 |
} |
2602 |
|
2603 |
/** |
2604 |
* Returns the folding action group, or <code>null</code> if there is none. |
2605 |
* |
2606 |
* @return the folding action group, or <code>null</code> if there is none |
2607 |
*/ |
2608 |
protected FoldingActionGroup getFoldingActionGroup() { |
2609 |
return fFoldingGroup; |
2610 |
} |
2611 |
|
2612 |
/* |
2613 |
* @see org.eclipse.ui.texteditor.AbstractTextEditor#performRevert() |
2614 |
*/ |
2615 |
protected void performRevert() { |
2616 |
ProjectionViewer projectionViewer = (ProjectionViewer) getSourceViewer(); |
2617 |
projectionViewer.setRedraw(false); |
2618 |
try { |
2619 |
|
2620 |
boolean projectionMode = projectionViewer.isProjectionMode(); |
2621 |
if (projectionMode) { |
2622 |
projectionViewer.disableProjection(); |
2623 |
if (fProjectionModelUpdater != null) |
2624 |
fProjectionModelUpdater.uninstall(); |
2625 |
} |
2626 |
|
2627 |
super.performRevert(); |
2628 |
|
2629 |
if (projectionMode) { |
2630 |
if (fProjectionModelUpdater != null) |
2631 |
fProjectionModelUpdater.install(this, projectionViewer); |
2632 |
projectionViewer.enableProjection(); |
1965 |
} |
2633 |
} |
|
|
2634 |
|
2635 |
} finally { |
2636 |
projectionViewer.setRedraw(true); |
1966 |
} |
2637 |
} |
1967 |
} |
2638 |
} |
1968 |
|
2639 |
|
|
|
2640 |
/** |
2641 |
* Sets the given message as error message to this editor's status line. |
2642 |
* |
2643 |
* @param msg message to be set |
2644 |
*/ |
2645 |
protected void setStatusLineErrorMessage(String msg) { |
2646 |
IEditorStatusLine statusLine = (IEditorStatusLine) getAdapter(IEditorStatusLine.class); |
2647 |
if (statusLine != null) |
2648 |
statusLine.setMessage(true, msg, null); |
2649 |
} |
2650 |
|
1969 |
/** |
2651 |
/** |
1970 |
* Text navigation action to navigate to the previous sub-word. |
2652 |
* Sets the given message as message to this editor's status line. |
1971 |
* |
2653 |
* |
1972 |
* @since 4.0 |
2654 |
* @param msg message to be set |
|
|
2655 |
* @since 3.0 |
1973 |
*/ |
2656 |
*/ |
1974 |
protected abstract class PreviousSubWordAction extends TextNavigationAction { |
2657 |
protected void setStatusLineMessage(String msg) { |
|
|
2658 |
IEditorStatusLine statusLine = (IEditorStatusLine) getAdapter(IEditorStatusLine.class); |
2659 |
if (statusLine != null) |
2660 |
statusLine.setMessage(false, msg, null); |
2661 |
} |
1975 |
|
2662 |
|
1976 |
protected CWordIterator fIterator = new CWordIterator(); |
2663 |
/** |
|
|
2664 |
* Returns the signed current selection. |
2665 |
* The length will be negative if the resulting selection |
2666 |
* is right-to-left (RtoL). |
2667 |
* <p> |
2668 |
* The selection offset is model based. |
2669 |
* </p> |
2670 |
* |
2671 |
* @param sourceViewer the source viewer |
2672 |
* @return a region denoting the current signed selection, for a resulting RtoL selections length is < 0 |
2673 |
*/ |
2674 |
protected IRegion getSignedSelection(ISourceViewer sourceViewer) { |
2675 |
StyledText text = sourceViewer.getTextWidget(); |
2676 |
Point selection = text.getSelectionRange(); |
2677 |
|
2678 |
if (text.getCaretOffset() == selection.x) { |
2679 |
selection.x = selection.x + selection.y; |
2680 |
selection.y = -selection.y; |
2681 |
} |
2682 |
|
2683 |
selection.x = widgetOffset2ModelOffset(sourceViewer, selection.x); |
2684 |
|
2685 |
return new Region(selection.x, selection.y); |
2686 |
} |
2687 |
|
2688 |
private static boolean isBracket(char character) { |
2689 |
for (int i = 0; i != BRACKETS.length; ++i) { |
2690 |
if (character == BRACKETS[i]) |
2691 |
return true; |
2692 |
} |
2693 |
return false; |
2694 |
} |
1977 |
|
2695 |
|
1978 |
/** |
2696 |
private static boolean isSurroundedByBrackets(IDocument document, int offset) { |
1979 |
* Creates a new previous sub-word action. |
2697 |
if (offset == 0 || offset == document.getLength()) |
1980 |
* |
2698 |
return false; |
1981 |
* @param code Action code for the default operation. Must be an action code from @see org.eclipse.swt.custom.ST. |
2699 |
|
1982 |
*/ |
2700 |
try { |
1983 |
protected PreviousSubWordAction(final int code) { |
2701 |
return isBracket(document.getChar(offset - 1)) && |
1984 |
super(getSourceViewer().getTextWidget(), code); |
2702 |
isBracket(document.getChar(offset)); |
|
|
2703 |
} catch (BadLocationException e) { |
2704 |
return false; |
2705 |
} |
2706 |
} |
2707 |
|
2708 |
private static char getEscapeCharacter(char character) { |
2709 |
switch (character) { |
2710 |
case '"': |
2711 |
case '\'': |
2712 |
return '\\'; |
2713 |
default: |
2714 |
return 0; |
1985 |
} |
2715 |
} |
|
|
2716 |
} |
1986 |
|
2717 |
|
1987 |
/* |
2718 |
private static char getPeerCharacter(char character) { |
1988 |
* @see org.eclipse.jface.action.IAction#run() |
2719 |
switch (character) { |
1989 |
*/ |
2720 |
case '(': |
1990 |
public void run() { |
2721 |
return ')'; |
1991 |
// Check whether sub word navigation is enabled. |
|
|
1992 |
final IPreferenceStore store = getPreferenceStore(); |
1993 |
if (!store.getBoolean(SUB_WORD_NAVIGATION)) { |
1994 |
super.run(); |
1995 |
return; |
1996 |
} |
1997 |
|
2722 |
|
1998 |
final ISourceViewer viewer = getSourceViewer(); |
2723 |
case ')': |
1999 |
final IDocument document = viewer.getDocument(); |
2724 |
return '('; |
2000 |
fIterator.setText((CharacterIterator) new DocumentCharacterIterator(document)); |
|
|
2001 |
int position = widgetOffset2ModelOffset(viewer, viewer.getTextWidget().getCaretOffset()); |
2002 |
if (position == -1) |
2003 |
return; |
2004 |
|
2725 |
|
2005 |
int previous = findPreviousPosition(position); |
2726 |
case '<': |
2006 |
if (previous != BreakIterator.DONE) { |
2727 |
return '>'; |
2007 |
setCaretPosition(previous); |
|
|
2008 |
getTextWidget().showSelection(); |
2009 |
fireSelectionChanged(); |
2010 |
} |
2011 |
|
2728 |
|
2012 |
} |
2729 |
case '>': |
|
|
2730 |
return '<'; |
2013 |
|
2731 |
|
2014 |
/** |
2732 |
case '[': |
2015 |
* Finds the previous position before the given position. |
2733 |
return ']'; |
2016 |
* |
|
|
2017 |
* @param position the current position |
2018 |
* @return the previous position |
2019 |
*/ |
2020 |
protected int findPreviousPosition(int position) { |
2021 |
ISourceViewer viewer = getSourceViewer(); |
2022 |
int widget = -1; |
2023 |
while (position != BreakIterator.DONE && widget == -1) { // TODO: optimize |
2024 |
position = fIterator.preceding(position); |
2025 |
if (position != BreakIterator.DONE) |
2026 |
widget = modelOffset2WidgetOffset(viewer, position); |
2027 |
} |
2028 |
return position; |
2029 |
} |
2030 |
|
2734 |
|
2031 |
/** |
2735 |
case ']': |
2032 |
* Sets the caret position to the sub-word boundary given with <code>position</code>. |
2736 |
return '['; |
2033 |
* |
|
|
2034 |
* @param position Position where the action should move the caret |
2035 |
*/ |
2036 |
protected abstract void setCaretPosition(int position); |
2037 |
} |
2038 |
|
2737 |
|
2039 |
/** |
2738 |
case '"': |
2040 |
* Text navigation action to navigate to the previous sub-word. |
2739 |
return character; |
2041 |
* |
|
|
2042 |
* @since 4.0 |
2043 |
*/ |
2044 |
protected class NavigatePreviousSubWordAction extends PreviousSubWordAction { |
2045 |
|
2740 |
|
2046 |
/** |
2741 |
case '\'': |
2047 |
* Creates a new navigate previous sub-word action. |
2742 |
return character; |
2048 |
*/ |
|
|
2049 |
public NavigatePreviousSubWordAction() { |
2050 |
super(ST.WORD_PREVIOUS); |
2051 |
} |
2052 |
|
2743 |
|
2053 |
/* |
2744 |
default: |
2054 |
* @see org.eclipse.cdt.internal.ui.editor.CEditor.PreviousSubWordAction#setCaretPosition(int) |
2745 |
throw new IllegalArgumentException(); |
2055 |
*/ |
|
|
2056 |
protected void setCaretPosition(final int position) { |
2057 |
getTextWidget().setCaretOffset(modelOffset2WidgetOffset(getSourceViewer(), position)); |
2058 |
} |
2746 |
} |
2059 |
} |
2747 |
} |
2060 |
|
2748 |
|
2061 |
/** |
2749 |
/* |
2062 |
* Text operation action to delete the previous sub-word. |
2750 |
* @see org.eclipse.cdt.internal.ui.editor.IReconcilingParticipant#reconciled() |
2063 |
* |
|
|
2064 |
* @since 4.0 |
2065 |
*/ |
2751 |
*/ |
2066 |
protected class DeletePreviousSubWordAction extends PreviousSubWordAction implements IUpdate { |
2752 |
public void reconciled(boolean somethingHasChanged) { |
2067 |
|
2753 |
if (getSourceViewer() == null) { |
2068 |
/** |
2754 |
return; |
2069 |
* Creates a new delete previous sub-word action. |
|
|
2070 |
*/ |
2071 |
public DeletePreviousSubWordAction() { |
2072 |
super(ST.DELETE_WORD_PREVIOUS); |
2073 |
} |
2755 |
} |
2074 |
|
2756 |
// this method must be called in a background thread |
2075 |
/* |
2757 |
assert getSourceViewer().getTextWidget().getDisplay().getThread() != Thread.currentThread(); |
2076 |
* @see org.eclipse.cdt.internal.ui.editor.CEditor.PreviousSubWordAction#setCaretPosition(int) |
2758 |
|
2077 |
*/ |
2759 |
if (fReconcilingListeners.size() > 0) { |
2078 |
protected void setCaretPosition(int position) { |
2760 |
// create AST and notify ICReconcilingListeners |
2079 |
if (!validateEditorInputState()) |
2761 |
ICElement cElement= getInputCElement(); |
|
|
2762 |
if (cElement == null) { |
2080 |
return; |
2763 |
return; |
2081 |
|
|
|
2082 |
final int length; |
2083 |
final ISourceViewer viewer = getSourceViewer(); |
2084 |
Point selection = viewer.getSelectedRange(); |
2085 |
if (selection.y != 0) { |
2086 |
position = selection.x; |
2087 |
length = selection.y; |
2088 |
} else { |
2089 |
length = widgetOffset2ModelOffset(viewer, viewer.getTextWidget().getCaretOffset()) - position; |
2090 |
} |
2764 |
} |
|
|
2765 |
|
2766 |
aboutToBeReconciled(); |
2091 |
|
2767 |
|
|
|
2768 |
// track changes to the document while parsing |
2769 |
IDocument doc= getDocumentProvider().getDocument(getEditorInput()); |
2770 |
SimplePositionTracker positionTracker= new SimplePositionTracker(); |
2771 |
positionTracker.startTracking(doc); |
2772 |
|
2092 |
try { |
2773 |
try { |
2093 |
viewer.getDocument().replace(position, length, ""); //$NON-NLS-1$ |
2774 |
IASTTranslationUnit ast= CUIPlugin.getDefault().getASTProvider().createAST(cElement, null); |
2094 |
} catch (BadLocationException exception) { |
2775 |
reconciled(ast, positionTracker, null); |
2095 |
// Should not happen |
2776 |
} finally { |
|
|
2777 |
positionTracker.stopTracking(); |
2096 |
} |
2778 |
} |
2097 |
} |
2779 |
} |
2098 |
|
2780 |
} |
2099 |
/* |
2781 |
|
2100 |
* @see org.eclipse.cdt.internal.ui.editor.CEditor.PreviousSubWordAction#findPreviousPosition(int) |
2782 |
public CSourceViewer getCSourceViewer() { |
2101 |
*/ |
2783 |
ISourceViewer viewer = getSourceViewer(); |
2102 |
protected int findPreviousPosition(int position) { |
2784 |
CSourceViewer cViewer = null ; |
2103 |
return fIterator.preceding(position); |
2785 |
if (viewer instanceof CSourceViewer) { |
2104 |
} |
2786 |
cViewer = (CSourceViewer) viewer; |
2105 |
|
|
|
2106 |
/* |
2107 |
* @see org.eclipse.ui.texteditor.IUpdate#update() |
2108 |
*/ |
2109 |
public void update() { |
2110 |
setEnabled(isEditorInputModifiable()); |
2111 |
} |
2787 |
} |
|
|
2788 |
return cViewer ; |
2112 |
} |
2789 |
} |
2113 |
|
2790 |
|
2114 |
/** |
2791 |
/* |
2115 |
* Text operation action to select the previous sub-word. |
2792 |
* @see org.eclipse.ui.texteditor.AbstractDecoratedTextEditor#collectContextMenuPreferencePages() |
2116 |
* |
|
|
2117 |
* @since 4.0 |
2118 |
*/ |
2793 |
*/ |
2119 |
protected class SelectPreviousSubWordAction extends PreviousSubWordAction { |
2794 |
protected String[] collectContextMenuPreferencePages() { |
2120 |
|
2795 |
// Add C/C++ Editor relevant pages |
2121 |
/** |
2796 |
String[] parentPrefPageIds = super.collectContextMenuPreferencePages(); |
2122 |
* Creates a new select previous sub-word action. |
2797 |
String[] prefPageIds = new String[parentPrefPageIds.length + 5]; |
2123 |
*/ |
2798 |
int nIds = 0; |
2124 |
public SelectPreviousSubWordAction() { |
2799 |
prefPageIds[nIds++] = "org.eclipse.cdt.ui.preferences.CEditorPreferencePage"; //$NON-NLS-1$ |
2125 |
super(ST.SELECT_WORD_PREVIOUS); |
2800 |
prefPageIds[nIds++] = "org.eclipse.cdt.ui.preferences.CodeAssistPreferencePage"; //$NON-NLS-1$ |
2126 |
} |
2801 |
prefPageIds[nIds++] = "org.eclipse.cdt.ui.preferences.TemplatePreferencePage"; //$NON-NLS-1$ |
2127 |
|
2802 |
prefPageIds[nIds++] = "org.eclipse.cdt.ui.preferences.SmartTypingPreferencePage"; //$NON-NLS-1$ |
2128 |
/* |
2803 |
prefPageIds[nIds++] = "org.eclipse.cdt.ui.preferences.CodeFormatterPreferencePage"; //$NON-NLS-1$ |
2129 |
* @see org.eclipse.cdt.internal.ui.editor.CEditor.PreviousSubWordAction#setCaretPosition(int) |
2804 |
System.arraycopy(parentPrefPageIds, 0, prefPageIds, nIds, parentPrefPageIds.length); |
2130 |
*/ |
2805 |
return prefPageIds; |
2131 |
protected void setCaretPosition(final int position) { |
|
|
2132 |
final ISourceViewer viewer = getSourceViewer(); |
2133 |
|
2134 |
final StyledText text = viewer.getTextWidget(); |
2135 |
if (text != null && !text.isDisposed()) { |
2136 |
|
2137 |
final Point selection = text.getSelection(); |
2138 |
final int caret = text.getCaretOffset(); |
2139 |
final int offset = modelOffset2WidgetOffset(viewer, position); |
2140 |
|
2141 |
if (caret == selection.x) |
2142 |
text.setSelectionRange(selection.y, offset - selection.y); |
2143 |
else |
2144 |
text.setSelectionRange(selection.x, offset - selection.x); |
2145 |
} |
2146 |
} |
2147 |
} |
2806 |
} |
2148 |
|
2807 |
|
2149 |
/* |
2808 |
/* |