Here's a short script to show how to get popup menus appearing for text tag objects.
#---------------
# texttag-popup.tcl
#---------------
#!/bin/sh
#\
exec tclsh "$0" "$@"
package require Gnocl
set txt [gnocl::text -wrapMode word]
gnocl::window -child $txt -setSize 0.25
#---------------
# display popup menu
#---------------
proc doTagPopup {args} {
foreach {arg val} $args { set [string trimleft $arg "-"] $val }
if {$t == "buttonPress" && $b == "3" } {
# these may need runtime re-definition
proc doHello {} {puts hello}
proc doGoodBye {} {puts goodbye}
set menu [gnocl::menu -title "menu" -tearoff 0]
$menu add [gnocl::menuItem -text "Hello" -onClicked doHello]
$menu add [gnocl::menuItem -text "Goodbye" -onClicked doGoodBye]
$menu popup $x $y
#proc doHello {} {}
#proc doGoodBye {} {}
}
}
$txt tag create tag_popup -onEvent {doTagPopup -t %t -b %b -x %X -y %Y } -underline single -foreground blue
$txt lorem
$txt tag apply {1 0} "1 20" -tags tag_popup
#---------------
# texttag-popup.tcl
#---------------
#!/bin/sh
#\
exec tclsh "$0" "$@"
package require Gnocl
set txt [gnocl::text -wrapMode word]
gnocl::window -child $txt -setSize 0.25
#---------------
# display popup menu
#---------------
proc doTagPopup {args} {
foreach {arg val} $args { set [string trimleft $arg "-"] $val }
if {$t == "buttonPress" && $b == "3" } {
# these may need runtime re-definition
proc doHello {} {puts hello}
proc doGoodBye {} {puts goodbye}
set menu [gnocl::menu -title "menu" -tearoff 0]
$menu add [gnocl::menuItem -text "Hello" -onClicked doHello]
$menu add [gnocl::menuItem -text "Goodbye" -onClicked doGoodBye]
$menu popup $x $y
#proc doHello {} {}
#proc doGoodBye {} {}
}
}
$txt tag create tag_popup -onEvent {doTagPopup -t %t -b %b -x %X -y %Y } -underline single -foreground blue
$txt lorem
$txt tag apply {1 0} "1 20" -tags tag_popup
Comments