2010-05-20 10 views
6

o: Eclipse için küçük eklenti yazmak ve aşağıdaki var * Bir org.eclipse.ui.texteditor.ITextEditor * Bir satır numarası otomatik olarak atlayabilirsiniz nasılEclipe PDE: satır X atlama ve vurgulamak Eclipse PDE gelişimi hakkında bir qustion

Bu çizgi ve işaretlemek? API'nin yalnızca belgenin içindeki ofsetleri (bkz: ITextEditor.selectAndReveal()) desteklediği, ancak hiçbir satır numarası görmediği üzücü.

olacağını iyi - bu işe yaramazsa rağmen:

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

It bu mümkün bir şekilde?

cevap

5

sınıfa DetailsView ben aşağıdaki yöntemi buldum.

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()); 
    } 
    } 
} 
1

Bir çözüm bulamadım bile org.eclipse.ui.texteditor.ITextEditor ofsetleri satıyor olsa bile, selectAndReveal() yöntemiyle satır numaranızı alabilmelidir.

Bkz. this thread ve this thread. hattı boyunca

deneyin şey:

((ITextEditor)org.eclipse.jdt.ui.JavaUI.openInEditor(compilationUnit)).selectAndReveal(int, int); 
İlgili konular