简体   繁体   中英

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

I am working on eclipse form based editor. 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). Now, undo redo starts working weird. They work only for instances that is opened at last.

for eg: Suppose my editor supports '.xeb' file. if i open test1.xeb and test2.xeb files one by one using with my editor. then undo redo only works for instances that is opened for test2.xeb file. 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><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:

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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