[Ludwig Callewaert
] wrote in
comp.lang.tcl, regarding
a change-sensitive text widget:
All changes to the text widget are either done with the insert or delete text widget command. Overload these (by using
Wcb for instance).
By overloading I mean that you provide a new implementation for those commands. In your case, the overloaded commands could first call the original insert or delete command and could then set a flag (a global variable for instance) indicating that the content of the text widget has changed. By putting a trace on that flag (with the trace command), you can make something happen everytime the widget content changes.
There are actually several ways to do this. One possibility is the following:
pack [text .t]
global flag
set flag 0
trace variable flag w changed
rename .t orig_t
proc .t {args} {
global flag
set returnVal [eval [concat orig_t $args]]
set command [lindex $args 0]
if {[string equal $command "insert"] || [string equal $command "delete"]} {
set flag 1
}
return $returnVal
}
proc changed {args} {
puts "something changed"
}
Wcb, the widget callback package which can be found at
http://www.nemethi.de/
is a more general way to do this.