@matheusbsbs / matheus-bagliano / commits / fb08baca33
Fork 0

git-gui: Prefer Tk's entry widget over a 1 line text field.

I'm a fool and previously used a text widget configured with a height of 1 and special bindings to handle focus traversal rather than the already built (and properly behaved) entry widget. Signed-off-by: Shawn O. Pearce <spearce@spearce.org>

Shawn O. Pearce committed Jan 25, 2007 at 16:50 UTC fb08baca3340099d149a88f6ede19a6870870c08
1 file changed +33 -42
git-gui.sh
+33 -42
@@ -1865,8 +1865,9 @@ proc do_create_branch_action {w} {
1865 global all_heads null_sha1 repo_config
1866 global create_branch_checkout create_branch_revtype
1867 global create_branch_head create_branch_trackinghead
1868 + global create_branch_name create_branch_revexp
1869
1869 - set newbranch [string trim [$w.desc.name_t get 0.0 end]]
1870 + set newbranch $create_branch_name
1871 if {$newbranch eq {}
1872 || $newbranch eq $repo_config(gui.newbranchtemplate)} {
1873 tk_messageBox \
@@ -1903,7 +1904,7 @@ proc do_create_branch_action {w} {
1904 switch -- $create_branch_revtype {
1905 head {set rev $create_branch_head}
1906 tracking {set rev $create_branch_trackinghead}
1906 - expression {set rev [string trim [$w.from.exp_t get 0.0 end]]}
1907 + expression {set rev $create_branch_revexp}
1908 }
1909 if {[catch {set cmt [exec git rev-parse --verify "${rev}^0"]}]} {
1910 tk_messageBox \
@@ -1958,6 +1959,7 @@ proc do_create_branch {} {
1959 global all_heads current_branch repo_config
1960 global create_branch_checkout create_branch_revtype
1961 global create_branch_head create_branch_trackinghead
1962 + global create_branch_name create_branch_revexp
1963
1964 set w .branch_editor
1965 toplevel $w
@@ -1983,26 +1985,18 @@ proc do_create_branch {} {
1985 -text {Branch Description} \
1986 -font font_ui
1987 label $w.desc.name_l -text {Name:} -font font_ui
1986 - text $w.desc.name_t \
1988 + entry $w.desc.name_t \
1989 -borderwidth 1 \
1990 -relief sunken \
1989 - -height 1 \
1991 -width 40 \
1991 - -font font_ui
1992 - $w.desc.name_t insert 0.0 $repo_config(gui.newbranchtemplate)
1993 - grid $w.desc.name_l $w.desc.name_t -sticky we -padx {0 5}
1994 - bind $w.desc.name_t <Shift-Key-Tab> {focus [tk_focusPrev %W];break}
1995 - bind $w.desc.name_t <Key-Tab> {focus [tk_focusNext %W];break}
1996 - bind $w.desc.name_t <Key-Return> "do_create_branch_action $w;break"
1997 - bind $w.desc.name_t <Key> {
1998 - if {{%K} ne {BackSpace}
1999 - && {%K} ne {Tab}
2000 - && {%K} ne {Escape}
2001 - && {%K} ne {Return}} {
2002 - if {%k <= 32} break
2003 - if {[string first %A {~^:?*[}] >= 0} break
1992 + -textvariable create_branch_name \
1993 + -font font_ui \
1994 + -validate key \
1995 + -validatecommand {
1996 + if {%d == 1 && [regexp {[~^:?*\[\0- ]} %S]} {return 0}
1997 + return 1
1998 }
2005 - }
1999 + grid $w.desc.name_l $w.desc.name_t -sticky we -padx {0 5}
2000 grid columnconfigure $w.desc 1 -weight 1
2001 pack $w.desc -anchor nw -fill x -pady 5 -padx 5
2002
@@ -2034,18 +2028,21 @@ proc do_create_branch {} {
2028 -value expression \
2029 -variable create_branch_revtype \
2030 -font font_ui
2037 - text $w.from.exp_t \
2031 + entry $w.from.exp_t \
2032 -borderwidth 1 \
2033 -relief sunken \
2040 - -height 1 \
2034 -width 50 \
2042 - -font font_ui
2035 + -textvariable create_branch_revexp \
2036 + -font font_ui \
2037 + -validate key \
2038 + -validatecommand {
2039 + if {%d == 1 && [regexp {\s} %S]} {return 0}
2040 + if {%d == 1 && [string length %S] > 0} {
2041 + set create_branch_revtype expression
2042 + }
2043 + return 1
2044 + }
2045 grid $w.from.exp_r $w.from.exp_t -sticky we -padx {0 5}
2044 - bind $w.from.exp_t <Shift-Key-Tab> {focus [tk_focusPrev %W];break}
2045 - bind $w.from.exp_t <Key-Tab> {focus [tk_focusNext %W];break}
2046 - bind $w.from.exp_t <Key-Return> "do_create_branch_action $w;break"
2047 - bind $w.from.exp_t <Key-space> break
2048 - bind $w.from.exp_t <Key> {set create_branch_revtype expression}
2046 grid columnconfigure $w.from 1 -weight 1
2047 pack $w.from -anchor nw -fill x -pady 5 -padx 5
2048
@@ -2062,8 +2059,14 @@ proc do_create_branch {} {
2059 set create_branch_checkout 1
2060 set create_branch_head $current_branch
2061 set create_branch_revtype head
2062 + set create_branch_name $repo_config(gui.newbranchtemplate)
2063 + set create_branch_revexp {}
2064
2066 - bind $w <Visibility> "grab $w; focus $w.desc.name_t"
2065 + bind $w <Visibility> "
2066 + grab $w
2067 + $w.desc.name_t icursor end
2068 + focus $w.desc.name_t
2069 + "
2070 bind $w <Key-Escape> "destroy $w"
2071 bind $w <Key-Return> "do_create_branch_action $w;break"
2072 wm title $w "[appname] ([reponame]): Create Branch"
@@ -3329,10 +3332,7 @@ proc do_options {} {
3332 pack $w.buttons.restore -side left
3333 button $w.buttons.save -text Save \
3334 -font font_ui \
3332 - -command "
3333 - catch {eval \[bind \[focus -displayof $w\] <FocusOut>\]}
3334 - do_save_config $w
3335 - "
3335 + -command [list do_save_config $w]
3336 pack $w.buttons.save -side right
3337 button $w.buttons.cancel -text {Cancel} \
3338 -font font_ui \
@@ -3382,21 +3382,12 @@ proc do_options {} {
3382 t {
3383 frame $w.$f.$name
3384 label $w.$f.$name.l -text "$text:" -font font_ui
3385 - text $w.$f.$name.v \
3385 + entry $w.$f.$name.v \
3386 -borderwidth 1 \
3387 -relief sunken \
3388 - -height 1 \
3388 -width 20 \
3389 + -textvariable ${f}_config_new(gui.$name) \
3390 -font font_ui
3391 - $w.$f.$name.v insert 0.0 [set ${f}_config_new(gui.$name)]
3392 - bind $w.$f.$name.v <Shift-Key-Tab> {focus [tk_focusPrev %W];break}
3393 - bind $w.$f.$name.v <Key-Tab> {focus [tk_focusNext %W];break}
3394 - bind $w.$f.$name.v <Key-Return> break
3395 - bind $w.$f.$name.v <FocusIn> "$w.$f.$name.v tag add sel 0.0 end"
3396 - bind $w.$f.$name.v <FocusOut> "
3397 - set ${f}_config_new(gui.$name) \
3398 - \[string trim \[$w.$f.$name.v get 0.0 end\]\]
3399 - "
3391 pack $w.$f.$name.l -side left -anchor w
3392 pack $w.$f.$name.v -side left -anchor w \
3393 -fill x -expand 1 \