| 1 | #///////////////////////////////////////////////////////////////////////////// |
|---|
| 2 | # FILE : btreeviewplus.tcl |
|---|
| 3 | # PURPOSE : Bayes Tree View. Tree View con un menu contextual y añadidos |
|---|
| 4 | #///////////////////////////////////////////////////////////////////////////// |
|---|
| 5 | |
|---|
| 6 | #@! OBSOLETO |
|---|
| 7 | #@! Usa BLT |
|---|
| 8 | |
|---|
| 9 | package require byscommon |
|---|
| 10 | package require BLT |
|---|
| 11 | package require bfunctions |
|---|
| 12 | package require bfieldsdialog |
|---|
| 13 | |
|---|
| 14 | |
|---|
| 15 | #///////////////////////////////////////////////////////////////////////////// |
|---|
| 16 | ::snit::widget btreeviewplus { |
|---|
| 17 | # |
|---|
| 18 | # PURPOSE: Treeview con menu contextual y caracteristicas adicionales |
|---|
| 19 | # |
|---|
| 20 | #///////////////////////////////////////////////////////////////////////////// |
|---|
| 21 | # opciones especificas |
|---|
| 22 | # readonly -> componente en modo de lectura o lectura/escritura |
|---|
| 23 | # keypress -> Activa la busqueda de filas mediante la pulsacion de teclas |
|---|
| 24 | # cols -> columnas del treeview no tiene en cuenta el "valor" principal |
|---|
| 25 | # hiddencols -> columnas del treeview que no se mostraran |
|---|
| 26 | # filtercols -> columnas del treeview que por las que puede realizarse filtrado |
|---|
| 27 | # initialdir -> directorio inicial para los dialogos de lec/esc de archivos,... |
|---|
| 28 | # orientation -> orientacion para el diálogo de añadir |
|---|
| 29 | # nomenu -> Si es 1, no se mostrará el menu contextual |
|---|
| 30 | # showtitles -> muestra o no los titulos de las columnas |
|---|
| 31 | # dragable -> Habilita o Deshabilita entorno Drag and Drop entre Elementos |
|---|
| 32 | # |
|---|
| 33 | # variables |
|---|
| 34 | # treeview -> el treeview de BLT sobre el que sobrecargamos funcionalidad |
|---|
| 35 | # menu -> el menu contextual del treeview |
|---|
| 36 | # xbar -> horizontal scrollbar |
|---|
| 37 | # ybar -> vertical scrollbar |
|---|
| 38 | # afterTime -> tiempo desde que se pulso la ultima tecla |
|---|
| 39 | # listKey -> lista de teclas pulsadas |
|---|
| 40 | #///////////////////////////////////////////////////////////////////////////// |
|---|
| 41 | widgetclass Btreeviewplus |
|---|
| 42 | |
|---|
| 43 | option -readonly 0 |
|---|
| 44 | option -keypress true |
|---|
| 45 | option -colkeypress "" |
|---|
| 46 | option -cols {} |
|---|
| 47 | option -hiddencols {} |
|---|
| 48 | option -filtercols {} |
|---|
| 49 | option -initialdir {} |
|---|
| 50 | option -orientation vertical |
|---|
| 51 | option -showtitles true |
|---|
| 52 | option -nomenu 0 |
|---|
| 53 | #pedro - DragNDrop Boolean |
|---|
| 54 | option -dragable 0 |
|---|
| 55 | |
|---|
| 56 | variable _treeview |
|---|
| 57 | variable _menu |
|---|
| 58 | variable xbar |
|---|
| 59 | variable ybar |
|---|
| 60 | variable created 0 |
|---|
| 61 | |
|---|
| 62 | variable afterTime 0 |
|---|
| 63 | variable listKey {} |
|---|
| 64 | |
|---|
| 65 | delegate method * to _treeview |
|---|
| 66 | delegate option * to _treeview |
|---|
| 67 | |
|---|
| 68 | #/////////////////////////////////////////////////////////////////////////// |
|---|
| 69 | constructor {args} { |
|---|
| 70 | # |
|---|
| 71 | # PURPOSE: Constructor de un btreeviewplus. Crea una instancia de un Treeview |
|---|
| 72 | # |
|---|
| 73 | # PARAMETERS: |
|---|
| 74 | # args -> opciones |
|---|
| 75 | # |
|---|
| 76 | #/////////////////////////////////////////////////////////////////////////// |
|---|
| 77 | |
|---|
| 78 | if {0} { |
|---|
| 79 | install _treeview using ::blt::treeview $self.tv \ |
|---|
| 80 | -activeicons "" -icons {} -selectmode multiple \ |
|---|
| 81 | -selectbackground grey -selectforeground white \ |
|---|
| 82 | -highlightthickness 0 -borderwidth 1 -selectborderwidth 1 \ |
|---|
| 83 | -nofocusselectbackground gray90 -font {Arial 9} -flat no |
|---|
| 84 | } else { |
|---|
| 85 | set _treeview [::blt::treeview $win.tv \ |
|---|
| 86 | -activeicons "" -icons {} -selectmode multiple \ |
|---|
| 87 | -selectbackground grey -selectforeground white \ |
|---|
| 88 | -highlightthickness 0 -borderwidth 1 -selectborderwidth 1 \ |
|---|
| 89 | -nofocusselectbackground gray90 -font {Arial 9} -flat no] |
|---|
| 90 | } |
|---|
| 91 | |
|---|
| 92 | install _menu using menu $win.m -tearoff 0 |
|---|
| 93 | install xbar using scrollbar $win.sbh -orient horizontal \ |
|---|
| 94 | -command "$_treeview xview" |
|---|
| 95 | install ybar using scrollbar $self.sbv -orient vertical \ |
|---|
| 96 | -command "$_treeview yview" |
|---|
| 97 | |
|---|
| 98 | $_treeview style configure text -bg white |
|---|
| 99 | $_treeview column configure treeView -bg white |
|---|
| 100 | |
|---|
| 101 | $self configure -readonly [from args -readonly] |
|---|
| 102 | $self _CreateMenu |
|---|
| 103 | |
|---|
| 104 | $_treeview column configure [list BLT TreeView $_treeview] -titleborderwidth 1 |
|---|
| 105 | |
|---|
| 106 | # Apply all arguments given: |
|---|
| 107 | $self configurelist $args |
|---|
| 108 | $_treeview configure -xscrollcommand "$xbar set" |
|---|
| 109 | $_treeview configure -yscrollcommand "$ybar set" |
|---|
| 110 | |
|---|
| 111 | # bind |
|---|
| 112 | $_treeview bind all <KeyPress> +[list $self _OnKeyPress %A] |
|---|
| 113 | |
|---|
| 114 | $self configure -nomenu [from args -nomenu] |
|---|
| 115 | $self configure -filtercols [from args -filtercols] |
|---|
| 116 | |
|---|
| 117 | # packing |
|---|
| 118 | grid $_treeview -row 0 -column 0 -sticky news |
|---|
| 119 | grid $ybar -row 0 -column 1 -sticky ns |
|---|
| 120 | grid $xbar -row 1 -column 0 -sticky ew |
|---|
| 121 | grid columnconfigure $self 0 -weight 1 |
|---|
| 122 | grid rowconfigure $self 0 -weight 1 |
|---|
| 123 | |
|---|
| 124 | ::autoscroll::autoscroll $ybar |
|---|
| 125 | ::autoscroll::autoscroll $xbar |
|---|
| 126 | set created 1 |
|---|
| 127 | } |
|---|
| 128 | |
|---|
| 129 | #/////////////////////////////////////////////////////////////////////////// |
|---|
| 130 | # |
|---|
| 131 | # PURPOSE: Metodos cget y configure |
|---|
| 132 | # |
|---|
| 133 | #/////////////////////////////////////////////////////////////////////////// |
|---|
| 134 | |
|---|
| 135 | onconfigure -cols { lst } { |
|---|
| 136 | set options(-cols) $lst |
|---|
| 137 | foreach col [$self column names] { |
|---|
| 138 | $self column delete $col |
|---|
| 139 | } |
|---|
| 140 | foreach col $options(-cols) { |
|---|
| 141 | $_treeview column insert end $col -justify left |
|---|
| 142 | $_treeview column configure $col -command "$self _SortByColumn [list $col]" \ |
|---|
| 143 | -titleborderwidth 1 |
|---|
| 144 | } |
|---|
| 145 | } |
|---|
| 146 | |
|---|
| 147 | onconfigure -hiddencols { lst } { |
|---|
| 148 | set options(-hiddencols) $lst |
|---|
| 149 | foreach col [$self column names] { |
|---|
| 150 | if { "-1" eq [lsearch $options(-hiddencols) $col] } { |
|---|
| 151 | $_treeview column configure $col -hide 0 |
|---|
| 152 | } else { |
|---|
| 153 | $_treeview column configure $col -hide 1 |
|---|
| 154 | } |
|---|
| 155 | } |
|---|
| 156 | } |
|---|
| 157 | |
|---|
| 158 | onconfigure -showtitles { bool } { |
|---|
| 159 | set options(-showtitles) $bool |
|---|
| 160 | $_treeview configure -showtitles $bool |
|---|
| 161 | $_treeview show |
|---|
| 162 | } |
|---|
| 163 | |
|---|
| 164 | onconfigure -nomenu { bool } { |
|---|
| 165 | if {$bool} { |
|---|
| 166 | # no mostrar menu |
|---|
| 167 | bind $_treeview <Button-3> "" |
|---|
| 168 | } else { |
|---|
| 169 | # mostrar menu |
|---|
| 170 | bind $_treeview <Button-3> "tk_popup $_menu %X %Y" |
|---|
| 171 | } |
|---|
| 172 | } |
|---|
| 173 | |
|---|
| 174 | onconfigure -readonly { bool } { |
|---|
| 175 | if {!($created)} { |
|---|
| 176 | set options(-readonly) $bool |
|---|
| 177 | } else { |
|---|
| 178 | puts "Btreeviewplus widget error: option -readonly only can be set on\ |
|---|
| 179 | creation time" |
|---|
| 180 | } |
|---|
| 181 | } |
|---|
| 182 | |
|---|
| 183 | #pedro - DND |
|---|
| 184 | onconfigure -dragable { bool } { |
|---|
| 185 | if { $bool } { |
|---|
| 186 | package require tkdnd |
|---|
| 187 | #pedro - Create Drag n Drop Binds & Link dnd events. |
|---|
| 188 | event add <<DragAttempt>> <Button1-Motion> |
|---|
| 189 | $self bind all <<DragAttempt>> "dnd drag $_treeview" |
|---|
| 190 | dnd bindsource $_treeview text/plain "return 1" |
|---|
| 191 | dnd bindtarget $_treeview text/plain <Drop> "dnd_event $_treeview %x %y" |
|---|
| 192 | } else { |
|---|
| 193 | event delete <<DragAttempt>> |
|---|
| 194 | } |
|---|
| 195 | } |
|---|
| 196 | |
|---|
| 197 | #pedro- end |
|---|
| 198 | |
|---|
| 199 | onconfigure -filtercols { lst } { |
|---|
| 200 | set cols [$self cget -cols] |
|---|
| 201 | set hiddencols [$self cget -hiddencols] |
|---|
| 202 | if { [llength cols] && [llength hiddencols]} { |
|---|
| 203 | set filtercols {} |
|---|
| 204 | foreach col $cols { |
|---|
| 205 | if {([lsearch -exact $hiddencols $col])} { |
|---|
| 206 | lappend filtercols $col |
|---|
| 207 | } |
|---|
| 208 | } |
|---|
| 209 | set options(-filtercols) $filtercols |
|---|
| 210 | } else { |
|---|
| 211 | if { [llength cols] } { |
|---|
| 212 | set options(-filtercols) $options(-cols) |
|---|
| 213 | } |
|---|
| 214 | } |
|---|
| 215 | } |
|---|
| 216 | |
|---|
| 217 | #/////////////////////////////////////////////////////////////////////////// |
|---|
| 218 | method _CreateMenu {args} { |
|---|
| 219 | # |
|---|
| 220 | # PURPOSE: Adds menu to treeview. |
|---|
| 221 | # |
|---|
| 222 | #/////////////////////////////////////////////////////////////////////////// |
|---|
| 223 | # read option |
|---|
| 224 | $_menu add command -label [mc "Select all"] \ |
|---|
| 225 | -command "$self _SelectAll" -accelerator CTRL+E |
|---|
| 226 | $_menu add command -label [mc "Unselect all"] \ |
|---|
| 227 | -command "$self selection clearall" |
|---|
| 228 | $_menu add command -label [mc "Toggle selection"] \ |
|---|
| 229 | -command "$self _ToggleSelection" |
|---|
| 230 | # read/write option |
|---|
| 231 | if {!([$self cget -readonly])} { |
|---|
| 232 | # delete |
|---|
| 233 | $_menu add separator |
|---|
| 234 | #$_menu add command -label [mc "Insert"] \ |
|---|
| 235 | -command "$self _OpenWR" -accelerator Ins |
|---|
| 236 | $_menu add command -label [mc "Delete all"] \ |
|---|
| 237 | -command "$self clear" |
|---|
| 238 | $_menu add command -label [mc "Delete selected"] \ |
|---|
| 239 | -command "lbDeleteSelection $self" |
|---|
| 240 | } |
|---|
| 241 | # read option |
|---|
| 242 | # copy |
|---|
| 243 | $_menu add separator |
|---|
| 244 | $_menu add command -label [mc "Filter"] -command "$self _OpenFD" |
|---|
| 245 | $_menu add command -label [mc "Unfilter"] -command "$self show all" |
|---|
| 246 | $_menu add separator |
|---|
| 247 | set mc [menu $_menu.copy -tearoff 0] |
|---|
| 248 | $_menu add cascade -label [mc "Copy"] -menu $mc |
|---|
| 249 | $mc add command -label [mc "Copy all"] \ |
|---|
| 250 | -command "$self _CopyToClipBoard 1 1" |
|---|
| 251 | $mc add command -label [mc "Copy selected"] \ |
|---|
| 252 | -command "$self _CopyToClipBoard 1 0" -accelerator CTRL+C |
|---|
| 253 | $mc add command -label [mc "Copy unselect"] \ |
|---|
| 254 | -command "$self _CopyToClipBoard 0 1" |
|---|
| 255 | # count |
|---|
| 256 | $_menu add separator |
|---|
| 257 | $_menu add command -label [mc "Count elements"] \ |
|---|
| 258 | -command "$self _ShowCountItems" |
|---|
| 259 | |
|---|
| 260 | # falta el menu archivo |
|---|
| 261 | # file |
|---|
| 262 | #$_menu add separator |
|---|
| 263 | #set mf [menu $_menu.file -tearoff 0] |
|---|
| 264 | #$_menu add cascade -label [mc "File"] -menu $mf |
|---|
| 265 | #$mf add command -label "[mc "Save to file"] ..." \ |
|---|
| 266 | -command "$self _SaveToFile 1 1" |
|---|
| 267 | #if {![$self cget -readonly]} { |
|---|
| 268 | # $mf add command -label "[mc "Load form file"] ..." \ |
|---|
| 269 | -command "$self _LoadFromFile" |
|---|
| 270 | #} |
|---|
| 271 | # bindings |
|---|
| 272 | $self bind all <Control-KeyRelease> +[list $self _OnControlKey $self %K %k] |
|---|
| 273 | $self bind all <Key-Delete> "lbDeleteSelection $self" |
|---|
| 274 | $self bind all <Key-Insert> "$self _OpenWR" |
|---|
| 275 | $self bind all <Shift-Up> "$self addPrevious" |
|---|
| 276 | $self bind all <Shift-Down> "$self addNext" |
|---|
| 277 | $self bind all <Up> "$self previous" |
|---|
| 278 | $self bind all <Down> "$self next" |
|---|
| 279 | $self bind all <Home> "$self first" |
|---|
| 280 | $self bind all <End> "$self last" |
|---|
| 281 | $self bind all <Shift-Home> "$self addAllPrevious" |
|---|
| 282 | $self bind all <Shift-End> "$self addAllNext" |
|---|
| 283 | $self bind all <Button-1> +[list focus -force %W] |
|---|
| 284 | } |
|---|
| 285 | #/////////////////////////////////////////////////////////////////////////// |
|---|
| 286 | method getMenu { } { |
|---|
| 287 | # |
|---|
| 288 | # PURPOSE: Devuelve el menu del btreeviewplus para poder modificarlo y |
|---|
| 289 | # ampliarlo |
|---|
| 290 | # |
|---|
| 291 | # RETURN: La variable de instancia que apunta al menu |
|---|
| 292 | # |
|---|
| 293 | #/////////////////////////////////////////////////////////////////////////// |
|---|
| 294 | return $_menu |
|---|
| 295 | } |
|---|
| 296 | |
|---|
| 297 | |
|---|
| 298 | #/////////////////////////////////////////////////////////////////////////// |
|---|
| 299 | method _OnKeyPress {key} { |
|---|
| 300 | # |
|---|
| 301 | # PURPOSE: Activa la fila que coincide con las teclas pulsadas. Distinge |
|---|
| 302 | # entre mayúculas y minúsculas |
|---|
| 303 | # |
|---|
| 304 | # PARAMETERS: key -> tecla pulsada |
|---|
| 305 | # |
|---|
| 306 | #/////////////////////////////////////////////////////////////////////////// |
|---|
| 307 | if {[$self cget -keypress]} { |
|---|
| 308 | set diference 500 |
|---|
| 309 | set result [lbOnKeyPress $self $key $listKey $afterTime $diference \ |
|---|
| 310 | [$self cget -colkeypress]] |
|---|
| 311 | set listKey [lindex $result 0] |
|---|
| 312 | set afterTime [lindex $result 1] |
|---|
| 313 | } |
|---|
| 314 | } |
|---|
| 315 | |
|---|
| 316 | |
|---|
| 317 | #/////////////////////////////////////////////////////////////////////////// |
|---|
| 318 | method _OnControlKey {_lb keysym keycode} { |
|---|
| 319 | # |
|---|
| 320 | # PURPOSE: Controla es uso de teclas rápidas para le ejecución de funciones |
|---|
| 321 | # |
|---|
| 322 | # PARAMETERS: _lb -> self |
|---|
| 323 | # keysym -> The keysym corresponding to the event, |
|---|
| 324 | # substituted as a textual string |
|---|
| 325 | # keycode -> The keycode field from the event |
|---|
| 326 | # |
|---|
| 327 | #/////////////////////////////////////////////////////////////////////////// |
|---|
| 328 | switch [string toupper $keysym] { |
|---|
| 329 | E { $_lb _SelectAll } |
|---|
| 330 | C { lbToClipBoard $_lb 1 0 } |
|---|
| 331 | } |
|---|
| 332 | } |
|---|
| 333 | |
|---|
| 334 | #/////////////////////////////////////////////////////////////////////////// |
|---|
| 335 | method _ShowCountItems {} { |
|---|
| 336 | # |
|---|
| 337 | # PURPOSE: Shows information on the selection of the elements |
|---|
| 338 | # |
|---|
| 339 | #/////////////////////////////////////////////////////////////////////////// |
|---|
| 340 | set info [lbCountItems $self] |
|---|
| 341 | set msg "[mc "Total"]: [lindex $info 0] \n\ |
|---|
| 342 | [mc "Selected"]: [lindex $info 1] \n\ |
|---|
| 343 | [mc "Not Selected"]: [lindex $info 2]" |
|---|
| 344 | tk_messageBox -default ok \ |
|---|
| 345 | -icon info \ |
|---|
| 346 | -message $msg \ |
|---|
| 347 | -type ok \ |
|---|
| 348 | -parent $self \ |
|---|
| 349 | -title [mc "numero de elementos"] |
|---|
| 350 | } |
|---|
| 351 | |
|---|
| 352 | |
|---|
| 353 | #///////////////////////////////////////////////////////////////////////////// |
|---|
| 354 | method _ToggleSelection {} { |
|---|
| 355 | # |
|---|
| 356 | # PURPOSE: Toggle selection elements |
|---|
| 357 | # |
|---|
| 358 | #///////////////////////////////////////////////////////////////////////////// |
|---|
| 359 | foreach i [$self get] { |
|---|
| 360 | $self selection toggle $i |
|---|
| 361 | } |
|---|
| 362 | } |
|---|
| 363 | |
|---|
| 364 | |
|---|
| 365 | #/////////////////////////////////////////////////////////////////////////// |
|---|
| 366 | method _SelectAll { } { |
|---|
| 367 | # |
|---|
| 368 | # PURPOSE: Selection all |
|---|
| 369 | # |
|---|
| 370 | #/////////////////////////////////////////////////////////////////////////// |
|---|
| 371 | foreach i [$self get] { |
|---|
| 372 | $self selection set $i |
|---|
| 373 | } |
|---|
| 374 | } |
|---|
| 375 | |
|---|
| 376 | |
|---|
| 377 | #///////////////////////////////////////////////////////////////////////////// |
|---|
| 378 | method _CopyToClipBoard { sl unSe {pref ""} {suf ""} {sep "\n"}} { |
|---|
| 379 | # |
|---|
| 380 | # PURPOSE: copy the elements indicates in clipboard |
|---|
| 381 | # |
|---|
| 382 | # PARAMETERS: |
|---|
| 383 | # sl -> Copy items selections |
|---|
| 384 | # unSe -> Copy items not selections |
|---|
| 385 | # pref -> Text to concatenate in the beginning. Default "" |
|---|
| 386 | # suf -> Text to concatenate in the end. Default "" |
|---|
| 387 | # sep -> Separating text of elements. Default "\n" |
|---|
| 388 | # |
|---|
| 389 | #///////////////////////////////////////////////////////////////////////////// |
|---|
| 390 | # items to copy |
|---|
| 391 | set lst {} |
|---|
| 392 | if { $sl } { |
|---|
| 393 | foreach i [$self curselection] { |
|---|
| 394 | lappend lst [$self get $i] |
|---|
| 395 | } |
|---|
| 396 | } |
|---|
| 397 | if { $unSe } { |
|---|
| 398 | foreach i [$self selection get unselected] { |
|---|
| 399 | lappend lst [$self get $i] |
|---|
| 400 | } |
|---|
| 401 | } |
|---|
| 402 | # copy |
|---|
| 403 | set str [ListToStr $lst $sep $pref $suf] |
|---|
| 404 | clipboard clear |
|---|
| 405 | clipboard append $str |
|---|
| 406 | } |
|---|
| 407 | |
|---|
| 408 | |
|---|
| 409 | #///////////////////////////////////////////////////////////////////////////// |
|---|
| 410 | method _SaveToFile {se unSe {pref ""} {suf ""} {sep "\n"}} { |
|---|
| 411 | # |
|---|
| 412 | # PURPOSE: Save the content from treeview in a file |
|---|
| 413 | # |
|---|
| 414 | # PARAMETERS: |
|---|
| 415 | # sl -> Copy items selections |
|---|
| 416 | # unSe -> Copy items not selections |
|---|
| 417 | # pref -> Text to concatenate in the beginning. Default "" |
|---|
| 418 | # suf -> Text to concatenate in the end. Default "" |
|---|
| 419 | # sep -> Separating text of elements. Default "\n" |
|---|
| 420 | # |
|---|
| 421 | #///////////////////////////////////////////////////////////////////////////// |
|---|
| 422 | # select file |
|---|
| 423 | |
|---|
| 424 | set filNam [tk_getSaveFile -parent $self -title [mc "File selector"] \ |
|---|
| 425 | -initialdir $options(-initialdir)] |
|---|
| 426 | if {$filNam != ""} { |
|---|
| 427 | # open file to write |
|---|
| 428 | if { ![ catch { set fd [open $filNam w] } msgerr] } { |
|---|
| 429 | # text to save |
|---|
| 430 | set lst {} |
|---|
| 431 | if { $se } { |
|---|
| 432 | foreach i [$self selection get selected] { |
|---|
| 433 | lappend lst [$self get $i] |
|---|
| 434 | } |
|---|
| 435 | } |
|---|
| 436 | if { $unSe } { |
|---|
| 437 | foreach i [$self selection get unselected] { |
|---|
| 438 | lappend lst [$self get $i] |
|---|
| 439 | } |
|---|
| 440 | } |
|---|
| 441 | set str [ListToStr $lst $sep $pref $suf] |
|---|
| 442 | # write |
|---|
| 443 | puts -nonewline $fd $str |
|---|
| 444 | close $fd |
|---|
| 445 | return 1 |
|---|
| 446 | } |
|---|
| 447 | error $msgerr |
|---|
| 448 | } |
|---|
| 449 | } |
|---|
| 450 | |
|---|
| 451 | |
|---|
| 452 | |
|---|
| 453 | #///////////////////////////////////////////////////////////////////////////// |
|---|
| 454 | method _LoadFromFile { } { |
|---|
| 455 | # |
|---|
| 456 | # PURPOSE: Load the content from treeview in a file |
|---|
| 457 | # |
|---|
| 458 | #///////////////////////////////////////////////////////////////////////////// |
|---|
| 459 | # select file |
|---|
| 460 | set filNam [tk_getOpenFile -parent $self -title [mc "File selector"] \ |
|---|
| 461 | -initialdir $options(-initialdir)] |
|---|
| 462 | if {$filNam != ""} { |
|---|
| 463 | # open file to read |
|---|
| 464 | if { ![ catch { set fd [open $filNam r] } msgerr] } { |
|---|
| 465 | while { [gets $fd line ] >= 0} { |
|---|
| 466 | $self add $line |
|---|
| 467 | } |
|---|
| 468 | close $fd |
|---|
| 469 | return 1 |
|---|
| 470 | } |
|---|
| 471 | error $msgerr |
|---|
| 472 | } |
|---|
| 473 | } |
|---|
| 474 | |
|---|
| 475 | |
|---|
| 476 | #/////////////////////////////////////////////////////////////////////////// |
|---|
| 477 | method _SortByColumn { col } { |
|---|
| 478 | # |
|---|
| 479 | # PURPOSE: Sorts the ListBox by the values of the given column |
|---|
| 480 | # |
|---|
| 481 | # PARAMETERS: |
|---|
| 482 | # col -> the column which the sort is performed |
|---|
| 483 | # |
|---|
| 484 | #/////////////////////////////////////////////////////////////////////////// |
|---|
| 485 | set lst [$self get] |
|---|
| 486 | set len [$self size] |
|---|
| 487 | for { set i [expr $len - 1] } { $i > 0 } { incr i -1 } { |
|---|
| 488 | for { set j 0 } { $j < $i } { incr j } { |
|---|
| 489 | set ida [lindex [$self get] $j] |
|---|
| 490 | set idb [lindex [$self get] [expr $j + 1]] |
|---|
| 491 | set a [$self get $ida $col] |
|---|
| 492 | set b [$self get $idb $col] |
|---|
| 493 | if { $a > $b } { $self move $ida after $idb } |
|---|
| 494 | } |
|---|
| 495 | } |
|---|
| 496 | } |
|---|
| 497 | |
|---|
| 498 | |
|---|
| 499 | #/////////////////////////////////////////////////////////////////////////// |
|---|
| 500 | proc _AddWR { elem father } { |
|---|
| 501 | # |
|---|
| 502 | # PURPOSE: adds the item introduced in the dialog to the selected list |
|---|
| 503 | # |
|---|
| 504 | # PARAMETERS: |
|---|
| 505 | # elem -> the element to insert from the add dialog |
|---|
| 506 | # father -> The dialog's window pathname |
|---|
| 507 | # |
|---|
| 508 | #/////////////////////////////////////////////////////////////////////////// |
|---|
| 509 | eval $father insert 0 $elem |
|---|
| 510 | } |
|---|
| 511 | |
|---|
| 512 | |
|---|
| 513 | #////////////////////////////////////////////////////////////////////////// |
|---|
| 514 | method _OpenWR {} { |
|---|
| 515 | # |
|---|
| 516 | # PURPOSE: Calls (and creates) an add dialog for insert by hand elements |
|---|
| 517 | # |
|---|
| 518 | #/////////////////////////////////////////////////////////////////////////// |
|---|
| 519 | |
|---|
| 520 | destroy $self.dw |
|---|
| 521 | set dialog [bfieldsdialog $self.dw -title [mc "Insert element"] \ |
|---|
| 522 | -parent $self -orientation $options(-orientation) \ |
|---|
| 523 | -fields $options(-cols) -procedure [codename _AddWR] \ |
|---|
| 524 | -buttons { add exit }] |
|---|
| 525 | |
|---|
| 526 | $dialog draw |
|---|
| 527 | } |
|---|
| 528 | |
|---|
| 529 | |
|---|
| 530 | #/////////////////////////////////////////////////////////////////////////// |
|---|
| 531 | proc _Filter { elem father } { |
|---|
| 532 | # |
|---|
| 533 | # PURPOSE: Filters the treeview with the filter suministred |
|---|
| 534 | # |
|---|
| 535 | # PARAMETERS: |
|---|
| 536 | # elem -> the list with the filter fields |
|---|
| 537 | # father -> The dialog's window pathname |
|---|
| 538 | # |
|---|
| 539 | #/////////////////////////////////////////////////////////////////////////// |
|---|
| 540 | eval $father filter $elem |
|---|
| 541 | } |
|---|
| 542 | |
|---|
| 543 | |
|---|
| 544 | #////////////////////////////////////////////////////////////////////////// |
|---|
| 545 | method _OpenFD {} { |
|---|
| 546 | # |
|---|
| 547 | # PURPOSE: Calls (and creates) a add dialog for getting a filter |
|---|
| 548 | # |
|---|
| 549 | #/////////////////////////////////////////////////////////////////////////// |
|---|
| 550 | |
|---|
| 551 | destroy $self.fd |
|---|
| 552 | set dialog [bfieldsdialog $self.fd -title [mc "Filter elements"] \ |
|---|
| 553 | -parent $self -orientation $options(-orientation) \ |
|---|
| 554 | -fields $options(-filtercols) -procedure [codename _Filter] \ |
|---|
| 555 | -buttons { info apply accept cancel }] |
|---|
| 556 | $dialog configure -info \ |
|---|
| 557 | "Los filtros admiten expresiones regulares: |
|---|
| 558 | |
|---|
| 559 | expresiones regulares básicas: |
|---|
| 560 | - literales: caracteres simples |
|---|
| 561 | - brackets: conincide con cualquier caracter especificado dentro |
|---|
| 562 | tambien pueden expecificarse rangos pe \[a-d\] equivale a \[abcd\] |
|---|
| 563 | o indicar la no coincidencia colocando como primer caracter ^ |
|---|
| 564 | rangos predefinidos: |
|---|
| 565 | \[:alnum:\] equivale a \[0-9a-zA-Z\] |
|---|
| 566 | \[:alpha:\] equivale a \[a-zA-Z\] |
|---|
| 567 | \[:digit:\] equivale a \[0-9\] |
|---|
| 568 | \\w equivale a \[:alnum:\] |
|---|
| 569 | \\W equivale a \[^:alnum:\] |
|---|
| 570 | para incluir el literal - ponerlo al final del braquet |
|---|
| 571 | para incluir el literal ^ ponerlo en cualquier lugar menos el primero |
|---|
| 572 | - punto . : coincide con cualquier caracter simple |
|---|
| 573 | - ^ y $ : coinciden respectivamente con el principio o final de linea |
|---|
| 574 | - caracteres especiales: los caracteres que tienen significado en las |
|---|
| 575 | expresiones regulares pueden escribirse precediendolos con \\ |
|---|
| 576 | |
|---|
| 577 | operadores sobre las expresiones: |
|---|
| 578 | - <e1><e2>: concatenacion, la expresion resultante coincide si coinciden |
|---|
| 579 | secuencialmente las expresiones |
|---|
| 580 | - <e1>|<e2> : disyuncion, coincide si coincide alguna de las expresiones |
|---|
| 581 | - <e>? : opcionalidad, coincide si la expresion anterior coincide 0 o 1 vez |
|---|
| 582 | - <e>* : repeticion, coincide si la expresion anterior coincide 0 o mas veces |
|---|
| 583 | - <e>+ : repeticion, coincide si la expresion anterior coincide 1 o mas veces |
|---|
| 584 | - <e>{n} : repeticion, coincide si la expresion anterior coincide n veces |
|---|
| 585 | - <e>{n,} : repeticion, coincide si la exp anterior coincide n o mas veces |
|---|
| 586 | - <e>{n,m} : repeticion, coincide si la exp anterior coincide por lo menos n |
|---|
| 587 | y no mas de m veces |
|---|
| 588 | |
|---|
| 589 | precedencia de los operadores: |
|---|
| 590 | - los operadores de repeticion tienen preferencia sobre la concatenacion |
|---|
| 591 | - la concatenacion tiene preferencia sobre la disyuncion |
|---|
| 592 | - las reglas pueden alterarse con el uso de parentesis |
|---|
| 593 | " |
|---|
| 594 | |
|---|
| 595 | $dialog draw |
|---|
| 596 | } |
|---|
| 597 | |
|---|
| 598 | |
|---|
| 599 | #/////////////////////////////////////////////////////////////////////////// |
|---|
| 600 | method selection { args } { |
|---|
| 601 | # |
|---|
| 602 | # PURPOSE: extends the original command to extend capabilities |
|---|
| 603 | # |
|---|
| 604 | # PARAMETERS: |
|---|
| 605 | # args: arguments |
|---|
| 606 | # |
|---|
| 607 | #/////////////////////////////////////////////////////////////////////////// |
|---|
| 608 | if { [lindex $args 0] eq "get" } { |
|---|
| 609 | if { [lindex $args 1] eq "unselected" } { |
|---|
| 610 | set result {} |
|---|
| 611 | set selected [$self curselection] |
|---|
| 612 | foreach i [$self get] { |
|---|
| 613 | if { "-1" eq [lsearch $selected $i] } { |
|---|
| 614 | lappend result $i |
|---|
| 615 | } |
|---|
| 616 | } |
|---|
| 617 | return $result |
|---|
| 618 | } else { |
|---|
| 619 | return [eval $_treeview curselection] |
|---|
| 620 | } |
|---|
| 621 | } |
|---|
| 622 | |
|---|
| 623 | eval $_treeview selection $args |
|---|
| 624 | } |
|---|
| 625 | |
|---|
| 626 | #/////////////////////////////////////////////////////////////////////////// |
|---|
| 627 | method insert { args } { |
|---|
| 628 | # |
|---|
| 629 | # PURPOSE: inserts an element into the treeview |
|---|
| 630 | # |
|---|
| 631 | # PARAMETERS: |
|---|
| 632 | # args: [-at node] position value list_data_values |
|---|
| 633 | # the list_data_values must be provided in order |
|---|
| 634 | # dragable: make the elements dragable between them. |
|---|
| 635 | # |
|---|
| 636 | #/////////////////////////////////////////////////////////////////////////// |
|---|
| 637 | set index 0 |
|---|
| 638 | set father "" |
|---|
| 639 | |
|---|
| 640 | if { [lindex $args $index] eq "-at" } { |
|---|
| 641 | incr index |
|---|
| 642 | set father [lindex $args $index] |
|---|
| 643 | incr index |
|---|
| 644 | } |
|---|
| 645 | |
|---|
| 646 | set pos [lindex $args $index] |
|---|
| 647 | incr index |
|---|
| 648 | |
|---|
| 649 | set value [lindex $args $index] |
|---|
| 650 | incr index |
|---|
| 651 | |
|---|
| 652 | set dats [lrange $args $index end] |
|---|
| 653 | if { [llength $dats] == 1 } { set dats [lindex $dats 0] } |
|---|
| 654 | set datos {} |
|---|
| 655 | set i 0 |
|---|
| 656 | |
|---|
| 657 | foreach col $options(-cols) { |
|---|
| 658 | lappend datos $col [lindex $dats $i] |
|---|
| 659 | incr i |
|---|
| 660 | } |
|---|
| 661 | |
|---|
| 662 | if { $father == "" } { |
|---|
| 663 | if { $datos == {} } { |
|---|
| 664 | set node [$_treeview insert $pos $value] |
|---|
| 665 | } else { |
|---|
| 666 | set node [$_treeview insert $pos $value -data $datos] |
|---|
| 667 | } |
|---|
| 668 | } else { |
|---|
| 669 | if { $datos == {} } { |
|---|
| 670 | set node [$_treeview insert -at $father $pos $value] |
|---|
| 671 | } else { |
|---|
| 672 | set node [$_treeview insert -at $father $pos $value -data $datos] |
|---|
| 673 | } |
|---|
| 674 | } |
|---|
| 675 | |
|---|
| 676 | } |
|---|
| 677 | |
|---|
| 678 | #/////////////////////////////////////////////////////////////////////////// |
|---|
| 679 | method delete { args } { |
|---|
| 680 | # |
|---|
| 681 | # PURPOSE: deletes elements from the treeview |
|---|
| 682 | # |
|---|
| 683 | # PARAMETERS: |
|---|
| 684 | # args: the tags or ids of the items to be deleted |
|---|
| 685 | # |
|---|
| 686 | #/////////////////////////////////////////////////////////////////////////// |
|---|
| 687 | # OJO un delete sobre un arbol vacio puede provocar un crash, es |
|---|
| 688 | # un bug en BLT!!! |
|---|
| 689 | eval $_treeview delete $args |
|---|
| 690 | #if { "-1" eq [lsearch $args 0] } { |
|---|
| 691 | # eval $_treeview delete $args |
|---|
| 692 | #} else { |
|---|
| 693 | # puts "Root node can't be deleted" |
|---|
| 694 | #} |
|---|
| 695 | } |
|---|
| 696 | |
|---|
| 697 | |
|---|
| 698 | #/////////////////////////////////////////////////////////////////////////// |
|---|
| 699 | method get { {id ""} {cols ""}} { |
|---|
| 700 | # |
|---|
| 701 | # PURPOSE: retrieves data from an entry identified by id |
|---|
| 702 | # |
|---|
| 703 | # PARAMETERS: |
|---|
| 704 | # id: id of the node |
|---|
| 705 | # cols: name of the cols from which retrieve data |
|---|
| 706 | # |
|---|
| 707 | #/////////////////////////////////////////////////////////////////////////// |
|---|
| 708 | if { $id eq "" } { return [lrange [$self find] 1 end] } |
|---|
| 709 | |
|---|
| 710 | set result {} |
|---|
| 711 | set data [$_treeview entry cget $id -data] |
|---|
| 712 | |
|---|
| 713 | if { "$cols" eq "" } { |
|---|
| 714 | set cols [$self column names] |
|---|
| 715 | } |
|---|
| 716 | |
|---|
| 717 | foreach col $cols { |
|---|
| 718 | set inx [lsearch $data $col] |
|---|
| 719 | if { "-1" ne $inx } { |
|---|
| 720 | incr inx |
|---|
| 721 | lappend result [lindex $data $inx] |
|---|
| 722 | } |
|---|
| 723 | } |
|---|
| 724 | return $result |
|---|
| 725 | } |
|---|
| 726 | |
|---|
| 727 | |
|---|
| 728 | #/////////////////////////////////////////////////////////////////////////// |
|---|
| 729 | method getName { args } { |
|---|
| 730 | # |
|---|
| 731 | # PURPOSE: retrieves name from an entry identified by id or its parent name |
|---|
| 732 | # |
|---|
| 733 | # PARAMETERS: |
|---|
| 734 | # id: id of the node |
|---|
| 735 | # |
|---|
| 736 | #/////////////////////////////////////////////////////////////////////////// |
|---|
| 737 | set id [lindex $args 0] |
|---|
| 738 | if { [llength $args] == 2 } { set id [lindex $args 1] } |
|---|
| 739 | |
|---|
| 740 | set result [$_treeview get -full $id] |
|---|
| 741 | set index [expr [llength $result] - 2] |
|---|
| 742 | |
|---|
| 743 | if { [lindex $args 0] eq "-parent" } { |
|---|
| 744 | return [lindex $result $index] |
|---|
| 745 | } |
|---|
| 746 | |
|---|
| 747 | if { [lindex $args 0] eq "-full" } { |
|---|
| 748 | return $result |
|---|
| 749 | } |
|---|
| 750 | |
|---|
| 751 | return [lindex [$_treeview get -full $id] end] |
|---|
| 752 | } |
|---|
| 753 | |
|---|
| 754 | #/////////////////////////////////////////////////////////////////////////// |
|---|
| 755 | method getId { args } { |
|---|
| 756 | # |
|---|
| 757 | # PURPOSE: retrieves id from an entry by a name pattern |
|---|
| 758 | # |
|---|
| 759 | # PARAMETERS: |
|---|
| 760 | # name: name of the node |
|---|
| 761 | # |
|---|
| 762 | # RETURN: Id of the node |
|---|
| 763 | # |
|---|
| 764 | #/////////////////////////////////////////////////////////////////////////// |
|---|
| 765 | set name [lindex $args 0] |
|---|
| 766 | if { [llength $args] == 2 } { |
|---|
| 767 | set name [lindex $args 1] |
|---|
| 768 | } |
|---|
| 769 | set result [$_treeview find -name $name] |
|---|
| 770 | return $result |
|---|
| 771 | } |
|---|
| 772 | |
|---|
| 773 | |
|---|
| 774 | #/////////////////////////////////////////////////////////////////////////// |
|---|
| 775 | method set { id data {cols ""}} { |
|---|
| 776 | # |
|---|
| 777 | # PURPOSE: changes data for an entry identified by id |
|---|
| 778 | # |
|---|
| 779 | # PARAMETERS: |
|---|
| 780 | # id: id of the node |
|---|
| 781 | # data: data to insert |
|---|
| 782 | # cols: name of the cols for which we are providing data |
|---|
| 783 | # |
|---|
| 784 | #/////////////////////////////////////////////////////////////////////////// |
|---|
| 785 | if { "$cols" eq "" } { |
|---|
| 786 | set cols [$self column names] |
|---|
| 787 | } |
|---|
| 788 | set datos {} |
|---|
| 789 | set i 0 |
|---|
| 790 | foreach col $cols { |
|---|
| 791 | lappend datos $col |
|---|
| 792 | lappend datos [lindex $data $i] |
|---|
| 793 | incr i |
|---|
| 794 | } |
|---|
| 795 | return [$_treeview entry configure $id -data $datos] |
|---|
| 796 | } |
|---|
| 797 | |
|---|
| 798 | |
|---|
| 799 | #/////////////////////////////////////////////////////////////////////////// |
|---|
| 800 | method first {} { |
|---|
| 801 | # |
|---|
| 802 | # PURPOSE: Selects and returns the first row of btreeviewplus |
|---|
| 803 | # |
|---|
| 804 | # RETURN: The index of first row |
|---|
| 805 | # |
|---|
| 806 | #/////////////////////////////////////////////////////////////////////////// |
|---|
| 807 | set all [$self get] |
|---|
| 808 | set selected [$self selection get] |
|---|
| 809 | if {$selected != ""} { |
|---|
| 810 | foreach item $selected { |
|---|
| 811 | $self selection clear $item |
|---|
| 812 | } |
|---|
| 813 | } |
|---|
| 814 | $self selection set [lindex $all 0] |
|---|
| 815 | return [lindex $all 0] |
|---|
| 816 | } |
|---|
| 817 | |
|---|
| 818 | |
|---|
| 819 | #/////////////////////////////////////////////////////////////////////////// |
|---|
| 820 | method last {} { |
|---|
| 821 | # |
|---|
| 822 | # PURPOSE: Selects and returns the last row of btreeviewplus |
|---|
| 823 | # |
|---|
| 824 | # RETURN: The index of last row |
|---|
| 825 | # |
|---|
| 826 | #/////////////////////////////////////////////////////////////////////////// |
|---|
| 827 | set all [$self get] |
|---|
| 828 | set selected [$self selection get] |
|---|
| 829 | if {$selected != ""} { |
|---|
| 830 | foreach item $selected { |
|---|
| 831 | $self selection clear $item |
|---|
| 832 | } |
|---|
| 833 | } |
|---|
| 834 | $self selection set [lindex $all [expr [llength $all] - 1]] |
|---|
| 835 | return [lindex $all [expr [llength $all] - 1]] |
|---|
| 836 | } |
|---|
| 837 | |
|---|
| 838 | |
|---|
| 839 | #/////////////////////////////////////////////////////////////////////////// |
|---|
| 840 | method addPrevious {} { |
|---|
| 841 | # |
|---|
| 842 | # PURPOSE: adds the row previous to the present selection |
|---|
| 843 | # |
|---|
| 844 | # RETURN: The index of the row previous |
|---|
| 845 | # |
|---|
| 846 | #/////////////////////////////////////////////////////////////////////////// |
|---|
| 847 | set all [$self get] |
|---|
| 848 | set selected [$self selection get] |
|---|
| 849 | if {$selected == ""} { |
|---|
| 850 | return -1 |
|---|
| 851 | } else { |
|---|
| 852 | set firstSelected [lindex $selected 0] |
|---|
| 853 | set first [lindex $all 0] |
|---|
| 854 | if { $first == $firstSelected } { |
|---|
| 855 | return [lindex $all 0] |
|---|
| 856 | } else { |
|---|
| 857 | set allPosition [lsearch -exact $all $firstSelected] |
|---|
| 858 | set firstSelected [lindex $all [expr $allPosition - 1]] |
|---|
| 859 | #set firstSelected [expr $firstSelected - 1] |
|---|
| 860 | $self selection set $firstSelected |
|---|
| 861 | return $firstSelected |
|---|
| 862 | } |
|---|
| 863 | } |
|---|
| 864 | } |
|---|
| 865 | |
|---|
| 866 | |
|---|
| 867 | #/////////////////////////////////////////////////////////////////////////// |
|---|
| 868 | method addNext {} { |
|---|
| 869 | # |
|---|
| 870 | # PURPOSE: Adds the following row to the present selection |
|---|
| 871 | # |
|---|
| 872 | # RETURN: The index of the following row |
|---|
| 873 | # |
|---|
| 874 | #/////////////////////////////////////////////////////////////////////////// |
|---|
| 875 | set all [$self get] |
|---|
| 876 | set selected [$self selection get] |
|---|
| 877 | if {$selected == ""} { |
|---|
| 878 | return -1 |
|---|
| 879 | } else { |
|---|
| 880 | set lastSelected [lindex $selected [expr [llength $selected] - 1] ] |
|---|
| 881 | set last [lindex $all [expr [llength $all] - 1]] |
|---|
| 882 | if { $last == $lastSelected } { |
|---|
| 883 | return [lindex $all [expr [llength $all] - 1]] |
|---|
| 884 | } else { |
|---|
| 885 | set allPosition [lsearch -exact $all $lastSelected] |
|---|
| 886 | set lastSelected [lindex $all [expr $allPosition + 1]] |
|---|
| 887 | $self selection set $lastSelected |
|---|
| 888 | return $lastSelected |
|---|
| 889 | } |
|---|
| 890 | } |
|---|
| 891 | } |
|---|
| 892 | |
|---|
| 893 | |
|---|
| 894 | #/////////////////////////////////////////////////////////////////////////// |
|---|
| 895 | method previous {} { |
|---|
| 896 | # |
|---|
| 897 | # PURPOSE: selects the row previous to the present selection |
|---|
| 898 | # |
|---|
| 899 | # RETURN: The index of the row previous |
|---|
| 900 | # |
|---|
| 901 | #/////////////////////////////////////////////////////////////////////////// |
|---|
| 902 | set all [$self get] |
|---|
| 903 | set selected [$self selection get] |
|---|
| 904 | if {$selected == ""} { |
|---|
| 905 | return -1 |
|---|
| 906 | } else { |
|---|
| 907 | foreach item $selected { |
|---|
| 908 | $self selection clear $item |
|---|
| 909 | } |
|---|
| 910 | set firstSelected [lindex $selected 0] |
|---|
| 911 | set first [lindex $all 0] |
|---|
| 912 | if { $first == $firstSelected } { |
|---|
| 913 | $self selection set $firstSelected |
|---|
| 914 | return [lindex $all 0] |
|---|
| 915 | } else { |
|---|
| 916 | set allPosition [lsearch -exact $all $firstSelected] |
|---|
| 917 | set firstSelected [lindex $all [expr $allPosition - 1]] |
|---|
| 918 | $self selection set $firstSelected |
|---|
| 919 | return $firstSelected |
|---|
| 920 | } |
|---|
| 921 | } |
|---|
| 922 | } |
|---|
| 923 | |
|---|
| 924 | |
|---|
| 925 | #/////////////////////////////////////////////////////////////////////////// |
|---|
| 926 | method next {} { |
|---|
| 927 | # |
|---|
| 928 | # PURPOSE: selects the following row to the present selection |
|---|
| 929 | # |
|---|
| 930 | # RETURN: The index of the following row |
|---|
| 931 | # |
|---|
| 932 | #/////////////////////////////////////////////////////////////////////////// |
|---|
| 933 | set all [$self get] |
|---|
| 934 | set selected [$self selection get] |
|---|
| 935 | if {$selected == ""} { |
|---|
| 936 | return -1 |
|---|
| 937 | } else { |
|---|
| 938 | foreach item $selected { |
|---|
| 939 | $self selection clear $item |
|---|
| 940 | } |
|---|
| 941 | set lastSelected [lindex $selected [expr [llength $selected] - 1] ] |
|---|
| 942 | set last [lindex $all [expr [llength $all] - 1]] |
|---|
| 943 | if { $last == $lastSelected } { |
|---|
| 944 | $self selection set $lastSelected |
|---|
| 945 | return [lindex $all [expr [llength $all] - 1]] |
|---|
| 946 | } else { |
|---|
| 947 | set allPosition [lsearch -exact $all $lastSelected] |
|---|
| 948 | set lastSelected [lindex $all [expr $allPosition + 1]] |
|---|
| 949 | $self selection set $lastSelected |
|---|
| 950 | return $lastSelected |
|---|
| 951 | } |
|---|
| 952 | } |
|---|
| 953 | } |
|---|
| 954 | |
|---|
| 955 | |
|---|
| 956 | #/////////////////////////////////////////////////////////////////////////// |
|---|
| 957 | method addAllPrevious {} { |
|---|
| 958 | # |
|---|
| 959 | # PURPOSE: Selects all the previous rows |
|---|
| 960 | # |
|---|
| 961 | # RETURN: The index of the first row |
|---|
| 962 | # |
|---|
| 963 | #/////////////////////////////////////////////////////////////////////////// |
|---|
| 964 | set all [$self get] |
|---|
| 965 | set selected [$self selection get] |
|---|
| 966 | if {$selected == ""} { |
|---|
| 967 | return -1 |
|---|
| 968 | } else { |
|---|
| 969 | set firstSelected [lindex $selected 0] |
|---|
| 970 | set first [lindex $all 0] |
|---|
| 971 | set allPosition [lsearch -exact $all $firstSelected] |
|---|
| 972 | while { $allPosition != 0 } { |
|---|
| 973 | $self addPrevious |
|---|
| 974 | #$self selection set $firstSelected |
|---|
| 975 | set selected [$self selection get] |
|---|
| 976 | set allPosition [lsearch -exact $all $firstSelected] |
|---|
| 977 | if { $allPosition != 0 } { |
|---|
| 978 | set firstSelected [lindex $all [expr $allPosition - 1]] |
|---|
| 979 | } |
|---|
| 980 | } |
|---|
| 981 | return [lindex $firstSelected] |
|---|
| 982 | } |
|---|
| 983 | } |
|---|
| 984 | |
|---|
| 985 | |
|---|
| 986 | #/////////////////////////////////////////////////////////////////////////// |
|---|
| 987 | method addAllNext {} { |
|---|
| 988 | # |
|---|
| 989 | # PURPOSE: Selects all the following rows |
|---|
| 990 | # |
|---|
| 991 | # RETURN: The index of the last row |
|---|
| 992 | # |
|---|
| 993 | #/////////////////////////////////////////////////////////////////////////// |
|---|
| 994 | set all [$self get] |
|---|
| 995 | set selected [$self selection get] |
|---|
| 996 | if {$selected == ""} { |
|---|
| 997 | return -1 |
|---|
| 998 | } else { |
|---|
| 999 | set lastSelected [lindex $selected [expr [llength $selected] - 1] ] |
|---|
| 1000 | set last [lindex $all [expr [llength $all] - 1]] |
|---|
| 1001 | set allPosition [lsearch -exact $all $lastSelected] |
|---|
| 1002 | while {$allPosition != [expr [llength $all] -1]} { |
|---|
| 1003 | $self addNext |
|---|
| 1004 | set selected [$self selection get] |
|---|
| 1005 | set lastSelected [lindex $selected [expr [llength $selected] - 1] ] |
|---|
| 1006 | set allPosition [lsearch -exact $all $lastSelected] |
|---|
| 1007 | } |
|---|
| 1008 | return $lastSelected |
|---|
| 1009 | } |
|---|
| 1010 | } |
|---|
| 1011 | |
|---|
| 1012 | |
|---|
| 1013 | #/////////////////////////////////////////////////////////////////////////// |
|---|
| 1014 | method clear {} { |
|---|
| 1015 | # |
|---|
| 1016 | # PURPOSE: deletes all nodes |
|---|
| 1017 | # |
|---|
| 1018 | #/////////////////////////////////////////////////////////////////////////// |
|---|
| 1019 | #foreach i [$self get] { |
|---|
| 1020 | # if { 0 eq $i } { continue } |
|---|
| 1021 | # $self delete $i |
|---|
| 1022 | #} |
|---|
| 1023 | $self delete 0 |
|---|
| 1024 | } |
|---|
| 1025 | |
|---|
| 1026 | |
|---|
| 1027 | #/////////////////////////////////////////////////////////////////////////// |
|---|
| 1028 | method size {} { |
|---|
| 1029 | # |
|---|
| 1030 | # PURPOSE: calculates the treeview size |
|---|
| 1031 | # |
|---|
| 1032 | #/////////////////////////////////////////////////////////////////////////// |
|---|
| 1033 | return [llength [$self get]] |
|---|
| 1034 | } |
|---|
| 1035 | |
|---|
| 1036 | |
|---|
| 1037 | #/////////////////////////////////////////////////////////////////////////// |
|---|
| 1038 | method column { args } { |
|---|
| 1039 | # |
|---|
| 1040 | # PURPOSE: modifies a particular case of column -> column names |
|---|
| 1041 | # |
|---|
| 1042 | #/////////////////////////////////////////////////////////////////////////// |
|---|
| 1043 | if { [lindex $args 0] eq "names" } { |
|---|
| 1044 | return [lrange [$_treeview column names] 1 end] |
|---|
| 1045 | } |
|---|
| 1046 | return [eval $_treeview column $args] |
|---|
| 1047 | } |
|---|
| 1048 | |
|---|
| 1049 | |
|---|
| 1050 | #/////////////////////////////////////////////////////////////////////////// |
|---|
| 1051 | method filter { filters } { |
|---|
| 1052 | # |
|---|
| 1053 | # PURPOSE: filters the treeview elements matching filters for each col in cols |
|---|
| 1054 | # |
|---|
| 1055 | # PARAMETERS: |
|---|
| 1056 | # filters: list of filters for the columns above |
|---|
| 1057 | # |
|---|
| 1058 | #/////////////////////////////////////////////////////////////////////////// |
|---|
| 1059 | foreach inx [$self get] { |
|---|
| 1060 | set datos [$self get $inx $options(-filtercols)] |
|---|
| 1061 | set match 1 |
|---|
| 1062 | for { set i 0 } { $i < [llength $filters] } { incr i } { |
|---|
| 1063 | set match [expr $match & [regexp [lindex $filters $i] [lindex $datos $i]]] |
|---|
| 1064 | } |
|---|
| 1065 | if { ! $match } { |
|---|
| 1066 | $_treeview hide $inx |
|---|
| 1067 | } else { |
|---|
| 1068 | $_treeview show $inx |
|---|
| 1069 | } |
|---|
| 1070 | } |
|---|
| 1071 | } |
|---|
| 1072 | |
|---|
| 1073 | #/////////////////////////////////////////////////////////////////////////// |
|---|
| 1074 | method update { } { |
|---|
| 1075 | # |
|---|
| 1076 | # PURPOSE: method to solve bug when a expanded node of tree |
|---|
| 1077 | # is collapsed and back to expand it. |
|---|
| 1078 | # This bug happens when the option -opencommand is used in an |
|---|
| 1079 | # entry of BLT treeview. |
|---|
| 1080 | # |
|---|
| 1081 | #/////////////////////////////////////////////////////////////////////////// |
|---|
| 1082 | $_treeview configure -width [expr [$_treeview cget -width] - 1] |
|---|
| 1083 | $_treeview configure -width [expr [$_treeview cget -width] + 1] |
|---|
| 1084 | update |
|---|
| 1085 | } |
|---|
| 1086 | |
|---|
| 1087 | } |
|---|
| 1088 | |
|---|
| 1089 | #pedro g - DND event handler |
|---|
| 1090 | #/////////////////////////////////////////////////////////////////////////////// |
|---|
| 1091 | proc dnd_event { w x y} { |
|---|
| 1092 | # PURPOSE: Handles the Drop Event. |
|---|
| 1093 | # ARGS: w = Widget window path, |
|---|
| 1094 | # x, y = Mouse Coords over Drop-Target, this are used to get the parent |
|---|
| 1095 | # |
|---|
| 1096 | # Ojo: El handler no puede realizar desplazamientos hacia el nodo |
|---|
| 1097 | # raiz del arbol por una limitacion del BLT 2.4. |
|---|
| 1098 | # Los nodos que se quieran mover al root deben ser recreados directamente |
|---|
| 1099 | # al root a partir de la cola de hijos del nodo a mover. |
|---|
| 1100 | # Warning: Handler won't move nodes towards the Node 0 of the tree because |
|---|
| 1101 | # of a BLT restriction. If a node was to be re-parented to the |
|---|
| 1102 | # Tree Root node, it'd have to be recreated by gathering a recursive |
|---|
| 1103 | # Child list from the node and then doing an insert with its elements |
|---|
| 1104 | # directly into the Tree Root. |
|---|
| 1105 | # TODOs: Pendiente hacer override a evento B1 para que mantenga la selección |
|---|
| 1106 | # antes de iniciar DND. |
|---|
| 1107 | # El bindtarget se aplica a toda el area editable del widget, por tanto |
|---|
| 1108 | # aceptará información drop de cualquier fuente, hay que validar |
|---|
| 1109 | # que el numero obtenido exista dentro de los elementos del tree. |
|---|
| 1110 | # De lo contrario da error. |
|---|
| 1111 | #/////////////////////////////////////////////////////////////////////////////// |
|---|
| 1112 | |
|---|
| 1113 | # Obtenemos Origen y Destino desde los elementos seleccionados y coordenadas del |
|---|
| 1114 | # Drop. |
|---|
| 1115 | set newHijo [$w curselection] |
|---|
| 1116 | set newParent [$w nearest $x $y] |
|---|
| 1117 | #Prohibimos Drop Hacia si mismo. |
|---|
| 1118 | if { $newHijo != $newParent } { |
|---|
| 1119 | # Añadimos soporte para drag&Drop cuando existe mas de un elemento seleccionado. |
|---|
| 1120 | foreach element $newHijo { |
|---|
| 1121 | # Obtenemos nombre de nuevo Padre e Hijo. |
|---|
| 1122 | set name [$w get -full $element] |
|---|
| 1123 | set nameP [$w get -full $newParent] |
|---|
| 1124 | # Pop-up, pregunta de "seguridad"...(..es un coñazo..remover cuanto antes) |
|---|
| 1125 | set answer [tk_messageBox -message "Mover el Elemento '$name' A '$nameP'" \ |
|---|
| 1126 | -type yesno -icon question -title "Bys TreeView - Pregunta"] |
|---|
| 1127 | if { $answer == "yes"} { |
|---|
| 1128 | # Evitamos liarla con la limitacion del BLT, pues devuelve "exit 1" |
|---|
| 1129 | if { $newParent != "0" } { |
|---|
| 1130 | if { [catch "$w move $element into $newParent" fid] } { |
|---|
| 1131 | # Mostramos mensaje de error en caso de que ocurra alguno. |
|---|
| 1132 | tk_messageBox -message "Error: !! $fid !!" -icon "error" -title "Bys TreeView - Error" |
|---|
| 1133 | return "" |
|---|
| 1134 | } |
|---|
| 1135 | return "" |
|---|
| 1136 | } else { |
|---|
| 1137 | #Mensaje en caso de usuario Animal. |
|---|
| 1138 | tk_messageBox -message "Opcion no permitida !! No puede desplazar a la raiz del Arbol"\ |
|---|
| 1139 | -title "Bys TreeView - Error" -icon "error" |
|---|
| 1140 | return "" |
|---|
| 1141 | } |
|---|
| 1142 | } else { |
|---|
| 1143 | return "" |
|---|
| 1144 | } |
|---|
| 1145 | } |
|---|
| 1146 | } |
|---|
| 1147 | } |
|---|
| 1148 | #pedro - end |
|---|
| 1149 | |
|---|
| 1150 | package provide btreeviewplus 1.0 |
|---|
| 1151 | |
|---|
| 1152 | # ------- TEST CODE ---- |
|---|
| 1153 | |
|---|
| 1154 | #///////////////////////////////////////////////////////////////////////////// |
|---|
| 1155 | proc test_btreeviewplus {} { |
|---|
| 1156 | # |
|---|
| 1157 | # PURPOSE: Funcion de test de un btreeviewplus |
|---|
| 1158 | # |
|---|
| 1159 | #///////////////////////////////////////////////////////////////////////////// |
|---|
| 1160 | global tcl_platform |
|---|
| 1161 | |
|---|
| 1162 | if { $tcl_platform(platform) != "unix" } { |
|---|
| 1163 | SendInit |
|---|
| 1164 | SendVerify |
|---|
| 1165 | } |
|---|
| 1166 | |
|---|
| 1167 | # defining the widgets |
|---|
| 1168 | variable data |
|---|
| 1169 | set data(-selected) 1 |
|---|
| 1170 | |
|---|
| 1171 | destroy .top |
|---|
| 1172 | toplevel .top -width 200 -height 100 |
|---|
| 1173 | |
|---|
| 1174 | TitleFrame .top.f1 -text "BTreeViewPlus test" |
|---|
| 1175 | set f1 [ .top.f1 getframe ] |
|---|
| 1176 | |
|---|
| 1177 | #Añadida la opcion Dragable (boolean 1 o 0), activa o desactiva el DND. |
|---|
| 1178 | btreeviewplus $f1.blb -cols { col1 col2 col3 col4 } \ |
|---|
| 1179 | -height 150 -width 500 -orientation vertical \ |
|---|
| 1180 | -hiddencols {col4} -dragable 1 |
|---|
| 1181 | puts "WIDGET btreeviewplus: $f1.blb" |
|---|
| 1182 | $f1.blb insert end numeros {1 2 3 4} |
|---|
| 1183 | $f1.blb insert end alpha {one two three four} |
|---|
| 1184 | $f1.blb insert -at 2 end alfa {uno dos tres cuatro} |
|---|
| 1185 | $f1.blb insert end kaka {k kk kkk kkkk} |
|---|
| 1186 | $f1.blb insert -at 1 end zero {0 0 0 0} |
|---|
| 1187 | $f1.blb insert end simbols {@ # $ %} |
|---|
| 1188 | |
|---|
| 1189 | # packing all |
|---|
| 1190 | grid .top.f1 -row 0 -column 0 -sticky "new" -padx 10 -pady 10 |
|---|
| 1191 | #grid .top.f2 -row 1 -column 0 -sticky "new" -padx 10 -pady 10 |
|---|
| 1192 | grid columnconfigure .top 0 -weight 1 |
|---|
| 1193 | grid rowconfigure .top 0 -weight 0 |
|---|
| 1194 | grid rowconfigure .top 1 -weight 1 |
|---|
| 1195 | |
|---|
| 1196 | grid $f1.blb -row 0 -column 0 -sticky "new" |
|---|
| 1197 | grid columnconfigure $f1 0 -weight 1 |
|---|
| 1198 | grid rowconfigure $f1 0 -weight 1 |
|---|
| 1199 | |
|---|
| 1200 | } |
|---|