【问题标题】:NetBeans plugin - open file at specific line and columnNetBeans 插件 - 在特定行和列打开文件
【发布时间】:2014-03-15 21:36:29
【问题描述】:

我想在 NetBeans 编辑器中的特定行和行打开由其路径指定的文件。 我想要与某些 Java/C/C++ 或任何其他编程语言打印异常时相同的功能。 就我目前而言:

  1. 在控制台中写入异常
  2. 通过使用 OutputListener 解决应该打印为超文本的内容
  3. OutputListener.outputLineAction 定义单击超文本时要执行的操作
  4. ---这里我不知道该怎么办---

我需要解决的错误消息示例:

E ERRORCODE: error definition; line=2; column=30; source='file:/C:/...'

如何在文本编辑器中打开插件中的文件并指向特定的行和列?

【问题讨论】:

    标签: java plugins netbeans netbeans-plugins


    【解决方案1】:

    http://wiki.netbeans.org/DevFaqOpenFileAtLine

    LineCookie - 见https://forums.netbeans.org/topic59253.html

    NbDocument#openDocument() - 见http://bits.netbeans.org/dev/javadoc/org-openide-text/org/openide/text/NbDocument.html#openDocument(org.openide.util.Lookup.Provider, int, int, org.openide.text.Line.ShowOpenType, org.openide.text.Line.ShowVisibilityType)


    使用LineCookie的示例

        FileObject fo = null;
        LineCookie lc = DataObject.find(fo).getLookup().lookup(LineCookie.class);
        int lineNumber=42;
        int colNumber=43;
        Line line = lc.getLineSet().getOriginal(lineNumber);
        line.show(Line.ShowOpenType.OPEN, Line.ShowVisibilityType.FRONT, colNumber);
    

    更多示例在

    【讨论】:

    • 我相信 NbDocument.openDocument 可能是正确的方法。但是我真的不知道如何使用 Lookup 和 Lookup.provider。作为查找,我使用Lookup lookup = Lookups.forPath(path_ref);,其中 path_ref 是我要打开的文件的字符串路径,然后 Lookup.Provider 使用此查找。问题是,openDocument() 方法不返回 true(并且不显示任何内容)。
    • 参见上面的代码示例。 LineCookie 应该可以胜任。
    • 我花了一段时间才回到我的电脑,但我必须感谢你! FileObject可以通过File f = new File(path_ref); FileObject fo = FileUtil.toFileObject(f);获取,其余同理。非常感谢!
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2013-05-06
    • 2012-10-30
    • 1970-01-01
    • 1970-01-01
    • 2018-10-08
    • 1970-01-01
    相关资源
    最近更新 更多