gitk: use $config_variables as list for save/restore

gitk includes many user defined configuration variables, has all of these are listed in $config_variables. But this list is not used to define the variables to be loaded, saved, or restored when cancelling the configuration dialog, and developers must maintain separate lists of variables for these purposes. This leads to unnecessary errors and merge conflicts. Let's replace those separate lists with $config_variables to make maintenance easier. While we are on topic, sort the list of names in $config_variables. This makes it simpler to scan and has fewer chances of conflicts when new names are introduced. Helped-by: Johannes Sixt <j6t@kdbg.org> Signed-off-by: Mark Levedahl <mlevedahl@gmail.com>

Mark Levedahl committed Jun 3, 2025 at 16:17 UTC 5b8103a0bdd64aa1e093e235966ae76b76b4f81d
1 file changed +66 -30
gitk
+66 -30
@@ -11669,10 +11669,8 @@ proc create_prefs_page {w} {
11669 }
11670
11671 proc prefspage_general {notebook} {
11672 - global NS maxwidth maxgraphpct showneartags showlocalchanges
11673 - global tabstop wrapcomment wrapdefault limitdiffs
11674 - global autocopy autoselect autosellen extdifftool perfile_attrs
11675 - global hideremotes want_ttk have_ttk maxrefs web_browser
11672 + global NS have_ttk
11673 + global {*}$::config_variables
11674
11675 set page [create_prefs_page $notebook.general]
11676
@@ -11833,11 +11831,8 @@ proc prefspage_fonts {notebook} {
11831 }
11832
11833 proc doprefs {} {
11836 - global maxwidth maxgraphpct use_ttk NS
11837 - global oldprefs prefstop showneartags showlocalchanges
11838 - global uicolor bgcolor fgcolor ctext diffcolors selectbgcolor markbgcolor
11839 - global tabstop limitdiffs autoselect autosellen extdifftool perfile_attrs
11840 - global hideremotes want_ttk have_ttk wrapcomment wrapdefault
11834 + global use_ttk NS oldprefs prefstop
11835 + global {*}$::config_variables
11836
11837 set top .gitkprefs
11838 set prefstop $top
@@ -11845,8 +11840,7 @@ proc doprefs {} {
11840 raise $top
11841 return
11842 }
11848 - foreach v {maxwidth maxgraphpct showneartags showlocalchanges \
11849 - limitdiffs tabstop perfile_attrs hideremotes want_ttk wrapcomment wrapdefault} {
11843 + foreach v $::config_variables {
11844 set oldprefs($v) [set $v]
11845 }
11846 ttk_toplevel $top
@@ -11970,10 +11964,9 @@ proc setfg {c} {
11964
11965 proc prefscan {} {
11966 global oldprefs prefstop
11967 + global {*}$::config_variables
11968
11974 - foreach v {maxwidth maxgraphpct showneartags showlocalchanges \
11975 - limitdiffs tabstop perfile_attrs hideremotes want_ttk wrapcomment wrapdefault} {
11976 - global $v
11969 + foreach v $::config_variables {
11970 set $v $oldprefs($v)
11971 }
11972 catch {destroy $prefstop}
@@ -11982,11 +11975,8 @@ proc prefscan {} {
11975 }
11976
11977 proc prefsok {} {
11985 - global maxwidth maxgraphpct
11986 - global oldprefs prefstop showneartags showlocalchanges
11987 - global fontpref mainfont textfont uifont
11988 - global limitdiffs treediffs perfile_attrs
11989 - global hideremotes wrapcomment wrapdefault
11978 + global oldprefs prefstop fontpref treediffs
11979 + global {*}$::config_variables
11980 global ctext
11981
11982 catch {destroy $prefstop}
@@ -12609,19 +12599,65 @@ catch {
12599 config_check_tmp_exists 50
12600
12601 set config_variables {
12612 - mainfont textfont uifont tabstop findmergefiles maxgraphpct maxwidth
12613 - cmitmode wrapcomment wrapdefault autocopy autoselect autosellen
12614 - showneartags maxrefs visiblerefs
12615 - hideremotes showlocalchanges datetimeformat limitdiffs uicolor want_ttk
12616 - bgcolor fgcolor uifgcolor uifgdisabledcolor colors diffcolors mergecolors
12617 - markbgcolor diffcontext selectbgcolor foundbgcolor currentsearchhitbgcolor
12618 - extdifftool perfile_attrs headbgcolor headfgcolor headoutlinecolor
12619 - remotebgcolor tagbgcolor tagfgcolor tagoutlinecolor reflinecolor
12620 - filesepbgcolor filesepfgcolor linehoverbgcolor linehoverfgcolor
12621 - linehoveroutlinecolor mainheadcirclecolor workingfilescirclecolor
12622 - indexcirclecolor circlecolors linkfgcolor circleoutlinecolor diffbgcolors
12602 + autocopy
12603 + autoselect
12604 + autosellen
12605 + bgcolor
12606 + circlecolors
12607 + circleoutlinecolor
12608 + cmitmode
12609 + colors
12610 + currentsearchhitbgcolor
12611 + datetimeformat
12612 + diffbgcolors
12613 + diffcolors
12614 + diffcontext
12615 + extdifftool
12616 + fgcolor
12617 + filesepbgcolor
12618 + filesepfgcolor
12619 + findmergefiles
12620 + foundbgcolor
12621 + headbgcolor
12622 + headfgcolor
12623 + headoutlinecolor
12624 + hideremotes
12625 + indexcirclecolor
12626 + limitdiffs
12627 + linehoverbgcolor
12628 + linehoverfgcolor
12629 + linehoveroutlinecolor
12630 + linkfgcolor
12631 + mainfont
12632 + mainheadcirclecolor
12633 + markbgcolor
12634 + maxgraphpct
12635 + maxrefs
12636 + maxwidth
12637 + mergecolors
12638 + perfile_attrs
12639 + reflinecolor
12640 + remotebgcolor
12641 + selectbgcolor
12642 + showlocalchanges
12643 + showneartags
12644 + tabstop
12645 + tagbgcolor
12646 + tagfgcolor
12647 + tagoutlinecolor
12648 + textfont
12649 + uicolor
12650 + uifgcolor
12651 + uifgdisabledcolor
12652 + uifont
12653 + visiblerefs
12654 + want_ttk
12655 web_browser
12656 + workingfilescirclecolor
12657 + wrapcomment
12658 + wrapdefault
12659 }
12660 +
12661 foreach var $config_variables {
12662 config_init_trace $var
12663 trace add variable $var write config_variable_change_cb