2
我有一个奇怪的问题让我感到困惑。我在Eclipse的编辑器中用这个代码打开一个文件:在Eclipse编辑器中打开一个文件,并将重点放在这个编辑器上
final IWorkbench wb = PlatformUI.getWorkbench();
IWorkbenchWindow window = wb.getActiveWorkbenchWindow();
final IWorkbenchPage page = window.getActivePage();
wb.getProgressService().runInUI(window, new IRunnableWithProgress() {
@Override
public void run(IProgressMonitor monitor) throws InvocationTargetException, InterruptedException {
if(null == monitor) {
monitor = new NullProgressMonitor();
}
try {
monitor.beginTask("Append to file", 2);
ITextEditor editor = (ITextEditor) IDE.openEditor(page, file);
monitor.worked(1);
// TODO Bug: Editor is active, it has the focus but doesn't process keypress events :-(
} catch(Exception e) {
throw new InvocationTargetException(e, "Error appending to file " + file);
} finally {
monitor.done();
}
}
}, null);
我收集了来自Internet上几个来源的零碎。
奇怪的问题是,编辑似乎有焦点(标签被突出显示,我看到蓝色边框周围)
但没有光标可见在编辑器中,当我输入的时候,没有什么发生(在工作台的其他地方也没有任何事情发生)。
我也试过ITextEditor editor = (ITextEditor) IDE.openEditor(page, file, true);
但具有相同的结果。
当我点击选项卡上,光标出现,我可以使用编辑器。然而,按F12
没有任何效果。
和想法?
你使用的是什么版本的eclipse?我问,因为我看到IDE.openEditor()并不确定它来自哪里。 –
3.7。代码来自FAQ:http://wiki.eclipse.org/FAQ_How_do_I_open_an_editor_on_a_file_in_the_workspace%3F –
我已经解决了这个问题,请访问: http://stackoverflow.com/questions/41606181/eclipse-rcp-have-the -same编辑器打开,在编辑器窗口/ 41631205#41631205 –