Recently I used the Eclipse plug-in to provide redo/undo functions for a Multi editor. I started to find a lot of information. I wrote an article on the redo/undo functions of treeviewer on the Internet (refer: http://www.ibm.com/developerworks/cn/opensource/os-cn-eclipse-udrd/index.html), but basically all about view redo/undo, no article is about editor. I tried it many times and wrote the operationhistory process to the setactivepage method of the contributor of the editor. The procedure is as follows:
Undocontext = new objectundocontext (this );
Approver = new askuserapprover (undocontext );
Getoperationhistory (). addoperationapprover (approver );
Int Limit = 10;
Getoperationhistory (). setlimit (undocontext, limit );
Undoredoactiongroup undoredogroup = new undoredoactiongroup (getsite (),
Undocontext, true );
Iactionbars actionbars = getactionbars ();
Undoredogroup. fillactionbars (actionbars );
For variables not defined in the Code, refer to the article I mentioned.
Now, although the redo/undo on the eclipse menu can work normally, we use Ctrl + z/y
The shortcut key cannot work. The plug-in we developed is complicated. It may be because the problem has been handled in the parent class in the early stage of development, and it has not been found for a long time.
Why is quick Jian unable to work, so I had to register the event on the Editor interface, so that the Undo/Redo works properly.
The event processing class is as follows:
Public class undoredolistener implements keylistener {
Public void keypressed (keyevent e ){
}
Public void keyreleased (keyevent e ){
Ioperationhistory operationhistory = operationhistoryfactory. getoperationhistory ();
Int mask = E. statemask;
Int CH = E. character;
If (mask = SWT. CTRL & Ch = 'Z'-'A' + 1 ){
If (operationhistory. canundo (scorecardtableeditor. getundocontext ())){
Try {
Operationhistory. Undo (scorecardtableeditor. getundocontext (), null, null );
} Catch (executionexception E1 ){
E1.printstacktrace ();
}
}
}
If (mask = SWT. CTRL & Ch = 'y'-'A' + 1 ){
If (operationhistory. canredo (scorecardtableeditor. getundocontext ())){
Try {
Operationhistory. Redo (scorecardtableeditor. getundocontext (), null, null );
} Catch (executionexception E1 ){
E1.printstacktrace ();
}
}
}
}
}
I don't know if there is a better way! This method uses the operation mechanism to manage the stack, which simplifies the implementation process and maximizes the sharing.
Functions provided by eclipse.