Improved handling of case where child is killed by a signal
[tcl-tlc.git] / scripts / textvariable.itcl
blob92dc35a885438222450055cc5ca691324bfe68ee
1 # vim: foldmarker=<<<,>>>
3 class tlc::Textvariable {
4 inherit tlc::Baselog
6 public {
7 variable textvariable ""
10 protected {
11 method textvariable_changed {newvalue}
12 method set_textvariable {newvalue}
15 private {
16 variable old_textvariable ""
17 variable lock 0
18 variable oldvalue ""
20 method newvalue {args}
25 configbody tlc::Textvariable::textvariable { #<<<1
26 log debug $this
27 if {$old_textvariable != ""} {
28 trace vdelete $old_textvariable w [code $this newvalue]
30 if {$textvariable != ""} {
31 trace variable $textvariable wu [code $this newvalue]
32 set old_textvariable $textvariable
34 newvalue
38 body tlc::Textvariable::newvalue {args} { #<<<1
39 log debug "$this lock: ($lock)"
40 if {[lindex $args 2] == "u"} {
41 # unset
42 return
44 if {$lock} return
45 if {$textvariable == ""} return
46 if {![info exists $textvariable]} return
48 set newvalue [set $textvariable]
50 incr lock
51 tlc::try {
52 textvariable_changed $newvalue
54 set oldvalue $newvalue
55 } onerr {
56 reject_change {
57 set $textvariable $oldvalue
60 default {
61 log error "\nDerived class textvariable_changed returned error: $errmsg\n$::errorInfo"
64 incr lock -1
68 body tlc::Textvariable::textvariable_changed {newvalue} { #<<<1
69 # Override in derived class to be notified of updates to the textvariable
70 log warning "$this This should be overridden in derived class"
74 body tlc::Textvariable::set_textvariable {newvalue} { #<<<1
75 log debug "$this locked: ($lock)"
76 if {$lock} return
78 incr lock
80 if {$textvariable != ""} {
81 set $textvariable $newvalue
84 incr lock -1