Skip to content

Commit c80d7be

Browse files
patthoytsspearce
authored andcommitted
git-gui: use themed tk widgets with Tk 8.5
This patch enables the use of themed Tk widgets with Tk 8.5 and above. These make a significant difference on Windows in making the application appear native. On Windows and MacOSX ttk defaults to the native look as much as possible. On X11 the user may select a theme using the TkTheme XRDB resource class by adding an line to the .Xresources file. The set of installed theme names is available using the Tk command 'ttk::themes'. The default on X11 is similar to the current un-themed style - a kind of thin bordered motif look. A new git config variable 'gui.usettk' may be set to disable this if the user prefers the classic Tk look. Using Tk 8.4 will also avoid the use of themed widgets as these are only available since 8.5. Some support is included for Tk 8.6 features (themed spinbox and native font chooser for MacOSX and Windows). Signed-off-by: Pat Thoyts <[email protected]> Signed-off-by: Shawn O. Pearce <[email protected]>
1 parent ab2d3b0 commit c80d7be

26 files changed

+697
-453
lines changed

git-gui.sh

Lines changed: 102 additions & 56 deletions
Original file line numberDiff line numberDiff line change
@@ -677,12 +677,17 @@ if {[is_Windows]} {
677677
## config defaults
678678
679679
set cursor_ptr arrow
680-
font create font_diff -family Courier -size 10
681680
font create font_ui
682-
catch {
683-
label .dummy
684-
eval font configure font_ui [font actual [.dummy cget -font]]
685-
destroy .dummy
681+
if {[lsearch -exact [font names] TkDefaultFont] != -1} {
682+
eval [linsert [font actual TkDefaultFont] 0 font configure font_ui]
683+
eval [linsert [font actual TkFixedFont] 0 font create font_diff]
684+
} else {
685+
font create font_diff -family Courier -size 10
686+
catch {
687+
label .dummy
688+
eval font configure font_ui [font actual [.dummy cget -font]]
689+
destroy .dummy
690+
}
686691
}
687692
688693
font create font_uiitalic
@@ -697,6 +702,9 @@ foreach class {Button Checkbutton Entry Label
697702
}
698703
if {![is_MacOSX]} {
699704
option add *Menu.font font_ui
705+
option add *Entry.borderWidth 1 startupFile
706+
option add *Entry.relief sunken startupFile
707+
option add *RadioButton.anchor w startupFile
700708
}
701709
unset class
702710
@@ -749,6 +757,18 @@ proc apply_config {} {
749757
font configure ${font}bold -weight bold
750758
font configure ${font}italic -slant italic
751759
}
760+
761+
global use_ttk NS
762+
set use_ttk 0
763+
set NS {}
764+
if {$repo_config(gui.usettk)} {
765+
set use_ttk [package vsatisfies [package provide Tk] 8.5]
766+
if {$use_ttk} {
767+
set NS ttk
768+
bind [winfo class .] <<ThemeChanged>> [list InitTheme]
769+
pave_toplevel .
770+
}
771+
}
752772
}
753773
754774
set default_config(branch.autosetupmerge) true
@@ -775,6 +795,7 @@ set default_config(gui.fontui) [font configure font_ui]
775795
set default_config(gui.fontdiff) [font configure font_diff]
776796
# TODO: this option should be added to the git-config documentation
777797
set default_config(gui.maxfilesdisplayed) 5000
798+
set default_config(gui.usettk) 1
778799
set font_descs {
779800
{fontui font_ui {mc "Main Font"}}
780801
{fontdiff font_diff {mc "Diff/Console Font"}}
@@ -2093,7 +2114,7 @@ proc do_quit {{rc {1}}} {
20932114
global ui_comm is_quitting repo_config commit_type
20942115
global GITGUI_BCK_exists GITGUI_BCK_i
20952116
global ui_comm_spell
2096-
global ret_code
2117+
global ret_code use_ttk
20972118
20982119
if {$is_quitting} return
20992120
set is_quitting 1
@@ -2151,8 +2172,13 @@ proc do_quit {{rc {1}}} {
21512172
}
21522173
set cfg_geometry [list]
21532174
lappend cfg_geometry [wm geometry .]
2154-
lappend cfg_geometry [lindex [.vpane sash coord 0] 0]
2155-
lappend cfg_geometry [lindex [.vpane.files sash coord 0] 1]
2175+
if {$use_ttk} {
2176+
lappend cfg_geometry [.vpane sashpos 0]
2177+
lappend cfg_geometry [.vpane.files sashpos 0]
2178+
} else {
2179+
lappend cfg_geometry [lindex [.vpane sash coord 0] 0]
2180+
lappend cfg_geometry [lindex [.vpane.files sash coord 0] 1]
2181+
}
21562182
if {[catch {set rc_geometry $repo_config(gui.geometry)}]} {
21572183
set rc_geometry {}
21582184
}
@@ -2919,14 +2945,13 @@ default {
29192945
29202946
# -- Branch Control
29212947
#
2922-
frame .branch \
2923-
-borderwidth 1 \
2924-
-relief sunken
2925-
label .branch.l1 \
2948+
${NS}::frame .branch
2949+
if {!$use_ttk} {.branch configure -borderwidth 1 -relief sunken}
2950+
${NS}::label .branch.l1 \
29262951
-text [mc "Current Branch:"] \
29272952
-anchor w \
29282953
-justify left
2929-
label .branch.cb \
2954+
${NS}::label .branch.cb \
29302955
-textvariable current_branch \
29312956
-anchor w \
29322957
-justify left
@@ -2936,15 +2961,20 @@ pack .branch -side top -fill x
29362961
29372962
# -- Main Window Layout
29382963
#
2939-
panedwindow .vpane -orient horizontal
2940-
panedwindow .vpane.files -orient vertical
2941-
.vpane add .vpane.files -sticky nsew -height 100 -width 200
2964+
${NS}::panedwindow .vpane -orient horizontal
2965+
${NS}::panedwindow .vpane.files -orient vertical
2966+
if {$use_ttk} {
2967+
.vpane add .vpane.files
2968+
} else {
2969+
.vpane add .vpane.files -sticky nsew -height 100 -width 200
2970+
}
29422971
pack .vpane -anchor n -side top -fill both -expand 1
29432972
29442973
# -- Index File List
29452974
#
2946-
frame .vpane.files.index -height 100 -width 200
2947-
label .vpane.files.index.title -text [mc "Staged Changes (Will Commit)"] \
2975+
${NS}::frame .vpane.files.index -height 100 -width 200
2976+
tlabel .vpane.files.index.title \
2977+
-text [mc "Staged Changes (Will Commit)"] \
29482978
-background lightgreen -foreground black
29492979
text $ui_index -background white -foreground black \
29502980
-borderwidth 0 \
@@ -2954,17 +2984,17 @@ text $ui_index -background white -foreground black \
29542984
-xscrollcommand {.vpane.files.index.sx set} \
29552985
-yscrollcommand {.vpane.files.index.sy set} \
29562986
-state disabled
2957-
scrollbar .vpane.files.index.sx -orient h -command [list $ui_index xview]
2958-
scrollbar .vpane.files.index.sy -orient v -command [list $ui_index yview]
2987+
${NS}::scrollbar .vpane.files.index.sx -orient h -command [list $ui_index xview]
2988+
${NS}::scrollbar .vpane.files.index.sy -orient v -command [list $ui_index yview]
29592989
pack .vpane.files.index.title -side top -fill x
29602990
pack .vpane.files.index.sx -side bottom -fill x
29612991
pack .vpane.files.index.sy -side right -fill y
29622992
pack $ui_index -side left -fill both -expand 1
29632993
29642994
# -- Working Directory File List
29652995
#
2966-
frame .vpane.files.workdir -height 100 -width 200
2967-
label .vpane.files.workdir.title -text [mc "Unstaged Changes"] \
2996+
${NS}::frame .vpane.files.workdir -height 100 -width 200
2997+
tlabel .vpane.files.workdir.title -text [mc "Unstaged Changes"] \
29682998
-background lightsalmon -foreground black
29692999
text $ui_workdir -background white -foreground black \
29703000
-borderwidth 0 \
@@ -2974,15 +3004,19 @@ text $ui_workdir -background white -foreground black \
29743004
-xscrollcommand {.vpane.files.workdir.sx set} \
29753005
-yscrollcommand {.vpane.files.workdir.sy set} \
29763006
-state disabled
2977-
scrollbar .vpane.files.workdir.sx -orient h -command [list $ui_workdir xview]
2978-
scrollbar .vpane.files.workdir.sy -orient v -command [list $ui_workdir yview]
3007+
${NS}::scrollbar .vpane.files.workdir.sx -orient h -command [list $ui_workdir xview]
3008+
${NS}::scrollbar .vpane.files.workdir.sy -orient v -command [list $ui_workdir yview]
29793009
pack .vpane.files.workdir.title -side top -fill x
29803010
pack .vpane.files.workdir.sx -side bottom -fill x
29813011
pack .vpane.files.workdir.sy -side right -fill y
29823012
pack $ui_workdir -side left -fill both -expand 1
29833013
2984-
.vpane.files add .vpane.files.workdir -sticky nsew
2985-
.vpane.files add .vpane.files.index -sticky nsew
3014+
.vpane.files add .vpane.files.workdir
3015+
.vpane.files add .vpane.files.index
3016+
if {!$use_ttk} {
3017+
.vpane.files paneconfigure .vpane.files.workdir -sticky news
3018+
.vpane.files paneconfigure .vpane.files.index -sticky news
3019+
}
29863020
29873021
foreach i [list $ui_index $ui_workdir] {
29883022
rmsel_tag $i
@@ -2992,68 +3026,69 @@ unset i
29923026
29933027
# -- Diff and Commit Area
29943028
#
2995-
frame .vpane.lower -height 300 -width 400
2996-
frame .vpane.lower.commarea
2997-
frame .vpane.lower.diff -relief sunken -borderwidth 1
3029+
${NS}::frame .vpane.lower -height 300 -width 400
3030+
${NS}::frame .vpane.lower.commarea
3031+
${NS}::frame .vpane.lower.diff -relief sunken -borderwidth 1
29983032
pack .vpane.lower.diff -fill both -expand 1
29993033
pack .vpane.lower.commarea -side bottom -fill x
3000-
.vpane add .vpane.lower -sticky nsew
3034+
.vpane add .vpane.lower
3035+
if {!$use_ttk} {.vpane paneconfigure .vpane.lower -sticky nsew}
30013036
30023037
# -- Commit Area Buttons
30033038
#
3004-
frame .vpane.lower.commarea.buttons
3005-
label .vpane.lower.commarea.buttons.l -text {} \
3039+
${NS}::frame .vpane.lower.commarea.buttons
3040+
${NS}::label .vpane.lower.commarea.buttons.l -text {} \
30063041
-anchor w \
30073042
-justify left
30083043
pack .vpane.lower.commarea.buttons.l -side top -fill x
30093044
pack .vpane.lower.commarea.buttons -side left -fill y
30103045
3011-
button .vpane.lower.commarea.buttons.rescan -text [mc Rescan] \
3046+
${NS}::button .vpane.lower.commarea.buttons.rescan -text [mc Rescan] \
30123047
-command ui_do_rescan
30133048
pack .vpane.lower.commarea.buttons.rescan -side top -fill x
30143049
lappend disable_on_lock \
30153050
{.vpane.lower.commarea.buttons.rescan conf -state}
30163051
3017-
button .vpane.lower.commarea.buttons.incall -text [mc "Stage Changed"] \
3052+
${NS}::button .vpane.lower.commarea.buttons.incall -text [mc "Stage Changed"] \
30183053
-command do_add_all
30193054
pack .vpane.lower.commarea.buttons.incall -side top -fill x
30203055
lappend disable_on_lock \
30213056
{.vpane.lower.commarea.buttons.incall conf -state}
30223057
30233058
if {![is_enabled nocommitmsg]} {
3024-
button .vpane.lower.commarea.buttons.signoff -text [mc "Sign Off"] \
3059+
${NS}::button .vpane.lower.commarea.buttons.signoff -text [mc "Sign Off"] \
30253060
-command do_signoff
30263061
pack .vpane.lower.commarea.buttons.signoff -side top -fill x
30273062
}
30283063
3029-
button .vpane.lower.commarea.buttons.commit -text [commit_btn_caption] \
3064+
${NS}::button .vpane.lower.commarea.buttons.commit -text [commit_btn_caption] \
30303065
-command do_commit
30313066
pack .vpane.lower.commarea.buttons.commit -side top -fill x
30323067
lappend disable_on_lock \
30333068
{.vpane.lower.commarea.buttons.commit conf -state}
30343069
30353070
if {![is_enabled nocommit]} {
3036-
button .vpane.lower.commarea.buttons.push -text [mc Push] \
3071+
${NS}::button .vpane.lower.commarea.buttons.push -text [mc Push] \
30373072
-command do_push_anywhere
30383073
pack .vpane.lower.commarea.buttons.push -side top -fill x
30393074
}
30403075
30413076
# -- Commit Message Buffer
30423077
#
3043-
frame .vpane.lower.commarea.buffer
3044-
frame .vpane.lower.commarea.buffer.header
3078+
${NS}::frame .vpane.lower.commarea.buffer
3079+
${NS}::frame .vpane.lower.commarea.buffer.header
30453080
set ui_comm .vpane.lower.commarea.buffer.t
30463081
set ui_coml .vpane.lower.commarea.buffer.header.l
30473082
30483083
if {![is_enabled nocommit]} {
3049-
radiobutton .vpane.lower.commarea.buffer.header.new \
3084+
${NS}::radiobutton .vpane.lower.commarea.buffer.header.new \
30503085
-text [mc "New Commit"] \
30513086
-command do_select_commit_type \
30523087
-variable selected_commit_type \
30533088
-value new
30543089
lappend disable_on_lock \
30553090
[list .vpane.lower.commarea.buffer.header.new conf -state]
3056-
radiobutton .vpane.lower.commarea.buffer.header.amend \
3091+
${NS}::radiobutton .vpane.lower.commarea.buffer.header.amend \
30573092
-text [mc "Amend Last Commit"] \
30583093
-command do_select_commit_type \
30593094
-variable selected_commit_type \
@@ -3062,7 +3097,7 @@ if {![is_enabled nocommit]} {
30623097
[list .vpane.lower.commarea.buffer.header.amend conf -state]
30633098
}
30643099
3065-
label $ui_coml \
3100+
${NS}::label $ui_coml \
30663101
-anchor w \
30673102
-justify left
30683103
proc trace_commit_type {varname args} {
@@ -3094,7 +3129,7 @@ text $ui_comm -background white -foreground black \
30943129
-width $repo_config(gui.commitmsgwidth) -height 9 -wrap none \
30953130
-font font_diff \
30963131
-yscrollcommand {.vpane.lower.commarea.buffer.sby set}
3097-
scrollbar .vpane.lower.commarea.buffer.sby \
3132+
${NS}::scrollbar .vpane.lower.commarea.buffer.sby \
30983133
-command [list $ui_comm yview]
30993134
pack .vpane.lower.commarea.buffer.header -side top -fill x
31003135
pack .vpane.lower.commarea.buffer.sby -side right -fill y
@@ -3160,19 +3195,19 @@ proc trace_current_diff_path {varname args} {
31603195
}
31613196
trace add variable current_diff_path write trace_current_diff_path
31623197
3163-
frame .vpane.lower.diff.header -background gold
3164-
label .vpane.lower.diff.header.status \
3198+
gold_frame .vpane.lower.diff.header
3199+
tlabel .vpane.lower.diff.header.status \
31653200
-background gold \
31663201
-foreground black \
31673202
-width $max_status_desc \
31683203
-anchor w \
31693204
-justify left
3170-
label .vpane.lower.diff.header.file \
3205+
tlabel .vpane.lower.diff.header.file \
31713206
-background gold \
31723207
-foreground black \
31733208
-anchor w \
31743209
-justify left
3175-
label .vpane.lower.diff.header.path \
3210+
tlabel .vpane.lower.diff.header.path \
31763211
-background gold \
31773212
-foreground black \
31783213
-anchor w \
@@ -3196,7 +3231,7 @@ bind_button3 .vpane.lower.diff.header.path "tk_popup $ctxm %X %Y"
31963231
31973232
# -- Diff Body
31983233
#
3199-
frame .vpane.lower.diff.body
3234+
${NS}::frame .vpane.lower.diff.body
32003235
set ui_diff .vpane.lower.diff.body.t
32013236
text $ui_diff -background white -foreground black \
32023237
-borderwidth 0 \
@@ -3205,9 +3240,9 @@ text $ui_diff -background white -foreground black \
32053240
-xscrollcommand {.vpane.lower.diff.body.sbx set} \
32063241
-yscrollcommand {.vpane.lower.diff.body.sby set} \
32073242
-state disabled
3208-
scrollbar .vpane.lower.diff.body.sbx -orient horizontal \
3243+
${NS}::scrollbar .vpane.lower.diff.body.sbx -orient horizontal \
32093244
-command [list $ui_diff xview]
3210-
scrollbar .vpane.lower.diff.body.sby -orient vertical \
3245+
${NS}::scrollbar .vpane.lower.diff.body.sby -orient vertical \
32113246
-command [list $ui_diff yview]
32123247
pack .vpane.lower.diff.body.sbx -side bottom -fill x
32133248
pack .vpane.lower.diff.body.sby -side right -fill y
@@ -3428,12 +3463,17 @@ $main_status show [mc "Initializing..."]
34283463
catch {
34293464
set gm $repo_config(gui.geometry)
34303465
wm geometry . [lindex $gm 0]
3431-
.vpane sash place 0 \
3432-
[lindex $gm 1] \
3433-
[lindex [.vpane sash coord 0] 1]
3434-
.vpane.files sash place 0 \
3435-
[lindex [.vpane.files sash coord 0] 0] \
3436-
[lindex $gm 2]
3466+
if {$use_ttk} {
3467+
.vpane sashpos 0 [lindex $gm 1]
3468+
.vpane.files sashpos 0 [lindex $gm 2]
3469+
} else {
3470+
.vpane sash place 0 \
3471+
[lindex $gm 1] \
3472+
[lindex [.vpane sash coord 0] 1]
3473+
.vpane.files sash place 0 \
3474+
[lindex [.vpane.files sash coord 0] 0] \
3475+
[lindex $gm 2]
3476+
}
34373477
unset gm
34383478
}
34393479
@@ -3701,3 +3741,9 @@ if {[is_enabled retcode]} {
37013741
if {$picked && [is_config_true gui.autoexplore]} {
37023742
do_explore
37033743
}
3744+
3745+
# Local variables:
3746+
# mode: tcl
3747+
# indent-tabs-mode: t
3748+
# tab-width: 4
3749+
# End:

0 commit comments

Comments
 (0)