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) <avihpit@yahoo.com>

Avi Halachmi (:avih) committed Dec 11, 2024 at 11:22 UTC d77c3e35bbca78a0cee6f0eacecccd9aac957c8b
1 file changed +11 -3
gitk
+11 -3
@@ -7344,7 +7344,7 @@ proc selectline {l isnew {desired_loc {}} {switch_to_patch 0}} {
7344 global mergemax numcommits pending_select
7345 global cmitmode showneartags allcommits
7346 global targetrow targetid lastscrollrows
7347 - global autoselect autosellen jump_to_here
7347 + global autocopy autoselect autosellen jump_to_here
7348 global vinlinediff
7349
7350 unset -nocomplain pending_select
@@ -7413,6 +7413,10 @@ proc selectline {l isnew {desired_loc {}} {switch_to_patch 0}} {
7413 if {$autoselect} {
7414 $sha1entry selection range 0 $autosellen
7415 }
7416 + if {$autocopy} {
7417 + clipboard clear
7418 + clipboard append [string range $id 0 [expr $autosellen - 1]]
7419 + }
7420 rhighlight_sel $id
7421
7422 $ctext conf -state normal
@@ -11576,7 +11580,7 @@ proc create_prefs_page {w} {
11580
11581 proc prefspage_general {notebook} {
11582 global NS maxwidth maxgraphpct showneartags showlocalchanges
11579 - global tabstop limitdiffs autoselect autosellen extdifftool perfile_attrs
11583 + global tabstop limitdiffs autocopy autoselect autosellen extdifftool perfile_attrs
11584 global hideremotes want_ttk have_ttk maxrefs web_browser
11585
11586 set page [create_prefs_page $notebook.general]
@@ -11598,6 +11602,9 @@ proc prefspage_general {notebook} {
11602 -variable hideremotes
11603 grid x $page.hideremotes -sticky w
11604
11605 + ${NS}::checkbutton $page.autocopy -text [mc "Copy commit ID to clipboard"] \
11606 + -variable autocopy
11607 + grid x $page.autocopy -sticky w
11608 ${NS}::checkbutton $page.autoselect -text [mc "Copy commit ID to X11 selection"] \
11609 -variable autoselect
11610 grid x $page.autoselect -sticky w
@@ -12403,6 +12410,7 @@ set maxlinelen 200
12410 set showlocalchanges 1
12411 set limitdiffs 1
12412 set datetimeformat "%Y-%m-%d %H:%M:%S"
12413 +set autocopy 0
12414 set autoselect 1
12415 set autosellen 40
12416 set perfile_attrs 0
@@ -12500,7 +12508,7 @@ config_check_tmp_exists 50
12508
12509 set config_variables {
12510 mainfont textfont uifont tabstop findmergefiles maxgraphpct maxwidth
12503 - cmitmode wrapcomment autoselect autosellen showneartags maxrefs visiblerefs
12511 + cmitmode wrapcomment autocopy autoselect autosellen showneartags maxrefs visiblerefs
12512 hideremotes showlocalchanges datetimeformat limitdiffs uicolor want_ttk
12513 bgcolor fgcolor uifgcolor uifgdisabledcolor colors diffcolors mergecolors
12514 markbgcolor diffcontext selectbgcolor foundbgcolor currentsearchhitbgcolor