【问题标题】:How to write a hyperlink to an eclipse console from a plugin如何从插件编写到 Eclipse 控制台的超链接
【发布时间】:2010-10-10 02:43:20
【问题描述】:

我想将文件的位置作为超链接写入 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。

任何帮助表示赞赏。

【问题讨论】:

    标签: java eclipse eclipse-plugin


    【解决方案1】:

    好吧,结果我写的代码很好,除了 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),它从控制台输出的开头开始计算。为什么你甚至想自己计算,但这是另一个讨论。

    【讨论】:

      【解决方案2】:

      如果你写(filename:linenumber),这一切都会自动发生。

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

      【讨论】:

        猜你喜欢
        • 2021-04-27
        • 1970-01-01
        • 2017-07-16
        • 2011-09-22
        • 2011-10-08
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多