2 package provide mlcm::menu 0.1
4 namespace eval mlcm::menu {
10 proc addentry {name rec} {
12 if [catch {set menus $_all($name)}] {
15 set len [llength $menus]
16 set ent [$rec get 3000]
17 set idx [expr $ent / 100]
18 for {set j $len} {$idx >= $j} {incr j} {
21 set lst [lindex $menus $idx]
22 set cfg [openIsisRec {} -fdt $mlcm::meta::fdtMenu]
23 eval $cfg add -ignore [$rec get -tags]
27 set _all($name) $menus
30 proc _sortentries {e1 e2} {
38 foreach {key lst} [array get _all] {
39 set len [llength $lst]
41 for {set j 0} {$len > $j} {incr j} {
42 set ent [lindex $lst $j]
44 set ent [lsort -command _sortentries $ent]
52 proc _name2lbl {name underl} {
54 set idx [string first & $name]
56 set res [string range $name [expr $idx + 1] end]
58 set n1 [string range $name 0 [expr $idx - 1]]
61 set idx "-underline $idx"
69 set name [_name2lbl [mlcm::lang::strippedMsg [$rec get name\[0\]]] underl]
70 return "-text $name $underl"
74 set name [_name2lbl [mlcm::lang::strippedMsg [$rec get name\[0\]]] underl]
75 set cmd [$rec get {command\[0\] {}}]
76 if [string length $cmd] {
77 set cmd "-command \{$cmd\}"
79 set act [$rec get {active\[0\] 1}]
83 set act "-state disabled"
85 return "-label \"$name\" $underl $cmd $act"
90 set _act [ expr ! $_act ]
93 proc showmenu {name parent} {
97 foreach lst $_all($name) {
98 set len [llength $lst]
100 set rec [lindex $lst 0]
103 set opts [_rec2btn $rec]
104 eval menubutton $bttn $opts \
105 -menu $subm -bd 2 -relief flat
106 pack $bttn -side left
107 menu $subm -tearoff 0 -borderwidth 2
108 for {set s 1} {$len > $s} {incr s} {
109 set rec [lindex $lst $s]
110 set opts [_rec2cmd $rec]
111 eval $subm add command $opts
117 set _men("$parent\ $name") $j
121 proc notify {name parent} {
124 if {0 == [string length $name]} {
127 if {0 == [string length $parent]} {
130 foreach {key maxm} [array get _men "\"$parent\ $name\""] {
131 set parent [eval lindex $key 0]
132 set name [eval lindex $key 1]
133 if ![llength [info command $parent]] {
134 puts "mlcm::menu: removing $parent"
135 array unset _men $key
139 foreach lst $_all($name) {
140 set len [llength $lst]
142 set subm $parent.$j.sub
143 for {set s 1} {$len > $s} {incr s} {
144 set rec [lindex $lst $s]
145 set act [$rec get {active\[0\] 1}]
146 if [eval expr $act] {
152 set sto [$subm entrycget $s1 -state]
153 if ![string equal $sto $stn] {
154 $subm entryconfigure $s1 -state $stn