【问题标题】:eclipse plug in: open editor with python syntax highlighting programmaticallyeclipse插件:以编程方式打开带有python语法突出显示的编辑器
【发布时间】:2016-04-23 21:53:39
【问题描述】:

我正在开发一个 Eclipse 插件,我可以通过它在 Eclipse 编辑器中打开外部文件,如下所示:

            IFileStore fileStore = EFS.getLocalFileSystem().getStore(fileToOpen.toURI());
        FileStoreEditorInput editorInput = new FileStoreEditorInput(fileStore);
        IWorkbenchPage page = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage();

        try {
            page.openEditor(editorInput, "org.eclipse.ui.DefaultTextEditor");
            TextEditor editor = (TextEditor) PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage().getActiveEditor();
            IDocument document= editor.getDocumentProvider().getDocument(editor.getEditorInput());
            editor.selectAndReveal(document.getLineOffset(line - 1), document.getLineLength(line-1));

        } catch ( PartInitException e ) {
            //Put your exception handler here if you wish to
        } catch (BadLocationException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }

实际上效果很好。但是其中一些文件是 *.py 文件、Python 代码,我希望像在 PyDev 编辑器中那样突出显示文本。

我想我需要打开一个不同的编辑器?!但我不知道如何或在哪里找到它。

非常感谢任何提示!谢谢!!!

【问题讨论】:

    标签: python eclipse plugins


    【解决方案1】:

    pyDev python 编辑器的编辑器 ID 似乎是 org.python.pydev.editor.PythonEditor。因此,如果您安装了 pyDev,您可以尝试指定该编辑器。

    注意:并非所有编辑器都支持编辑外部文件。有些仅适用于工作区中的文件,或者减少了对非工作区文件的功能。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2012-11-27
      • 2017-06-09
      • 2013-11-18
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2023-03-16
      相关资源
      最近更新 更多