3

I would like to write the location of a file to the eclipse console as a hyperlink. When you click on it it should open the file in eclipse. I'm currently doing something like this (but the link doesn't show up)

console = new MessageConsole("myconsole", null);
console.activate();
ConsolePlugin.getDefault().getConsoleManager().addConsoles(new IConsole[]{ console });

IPath path = Path.fromOSString(filePath);
IFile file = ResourcesPlugin.getWorkspace().getRoot().getFileForLocation(path);
FileLink fileLink = new FileLink(file, null, 0, 0, 0);
console.addHyperlink(fileLink, 0, 0);

I should probably not pass in 0 for the offset, filelength parameters etc.

Any help appreciated.

SebastianWilke
  • 470
  • 1
  • 4
  • 15
Benjamin
  • 539
  • 2
  • 6
  • 16

2 Answers2

5

Well, turns out the code I wrote is fine except for 2 minor changes it should actually be

console = new MessageConsole("myconsole", null);
console.activate();
ConsolePlugin.getDefault().getConsoleManager().addConsoles(new IConsole[]{ console });

IPath path = Path.fromOSString(filePath);
IFile file = ResourcesPlugin.getWorkspace().getRoot().getFileForLocation(path);
FileLink fileLink = new FileLink(file, null, -1, -1, -1);
console.addHyperlink(fileLink, 10, 5); 

I was a little suprised that the offset (10) had to be provided, which counts from the beginning of the console output. Why would you even want to calculate that yourself, but that's another discussion.

Jon
  • 398
  • 1
  • 11
Benjamin
  • 539
  • 2
  • 6
  • 16
1

If you write (filename:linenumber) it will all happen automatically.

Also see How to get Eclipse Console to hyperlink text to source code files?

Community
  • 1
  • 1
Tonny Madsen
  • 12,628
  • 4
  • 31
  • 70