简体   繁体   English

如何为基于Eclipse表单的插件编辑器的多个实例设置单独的全局操作处理程序

[英]How to set seperate global action handler for multiple instance of eclipse form based plugin editor

I am working on eclipse form based editor. 我正在基于Eclipse表单的编辑器上工作。 I have given support of handling of Undo Redo and dirty flag to my editor.Both of these feature working fine for single instances of plugin. 我已经为编辑器提供了对撤消重做和脏标志的处理支持,这两个功能对于单个插件实例都可以正常工作。 Problem is coming when i open it with 2 or more files (2 or more instances of eclipse plugin). 当我用2个或更多文件(2个或更多eclipse插件实例)打开它时,问题就来了。 Now, undo redo starts working weird. 现在,撤消重做开始变得很奇怪。 They work only for instances that is opened at last. 它们仅适用于最后打开的实例。

for eg: Suppose my editor supports '.xeb' file. 例如:假设我的编辑器支持'.xeb'文件。 if i open test1.xeb and test2.xeb files one by one using with my editor. 如果我用我的编辑器一个一个地打开test1.xeb和test2.xeb文件。 then undo redo only works for instances that is opened for test2.xeb file. 然后撤消重做仅适用于为test2.xeb文件打开的实例。 If i switch back to other instances, then undo redo of first instance gets appear. 如果我切换回其他实例,则会出现第一个实例的撤消重做。

i have below entries in my editor's plugin.xml: 我在编辑器的plugin.xml中有以下条目:

  <plugin><extension
     point="org.eclipse.ui.editors">
  <editor
        class="Testeditor"
        default="true"
        extensions="xeb"
        icon="icons/sample.gif"
        id="testeditor"
        name="editor">
  </editor>
 </plugin>

i debugged the code and found that this weird behavior is happening due to handling of global action in wrong way.I used below code to set global action handler: 我调试了代码,发现这种奇怪的行为是由于以错误的方式处理全局动作而发生的。我使用下面的代码来设置全局动作处理程序:

public void setUndoRedoActionHandlers() {

    final IActionBars actionBars = getEditorSite().getActionBars();
    actionBars.setGlobalActionHandler(ActionFactory.UNDO.getId(),
            mUndoAction);
    actionBars.setGlobalActionHandler(ActionFactory.REDO.getId(),
            mRedoAction);
    actionBars.updateActionBars();
} 

i went through some links related to this issue. 我浏览了一些与此问题有关的链接。 but couldn't understood the concept to implement this behavior. 但无法理解实现此行为的概念。

http://wiki.eclipse.org/FAQ_How_do_I_find_out_what_view_or_editor_is_selected%3F
http://wiki.eclipse.org/FAQ_How_do_I_hook_into_global_actions,_such_as_Copy_and_Delete%3F

Can any one look into this issue. 任何人都可以调查这个问题。 Thanks in advance. 提前致谢。

only override the setFocus() method of MultiPageEditorPart in you editor class and call the appropriate method of setting the global action handler,like this way: 仅在编辑器类中重写MultiPageEditorPart的setFocus()方法,并调用设置全局操作处理程序的适当方法,如下所示:

@Override
    public void setFocus() {
        switch (getActivePage()) {
        case 0:
            pageOne.setUndoRedoActionHandlers();
            break;
        case 1:
            pageTwo.setUndoRedoActionHandlers();
            break;
        }   
        super.setFocus();
    }

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM