[Haskell] PersistentDocument: A library for dealing with undo and file management in Haskell

Arjan van IJzendoorn afie at cs.uu.nl
Thu Dec 9 09:10:06 EST 2004


Hello all,

In our Bayesian network editor Dazzle with a wxHaskell GUI there were 
two places where we needed to maintain a document that can be saved to 
disk. And we wanted to have undo (and redo) in both places. Of course, 
we didn't want to write this functionality twice. After factoring out 
the common parts the library is so general that it might be useful for 
others writing editors, too.

The library takes care of maintaining a document, keeping track of 
whether it is dirty (changed w.r.t. disk version), providing save and 
save as functionality, enabling and disabling menu items, updating the 
title bar, warning if you try to close a document that is "dirty", 
dealing with unlimited undo/redo and more.

The reason for combining undo/redo and file management is because there 
is interaction between them. For example, when you save a file, the 
versions of the document in the undo and redo buffers become "dirty". 
All in all, it is quite subtle code that you don't want to write time 
after time.

If you are writing some kind of editor and are interested in using the 
library, check out the (heavily documented) source code at:

http://www.cs.uu.nl/~afie/pd09122004.zip

The zip contains three files:
1) PersistentDocument.hs: the implementation of what is described above. 
This module is not dependent on wxHaskell by the way.
2) PDDefaults.hs: default implementations of the call-back functions in 
wxHaskell
3) PDDemo.hs: a demo application allowing you to edit a list of strings. 
It uses the two other files and thus supports undo/redo and cool file 
management for "free". In the demo file you can see how to start it.

If you have suggestions for better names, need functions that are not in 
the interface or you have any other comment, send it to 
wxhaskell-users at lists.sourceforge.net

At some point this functionality will be added to the wxHaskell 
distribution. However, I first want to let other people have a look at 
it and process their comments.

Have fun, Arjan

PS: If you want to see what our Dazzle editor looks like, go to 
http://www.cs.uu.nl/dazzle/


More information about the Haskell mailing list