Text Highlighting [message #330633] |
Wed, 06 August 2008 12:54  |
Eclipse User |
|
|
|
Hi,
Provided "file names" and "line numbers", How can i highlight given lines
in corresponding text editors of the active project?
Thanks,
Sana
|
|
|
Re: Text Highlighting [message #330640 is a reply to message #330633] |
Wed, 06 August 2008 17:47   |
Eclipse User |
|
|
|
sana wrote:
> Hi,
>
> Provided "file names" and "line numbers", How can i highlight given
> lines in corresponding text editors of the active project?
> Thanks,
> Sana
>
I assume "file names" here the IPaths to the files/resources in the
workspace? If so, a couple hints:
a) Use IDE.openEditor(....) to open the IResource found from an IPath.
That should open the correct editor or the default editor for that resource.
b) IDE.openEditor(...) returns an IEditorPart and from there somehow you
get the ITextViewer. See
org.eclipse.jface.text.DefaultTextDoubleClickStrategy to see how to
highlight the text given an ITextViewer. (See the
doubleClicked(ITextViewer) method.)
Hope that helps.
|
|
|
Re: Text Highlighting [message #330644 is a reply to message #330640] |
Thu, 07 August 2008 06:25   |
Eclipse User |
|
|
|
You can also use markers to hilight stuff.
You have to define a marker type in the Manifest.mf and set its hilight
color there.
To create a marker of that type which hilights a specific line and add it
to the resource:
IDocument
document=editor.getDocumentProvider().getDocument(editor.get EditorInput());
String markerName="myMarker";//the id of the marker in the
manifest
//Create the marker
IMarker newMarker=resource.createMarker(markerName);
newMarker.setAttribute(IMarker.LINE_NUMBER, lineNumber);
int charStart=document.getLineOffset(lineNumber);
newMarker.setAttribute(IMarker.CHAR_START,charStart);
int charEnd=charStart+document.getLineLength(lineNumber);
newMarker.setAttribute(IMarker.CHAR_END, charEnd);
|
|
|
Re: Text Highlighting [message #330653 is a reply to message #330640] |
Thu, 07 August 2008 12:33   |
Eclipse User |
|
|
|
You r right.. file names are indeed the IPaths to Resources..
1)I managed to get IEditorPart from IDE.openEditor(IWorkbenchPage,IFile)
2)However , i did not manage to get the ITextViewer from IEditorPart...
any more hints..
thanks,
sana.
|
|
|
Re: Text Highlighting [message #330654 is a reply to message #330644] |
Thu, 07 August 2008 12:39   |
Eclipse User |
|
|
|
How exactly should i define marker type??
I have added "org.eclipse.core.resources.markers" extension. but this
does not have any highlight color attribute.
Thanks,
sana
|
|
|
Re: Text Highlighting [message #330721 is a reply to message #330653] |
Mon, 11 August 2008 22:01   |
Eclipse User |
|
|
|
sana wrote:
> You r right.. file names are indeed the IPaths to Resources..
>
> 1)I managed to get IEditorPart from IDE.openEditor(IWorkbenchPage,IFile)
>
> 2)However , i did not manage to get the ITextViewer from IEditorPart...
> any more hints..
>
For step 2. Once you get the IEditorPart, test if it's an instance of
AbstractDecoratedTextEditor. If so, cast to it, and call
getSourceViewer(), which returns a SourceViewer that implements
ISourceViewer. SourceViewer extends TextViewer :-)
> thanks,
> sana.
>
|
|
|
Re: Text Highlighting [message #330780 is a reply to message #330654] |
Wed, 13 August 2008 12:55  |
Eclipse User |
|
|
|
Here's an example:
<extension
id="com.ibm.seecode.resources.LineMod4Marker"
name="LineMod4Marker"
point="org.eclipse.core.resources.markers">
<super type="org.eclipse.core.resources.marker"/>
<persistent value="false"/>
</extension>
<extension
id="org.eclipse.irtviewer.LineMod4AnnotationSpecification"
name="LineMod4AnnotationSpecification"
point="org.eclipse.ui.editors.markerAnnotationSpecification ">
<specification
annotationType="com.ibm.seecode.LineMod4"
colorPreferenceKey="LM4SearchResultIndicationColor"
colorPreferenceValue="255,165,127"
contributesToHeader="true"
highlightPreferenceKey="LM4SearchResultHighlighting"
highlightPreferenceValue="true"
includeOnPreferencePage="true"
isGoToNextNavigationTarget="true"
isGoToNextNavigationTargetKey="LM4IsSearchResultGoToNextNavigationTarget "
isGoToPreviousNavigationTarget="true"
isGoToPreviousNavigationTargetKey="LM4IsSearchResultGoToPreviousNavigationTarget "
label="LineMod4"
overviewRulerPreferenceKey="LM4SearchResultIndicationInOverviewRuler "
overviewRulerPreferenceValue="true"
showInNextPrevDropdownToolbarAction="true"
showInNextPrevDropdownToolbarActionKey="LM4ShowSearchResultInNextPrevDropdownToolbarAction "
textPreferenceKey="LM4SearchResultIndication"
textPreferenceValue="false"
verticalRulerPreferenceKey="LM4SearchResultIndicationInVerticalRuler "
verticalRulerPreferenceValue="true">
</specification>
</extension>
<extension
point="org.eclipse.ui.editors.annotationTypes">
<type
markerType="com.ibm.seecode.resources.LineMod4Marker"
name="com.ibm.seecode.LineMod4">
</type>
</extension>
|
|
|
Powered by
FUDForum. Page generated in 0.03122 seconds