diff options
author | patthoyts <patthoyts@noemail.net> | 2010-01-04 21:22:07 (GMT) |
---|---|---|
committer | patthoyts <patthoyts@noemail.net> | 2010-01-04 21:22:07 (GMT) |
commit | b895fd731abf46328753ee508d4ea609e99d32c7 (patch) | |
tree | 83f909d61e5648d9f1f170aba1afebdeb0946e75 | |
parent | 2f0e049c7c36ef566c229a458e1797ad1c6a7116 (diff) | |
download | tk-b895fd731abf46328753ee508d4ea609e99d32c7.zip tk-b895fd731abf46328753ee508d4ea609e99d32c7.tar.gz tk-b895fd731abf46328753ee508d4ea609e99d32c7.tar.bz2 |
Fix the <Return> binding for tk_dialog to invoke the focused button.
The standard for Windows and Gtk+ is that the <Return> binding invokes
the button that currently has the keyboard focus. This can be seen in
tk_messageBox which implements this.
This patch implements this feature and also makes use of the tk grab
utility functions to replace the grab handling code.
FossilOrigin-Name: 8f0a215fbfd4a977ec7a1669bffd68a047318e89
-rw-r--r-- | ChangeLog | 2 | ||||
-rw-r--r-- | library/dialog.tcl | 35 |
2 files changed, 13 insertions, 24 deletions
@@ -1,5 +1,7 @@ 2010-01-04 Pat Thoyts <patthoyts@users.sourceforge.net> + * library/dialog.tcl: [Bug 2811266] <Return> binding should invoke + the button with the focus. * library/fontchooser.tcl: [Bug 2727476] Fix default size of font chooser dialog and assigned minimum sizes for the lists. * library/console.tcl: [Bug 580361] Fix console <<Cut>> binding. diff --git a/library/dialog.tcl b/library/dialog.tcl index b032b62..5012823 100644 --- a/library/dialog.tcl +++ b/library/dialog.tcl @@ -3,7 +3,7 @@ # This file defines the procedure tk_dialog, which creates a dialog # box containing a bitmap, a message, and one or more buttons. # -# RCS: @(#) $Id: dialog.tcl,v 1.24 2007/12/13 15:26:27 dgp Exp $ +# RCS: @(#) $Id: dialog.tcl,v 1.25 2010/01/04 21:22:08 patthoyts Exp $ # # Copyright (c) 1992-1993 The Regents of the University of California. # Copyright (c) 1994-1997 Sun Microsystems, Inc. @@ -129,15 +129,14 @@ proc ::tk_dialog {w title text bitmap default args} { # 4. Create a binding for <Return> on the dialog if there is a # default button. + # Convention also dictates that if the keyboard focus moves among the + # the buttons that the <Return> binding affects the button with the focus. if {$default >= 0} { - bind $w <Return> " - [list $w.button$default] configure -state active -relief sunken - update idletasks - after 100 - set ::tk::Priv(button) $default - " + bind $w <Return> [list $w.button$default invoke] } + bind $w <<PrevWindow>> [list bind $w <Return> {[tk_focusPrev %W] invoke}] + bind $w <<NextWindow>> [list bind $w <Return> {[tk_focusNext %W] invoke}] # 5. Create a <Destroy> binding for the window that sets the # button variable to -1; this is needed in case something happens @@ -172,17 +171,12 @@ proc ::tk_dialog {w title text bitmap default args} { # 7. Set a grab and claim the focus too. - set oldFocus [focus] - set oldGrab [grab current $w] - if {$oldGrab ne ""} { - set grabStatus [grab status $oldGrab] - } - grab $w if {$default >= 0} { - focus $w.button$default + set focus $w.button$default } else { - focus $w + set focus $w } + tk::SetFocusGrab $w $focus # 8. Wait for the user to respond, then restore the focus and # return the index of the selected button. Restore the focus @@ -191,21 +185,14 @@ proc ::tk_dialog {w title text bitmap default args} { # restore any grab that was in effect. vwait ::tk::Priv(button) - catch {focus $oldFocus} + catch { # It's possible that the window has already been destroyed, # hence this "catch". Delete the Destroy handler so that # Priv(button) doesn't get reset by it. bind $w <Destroy> {} - destroy $w - } - if {$oldGrab ne ""} { - if {$grabStatus ne "global"} { - grab $oldGrab - } else { - grab -global $oldGrab - } } + tk::RestoreFocusGrab $w $focus return $Priv(button) } |