|
Lines 12-18
Link Here
|
| 12 |
import java.util.Iterator; |
12 |
import java.util.Iterator; |
| 13 |
import java.util.List; |
13 |
import java.util.List; |
| 14 |
|
14 |
|
|
|
15 |
import org.eclipse.core.commands.IHandler; |
| 15 |
import org.eclipse.core.resources.IMarker; |
16 |
import org.eclipse.core.resources.IMarker; |
|
|
17 |
import org.eclipse.jface.action.Action; |
| 18 |
import org.eclipse.jface.commands.ActionHandler; |
| 16 |
import org.eclipse.jface.text.DefaultInformationControl; |
19 |
import org.eclipse.jface.text.DefaultInformationControl; |
| 17 |
import org.eclipse.jface.text.Document; |
20 |
import org.eclipse.jface.text.Document; |
| 18 |
import org.eclipse.jface.text.IInformationControl; |
21 |
import org.eclipse.jface.text.IInformationControl; |
|
Lines 27-42
Link Here
|
| 27 |
import org.eclipse.jface.text.TextViewer; |
30 |
import org.eclipse.jface.text.TextViewer; |
| 28 |
import org.eclipse.jface.text.source.Annotation; |
31 |
import org.eclipse.jface.text.source.Annotation; |
| 29 |
import org.eclipse.jface.text.source.AnnotationModel; |
32 |
import org.eclipse.jface.text.source.AnnotationModel; |
| 30 |
import org.eclipse.jface.text.source.AnnotationPainter; |
|
|
| 31 |
import org.eclipse.jface.text.source.AnnotationRulerColumn; |
| 32 |
import org.eclipse.jface.text.source.CompositeRuler; |
| 33 |
import org.eclipse.jface.text.source.IAnnotationAccess; |
33 |
import org.eclipse.jface.text.source.IAnnotationAccess; |
| 34 |
import org.eclipse.jface.text.source.IAnnotationAccessExtension; |
34 |
import org.eclipse.jface.text.source.IAnnotationAccessExtension; |
| 35 |
import org.eclipse.jface.text.source.IAnnotationHover; |
35 |
import org.eclipse.jface.text.source.IAnnotationHover; |
| 36 |
import org.eclipse.jface.text.source.ISharedTextColors; |
36 |
import org.eclipse.jface.text.source.ISharedTextColors; |
| 37 |
import org.eclipse.jface.text.source.ISourceViewer; |
37 |
import org.eclipse.jface.text.source.ISourceViewer; |
| 38 |
import org.eclipse.jface.text.source.ImageUtilities; |
38 |
import org.eclipse.jface.text.source.ImageUtilities; |
| 39 |
import org.eclipse.jface.text.source.OverviewRuler; |
39 |
import org.eclipse.jface.text.source.SourceViewer; |
| 40 |
import org.eclipse.mylyn.internal.tasks.ui.TaskListColorsAndFonts; |
40 |
import org.eclipse.mylyn.internal.tasks.ui.TaskListColorsAndFonts; |
| 41 |
import org.eclipse.mylyn.internal.tasks.ui.editors.RepositoryTextViewer; |
41 |
import org.eclipse.mylyn.internal.tasks.ui.editors.RepositoryTextViewer; |
| 42 |
import org.eclipse.mylyn.internal.tasks.ui.editors.RepositoryViewerConfig; |
42 |
import org.eclipse.mylyn.internal.tasks.ui.editors.RepositoryViewerConfig; |
|
Lines 44-49
Link Here
|
| 44 |
import org.eclipse.mylyn.tasks.core.TaskRepository; |
44 |
import org.eclipse.mylyn.tasks.core.TaskRepository; |
| 45 |
import org.eclipse.swt.SWT; |
45 |
import org.eclipse.swt.SWT; |
| 46 |
import org.eclipse.swt.custom.StyledText; |
46 |
import org.eclipse.swt.custom.StyledText; |
|
|
47 |
import org.eclipse.swt.events.DisposeEvent; |
| 48 |
import org.eclipse.swt.events.DisposeListener; |
| 47 |
import org.eclipse.swt.events.FocusEvent; |
49 |
import org.eclipse.swt.events.FocusEvent; |
| 48 |
import org.eclipse.swt.events.FocusListener; |
50 |
import org.eclipse.swt.events.FocusListener; |
| 49 |
import org.eclipse.swt.graphics.Color; |
51 |
import org.eclipse.swt.graphics.Color; |
|
Lines 57-66
Link Here
|
| 57 |
import org.eclipse.swt.widgets.Display; |
59 |
import org.eclipse.swt.widgets.Display; |
| 58 |
import org.eclipse.swt.widgets.Shell; |
60 |
import org.eclipse.swt.widgets.Shell; |
| 59 |
import org.eclipse.swt.widgets.Text; |
61 |
import org.eclipse.swt.widgets.Text; |
|
|
62 |
import org.eclipse.ui.ActiveShellExpression; |
| 63 |
import org.eclipse.ui.PlatformUI; |
| 60 |
import org.eclipse.ui.actions.ActionFactory; |
64 |
import org.eclipse.ui.actions.ActionFactory; |
|
|
65 |
import org.eclipse.ui.editors.text.EditorsUI; |
| 66 |
import org.eclipse.ui.editors.text.TextSourceViewerConfiguration; |
| 61 |
import org.eclipse.ui.forms.IManagedForm; |
67 |
import org.eclipse.ui.forms.IManagedForm; |
| 62 |
import org.eclipse.ui.forms.editor.FormEditor; |
68 |
import org.eclipse.ui.forms.editor.FormEditor; |
| 63 |
import org.eclipse.ui.forms.editor.FormPage; |
69 |
import org.eclipse.ui.forms.editor.FormPage; |
|
|
70 |
import org.eclipse.ui.handlers.IHandlerActivation; |
| 71 |
import org.eclipse.ui.handlers.IHandlerService; |
| 72 |
import org.eclipse.ui.texteditor.AnnotationPreference; |
| 73 |
import org.eclipse.ui.texteditor.DefaultMarkerAnnotationAccess; |
| 74 |
import org.eclipse.ui.texteditor.ITextEditorActionDefinitionIds; |
| 75 |
import org.eclipse.ui.texteditor.MarkerAnnotationPreferences; |
| 76 |
import org.eclipse.ui.texteditor.SourceViewerDecorationSupport; |
| 64 |
import org.eclipse.ui.themes.IThemeManager; |
77 |
import org.eclipse.ui.themes.IThemeManager; |
| 65 |
|
78 |
|
| 66 |
/** |
79 |
/** |
|
Lines 69-74
Link Here
|
| 69 |
* NOTE: likely to change for 3.0. |
82 |
* NOTE: likely to change for 3.0. |
| 70 |
* |
83 |
* |
| 71 |
* @author Rob Elves |
84 |
* @author Rob Elves |
|
|
85 |
* @author Eugene Kuleshov (spelling correction) |
| 86 |
* |
| 72 |
* @ref: PDEFormPage.class ref: |
87 |
* @ref: PDEFormPage.class ref: |
| 73 |
* @ref: http://dev.eclipse.org/newslists/news.eclipse.platform.swt/msg19676.html |
88 |
* @ref: http://dev.eclipse.org/newslists/news.eclipse.platform.swt/msg19676.html |
| 74 |
*/ |
89 |
*/ |
|
Lines 80-87
Link Here
|
| 80 |
|
95 |
|
| 81 |
protected List<TextViewer> textViewers = new ArrayList<TextViewer>(); |
96 |
protected List<TextViewer> textViewers = new ArrayList<TextViewer>(); |
| 82 |
|
97 |
|
| 83 |
private static final ISharedTextColors sharedTextColors = new SharedTextColors(); |
|
|
| 84 |
|
| 85 |
private void addTextViewer(TextViewer viewer) { |
98 |
private void addTextViewer(TextViewer viewer) { |
| 86 |
textViewers.add(viewer); |
99 |
textViewers.add(viewer); |
| 87 |
} |
100 |
} |
|
Lines 304-352
Link Here
|
| 304 |
actionContributor = ((TaskEditor) getEditor()).getContributor(); |
317 |
actionContributor = ((TaskEditor) getEditor()).getContributor(); |
| 305 |
} |
318 |
} |
| 306 |
|
319 |
|
| 307 |
CompositeRuler fCompositeRuler = null; |
320 |
AnnotationModel annotationModel = new AnnotationModel(); |
| 308 |
OverviewRuler fOverviewRuler = null; |
321 |
final RepositoryTextViewer commentViewer = new RepositoryTextViewer(null, null, repository, composite, style); |
| 309 |
IAnnotationAccess fAnnotationAccess = null; |
322 |
commentViewer.showAnnotations(false); |
| 310 |
AnnotationRulerColumn annotationRuler = null; |
323 |
commentViewer.showAnnotationsOverview(false); |
| 311 |
|
|
|
| 312 |
AnnotationModel fAnnotationModel = null; |
| 313 |
|
| 314 |
if (true) { |
| 315 |
fAnnotationModel = new AnnotationModel(); |
| 316 |
fAnnotationAccess = new AnnotationMarkerAccess(); |
| 317 |
|
| 318 |
fCompositeRuler = new CompositeRuler(); |
| 319 |
fOverviewRuler = new OverviewRuler(fAnnotationAccess, 12, sharedTextColors); |
| 320 |
annotationRuler = new AnnotationRulerColumn(fAnnotationModel, 16, fAnnotationAccess); |
| 321 |
fCompositeRuler.setModel(fAnnotationModel); |
| 322 |
fOverviewRuler.setModel(fAnnotationModel); |
| 323 |
|
| 324 |
// annotation ruler is decorating our composite ruler |
| 325 |
fCompositeRuler.addDecorator(0, annotationRuler); |
| 326 |
|
| 327 |
// what types are show on the different rulers |
| 328 |
annotationRuler.addAnnotationType(ErrorAnnotation.ERROR_TYPE); |
| 329 |
fOverviewRuler.addAnnotationType(ErrorAnnotation.ERROR_TYPE); |
| 330 |
|
324 |
|
| 331 |
fOverviewRuler.addHeaderAnnotationType(ErrorAnnotation.ERROR_TYPE); |
325 |
IAnnotationAccess annotationAccess = new DefaultMarkerAnnotationAccess(); |
| 332 |
fOverviewRuler.setAnnotationTypeLayer(ErrorAnnotation.ERROR_TYPE, 3); |
|
|
| 333 |
|
326 |
|
| 334 |
fOverviewRuler.setAnnotationTypeColor(ErrorAnnotation.ERROR_TYPE, |
327 |
final SourceViewerDecorationSupport support = new SourceViewerDecorationSupport(commentViewer, null, |
| 335 |
TaskListColorsAndFonts.COLOR_SPELLING_ERROR); |
328 |
annotationAccess, EditorsUI.getSharedTextColors()); |
| 336 |
|
329 |
|
|
|
330 |
@SuppressWarnings("unchecked") |
| 331 |
Iterator e = new MarkerAnnotationPreferences().getAnnotationPreferences().iterator(); |
| 332 |
while (e.hasNext()) { |
| 333 |
support.setAnnotationPreference((AnnotationPreference) e.next()); |
| 337 |
} |
334 |
} |
| 338 |
final RepositoryTextViewer commentViewer = new RepositoryTextViewer(fCompositeRuler, fOverviewRuler, |
|
|
| 339 |
repository, composite, style); |
| 340 |
commentViewer.showAnnotations(false); |
| 341 |
commentViewer.showAnnotationsOverview(false); |
| 342 |
|
335 |
|
| 343 |
// to paint the annotations |
336 |
support.install(EditorsUI.getPreferenceStore()); |
| 344 |
final AnnotationPainter ap = new AnnotationPainter(commentViewer, fAnnotationAccess); |
337 |
|
| 345 |
ap.addAnnotationType(ErrorAnnotation.ERROR_TYPE); |
338 |
commentViewer.getTextWidget().addDisposeListener(new DisposeListener() { |
| 346 |
ap.setAnnotationTypeColor(ErrorAnnotation.ERROR_TYPE, TaskListColorsAndFonts.COLOR_SPELLING_ERROR); |
339 |
public void widgetDisposed(DisposeEvent e) { |
|
|
340 |
support.uninstall(); |
| 341 |
} |
| 342 |
}); |
| 347 |
|
343 |
|
| 348 |
// this will draw the squigglies under the text |
344 |
final IHandlerService handlerService = (IHandlerService) PlatformUI.getWorkbench().getService( |
| 349 |
commentViewer.addPainter(ap); |
345 |
IHandlerService.class); |
| 350 |
|
346 |
|
| 351 |
IThemeManager themeManager = getSite().getWorkbenchWindow().getWorkbench().getThemeManager(); |
347 |
IThemeManager themeManager = getSite().getWorkbenchWindow().getWorkbench().getThemeManager(); |
| 352 |
|
348 |
|
|
Lines 356-372
Link Here
|
| 356 |
commentViewer.addSelectionChangedListener(actionContributor); |
352 |
commentViewer.addSelectionChangedListener(actionContributor); |
| 357 |
|
353 |
|
| 358 |
commentViewer.getTextWidget().addFocusListener(new FocusListener() { |
354 |
commentViewer.getTextWidget().addFocusListener(new FocusListener() { |
| 359 |
|
355 |
private IHandlerActivation handlerActivation; |
|
|
356 |
|
| 360 |
public void focusGained(FocusEvent e) { |
357 |
public void focusGained(FocusEvent e) { |
| 361 |
|
|
|
| 362 |
actionContributor.updateSelectableActions(commentViewer.getSelection()); |
358 |
actionContributor.updateSelectableActions(commentViewer.getSelection()); |
| 363 |
|
359 |
|
|
|
360 |
handlerActivation = handlerService.activateHandler( |
| 361 |
ITextEditorActionDefinitionIds.QUICK_ASSIST, createQuickFixActionHandler(commentViewer), |
| 362 |
new ActiveShellExpression(commentViewer.getTextWidget().getShell())); |
| 364 |
} |
363 |
} |
| 365 |
|
364 |
|
| 366 |
public void focusLost(FocusEvent e) { |
365 |
public void focusLost(FocusEvent e) { |
| 367 |
StyledText st = (StyledText) e.widget; |
366 |
StyledText st = (StyledText) e.widget; |
| 368 |
st.setSelectionRange(st.getCaretOffset(), 0); |
367 |
st.setSelectionRange(st.getCaretOffset(), 0); |
| 369 |
actionContributor.forceActionsEnabled(); |
368 |
actionContributor.forceActionsEnabled(); |
|
|
369 |
|
| 370 |
if(handlerActivation!=null) { |
| 371 |
handlerService.deactivateHandler(handlerActivation); |
| 372 |
} |
| 370 |
} |
373 |
} |
| 371 |
}); |
374 |
}); |
| 372 |
|
375 |
|
|
Lines 380-422
Link Here
|
| 380 |
commentViewer.getTextWidget().setMenu(getManagedForm().getForm().getMenu()); |
383 |
commentViewer.getTextWidget().setMenu(getManagedForm().getForm().getMenu()); |
| 381 |
Document document = new Document(text); |
384 |
Document document = new Document(text); |
| 382 |
|
385 |
|
| 383 |
// NOTE: Configuration must be applied before the document is set in |
386 |
// NOTE: Configuration must be applied before the document is set in order for |
| 384 |
// order for |
387 |
// Hyperlink coloring to work. (Presenter needs document object up front) |
| 385 |
// Hyperlink colouring to work. (Presenter needs document object up |
388 |
TextSourceViewerConfiguration viewerConfig = new RepositoryViewerConfig(spellCheck); |
| 386 |
// front) |
389 |
commentViewer.configure(viewerConfig); |
| 387 |
RepositoryViewerConfig repositoryViewerConfig = new RepositoryViewerConfig(spellCheck); |
|
|
| 388 |
repositoryViewerConfig.setAnnotationModel(fAnnotationModel, document); |
| 389 |
commentViewer.configure(repositoryViewerConfig); |
| 390 |
|
390 |
|
| 391 |
commentViewer.setDocument(document, fAnnotationModel); |
391 |
commentViewer.setDocument(document, annotationModel); |
| 392 |
|
392 |
|
| 393 |
// !DND! hover manager that shows text when we hover |
393 |
// !DND! hover manager that shows text when we hover |
| 394 |
// AnnotationBarHoverManager fAnnotationHoverManager = new |
394 |
// AnnotationBarHoverManager fAnnotationHoverManager = new AnnotationBarHoverManager(fCompositeRuler, |
| 395 |
// AnnotationBarHoverManager(fCompositeRuler, |
395 |
// commentViewer, new AnnotationHover(fAnnotationModel), new AnnotationConfiguration()); |
| 396 |
// commentViewer, new AnnotationHover(fAnnotationModel), new |
|
|
| 397 |
// AnnotationConfiguration()); |
| 398 |
// fAnnotationHoverManager.install(annotationRuler.getControl()); |
396 |
// fAnnotationHoverManager.install(annotationRuler.getControl()); |
| 399 |
|
397 |
|
| 400 |
// !DND! Sample debugging code |
398 |
// !DND! Sample debugging code |
| 401 |
// document.set("Here's some texst so that we have somewhere to show an |
399 |
// document.set("Here's some texst so that we have somewhere to show an error"); |
| 402 |
// error"); |
|
|
| 403 |
// |
400 |
// |
| 404 |
// // // add an annotation |
401 |
// // // add an annotation |
| 405 |
// ErrorAnnotation errorAnnotation = new ErrorAnnotation(1, ""); |
402 |
// ErrorAnnotation errorAnnotation = new ErrorAnnotation(1, ""); |
| 406 |
// // lets underline the word "texst" |
403 |
// // lets underline the word "texst" |
| 407 |
// fAnnotationModel.addAnnotation(errorAnnotation, new Position(12, 5)); |
404 |
// fAnnotationModel.addAnnotation(errorAnnotation, new Position(12, 5)); |
| 408 |
|
405 |
|
| 409 |
// CoreSpellingProblem iProblem = new CoreSpellingProblem(12, 5, 1, |
406 |
// CoreSpellingProblem iProblem = new CoreSpellingProblem(12, 5, 1, |
| 410 |
// "problem message", "theword", false, false, |
407 |
// "problem message", "theword", false, false, document, "task editor"); |
| 411 |
// document, "task editor");// editorInput.getName() |
408 |
// editorInput.getName() |
| 412 |
// |
409 |
// |
| 413 |
// fAnnotationModel.addAnnotation(new ProblemAnnotation(iProblem, null), |
410 |
// fAnnotationModel.addAnnotation(new ProblemAnnotation(iProblem, null), new Position(12, 5)); |
| 414 |
// new Position(12, 5)); |
|
|
| 415 |
|
411 |
|
| 416 |
addTextViewer(commentViewer); |
412 |
addTextViewer(commentViewer); |
| 417 |
return commentViewer; |
413 |
return commentViewer; |
| 418 |
} |
414 |
} |
| 419 |
|
415 |
|
|
|
416 |
private IHandler createQuickFixActionHandler(final SourceViewer viewer) { |
| 417 |
Action quickFixAction = new Action() { |
| 418 |
public void run() { |
| 419 |
if (viewer.canDoOperation(ISourceViewer.QUICK_ASSIST)) { |
| 420 |
viewer.doOperation(ISourceViewer.QUICK_ASSIST); |
| 421 |
} |
| 422 |
} |
| 423 |
}; |
| 424 |
quickFixAction.setActionDefinitionId(ITextEditorActionDefinitionIds.QUICK_ASSIST); |
| 425 |
return new ActionHandler(quickFixAction); |
| 426 |
} |
| 427 |
|
| 420 |
@Override |
428 |
@Override |
| 421 |
public boolean isDirty() { |
429 |
public boolean isDirty() { |
| 422 |
return isDirty; |
430 |
return isDirty; |