Eclipse插件:获取编辑器状态信息

huangapple 未分类评论56阅读模式
英文:

Eclipse Plugin: Get editor state information

问题

以下是翻译的内容:

我有以下问题,并且非常感谢任何帮助。

我在插件中为文件启动批处理,不幸的是,我必须确保文件在文本编辑器中被关闭。
我还必须确保关闭同一文件的其他编辑器引用。
例子:
"菜单 => 窗口 => 新建窗口"
"菜单 => 编辑器 => 切换水平/垂直分割和克隆"
这部分我也希望已经解决了。

以下是我的代码:

IWorkbenchWindow[] windows = PlatformUI.getWorkbench().getWorkbenchWindows();
for (IWorkbenchWindow window : windows) {
    IWorkbenchPage page = window.getActivePage();
    IEditorReference[] editorReferences = page.getEditorReferences();
    for (IEditorReference editorReference : editorReferences) {
        String name = editorReference.getName();
        IEditorPart editorPart = editorReference.getEditor(false);
        if (editorPart instanceof ITextEditor && name != null) {
            
            // 在这里记录各种属性,例如分割
            if (name.equals(memberName)) {
                MPart mPart = editorPart.getSite().getService(MPart.class);
                if (mPart != null) {
                    List<String> tags = mPart.getTags();
                    if (tags.contains(IPresentationEngine.SPLIT_HORIZONTAL)) {
                        openConfiguration.setSplitHorizontal();
                    } else if (tags.contains(IPresentationEngine.SPLIT_VERTICAL)) {
                        openConfiguration.setSplitVertical();
                    }
                }
                
                ... // 其他属性
                
                // 关闭编辑器
                page.closeEditor(editorPart, false);
                
            }
        }
    }
}

现在我有一个问题,即在批处理完成后,文件会以相同的状态恢复。例如,如果用户在之前关闭的文件上进行了“水平分割”或“克隆”操作,现在应该与以前完全相同地显示。例如,在分割时,比例也应与以前相同。

我的解决方案是,在打开后重新设置之前记住的相关数据(在关闭时,请参见上面的代码)。

问题:这是正确的方法吗,还是有更优雅的方法?

问题:如何确定分割的比例?

问题:如何识别克隆引用?("菜单 => 编辑器 => 克隆")

该插件必须在基于 Eclipse 4.8 且支持 Eclipse 3.x API 的 RCA 中运行。

英文:

i have the following problem and am grateful for any help.

I start a batch processing for a file in my plugin and unfortunately I have to make sure that the file is closed in the text editor.
<br/>I also have to make sure that other editor references for the same file are closed.
<p>
Examples:
"Menu => Window => new Window<br/>
"Menu => Editor => Toggle Split Horizontal/Vertical and Clone.<p>
This I have also hopefully managed to do

Here's my code:

IWorkbenchWindow[] windows = PlatformUI.getWorkbench().getWorkbenchWindows();
		for (IWorkbenchWindow window : windows) {
			IWorkbenchPage page = window.getActivePage();
			IEditorReference[] editorReferences = page.getEditorReferences();
			for (IEditorReference editorReference : editorReferences) {
				String name = editorReference.getName();
				IEditorPart editorPart = editorReference.getEditor(false);
				if (editorPart instanceof ITextEditor &amp;&amp; name != null) {
					
					// Here I note down various attributes, e.g. split
					if (name.equals(memberName)) {
						MPart mPart = editorPart.getSite().getService(MPart.class);
						if (mPart != null) {
							List&lt;String&gt; tags = mPart.getTags();
							if (tags.contains(IPresentationEngine.SPLIT_HORIZONTAL)) {
								openConfiguration.setSplitHorizontal();
							} else if (tags.contains(IPresentationEngine.SPLIT_VERTICAL)) {
								openConfiguration.setSplitVertical();
							}
						}
						
						... // another attributes
						
						// close Editor
						page.closeEditor(editorPart, false);
						
					}
				}
			}
		}

Now I have the problem that the file is restored in the same state after the batch processing is finished. For example, if the user has done a "horizontal split" or a "clone" on the previously closed file, this should now be displayed exactly as before. When splitting, for example, also with the same ratio as before.

My solution is that I remember the relevant data before (when closing, see code above) and set it again after opening.

Question: Is this the right approach or is there a more elegant way?

Question: How do I determine the ratio for a split?

Question: How do I recognize a clone reference? ("Menu => Editor => Clone")

The plugin must run in an RCA that is still based on Eclipse 4.8 and supports the Eclipse 3.x API.

huangapple
  • 本文由 发表于 2020年7月28日 21:22:53
  • 转载请务必保留本文链接:https://java.coder-hub.com/63135169.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定