Skip to main content



      Home
Home » Newcomers » Newcomers » Dirty State Handling with TextViewers (Dirty State Handling for TextViewer Objects in the Context of Undo/Redo in an Editor)
Dirty State Handling with TextViewers [message #1691021] Wed, 01 April 2015 11:37
Eclipse UserFriend
Hi there,

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 is 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 becomes dirty.
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("");
fText.setDocument(fTextModel);
int MAX_UNDO_LEVEL = 99;
TextViewerUndoManager undoMgr = new TextViewerUndoManager(MAX_UNDO_LEVEL);	
fText.setUndoManager(undoMgr);
fText.getUndoManager().connect(fText);
ObjectUndoContext context = (ObjectUndoContext) undoMgr.getUndoContext();
MyEditor editor = (MyEditor) site.getPart();
context.addMatch(editor.getUndoContext());
MenuManager manager = new MenuManager(null, "#PopupMenu");
Menu menu = manager.createContextMenu(ftext.getControl());
ftext.getControl().setMenu(menu);
site.registerContextMenu(manager, ftext);


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!

Regards,

Adalbert.
Previous Topic: eclipse
Next Topic:how do use gradle /meven dependency tooling to import eclipse 4.4 (or other build) jars
Goto Forum:
  


Current Time: Mon May 12 20:32:08 EDT 2025

Powered by FUDForum. Page generated in 0.09467 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software

Back to the top