[v3] git-gui: add hotkey to toggle "Amend Last Commit"
diff mbox series

Message ID 20190912184100.8212-1-birger.sp@gmail.com
State New
Headers show
Series
  • [v3] git-gui: add hotkey to toggle "Amend Last Commit"
Related show

Commit Message

Birger Skogeng Pedersen Sept. 12, 2019, 6:41 p.m. UTC
Selecting whether to do a "New Commit" or "Amend Last Commit" does not have
a hotkey.

With this patch, the user may toggle between the two options with
CTRL/CMD+e.

Signed-off-by: Birger Skogeng Pedersen <birger.sp@gmail.com>
Signed-off-by: Bert Wesarg <bert.wesarg@googlemail.com>
---
 git-gui.sh | 41 ++++++++++++++++++++++++++++++++++++-----
 1 file changed, 36 insertions(+), 5 deletions(-)

Comments

Pratyush Yadav Sept. 13, 2019, 2:37 p.m. UTC | #1
Hi Birger,

I'm afraid you are working on an older version of this patch. You should 
be re-rolling [0], which works well with Bert's "amend check button" 
change.

[0] https://public-inbox.org/git/b82a00441ff1a6a9cea3fd235c1c33729ec31b71.1567713659.git.bert.wesarg@googlemail.com/

