1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279
|
# Copyright (C) 1987-2005 by Jeffery P. Hansen
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
#
# Last edit by hansen on Thu Sep 2 11:07:49 2004
#
set blk_src ""
set blk_dst ""
proc tkg_blockOp {cap sprompt dprompt opr} {
global blk_src blk_dst tkg_currentBlock
if { [catch { toplevel .blk } ] } { return }
wm title .blk $cap
wm geometry .blk [offsetgeometry . 50 50 ]
wm transient .blk .
set blk_src ""
set blk_dst ""
set i [.sbar.blklst.f.list curselection]
if { $i != "" } {
set blk_src [string trim [.sbar.blklst.f.list get $i] "+()"]
} else {
#
# Get the current block name and remove any junk if necessary.
#
set blk_src $tkg_currentBlock
set i [string last ":" $blk_src]
if { $i >= 0 } {
set blk_src [string range $blk_src [expr $i+1] end]
}
set i [string first "(" $blk_src]
if { $i >= 0 } {
set blk_src [string range $blk_src 0 [expr $i - 1]]
}
}
frame .blk.t -relief raised -bd 2
label .blk.t.tsrc -text $sprompt
entry .blk.t.esrc -textvariable blk_src
grid .blk.t.tsrc -row 0 -column 0 -sticky e -padx 3 -pady 3
grid .blk.t.esrc -row 0 -column 1 -sticky w -padx 3 -pady 3
set opr "destroy .blk; $opr"
if { $dprompt != "" } {
label .blk.t.tdst -text $dprompt
entry .blk.t.edst -textvariable blk_dst
grid .blk.t.tdst -row 1 -column 0 -sticky e -padx 3 -pady 3
grid .blk.t.edst -row 1 -column 1 -sticky w -padx 3 -pady 3
append opr { $blk_src $blk_dst }
bind .blk.t.esrc <Return> $opr
bind .blk.t.edst <Return> $opr
} else {
append opr { $blk_src }
bind .blk.t.esrc <Return> $opr
}
okcancel .blk.b $opr { destroy .blk }
pack .blk.t -ipadx 10 -ipady 10
pack .blk.b -fill x
if { $blk_src != "" } { .blk.t.esrc selection range 0 end }
focus .blk.t.esrc
grab set .blk
tkwait window .blk
grab release .blk
}
proc tkg_blockNew {} {
tkg_blockOp "TKGate: Module New" "[m blklst.newmod]:" "" gat_newBlock
}
proc tkg_blockDelete {} {
tkg_blockOp "TKGate: Module Delete" "[m blklst.delmod]:" "" gat_deleteBlock
}
proc tkg_blockCopy {} {
tkg_blockOp "TKGate: Module Copy" "[m blklst.frommod]:" "[m blklst.tomod]:" gat_copyBlock
}
proc tkg_blockRename {} {
tkg_blockOp "TKGate: Module Rename" "[m blklst.oldname]:" "[m blklst.newname]:" gat_renameBlock
}
proc tkg_blockClaim {} {
tkg_blockOp "TKGate: Claim Module" "[m blklst.claim]:" "" gat_claimBlock
}
#
# Compare two block names.
#
proc blklstCompare {A B} {
set tA [string trim $A "+()"]
set tB [string trim $B "+()"]
set lcA [string tolower $tA]
set lcB [string tolower $tB]
set c [string compare $lcA $lcB]
if {$c == 0} {
set c [string compare $tA $tB]
}
return $c
}
#
# Add a block to the block list in sorted order
#
proc tkg_blockListAdd {blk} {
lbSortRInsert .sbar.blklst.f.list $blk blklstCompare
}
proc tkg_blockListClear {} {
.sbar.blklst.f.list delete 0 end
}
proc tkg_blockListRemove {blk} {
lbSortDelete .sbar.blklst.f.list $blk blklstCompare
}
#
# Make item at position i the root module
#
proc tkg_blockListIdxSetRoot {j} {
set n [.sbar.blklst.f.list size]
for { set i 0 } { $i < $n } { incr i } {
set s [.sbar.blklst.f.list get $i]
if { [string match "*+" $s] } {
set s [string trim $s "+()"]
.sbar.blklst.f.list delete $i
.sbar.blklst.f.list insert $i $s
.sbar.blklst.f.list selection set $i
break
}
}
set s [.sbar.blklst.f.list get $j]
.sbar.blklst.f.list delete $j
.sbar.blklst.f.list insert $j "$s+"
.sbar.blklst.f.list selection clear 0 end
.sbar.blklst.f.list selection set $j
}
#
# Make the named module a library if islib is set, or not a libary if it is not set.
#
proc tkg_blockListSetLibFlag {name islib} {
set n [.sbar.blklst.f.list size]
for { set i 0 } { $i < $n } { incr i } {
set q [.sbar.blklst.f.list get $i]
set s [string trim $q "()+"]
if { $s == $name } {
if { $islib != 0 } { set s "($s)" }
if { [string first "+" $q] >= 0 } { set s "$s+" }
.sbar.blklst.f.list delete $i
.sbar.blklst.f.list insert $i $s
break
}
}
}
namespace eval BlockListDrag {
variable drag_obj ""
variable mouseset_x 0
variable mouseset_y 0
proc seeB1 {w x y} {
variable mouseset_x
variable mouseset_y
variable drag_obj
set mouseset_x ""
set mouseset_y ""
set drag_obj ""
}
proc seeModuleDrop {m w x y} {
variable mouseset_x
variable mouseset_y
set mouseset_x ""
set mouseset_y ""
if { $w == ".frame.cf.canvas"} {
action Make "gat_make block -func $m -x $x -y $y -interface 1"
}
}
#
# Respond to motion of the mouse with button 1 depressed
#
proc seeMotion {w x y} {
variable drag_obj
variable mouseset_x
variable mouseset_y
global bd
if { $mouseset_x == "" } {
set mouseset_x $x
set mouseset_y $y
set i [$w curselection]
if { $i != "" } {
set drag_obj [$w get $i]
} else {
set drag_obj ""
}
return
}
if { $drag_obj != "" } {
set dx [expr $mouseset_x - $x]
set dy [expr $mouseset_y - $y]
if { [expr $dx*$dx + $dy*$dy] > 25 } {
set lbl [string trim $drag_obj "+@()"]
set dw [Dragger::make -command "BlockListDrag::seeModuleDrop $lbl"]
if {$dw != "" } {
label $dw.icon -image [gifI "$bd/module.gif"]
label $dw.label -text $lbl
pack $dw.icon $dw.label -padx 2 -pady 2 -side left
}
}
}
}
}
proc tkg_makeBlockList {w} {
labelframe $w [m iblmodule]
frame $w.pad
pack $w.pad -pady 3
frame $w.f
listbox $w.f.list -width 15 -height 1 -yscrollcommand "$w.f.sb set" -takefocus 0
scrollbar $w.f.sb -command "$w.f.list yview" -takefocus 0
# pack $w.f.lab -anchor w
pack $w.f.list $w.f.sb -side left -padx 1 -pady 1 -fill y
pack $w.f -padx 2 -pady 4 -fill y -expand 1
set cmd { continueAction GotoBlock { gat_openBox [string trim [.sbar.blklst.f.list get [.sbar.blklst.f.list curselection]] "+()"]} }
bind $w.f.list <Double-ButtonRelease-1> $cmd
bind $w.f.list <ButtonPress> { action -Unselect { tkg_undoSelections blocks }; BlockListDrag::seeB1 %W %X %Y }
bind $w.f.list <B1-Motion> { BlockListDrag::seeMotion %W %X %Y }
# helpon $w.f.lab [m ho.f.modlist]
helpon ${w}_label [m ho.f.modlist]
}
proc tkg_blockListTest {} {
button .open -text Open -command tkg_blockListTestSetup
pack .open
}
tkg_makeBlockList .sbar.blklst
pack .sbar.blklst -fill both -expand 1 -padx 3 -pady 5
#tkg_blockListTest
|