5

Android のリソース編集を容易にする Eclipse プラグインを作成しています。ユーザーがプロジェクト内の任意の XML リソース ファイルをクリックすると、エディターが開き、プロジェクト内のすべてのリソースを一度に編集できます。

別の既定の Android リソース エディターで同じファイルを開く機能を追加したいと考えています。そのエディターの ID は知っていますが、そのクラスにアクセスできません。

IDE.openEditor を呼び出しても、別の Android エディターの ID を指定しても、そのファイルに対して既にエディターが開かれているため、何もしません。

同じ入力に対してEclipseに別のエディタを開くように強制する方法は?

一方、クラスではなく ID のみにアクセスできる場合、別のエディターを MultiPageEditorPart に埋め込むことは可能ですか?

4

2 に答える 2

4

メソッドは、最後に対応するメソッドをIDE.openEditor呼び出しIWorkbenchPageてエディターを開きます。

あなたの場合に役立つかもしれない方法は org.eclipse.ui.IWorkbenchPage.openEditor(IEditorInput, String, boolean, int)

    /**
     * Opens an editor on the given input.
     * <p>
     * If this page already has an editor open that matches the given input
     * and/or editor id (as specified by the matchFlags argument), that editor
     * is brought to the front; otherwise, a new editor is opened. Two editor
     * inputs are considered the same if they equal. See
     * <code>Object.equals(Object)<code>
     * and <code>IEditorInput</code>. If <code>activate == true</code> the editor
     * will be activated.  
     * </p><p>
     * The editor type is determined by mapping <code>editorId</code> to an editor
     * extension registered with the workbench.  An editor id is passed rather than
     * an editor object to prevent the accidental creation of more than one editor
     * for the same input. It also guarantees a consistent lifecycle for editors,
     * regardless of whether they are created by the user or restored from saved 
     * data.
     * </p>
     * 
     * @param input the editor input
     * @param editorId the id of the editor extension to use
     * @param activate if <code>true</code> the editor will be activated
     * @param matchFlags a bit mask consisting of zero or more of the MATCH_* constants OR-ed together
     * @return an open editor, or <code>null</code> if an external editor was opened
     * @exception PartInitException if the editor could not be created or initialized
     * 
     * @see #MATCH_NONE
     * @see #MATCH_INPUT
     * @see #MATCH_ID
     * @since 3.2
     */
    public IEditorPart openEditor(final IEditorInput input,
        final String editorId, final boolean activate, final int matchFlags)
        throws PartInitException;

これを呼び出して渡す必要があります。これMATCH_ID | MATCH_INPUTにより、既存のエディターを再利用するか、新しいエディターを作成するかを決定するときに、エディターIDが考慮されます。

于 2012-09-26T09:00:51.410 に答える
2

エディター拡張ポイントを使用すると、拡張機能org.eclipse.ui.editorsに を追加できますmatchingStrategy。これにより、Eclipse が特定の ID および特定のエディター入力のエディターが既に開いているかどうかを判断しようとするときの動作に影響を与えることができます。

実装はかなり簡単です。interface の実装を提供するだけで済みますorg.eclipse.ui.IEditorMatchingStrategy。その方法はただ一つ

boolean matches(IEditorReference editorRef, IEditorInput input);

ここに戻るfalseと、たとえエディター ID とエディター入力が同じであっても、Eclipse は毎回新しいエディターを開きます。

于 2012-09-26T09:31:22.230 に答える