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