Skip to content

Commit c0932ed

Browse files
committed
gitk: add theme selection to color configuration page
gitk allows configuring a particular theme in its configuration file (default on linux: ~/.config/git/gitk), but offers no ability to modify this from gitk's configuration editor. Let's add this to the color configuration page. Present the offered themes in a list, and allow choosing / modifying a theme definition file ($themeloader). Update the list of themes if the theme file is modified, and update the theme if specifically requested (by default, just change the value for use after gitk is restarted). Any theme definition file can change the global options database, affecting potentially any theme. So, the ultimate configuration should have either - no theme definition file (themeloader = {}), and a native Tk, theme, or - themeloader naming a valid file, and $theme naming a theme defined by that file. But, there is no trivial way to enforce the above. Shrug. Helped-by: Johannes Sixt <[email protected]> Signed-off-by: Mark Levedahl <[email protected]>
1 parent 830c457 commit c0932ed

File tree

1 file changed

+53
-1
lines changed

1 file changed

+53
-1
lines changed

gitk

Lines changed: 53 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11735,9 +11735,32 @@ proc prefspage_general {notebook} {
1173511735
proc prefspage_colors {notebook} {
1173611736
global bgcolor fgcolor ctext diffcolors selectbgcolor markbgcolor
1173711737
global diffbgcolors
11738+
global themeloader
1173811739
1173911740
set page [create_prefs_page $notebook.colors]
1174011741
11742+
ttk::label $page.themesel -font mainfontbold \
11743+
-text [mc "Themes - change requires restart"]
11744+
grid $page.themesel - -sticky w -pady 10
11745+
ttk::label $page.themelabel -text [mc "Theme to use after restart"]
11746+
makedroplist $page.theme theme {*}[lsort [ttk::style theme names]]
11747+
grid x $page.themelabel $page.theme -sticky w
11748+
11749+
ttk::entry $page.tloadvar -textvariable themeloader
11750+
ttk::frame $page.tloadframe
11751+
ttk::label $page.tloadframe.l -text [mc "Theme definition file"]
11752+
ttk::button $page.tloadframe.b -text [mc "Choose..."] \
11753+
-command [list choose_themeloader $page]
11754+
pack $page.tloadframe.l $page.tloadframe.b -side left -padx 2
11755+
pack configure $page.tloadframe.l -padx 0
11756+
grid x $page.tloadframe $page.tloadvar -sticky ew
11757+
11758+
ttk::label $page.themelabel2 -text \
11759+
[mc "The theme definition file may affect all themes."]
11760+
ttk::button $page.themebut2 -text [mc "Apply theme"] \
11761+
-command [list updatetheme $page]
11762+
grid x $page.themebut2 $page.themelabel2 -sticky w
11763+
1174111764
ttk::label $page.cdisp -text [mc "Colors: press to choose"] -font mainfontbold
1174211765
grid $page.cdisp - -sticky w -pady 10
1174311766
label $page.bg -padx 40 -relief sunk -background $bgcolor
@@ -11878,6 +11901,34 @@ proc run_themeloader {f} {
1187811901
return [dict get $::_themefiles_seen $fn]
1187911902
}
1188011903
11904+
proc updatetheme {prefspage {dotheme 1}} {
11905+
global theme
11906+
global themeloader
11907+
if {$themeloader ne {}} {
11908+
if {![run_themeloader $themeloader]} {
11909+
set themeloader {}
11910+
return
11911+
} else {
11912+
$prefspage.theme configure -values \
11913+
[lsort [ttk::style theme names]]
11914+
}
11915+
}
11916+
if {$dotheme} {
11917+
ttk::style theme use $theme
11918+
set_gui_colors
11919+
prefspage_set_colorswatches $prefspage
11920+
}
11921+
}
11922+
11923+
proc choose_themeloader {prefspage} {
11924+
global themeloader
11925+
set tfile [tk_getOpenFile -title [mc "Gitk: select theme definition"] -multiple false]
11926+
if {$tfile ne {}} {
11927+
set themeloader $tfile
11928+
updatetheme $prefspage 0
11929+
}
11930+
}
11931+
1188111932
proc choosecolor {v vi prefspage x} {
1188211933
global $v
1188311934
@@ -11949,6 +12000,7 @@ proc prefscan {} {
1194912000
catch {destroy $prefstop}
1195012001
unset prefstop
1195112002
fontcan
12003+
setttkstyle
1195212004
set_gui_colors
1195312005
}
1195412006
@@ -12759,7 +12811,7 @@ set nullid2 "0000000000000000000000000000000000000001"
1275912811
set nullfile "/dev/null"
1276012812
1276112813
if {[file exists $themeloader]} {
12762-
if {[run_themeloader $themeloader] == 0} {
12814+
if {![run_themeloader $themeloader]} {
1276312815
puts stderr "Could not interpret themeloader: $themeloader"
1276412816
exit 1
1276512817
}

0 commit comments

Comments
 (0)