MVVM + UndoRedo + Scripting

34 views
Skip to first unread message

Zhou Yong

unread,
Jan 21, 2010, 5:26:08 AM1/21/10
to wpf-di...@googlegroups.com
I have a situation in which I need to support scripting over the domain model, and also support undo / redo over the operations performed over the domain model, I've got several hundred domain model to work with (aka script it and undo / redo it).

I've looked into Expression Blend's implementation of the Undo / Redo pattern, and I think it's not suitable for my scenarios, since from my personal understanding in Expression Blend, it only gets one domain model aka XamlDocument, so it's cheap to add a UndoXamlDocument or something like that over the domain model, but I've got several hundred domain models, and it will be cumbersome to implement the parallel undoable domain model over them.

How do you guys perceive this issue?

MarcoZ

Peter O'Hanlon

unread,
Jan 21, 2010, 5:37:24 AM1/21/10
to wpf-di...@googlegroups.com
Hah, talk about timing. I'm pulling together a sample implementation for Goldlight right now that covers undo/redo support in an application. In a nutshell, it uses a combination of INotifyPropertyChanging, an UndoableObservableCollection and a Mediator to coordinate it all.
--
Peter O'Hanlon

Zhou Yong

unread,
Jan 21, 2010, 8:33:04 AM1/21/10
to wpf-di...@googlegroups.com
Hi Peter,

Can I have a look at your sample implementation? I don't think UndoableObservableCollection fits my need, but glad to see how you perceive this from another angle?

MarcoZ

Peter O'Hanlon

unread,
Jan 21, 2010, 8:42:19 AM1/21/10
to wpf-di...@googlegroups.com
Once I've finished pulling it all together, you're more than welcome.
--
Peter O'Hanlon

Michael D. Brown

unread,
Jan 22, 2010, 1:10:52 AM1/22/10
to wpf-di...@googlegroups.com

First I need to state the obvious…some actions can’t be undone. That being said for all other actions there is an advanced concept that Greg Young talks about called DDDD (Distributed Domain Driven Design). The basic gist is…everything that occurs within your system occurs through a recordable and reversible message (a command if you will). At any point those messages can be “committed”/saved/persisted/ what have you and from there out all new messages go against the new baseline of your system. Think of it as how SQL Server does a backup log. Every action within SQL Server gets logged, when you make a backup, the log is cleared.

 

So now your domain model consists of the commands that can be performed (against your original domain model)

 

Take for example a simple drawing app. Some commands might be:

draw line from point a to point b with color c

draw rectangle with upper left corner a and lower right corner b

draw ellipse with bounding rectangle x

apply gradient to object y with these settings

add stop to gradient z

 

You get the picture. Once you have this, the game gets interesting because you can do a basic stack (last in first out) where a user can undo one command at a time until he gets to a specific one. Or you can allow the user to choose individual commands to “forget” Retaining the others.

 

If you’d like to discuss more, I love the topic. So feel free to fire a message.

 

--Mike

Laurent Bugnion (GalaSoft)

unread,
Jan 22, 2010, 2:25:33 AM1/22/10
to wpf-di...@googlegroups.com

FWIW I love how Paint.NET is doing undo/redo, by displaying the stack of operations and showing you which operations are available for undo/redo. This is a cool visualization to what Mike is describing below!

 

Cheers,

Laurent

Reply all
Reply to author
Forward
0 new messages