如何从插件编写到 Eclipse 控制台的超链接 [英] How to write a hyperlink to an eclipse console from a plugin

查看:20
本文介绍了如何从插件编写到 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.

这篇关于如何从插件编写到 Eclipse 控制台的超链接的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