【问题标题】:Open a file in an Eclipse editor and set the focus on this editor在 Eclipse 编辑器中打开一个文件并将焦点设置在该编辑器上
【发布时间】:2012-11-10 00:43:06
【问题描述】:

我有一个奇怪的问题让我很困惑。我使用以下代码在 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 );

我从互联网上的几个来源收集了一些零碎的东西。

奇怪的问题是编辑器似乎有焦点(标签被突出显示,我看到它周围的蓝色边框)

但是在编辑器中看不到光标,当我输入内容时,什么也没有发生(工作台的其他地方也没有发生任何事情)。

我也尝试了ITextEditor editor = (ITextEditor) IDE.openEditor( page, file, true );,但结果相同。

当我点击选项卡时,光标出现,我可以使用编辑器。不过,按F12 无效。

还有什么想法?

【问题讨论】:

标签: eclipse editor focus


【解决方案1】:

尝试page.activate(editor);(即使它应该已经处于活动状态)。

【讨论】:

  • 链接失效。请更新链接或在您的回答中提供更多信息。
  • @Sadik 答案已被删除,自 18 年 6 月以来 Chetan 没有任何活动。删除了链接。
猜你喜欢
  • 2015-04-09
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2013-02-28
  • 1970-01-01
  • 2011-01-04
  • 1970-01-01
相关资源
最近更新 更多