Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to offer links in an eclipse editor plugin?

I'm writing an eclipse editor plugin for a custom file format and want to offer a way to quickly jump to the definition of an entity from a named reference to it - basically the "open declaration" functionality of the eclipse Java editor.

I know I can do this by registering an editor action and putting it in the context menu, but I'd really like the way all Java identifiers turn into links to their declaration when you press CTRL in the Java editor - how can I do that? I can't find anything about it in the documentation.

like image 496
Michael Borgwardt Avatar asked Jan 03 '09 20:01

Michael Borgwardt


People also ask

How do I create a link in Eclipse?

In eclipse, you can paste the link to a comment, hold down control and click it. If you want to be able to just press it without holding anything down, go to Window -> Preferences -> General -> Editors -> Text Editors -> Hyperlinking, then click on URL and remove the modifier key, click apply, click ok and you're done!

How to make a text editor in Eclipse?

Eclipse projects If you want to use Eclipse to create arbitrary text files that are not associated with a code project, then you can create a project file just for your text files. To create a new project, navigate to the File menu and select New Project. From the list of project templates, select General.

What is text editor in Eclipse?

The text editor framework provides the abstract implementation of an Eclipse text editor. The File Buffers plug-in which introduces text file buffers for shared access to the content of a text file in form of an IDocument and and associated IAnnotationModel.

How do I find the editor in Eclipse?

Tip. You can set which Eclipse editor or external program to use to open a specific type of file based on its file extension. Just select Window→ Preferences→ Workbench→ File Associations, select the file type, and associate an editor or program with it (if nothing else, you can use Eclipse's default text editor).


1 Answers

I think you are looking for hyper link detectors. Extension point is: org.eclipse.ui.workbench.texteditor.hyperlinkDetectors, Here is snippet from Mylyn plugin.xml:

<extension point="org.eclipse.ui.workbench.texteditor.hyperlinkDetectors">
  <hyperlinkDetector            
        class="org.eclipse.mylyn.internal.tasks.ui.editors.TaskHyperlinkDetector"
        id="org.eclipse.mylyn.tasks.ui.hyperlinks.detectors.task"
        name="%TaskHyperlinkDetector.name"
        targetId="org.eclipse.ui.DefaultTextEditor">
  </hyperlinkDetector>

Also check out AbstractHyperlinkDetector, useful abstract class you can extend to provide your custom detector.

like image 119
Peter Štibraný Avatar answered Oct 28 '22 14:10

Peter Štibraný