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

时间:2009-02-26 15:29:28

标签: eclipse eclipse-plugin

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

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传递offset,filelength参数等。

任何帮助表示感谢。

2 个答案:

答案 0 :(得分:4)

好吧,事实证明我编写的代码很好,除了它应该实际上是2次微小更改

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),从控制台输出的开头算起。你为什么甚至想自己计算一下,但这是另一个讨论。

答案 1 :(得分:1)

如果你写(filename:linenumber),它将全部自动发生。

另见How to get Eclipse Console to hyperlink text to source code files?

相关问题