|
Boost : |
From: Andreas Nicolai (Andreas.Nicolai_at_[hidden])
Date: 2003-01-24 07:59:29
"Ihsan Ali Al Darhi" <iad929_at_[hidden]> schrieb im Newsbeitrag
news:<01d001c2c2ba$6af14ea0$73c721d4_at_h8p7o2>...
> Can I use this library to implement multiple undo/redo in GUI applications
> under Windows? For example in a word processor.
Yes you can. Even if the other suggested improvements of the library are
left out (which might really be useful for a word-processor, especially the
grouping of commands...) you can already use it. Let me give a small
example:
Usually you can mark text in a word processor. When typing a new key, you
will certainly overwrite the selected text with the typed key (typical
behaviour). Now what has to happen in this KeyPress function (probably an
event)...
1. store the data in the selection -> std::string
2. store the insert position (pos) and the length (len) of that string
3. create an undo-action for the insertion of the selected text and send it
to the command manager (or add the undo-function via boost::bind() to the
command manager's list)
4. remove text from whatever memo-field-like interface you are using
5. insert the char of the pressed key
Well, what has to be in the undo-function?
1. store the char at position pos (that was the inserted char)
2. remove that char
3. insert the cut-out-string at position pos
4. select the inserted text and move the cursor at the end of that text (and
scroll that text area into view)
5. signal the command manager, that you want him to store a redo-action for
this
That's it already. You see it's straight forward to implement this.
Andreas
PS: Maybe we should seperate the discussion for command manager issues and
the way undo/redo-commands are represented.
Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk