如何识别来自 Eclipse 中 CompareEditorInput 的文本选择事件的来源?

发布于 2024-08-26 06:51:26 字数 1327 浏览 4 评论 0原文

在我的 eclipse 插件中,我有以下代码:

public class MyHandler extends AbstractHandler {
    @Override
    public Object execute( ExecutionEvent event ) throws ExecutionException {
        ISelection sel = HandlerUtil
            .getActiveWorkbenchWindowChecked( event )
            .getSelectionService()
            .getSelection();

        if( sel instanceof TextSelection ) {
            IEditorPart activeEditor = PlatformUI
                    .getWorkbench()
                    .getActiveWorkbenchWindow()
                    .getActivePage()
                    .getActiveEditor();
            IEditorInput editorInput = activeEditor.getEditorInput();

            if( editorInput instanceof CompareEditorInput ) {
                // here are two possible sources of the text selection, the
                // left or the right side of the compare editor.

                // How can I find out, which side it is from?
            }
        }
        return null;
    }
}

这里我正在处理来自 CompareEditorInput 的文本选择事件,即将文件的两个远程版本与 subclipse 进行比较的结果。

现在我想正确处理文本选择。为此,我必须知道它是否选择左侧编辑器内或右侧编辑器内的某些文本。

我怎样才能找到它?

编辑2010-04-10:

CompareEditorInput 的具体实例是org.tigris.subversion.subclipse.ui.compare.SVNCompareEditorInput

In my eclipse plugin I have the following code:

public class MyHandler extends AbstractHandler {
    @Override
    public Object execute( ExecutionEvent event ) throws ExecutionException {
        ISelection sel = HandlerUtil
            .getActiveWorkbenchWindowChecked( event )
            .getSelectionService()
            .getSelection();

        if( sel instanceof TextSelection ) {
            IEditorPart activeEditor = PlatformUI
                    .getWorkbench()
                    .getActiveWorkbenchWindow()
                    .getActivePage()
                    .getActiveEditor();
            IEditorInput editorInput = activeEditor.getEditorInput();

            if( editorInput instanceof CompareEditorInput ) {
                // here are two possible sources of the text selection, the
                // left or the right side of the compare editor.

                // How can I find out, which side it is from?
            }
        }
        return null;
    }
}

Here I'm handling a text selection event coming from an CompareEditorInput, i.e. the result of comparing two remote revisions of a file with subclipse.

Now I want to handle the text selection properly. For that I have to know if it selects some text inside the left side editor or inside the right side editor.

How can I find that out?

EDIT 2010-04-10:

The concrete instance of CompareEditorInput is org.tigris.subversion.subclipse.ui.compare.SVNCompareEditorInput.

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

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

发布评论

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

评论(1

虫児飞 2024-09-02 06:51:26

问题是: org.eclipse.compare.CompareEditorInput (其具有 java 源代码)是一个抽象类,它并不总是“左”或“右”窗格:

/**
 * The most important part of this implementation is the setup 
 *  of the compare/merge UI.
 * The UI uses a simple browser metaphor to present compare results.
 * The top half of the layout shows the structural compare results 
 *  (e.g. added, deleted, and changed files),
 * The bottom half the content compare results  
 *  (e.g. textual differences between two files).
 * A selection in the top pane is fed to the bottom pane. 
 * If a content viewer is registered for the type of the selected object, 
 *  this viewer is installed in the pane.
 * In addition if a structure viewer is registered for the selection type,
 *  the top pane is split horizontally to make room for another pane 
 *  and the structure viewer is installed in it. 
 * When comparing Java files this second structure viewer would show 
 *  the structural differences within a Java file, 
 *  e.g. added, deleted or changed methods and fields.
 */

问题是:你知道它的确切实现类型吗?这个CompareEditorInput 对象?

即:看看具体类如何处理选择很有趣:
org.eclipse.compare.internal。 ResourceCompareInput 例如处理 < code>org.eclipse.jface.viewers.IStructuredSelection,并附带 根据选择获取左右 IResource 的实用函数

The issue is: org.eclipse.compare.CompareEditorInput (which have its java sources here) is an abstract class which has not always "left" or "right" pane:

/**
 * The most important part of this implementation is the setup 
 *  of the compare/merge UI.
 * The UI uses a simple browser metaphor to present compare results.
 * The top half of the layout shows the structural compare results 
 *  (e.g. added, deleted, and changed files),
 * The bottom half the content compare results  
 *  (e.g. textual differences between two files).
 * A selection in the top pane is fed to the bottom pane. 
 * If a content viewer is registered for the type of the selected object, 
 *  this viewer is installed in the pane.
 * In addition if a structure viewer is registered for the selection type,
 *  the top pane is split horizontally to make room for another pane 
 *  and the structure viewer is installed in it. 
 * When comparing Java files this second structure viewer would show 
 *  the structural differences within a Java file, 
 *  e.g. added, deleted or changed methods and fields.
 */

The question is: do you know the exact implementation type of this CompareEditorInput object?

I.e: It is interesting to see how concrete classes deal with selection:
The org.eclipse.compare.internal.ResourceCompareInput for instance deals with org.eclipse.jface.viewers.IStructuredSelection, and comes with an utility function to get left and right IResource based on the selection.

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