Re: Undo/Redo



Scribit Mickael Drean dies 29/05/2006 hora 14:40:
> I need to add the undo/redo functions to my app, i searched on the web
> but i only found MFC examples. So, I would like to know how to do with
> Gtkmm. If someone have already done it, it would be greatful.

I'm not sure there should be anything framework specific for an
undo/redo feature.

The obvious way to achieve it is to build an objet that represents all
the state of the application to which undo/redo could be applied, and
have two stacks of such an object: one for the 'done' states and one for
the 'undone' states.

And maybe a single object for the current state, of course, though this
object could be constructed when needed instead of existing everytime.

You have also to define which modifications of the state should be
undoable.

Then, each time when a undoable modification will be done, the current
state is pushed on the 'done' stack, and modification made.

Undo, then, is pushing the current state on the 'undone' stack, and
popping a state from the 'done' stack to the current state.

Redo, naturally, is the opposite: pushing the current state to the
'done' stack and popping a state from the 'undone' stack to the current
state.

All this might be a very good candidate for a templated undo framework,
in fact...

Quickly,
Nowhere man
-- 
nowhere man levallois eu org
OpenPGP 0xD9D50D8A

Attachment: signature.asc
Description: Digital signature



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]