Friday 9 November 2018

How does Undo work in Studio Developer?

One of the most useful new features in Studio Developer is the undo/redo capability that is provided with the new action diagram editor, UI Designer and Screen Designer.

We are all familiar with using Undo in all sorts of programs that we use on a daily basis. The lack of an undo capability in the Gen toolset comes as a surprise to those new to the tool and is often sorely missed, especially when you accidentally delete something in an action diagram or move controls in the UI designer.

Whilst 'undo' has probably been the most requested enhancement to the Gen toolset over the past 30 years, it was not easy to implement
in the old Gen toolset because of the way that Gen stores objects in the model. All of the diagrams in Gen work off a common model (set of objects, associations and properties), so if you change an object like an attribute, the effect is immediate on any other diagram that references the object.  Gen also imposes very strict and rigid constraints on the model: you cannot reference a non-existent object and you cannot delete an object that is referenced.

As a result, the concept of being able to undo changes made in a single action diagram is not feasible with a single underlying data store. As an example, consider simultaneous updates to two action diagrams:
  1. Change #1 in Action Diagram A
  2. Change #1 in Action Diagram B
  3. Change #2 in Action Diagram A
If you wanted to undo Changes #1 and #2 in Action Diagram A, rolling back the transactions to the model back to point (1) would also require undoing the change to Action Diagram B, which would not be desirable.

Therefore, to support an undo capability within a single diagram, it follows that each diagram must maintain its own private copy of the model that is separate to the local model and provide a mechanism to save these changes to the local model on demand.

In designing Studio Developer, the architecture included support for maintaining the diagram's private model in a Document Object Model (DOM) with support for undo and redo and applying the changes to the local Gen model. Once the changes have been applied to the local model, previous changes to the diagram cannot be undone, so the undo capability is only back to the last apply point.

Another design feature of the DOM is less strict enforcement of model consistency to support the partial completion of statements, as described in a previous post

No comments: