Re: [PATCH 2/5] gitk: condense repetitive code around color buttons into foreach loops
mark <[email protected]>
| Newsgroups | org.kernel.vger.git |
|---|---|
| Message-ID | <[email protected]> |
On 8/6/26 2:40 AM, Johannes Sixt via GitGitGadget wrote: > From: Johannes Sixt <[email protected]> > > 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 <[email protected]> > --- > gitk-git/gitk | 114 ++++++++++++++++++++++++-------------------------- > 1 file changed, 55 insertions(+), 59 deletions(-) > > diff --git a/gitk-git/gitk b/gitk-git/gitk > index f5eb963b86..137940defb 100755 > --- a/gitk-git/gitk > +++ b/gitk-git/gitk > @@ -11832,55 +11832,46 @@ proc prefspage_colors {notebook} { > - > - 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"] \ The list is computed and used each time a dialog box is started from all static elements, no real change. But this cleanly separates the per item data from the boiler plate, definitely more readable. Good.