[fxruby-users] FXText undo functions? keysend of Ctrl + z?

Lyle Johnson lyle at lylejohnson.name
Fri Mar 7 12:26:52 EST 2008


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).

Hope this helps,

Lyle

---
"FXRuby: Create Lean and Mean GUIs with Ruby"
Now available as a Beta book from the Pragmatic Bookshelf
http://www.pragprog.com/titles/fxruby





More information about the fxruby-users mailing list