]> git.ipfire.org Git - thirdparty/git.git/commitdiff
gitk: restore ui colors after cancelling config dialog
authorMark Levedahl <mlevedahl@gmail.com>
Fri, 6 Jun 2025 15:34:04 +0000 (11:34 -0400)
committerMark Levedahl <mlevedahl@gmail.com>
Thu, 17 Jul 2025 03:01:51 +0000 (23:01 -0400)
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>
gitk

diff --git a/gitk b/gitk
index f331d9ccd549d83fff8c88d87c8830243f7bb809..b5ddfd1c83f37a7f12029925acaca58ac85a39d7 100755 (executable)
--- a/gitk
+++ b/gitk
@@ -11660,53 +11660,43 @@ proc prefspage_colors {notebook} {
     grid $page.cdisp - -sticky w -pady 10
     label $page.ui -padx 40 -relief sunk -background $uicolor
     ttk::button $page.uibut -text [mc "Interface"] \
-       -command [list choosecolor uicolor {} $page [mc "interface"] setui]
+       -command [list choosecolor uicolor {} $page [mc "interface"]]
     grid x $page.uibut $page.ui -sticky w
     label $page.bg -padx 40 -relief sunk -background $bgcolor
     ttk::button $page.bgbut -text [mc "Background"] \
-        -command [list choosecolor bgcolor {} $page [mc "background"] setbg]
+        -command [list choosecolor bgcolor {} $page [mc "background"]]
     grid x $page.bgbut $page.bg -sticky w
     label $page.fg -padx 40 -relief sunk -background $fgcolor
     ttk::button $page.fgbut -text [mc "Foreground"] \
-        -command [list choosecolor fgcolor {} $page [mc "foreground"] setfg]
+        -command [list choosecolor fgcolor {} $page [mc "foreground"]]
     grid x $page.fgbut $page.fg -sticky w
     label $page.diffold -padx 40 -relief sunk -background [lindex $diffcolors 0]
     ttk::button $page.diffoldbut -text [mc "Diff: old lines"] \
-        -command [list choosecolor diffcolors 0 $page [mc "diff old lines"] \
-                      [list $ctext tag conf d0 -foreground]]
+        -command [list choosecolor diffcolors 0 $page [mc "diff old lines"]]
     grid x $page.diffoldbut $page.diffold -sticky w
     label $page.diffoldbg -padx 40 -relief sunk -background [lindex $diffbgcolors 0]
     ttk::button $page.diffoldbgbut -text [mc "Diff: old lines bg"] \
-        -command [list choosecolor diffbgcolors 0 $page \
-                      [mc "diff old lines bg"] \
-                      [list $ctext tag conf d0 -background]]
+        -command [list choosecolor diffbgcolors 0 $page [mc "diff old lines bg"]]
     grid x $page.diffoldbgbut $page.diffoldbg -sticky w
     label $page.diffnew -padx 40 -relief sunk -background [lindex $diffcolors 1]
     ttk::button $page.diffnewbut -text [mc "Diff: new lines"] \
-        -command [list choosecolor diffcolors 1 $page [mc "diff new lines"] \
-                      [list $ctext tag conf dresult -foreground]]
+        -command [list choosecolor diffcolors 1 $page [mc "diff new lines"]]
     grid x $page.diffnewbut $page.diffnew -sticky w
     label $page.diffnewbg -padx 40 -relief sunk -background [lindex $diffbgcolors 1]
     ttk::button $page.diffnewbgbut -text [mc "Diff: new lines bg"] \
-        -command [list choosecolor diffbgcolors 1 $page \
-                      [mc "diff new lines bg"] \
-                      [list $ctext tag conf dresult -background]]
+        -command [list choosecolor diffbgcolors 1 $page [mc "diff new lines bg"]]
     grid x $page.diffnewbgbut $page.diffnewbg -sticky w
     label $page.hunksep -padx 40 -relief sunk -background [lindex $diffcolors 2]
     ttk::button $page.hunksepbut -text [mc "Diff: hunk header"] \
-        -command [list choosecolor diffcolors 2 $page \
-                      [mc "diff hunk header"] \
-                      [list $ctext tag conf hunksep -foreground]]
+        -command [list choosecolor diffcolors 2 $page [mc "diff hunk header"]]
     grid x $page.hunksepbut $page.hunksep -sticky w
     label $page.markbgsep -padx 40 -relief sunk -background $markbgcolor
     ttk::button $page.markbgbut -text [mc "Marked line bg"] \
-        -command [list choosecolor markbgcolor {} $page \
-                      [mc "marked line background"] \
-                      [list $ctext tag conf omark -background]]
+        -command [list choosecolor markbgcolor {} $page [mc "marked line background"]]
     grid x $page.markbgbut $page.markbgsep -sticky w
     label $page.selbgsep -padx 40 -relief sunk -background $selectbgcolor
     ttk::button $page.selbgbut -text [mc "Select bg"] \
-        -command [list choosecolor selectbgcolor {} $page [mc "background"] setselbg]
+        -command [list choosecolor selectbgcolor {} $page [mc "background"]]
     grid x $page.selbgbut $page.selbgsep -sticky w
     return $page
 }
@@ -11794,14 +11784,14 @@ proc choose_extdiff {} {
     }
 }
 
-proc choosecolor {v vi prefspage x cmd} {
+proc choosecolor {v vi prefspage x} {
     global $v
 
     set c [tk_chooseColor -initialcolor [lindex [set $v] $vi] \
                -title [mc "Gitk: choose color for %s" $x]]
     if {$c eq {}} return
     lset $v $vi $c
-    eval $cmd $c
+    set_gui_colors
     prefspage_set_colorswatches $prefspage
 }
 
@@ -11855,6 +11845,22 @@ proc setfg {c} {
     $canv itemconf markid -outline $c
 }
 
+proc set_gui_colors {} {
+    global uicolor bgcolor fgcolor ctext diffcolors selectbgcolor markbgcolor
+    global diffbgcolors
+
+    setui $uicolor
+    setbg $bgcolor
+    setfg $fgcolor
+    $ctext tag conf d0 -foreground [lindex $diffcolors   0]
+    $ctext tag conf d0 -background [lindex $diffbgcolors 0]
+    $ctext tag conf dresult -foreground [lindex $diffcolors   1]
+    $ctext tag conf dresult -background [lindex $diffbgcolors 1]
+    $ctext tag conf hunksep -foreground [lindex $diffcolors   2]
+    $ctext tag conf omark -background $markbgcolor
+    setselbg $selectbgcolor
+}
+
 proc prefscan {} {
     global oldprefs prefstop
     global {*}$::config_variables
@@ -11865,6 +11871,7 @@ proc prefscan {} {
     catch {destroy $prefstop}
     unset prefstop
     fontcan
+    set_gui_colors
 }
 
 proc prefsok {} {
@@ -12567,8 +12574,6 @@ eval font create textfontbold [fontflags textfont 1]
 parsefont uifont $uifont
 eval font create uifont [fontflags uifont]
 
-setui $uicolor
-
 setoptions
 
 # check that we can find a .git directory somewhere...
@@ -12757,6 +12762,8 @@ if {[tk windowingsystem] eq "win32"} {
     focus -force .
 }
 
+set_gui_colors
+
 getcommits {}
 
 # Local variables: