更新时间:2023-01-13 21:26:57
我不太清楚此时显示弹出对话框"是什么意思,但请执行以下操作:
I'm not exactly sure what do you mean under "show popup dialog at this point", but do something like this:
IEditorPart editor = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage().getActiveEditor();
if (editor instanceof ITextEditor) {
ISelectionProvider selectionProvider = ((ITextEditor)editor).getSelectionProvider();
ISelection selection = selectionProvider.getSelection();
if (selection instanceof ITextSelection) {
ITextSelection textSelection = (ITextSelection)selection;
int offset = textSelection.getOffset(); // etc.
}
}
当然,在生产代码中做空检查等.
Of course, in production code do null checks etc.