6

Eclipse PDE開発に関する質問:Eclipse用の小さなプラグインを作成し、次の* org.eclipse.ui.texteditor.ITextEditor *行番号を持っています

その行に自動的にジャンプしてマークを付けるにはどうすればよいですか?APIがドキュメント内のオフセット(ITextEditor.selectAndReveal()を参照)のみをサポートし、行番号をサポートしていないように見えるのは残念です。

最善は-これは機能しませんが:

ITextEditor editor = (ITextEditor)IDE.openEditor(PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage(), file, true );
editor.goto(line);
editor.markLine(line);

これは何らかの方法で可能ですか?解決策が見つかりませんでした

4

2 に答える 2

5

クラスDetailsViewで、次のメソッドを見つけました。

private static void goToLine(IEditorPart editorPart, int lineNumber) {
  if (!(editorPart instanceof ITextEditor) || lineNumber <= 0) {
    return;
  }
  ITextEditor editor = (ITextEditor) editorPart;
  IDocument document = editor.getDocumentProvider().getDocument(
    editor.getEditorInput());
  if (document != null) {
    IRegion lineInfo = null;
    try {
      // line count internaly starts with 0, and not with 1 like in
      // GUI
      lineInfo = document.getLineInformation(lineNumber - 1);
    } catch (BadLocationException e) {
      // ignored because line number may not really exist in document,
      // we guess this...
    }
    if (lineInfo != null) {
      editor.selectAndReveal(lineInfo.getOffset(), lineInfo.getLength());
    }
  }
}
于 2010-07-25T13:55:10.860 に答える
1

org.eclipse.ui.texteditor.ITextEditorはオフセットを処理しますが、selectAndReveal()メソッドで行番号を取得できるはずです。

このスレッドこのスレッドを参照してください。

次のようなことを試してください。

((ITextEditor)org.eclipse.jdt.ui.JavaUI.openInEditor(compilationUnit)).selectAndReveal(int, int);
于 2010-05-20T13:16:10.970 に答える