threads / patch / 28731

patchgit-gui: delegate selection from gutter columns to text output

Subject: [PATCH] git-gui: delegate selection from gutter columns to text output

## tl;dr

4 messages between Oct 20, 2011 and Oct 22, 2011. Diffs are folded; open one to read it.

replies: 3people: 2as markdown or json

Bert Wesarg· Oct 20, 2011, 19:45 UTC · lore

Selecting in the gutter columns of the blame view should make no sense, so delegate any selection action in these columns to the text output by selecting whole lines there.

Signed-off-by: Bert Wesarg <bert.wesarg@googlemail.com>
---
 git-gui.sh    |   20 ++++++++++++++++++++
 lib/blame.tcl |    4 +++-
 2 files changed, 23 insertions(+), 1 deletions(-)
Show changes to 2 files +23 −1

git-gui.sh, lib/blame.tcl

diff --git a/git-gui.sh b/git-gui.sh
index 21033cb..cf5ed79 100755
--- a/git-gui.sh
+++ b/git-gui.sh
@@ -2077,6 +2077,26 @@ proc many2scrollbar {list mode sb top bottom} {
 	foreach w $list {$w $mode moveto $top}
 }
 
+proc delegate_sel_to {w from} {
+	set bind_list [list \
+		<Button-1> \
+		<B1-Motion> \
+		<Double-Button-1> \
+		<Triple-Button-1> \
+		<Shift-Button-1> \
+		<Double-Shift-Button-1> \
+		<Triple-Shift-Button-1> \
+	]
+
+	foreach seq $bind_list {
+		set script [bind Text $seq]
+		set new_script [string map [list %W $w %x 0 word line] $script]
+		foreach f $from {
+			bind $f $seq "$new_script; break"
+		}
+	}
+}
+
 proc incr_font_size {font {amt 1}} {
 	set sz [font configure $font -size]
 	incr sz $amt
diff --git a/lib/blame.tcl b/lib/blame.tcl
index 49eae19..9ab0da5 100644
--- a/lib/blame.tcl
+++ b/lib/blame.tcl
@@ -210,6 +210,8 @@ constructor new {i_commit i_path i_jump} {
 
 	set w_columns [list $w_amov $w_asim $w_line $w_file]
 
+	delegate_sel_to $w_file [list $w_amov $w_asim $w_line]
+
 	${NS}::scrollbar $w.file_pane.out.sbx \
 		-orient h \
 		-command [list $w_file xview]
@@ -315,7 +317,7 @@ constructor new {i_commit i_path i_jump} {
 		$i conf -yscrollcommand \
 			"[list ::searchbar::scrolled $finder]
 			 [list many2scrollbar $w_columns yview $w.file_pane.out.sby]"
-		bind $i <Button-1> "
+		bind $i <Button-1> "+
 			[cb _hide_tooltip]
 			[cb _click $i @%x,%y]
 			focus $i
-- 
1.7.7.759.gfc8c6
Pat Thoyts· Oct 21, 2011, 22:24 UTC · re: Bert Wesarg · lore

Re: [PATCH] git-gui: delegate selection from gutter columns to text output

Bert Wesarg <bert.wesarg@googlemail.com> writes:
Show 63 quoted lines
>Selecting in the gutter columns of the blame view should make no sense,
>so delegate any selection action in these columns to the text output
>by selecting whole lines there.
>
>Signed-off-by: Bert Wesarg <bert.wesarg@googlemail.com>
>---
> git-gui.sh    |   20 ++++++++++++++++++++
> lib/blame.tcl |    4 +++-
> 2 files changed, 23 insertions(+), 1 deletions(-)
>
>diff --git a/git-gui.sh b/git-gui.sh
>index 21033cb..cf5ed79 100755
>--- a/git-gui.sh
>+++ b/git-gui.sh
>@@ -2077,6 +2077,26 @@ proc many2scrollbar {list mode sb top bottom} {
> 	foreach w $list {$w $mode moveto $top}
> }
> 
>+proc delegate_sel_to {w from} {
>+	set bind_list [list \
>+		<Button-1> \
>+		<B1-Motion> \
>+		<Double-Button-1> \
>+		<Triple-Button-1> \
>+		<Shift-Button-1> \
>+		<Double-Shift-Button-1> \
>+		<Triple-Shift-Button-1> \
>+	]
>+
>+	foreach seq $bind_list {
>+		set script [bind Text $seq]
>+		set new_script [string map [list %W $w %x 0 word line] $script]
>+		foreach f $from {
>+			bind $f $seq "$new_script; break"
>+		}
>+	}
>+}
>+
> proc incr_font_size {font {amt 1}} {
> 	set sz [font configure $font -size]
> 	incr sz $amt
>diff --git a/lib/blame.tcl b/lib/blame.tcl
>index 49eae19..9ab0da5 100644
>--- a/lib/blame.tcl
>+++ b/lib/blame.tcl
>@@ -210,6 +210,8 @@ constructor new {i_commit i_path i_jump} {
> 
> 	set w_columns [list $w_amov $w_asim $w_line $w_file]
> 
>+	delegate_sel_to $w_file [list $w_amov $w_asim $w_line]
>+
> 	${NS}::scrollbar $w.file_pane.out.sbx \
> 		-orient h \
> 		-command [list $w_file xview]
>@@ -315,7 +317,7 @@ constructor new {i_commit i_path i_jump} {
> 		$i conf -yscrollcommand \
> 			"[list ::searchbar::scrolled $finder]
> 			 [list many2scrollbar $w_columns yview $w.file_pane.out.sby]"
>-		bind $i <Button-1> "
>+		bind $i <Button-1> "+
> 			[cb _hide_tooltip]
> 			[cb _click $i @%x,%y]
> 			focus $i

The patch seems to be fine but I don't think I agree with the intention here. Currently clicking anywhere that is not marked as a link (blue underlined text) selects a commit and shows information in the lower pane. With this change, the left hand columns become inactive in regards to selecting a commit. I don't see why that is desirable.

-- 
Pat Thoyts                            http://www.patthoyts.tk/
PGP fingerprint 2C 6E 98 07 2C 59 C8 97  10 CE 11 E6 04 E0 B9 DD
Bert Wesarg· Oct 22, 2011, 15:41 UTC · re: Pat Thoyts · lore

Re: [PATCH] git-gui: delegate selection from gutter columns to text output

On Sat, Oct 22, 2011 at 00:24, Pat Thoyts <patthoyts@users.sourceforge.net> wrote:

Show 71 quoted lines
> Bert Wesarg <bert.wesarg@googlemail.com> writes:
>
>>Selecting in the gutter columns of the blame view should make no sense,
>>so delegate any selection action in these columns to the text output
>>by selecting whole lines there.
>>
>>Signed-off-by: Bert Wesarg <bert.wesarg@googlemail.com>
>>---
>> git-gui.sh    |   20 ++++++++++++++++++++
>> lib/blame.tcl |    4 +++-
>> 2 files changed, 23 insertions(+), 1 deletions(-)
>>
>>diff --git a/git-gui.sh b/git-gui.sh
>>index 21033cb..cf5ed79 100755
>>--- a/git-gui.sh
>>+++ b/git-gui.sh
>>@@ -2077,6 +2077,26 @@ proc many2scrollbar {list mode sb top bottom} {
>>       foreach w $list {$w $mode moveto $top}
>> }
>>
>>+proc delegate_sel_to {w from} {
>>+      set bind_list [list \
>>+              <Button-1> \
>>+              <B1-Motion> \
>>+              <Double-Button-1> \
>>+              <Triple-Button-1> \
>>+              <Shift-Button-1> \
>>+              <Double-Shift-Button-1> \
>>+              <Triple-Shift-Button-1> \
>>+      ]
>>+
>>+      foreach seq $bind_list {
>>+              set script [bind Text $seq]
>>+              set new_script [string map [list %W $w %x 0 word line] $script]
>>+              foreach f $from {
>>+                      bind $f $seq "$new_script; break"
>>+              }
>>+      }
>>+}
>>+
>> proc incr_font_size {font {amt 1}} {
>>       set sz [font configure $font -size]
>>       incr sz $amt
>>diff --git a/lib/blame.tcl b/lib/blame.tcl
>>index 49eae19..9ab0da5 100644
>>--- a/lib/blame.tcl
>>+++ b/lib/blame.tcl
>>@@ -210,6 +210,8 @@ constructor new {i_commit i_path i_jump} {
>>
>>       set w_columns [list $w_amov $w_asim $w_line $w_file]
>>
>>+      delegate_sel_to $w_file [list $w_amov $w_asim $w_line]
>>+
>>       ${NS}::scrollbar $w.file_pane.out.sbx \
>>               -orient h \
>>               -command [list $w_file xview]
>>@@ -315,7 +317,7 @@ constructor new {i_commit i_path i_jump} {
>>               $i conf -yscrollcommand \
>>                       "[list ::searchbar::scrolled $finder]
>>                        [list many2scrollbar $w_columns yview $w.file_pane.out.sby]"
>>-              bind $i <Button-1> "
>>+              bind $i <Button-1> "+
>>                       [cb _hide_tooltip]
>>                       [cb _click $i @%x,%y]
>>                       focus $i
>
> The patch seems to be fine but I don't think I agree with the intention
> here. Currently clicking anywhere that is not marked as a link (blue
> underlined text) selects a commit and shows information in the lower
> pane. With this change, the left hand columns become inactive in regards
> to selecting a commit. I don't see why that is desirable.

Sorry, this was not intended. And I thought I took care for it with the last hunk. I have a look at it again.

Bert
Show 5 quoted lines
>
> --
> Pat Thoyts                            http://www.patthoyts.tk/
> PGP fingerprint 2C 6E 98 07 2C 59 C8 97  10 CE 11 E6 04 E0 B9 DD
>
Bert Wesarg· Oct 22, 2011, 19:38 UTC · re: Bert Wesarg · lore

[PATCHv2] git-gui: delegate selection from gutter columns to text output

Selecting in the gutter columns of the blame view should make no sense, so delegate any selection action in these columns to the text output by selecting whole lines there.

Signed-off-by: Bert Wesarg <bert.wesarg@googlemail.com>
---
 git-gui.sh    |   29 +++++++++++++++++++++++++++++
 lib/blame.tcl |   20 +++++++++++++++-----
 2 files changed, 44 insertions(+), 5 deletions(-)
Show changes to 2 files +44 −5

git-gui.sh, lib/blame.tcl

diff --git a/git-gui.sh b/git-gui.sh
index 21033cb..53d6b43 100755
--- a/git-gui.sh
+++ b/git-gui.sh
@@ -2077,6 +2077,35 @@ proc many2scrollbar {list mode sb top bottom} {
 	foreach w $list {$w $mode moveto $top}
 }
 
+# delegates mouse selection actions from gutter columns to the main text
+# widget
+# use delegator_bind, if you need to bind more actions
+proc delegate_sel_to {w from} {
+	set bind_list [list \
+		<Button-1> \
+		<B1-Motion> \
+		<Double-Button-1> \
+		<Triple-Button-1> \
+		<Shift-Button-1> \
+		<Double-Shift-Button-1> \
+		<Triple-Shift-Button-1> \
+	]
+
+	foreach seq $bind_list {
+		set script [bind Text $seq]
+		set new_script [string map [list %W $w %x 0 word line] $script]
+		foreach f $from {
+			bind $f $seq "$new_script; focus $w; break"
+		}
+	}
+}
+
+# use this for binding any of the mouse actions from a delegator
+# see bind_list in delegate_sel_to
+proc delegator_bind {tag seq script} {
+	bind $tag $seq "$script; [bind $tag $seq]"
+}
+
 proc incr_font_size {font {amt 1}} {
 	set sz [font configure $font -size]
 	incr sz $amt
diff --git a/lib/blame.tcl b/lib/blame.tcl
index b031e66..b7eb18a 100644
--- a/lib/blame.tcl
+++ b/lib/blame.tcl
@@ -210,6 +210,8 @@ constructor new {i_commit i_path i_jump} {
 
 	set w_columns [list $w_amov $w_asim $w_line $w_file]
 
+	delegate_sel_to $w_file [list $w_amov $w_asim $w_line]
+
 	${NS}::scrollbar $w.file_pane.out.sbx \
 		-orient h \
 		-command [list $w_file xview]
@@ -318,11 +320,19 @@ constructor new {i_commit i_path i_jump} {
 		$i conf -yscrollcommand \
 			"[list ::searchbar::scrolled $finder]
 			 [list many2scrollbar $w_columns yview $w.file_pane.out.sby]"
-		bind $i <Button-1> "
-			[cb _hide_tooltip]
-			[cb _click $i @%x,%y]
-			focus $i
-		"
+		if {$i eq $w_file} {
+			bind $i <Button-1> "
+				[cb _hide_tooltip]
+				[cb _click $i @%x,%y]
+				focus $i
+			"
+		} else {
+			delegator_bind $i <Button-1> "
+				[cb _hide_tooltip]
+				[cb _click $i @%x,%y]
+				focus $i
+			"
+		}
 		bind $i <Any-Motion>  [cb _show_tooltip $i @%x,%y]
 		bind $i <Any-Enter>   [cb _hide_tooltip]
 		bind $i <Any-Leave>   [cb _hide_tooltip]
-- 
1.7.7.908.g383b5

← back to recent threads