Changing color of text in editor [message #324159] |
Thu, 17 January 2008 22:51  |
Eclipse User |
|
|
|
Originally posted by: nazdak9.gmail.com
Hi everyone,
At the moment I'm using the following code to allow a user to change a highlighted piece of text (in the standard Java editor) to uppercase:
IDocument document = editor.getDocumentProvider().getDocument(editor.getEditorInp ut());
ISelectionProvider selectionProvider = editor.getSelectionProvider();
ITextSelection selection = (ITextSelection) selectionProvider.getSelection();
String text = selection.getText();
String newText = text.toUpperCase();
document.replace(selection.getOffset(), selection.getLength(), newText);
What i really want to do however, is change the color of the selected text, instead of the case. Does anyone know how I might do this?
Cheers.
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Re: Changing color of text in editor [message #324722 is a reply to message #324699] |
Thu, 31 January 2008 04:33  |
Eclipse User |
|
|
|
Shane wrote:
>Hi Dani.
>
>First of all thanks for your responses.
>I see what you mean now by users continuing to type within a range. If they do so their input will be displayed as normal, without any color changes (i.e. back to the default black).
>
>The code I posted does what I want, except it changes case instead of color.
>
>Unfortunately, the editor is not mine, but rather the default JDT java editor in eclipse. I just thought that as there is a way to capture text and change case, their must be a way to change color also.
>
>Any ideas?
>
>
You can do it via annotation: instead of getting the document from the
doc provider you ask for the annotation model and add an annotation of
your newly defined annotation type.
See the following extension points:
org.eclipse.ui.editors.annotationTypes
org.eclipse.ui.editors.markerAnnotationSpecification
Dani
|
|
|
Powered by
FUDForum. Page generated in 0.07831 seconds