Sorry really new to Fox and FXruby in particular. So these may be extreemly dumb questions. Does FXText have a native undo/redo function? I have written one from scrach for what I am doing but one exists, would really love to know how to use it. 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. -- View this message in context: http://www.nabble.com/FXText---undo-functions----keysend-of-Ctrl-%2B-z--tp15891260p15891260.html Sent from the FXRuby Users mailing list archive at Nabble.com.
Lyle Johnson
2008-Mar-07 17:26 UTC
[fxruby-users] FXText undo functions? keysend of Ctrl + z?
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
Jeroen van der Zijp
2008-Mar-07 19:44 UTC
[fxruby-users] FXText undo functions? keysend of Ctrl + z?
On Friday 07 March 2008, datatec wrote:> > Sorry really new to Fox and FXruby in particular. So these may be extreemly > dumb questions. > > > Does FXText have a native undo/redo function?It is intended that it could be hooked up to one; see Adie editor.> I have written one from scrach for what I am doing but one exists, would > really love to know how to use it.OK, FXText [and some other widgets too, BTW], have been written to emit some messages when changes are made to the contents by the user. For example, FXText emits SEL_INSERTED, SEL_REPLACED, SEL_DELETED messages, which reference a FXTextChange struct, which contains some information about the change that just took place. The typical thing to do is to stuff this information into a (subclass of) FXCommand, which is then hung under FXUndoList. Neat is, FXUndoList can be directly hooked up to FXMenuCommand or FXButton so that there is no further glue needed between the GUI and this functionality. In the case of Adie, these subclasses are called FXTextInsert, FXTextDelete, and FXTextReplace. Each of these corresponds to one of the possible callback messages from above. Of course, you can write your own methods to handle these as well. However, I recommend intercepting the same messages since they''re intended for this very same purpose and its probably less work than intercepting all possible keystrokes [plus, some text changes happen e.g. by means of drag and drop, and you wouldn''t know about these except via SEL_INSERTED, SEL_REPLACED, SEL_DELETED]. Hope this helps, Jeroen
Jeroen van der Zijp
2008-Mar-07 19:49 UTC
[fxruby-users] FXText undo functions? keysend of Ctrl + z?
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