git/list[1] front-page[2] threads[3] people[4] search[5] about
 

Re: [PATCH] Feature: custom guitool commands can now have custom keyboard shortcuts

From
Harish Karumuthil <harish2704@gmail.com>
Date
Oct 8, 2019, 19:31 UTC
Message-ID
<f751705949a7fd23c77cbbf839c081b95b12394b.camel@gmail.com>
In-Reply-To
<nycvar.QRO.7.76.6.1910071159530.46@tvgsbejvaqbjf.bet>
Hi all, there is an update:

I added necessary error catching code so that, script will not crash if the keybinding code is worng. Instead of crashing it will print error message. The final patch will look something like this.

---
 lib/tools.tcl | 24 ++++++++++++++++++++----
 1 file changed, 20 insertions(+), 4 deletions(-)
diff --git a/lib/tools.tcl b/lib/tools.tcl
index 413f1a1700..3135e19131 100644
--- a/lib/tools.tcl
+++ b/lib/tools.tcl
@@ -38,7 +38,7 @@ proc tools_create_item {parent args} {
 }
 
 proc tools_populate_one {fullname} {
-	global tools_menubar tools_menutbl tools_id
+	global tools_menubar tools_menutbl tools_id repo_config
 
 	if {![info exists tools_id]} {
 		set tools_id 0
@@ -61,9 +61,25 @@ proc tools_populate_one {fullname} {
 		}
 	}
 
-	tools_create_item $parent command \
-		-label [lindex $names end] \
-		-command [list tools_exec $fullname]
+	set accel_key_bound 0
+	if {[info exists repo_config(guitool.$fullname.gitgui-shortcut)]} {
+		set accel_key $repo_config(guitool.$fullname.gitgui-shortcut)
+		if { [ catch { bind . <$accel_key> [list tools_exec $fullname] } msg ] } {
+			puts stderr "Failed to bind keyboard shortcut '$accel_key' for custom tool '$fullname'. Error: $msg"
+		} else {
+			tools_create_item $parent command \
+			-label [lindex $names end] \
+			-command [list tools_exec $fullname] \
+			-accelerator $accel_key
+			set accel_key_bound true
+		}
+	}
+
+	if { ! $accel_key_bound } {
+		tools_create_item $parent command \
+			-label [lindex $names end] \
+			-command [list tools_exec $fullname]
+	}
 }
 
 proc tools_exec {fullname} {
---

@Johannes Schindelin: In short, from your previous message I understand point.

1. shortcut codes like "<Control-,>" will only in Windows platform. It may not work in Linux / Mac.
2. We need do translate shortcut codes somehow ( using one-to-one maping ).

If this is correct, do you have any example on how to do one-to-one maping of a list of string on TCL ?
Previous: Johannes SchindelinNext: Johannes Schindelin
Message 23 of 27 in “Feature: custom guitool commands can now have custom keyboard shortcuts”
  1. Feature: custom guitool commands can now have custom keyboard shortcutsHarish K, Mar 29, 2016
  2. David AguilarMar 31, 2016
  3. harish kApr 1, 2016
  4. harish kOct 3, 2019
  5. Pratyush YadavOct 3, 2019
  6. Johannes SchindelinOct 4, 2019
  7. Pratyush YadavOct 4, 2019
  8. Harish KarumuthilOct 5, 2019
  9. Pratyush YadavOct 5, 2019
  10. Johannes SchindelinOct 6, 2019
  11. Pratyush YadavOct 6, 2019
  12. Philip OakleyOct 6, 2019
  13. Johannes SchindelinOct 6, 2019
  14. Pratyush YadavOct 6, 2019
  15. GitGUIGadget, was Re: [PATCH] Feature: custom guitool commands can now have custom keyboard shortcutsJohannes Schindelin, Oct 7, 2019
  16. Birger Skogeng PedersenOct 7, 2019
  17. Alban GruinOct 7, 2019
  18. Making GitGitGadget's list -> PR comment mirroring bidirectional, was Re: [PATCH] Feature: custom guitool commands can now have custom keyboard shortcutsJohannes Schindelin, Nov 19, 2019
  19. Pratyush YadavNov 20, 2019
  20. Philip OakleyOct 6, 2019
  21. Harish KarumuthilOct 7, 2019
  22. Johannes SchindelinOct 7, 2019
  23. Harish KarumuthilOct 8, 2019
  24. Johannes SchindelinOct 9, 2019
  25. Pratyush YadavOct 13, 2019
  26. Harish KarumuthilOct 7, 2019
  27. Pratyush YadavOct 13, 2019

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.