@matheusbsbs / matheus-bagliano / commits / 3849bfba84
Fork 0

git-gui: Disable native platform text selection in "lists"

Sometimes we use a Tk text widget as though it were a listbox. This happens typically when we want to show an icon to the left of the text label or just when a text widget is generally a better choice then the native listbox widget. In these cases if we want the user to have control over the selection we implement our own "in_sel" tag that shows the selected region and we perform our own selection management in the background via keybindings and mouse bindings. In such uses we don't want the user to be able to activate the native platform selection by dragging their mouse through the text widget. Doing so creates a very confusing display and the user is left wondering what it may mean to have two different types of selection in the same widget. Tk doesn't allow us to delete the "sel" tag that it uses internally to manage the native selection but it will allow us to make it invisible by setting the tag to have the same display properties as unselected text. So long as we don't actually use the "sel" tag for anything in code its effectively invisible. Signed-off-by: Shawn O. Pearce <spearce@spearce.org>

Shawn O. Pearce committed Sep 16, 2007 at 23:12 UTC 3849bfba84fb5b0e9d46920f62105b4e1dd97e63
3 files changed +18 -9
git-gui.sh
+12 -2
@@ -481,6 +481,16 @@ proc tk_optionMenu {w varName args} {
481 return $m
482 }
483
484 +proc rmsel_tag {text} {
485 + $text tag conf sel \
486 + -background [$text cget -background] \
487 + -foreground [$text cget -foreground] \
488 + -borderwidth 0
489 + $text tag conf in_sel -background lightgray
490 + bind $text <Motion> break
491 + return $text
492 +}
493 +
494 ######################################################################
495 ##
496 ## find git
@@ -2151,8 +2161,8 @@ pack $ui_workdir -side left -fill both -expand 1
2161 .vpane.files add .vpane.files.workdir -sticky nsew
2162
2163 foreach i [list $ui_index $ui_workdir] {
2154 - $i tag conf in_diff -background lightgray
2155 - $i tag conf in_sel -background lightgray
2164 + rmsel_tag $i
2165 + $i tag conf in_diff -background [$i tag cget in_sel -background]
2166 }
2167 unset i
2168
lib/browser.tcl
+1 -3
@@ -47,9 +47,7 @@ constructor new {commit {path {}}} {
47 -width 70 \
48 -xscrollcommand [list $w.list.sbx set] \
49 -yscrollcommand [list $w.list.sby set]
50 - $w_list tag conf in_sel \
51 - -background [$w_list cget -foreground] \
52 - -foreground [$w_list cget -background]
50 + rmsel_tag $w_list
51 scrollbar $w.list.sbx -orient h -command [list $w_list xview]
52 scrollbar $w.list.sby -orient v -command [list $w_list yview]
53 pack $w.list.sbx -side bottom -fill x
lib/choose_font.tcl
+5 -4
@@ -62,6 +62,7 @@ constructor pick {path title a_family a_size} {
62 -width 30 \
63 -height 10 \
64 -yscrollcommand [list $w.inner.family.sby set]
65 + rmsel_tag $w_family
66 scrollbar $w.inner.family.sby -command [list $w_family yview]
67 pack $w.inner.family.l -side top -fill x
68 pack $w.inner.family.sby -side right -fill y
@@ -95,6 +96,7 @@ constructor pick {path title a_family a_size} {
96 -relief sunken \
97 -height 3 \
98 -width 40
99 + rmsel_tag $w_example
100 $w_example tag conf example -justify center
101 $w_example insert end [mc "This is example text.\nIf you like this text, it can be your font."] example
102 $w_example conf -state disabled
@@ -108,11 +110,10 @@ constructor pick {path title a_family a_size} {
110
111 $w_family tag conf pick
112 $w_family tag bind pick <Button-1> [cb _pick_family %x %y]\;break
111 - $w_family tag conf cpck -background lightgray
113 foreach f $all_families {
114 set sel [list pick]
115 if {$f eq $f_family} {
115 - lappend sel cpck
116 + lappend sel in_sel
117 }
118 $w_family insert end "$f\n" $sel
119 }
@@ -145,8 +146,8 @@ method _pick_family {x y} {
146 set i [lindex [split [$w_family index @$x,$y] .] 0]
147 set n [lindex $all_families [expr {$i - 1}]]
148 if {$n ne {}} {
148 - $w_family tag remove cpck 0.0 end
149 - $w_family tag add cpck $i.0 [expr {$i + 1}].0
149 + $w_family tag remove in_sel 0.0 end
150 + $w_family tag add in_sel $i.0 [expr {$i + 1}].0
151 set f_family $n
152 _update $this
153 }