我正在开发一个eclipse插件,并在视图中显示某些行号。当用户点击行号时,我希望焦点转到主编辑器中特定文件的行号。如何实现这一目标?
答案 0 :(得分:0)
您可以使用以下内容在活动文本编辑器中设置当前行:
IWorkbenchPage page = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage();
IEditorPart editorPart = page.getActiveEditor();
if (editorPart instanceof ITextEditor) {
ITextEditor editor = (ITextEditor)editorPart;
IDocumentProvider provider = editor.getDocumentProvider();
IDocument document = provider.getDocument(editor.getEditorInput());
try {
int lineStart = document.getLineOffset(line);
editor.selectAndReveal(lineStart, 0);
page.activate(editor);
} catch (BadLocationException x) {
// ignore
}
}
(基于' Goto Line'对话框中的代码)