source: tol/tolbase/lib/toltk/tolprj.tcl @ cc64b09

1941-docker-image-to-testdevel
Last change on this file since cc64b09 was cc64b09, checked in by Pedro Gea <pgea@…>, 10 years ago

Refs #1933
Se revisan los binds respecto a wtree y su treectrl.
Se quitan los métodos específicos para la creación de columnas e inserción de nodos que quedaban en tolinspe.
Se añade un update del nodo de paquetes para que se actualice ante un "require".
Se revisan los métodos de botón derecho para que aparezcan sólo sobre los objetos seleccionados.
Se añade un método a wtree para gestionar el color de todas las columnas de un nodo.
Se añaden las columnas al root de wtree.

git-svn-id: ​https://www.tol-project.org/svn/tolp/trunk@7355 be4846ae-f051-483a-831f-b64e7d08527f

  • Property mode set to 100644
File size: 60.5 KB
Line 
1#/////////////////////////////////////////////////////////////////////////////
2# FILE    : tolprj.tcl
3# PURPOSE : This file contains a namespace called TolProject with its
4#           functions. It's for managing TOL projects that are groups of TOL
5#           objects (text files, table files, etc.). They are showed as a
6#           hierarchical treeview.
7#/////////////////////////////////////////////////////////////////////////////
8
9package require bfunctions
10
11#/////////////////////////////////////////////////////////////////////////////
12namespace eval TolProject {
13#
14# PURPOSE: The purpose of this namespace is organize code and functions and
15#          manage common options for all tol project editors such as last
16#          edited files, last directory used, etc.
17#          A special namespace is created for each instance of project.
18#
19# VARIABLES:
20#   options -> common options for all project windows:
21#     wm,state  -> initial window project state
22#     geometry  -> initial window project geometry
23#     lastDir   -> last directory used
24#     chEdited  -> boolen for saving last project files path
25#     numEdited -> number of last project files path to save
26#     edited    -> path of last used projects
27#   tmpOpt      -> temporary array used to store the widgets and variables of
28#              the options dialog.
29#   num_Project -> incrementally number to identify each project window
30#   typelist    -> list of type files supported by project editor
31#   defExt      -> default extension for files managed by project editor
32#   num         -> incrementally number to identify each item in the
33#                 [Included TOL Files] section of project file
34#
35#/////////////////////////////////////////////////////////////////////////////
36  variable options
37  variable tmpOpt
38  variable num_Project 0
39  variable typelist {{"Project" {".prj"}}}
40  variable defExt .prj
41}
42
43#/////////////////////////////////////////////////////////////////////////////
44proc ::TolProject::ComputeFullPath {this path} {
45#
46# PURPOSE: Prepends name of project base directory if necessary to a given
47#          path.
48#          This will be necessary in case path is not an absolute path.
49#
50# PARAMETERS:
51#   this  -> instance of tol project
52#   path  -> path to which name of project base directory is to be prepended.
53#
54# RETURN: The path modified or not as necessary.
55#
56#/////////////////////////////////////////////////////////////////////////////
57  upvar \#0 ${this}::data data
58
59  if {[file pathtype $path] == "absolute"} {
60    return $path
61  } else {
62    return [file join $data(baseDir) $path]
63  }
64}
65
66#/////////////////////////////////////////////////////////////////////////////
67proc ::TolProject::New {{path ""}} {
68#
69# PURPOSE: Creates a new project window and an instance of it. This also
70#          initializes the instance and register the window in the project.
71#
72# PARAMETERS:
73#   path  -> path of project to use. If it isn't specified a new white
74#            project is created.
75#
76# RETURN: A instance of TolProject.
77#
78#/////////////////////////////////////////////////////////////////////////////
79  variable num_Project
80  incr num_Project
81
82  set this [Create .proy$num_Project]
83  SetTraces $this
84  InitState $this new
85  update
86  if {$path == ""} {
87    CmdNew $this
88  }
89  return $this
90}
91
92#/////////////////////////////////////////////////////////////////////////////
93proc ::TolProject::Open {{path ""} {run 0}} {
94#
95# PURPOSE: Open a project file in a project window. If file is already opened
96#          it raises its window, else it creates a new tol project window and
97#          an instance of it.
98#
99# PARAMETERS:
100#   path  -> path of file to open. If it isn't specified it ask for it.
101#   run   -> indicates if the project must be compiled.
102#
103# RETURN: A instance of tol project.
104#
105#/////////////////////////////////////////////////////////////////////////////
106  if {$path != ""} {
107    #Comprobar si el archivo ya está abierto y si es así hacer un raise
108    if { ![ catch { set lst [namespace children ::TolProject] } msgerr] } {
109      foreach ins $lst {
110        upvar \#0 ${ins}::data data
111        if {[string equal "$data(baseDir)/$data(nameFile)" $path]} {
112          #wm deiconify $data(f)
113          raise $data(f)
114          return $ins
115        }
116      }
117      update
118    }
119  }
120
121  if {$path == ""} {
122    CmdOpen ""
123  } else  {
124    set this [New $path]
125    GetFromFile $this $path $run
126  } 
127
128  if {[info exists this]} {
129    return $this
130  } else  {
131    return ""
132  }
133}
134
135#/////////////////////////////////////////////////////////////////////////////
136proc ::TolProject::postEdited {m {ord 0}} {
137#
138# PURPOSE: Fills a menu with the last used project files, according to the
139#          information of 'options' variable.
140#
141# PARAMETERS:
142#   m   -> menu's path that will have the list of last used projects
143#   ord -> flag that indicates if files must be shown sorted
144#
145#/////////////////////////////////////////////////////////////////////////////
146  variable options
147  $m delete 0 end
148  if $options(chEdited) {
149    set options(edited) [lrange $options(edited) 0 [expr $options(numEdited)-1]]
150    if $ord {
151      set lst [lsort -ascii $options(edited)]
152    } else {
153      set lst $options(edited)
154    }
155    foreach w $lst {
156      $m add command -label $w -command [list ::TolProject::Open $w]
157    }
158    if [llength $lst] {
159      $m add separator
160      $m add command -label [mc "Clear"]\
161           -command [list ::TolProject::clearEdited]
162    }
163  }
164}
165
166#/////////////////////////////////////////////////////////////////////////////
167proc ::TolProject::clearEdited {} {
168#
169# PURPOSE: Clears the list of last edited files
170#
171#/////////////////////////////////////////////////////////////////////////////
172  variable options
173  set options(edited) ""
174  ::iniFile::Write TolProject recent       $options(edited)
175  ::iniFile::Flush
176}
177
178#/////////////////////////////////////////////////////////////////////////////
179proc ::TolProject::OnDelete {this} {
180#
181# PURPOSE: Procedure to check things before destroying tol project window
182#
183# PARAMETERS:
184#   this  -> Instance of tol project
185#
186#/////////////////////////////////////////////////////////////////////////////
187  upvar \#0 ${this}::data data
188  if {[string equal [CheckOpen $this] "cancel"]} {
189    return 0
190  }
191  destroy $data(f)
192  return 1
193}
194
195#/////////////////////////////////////////////////////////////////////////////
196proc ::TolProject::Destroy {this w} {
197#
198# PURPOSE: Deletes the instance of the tol project. Before this, writes the
199#          ini file.
200#
201# PARAMETERS:
202#   this  -> Instance of tol project
203#
204#/////////////////////////////////////////////////////////////////////////////
205  upvar \#0 ${this}::data data
206  if [string equal $data(f) $w] {
207    WriteIni $this
208    namespace delete $this
209  }
210}
211
212#/////////////////////////////////////////////////////////////////////////////
213proc ::TolProject::InitState {this from} {
214#
215# PURPOSE: Initializes some variables according to the state of the tol
216#          project.
217#
218# PARAMETERS:
219#   this  -> Instance of tol project
220#   from  -> State that defines values for the variables
221#
222#/////////////////////////////////////////////////////////////////////////////
223  upvar \#0 ${this}::data data
224
225  switch $from {
226    new {
227      set data(compiling) 0
228      set data(isSaved) 1
229      set data(nameFile) ""
230      set data(baseDir) ""
231      set data(lastOpenedNodeDir) ""
232    }
233    open {
234      set data(compiling) 0
235      set data(isSaved) 1
236#      set data(nameFile) ""
237    }
238    save {
239      set data(isSaved) 1
240    }
241  }
242}
243
244#/////////////////////////////////////////////////////////////////////////////
245proc ::TolProject::SetTraces {this} {
246#
247# PURPOSE: Sets some traces of variables to control changes in tol project
248#          widget
249#
250# PARAMETERS:
251#   this  -> Instance of tol project
252#
253#/////////////////////////////////////////////////////////////////////////////
254  upvar \#0 ${this}::data data
255
256  trace variable ${this}::data(nameFile) w \
257          [list ::TolProject::TraceNameFile $this]
258  trace variable ${this}::data(isSaved)  w \
259          [list ::TolProject::TraceSaved $this]
260  trace variable ${this}::data(compiling)  w \
261          [list ::TolProject::TraceCompiling $this]
262}
263
264#/////////////////////////////////////////////////////////////////////////////
265proc ::TolProject::TraceNameFile {this name1 name2 op} {
266#
267# PURPOSE: Sets tol project's name each time var nameFile changes.
268#
269# PARAMETERS:
270#   this  -> Instance of tol project
271#   name1, name2, op ->
272#     Name1 and name2 give the name(s) for the variable being accessed: if the
273#     variable is a scalar then name1 gives the variable's name and name2 is
274#     an empty string; if the variable is an array element then name1 gives
275#     the name of the array and name2 gives the index into the array; if an
276#     entire array is being deleted and the trace was registered on the
277#     overall array, rather than a single element, then name1 gives the array
278#     name and name2 is an empty string. Name1 and name2 are not necessarily
279#     the same as the name used in the trace variable command: the upvar
280#     command allows a procedure to reference a variable under a different
281#     name. Op indicates what operation is being performed on the variable,
282#     and is one of r, w, or u.
283#
284#/////////////////////////////////////////////////////////////////////////////
285  upvar \#0 ${this}::data data
286  if {$data(nameFile) != ""} {
287    set data(labelWindow) $data(nameFile)
288  } else  {
289    set data(labelWindow) "untitled.prj"
290  }
291  $data(f) configure -title "[mc Project] $data(labelWindow)"
292  set tv [GetTreeview $this]
293  #@ Antes se usaba $data(nameFile) como FileName y $data(labelWindow) como label   
294  $tv item text root FileName [file tail $data(labelWindow)]
295}
296
297#/////////////////////////////////////////////////////////////////////////////
298proc ::TolProject::TraceSaved {this name1 name2 op} {
299#
300# PURPOSE: Sets saved/not saved info in status bar each time var 'isSaved'
301#          changes.
302#
303# PARAMETERS:
304#   this  -> Instance of tol project
305#   name1, name2, op -> see above
306#
307#/////////////////////////////////////////////////////////////////////////////
308  upvar \#0 ${this}::data data
309
310  if $data(isSaved) {
311    $data(sb,modi) configure -text [mc "Saved"] -relief groove
312  } else  {
313    $data(sb,modi) configure -text [mc "Not Saved"] -relief raised
314  }
315}
316
317#/////////////////////////////////////////////////////////////////////////////
318proc ::TolProject::TraceCompiling {this name1 name2 op} {
319#
320# PURPOSE: Enables/disables compiling options each time var 'compiling'
321#          changes.
322#
323# PARAMETERS:
324#   this  -> Instance of tol project
325#   name1, name2, op -> see above
326#
327#/////////////////////////////////////////////////////////////////////////////
328  upvar \#0 ${this}::data data
329  set menu [GetMenu $this]
330
331  if {$data(compiling) eq 1} {
332    set state disabled
333  } else  {
334    set state normal   
335  }
336  foreach ite [list 4 5 6 7 8] {
337    catch { $menu entryconfigure $ite -state $state }
338  }
339}
340
341#/////////////////////////////////////////////////////////////////////////////
342proc ::TolProject::Create {path} {
343#
344# PURPOSE: Creates a Tol Project instance. Creates and packs the tol projedt
345#          window (toplevel, treeview, toolbar, statusbar, popup menu, ...).
346#
347# PARAMETERS:
348#   path  -> project window's path (toplevel)
349#
350# RETURN: Tol project's instance
351#
352#/////////////////////////////////////////////////////////////////////////////
353  variable options
354  global toltk_options
355  set this ::TolProject::$path
356  if { [lsearch [namespace children ::TolProject] $this] != -1 } {
357    error "$this already exists as a children of ::TolProject"
358  }
359
360  #  A namespace is created for each tol project widget.
361
362  namespace eval $this {
363 
364    # data -> array with information about the instance:
365    #   f          -> toplevel path
366    #   tb,frame   -> toolbar's frame path
367    #   sb,frame   -> statusbar's frame path
368    #   mainMenu
369
370    variable data
371  }
372
373  upvar \#0 ${this}::data data
374  # create
375  set data(f) [set f [::project::CreateForm -width 400 -height 500 \
376                        -type [mc Projects] \
377                        -iniconfig TolProject \
378                        -closecmd [list ::TolProject::OnDelete $this] \
379                        -helpkey "Tb4Edp"]]
380  set f [$f getframe]
381
382  set n_b [list \
383     "bnew"     "CmdNew"      "[mc [list New white project]] (CTRL+N)" \
384     "openprj"  "CmdOpen"     "[mc Open] (CTRL+A)" \
385     "bsave"    "CmdSave"     "[mc Save] (CTRL+S)" \
386     "sep1"     "--"          ""\
387     "tools"    "CmdOptions"  "[mc Options]"]
388  # botonera superior
389  set data(tb,frame) [frame $f.ftop -relief raised -bd 1]
390  foreach {n_img n_proc n_hint} $n_b {
391    if {[string equal $n_proc "--"]} {
392      Separator $f.ftop.$n_img -orient vertical
393    } else {
394      set data(tb,$n_img) [Button $f.ftop.$n_img\
395              -image [::Bitmap::get ${n_img}] -relief link -helptext $n_hint\
396              -bd 2 -command [list ::TolProject::$n_proc $this]]
397    }
398    pack $f.ftop.$n_img -side left -pady 2 -fill y -padx 1
399  }
400
401  # frame y label para barra de estado
402  set data(sb,frame) [frame $f.fop -relief groove -bd 1 -height 7]
403  set data(sb,modi)  [label $f.fop.modi -bd 1 -width 14]
404  set data(sb,desc)  [label $f.fop.desc -relief groove -bd 1 -anchor w]
405
406  # treeview y scroll
407  ScrolledWindow $f.sw
408  set tv [::wtree $f.sw.t -table 0 -filter no \
409    -background white -showroot 1 -selectmode single -showheader 0 \
410    -selectcommand "::TolProject::SelectProc $this" \
411    -highlightbackground gray75 -highlightcolor black \
412    -highlightthickness 0 -font $toltk_options(fonts,Label) \
413    -columns [list \
414      [list {image text} -label FileName -tags FileName] \
415      [list text -label Description -tags Description] \
416      [list text -label Type -tags Type] \
417      [list text -label Exclude -tags Exclude] \
418      [list text -label ExcludeTOL -tags ExcludeTOL] \
419    ] ]
420  set data(treeview) $tv
421  $tv column configure "range 1 end" -visible no
422  $tv column configure first -expand yes -weight 1
423  $tv column configure all -itembackground ""
424 
425  $f.sw setwidget $f.sw.t
426   
427  # empaquetamos los label de estado
428  pack $f.fop.modi -side left
429  pack $f.fop.desc -expand true -fill x
430   
431  grid $f.ftop  -sticky new
432  grid $f.sw    -sticky news 
433  grid $f.fop   -sticky ews
434
435  grid rowconfigure    $f 1 -weight 1
436  grid columnconfigure $f 0 -weight 1
437
438  bind $tv <Control-KeyRelease> [list ::TolProject::OnControlKey $this %K %k]
439  bind $tv <Button-1> "::focus $tv"
440  bind $tv <Button-3> +[list ::TolProject::PostVariable $this %X %Y]
441
442  bind $tv <Double-1> "mdidoc disableglobalraise ; ::TolProject::OpenNodeIfTerminal $this"
443  bind $tv <KeyPress-Return> "::TolProject::OpenNodeIfTerminal $this"
444
445  bind $tv <KeyPress-space>  +[list ::TolProject::NodeActiveAttributes $this]
446  bind $tv <KeyPress-Delete> +[list ::TolProject::DeleteActiveNode     $this]
447  bind $tv <KeyPress-F9>     "::TolProject::CompileActiveNode    $this ; break"
448  bind $tv <KeyPress-F8>     "::TolProject::DecompileActiveNode  $this ; break" 
449 
450  set data(mainMenu) [menu $tv.m -tearoff 0]
451
452  bind $data(f) <Destroy> +[list ::TolProject::Destroy $this %W]
453  $data(f) bind <Control-F4> "$data(f) kill; break"
454  return $this
455}
456
457#///////////////////////////////////////////////////////////////////////////
458proc ::TolProject::OnControlKey {this keysym keycode} {
459#
460# PURPOSE: Control the "Control + Key Press"
461#
462# PARAMETERS: this ->  Instance of project editor
463#             keysym -> The keysym corresponding to the event,
464#                       substituted as a textual string
465#             keycode -> The keycode field from the event
466#
467#///////////////////////////////////////////////////////////////////////////
468  #puts "PLATFORM: $::tcl_platform(platform)"
469  switch [string toupper $keysym] {
470    A { ::TolProject::CmdOpen $this}
471    N { ::TolProject::CmdNew  $this}
472    S { ::TolProject::CmdSave $this}
473  }
474}
475
476#/////////////////////////////////////////////////////////////////////////////
477# File management commands (new, open, save, save as...)
478#/////////////////////////////////////////////////////////////////////////////
479
480#/////////////////////////////////////////////////////////////////////////////
481proc ::TolProject::CmdNew {this} {
482#
483# PURPOSE: Cleans project window to edit a new white project
484#
485# PARAMETERS:
486#   this  -> Instance of Tol project
487#
488#/////////////////////////////////////////////////////////////////////////////
489  upvar \#0 ${this}::data data
490
491  set tv [GetTreeview $this]
492  if [string equal [CheckOpen $this] "cancel"] return
493  $tv item delete all
494  set img [GetImageFromType ROOT]
495  $tv item image root FileName $img
496  $tv item text root FileName "" Description "Root node" \
497    Type "ROOT" Exclude 0 ExcludeTOL 0
498  InitState $this new
499}
500
501#/////////////////////////////////////////////////////////////////////////////
502proc ::TolProject::UpdateListEdited {path} {
503#
504# PURPOSE: Updates list of last edited project files adding a new file path.
505#
506# PARAMETERS:
507#   path  -> path of the last edited project file
508#
509#/////////////////////////////////////////////////////////////////////////////
510  variable options
511  # guardamos el ultimo directorio abierto
512  set options(lastDir) [file dirname $path]
513  if { [set idx [lsearch $options(edited) $path]] == -1 } {
514    set options(edited) [linsert $options(edited) 0 $path]
515  } else {
516    set ll ""
517    lappend ll $path
518    set i 0
519    foreach f $options(edited) {
520      if  {$i != $idx} {
521        lappend ll $f
522      }
523      incr i
524    }
525    set options(edited) $ll
526  }
527  set options(edited) [lrange $options(edited) 0 [expr $options(numEdited)-1]]
528}
529
530#/////////////////////////////////////////////////////////////////////////////
531proc ::TolProject::CmdOpen {{this ""}} {
532#
533# PURPOSE: Asks for a project file path and if it's given opens it into the
534#          project window.
535#
536# PARAMETERS:
537#   this -> Instance of tol project
538#
539#/////////////////////////////////////////////////////////////////////////////
540  variable options
541  variable typelist
542  variable defExt
543 
544  if {$this == ""} {
545    set parent .
546  } else  {
547    set parent [GetTreeview $this]
548    if [string equal [CheckOpen $this] "cancel"] return
549  }
550
551  set path [tk_getOpenFile -title [mc "Open"] \
552          -parent $parent -initialdir $options(lastDir) \
553          -defaultextension $defExt -filetypes $typelist]
554
555  if { $path != "" } {
556    # abrimos solo si no esta ya abierto
557    foreach ins [namespace children ::TolProject::] {
558      upvar \#0 ${ins}::data data
559      if {[string equal "$data(baseDir)/$data(nameFile)" $path]} {
560        $data(f) raise
561            set resp [tk_messageBox -type ok -icon warning \
562             -message [mc "The project is allready opened!"] ]
563        return
564      }
565    }
566    if {$this == ""} {
567      set this [New $path]
568    }
569    GetFromFile $this $path
570  }
571}
572
573#/////////////////////////////////////////////////////////////////////////////
574proc ::TolProject::GetFromFile {this path {run 0}} {
575#
576# PURPOSE: Loads a project into the project window . This converts from the
577#          file especification to the treeview representation.
578#
579# PARAMETERS:
580#   this -> Instance of tol project
581#   path -> project file's path
582#   run  -> if 1 the project will be automatically compiled
583#
584#/////////////////////////////////////////////////////////////////////////////
585  upvar \#0 ${this}::data data
586  set tv [GetTreeview $this]
587  $tv item delete all
588  if {[::TolProject::WtreeFromFile $tv $path ::TolProject::GetImageFromType]} {
589    set data(baseDir) [file dirname $path]
590    set data(lastOpenedNodeDir) $data(baseDir)
591    set data(nameFile) [file tail $path]
592    UpdateListEdited $path
593  } else {
594    set data(nameFile) ""
595  }
596  $data(f) raise
597  InitState $this open
598  if { $run } {
599    CompileNode $this root
600  }
601}
602
603#/////////////////////////////////////////////////////////////////////////////
604proc ::TolProject::CheckAll {} {
605#
606# PURPOSE: Checks for files opened if anyone has changed and asks for saving.
607#
608#/////////////////////////////////////////////////////////////////////////////
609  if { ![ catch { set lst [namespace children ::TolProject] } msgerr] } {
610    foreach ins $lst {
611      if {[CheckOpen $ins] eq "cancel"} {
612        return "cancel"
613      }
614    }
615  }
616  return "ok"
617}
618
619#/////////////////////////////////////////////////////////////////////////////
620proc ::TolProject::CheckOpen {this {type "yesnocancel"}} {
621#
622# PURPOSE: Checks if a file has changed and asks for saving.
623#
624# PARAMETERS:
625#   this -> Instance of Tol project
626#   type -> type of messageBox to ask. (yesnocancel by default)
627#
628# RETURN: Returns user answer for saving.
629#
630#/////////////////////////////////////////////////////////////////////////////
631  upvar \#0 ${this}::data data
632   
633  # comprobamos si necesita ser guardado
634  if { !$data(isSaved)} {
635    if {$data(nameFile) != ""} {
636      set name $data(nameFile)
637    } else  {
638      set name "untitled.prj"
639    }
640    # preguntamos por conformidad
641    set tv [GetTreeview $this]
642    set rq [tk_messageBox -type $type -icon warning -title [mc "Warning"]\
643            -parent $tv -message "[mc "File %1\$s has changed!" $name].\n\
644            [mc "Do you want to save changes?"]"]
645    switch -exact $rq {
646      yes {
647        if {$data(nameFile) != "" } {
648          FileSave $this $data(nameFile)
649        } else {
650          CmdSaveAs $this $data(nameFile)
651        }
652      }
653      cancel {return cancel}
654      default {return ok}
655    }
656  }
657  return ok
658}
659
660#/////////////////////////////////////////////////////////////////////////////
661proc ::TolProject::CmdSave {this} {
662#
663# PURPOSE: Saves project info actually opened in the project editor. If it
664#          doesn't have a name, asks for ti (CmdSaveAs).
665#
666# PARAMETERS:
667#   this -> Instance of Tol project
668#
669# RETURN: Returns 1 if file has been saved correctly or 0 if not.
670#
671#/////////////////////////////////////////////////////////////////////////////
672  upvar \#0 ${this}::data data
673
674  if {$data(nameFile) == ""} {
675    set ok [CmdSaveAs $this]
676  } else {
677    set ok [FileSave $this $data(nameFile)]
678  }
679  return $ok
680}
681
682#/////////////////////////////////////////////////////////////////////////////
683proc ::TolProject::CmdSaveAs {this {nf ""}} {
684#
685# PURPOSE: Saves project actually opened in project editor asking for the
686#          user to select a file to save it.
687#
688# PARAMETERS:
689#   this -> Instance of Tol project
690#   nf   -> name of file proposed
691#
692# RETURN: Returns 1 if file has been saved correctly or 0 if not.
693#
694#/////////////////////////////////////////////////////////////////////////////
695  upvar \#0 ${this}::data data
696  variable options
697  variable typelist
698  variable defExt
699  set tv [GetTreeview $this]
700 
701  if {$nf == ""} {
702    set dir $options(lastDir)
703    set fil ""
704  } else  {
705    set dir "[file dirname $nf]"
706    set fil "[file tail $nf]"
707  }
708  set path [tk_getSaveFile -title [mc "Save as"] -initialdir $dir \
709       -initialfile $fil -parent $tv \
710       -defaultextension $defExt -filetypes $typelist]
711  if {![string equal $path ""] } {
712    set data(baseDir) [file dirname $path]
713    set data(lastOpenedNodeDir) $data(baseDir)
714    set data(nameFile) [file tail $path]
715    set ok [FileSave $this [file tail $path]]
716  } else {
717    set ok 0
718  }
719  return $ok
720}
721
722#/////////////////////////////////////////////////////////////////////////////
723proc ::TolProject::FileSave { this path } {
724#
725# PURPOSE: Saves project actually opened in project editor in a text file.
726#
727# PARAMETERS:
728#   this -> Instance of tol project
729#   path -> name of file
730#
731# RETURN: Returns 1 if file has been saved correctly or 0 if not.
732#
733#/////////////////////////////////////////////////////////////////////////////
734  variable options
735  upvar \#0 ${this}::data data
736
737  #Guardar la transformación de treeview a archivo
738  if {[::TolProject::WtreeToFile [GetTreeview $this] \
739      [::TolProject::ComputeFullPath $this $path]]} {
740    #Añadir al archivo la entrada para que pueda ser llamado desde tol.exe
741    AddEntry $this [::TolProject::ComputeFullPath $this $path]
742    set data(nameFile) $path
743    InitState $this save
744    # guardamos el ultimo directorio utilizado
745    set options(lastDir) $data(baseDir)
746    set ok 1
747  } else  {
748    set ok 0
749  }
750  return $ok
751}
752
753#/////////////////////////////////////////////////////////////////////////////
754proc ::TolProject::AddEntry {this path} {
755#
756# PURPOSE: Adds a special entry in file path for including proyect from TOL.
757#
758# PARAMETERS:
759#   this -> Instance of tol project
760#   path -> name of file
761#
762#/////////////////////////////////////////////////////////////////////////////
763  upvar \#0 ${this}::data data
764  set data(num) 1
765  set fd [iniparse:openfile $path]
766  NodeToFile $this root $fd [file tail [file rootname $path]]
767  iniparse:closefile $fd
768}
769
770#/////////////////////////////////////////////////////////////////////////////
771proc ::TolProject::NodeToFile {this index fd name} {
772#
773# PURPOSE:
774#
775# PARAMETERS:
776#   this -> Instance of tol project
777#   index -> treeview node index
778#   fd    -> channel identifier of text file
779#   name  ->
780#
781#/////////////////////////////////////////////////////////////////////////////
782  upvar \#0 ${this}::data data
783  set key "Included TOL Files"
784
785  set tv [GetTreeview $this]
786  # Guardar data del nodo actual
787  set excludeTOL [$tv item text $index ExcludeTOL]
788  if ![string equal $excludeTOL 1] {
789    if {[IsCompilable $this $index] } {
790      set filename [$tv item text $index FileName]
791      set item "Set $name.$data(num)"
792      set value "Include(\"$filename\");"
793      writeini $fd $key $item $value
794      incr data(num)
795    }
796    # Llamar recursivamente para los hijos
797    foreach child [$tv item children $index] {
798      NodeToFile $this $child $fd $name
799    }
800  }
801}
802
803#/////////////////////////////////////////////////////////////////////////////
804proc ::TolProject::GetTreeview {this} {
805#
806# PURPOSE: Returns treeview's path of a given instance
807#
808# PARAMETERS:
809#   this -> Instance of tol project
810#
811# RETURN: Treeview's path
812#
813#/////////////////////////////////////////////////////////////////////////////
814  upvar \#0 ${this}::data data
815  return $data(treeview)
816}
817
818#/////////////////////////////////////////////////////////////////////////////
819proc ::TolProject::GetMenu {this} {
820#
821# PURPOSE: Returns treeview's menu of a given instance
822#
823# PARAMETERS:
824#   this -> Instance of tol project
825#
826# RETURN: Treeview menu's path
827#
828#/////////////////////////////////////////////////////////////////////////////
829  upvar \#0 ${this}::data data
830  return $data(mainMenu)
831}
832
833#/////////////////////////////////////////////////////////////////////////////
834proc ::TolProject::SelectProc {this} {
835#
836#/////////////////////////////////////////////////////////////////////////////
837  upvar \#0 ${this}::data data
838  set tv [GetTreeview $this]
839  set node [$tv selection get end] ;# anchor
840  if { $node eq "" } return
841  set description [$tv item text $node Description]
842  $data(sb,desc) configure -text "$description"
843}
844
845#/////////////////////////////////////////////////////////////////////////////
846proc ::TolProject::PostVariable {this x y} {
847#
848# PURPOSE: Composes a popup menu and displays it. Its composed depending on
849#          the node clicked by user.
850#
851# PARAMETERS:
852#   x -> x-coordinate where popup menu is drawn
853#   y -> y-coordinate where popup menu is drawn
854#
855#/////////////////////////////////////////////////////////////////////////////
856  upvar \#0 ${this}::data data
857  set tv [GetTreeview $this]
858  set menu [GetMenu $this]
859  $menu delete 0 end
860
861  set state [expr {$data(compiling)? "disabled" : "normal" }]
862
863  set node [$tv selection get end] ;# current
864  if { [string length $node] } {
865    if [IsTerminal $this $node] {
866      $menu add command -label [mc "Open node"] -accelerator Return\
867         -command [list ::TolProject::OpenNode $this $node]
868 
869      # Compute insertion point and prepare menu entry     
870      set nodefocus [$tv selection get end] ;# focus
871      set parent [$tv item parent $nodefocus]   
872      set prev [$tv item prevsibling $nodefocus]
873      if {[string equal $prev ""]} {
874        set prevCount 1
875      } else {
876        set prevCount [expr [lsearch [$tv item children $parent] $node] + 1]
877      }
878      $menu add command -label [mc "Add node"] \
879        -command [list ::TolProject::AddNode $this $parent $prevCount]\
880        -accelerator Ins
881 
882    } else {
883      # This adds to the end of the non-terminal node
884      $menu add command -label [mc "Add node"] -accelerator Ins\
885            -command [list ::TolProject::AddNode $this $node]
886    }
887    $menu add command -label [mc "Attributes"] -accelerator space\
888          -command [list ::TolProject::NodeAttributes $this $node]
889    $menu add command -label [mc "Delete node"] -accelerator Sup\
890          -command [list ::TolProject::DeleteNode $this $node]
891    $menu add separator
892    if [IsTerminal $this $node] {
893      $menu add command -label [mc "Compile node"] -state $state \
894         -command [list ::TolProject::CompileNode $this $node]\
895         -accelerator F9
896      $menu add command -label [mc "Decompile node"]  -state $state \
897         -command [list ::TolProject::DecompileNode $this $node]\
898         -accelerator F8
899    } else {
900      $menu add command -label [mc "Compile node"] -state $state \
901         -command [list ::TolProject::CompileNode $this $node]\
902         -accelerator F9
903      $menu add command -label [mc "Decompile node"]  -state $state \
904         -command [list ::TolProject::DecompileNode $this $node]\
905         -accelerator F8
906    }
907    $menu add command -label [mc "Compile to the end"] -state $state \
908       -command [list ::TolProject::CompileIfBeforeNode $this root $node]
909    $menu add command -label [mc "Compile up to here"] -state $state \
910       -command [list ::TolProject::CompileUpToHereNode $this root $node]   
911    # save as
912    $menu add separator   
913    $menu add command -label "[mc "Save as"] ..." \
914      -command [list ::TolProject::CmdSaveAs $this]   
915    # show menu
916    tk_popup $menu $x $y     
917  }
918}
919
920#/////////////////////////////////////////////////////////////////////////////
921proc ::TolProject::OpenNodeIfTerminal {this} {
922#
923# PURPOSE:
924#
925# PARAMETERS:
926#   this -> Instance of tol project
927#
928#/////////////////////////////////////////////////////////////////////////////
929  upvar \#0 ${this}::data data
930  set tv [GetTreeview $this]
931  set node [$tv selection get end] ;# anchor
932  OpenNode $this $node
933}
934
935#/////////////////////////////////////////////////////////////////////////////
936proc ::TolProject::OpenNode {this node} {
937#
938# PURPOSE: Opens a terminal node of the project. It depends on the node type
939#          what kind of editor use for opening the node (text or table).
940#
941# PARAMETERS:
942#   this -> Instance of tol project
943#   node -> Node active in treeview, which is opened
944#
945#/////////////////////////////////////////////////////////////////////////////
946  upvar \#0 ${this}::data data
947  set tv [GetTreeview $this]
948 
949  set type [$tv item text $node Type]
950  set filename [$tv item text $node FileName]
951  switch $type {
952    TOL { ::Editor::Open \
953          [::TolProject::ComputeFullPath $this $filename] }
954    BDT -
955    BST { ::EditTable::Open \
956          [::TolProject::ComputeFullPath $this $filename] }
957  }
958}
959
960#/////////////////////////////////////////////////////////////////////////////
961proc ::TolProject::AddNode {this node {prev end}} {
962#
963# PURPOSE: Adds a node to the project. First of all, asks for the node type.
964#
965# PARAMETERS:
966#   this -> Instance of tol project
967#   node -> Node active in treeview, in which the new node is added
968#   prev -> where is added, end if nothing is specified
969#
970#/////////////////////////////////////////////////////////////////////////////
971  upvar \#0 ${this}::data data
972  set tv [GetTreeview $this]
973 
974  #si no hay un directorio base establecido mostramos dialogo de guardar proyecto
975  if { $data(baseDir) eq "" } {
976    CmdSave $this
977    return
978  }
979 
980  ClearData $this
981  DialogType $this $tv
982  # si no se ha pulsado cancelar
983  if {$data(type) != -1} {
984    if {!($data(type) eq "Fol") } {
985      set title "[mc Add] [mc {a file of type}] $data(type) "
986    } else {
987      set title "[mc Add] [mc folder]"
988    }
989    DialogAttributes $this $tv $title
990    # si no se ha pulsado cancelar
991    if {![string equal $data(name) ""]} {
992
993      # Path name gets transformed for files
994      switch -exact $data(type) {
995        TOL -
996        BDT -
997        BST {
998          set data(lastOpenedNodeDir) [file dirname $data(name)]
999          set data(name) \
1000          [ObtainRelativePath $data(name) $data(baseDir)]
1001        }
1002        default {
1003          # do nothing for folders
1004        }
1005      }
1006     
1007      set img [GetImageFromType $data(type)]                                       
1008      if { $data(type) eq "Fol" } {
1009        set hasbutton 1
1010      } else {
1011        set hasbutton 0
1012      }
1013      if {$prev eq "end"} {
1014        set idx [$tv item create -parent $node -button $hasbutton -open 0]
1015      } else {
1016        set idx [$tv item create -prevsibling $prev -button $hasbutton -open 0]
1017      }
1018      $tv item image $idx FileName $img
1019      $tv item text $idx FileName $data(name) Description $data(desc) \
1020        Type $data(type) Exclude $data(exclude) ExcludeTOL $data(excludeTOL)
1021      set data(isSaved) 0
1022    }
1023  }
1024}
1025
1026#/////////////////////////////////////////////////////////////////////////////
1027proc ::TolProject::NodeActiveAttributes {this args} {
1028#/////////////////////////////////////////////////////////////////////////////
1029  upvar \#0 ${this}::data data
1030  set tv [GetTreeview $this]
1031  set node [$tv selection get end] ;# anchor
1032  NodeAttributes $this $node
1033}
1034
1035#/////////////////////////////////////////////////////////////////////////////
1036proc ::TolProject::NodeAttributes {this node} {
1037#
1038# PURPOSE: Shows the attributes of the selected node.
1039#
1040# PARAMETERS:
1041#   this -> Instance of tol project
1042#   node -> Node active in treeview, whose attributes are shown
1043#
1044#/////////////////////////////////////////////////////////////////////////////
1045  upvar \#0 ${this}::data data
1046  set tv [GetTreeview $this]
1047  GetDataFromNode $this $node
1048  set name_old $data(name)
1049  set desc_old $data(desc)
1050  set excl_old $data(exclude)
1051  set exct_old $data(excludeTOL)
1052  set title "[$tv item text $node FileName] [mc Attributes]"
1053  DialogAttributes $this $tv $title
1054  # si no se ha pulsado cancelar
1055  if {![string equal $data(name) ""]} {
1056    # si se ha cambiado algun dato
1057    if {![string equal $name_old $data(name)] ||
1058        ![string equal $desc_old $data(desc)] ||
1059        ![string equal $excl_old $data(exclude)] ||
1060        ![string equal $exct_old $data(excludeTOL)]} {
1061      $tv item text $node FileName $data(name) Description $data(desc) \
1062        Exclude $data(exclude) ExcludeTOL $data(excludeTOL)                       
1063      set data(isSaved) 0
1064    }
1065  }
1066}
1067
1068#/////////////////////////////////////////////////////////////////////////////
1069proc ::TolProject::DeleteActiveNode {this args} {
1070#/////////////////////////////////////////////////////////////////////////////
1071  upvar \#0 ${this}::data data
1072  set tv [GetTreeview $this]
1073  set node [$tv selection get end] ;# current
1074  DeleteNode $this $node
1075}
1076
1077#/////////////////////////////////////////////////////////////////////////////
1078proc ::TolProject::DeleteNode {this node} {
1079#
1080# PURPOSE: Deletes a node and all its childs from the project.
1081#
1082# PARAMETERS:
1083#   this -> Instance of tol project
1084#   node -> Node active in treeview, which is deleted
1085#
1086#/////////////////////////////////////////////////////////////////////////////
1087  upvar \#0 ${this}::data data
1088
1089  set tv [GetTreeview $this]
1090  set name [$tv item text $node FileName]
1091  set answer [tk_messageBox -title [mc "Question"]\
1092            -parent $tv\
1093            -message [mc "Are you sure you want to delete node %1\$s?" $name] \
1094            -type yesno -icon question]
1095  if { [string compare $answer yes] == 0 } {
1096    $tv item delete $node
1097    set data(isSaved) 0
1098  }
1099}
1100
1101#/////////////////////////////////////////////////////////////////////////////
1102proc ::TolProject::CompileActiveNode {this args} {
1103#/////////////////////////////////////////////////////////////////////////////
1104  upvar \#0 ${this}::data data
1105  set tv [GetTreeview $this]
1106  set node [$tv selection get end] ;# current
1107  CompileNode $this $node
1108}
1109
1110#/////////////////////////////////////////////////////////////////////////////
1111proc ::TolProject::CompileNode {this node } {
1112#
1113# PURPOSE: Compiles a node and all its childs if parameter 'childs' is true.
1114#
1115# PARAMETERS:
1116#   this   -> Instance of tol project
1117#   node   -> Node active in treeview, which is compiled
1118#   childs -> flag that indicates if childs must be compiled too
1119#
1120#/////////////////////////////////////////////////////////////////////////////
1121  upvar \#0 ${this}::data data
1122  set tv [GetTreeview $this]
1123  set exclude [$tv item text $node Exclude]
1124  if ![string equal $exclude 1] { 
1125    if [IsCompilable $this $node] {
1126      #Tolcon_Trace "  Compilo $node"
1127      set data(compiling) 1
1128      set filename [$tv item text $node FileName]   
1129      ::TolConsole::Include \
1130        [::TolProject::ComputeFullPath $this $filename]
1131      set data(compiling) 0
1132    }
1133    foreach child [$tv item children $node] {
1134      CompileNode $this $child
1135    }
1136  }
1137}
1138
1139#/////////////////////////////////////////////////////////////////////////////
1140proc ::TolProject::CompileIfBeforeNode {this node ref} {
1141#
1142# PURPOSE: Compiles a node if it's after a node given as reference
1143#
1144# PARAMETERS:
1145#   this -> Instance of tol project
1146#   node -> Node to check if it's after a given node to compile it
1147#   ref  -> Node given as reference
1148#
1149#/////////////////////////////////////////////////////////////////////////////
1150  set tv [GetTreeview $this]
1151  #Tolcon_Trace "CompileIfBeforeNode. node: $node, ref: $ref"
1152  set isbefore [expr [$tv item order $node] < [$tv item order $ref]] 
1153  if !$isbefore {
1154    CompileNode $this $node
1155  } else  {
1156    foreach child [$tv item children $node] {
1157      CompileIfBeforeNode $this $child $ref
1158    }
1159  }
1160}
1161
1162#/////////////////////////////////////////////////////////////////////////////
1163proc ::TolProject::CompileUpToHereNode {this node ref} {
1164#
1165# PURPOSE: Compiles up to here
1166#
1167# PARAMETERS:
1168#   this -> Instance of tol project
1169#   node -> Node to check if it's after a given node to compile it
1170#   ref  -> Node given as reference
1171#
1172#/////////////////////////////////////////////////////////////////////////////
1173  set tv [GetTreeview $this]
1174  #Tolcon_Trace "CompileUpToHereNode. node: $node, ref: $ref"
1175  set isbefore [expr [$tv item order $node] < [$tv item order $ref]] 
1176  if {((![string eq root $node] && [string eq $node $ref]) ||
1177       (![string eq root $node] && $isbefore))} {
1178    CompileNode $this $node
1179  } else  {
1180    foreach child [$tv item children $node] {
1181      CompileUpToHereNode $this $child $ref
1182    }
1183  }
1184}
1185
1186#/////////////////////////////////////////////////////////////////////////////
1187proc ::TolProject::DecompileActiveNode {this args} {
1188#/////////////////////////////////////////////////////////////////////////////
1189  upvar \#0 ${this}::data data
1190  set tv [GetTreeview $this]
1191  set node [$tv selection get end] ;# current
1192  DecompileNode $this $node
1193}
1194
1195#/////////////////////////////////////////////////////////////////////////////
1196proc ::TolProject::DecompileNode {this node} {
1197#
1198# PURPOSE: Decompiles a node and all its childs.
1199#
1200# PARAMETERS:
1201#   this   -> Instance of tol project
1202#   node   -> Node active in treeview, which is decompiled
1203#
1204#/////////////////////////////////////////////////////////////////////////////
1205  set tv [GetTreeview $this]
1206  set exclude [$tv item text $node Exclude]
1207  if ![string equal $exclude 1] {
1208    if [IsCompilable $this $node] {
1209      set filename [$tv item text $node FileName]   
1210      catch {::TolInspector::DecompileFile \
1211             [::TolProject::ComputeFullPath $this $filename]}
1212      ::TolInspector::UpdateFileRoot
1213    }
1214    foreach child [$tv item children $node] {
1215      DecompileNode $this $child
1216    }
1217  }
1218}
1219
1220#/////////////////////////////////////////////////////////////////////////////
1221proc ::TolProject::ClearData {this} {
1222#
1223# PURPOSE: Clears some variables of data array relatives to attributes of
1224#          active node.
1225#
1226# PARAMETERS:
1227#   this -> Instance of tol project
1228#
1229#/////////////////////////////////////////////////////////////////////////////
1230  upvar \#0 ${this}::data data
1231  set data(name) ""
1232  set data(desc) ""
1233  set data(type) ""
1234  set data(exclude) 0
1235  set data(excludeTOL) 0
1236}
1237
1238#/////////////////////////////////////////////////////////////////////////////
1239proc ::TolProject::GetDataFromNode {this index} {
1240#
1241# PURPOSE: Sets some variables of data array, getting its values from a given
1242#          node.
1243#
1244# PARAMETERS:
1245#   this  -> Instance of tol project
1246#   index -> node index of a treeview to get values
1247#
1248#/////////////////////////////////////////////////////////////////////////////
1249  upvar \#0 ${this}::data data
1250  set tv [GetTreeview $this]
1251  set data(name)       [$tv item text $index FileName]
1252  set data(desc)       [$tv item text $index Description]
1253  set data(type)       [$tv item text $index Type]
1254  set data(exclude)    [$tv item text $index Exclude]
1255  set data(excludeTOL) [$tv item text $index ExcludeTOL]
1256}
1257
1258#/////////////////////////////////////////////////////////////////////////////
1259proc ::TolProject::GetImageFromType {type} {
1260#
1261# PURPOSE: Returns the image's path of a node given its type
1262#
1263# PARAMETERS:
1264#   type -> type of node
1265#
1266# RETURN: Image's path that correspond to type or "" if error
1267#
1268#/////////////////////////////////////////////////////////////////////////////
1269  set path ""
1270  switch -exact $type {
1271    ROOT { set path [Bitmap::get Files] }
1272    Fol  { set path [Bitmap::get DIRFile] }
1273    TOL -
1274    BDT -
1275    BST  { set path [Bitmap::get ${type}File] }
1276  }
1277  return $path
1278}
1279
1280#/////////////////////////////////////////////////////////////////////////////
1281proc ::TolProject::IsTerminal {this node} {
1282#
1283# PURPOSE: Determines if a node is terminal or not
1284#
1285# PARAMETERS:
1286#   this -> Instance of tol project
1287#   node -> node index of a treeview
1288#
1289# RETURN: True if node is terminal and false if not
1290#
1291#/////////////////////////////////////////////////////////////////////////////
1292  set terminal 0
1293  set tv [GetTreeview $this]
1294  set type [$tv item text $node Type]
1295  switch $type {
1296    Fol -
1297    ROOT { set terminal 0 }
1298    TOL -
1299    BDT -
1300    BST { set terminal 1 }
1301  }
1302  return $terminal
1303}
1304
1305#/////////////////////////////////////////////////////////////////////////////
1306proc ::TolProject::IsCompilable {this node} {
1307#
1308# PURPOSE: Determines if a node is compilable or not
1309#
1310# PARAMETERS:
1311#   this -> Instance of tol project
1312#   node -> node index of a treeview
1313#
1314# RETURN: True if node is compilable and false if not
1315#
1316#/////////////////////////////////////////////////////////////////////////////
1317  set compilable 0
1318  set tv [GetTreeview $this]
1319  set type [$tv item text $node Type]
1320  switch $type {
1321    Fol -
1322    ROOT { set compilable 0 }
1323    TOL -
1324    BDT -
1325    BST {
1326        set compilable 1
1327    }
1328  }
1329  return $compilable
1330}
1331
1332#/////////////////////////////////////////////////////////////////////////////
1333proc ::TolProject::DialogType {this path} {
1334#
1335# PURPOSE: Shows a dialog to ask for the type of a node
1336#
1337# PARAMETERS:
1338#   this -> Instance of tol project
1339#   path -> dialog's parent path
1340#
1341#/////////////////////////////////////////////////////////////////////////////
1342  #Type node dialog
1343  set tv [GetTreeview $this]
1344  set dialog [Dialog $tv.dt -title [mc "Select node type"]\
1345          -modal local -parent $tv]
1346  wm resizable $dialog 0 0
1347  wm protocol $dialog WM_DELETE_WINDOW \
1348          [list ::TolProject::OptionsDestroy $this $dialog]
1349  set w [$dialog getframe]
1350 
1351  set ${this}::data(type) TOL
1352  set f [labelframe $w.f -text [mc "Node type"]]
1353  radiobutton $f.rbTOL -text [mc "TOL file"] -value TOL -highlightthickness 0\
1354        -pady 0 -variable ${this}::data(type)
1355  radiobutton $f.rbBDT -text [mc "BDT file"] -value BDT -highlightthickness 0\
1356        -pady 0 -variable ${this}::data(type)
1357  radiobutton $f.rbBST -text [mc "BST file"] -value BST -highlightthickness 0\
1358        -pady 0 -variable ${this}::data(type)
1359  radiobutton $f.rbFol -text [mc "Folder"]   -value Fol -highlightthickness 0\
1360        -pady 0 -variable ${this}::data(type) 
1361
1362  grid $f.rbTOL $f.rbBDT -sticky nw -padx 0
1363  grid $f.rbBST $f.rbFol -sticky nw -padx 0
1364 
1365 
1366 
1367   set w_bbox \
1368          [ButtonBox $w.bb -orient horizontal -spacing 10 -padx 0 -pady 0 \
1369          -homogeneous false]
1370    $w_bbox add -text [mc "Accept"] -relief link \
1371          -helptext [mc "Continue"] \
1372          -image [::Bitmap::get accept] -compound left -padx 5 -pady 1 \
1373          -command [list ::TolProject::DialogTypeOK $this $dialog]
1374    $w_bbox add -text [mc "Cancel"] -relief link \
1375          -helptext [mc "Cancel"]\
1376          -image [::Bitmap::get cancelx] -compound left -padx 5 -pady 1 \
1377          -command [list ::TolProject::DialogTypeDestroy $this $dialog]
1378   
1379  pack $w_bbox -expand true -fill x    -side bottom
1380  pack $f      -expand true -fill both
1381
1382  bind $dialog <F1> "ShowHelp Tb4Edp"
1383  $dialog draw
1384}
1385
1386#/////////////////////////////////////////////////////////////////////////////
1387proc ::TolProject::DialogTypeOK {this dialog} {
1388#
1389# PURPOSE:
1390#
1391# PARAMETERS:
1392#   this   -> Instance of tol project
1393#   dialog -> Get type dialog
1394#
1395#/////////////////////////////////////////////////////////////////////////////
1396  upvar \#0 ${this}::data data
1397 
1398  destroy $dialog
1399}
1400
1401#/////////////////////////////////////////////////////////////////////////////
1402proc ::TolProject::DialogTypeDestroy {this dialog} {
1403#
1404# PURPOSE: Destroy get type dialog
1405#
1406# PARAMETERS:
1407#   this   -> Instance of tol project
1408#   dialog -> Get type dialog
1409#
1410#/////////////////////////////////////////////////////////////////////////////
1411  upvar \#0 ${this}::data data
1412  set data(type) -1
1413  destroy $dialog
1414}
1415
1416#/////////////////////////////////////////////////////////////////////////////
1417proc ::TolProject::DialogAttributes {this path title} {
1418#
1419# PURPOSE: Shows a dialog to ask for the attributes of a node
1420#
1421# PARAMETERS:
1422#   this  -> Instance of tol project
1423#   path  -> dialog's parent path
1424#   title ->
1425#
1426#/////////////////////////////////////////////////////////////////////////////
1427  upvar \#0 ${this}::data data
1428  #Attributes node dialog
1429  set tv [GetTreeview $this]
1430  set dialog [Dialog $tv.da -title $title -modal local -parent $tv\
1431     -default 0 -cancel 1]
1432  wm resizable $dialog 0 0
1433  wm protocol $dialog WM_DELETE_WINDOW \
1434          [list ::TolProject::OptionsDestroy $this $dialog]
1435  set w [$dialog getframe]
1436 
1437  set f1 [labelframe $w.f1 -text [mc "File name"]]
1438 
1439  switch -exact $data(type) {
1440    TOL {
1441      set typelist {{"Tol Files" {".tol"}} {"All Files" {"*"}}}
1442      set defExt   .tol
1443    }
1444    BDT {
1445      set typelist {{"Bayes Data Table" {".bdt"}} {"All Files" {"*"}}}
1446      set defExt   .bdt
1447    }
1448    BST {
1449      set typelist {{"Bayes Struct Table" {".bst"}} {"All Files" {"*"}}}
1450      set defExt   .bst
1451    }
1452    default {
1453      set typelist {{"All Files" {"*"}}}
1454      set defExt ""
1455    }
1456  }
1457
1458  # This passes -initialdir to ::Objects::ChooseFileCreate
1459  # which might need further study
1460  entry  $f1.eFile -width 50 -textvariable ${this}::data(name)
1461  ::Objects::ChooseFileCreate ${this}::data(name) $f1.bFile \
1462    -filetypes $typelist -defaultextension $defExt \
1463    -initialdir $data(lastOpenedNodeDir)
1464 
1465  set f2 [labelframe $w.f2 -text [mc "Description"]]
1466  entry $f2.description -width 60 -textvariable ${this}::data(desc)
1467
1468  checkbutton $w.chExclude -text [mc "Exclude in TOLBase"] \
1469            -variable ${this}::data(exclude)
1470
1471  checkbutton $w.chExcludeTOL -text [mc "Exclude in tol.exe"] \
1472        -variable ${this}::data(excludeTOL)
1473
1474  if {[string equal $data(type) "Fol"] ||
1475      [string equal $data(type) "ROOT"] } {
1476    grid $f1.eFile -sticky nw -padx 2 -pady 2
1477  } else  {
1478    grid $f1.eFile $f1.bFile -sticky nw -padx 2 -pady 2
1479  }
1480  grid $f2.description     -sticky nw -padx 2 -pady 2
1481
1482  set w_bbox \
1483    [ButtonBox $w.bb -orient horizontal -spacing 10 -padx 0 -pady 0 \
1484    -homogeneous false]
1485  $w_bbox add -text [mc "Accept"] -relief link \
1486    -helptext [mc "Continue"] \
1487    -image [::Bitmap::get accept] -compound left -padx 5 -pady 1 \
1488    -command [list ::TolProject::DialogAttributesOK $this $dialog]
1489  $w_bbox add -text [mc "Cancel"] -relief link \
1490    -helptext [mc "Cancel selection"]\
1491    -image [::Bitmap::get cancelx] -compound left -padx 5 -pady 1 \
1492    -command [list ::TolProject::DialogAttributesDestroy $this $dialog]
1493 
1494  grid $f1 - -sticky news
1495  grid $f2 - -sticky news
1496  grid $w.chExclude $w.chExcludeTOL -sticky nw -pady 2
1497  grid $w_bbox                       -sticky ns -pady 2 -columnspan 2
1498
1499  focus $f1.eFile
1500 
1501  bind $dialog <F1> "ShowHelp Tb4Edp"
1502  $dialog draw
1503
1504}
1505
1506#/////////////////////////////////////////////////////////////////////////////
1507proc ::TolProject::DialogAttributesOK {this dialog} {
1508#
1509# PURPOSE:
1510#
1511# PARAMETERS:
1512#   this   -> Instance of tol project
1513#   dialog -> Get type dialog
1514#
1515#/////////////////////////////////////////////////////////////////////////////
1516  upvar \#0 ${this}::data data
1517   
1518  destroy $dialog
1519}
1520
1521#/////////////////////////////////////////////////////////////////////////////
1522proc ::TolProject::DialogAttributesDestroy {this dialog} {
1523#
1524# PURPOSE: Destroy get type dialog
1525#
1526# PARAMETERS:
1527#   this   -> Instance of tol project
1528#   dialog -> Get type dialog
1529#
1530#/////////////////////////////////////////////////////////////////////////////
1531  upvar \#0 ${this}::data data
1532  set data(name) ""
1533  destroy $dialog
1534}
1535
1536#/////////////////////////////////////////////////////////////////////////////
1537# OPTIONS
1538#/////////////////////////////////////////////////////////////////////////////
1539
1540#/////////////////////////////////////////////////////////////////////////////
1541proc ::TolProject::CmdOptions {this} {
1542#
1543# PURPOSE: Creates a dialog options for Tol Project Editors
1544#
1545# PARAMETERS:
1546#   this -> Instance of tol project
1547#
1548#/////////////////////////////////////////////////////////////////////////////
1549  set path [GetTreeview $this]
1550  set dialog [Dialog $path.d -title [mc "TOL Project Editor Options"]\
1551            -modal local -parent $path]
1552  wm resizable $dialog 0 0
1553  wm protocol $dialog WM_DELETE_WINDOW \
1554        [list ::TolProject::OptionsDestroy $this $dialog]
1555  set w [$dialog getframe]
1556  set w_tabset [NoteBook $w.nb -tabbevelsize 8 -tabpady {2 6} -font {Arial 8}]
1557  #insertar tabset
1558  set num_i 0
1559  foreach lab_i [list Others] {
1560    $w_tabset insert $num_i $lab_i -text "  [mc $lab_i]  " -background \#d9d9d9
1561    set tab_i [$w_tabset getframe $lab_i]
1562    $tab_i configure -borderwidth 2 -background \#d9d9d9
1563    incr num_i   
1564    set f$num_i [frame $tab_i.f]
1565    pack $tab_i.f -fill both -expand yes 
1566  }
1567  $w_tabset raise [$w_tabset pages 0]
1568     
1569  OptionsGet $this
1570  OptionsCreateOthers  $this $f1 
1571  OptionsCheck $this
1572   
1573  set w_bbox \
1574    [ButtonBox $w.bb -orient horizontal -spacing 10 -padx 0 -pady 0 \
1575    -homogeneous false]
1576  $w_bbox add -text [mc "Accept"] -relief link \
1577    -helptext [mc "Accept"] \
1578    -image [::Bitmap::get accept] -compound left -padx 5 -pady 1 \
1579    -command [list ::TolProject::OptionsOK $this $dialog]
1580  $w_bbox add -text [mc "Cancel"] -relief link \
1581    -helptext [mc "Cancel"]\
1582    -image [::Bitmap::get cancelx] -compound left -padx 5 -pady 1 \
1583    -command [list ::SetGraphDialog::Cancel $dialog]
1584   
1585  pack $w_bbox   -fill x -expand false -side bottom
1586  $w_tabset compute_size
1587  pack $w_tabset -fill both -expand true
1588
1589  bind $dialog <F1> "ShowHelp Tb4EdpOpc"
1590  $dialog draw
1591}
1592
1593#/////////////////////////////////////////////////////////////////////////////
1594proc ::TolProject::OptionsCreateOthers {this w} {
1595#
1596# PURPOSE: Creates a frame with general options as number of files edited
1597#          recently
1598#
1599# PARAMETERS:
1600#   this -> Instance of tol project
1601#   w    -> widget's path to allocate the frame
1602#
1603#/////////////////////////////////////////////////////////////////////////////
1604  variable tmpOpt
1605   
1606  TitleFrame $w.tf1 -text [mc "General Options"]
1607  set f1 [$w.tf1 getframe]
1608   
1609  checkbutton $f1.chEdited -text [mc "Files edited recently"]\
1610          -variable ::TolProject::tmpOpt(var,chEdited)\
1611          -command [list ::TolProject::OptionsCheckEdited $this]
1612   
1613  set tmpOpt(widget,edited) [SpinBox $f1.sbEdited -justify right -width 4 \
1614          -editable 0 -range {0 10} \
1615          -textvariable ::TolProject::tmpOpt(var,numEdited)]
1616  label $f1.lFiles -text [mc files]
1617 
1618  frame $f1.f -width 25
1619   
1620  grid $f1.f $f1.chEdited     $f1.sbEdited     $f1.lFiles -sticky nw -padx 2
1621  grid rowconfigure    $f1 0 -weight 1
1622  grid columnconfigure $f1 3 -weight 1
1623   
1624  grid $w.tf1 -sticky news -padx 2
1625   
1626  grid rowconfigure    $w 1 -weight 1
1627  grid rowconfigure    $w 2 -weight 2
1628  grid columnconfigure $w 0 -weight 1
1629}
1630
1631#/////////////////////////////////////////////////////////////////////////////
1632proc ::TolProject::OptionsGet {this} {
1633#
1634# PURPOSE: Gets all options variables values from ini file  and copies them
1635#          to the temporary tmpOpt array.
1636#
1637# PARAMETERS:
1638#   this   -> Instance of tol project
1639#
1640#/////////////////////////////////////////////////////////////////////////////
1641  variable options
1642  variable tmpOpt
1643  set tmpOpt(var,chEdited)   $options(chEdited)
1644  set tmpOpt(var,numEdited)  $options(numEdited)
1645}
1646
1647#/////////////////////////////////////////////////////////////////////////////
1648proc ::TolProject::OptionsSet {this} {
1649#
1650# PURPOSE: Copies all .
1651#
1652# PARAMETERS:
1653#   this   -> Instance of tol project
1654#
1655#/////////////////////////////////////////////////////////////////////////////
1656  variable options
1657  variable tmpOpt
1658   
1659  regsub -all var, [array names ::TolProject::tmpOpt var,*] "" optNames
1660  foreach it $optNames {
1661    set options($it) $tmpOpt(var,$it)
1662  } 
1663}
1664
1665#/////////////////////////////////////////////////////////////////////////////
1666proc ::TolProject::OptionsCheck {this} {
1667#
1668# PURPOSE: Checks for all widgets from dialog options that need to be checked
1669#          for enabling/disabling other associated controls.
1670#
1671# PARAMETERS:
1672#   this   -> Instance of tol project
1673#
1674#/////////////////////////////////////////////////////////////////////////////
1675  OptionsCheckEdited           $this
1676}
1677
1678#/////////////////////////////////////////////////////////////////////////////
1679proc ::TolProject::OptionsCheckEdited {this} {
1680#
1681# PURPOSE: Checks if option chEdited is checked and enables/disabled other
1682#          associated controls.
1683#
1684# PARAMETERS:
1685#   this   -> Instance of tol project
1686#
1687#/////////////////////////////////////////////////////////////////////////////
1688  variable tmpOpt
1689  if {!$tmpOpt(var,chEdited)} {     
1690    $tmpOpt(widget,edited) configure -state disabled
1691  } else  {
1692    $tmpOpt(widget,edited) configure -state normal
1693  }
1694}
1695
1696#/////////////////////////////////////////////////////////////////////////////
1697proc ::TolProject::OptionsDestroy {this dialog} {
1698#
1699# PURPOSE: Destroy options dialog
1700#
1701# PARAMETERS:
1702#   this   -> Instance of tol project
1703#   dialog -> Options dialog
1704#
1705#/////////////////////////////////////////////////////////////////////////////
1706  variable tmpOpt
1707   
1708  array unset tmpOpt
1709  destroy $dialog
1710}
1711
1712#///////////////////////////////////////////////////////////////////////////// 
1713proc ::TolProject::OptionsApply {this} {
1714#
1715# PURPOSE: Applies options from the options dialog
1716#
1717# PARAMETERS:
1718#   this   -> Instance of tol project
1719#
1720#/////////////////////////////////////////////////////////////////////////////
1721  OptionsSet $this
1722}
1723
1724#/////////////////////////////////////////////////////////////////////////////
1725proc ::TolProject::OptionsOK {this dialog} {
1726#
1727# PURPOSE: Applies options and closes options dialog
1728#
1729# PARAMETERS:
1730#   this   -> Instance of tol project
1731#   dialog -> Options dialog
1732#
1733#/////////////////////////////////////////////////////////////////////////////
1734  OptionsApply   $this
1735  OptionsDestroy $this $dialog
1736}
1737
1738#/////////////////////////////////////////////////////////////////////////////
1739# INIFILE
1740#/////////////////////////////////////////////////////////////////////////////
1741
1742#/////////////////////////////////////////////////////////////////////////////
1743proc ::TolProject::ReadIniSpecial {} {
1744#
1745# PURPOSE: Reads common Edit Table options from .ini file. This options are
1746#          common for all instances of Tol Project Editor. They are read just
1747#          one time.
1748#
1749#/////////////////////////////////////////////////////////////////////////////
1750  variable options
1751  global toltk_options
1752
1753  set rini ::iniFile::Read
1754  set options(chEdited)   [$rini TolProject saveRecent  1]
1755  set options(numEdited)  [$rini TolProject numRecent   8]
1756  set options(edited)     [$rini TolProject recent      {}]
1757
1758  set options(font)       [$rini TolProject font  $toltk_options(fonts,Fixed)]
1759  set options(lastDir)    [$rini TolProject lastDir  ""]
1760}
1761
1762#/////////////////////////////////////////////////////////////////////////////
1763proc ::TolProject::WriteIni {this} {
1764#
1765# PURPOSE: Write common Tol Projects options to .ini file
1766#
1767# PARAMETERS:
1768#   this  -> Instance of tol project
1769#
1770#/////////////////////////////////////////////////////////////////////////////
1771  variable options
1772  upvar \#0 ${this}::data data
1773  set wini ::iniFile::Write
1774
1775  # Common options
1776  $wini TolProject saveRecent   $options(chEdited)
1777  $wini TolProject numRecent    $options(numEdited)
1778  $wini TolProject recent       $options(edited)
1779  $wini TolProject font         $options(font)
1780  $wini TolProject lastDir      $options(lastDir)
1781
1782  ::iniFile::Flush
1783}
1784
1785#/////////////////////////////////////////////////////////////////////////////
1786# Métodos que estaban en ::BayesTreeview (bftrview.tcl)
1787#/////////////////////////////////////////////////////////////////////////////
1788
1789#/////////////////////////////////////////////////////////////////////////////
1790proc ::TolProject::WtreeFromFile {tv path {proc ""}} {
1791#
1792# PURPOSE: Loads a wtree info data from a text especification file of a wtree.
1793#
1794# PARAMETERS:
1795#   tv   -> wtree's path
1796#   path -> name of file
1797# proc -> procedure that converts type node to the path of the image of node
1798#
1799# RETURN: Returns 1 if wtree has been loaded correctly or 0 if not.
1800#
1801#/////////////////////////////////////////////////////////////////////////////
1802  if ![file exists $path] {
1803    return -code error "File $path doesn't exist"
1804  }
1805  set fd [iniparse:openfile $path]
1806  BNodeFromFile $tv root "" $fd $proc
1807  iniparse:closefile $fd
1808  return 1
1809}
1810
1811#/////////////////////////////////////////////////////////////////////////////
1812proc ::TolProject::WtreeToFile {tv path} {
1813#
1814# PURPOSE: Saves a wtree info data into a text especification file of a wtree.
1815#
1816# PARAMETERS:
1817#   tv   -> wtree's path
1818#   path -> name of file
1819#
1820# RETURN: Returns 1 if file has been saved correctly or 0 if not.
1821#
1822#/////////////////////////////////////////////////////////////////////////////
1823  #borrar archivo pq iniparse:openfile abre para solo lectura si existe
1824  file delete $path
1825  set fd [iniparse:openfile $path]
1826  BNodeToFile $tv root $fd
1827  iniparse:closefile $fd
1828  return 1
1829}
1830
1831#/////////////////////////////////////////////////////////////////////////////
1832proc ::TolProject::BNodeToFile {tv index fd} {
1833#
1834# PURPOSE: Saves a wtree's node info data into a text file.
1835#
1836# PARAMETERS:
1837#   tv    -> wtree's path
1838#   index -> wtree node index
1839#   fd    -> channel identifier of text file
1840#
1841#/////////////////////////////////////////////////////////////////////////////
1842  set key $index
1843
1844  # Guardar data del nodo actual
1845  set columnNames [list FileName Description Type Exclude ExcludeTOL]
1846  foreach item $columnNames {
1847    writeini $fd $key $item [$tv item text $index $item]
1848  }
1849 
1850  writeini $fd $key Label [$tv item text $index FileName]
1851  # Guardar sus hijos
1852  writeini $fd $key Children [$tv item children $index]
1853
1854  # Llamar recursivamente para los hijos
1855  foreach child [$tv item children $index] {
1856    BNodeToFile $tv $child $fd
1857  }
1858}
1859
1860#/////////////////////////////////////////////////////////////////////////////
1861proc ::TolProject::BNodeFromFile {tv index parent fd {imgFromType ""}} {
1862#
1863# PURPOSE: Loads a wtree's node info data from a text file.
1864#
1865# PARAMETERS:
1866#   tv     -> wtree's path
1867#   index  -> wtree node index
1868#   parent -> wtree node's parent index
1869#   fd     -> channel identifier of text file
1870#
1871#/////////////////////////////////////////////////////////////////////////////
1872  set key $index
1873  set image "" 
1874  set filename ""
1875  set description ""
1876  set type ""
1877  set exclude 0
1878  set excludeTOL 0 ;#@ puede que no lo tenga el prj
1879  foreach item [readini $fd $key] {
1880    set value [readini $fd $key $item]
1881    switch -exact $item {
1882      FileName { set filename $value }
1883      Description { set description $value }
1884      Type { set type $value }
1885      Exclude { set exclude $value }
1886      ExcludeTOL { set excludeTOL $value }
1887      Label { set void 0 }     
1888    }
1889    if {[string equal $item "Type"] && ![string equal $imgFromType ""]} {
1890      set img [$imgFromType $value]
1891      if ![string equal $img ""] {
1892        set image $img
1893      }
1894    }
1895  }
1896  if ![string equal $parent ""] {
1897    #@ se inserta un nodo
1898    if { $type eq "Fol" } {
1899      set hasbutton 1
1900    } else {
1901      set hasbutton 0
1902    } 
1903    set idx [$tv item create -parent $parent -button $hasbutton -open 0]
1904    $tv item image $idx FileName $image
1905    $tv item text $idx FileName $filename Description $description \
1906      Type $type Exclude $exclude ExcludeTOL $excludeTOL 
1907  } else {
1908    #@ se actualiza root
1909    $tv item image root FileName $image
1910    $tv item text root FileName $filename Description $description \
1911      Type $type Exclude $exclude ExcludeTOL $excludeTOL
1912    set idx root
1913  } 
1914  # Llamar recursivamente para los hijos
1915  foreach child [readini $fd $key Children] {
1916    BNodeFromFile $tv $child $idx $fd $imgFromType
1917  }
1918}
1919
1920::TolProject::ReadIniSpecial
Note: See TracBrowser for help on using the repository browser.