如何从插件编写到 Eclipse 控制台的超链接

2022-01-16 00:00:00 eclipse-plugin java eclipse

我想将文件的位置作为超链接写入 Eclipse 控制台.当您单击它时,它应该在 eclipse 中打开该文件.我目前正在做这样的事情(但链接不显示)

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);

我可能不应该为偏移量、文件长度参数等传入 0.

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

任何帮助表示赞赏.

推荐答案

好吧,结果我写的代码很好,除了 2 个小改动它实际上应该是

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); 

我有点惊讶必须提供偏移量 (10),它从控制台输出的开头开始计算.为什么你甚至想自己计算,但这是另一个讨论.

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.

相关文章