From e7e62f428b3f460f0849dd6095643a7769248f29 Mon Sep 17 00:00:00 2001 From: Johannes Sixt Date: Mon, 3 Aug 2026 11:48:51 +0200 Subject: [PATCH 1/6] gitk: set intitial colors of swatches using the available helper After the user has selected a color in the Preferences dialog, the helper proc prefspage_set_colorswatches is used to update the colors shown in the Preferences dialog. Use this proc also to show the initial colors after the Preferences dialog is constructed. This keeps the procedure that gives the UI elements their colors in a single place. Signed-off-by: Johannes Sixt --- gitk-git/gitk | 25 ++++++++++++------------- 1 file changed, 12 insertions(+), 13 deletions(-) diff --git a/gitk-git/gitk b/gitk-git/gitk index 0f3571050bef1c..f5eb963b864dec 100755 --- a/gitk-git/gitk +++ b/gitk-git/gitk @@ -11801,8 +11801,6 @@ proc prefspage_general {notebook} { } proc prefspage_colors {notebook} { - global bgcolor fgcolor ctext diffcolors selectbgcolor markbgcolor - global diffbgcolors linkfgcolor global themeloader set page [create_prefs_page $notebook.colors] @@ -11834,63 +11832,64 @@ proc prefspage_colors {notebook} { ttk::label $page.cdisp -text [mc "Colors: press to choose"] -font mainfontbold grid $page.cdisp - -sticky w -pady 10 - label $page.bg -padx 40 -relief sunk -background $bgcolor + label $page.bg -padx 40 -relief sunk ttk::button $page.bgbut -text [mc "Background"] \ -command [list choosecolor bgcolor {} $page [mc "background"]] grid x $page.bgbut $page.bg -sticky w - label $page.fg -padx 40 -relief sunk -background $fgcolor + label $page.fg -padx 40 -relief sunk ttk::button $page.fgbut -text [mc "Foreground"] \ -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] + label $page.diffold -padx 40 -relief sunk ttk::button $page.diffoldbut -text [mc "Diff: old lines"] \ -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] + label $page.diffoldbg -padx 40 -relief sunk ttk::button $page.diffoldbgbut -text [mc "Diff: old lines bg"] \ -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] + label $page.diffnew -padx 40 -relief sunk ttk::button $page.diffnewbut -text [mc "Diff: new lines"] \ -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] + label $page.diffnewbg -padx 40 -relief sunk ttk::button $page.diffnewbgbut -text [mc "Diff: new lines bg"] \ -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] + label $page.hunksep -padx 40 -relief sunk ttk::button $page.hunksepbut -text [mc "Diff: hunk header"] \ -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 + label $page.markbgsep -padx 40 -relief sunk ttk::button $page.markbgbut -text [mc "Marked line bg"] \ -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 + label $page.selbgsep -padx 40 -relief sunk ttk::button $page.selbgbut -text [mc "Select bg"] \ -command [list choosecolor selectbgcolor {} $page [mc "background"]] grid x $page.selbgbut $page.selbgsep -sticky w - label $page.linkfg -padx 40 -relief sunk -background $linkfgcolor + label $page.linkfg -padx 40 -relief sunk ttk::button $page.linkfgbut -text [mc "Link"] \ -command [list choosecolor linkfgcolor {} $page [mc "link"]] grid x $page.linkfgbut $page.linkfg -sticky w grid columnconfigure $page 2 -weight 1 + prefspage_set_colorswatches $page return $page } proc prefspage_set_colorswatches {page} { - global bgcolor fgcolor ctext diffcolors selectbgcolor markbgcolor + global bgcolor fgcolor diffcolors selectbgcolor markbgcolor global diffbgcolors linkfgcolor $page.bg configure -background $bgcolor From 52dacc4924163812f8c68399ba7b56b6352e815a Mon Sep 17 00:00:00 2001 From: Johannes Sixt Date: Mon, 3 Aug 2026 12:58:26 +0200 Subject: [PATCH 2/6] gitk: condense repetitive code around color buttons into foreach loops The color selection elements in the Preferences dialog are set up in a very uniform manner. The code doing that has grown in the past by simply modifying a copy of a paragraph. Extract the varying parts into a list and then operate the repeating parts in a foreach loop. This helps a later change where we want to set up the UI elements in a different way. Change the UI names "markbgsep" and "selbgsep" to drop the "sep", which has obviously been left over by accident when "hunksep" was copied. Change the suffix "but" to "btn", which resonates a bit better when reading the code. Signed-off-by: Johannes Sixt --- gitk-git/gitk | 114 ++++++++++++++++++++++++-------------------------- 1 file changed, 55 insertions(+), 59 deletions(-) diff --git a/gitk-git/gitk b/gitk-git/gitk index f5eb963b864dec..137940defb1d94 100755 --- a/gitk-git/gitk +++ b/gitk-git/gitk @@ -11832,55 +11832,46 @@ proc prefspage_colors {notebook} { ttk::label $page.cdisp -text [mc "Colors: press to choose"] -font mainfontbold grid $page.cdisp - -sticky w -pady 10 - label $page.bg -padx 40 -relief sunk - ttk::button $page.bgbut -text [mc "Background"] \ - -command [list choosecolor bgcolor {} $page [mc "background"]] - grid x $page.bgbut $page.bg -sticky w - - label $page.fg -padx 40 -relief sunk - ttk::button $page.fgbut -text [mc "Foreground"] \ - -command [list choosecolor fgcolor {} $page [mc "foreground"]] - grid x $page.fgbut $page.fg -sticky w - - label $page.diffold -padx 40 -relief sunk - ttk::button $page.diffoldbut -text [mc "Diff: old lines"] \ - -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 - ttk::button $page.diffoldbgbut -text [mc "Diff: old lines bg"] \ - -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 - ttk::button $page.diffnewbut -text [mc "Diff: new lines"] \ - -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 - ttk::button $page.diffnewbgbut -text [mc "Diff: new lines bg"] \ - -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 - ttk::button $page.hunksepbut -text [mc "Diff: hunk header"] \ - -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 - ttk::button $page.markbgbut -text [mc "Marked line bg"] \ - -command [list choosecolor markbgcolor {} $page [mc "marked line background"]] - grid x $page.markbgbut $page.markbgsep -sticky w - - label $page.selbgsep -padx 40 -relief sunk - ttk::button $page.selbgbut -text [mc "Select bg"] \ - -command [list choosecolor selectbgcolor {} $page [mc "background"]] - grid x $page.selbgbut $page.selbgsep -sticky w - - label $page.linkfg -padx 40 -relief sunk - ttk::button $page.linkfgbut -text [mc "Link"] \ - -command [list choosecolor linkfgcolor {} $page [mc "link"]] - grid x $page.linkfgbut $page.linkfg -sticky w + + set coloruielems [list \ + bg bgcolor {} \ + [mc "Background"] \ + [mc "background"] \ + fg fgcolor {} \ + [mc "Foreground"] \ + [mc "foreground"] \ + diffold diffcolors 0 \ + [mc "Diff: old lines"] \ + [mc "diff old lines"] \ + diffoldbg diffbgcolors 0 \ + [mc "Diff: old lines bg"] \ + [mc "diff old lines bg"] \ + diffnew diffcolors 1 \ + [mc "Diff: new lines"] \ + [mc "diff new lines"] \ + diffnewbg diffbgcolors 1 \ + [mc "Diff: new lines bg"] \ + [mc "diff new lines bg"] \ + hunksep diffcolors 2 \ + [mc "Diff: hunk header"] \ + [mc "diff hunk header"] \ + markbg markbgcolor {} \ + [mc "Marked line bg"] \ + [mc "marked line background"] \ + selbg selectbgcolor {} \ + [mc "Select bg"] \ + [mc "background"] \ + linkfg linkfgcolor {} \ + [mc "Link"] \ + [mc "link"] \ + ] + + foreach {uielem colorvar idx label title} $coloruielems { + label $page.$uielem -padx 40 -relief sunk + ttk::button $page.${uielem}btn -text $label \ + -command [list choosecolor $colorvar $idx $page $title] + grid x $page.${uielem}btn $page.$uielem -sticky w + } grid columnconfigure $page 2 -weight 1 prefspage_set_colorswatches $page @@ -11892,16 +11883,21 @@ proc prefspage_set_colorswatches {page} { global bgcolor fgcolor diffcolors selectbgcolor markbgcolor global diffbgcolors linkfgcolor - $page.bg configure -background $bgcolor - $page.fg configure -background $fgcolor - $page.diffold configure -background [lindex $diffcolors 0] - $page.diffoldbg configure -background [lindex $diffbgcolors 0] - $page.diffnew configure -background [lindex $diffcolors 1] - $page.diffnewbg configure -background [lindex $diffbgcolors 1] - $page.hunksep configure -background [lindex $diffcolors 2] - $page.markbgsep configure -background $markbgcolor - $page.selbgsep configure -background $selectbgcolor - $page.linkfg configure -background $linkfgcolor + set coloruielems [list \ + bg $bgcolor \ + fg $fgcolor \ + diffold [lindex $diffcolors 0] \ + diffoldbg [lindex $diffbgcolors 0] \ + diffnew [lindex $diffcolors 1] \ + diffnewbg [lindex $diffbgcolors 1] \ + hunksep [lindex $diffcolors 2] \ + markbg $markbgcolor \ + selbg $selectbgcolor \ + linkfg $linkfgcolor \ + ] + foreach {uielem color} $coloruielems { + $page.$uielem configure -background $color + } } proc prefspage_fonts {notebook} { From 75202a52d7912e67f6b92662f5349127c26c70b7 Mon Sep 17 00:00:00 2001 From: Johannes Sixt Date: Mon, 3 Aug 2026 22:28:52 +0200 Subject: [PATCH 3/6] gitk: show color preferences on the button instead of the label When the user goes to the color preferences, the eye is automatically drawn to the color samples. However, clicking on the sample with the intent to change it does nothing. Instead, the text label also acts as a button and must be clicked to change the color. Turn the color samples into clickable buttons and the text labels into static text. Use non-themed buttons because their color can be changed by simply specifying the color properties. (Themed buttons would need a lot more elaboration.) Signed-off-by: Johannes Sixt --- gitk-git/gitk | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/gitk-git/gitk b/gitk-git/gitk index 137940defb1d94..afc7c2d39d8f10 100755 --- a/gitk-git/gitk +++ b/gitk-git/gitk @@ -11867,10 +11867,10 @@ proc prefspage_colors {notebook} { ] foreach {uielem colorvar idx label title} $coloruielems { - label $page.$uielem -padx 40 -relief sunk - ttk::button $page.${uielem}btn -text $label \ + ttk::label $page.$uielem -text $label + button $page.${uielem}btn -padx 40 -pady 0 -borderwidth 2 \ -command [list choosecolor $colorvar $idx $page $title] - grid x $page.${uielem}btn $page.$uielem -sticky w + grid x $page.$uielem $page.${uielem}btn -sticky w -pady 1 } grid columnconfigure $page 2 -weight 1 @@ -11896,7 +11896,7 @@ proc prefspage_set_colorswatches {page} { linkfg $linkfgcolor \ ] foreach {uielem color} $coloruielems { - $page.$uielem configure -background $color + $page.${uielem}btn configure -background $color -activebackground $color } } From 45d5b05281cd4f3f43290d128d631a47975225f3 Mon Sep 17 00:00:00 2001 From: Johannes Sixt Date: Mon, 3 Aug 2026 23:37:33 +0200 Subject: [PATCH 4/6] gitk: use more natural language for labels of color preferences The labels used to be clickable buttons. These would have looked funny if they carried long texts. For this reason, jargon and abbreviations were used to keep them short. Since there is no button frame around the labels anymore, the texts can become longer without becoming ugly. Bring them closer to natural language. Remove the prefix "Diff" from labels, because the remaining texts are sufficiently unambiguous that they are about diff text. Signed-off-by: Johannes Sixt --- gitk-git/gitk | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/gitk-git/gitk b/gitk-git/gitk index afc7c2d39d8f10..c0ab55845ba155 100755 --- a/gitk-git/gitk +++ b/gitk-git/gitk @@ -11838,31 +11838,31 @@ proc prefspage_colors {notebook} { [mc "Background"] \ [mc "background"] \ fg fgcolor {} \ - [mc "Foreground"] \ + [mc "Main text"] \ [mc "foreground"] \ diffold diffcolors 0 \ - [mc "Diff: old lines"] \ + [mc "Old line text"] \ [mc "diff old lines"] \ diffoldbg diffbgcolors 0 \ - [mc "Diff: old lines bg"] \ + [mc "Old line background"] \ [mc "diff old lines bg"] \ diffnew diffcolors 1 \ - [mc "Diff: new lines"] \ + [mc "New line text"] \ [mc "diff new lines"] \ diffnewbg diffbgcolors 1 \ - [mc "Diff: new lines bg"] \ + [mc "New line background"] \ [mc "diff new lines bg"] \ hunksep diffcolors 2 \ - [mc "Diff: hunk header"] \ + [mc "Hunk header text"] \ [mc "diff hunk header"] \ markbg markbgcolor {} \ - [mc "Marked line bg"] \ + [mc "Marked line background"] \ [mc "marked line background"] \ selbg selectbgcolor {} \ - [mc "Select bg"] \ + [mc "Selected text background"] \ [mc "background"] \ linkfg linkfgcolor {} \ - [mc "Link"] \ + [mc "Link text"] \ [mc "link"] \ ] From 697159c20e9903dc720d8afdd6535007e61fa095 Mon Sep 17 00:00:00 2001 From: Johannes Sixt Date: Mon, 3 Aug 2026 23:42:36 +0200 Subject: [PATCH 5/6] gitk: avoid constructing dialog titles from text pieces When the user clicks a color preference, a color selection dialog is presented whose title is provided in parts by the caller. The dialog implementation must supply the rest of the title. This is unfriendly for translations. Provide the full title by the caller. Rewrite the texts to be more natural language. Signed-off-by: Johannes Sixt --- gitk-git/gitk | 24 ++++++++++++------------ 1 file changed, 12 insertions(+), 12 deletions(-) diff --git a/gitk-git/gitk b/gitk-git/gitk index c0ab55845ba155..d4c229a3c0b9e5 100755 --- a/gitk-git/gitk +++ b/gitk-git/gitk @@ -11836,34 +11836,34 @@ proc prefspage_colors {notebook} { set coloruielems [list \ bg bgcolor {} \ [mc "Background"] \ - [mc "background"] \ + [mc "choose background color"] \ fg fgcolor {} \ [mc "Main text"] \ - [mc "foreground"] \ + [mc "choose main text color"] \ diffold diffcolors 0 \ [mc "Old line text"] \ - [mc "diff old lines"] \ + [mc "choose text color of old lines"] \ diffoldbg diffbgcolors 0 \ [mc "Old line background"] \ - [mc "diff old lines bg"] \ + [mc "choose background color of old lines"] \ diffnew diffcolors 1 \ [mc "New line text"] \ - [mc "diff new lines"] \ + [mc "choose text color of new lines"] \ diffnewbg diffbgcolors 1 \ [mc "New line background"] \ - [mc "diff new lines bg"] \ + [mc "choose background color of new lines"] \ hunksep diffcolors 2 \ [mc "Hunk header text"] \ - [mc "diff hunk header"] \ + [mc "choose text color of hunk headers"] \ markbg markbgcolor {} \ [mc "Marked line background"] \ - [mc "marked line background"] \ + [mc "choose background color of marked lines"] \ selbg selectbgcolor {} \ [mc "Selected text background"] \ - [mc "background"] \ + [mc "choose background color of selected text"] \ linkfg linkfgcolor {} \ [mc "Link text"] \ - [mc "link"] \ + [mc "choose color of link text"] \ ] foreach {uielem colorvar idx label title} $coloruielems { @@ -12014,11 +12014,11 @@ proc choose_themeloader {prefspage} { } } -proc choosecolor {v vi prefspage x} { +proc choosecolor {v vi prefspage title} { global $v set c [tk_chooseColor -initialcolor [lindex [set $v] $vi] \ - -title [mc "Gitk: choose color for %s" $x]] + -title "Gitk: $title"] if {$c eq {}} return lset $v $vi $c set_gui_colors From 36590e857d3c9a83b17f32b5790df2bd6c1cb588 Mon Sep 17 00:00:00 2001 From: Johannes Sixt Date: Sun, 9 Aug 2026 18:05:50 +0200 Subject: [PATCH 6/6] gitk: move UI for generic colors above diff colors The selection and link colors apply not only to the diff panel, but also to the the commit list. Move these right after the generic background and text color options. The color for marked lines is only used in the diff panel, hence, leave it below the diff color options. Signed-off-by: Johannes Sixt --- gitk-git/gitk | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/gitk-git/gitk b/gitk-git/gitk index d4c229a3c0b9e5..9506739c503b1a 100755 --- a/gitk-git/gitk +++ b/gitk-git/gitk @@ -11840,6 +11840,12 @@ proc prefspage_colors {notebook} { fg fgcolor {} \ [mc "Main text"] \ [mc "choose main text color"] \ + selbg selectbgcolor {} \ + [mc "Selected text background"] \ + [mc "choose background color of selected text"] \ + linkfg linkfgcolor {} \ + [mc "Link text"] \ + [mc "choose color of link text"] \ diffold diffcolors 0 \ [mc "Old line text"] \ [mc "choose text color of old lines"] \ @@ -11858,12 +11864,6 @@ proc prefspage_colors {notebook} { markbg markbgcolor {} \ [mc "Marked line background"] \ [mc "choose background color of marked lines"] \ - selbg selectbgcolor {} \ - [mc "Selected text background"] \ - [mc "choose background color of selected text"] \ - linkfg linkfgcolor {} \ - [mc "Link text"] \ - [mc "choose color of link text"] \ ] foreach {uielem colorvar idx label title} $coloruielems {