Skip to content

Commit 30508bc

Browse files
committed
Amend tab ordering and text widget border and highlighting.
Tab order follows widget creation order (and Z-order) so amend this to match the layout more logically. For keyboard selection a highlight around the selected text widget is useful. Customized on Windows themed Tk to follow the native theme more closely with a custom EntryFrame style. Signed-off-by: Pat Thoyts <[email protected]>
1 parent 088ad75 commit 30508bc

File tree

2 files changed

+124
-31
lines changed

2 files changed

+124
-31
lines changed

git-gui.sh

Lines changed: 38 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -3194,13 +3194,34 @@ if {$use_ttk} {
31943194
}
31953195
pack .vpane -anchor n -side top -fill both -expand 1
31963196
3197+
# -- Working Directory File List
3198+
3199+
textframe .vpane.files.workdir -height 100 -width 200
3200+
tlabel .vpane.files.workdir.title -text [mc "Unstaged Changes"] \
3201+
-background lightsalmon -foreground black
3202+
ttext $ui_workdir -background white -foreground black \
3203+
-borderwidth 0 \
3204+
-width 20 -height 10 \
3205+
-wrap none \
3206+
-takefocus 1 -highlightthickness 1\
3207+
-cursor $cursor_ptr \
3208+
-xscrollcommand {.vpane.files.workdir.sx set} \
3209+
-yscrollcommand {.vpane.files.workdir.sy set} \
3210+
-state disabled
3211+
${NS}::scrollbar .vpane.files.workdir.sx -orient h -command [list $ui_workdir xview]
3212+
${NS}::scrollbar .vpane.files.workdir.sy -orient v -command [list $ui_workdir yview]
3213+
pack .vpane.files.workdir.title -side top -fill x
3214+
pack .vpane.files.workdir.sx -side bottom -fill x
3215+
pack .vpane.files.workdir.sy -side right -fill y
3216+
pack $ui_workdir -side left -fill both -expand 1
3217+
31973218
# -- Index File List
31983219
#
3199-
${NS}::frame .vpane.files.index -height 100 -width 200
3220+
textframe .vpane.files.index -height 100 -width 200
32003221
tlabel .vpane.files.index.title \
32013222
-text [mc "Staged Changes (Will Commit)"] \
32023223
-background lightgreen -foreground black
3203-
text $ui_index -background white -foreground black \
3224+
ttext $ui_index -background white -foreground black \
32043225
-borderwidth 0 \
32053226
-width 20 -height 10 \
32063227
-wrap none \
@@ -3216,27 +3237,8 @@ pack .vpane.files.index.sx -side bottom -fill x
32163237
pack .vpane.files.index.sy -side right -fill y
32173238
pack $ui_index -side left -fill both -expand 1
32183239
3219-
# -- Working Directory File List
3240+
# -- Insert the workdir and index into the panes
32203241
#
3221-
${NS}::frame .vpane.files.workdir -height 100 -width 200
3222-
tlabel .vpane.files.workdir.title -text [mc "Unstaged Changes"] \
3223-
-background lightsalmon -foreground black
3224-
text $ui_workdir -background white -foreground black \
3225-
-borderwidth 0 \
3226-
-width 20 -height 10 \
3227-
-wrap none \
3228-
-takefocus 1 -highlightthickness 1\
3229-
-cursor $cursor_ptr \
3230-
-xscrollcommand {.vpane.files.workdir.sx set} \
3231-
-yscrollcommand {.vpane.files.workdir.sy set} \
3232-
-state disabled
3233-
${NS}::scrollbar .vpane.files.workdir.sx -orient h -command [list $ui_workdir xview]
3234-
${NS}::scrollbar .vpane.files.workdir.sy -orient v -command [list $ui_workdir yview]
3235-
pack .vpane.files.workdir.title -side top -fill x
3236-
pack .vpane.files.workdir.sx -side bottom -fill x
3237-
pack .vpane.files.workdir.sy -side right -fill y
3238-
pack $ui_workdir -side left -fill both -expand 1
3239-
32403242
.vpane.files add .vpane.files.workdir
32413243
.vpane.files add .vpane.files.index
32423244
if {!$use_ttk} {
@@ -3319,7 +3321,7 @@ if {![is_enabled nocommit]} {
33193321
#
33203322
${NS}::frame .vpane.lower.commarea.buffer
33213323
${NS}::frame .vpane.lower.commarea.buffer.header
3322-
set ui_comm .vpane.lower.commarea.buffer.t
3324+
set ui_comm .vpane.lower.commarea.buffer.frame.t
33233325
set ui_coml .vpane.lower.commarea.buffer.header.l
33243326
33253327
if {![is_enabled nocommit]} {
@@ -3362,20 +3364,25 @@ if {![is_enabled nocommit]} {
33623364
pack .vpane.lower.commarea.buffer.header.new -side right
33633365
}
33643366
3365-
text $ui_comm -background white -foreground black \
3367+
textframe .vpane.lower.commarea.buffer.frame
3368+
ttext $ui_comm -background white -foreground black \
33663369
-borderwidth 1 \
33673370
-undo true \
33683371
-maxundo 20 \
33693372
-autoseparators true \
3373+
-takefocus 1 \
3374+
-highlightthickness 1 \
33703375
-relief sunken \
33713376
-width $repo_config(gui.commitmsgwidth) -height 9 -wrap none \
33723377
-font font_diff \
3373-
-yscrollcommand {.vpane.lower.commarea.buffer.sby set}
3374-
${NS}::scrollbar .vpane.lower.commarea.buffer.sby \
3378+
-yscrollcommand {.vpane.lower.commarea.buffer.frame.sby set}
3379+
${NS}::scrollbar .vpane.lower.commarea.buffer.frame.sby \
33753380
-command [list $ui_comm yview]
3376-
pack .vpane.lower.commarea.buffer.header -side top -fill x
3377-
pack .vpane.lower.commarea.buffer.sby -side right -fill y
3381+
3382+
pack .vpane.lower.commarea.buffer.frame.sby -side right -fill y
33783383
pack $ui_comm -side left -fill y
3384+
pack .vpane.lower.commarea.buffer.header -side top -fill x
3385+
pack .vpane.lower.commarea.buffer.frame -side left -fill y
33793386
pack .vpane.lower.commarea.buffer -side left -fill y
33803387
33813388
# -- Commit Message Buffer Context Menu
@@ -3473,12 +3480,13 @@ bind_button3 .vpane.lower.diff.header.path "tk_popup $ctxm %X %Y"
34733480
34743481
# -- Diff Body
34753482
#
3476-
${NS}::frame .vpane.lower.diff.body
3483+
textframe .vpane.lower.diff.body
34773484
set ui_diff .vpane.lower.diff.body.t
3478-
text $ui_diff -background white -foreground black \
3485+
ttext $ui_diff -background white -foreground black \
34793486
-borderwidth 0 \
34803487
-width 80 -height 5 -wrap none \
34813488
-font font_diff \
3489+
-takefocus 1 -highlightthickness 1 \
34823490
-xscrollcommand {.vpane.lower.diff.body.sbx set} \
34833491
-yscrollcommand {.vpane.lower.diff.body.sby set} \
34843492
-state disabled

lib/themed.tcl

Lines changed: 86 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,57 @@ proc InitTheme {} {
7878
}
7979
}
8080

81+
# Define a style used for the surround of text widgets.
82+
proc InitEntryFrame {} {
83+
ttk::style theme settings default {
84+
ttk::style layout EntryFrame {
85+
EntryFrame.field -sticky nswe -border 0 -children {
86+
EntryFrame.fill -sticky nswe -children {
87+
EntryFrame.padding -sticky nswe
88+
}
89+
}
90+
}
91+
ttk::style configure EntryFrame -padding 1 -relief sunken
92+
ttk::style map EntryFrame -background {}
93+
}
94+
ttk::style theme settings classic {
95+
ttk::style configure EntryFrame -padding 2 -relief sunken
96+
ttk::style map EntryFrame -background {}
97+
}
98+
ttk::style theme settings alt {
99+
ttk::style configure EntryFrame -padding 2
100+
ttk::style map EntryFrame -background {}
101+
}
102+
ttk::style theme settings clam {
103+
ttk::style configure EntryFrame -padding 2
104+
ttk::style map EntryFrame -background {}
105+
}
106+
107+
# Ignore errors for missing native themes
108+
catch {
109+
ttk::style theme settings winnative {
110+
ttk::style configure EntryFrame -padding 2
111+
}
112+
ttk::style theme settings xpnative {
113+
ttk::style configure EntryFrame -padding 1
114+
ttk::style element create EntryFrame.field vsapi \
115+
EDIT 1 {disabled 4 focus 3 active 2 {} 1} -padding 1
116+
}
117+
ttk::style theme settings vista {
118+
ttk::style configure EntryFrame -padding 2
119+
ttk::style element create EntryFrame.field vsapi \
120+
EDIT 6 {disabled 4 focus 3 active 2 {} 1} -padding 2
121+
}
122+
}
123+
124+
bind EntryFrame <Enter> {%W instate !disabled {%W state active}}
125+
bind EntryFrame <Leave> {%W state !active}
126+
bind EntryFrame <<ThemeChanged>> {
127+
set pad [ttk::style lookup EntryFrame -padding]
128+
%W configure -padding [expr {$pad eq {} ? 1 : $pad}]
129+
}
130+
}
131+
81132
proc gold_frame {w args} {
82133
global use_ttk
83134
if {$use_ttk} {
@@ -123,7 +174,7 @@ proc paddedlabel {w args} {
123174
# place a themed frame over the surface.
124175
proc Dialog {w args} {
125176
eval [linsert $args 0 toplevel $w -class Dialog]
126-
catch {wm attributes $w -type dialog}
177+
catch {wm attributes $w -type dialog}
127178
pave_toplevel $w
128179
return $w
129180
}
@@ -193,6 +244,40 @@ proc tspinbox {w args} {
193244
}
194245
}
195246

247+
# Create a text widget with any theme specific properties.
248+
proc ttext {w args} {
249+
global use_ttk
250+
if {$use_ttk} {
251+
switch -- [ttk::style theme use] {
252+
"vista" - "xpnative" {
253+
lappend args -highlightthickness 0 -borderwidth 0
254+
}
255+
}
256+
}
257+
set w [eval [linsert $args 0 text $w]]
258+
if {$use_ttk} {
259+
if {[winfo class [winfo parent $w]] eq "EntryFrame"} {
260+
bind $w <FocusIn> {[winfo parent %W] state focus}
261+
bind $w <FocusOut> {[winfo parent %W] state !focus}
262+
}
263+
}
264+
return $w
265+
}
266+
267+
# themed frame suitable for surrounding a text field.
268+
proc textframe {w args} {
269+
global use_ttk
270+
if {$use_ttk} {
271+
if {[catch {ttk::style layout EntryFrame}]} {
272+
InitEntryFrame
273+
}
274+
eval [linsert $args 0 ttk::frame $w -class EntryFrame -style EntryFrame]
275+
} else {
276+
eval [linsert $args 0 frame $w]
277+
}
278+
return $w
279+
}
280+
196281
proc tentry {w args} {
197282
global use_ttk
198283
if {$use_ttk} {

0 commit comments

Comments
 (0)