从比较编辑器获取文档

发布于 2024-12-25 22:30:30 字数 96 浏览 1 评论 0原文

如何从比较编辑器获取文档?我有 CompareViewerSwitchingPane,但我不知道如何提取左窗格和右窗格的文档。

我需要它来获取编辑器中显示的文本。

How to get document from compare editor? I have got CompareViewerSwitchingPane, but I don't know how to extract document for left and right pane.

I need it to get text that is displayed in the editor.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

时光无声 2025-01-01 22:30:30

下面的代码示例展示了如何获取左右比较编辑器文档(以及文档中的文本):

IWorkbench workbench = PlatformUI.getWorkbench();
IEditorPart editorPart = workbench.getActiveWorkbenchWindow().getActivePage().getActiveEditor();
CompareEditorInput compareEditorInput = (CompareEditorInput) editorPart.getEditorInput();
ICompareInput compareInput = (ICompareInput) compareEditorInput.getCompareResult();
ITypedElement leftTypedElement = compareInput.getLeft();
ITypedElement rightTypedElement = compareInput.getRight();
IDocument leftDocument = CompareUI.getDocument(leftTypedElement);
IDocument rightDocument = CompareUI.getDocument(rightTypedElement);
String left = leftDocument.get();
String right = rightDocument.get();

The following code example shows how to get the left and right compare editor Document (and the text in the document):

IWorkbench workbench = PlatformUI.getWorkbench();
IEditorPart editorPart = workbench.getActiveWorkbenchWindow().getActivePage().getActiveEditor();
CompareEditorInput compareEditorInput = (CompareEditorInput) editorPart.getEditorInput();
ICompareInput compareInput = (ICompareInput) compareEditorInput.getCompareResult();
ITypedElement leftTypedElement = compareInput.getLeft();
ITypedElement rightTypedElement = compareInput.getRight();
IDocument leftDocument = CompareUI.getDocument(leftTypedElement);
IDocument rightDocument = CompareUI.getDocument(rightTypedElement);
String left = leftDocument.get();
String right = rightDocument.get();
不必了 2025-01-01 22:30:30

我找到了一种方法来获取其 CompareEditorInput 的文档。有不同类型的比较输入:一种进入 CompareEditor,一种进入 CompareEditor 查看器。

我与 CompareUI.getDocument(Object) 非常接近,但第一次发现它时,我给了它 CompareEditorInput,它返回了我 null 而不是一个合理的对象(对于中级开发人员来说可能没有什么神秘之处,但不适合我)。我就搁置了,认为这个方法行不通。

感谢 aphex,因此我对 CompareUI.getDocument(Object) 给予了更多关注它让我想到了一个想法:嘿,为什么不尝试传递 DiffNode 而不是 CompareEditor,最后它成功了!

I have found a way how one could get document for his CompareEditorInput. There are different kinds of compare inputs: the one that goes to CompareEditor and the ones that go to CompareEditor viewers.

I was so close with CompareUI.getDocument(Object), but first time I found it I gave it CompareEditorInput and it returned me null instead of a reasonable object (may be for intermediate developer there is no mysteries, but not for me). And I put it aside thinking that this method does not work.

Thanks to aphex due to which I gave a bit more attention to CompareUI.getDocument(Object) and it stroke me with an idea: hey, why not to try to pass DiffNode instead of a CompareEditor and finally it worked!

追星践月 2025-01-01 22:30:30

您需要检索 EditorInput,它扩展了 CompareEditorInput。从 Pluginclass 中,您可以使用以下方法检索当前活动编辑器:

getActiveWorkbenchWindow().getActivePage().getActiveEditor().getEditorInput();

此处 您可以看到比较编辑器的工作原理以及如何向比较编辑器填充工作所需的信息。

编辑:链接已修复。

You need to retrieve the EditorInput, which extends CompareEditorInput. From the Pluginclass you can retrieve the current active editor using:

getActiveWorkbenchWindow().getActivePage().getActiveEditor().getEditorInput();

Here you can see how the compare editor works and how you fill the compare editor with the needed information to work.

EDIT: Link fixed.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文