Improved handling of case where child is killed by a signal
[tcl-tlc.git] / scripts / dspopup.itk
blob60fc7c2b24b6d0df43cb0f347c1e1db858cab4ea
1 # vim: ft=tcl foldmethod=marker foldmarker=<<<,>>> ts=4 shiftwidth=4
3 option add *DSpopup.showRoot                    false           widgetDefault
4 option add *DSpopup.yScrollMode                 "static"        widgetDefault
5 option add *DSpopup.xScrollMode                 "dynamic"       widgetDefault
6 option add *DSpopup.actionButtonWidth   9                       widgetDefault
9 class tlc:DSpopup {
10         inherit tlc::Module tlc::Baselog
12         constructor {args} {}
13         destructor {}
15         public {
16                 variable ds             {}
17                 variable parent
18         }
20         private {
21                 variable old_ds
22                 variable row_cache      {}
24                 method headers_changed {new_headers}
25                 method item_selected {item_arr}
26                 method onchange {}
27         }
31 configbody tlc::DSpopup::ds { #<<<1
32         if {[info exists old_ds] && [itcl::is object $old_ds]} {
33                 $old_ds deregister_handler headers_changed [code $this headers_changed]
34                 $old_ds deregister_handler onchange [code $this onchange]
35         }
36         $itk_component(list) configure -datasource $ds
38         if {$ds != {}} {
39                 $ds register_handler headers_changed [code $this headers_changed]
40                 $ds register_handler onchange [code $this onchange]
41                 set old_ds      $ds
42                 onchange
43                 headers_changed [$ds get_headers]
44         } else {
45                 if {[info exists old_ds]} {
46                         unset old_ds
47                 }
48         }
52 body tlc::DSpopup::constructor {args} { #<<<1
53         itk_component add list {
54                 tlc::Browse_tktreectrl $w.list
55         } {
56                 keep -filter_options -actionside -criteria -column_defaults
57                 keep -column_options -column_styles
58                 keep -textbackground
59                 keep -cursor -highlightbackground -highlightcolor
60                 keep -highlightthickness -foreground -backgroundimage -backgroundmode
61                 keep -buttonbitmap -buttoncolor -buttonimage -buttonsize
62                 keep -buttonthickness -columnprefix -columnproxy
63                 keep -columnresizemode -doublebuffer -height -indent
64                 keep -itemheight -itemprefix -itemwidth -itemwidthequal
65                 keep -itemwidthmultiple -linecolor -linestyle -linethickness
66                 keep -minitemheight -scrollmargin -selectmode -showbuttons -showheader
67                 keep -showlines -showroot -showrootbutton -showrootlines -treecolumn
68                 keep -usetheme -width -wrap -orient -xscrolldelay -xscrollincrement
69                 keep -yscrolldelay -yscrollincrement
70                 #keep -borderwidth -relief -takefocus
71         }
73         eval itk_initialize $args
75         foreach reqf {parent} {
76                 if {![info exists $reqf]} {
77                         error "Must set -$reqf" "" [list missing_field $reqf]
78                 }
79         }
81         $w.list filter_add "Search" {spec entry}
82         headers_changed [$ds get_headers]
84         $w.list register_handler onselect_arr [code $this item_selected]
88 body tlc::DSpopup::destructor {} { #<<<1
89         $ds deregister_handler headers_changed [code $this headers_changed]
90         $ds deregister_handler onchange [code $this onchange]
94 body tlc::DSpopup::headers_changed {new_headers} { #<<<1
95         set filter      {}
96         if {$ds != {}} {
97                 foreach h $new_headers {
98                         lappend filter [string map \
99                                         [list %field% [list $h]] \
100                                         {[string match -nocase "*$filter(spec)*" $row(%field%)]}]
101                 }
102         }
103         $w.list filter_update "Search" [join $filter " ||\n"]
107 body tlc::DSpopup::item_selected {item_arr} { #<<<1
108         $parent set_choice $item_arr
112 body tlc::DSpopup::onchange {} { #<<<1
113         set row_cache   [$ds get_list {}]