Eclipse redo undo implementation

Source: Internet
Author: User
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.
Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.