4

私の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ここでは、ファイルの 2 つのリモート リビジョンをサブクリップと比較した結果であるからのテキスト選択イベントを処理しています。

ここで、テキストの選択を適切に処理したいと思います。そのためには、左側のエディターまたは右側のエディター内のテキストを選択するかどうかを知る必要があります。

どうすればそれを見つけることができますか?

編集 2010-04-10:

の具体的なインスタンスはCompareEditorInputですorg.tigris.subversion.subclipse.ui.compare.SVNCompareEditorInput

4

1 に答える 1

1

問題は次のとおりです:(ここorg.eclipse.compare.CompareEditorInputjavaソースがあります)は、常に「左」または「右」ペインを持っているとは限らない抽象クラスです。

/**
 * 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、を処理し、選択に基づいて左右に移動org.eclipse.jface.viewers.IStructuredSelectionするユーティリティ関数が付属しています。IResource

于 2010-04-10T07:27:35.143 に答える