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

时间:2010-03-23 21:53:40

标签: eclipse event-handling diff subclipse eclipse-pde

在我的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

1 个答案:

答案 0 :(得分:1)

问题是:org.eclipse.compare.CompareEditorInput(其java sources here}是一个抽象类,它并不总是“左”或“右”窗格:

/**
 * 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对象的确切实现类型吗?

I.e:有趣的是看具体课程如何处理选择:
例如org.eclipse.compare.internal.ResourceCompareInput处理org.eclipse.jface.viewers.IStructuredSelection,并附带utility function to get left and right IResource based on the selection