|Undo/Redo with TextViewers and Dirty State Handling [message #1693338]
||Thu, 23 April 2015 10:10
| Adalbert Perbandt
Registered: March 2014
some time ago I posted a problem I'm facing with Undo/Redo behavior in conjunction with dirty state handling in a multipage editor using Eclipse forms in the Eclipse Community forum for newcomers. Unfortunately I got no response on my posting and so I assume that this was not the proper place to publish my problem. I just discovered the JFace forum so I'd like to publish my issue here in the hope someone can provide some helpful information.
I'm implementing an editor plugin. The editor is constructed in the form of a multi-page editor with the pages implemented using Eclipse Forms. It looks a little bit similar to Eclipse's plugin.xml editor in the sense that each page is structured in sections (extending SectionPart). The sections contain several different GUI components, e.g. TextViewers, TableViewers and TreeViewers. Whenever in any of the GUI components belonging to the editor a change is made, the editor
I'm now in the process of implementing Undo/Redo for my editor. For the TreeViewers and TableViewers I made this work already. So addition or removal of objects in a TreeViewer or TableViewer can be undone and in case the editor's dirty state before the respective operation was clean, then after undoing the operation the editor becomes clean again. I achieved this by caching the editor's dirty state in the respective operation so that when undo is executed on it the previous dirty state is restored again in the editor.
But with undo/redo of changes made in TextViewer objects I couldn't figure out yet how to achieve this behavior. The problem for me is that the TextViewer already has undo/redo implemented in a helper class called TextViewerUndoManager. I only needed to create an instance of this class, set it into the TextViewer and connect it with this TextViewer instance. Besides this I created a context menu for the TextViewer. And I managed to make the editor's undo context match the undo context provided by the TextViewer's undo manager. The code that does all that looks as follows:
fText = new TextViewer(parent, styles);
fTextModel = new Document("");
int MAX_UNDO_LEVEL = 99;
TextViewerUndoManager undoMgr = new TextViewerUndoManager(MAX_UNDO_LEVEL);
ObjectUndoContext context = (ObjectUndoContext) undoMgr.getUndoContext();
MyEditor editor = (MyEditor) site.getPart();
MenuManager manager = new MenuManager(null, "#PopupMenu");
Menu menu = manager.createContextMenu(ftext.getControl());
I assumed that the TextViewer's document should somehow already support the concept of a dirty state or that the UndoManager would provide some API for dirty state handling but could not find anything.
Any helpful hint would be very welcome!
Powered by FUDForum
. Page generated in 0.02652 seconds