Commit

942fe6c4275192d6a64c18b1150aa66481995990

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 <j6t@kdbg.org>

Johannes Sixt <j6t@kdbg.org> · 2026-08-03 09:48 UTC

Browse files
1 file changed, +12 −13
modified gitk
@@ -11801,8 +11801,6 @@ proc prefspage_general {notebook} {
11801 11801 }
11802 11802
11803 11803 proc prefspage_colors {notebook} {
11804 - global bgcolor fgcolor ctext diffcolors selectbgcolor markbgcolor
11805 - global diffbgcolors linkfgcolor
11806 11804 global themeloader
11807 11805
11808 11806 set page [create_prefs_page $notebook.colors]
@@ -11834,63 +11832,64 @@ proc prefspage_colors {notebook} {
11834 11832
11835 11833 ttk::label $page.cdisp -text [mc "Colors: press to choose"] -font mainfontbold
11836 11834 grid $page.cdisp - -sticky w -pady 10
11837 - label $page.bg -padx 40 -relief sunk -background $bgcolor
11835 + label $page.bg -padx 40 -relief sunk
11838 11836 ttk::button $page.bgbut -text [mc "Background"] \
11839 11837 -command [list choosecolor bgcolor {} $page [mc "background"]]
11840 11838 grid x $page.bgbut $page.bg -sticky w
11841 11839
11842 - label $page.fg -padx 40 -relief sunk -background $fgcolor
11840 + label $page.fg -padx 40 -relief sunk
11843 11841 ttk::button $page.fgbut -text [mc "Foreground"] \
11844 11842 -command [list choosecolor fgcolor {} $page [mc "foreground"]]
11845 11843 grid x $page.fgbut $page.fg -sticky w
11846 11844
11847 - label $page.diffold -padx 40 -relief sunk -background [lindex $diffcolors 0]
11845 + label $page.diffold -padx 40 -relief sunk
11848 11846 ttk::button $page.diffoldbut -text [mc "Diff: old lines"] \
11849 11847 -command [list choosecolor diffcolors 0 $page [mc "diff old lines"]]
11850 11848 grid x $page.diffoldbut $page.diffold -sticky w
11851 11849
11852 - label $page.diffoldbg -padx 40 -relief sunk -background [lindex $diffbgcolors 0]
11850 + label $page.diffoldbg -padx 40 -relief sunk
11853 11851 ttk::button $page.diffoldbgbut -text [mc "Diff: old lines bg"] \
11854 11852 -command [list choosecolor diffbgcolors 0 $page [mc "diff old lines bg"]]
11855 11853 grid x $page.diffoldbgbut $page.diffoldbg -sticky w
11856 11854
11857 - label $page.diffnew -padx 40 -relief sunk -background [lindex $diffcolors 1]
11855 + label $page.diffnew -padx 40 -relief sunk
11858 11856 ttk::button $page.diffnewbut -text [mc "Diff: new lines"] \
11859 11857 -command [list choosecolor diffcolors 1 $page [mc "diff new lines"]]
11860 11858 grid x $page.diffnewbut $page.diffnew -sticky w
11861 11859
11862 - label $page.diffnewbg -padx 40 -relief sunk -background [lindex $diffbgcolors 1]
11860 + label $page.diffnewbg -padx 40 -relief sunk
11863 11861 ttk::button $page.diffnewbgbut -text [mc "Diff: new lines bg"] \
11864 11862 -command [list choosecolor diffbgcolors 1 $page [mc "diff new lines bg"]]
11865 11863 grid x $page.diffnewbgbut $page.diffnewbg -sticky w
11866 11864
11867 - label $page.hunksep -padx 40 -relief sunk -background [lindex $diffcolors 2]
11865 + label $page.hunksep -padx 40 -relief sunk
11868 11866 ttk::button $page.hunksepbut -text [mc "Diff: hunk header"] \
11869 11867 -command [list choosecolor diffcolors 2 $page [mc "diff hunk header"]]
11870 11868 grid x $page.hunksepbut $page.hunksep -sticky w
11871 11869
11872 - label $page.markbgsep -padx 40 -relief sunk -background $markbgcolor
11870 + label $page.markbgsep -padx 40 -relief sunk
11873 11871 ttk::button $page.markbgbut -text [mc "Marked line bg"] \
11874 11872 -command [list choosecolor markbgcolor {} $page [mc "marked line background"]]
11875 11873 grid x $page.markbgbut $page.markbgsep -sticky w
11876 11874
11877 - label $page.selbgsep -padx 40 -relief sunk -background $selectbgcolor
11875 + label $page.selbgsep -padx 40 -relief sunk
11878 11876 ttk::button $page.selbgbut -text [mc "Select bg"] \
11879 11877 -command [list choosecolor selectbgcolor {} $page [mc "background"]]
11880 11878 grid x $page.selbgbut $page.selbgsep -sticky w
11881 11879
11882 - label $page.linkfg -padx 40 -relief sunk -background $linkfgcolor
11880 + label $page.linkfg -padx 40 -relief sunk
11883 11881 ttk::button $page.linkfgbut -text [mc "Link"] \
11884 11882 -command [list choosecolor linkfgcolor {} $page [mc "link"]]
11885 11883 grid x $page.linkfgbut $page.linkfg -sticky w
11886 11884
11887 11885 grid columnconfigure $page 2 -weight 1
11886 + prefspage_set_colorswatches $page
11888 11887
11889 11888 return $page
11890 11889 }
11891 11890
11892 11891 proc prefspage_set_colorswatches {page} {
11893 - global bgcolor fgcolor ctext diffcolors selectbgcolor markbgcolor
11892 + global bgcolor fgcolor diffcolors selectbgcolor markbgcolor
11894 11893 global diffbgcolors linkfgcolor
11895 11894
11896 11895 $page.bg configure -background $bgcolor