I'm graduating in a few weeks, so I'll have some free time I can dedicate 
to sup again.

Recently redo functionality was suggested, I believe this was meant to be 
a solution for something, but I have been thinking about it for a while.
I'd like to register Ctrl-R to keep with the vim bindings.

Redo is fairly straightforward from the UndoManager side; it simply has
to push and pop from one list to another when undoing/redoing. The qualm
I have is with the code generating the undo hooks.

Right now, code is written in duplicate. Something like toggle_starred
has to perform three things:

* toggle the star on the message
* generate a lambda to unstar the message (effectively duplicating
  toggle_starred)
* register the lambda with UndoManager

There are two obvious ways to implement redo that I think are ugly, and
one slightly clever one that might be better. If you know some Ruby magic 
that resolves this, please let me know!

Ugly method 1: write code in triplicate. When you call an action, it does 
4 things:

* actually perform the action
* create a lambda undoing that action
* create a lambda redoing the action
* registering undo and redo

Ugly method 2: write code in duplicate, register a redo and call redo
This saves duplication of code, but it seems unnecessarily complex.

* create undo lambda
* create redo lambda
* register undo and redo, but 'queue up' redo
* UndoManager.redo

Slightly clever method: have primitives return their own undo/redo. This
can be seen in toggle_starred where actually_toggle_starred returns its
inverse. This shifts the complexity down and keeps higher level code clean.

Any thoughts?
- Mike

--
Mike Stipicevic
RPI EE/CSYS '09

sti...@rpi.edu
mstipice...@ieee.org


_______________________________________________
sup-talk mailing list
sup-talk@rubyforge.org
http://rubyforge.org/mailman/listinfo/sup-talk

Reply via email to