gitk: restore ui colors after cancelling config dialog
gitk provides a dialog to configure many ui colors. Any color element changed in the dialog takes immediate effect before closing the dialog. While cancelling the dialog after changing one or more colors avoids saving the modified colors, the user must restart gitk to restore the prior color set. This unfortunate behavior results because gitk does not have a single routine to update all of the ui colors. The prior commit eliminated the key impediment to having such a routine. So, let's create a routine to update all configured colors at once, use this when modifying colors, and also invoke this after restoring the prior set if the dialog is cancelled. Signed-off-by: Mark Levedahl <mlevedahl@gmail.com>
Mark Levedahl committed
Jun 6, 2025 at 11:34 UTC
fdaba070bcbadd902610c09707802d0a1e2d3201
1 file changed
+31
-24
gitk
+31
-24
@@ -11660,53 +11660,43 @@ proc prefspage_colors {notebook} {
11660
grid $page.cdisp - -sticky w -pady 10
11661
label $page.ui -padx 40 -relief sunk -background $uicolor
11662
ttk::button $page.uibut -text [mc "Interface"] \
11663
- -command [list choosecolor uicolor {} $page [mc "interface"] setui]
11663
+ -command [list choosecolor uicolor {} $page [mc "interface"]]
11664
grid x $page.uibut $page.ui -sticky w
11665
label $page.bg -padx 40 -relief sunk -background $bgcolor
11666
ttk::button $page.bgbut -text [mc "Background"] \
11667
- -command [list choosecolor bgcolor {} $page [mc "background"] setbg]
11667
+ -command [list choosecolor bgcolor {} $page [mc "background"]]
11668
grid x $page.bgbut $page.bg -sticky w
11669
label $page.fg -padx 40 -relief sunk -background $fgcolor
11670
ttk::button $page.fgbut -text [mc "Foreground"] \
11671
- -command [list choosecolor fgcolor {} $page [mc "foreground"] setfg]
11671
+ -command [list choosecolor fgcolor {} $page [mc "foreground"]]
11672
grid x $page.fgbut $page.fg -sticky w
11673
label $page.diffold -padx 40 -relief sunk -background [lindex $diffcolors 0]
11674
ttk::button $page.diffoldbut -text [mc "Diff: old lines"] \
11675
- -command [list choosecolor diffcolors 0 $page [mc "diff old lines"] \
11676
- [list $ctext tag conf d0 -foreground]]
11675
+ -command [list choosecolor diffcolors 0 $page [mc "diff old lines"]]
11676
grid x $page.diffoldbut $page.diffold -sticky w
11677
label $page.diffoldbg -padx 40 -relief sunk -background [lindex $diffbgcolors 0]
11678
ttk::button $page.diffoldbgbut -text [mc "Diff: old lines bg"] \
11680
- -command [list choosecolor diffbgcolors 0 $page \
11681
- [mc "diff old lines bg"] \
11682
- [list $ctext tag conf d0 -background]]
11679
+ -command [list choosecolor diffbgcolors 0 $page [mc "diff old lines bg"]]
11680
grid x $page.diffoldbgbut $page.diffoldbg -sticky w
11681
label $page.diffnew -padx 40 -relief sunk -background [lindex $diffcolors 1]
11682
ttk::button $page.diffnewbut -text [mc "Diff: new lines"] \
11686
- -command [list choosecolor diffcolors 1 $page [mc "diff new lines"] \
11687
- [list $ctext tag conf dresult -foreground]]
11683
+ -command [list choosecolor diffcolors 1 $page [mc "diff new lines"]]
11684
grid x $page.diffnewbut $page.diffnew -sticky w
11685
label $page.diffnewbg -padx 40 -relief sunk -background [lindex $diffbgcolors 1]
11686
ttk::button $page.diffnewbgbut -text [mc "Diff: new lines bg"] \
11691
- -command [list choosecolor diffbgcolors 1 $page \
11692
- [mc "diff new lines bg"] \
11693
- [list $ctext tag conf dresult -background]]
11687
+ -command [list choosecolor diffbgcolors 1 $page [mc "diff new lines bg"]]
11688
grid x $page.diffnewbgbut $page.diffnewbg -sticky w
11689
label $page.hunksep -padx 40 -relief sunk -background [lindex $diffcolors 2]
11690
ttk::button $page.hunksepbut -text [mc "Diff: hunk header"] \
11697
- -command [list choosecolor diffcolors 2 $page \
11698
- [mc "diff hunk header"] \
11699
- [list $ctext tag conf hunksep -foreground]]
11691
+ -command [list choosecolor diffcolors 2 $page [mc "diff hunk header"]]
11692
grid x $page.hunksepbut $page.hunksep -sticky w
11693
label $page.markbgsep -padx 40 -relief sunk -background $markbgcolor
11694
ttk::button $page.markbgbut -text [mc "Marked line bg"] \
11703
- -command [list choosecolor markbgcolor {} $page \
11704
- [mc "marked line background"] \
11705
- [list $ctext tag conf omark -background]]
11695
+ -command [list choosecolor markbgcolor {} $page [mc "marked line background"]]
11696
grid x $page.markbgbut $page.markbgsep -sticky w
11697
label $page.selbgsep -padx 40 -relief sunk -background $selectbgcolor
11698
ttk::button $page.selbgbut -text [mc "Select bg"] \
11709
- -command [list choosecolor selectbgcolor {} $page [mc "background"] setselbg]
11699
+ -command [list choosecolor selectbgcolor {} $page [mc "background"]]
11700
grid x $page.selbgbut $page.selbgsep -sticky w
11701
return $page
11702
}
@@ -11794,14 +11784,14 @@ proc choose_extdiff {} {
11784
}
11785
}
11786
11797
-proc choosecolor {v vi prefspage x cmd} {
11787
+proc choosecolor {v vi prefspage x} {
11788
global $v
11789
11790
set c [tk_chooseColor -initialcolor [lindex [set $v] $vi] \
11791
-title [mc "Gitk: choose color for %s" $x]]
11792
if {$c eq {}} return
11793
lset $v $vi $c
11804
- eval $cmd $c
11794
+ set_gui_colors
11795
prefspage_set_colorswatches $prefspage
11796
}
11797
@@ -11855,6 +11845,22 @@ proc setfg {c} {
11845
$canv itemconf markid -outline $c
11846
}
11847
11848
+proc set_gui_colors {} {
11849
+ global uicolor bgcolor fgcolor ctext diffcolors selectbgcolor markbgcolor
11850
+ global diffbgcolors
11851
+
11852
+ setui $uicolor
11853
+ setbg $bgcolor
11854
+ setfg $fgcolor
11855
+ $ctext tag conf d0 -foreground [lindex $diffcolors 0]
11856
+ $ctext tag conf d0 -background [lindex $diffbgcolors 0]
11857
+ $ctext tag conf dresult -foreground [lindex $diffcolors 1]
11858
+ $ctext tag conf dresult -background [lindex $diffbgcolors 1]
11859
+ $ctext tag conf hunksep -foreground [lindex $diffcolors 2]
11860
+ $ctext tag conf omark -background $markbgcolor
11861
+ setselbg $selectbgcolor
11862
+}
11863
+
11864
proc prefscan {} {
11865
global oldprefs prefstop
11866
global {*}$::config_variables
@@ -11865,6 +11871,7 @@ proc prefscan {} {
11871
catch {destroy $prefstop}
11872
unset prefstop
11873
fontcan
11874
+ set_gui_colors
11875
}
11876
11877
proc prefsok {} {
@@ -12567,8 +12574,6 @@ eval font create textfontbold [fontflags textfont 1]
12574
parsefont uifont $uifont
12575
eval font create uifont [fontflags uifont]
12576
12570
-setui $uicolor
12571
-
12577
setoptions
12578
12579
# check that we can find a .git directory somewhere...
@@ -12757,6 +12762,8 @@ if {[tk windowingsystem] eq "win32"} {
12762
focus -force .
12763
}
12764
12765
+set_gui_colors
12766
+
12767
getcommits {}
12768
12769
# Local variables: