@matheusbsbs / matheus-bagliano / commits / 16fccd7a11
Fork 0

git-gui: Improve right click context menu binding on all platforms.

Apparently <Button-3> doesn't work on my single button PowerBook mouse under Mac OS X. I'm guessing this is because Tk is stealing every event and doesn't realize that Control-Button-1 is actually supposed to invoke the context menu on this platform. So now we have a utility procedure is_MacOSX to guess if we are running on a Mac OS X system, and if so setup Control-Button-1 to also activate what Button-3 should have. This does mean that I need to stay away from using Control-Button-1 as a binding in any other context. Of course we should use $M1B for that, which is M1 (aka Command) on Mac OS X so that shouldn't prove to be a problem. Signed-off-by: Shawn O. Pearce <spearce@spearce.org>

Shawn O. Pearce committed Nov 12, 2006 at 02:22 UTC 16fccd7a1111c1fca6ce973ddaff690188e742d0
1 file changed +29 -8
git-gui
+29 -8
@@ -1285,6 +1285,23 @@ unset filemask i
1285 ##
1286 ## util
1287
1288 +proc is_MacOSX {} {
1289 + global tcl_platform tk_library
1290 + if {$tcl_platform(platform) == {unix}
1291 + && $tcl_platform(os) == {Darwin}
1292 + && [string match /Library/Frameworks/* $tk_library]} {
1293 + return 1
1294 + }
1295 + return 0
1296 +}
1297 +
1298 +proc bind_button3 {w cmd} {
1299 + bind $w <Any-Button-3> $cmd
1300 + if {[is_MacOSX]} {
1301 + bind $w <Control-Button-1> $cmd
1302 + }
1303 +}
1304 +
1305 proc incr_font_size {font {amt 1}} {
1306 set sz [font configure $font -size]
1307 incr sz $amt
@@ -1398,7 +1415,7 @@ proc console_init {w} {
1415 -command "destroy $w"
1416 pack $w.ok -side bottom
1417
1401 - bind $w.m.t <Any-Button-3> "tk_popup $w.ctxm %X %Y"
1418 + bind_button3 $w.m.t "tk_popup $w.ctxm %X %Y"
1419 bind $w.m.t <$M1B-Key-a> "$w.m.t tag add sel 0.0 end;break"
1420 bind $w.m.t <$M1B-Key-A> "$w.m.t tag add sel 0.0 end;break"
1421 bind $w <Visibility> "focus $w"
@@ -1655,10 +1672,14 @@ font configure font_uibold -weight bold
1672 eval font create font_diffbold [font configure font_diff]
1673 font configure font_diffbold -weight bold
1674
1658 -switch -glob -- "$tcl_platform(platform),$tcl_platform(os)" {
1659 -windows,* {set M1B Control; set M1T Ctrl}
1660 -unix,Darwin {set M1B M1; set M1T Cmd}
1661 -* {set M1B M1; set M1T M1}
1675 +set M1B M1
1676 +set M1T M1
1677 +if {$tcl_platform(platform) == {windows}} {
1678 + set M1B Control
1679 + set M1T Ctrl
1680 +} elseif {[is_MacOSX]} {
1681 + set M1B M1
1682 + set M1T Cmd
1683 }
1684
1685 # -- Menu Bar
@@ -1920,7 +1941,7 @@ $ui_comm.ctxm add separator
1941 $ui_comm.ctxm add command -label "Sign Off" \
1942 -font font_ui \
1943 -command do_signoff
1923 -bind $ui_comm <Any-Button-3> "tk_popup $ui_comm.ctxm %X %Y"
1944 +bind_button3 $ui_comm "tk_popup $ui_comm.ctxm %X %Y"
1945
1946 # -- Diff Header
1947 set ui_fname_value {}
@@ -1997,7 +2018,7 @@ $ui_diff.ctxm add command -label "Decrease Font Size" \
2018 $ui_diff.ctxm add command -label "Increase Font Size" \
2019 -font font_ui \
2020 -command {incr_font_size font_diff 1}
2000 -bind $ui_diff <Any-Button-3> "tk_popup $ui_diff.ctxm %X %Y"
2021 +bind_button3 $ui_diff "tk_popup $ui_diff.ctxm %X %Y"
2022
2023 # -- Status Bar
2024 set ui_status_value {Initializing...}
@@ -2063,8 +2084,8 @@ bind all <$M1B-Key-w> {destroy [winfo toplevel %W]}
2084 bind all <$M1B-Key-W> {destroy [winfo toplevel %W]}
2085 foreach i [list $ui_index $ui_other] {
2086 bind $i <Button-1> {click %W %x %y 1 %X %Y; break}
2066 - bind $i <Button-3> {click %W %x %y 3 %X %Y; break}
2087 bind $i <ButtonRelease-1> {unclick %W %x %y; break}
2088 + bind_button3 $i {click %W %x %y 3 %X %Y; break}
2089 }
2090 unset i
2091