source: tol/tolbase/lib/toltk/tolprj.tcl @ 88e6fd7

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

Se eliminan algunos espacios en blanco y saltos de línea.

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

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