[fxruby-users] FXText undo functions? keysend of Ctrl + z?
Jeroen van der Zijp
jeroen at fox-toolkit.org
Fri Mar 7 14:49:58 EST 2008
On Friday 07 March 2008, Lyle Johnson wrote:
>
> On Mar 7, 2008, at 8:56 AM, datatec wrote:
>
> > Does FXText have a native undo/redo function?
>
> No, there's no built-in undo/redo capability for FXText (or any of the
> other widgets). There is however an FXUndoList class in the library
> that provides a sample implementation of an undo/redo capability for
> FXRuby applications. You can read about the FXUndoList class here:
>
> http://www.fxruby.org/doc/api/classes/Fox/FXUndoList.html
>
> and its use is demonstrated in the textedit.rb example program
> included with the FXRuby source distribution.
>
> > Secondly I am using something like this for the undo functon
> >
> > @text.connect(SEL_KEYRELEASE) { |sender, sel, event|
> > if event.code == KEY_Control_R
> > puts "UNDO Pressed (Ctrl R)"
> > undofunct()
> >
> > I really would like to change this to a generic any Ctrl key + the z
> > key
> > but cannot seem to find how to do something that happens only when
> > two keys
> > are pressed in combination.
>
> You need to test both the event.code and the event.state, e.g.
>
> if event.code == KEY_r && ((event.state & CONTROLMASK) != 0)
> puts "UNDO pressed...
> ...
> end
>
> A different approach would be to add an application-wide keyboard
> accelerator that maps to this keypress. I believe this technique is
> demonstrated in the textedit.rb example (mentioned earlier).
Regardless of whether FXUndoList is used, the best way to track
changes to widgets is SEL_INSERTED, SEL_REPLACED, and SEL_DELETED.
These are reliably generated when the FXText widget is changed, by
any means [including programmatically, if notify==true].
For instance, drag and drop, clipboard, and so on, also generate
these messages. Tracking keys is a bad idea since you would not
be notified when the text changes by other means.
Hope this helps,
- Jeroen
More information about the fxruby-users
mailing list