From 66496dabd4fe26e8b2093ab923c7dea30e0fe7e4 Mon Sep 17 00:00:00 2001 From: "Avi Halachmi (:avih)" Date: Wed, 11 Dec 2024 10:07:54 +0200 Subject: [PATCH 1/4] gitk: UI text: change "SHA1 ID" to "Commit ID" SHA1 might not stay forever, and plans to use SHA256 already exist, so use the official name for it - "Commit ID". Only visible UI texts are modified to reduce the noise when using git-blame, while comments and variable names still contain SHA1/sha1. Signed-off-by: Avi Halachmi (:avih) --- gitk | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/gitk b/gitk index de278557b3..7d1da05256 100755 --- a/gitk +++ b/gitk @@ -2223,7 +2223,7 @@ proc makewindow {} { set sha1entry .tf.bar.sha1 set entries $sha1entry set sha1but .tf.bar.sha1label - button $sha1but -text "[mc "SHA1 ID:"] " -state disabled -relief flat \ + button $sha1but -text "[mc "Commit ID:"] " -state disabled -relief flat \ -command gotocommit -width 8 $sha1but conf -disabledforeground [$sha1but cget -foreground] pack .tf.bar.sha1label -side left @@ -8756,7 +8756,7 @@ proc sha1change {n1 n2 op} { if {$state == "normal"} { $sha1but conf -state normal -relief raised -text "[mc "Goto:"] " } else { - $sha1but conf -state disabled -relief flat -text "[mc "SHA1 ID:"] " + $sha1but conf -state disabled -relief flat -text "[mc "Commit ID:"] " } } @@ -8775,7 +8775,7 @@ proc gotocommit {} { set matches [longid $id] if {$matches ne {}} { if {[llength $matches] > 1} { - error_popup [mc "Short SHA1 id %s is ambiguous" $id] + error_popup [mc "Short commit ID %s is ambiguous" $id] return } set id [lindex $matches 0] @@ -8792,7 +8792,7 @@ proc gotocommit {} { return } if {[regexp {^[0-9a-fA-F]{4,}$} $sha1string]} { - set msg [mc "SHA1 id %s is not known" $sha1string] + set msg [mc "Commit ID %s is not known" $sha1string] } else { set msg [mc "Revision %s is not in the current view" $sha1string] } @@ -11594,7 +11594,7 @@ proc prefspage_general {notebook} { ${NS}::checkbutton $page.showlocal -text [mc "Show local changes"] \ -variable showlocalchanges grid x $page.showlocal -sticky w - ${NS}::checkbutton $page.autoselect -text [mc "Auto-select SHA1 (length)"] \ + ${NS}::checkbutton $page.autoselect -text [mc "Auto-select commit ID (length)"] \ -variable autoselect spinbox $page.autosellen -from 1 -to 40 -width 4 -textvariable autosellen grid x $page.autoselect $page.autosellen -sticky w From 92d911a531e905ec730fa527d55d1622e948d83a Mon Sep 17 00:00:00 2001 From: "Avi Halachmi (:avih)" Date: Wed, 11 Dec 2024 10:18:31 +0200 Subject: [PATCH 2/4] gitk: prefs dialog: refine Auto-select UI Tl;DR: change Auto-select text, move the length input to a new line. The Auto-select preference auto-selects [part of] the commit ID text at the respective widget on startup, and when the current commit at the graph changes. Its real premise, however, is to populate the selection clipboard with the commit ID. Consider, for instance, how meaningless it is on platforms without a selection clipboard - like Windows or macOS (on Windows the selection is not even visible with the default Tk theme, because it's only visible in focused widgets - which the commit ID widget is not during normal application of this selection). So rename the Auto-select label to "Copy commit ID to X11 selection", to reflect better the ultimate outcome of its application Note that there exists other, non-X11 platforms with a selection clipboard, like Wayland, and if a native Tk client exists on such platforms, then the description will not be accurate, but hopefully it's not too misleading either. Additionally, move the length input widget to a new line, because: - This length applies to both Auto-select and "Copy commit reference" context menu item, so it's not exclusive to the selection length. - The next commit will add support for primary clipboard as well, where this length will also be used. Also, move the "Hide remotes" item above these selection prefs, to keep the selection prefs semi-grouped before the spacing of the following title "Diff display options". Signed-off-by: Avi Halachmi (:avih) --- gitk | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/gitk b/gitk index 7d1da05256..322236d361 100755 --- a/gitk +++ b/gitk @@ -11594,14 +11594,17 @@ proc prefspage_general {notebook} { ${NS}::checkbutton $page.showlocal -text [mc "Show local changes"] \ -variable showlocalchanges grid x $page.showlocal -sticky w - ${NS}::checkbutton $page.autoselect -text [mc "Auto-select commit ID (length)"] \ - -variable autoselect - spinbox $page.autosellen -from 1 -to 40 -width 4 -textvariable autosellen - grid x $page.autoselect $page.autosellen -sticky w ${NS}::checkbutton $page.hideremotes -text [mc "Hide remote refs"] \ -variable hideremotes grid x $page.hideremotes -sticky w + ${NS}::checkbutton $page.autoselect -text [mc "Copy commit ID to X11 selection"] \ + -variable autoselect + grid x $page.autoselect -sticky w + spinbox $page.autosellen -from 1 -to 40 -width 4 -textvariable autosellen + ${NS}::label $page.autosellenl -text [mc "Length of commit ID to copy"] + grid x $page.autosellenl $page.autosellen -sticky w + ${NS}::label $page.ddisp -text [mc "Diff display options"] grid $page.ddisp - -sticky w -pady 10 ${NS}::label $page.tabstopl -text [mc "Tab spacing"] From d77c3e35bbca78a0cee6f0eacecccd9aac957c8b Mon Sep 17 00:00:00 2001 From: "Avi Halachmi (:avih)" Date: Wed, 11 Dec 2024 11:22:03 +0200 Subject: [PATCH 3/4] gitk: support auto-copy comit ID to primary clipboard Auto-select ("Copy commit ID to X11 selection") is useful when a selection cliboard exists, but otherwise generally meaningless, for instance on Windows. Add a similar pref and behavior which copies the commit ID to the primary clipboard - for platforms without a selection clipboard, but which can also be useful additionally on platforms with selection. Note that while autoselect is enabled by default, autocopy isn't. That's because the selection clipboard is typically dispensable, while the primary clipboard can be considered a more precious resource, which we don't want to (clear and) overwrite by default. Signed-off-by: Avi Halachmi (:avih) --- gitk | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) diff --git a/gitk b/gitk index 322236d361..38baf20b95 100755 --- a/gitk +++ b/gitk @@ -7344,7 +7344,7 @@ proc selectline {l isnew {desired_loc {}} {switch_to_patch 0}} { global mergemax numcommits pending_select global cmitmode showneartags allcommits global targetrow targetid lastscrollrows - global autoselect autosellen jump_to_here + global autocopy autoselect autosellen jump_to_here global vinlinediff unset -nocomplain pending_select @@ -7413,6 +7413,10 @@ proc selectline {l isnew {desired_loc {}} {switch_to_patch 0}} { if {$autoselect} { $sha1entry selection range 0 $autosellen } + if {$autocopy} { + clipboard clear + clipboard append [string range $id 0 [expr $autosellen - 1]] + } rhighlight_sel $id $ctext conf -state normal @@ -11576,7 +11580,7 @@ proc create_prefs_page {w} { proc prefspage_general {notebook} { global NS maxwidth maxgraphpct showneartags showlocalchanges - global tabstop limitdiffs autoselect autosellen extdifftool perfile_attrs + global tabstop limitdiffs autocopy autoselect autosellen extdifftool perfile_attrs global hideremotes want_ttk have_ttk maxrefs web_browser set page [create_prefs_page $notebook.general] @@ -11598,6 +11602,9 @@ proc prefspage_general {notebook} { -variable hideremotes grid x $page.hideremotes -sticky w + ${NS}::checkbutton $page.autocopy -text [mc "Copy commit ID to clipboard"] \ + -variable autocopy + grid x $page.autocopy -sticky w ${NS}::checkbutton $page.autoselect -text [mc "Copy commit ID to X11 selection"] \ -variable autoselect grid x $page.autoselect -sticky w @@ -12403,6 +12410,7 @@ set maxlinelen 200 set showlocalchanges 1 set limitdiffs 1 set datetimeformat "%Y-%m-%d %H:%M:%S" +set autocopy 0 set autoselect 1 set autosellen 40 set perfile_attrs 0 @@ -12500,7 +12508,7 @@ config_check_tmp_exists 50 set config_variables { mainfont textfont uifont tabstop findmergefiles maxgraphpct maxwidth - cmitmode wrapcomment autoselect autosellen showneartags maxrefs visiblerefs + cmitmode wrapcomment autocopy autoselect autosellen showneartags maxrefs visiblerefs hideremotes showlocalchanges datetimeformat limitdiffs uicolor want_ttk bgcolor fgcolor uifgcolor uifgdisabledcolor colors diffcolors mergecolors markbgcolor diffcontext selectbgcolor foundbgcolor currentsearchhitbgcolor From 36625a6974156fbc56bbb97c983b09ae303a06ff Mon Sep 17 00:00:00 2001 From: Johannes Sixt Date: Sat, 14 Dec 2024 15:53:35 +0100 Subject: [PATCH 4/4] gitk: offer "Copy commit ID to X11 selection" only on X11 This option is only useful where a selection clipboard is available, which is only the case on X11. Do not clutter the UI in other environments. Signed-off-by: Johannes Sixt --- gitk | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/gitk b/gitk index 38baf20b95..12c0dc401e 100755 --- a/gitk +++ b/gitk @@ -1969,6 +1969,10 @@ proc confirm_popup {msg {owner .}} { return $confirm_ok } +proc haveselectionclipboard {} { + return [expr {[tk windowingsystem] eq "x11"}] +} + proc setoptions {} { global use_ttk @@ -7410,7 +7414,7 @@ proc selectline {l isnew {desired_loc {}} {switch_to_patch 0}} { $sha1entry delete 0 end $sha1entry insert 0 $id - if {$autoselect} { + if {$autoselect && [haveselectionclipboard]} { $sha1entry selection range 0 $autosellen } if {$autocopy} { @@ -11605,9 +11609,11 @@ proc prefspage_general {notebook} { ${NS}::checkbutton $page.autocopy -text [mc "Copy commit ID to clipboard"] \ -variable autocopy grid x $page.autocopy -sticky w - ${NS}::checkbutton $page.autoselect -text [mc "Copy commit ID to X11 selection"] \ - -variable autoselect - grid x $page.autoselect -sticky w + if {[haveselectionclipboard]} { + ${NS}::checkbutton $page.autoselect -text [mc "Copy commit ID to X11 selection"] \ + -variable autoselect + grid x $page.autoselect -sticky w + } spinbox $page.autosellen -from 1 -to 40 -width 4 -textvariable autosellen ${NS}::label $page.autosellenl -text [mc "Length of commit ID to copy"] grid x $page.autosellenl $page.autosellen -sticky w