On 12/09/19 08:41PM, Birger Skogeng Pedersen wrote:
> Selecting whether to do a "New Commit" or "Amend Last Commit" does not have
> a hotkey.
> 
> With this patch, the user may toggle between the two options with
> CTRL/CMD+e.
> 
> Signed-off-by: Birger Skogeng Pedersen <birger.sp@gmail.com>
> Signed-off-by: Bert Wesarg <bert.wesarg@googlemail.com>
> ---
>  git-gui.sh | 41 ++++++++++++++++++++++++++++++++++++-----
>  1 file changed, 36 insertions(+), 5 deletions(-)
> 
> diff --git a/git-gui.sh b/git-gui.sh
> index 5bc21b8..ebe267f 100755
> --- a/git-gui.sh
> +++ b/git-gui.sh
> @@ -1445,7 +1445,7 @@ proc force_amend {} {
>  	set commit_type $newType
>  
>  	set selected_commit_type amend
> -	do_select_commit_type
> +	ui_select_commit_type
>  }
>  
>  proc rescan {after {honor_trustmtime 1}} {
> @@ -2640,6 +2640,16 @@ proc show_less_context {} {
>  	}
>  }
>  
> +proc toggle_commit_type {} {
> +	global selected_commit_type
> +	if {[string match amend* $selected_commit_type]} {
> +		set selected_commit_type new
> +	} else {
> +		set selected_commit_type amend
> +	}
> +	ui_select_commit_type
> +}
> +
>  ######################################################################
>  ##
>  ## ui construction
> @@ -2824,13 +2834,31 @@ proc commit_btn_caption {} {
>  	}
>  }
>  
> +proc ui_select_commit_type {} {
> +	global selected_commit_type
> +	global ui_commit_type_commit ui_commit_type_amend
> +
> +	do_select_commit_type
> +	if {$selected_commit_type eq {new}} {
> +		.mbar.commit entryconf [mc "New Commit"] \
> +			-accelerator {}
> +		.mbar.commit entryconf [mc "Amend Last Commit"] \
> +			-accelerator $::M1T-E
> +	} elseif {$selected_commit_type eq {amend}} {
> +		.mbar.commit entryconf [mc "New Commit"] \
> +			-accelerator $::M1T-E
> +		.mbar.commit entryconf [mc "Amend Last Commit"] \
> +			-accelerator {}
> +	}
> +}
> +
>  if {[is_enabled multicommit] || [is_enabled singlecommit]} {
>  	menu .mbar.commit
>  
>  	if {![is_enabled nocommit]} {
>  		.mbar.commit add radiobutton \
>  			-label [mc "New Commit"] \
> -			-command do_select_commit_type \
> +			-command ui_select_commit_type \
>  			-variable selected_commit_type \
>  			-value new
>  		lappend disable_on_lock \
> @@ -2838,7 +2866,8 @@ if {[is_enabled multicommit] || [is_enabled singlecommit]} {
>  
>  		.mbar.commit add radiobutton \
>  			-label [mc "Amend Last Commit"] \
> -			-command do_select_commit_type \
> +			-accelerator $M1T-E \
> +			-command ui_select_commit_type \
>  			-variable selected_commit_type \
>  			-value amend
>  		lappend disable_on_lock \
> @@ -3315,14 +3344,14 @@ set ui_coml .vpane.lower.commarea.buffer.header.l
>  if {![is_enabled nocommit]} {
>  	${NS}::radiobutton .vpane.lower.commarea.buffer.header.new \
>  		-text [mc "New Commit"] \
> -		-command do_select_commit_type \
> +		-command ui_select_commit_type \
>  		-variable selected_commit_type \
>  		-value new
>  	lappend disable_on_lock \
>  		[list .vpane.lower.commarea.buffer.header.new conf -state]
>  	${NS}::radiobutton .vpane.lower.commarea.buffer.header.amend \
>  		-text [mc "Amend Last Commit"] \
> -		-command do_select_commit_type \
> +		-command ui_select_commit_type \
>  		-variable selected_commit_type \
>  		-value amend
>  	lappend disable_on_lock \
> @@ -3837,6 +3866,8 @@ bind .   <$M1B-Key-j> do_revert_selection
>  bind .   <$M1B-Key-J> do_revert_selection
>  bind .   <$M1B-Key-i> do_add_all
>  bind .   <$M1B-Key-I> do_add_all
> +bind .   <$M1B-Key-e> toggle_commit_type
> +bind .   <$M1B-Key-E> toggle_commit_type
>  bind .   <$M1B-Key-minus> {show_less_context;break}
>  bind .   <$M1B-Key-KP_Subtract> {show_less_context;break}
>  bind .   <$M1B-Key-equal> {show_more_context;break}
> -- 
> 2.21.0.windows.1
>

Patch
diff mbox series

diff --git a/git-gui.sh b/git-gui.sh
index 5bc21b8..ebe267f 100755
--- a/git-gui.sh
+++ b/git-gui.sh
@@ -1445,7 +1445,7 @@  proc force_amend {} {
 	set commit_type $newType
 
 	set selected_commit_type amend
-	do_select_commit_type
+	ui_select_commit_type
 }
 
 proc rescan {after {honor_trustmtime 1}} {
@@ -2640,6 +2640,16 @@  proc show_less_context {} {
 	}
 }
 
+proc toggle_commit_type {} {
+	global selected_commit_type
+	if {[string match amend* $selected_commit_type]} {
+		set selected_commit_type new
+	} else {
+		set selected_commit_type amend
+	}
+	ui_select_commit_type
+}
+
 ######################################################################
 ##
 ## ui construction
@@ -2824,13 +2834,31 @@  proc commit_btn_caption {} {
 	}
 }
 
+proc ui_select_commit_type {} {
+	global selected_commit_type
+	global ui_commit_type_commit ui_commit_type_amend
+
+	do_select_commit_type
+	if {$selected_commit_type eq {new}} {
+		.mbar.commit entryconf [mc "New Commit"] \
+			-accelerator {}
+		.mbar.commit entryconf [mc "Amend Last Commit"] \
+			-accelerator $::M1T-E
+	} elseif {$selected_commit_type eq {amend}} {
+		.mbar.commit entryconf [mc "New Commit"] \
+			-accelerator $::M1T-E
+		.mbar.commit entryconf [mc "Amend Last Commit"] \
+			-accelerator {}
+	}
+}
+
 if {[is_enabled multicommit] || [is_enabled singlecommit]} {
 	menu .mbar.commit
 
 	if {![is_enabled nocommit]} {
 		.mbar.commit add radiobutton \
 			-label [mc "New Commit"] \
-			-command do_select_commit_type \
+			-command ui_select_commit_type \
 			-variable selected_commit_type \
 			-value new
 		lappend disable_on_lock \
@@ -2838,7 +2866,8 @@  if {[is_enabled multicommit] || [is_enabled singlecommit]} {
 
 		.mbar.commit add radiobutton \
 			-label [mc "Amend Last Commit"] \
-			-command do_select_commit_type \
+			-accelerator $M1T-E \
+			-command ui_select_commit_type \
 			-variable selected_commit_type \
 			-value amend
 		lappend disable_on_lock \
@@ -3315,14 +3344,14 @@  set ui_coml .vpane.lower.commarea.buffer.header.l
 if {![is_enabled nocommit]} {
 	${NS}::radiobutton .vpane.lower.commarea.buffer.header.new \
 		-text [mc "New Commit"] \
-		-command do_select_commit_type \
+		-command ui_select_commit_type \
 		-variable selected_commit_type \
 		-value new
 	lappend disable_on_lock \
 		[list .vpane.lower.commarea.buffer.header.new conf -state]
 	${NS}::radiobutton .vpane.lower.commarea.buffer.header.amend \
 		-text [mc "Amend Last Commit"] \
-		-command do_select_commit_type \
+		-command ui_select_commit_type \
 		-variable selected_commit_type \
 		-value amend
 	lappend disable_on_lock \
@@ -3837,6 +3866,8 @@  bind .   <$M1B-Key-j> do_revert_selection
 bind .   <$M1B-Key-J> do_revert_selection
 bind .   <$M1B-Key-i> do_add_all
 bind .   <$M1B-Key-I> do_add_all
+bind .   <$M1B-Key-e> toggle_commit_type
+bind .   <$M1B-Key-E> toggle_commit_type
 bind .   <$M1B-Key-minus> {show_less_context;break}
 bind .   <$M1B-Key-KP_Subtract> {show_less_context;break}
 bind .   <$M1B-Key-equal> {show_more_context;break}