0

side-by-side displayを使用して Eclipse で PyDev エディターを正常に拡張しましたが、追加した追加の SourceViewer の内容をコピーできません。Ctrlディスプレイでテキストを選択できますが、 +を押すCと、メインの PyDev エディターで選択されたテキストが常にコピーされます。

Eclipse エディターのキー バインディングに関する記事を見つけましたが、そこにあるコードは不完全で少し古くなっているようです。フォーカスのある SourceViewer からコピーするように copy コマンドを構成するにはどうすればよいですか?

私がこれをやりたい理由は、Pythonでライブ コーディング用のツールを作成したためです。表示をコピーしてバグの説明に貼り付けることができれば、ユーザーがバグ レポートを送信するのははるかに簡単になります。

4

1 に答える 1

0

David Green の記事は良いスタートでしたが、すべてを機能させるには少し掘り下げました。完全なサンプル プロジェクトを GitHub に公開しました。いくつかのスニペットをここに投稿します。

このTextViewerSupportクラスは、エクストラ テキスト ビューアに委譲するコマンドごとに新しいアクション ハンドラを関連付けます。複数のテキスト ビューアがあるTextViewerSupport場合は、それぞれに対してオブジェクトをインスタンス化するだけです。コンストラクターですべてを結び付けます。

public TextViewerSupport(TextViewer textViewer) {
    this.textViewer = textViewer;
    StyledText textWidget = textViewer.getTextWidget();
    textWidget.addFocusListener(this);
    textWidget.addDisposeListener(this);

    IWorkbenchWindow window = PlatformUI.getWorkbench()
            .getActiveWorkbenchWindow();
    handlerService = (IHandlerService) window
            .getService(IHandlerService.class);

    if (textViewer.getTextWidget().isFocusControl()) {
        activateContext();
    }
}

このactivateContext()メソッドには、委譲するすべてのコマンドのリストがあり、それぞれに新しいハンドラーを登録します。これは David の記事からの変更の 1 つです。thisITextEditorActionDefinitionIdsは廃止され、 に置き換えられましたIWorkbenchCommandConstants

protected void activateContext() {
    if (handlerActivations.isEmpty()) {
        activateHandler(ITextOperationTarget.COPY,
                IWorkbenchCommandConstants.EDIT_COPY);
    }
}

// Add a single handler.
protected void activateHandler(int operation, String actionDefinitionId) {
    StyledText textWidget = textViewer.getTextWidget();
    IHandler actionHandler = createActionHandler(operation,
            actionDefinitionId);
    IHandlerActivation handlerActivation = handlerService.activateHandler(
            actionDefinitionId, actionHandler,
            new ActiveFocusControlExpression(textWidget));

    handlerActivations.add(handlerActivation);
}

// Create a handler that delegates to the text viewer.
private IHandler createActionHandler(final int operation,
        String actionDefinitionId) {
    Action action = new Action() {
        @Override
        public void run() {
            if (textViewer.canDoOperation(operation)) {
                textViewer.doOperation(operation);
            }
        }
    };
    action.setActionDefinitionId(actionDefinitionId);
    return new ActionHandler(action);
}

これActiveFocusControlExpressionにより、新しいハンドラーに十分な優先度が与えられ、標準のハンドラーが置き換えられます。これは、David のバージョンとほとんど同じです。ただし、コンパイルするには、プラグイン マニフェストに追加の依存関係を追加する必要がありました。パッケージorg.eclipse.core.expressionsorg.eclipse.ui.texteditor.

于 2012-12-23T05:51:40.630 に答える