[Gnocl -the Tcl/Gtk Bindings] Cancellation of a Recent Pull-Down Menu

已查看 3 次
跳至第一个未读帖子

William J Giddings

未读,
2015年1月20日 08:20:092015/1/20
收件人 gn...@googlegroups.com
Its been some time since support for 'recent file' operations was first added to the Gnocl sources. At the time I was quite pleased with its inclusion but there was always a annoying snag to it, something which is an inhereted feature from the API: if no selection if made, then the last file URI added to the list is always returned. This is not really a sign of anything lacking in the GTK sources, but the documentation does not suggest how to handle any need to CANCEL the menu by pressing the 'ESC' key.
 A quick gloss over the docs shows that there is a 'cancel' signal for the MENU-SHELL containing the recent items, but this automatically generates a 'selection-done' signal, the very signal that we want to avoid. The obvious solution for this is to set a boolean cancel flag and test for its TRUE or FALSE state during the execution of any 'selection-done' event handler.

For a TCL side solution it was first was necessary to implement a gnocl -onCancel option. So, this could added to any test script:

set cancel 0
set rc_menu [gnocl::menuRecentChooser \
...
-onCancel {  set cancel 1 } \
-onClicked {
     if { !$cancel } {
        set fname [string range %f 5 end]
        openFile $fname
        }
    set cancel 0
}

Works nicely, but its better if this becomes invisible to the scripter.This of course, is not a problem to implement in C and so the relevant handlers have been modified to offer the benefit of this functionality.

--
Posted By William J Giddings to Gnocl -the Tcl/Gtk Bindings on 1/20/2015 01:20:00 pm
回复全部
回复作者
转发
0 个新帖子