source: tol/tolbase/lib/toltk/tolbase.tcl @ c14b554

1941-docker-image-to-testdevel
Last change on this file since c14b554 was c14b554, checked in by Jorge Pérez <josp.jorge@…>, 18 years ago

merging from NameBlock/VMatrix branch

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

  • Property mode set to 100644
File size: 80.8 KB
Line 
1#/////////////////////////////////////////////////////////////////////////////
2# FILE    : tolbase.tcl
3# PURPOSE : This file
4#/////////////////////////////////////////////////////////////////////////////
5
6#/////////////////////////////////////////////////////////////////////////////     
7if { 0 } {
8# 
9#/////////////////////////////////////////////////////////////////////////////       
10  set toltk_script_path [file dirname [info script]]
11 
12  puts $toltk_script_path
13   
14  if { [lsearch $auto_path $toltk_library] == -1 } {
15    lappend auto_path $toltk_library
16  }
17  if { ![info exists blt_libPath] } {
18    set blt_libPath [file join $toltk_library blt]
19  }
20  if { ![info exists env(BLT_LIBRARY)] } {
21    set env(BLT_LIBRARY) [file join $toltk_library blt]
22  }
23  package require BWidget
24 
25  source [file join $toltk_script_path "prjmenu.tcl"]
26  source [file join $toltk_script_path "tolinspect.tcl"]
27  source [file join $toltk_script_path "toltable.tcl"]
28  source [file join $toltk_script_path "calendar.tcl"]
29  source [file join $toltk_script_path "editSelector.tcl"]
30  source [file join $toltk_script_path "selector.tcl"]
31  source [file join $toltk_script_path "bayesgraph.tcl"]
32  source [file join $toltk_script_path "sergraph.tcl"]
33  source [file join $toltk_script_path "autocorgraph.tcl"]
34  source [file join $toltk_script_path "graph.tcl"]
35  source [file join $toltk_script_path "BfString.tcl"]
36  source [file join $toltk_script_path "BfList.tcl"]
37  source [file join $toltk_script_path "newButtonDiag2.tcl"]
38  source [file join $toltk_script_path "newToolbarDiag.tcl"]
39} else {
40    if {$::tcl_platform(platform) eq "unix"} {
41        proc ::dnd {args} {}
42    } else {
43        package require tkdnd
44        source [file join $toltk_script_path "newButtonDiag2.tcl"]
45        source [file join $toltk_script_path "newToolbarDiag.tcl"]
46    }
47}
48
49global tcl_platform
50if { [string equal $tcl_platform(platform) "unix"] } {
51  source [file join $toltk_script_path "panedw.tcl"]
52} else {
53  source [file join $toltk_script_path "panedw.tcl"]
54}
55
56#source [file join $toltk_script_path "scrollw.tcl"]
57
58namespace eval ::TolConsole {
59  # widgets -> array with entries:
60  #   inspector -> toplevel containing inspector and tabs of info.
61  #   tabset    -> tabset containing: eval, output & info.
62  #   eval      -> text for evaluating.
63  #   output    -> text with the output.
64  #   info      -> text with info on inspector objects.
65  # data -> array with entries:
66  #   (path) -> directory of the last included file
67  #   (included) -> last included files
68  #   (font,eval)
69  #   (font,output)
70  #   (font,info)
71  #   (viewmode)
72  variable data
73  variable widgets
74  variable time     [clock clicks -milliseconds]
75  variable languages [list de German en English es Spanish fr French \
76    it Italian ja Japanese nl Dutch po Portuguese ru Russian sv Swedish \
77    zh Chinese]
78}
79
80
81#/////////////////////////////////////////////////////////////////////////////
82proc ::TolConsole::Create { w } {
83#
84# PURPOSE: Creates TolBase main windows (tol inspector + eval/output/info
85#          windows)
86# PARAMTERS:
87#  w: path of father the widget inspector
88#  name: name of widget inspector
89#
90# RETURN: path of widget inspector
91#
92#/////////////////////////////////////////////////////////////////////////////
93  variable widgets
94  variable data
95
96  # connection BODBC
97  set data(bodbc) [$::project::data(bodbc) connection \
98                     -name TolBase \
99                     -stdtolcon 1  \
100                     -stdtclcon 0  \
101                     -iniconfig TolBaseODBC \
102                     -savealias 1  \
103                     -saveuser  1]
104  Tolcon_Trace "TolConsole.Create : data(bodbc)=$data(bodbc)"
105
106  #Control de modo de visualizacion
107  #Frame
108
109  set path [::project::CreateForm \
110              -iniconfig ObjectInspector \
111              -title [mc {Inspector}] -width 700 -height 400 \
112              -helpkey "Tb4Ins"]
113  $path configure -closecmd "$path minimize; return 0"
114  set pathf [$path getframe]
115                                           
116  set pw1   [PanedWindow $pathf.pw -side right -pad 0 -width 4]
117  set pane1 [$pw1 add -weight $data(geometry,wtop)]
118  set pane2 [$pw1 add -weight $data(geometry,wbottom)]
119
120#  set widgets(pw)           $path
121  set widgets(pw)           $pw1
122  set widgets(panes,top)    $pane1
123  set widgets(panes,bottom) $pane2
124  # object inspector component
125
126  ::TolInspector::Create $pane1.ti \
127      -onselcmd ::TolConsole::OnInfo \
128      -wleft $data(geometry,wleft) \
129      -wright $data(geometry,wright)
130
131  ::TolInspector::OnBusy ::TolConsole::OnBusy
132
133  # tabset for eval, output & description
134  set widgets(tabset) $pane2.ts
135  set w_tabset [::blt::tabset $widgets(tabset) -side top -relief flat \
136                    -bd 0 -outerpad 0 -tier 2 -slant right -textside right \
137                    -highlightthickness 0]
138  set sw2 [ScrolledWindow $w_tabset.sw2 -auto both]
139  set sw3 [ScrolledWindow $w_tabset.sw3 -auto both]
140   
141  $w_tabset insert end \
142     Eval   -text "[mc Eval]   <Ctrl+A>" -selectbackground \#d9d9d9 -bg gray75 -pady 0\
143     Output -text "[mc Output] <Ctrl+O>" -selectbackground \#d9d9d9 -bg gray75 -pady 0\
144     Info   -text "[mc Info]   <Ctrl+I>" -selectbackground \#d9d9d9 -bg gray75 -pady 0
145
146  # OUTPUT CONSOLE COMPONENT 
147  set widgets(output) $sw2.out
148  set w_output [text $widgets(output) -wrap none -cursor ""\
149     -state disabled -font $data(font,output)]
150  $sw2 setwidget $w_output
151
152  # EVAL CONSOLE COMPONENT     
153  set feval $w_tabset.f 
154  CreateEvalWindow $feval
155
156  # configuro los mensajes del output
157  $w_output tag configure errorTag   -foreground $data(colorErr)
158  $w_output tag configure warningTag -foreground $data(colorWar)
159  set data(output,TAG,E) errorTag
160  set data(output,TAG,W) warningTag
161
162  set menu [::BayesText::MenuCreate $w_output]
163  # Añadimos la opción de recuperar la salida
164  $menu insert 0 separator
165  $menu insert 0 command -label [mc "Recover from log"] \
166                  -command [list ::TolConsole::Recover $w_output]
167  $menu insert 0 command -label [mc "Delete all"] \
168                  -command [list ::BayesText::DeleteAll $w_output]
169
170  # Habilitamos la opción de borrar
171  $menu entryconfigure [mc "Delete"] -state normal
172  bind $w_output <Delete>    [list ::BayesText::Delete $w_output]
173     
174  # INFO CONSOLE COMPONENT
175  set widgets(info) $sw3.info
176  set w_info [text $widgets(info) -wrap word -cursor ""\
177     -state disabled -font $data(font,info)]
178  $sw3 setwidget $w_info
179  ::BayesText::MenuCreate $w_info
180   
181  set def_font [$w_info cget -font]
182  if { [lsearch -exact [font names] fnBold] == -1 } {
183    if {[string length [lindex $def_font 1]]} {
184      font create fnBold -family [lindex $def_font 0] \
185            -size [lindex $def_font 1] -weight bold
186    } else {
187       font create fnBold -family [lindex $def_font 0] -size 10 -weight bold
188    }
189  }
190
191  # teclas acceso rapido solapas de Informacion
192  $path bind <Control-F4> +[list $path kill]
193 
194  bind $path <Control-KeyRelease> \
195      +[list ::TolConsole::OnControlKey %K %k]
196  $w_tabset tab configure Eval   -window $feval -fill both -padx 0
197  $w_tabset tab configure Output -window $sw2   -fill both -padx 0
198  $w_tabset tab configure Info   -window $sw3   -fill both -padx 0
199  pack $w_tabset -fill both -expand yes
200   
201  pack $pw1 -fill both -expand yes   
202  Configure
203 
204  bind . <Control-Key-k> +::tol::stop
205  bind Text <Control-Key-k> ""
206  return $path
207}
208
209#/////////////////////////////////////////////////////////////////////////////
210proc ::TolConsole::CreateEvalWindow {w} {
211#
212# PURPOSE: Creates eval window as widget w
213#
214#/////////////////////////////////////////////////////////////////////////////
215  variable widgets
216  variable data
217
218  set feval   [frame $w]
219  set sw1 [ScrolledWindow $feval.sw1 -auto both]
220  set widgets(eval) $sw1.eval
221
222  #Creamos text con resaltado TOL
223  set w_eval [::BayesText::CreateHLText $widgets(eval) tol \
224    -font $data(font,eval)]
225
226  set m [::BayesText::MenuCreate $w_eval]
227  # Añadimos la opcion de refrescar el resaltado en la ventana eval
228  $m insert 0 separator
229  $m insert 0 command -label [mc Refresh]   -accelerator F5\
230     -command [list ::BayesText::Refresh $w_eval]
231  $m insert 0 command -label [mc "Syntax Check"] -accelerator F7 \
232     -command [list ::BayesText::TolSyntaxCheck $w_eval]
233  $m insert 0 command -label [mc Decompile] -accelerator F8\
234     -command ::TolConsole::ClearConsole
235  $m insert 0 command -label [mc Compile]   -accelerator F9\
236     -command ::TolConsole::Compile
237
238  # Añadimos la opción de limpiar la ventana de eval
239  $m insert 0 separator
240  $m insert 0 command -label [mc "Delete all"] \
241     -command [list ::BayesText::DeleteAll $w_eval]
242  bind $w_eval <F9> "::TolConsole::Compile ; break"
243  bind $w_eval <F8> "::TolConsole::ClearConsole ; break"
244  bind $w_eval <F5> "::BayesText::Refresh $w_eval ; break"
245  bind $w_eval <F7> "::BayesText::TolSyntaxCheck $w_eval ; break"
246  bind $w_eval <F10> "::TolConsole::OpenEval ; break"
247 
248  ## 1) Create a horizontal toolbar frame...
249  set TF [::toolbar::ToolbarFrame $feval.toolbarFrame]
250    ## 2) Create a toolbar in this toolbar frame...
251    set tb1 [::toolbar::create $TF.tb1]
252    # add compile button
253    ::toolbar::addbutton $tb1 -image [::Bitmap::get "eval"] \
254      -statuswidget $widgets(sb,path) -tooltip "[mc Compile] (F9)"\
255      -command [list ::TolConsole::Compile]
256    # add decompile button
257    ::toolbar::addbutton $tb1 -image [::Bitmap::get "decom"] \
258      -statuswidget $widgets(sb,path) -tooltip "[mc Decompile] (F8)"\
259      -command [list ::TolConsole::ClearConsole]
260    # add syntax check button
261    ::toolbar::addbutton $tb1 -image [::Bitmap::get "syntaxcheck"] \
262      -statuswidget $widgets(sb,path) -tooltip "[mc Syntax Check] (F7)"\
263      -command [list ::BayesText::TolSyntaxCheck $w_eval]
264    #add Refresh button
265    ::toolbar::addbutton $tb1 -image [::Bitmap::get "refresh"] \
266      -statuswidget $widgets(sb,path) -tooltip "[mc Refresh] (F5)"\
267      -command [list ::BayesText::Refresh $w_eval]
268    #add History button
269    ::toolbar::addbutton $tb1 -image [::Bitmap::get "History"] \
270      -statuswidget $widgets(sb,path) -tooltip "[mc "Show history file"] (F10)"\
271      -command [list ::TolConsole::OpenEval]
272
273    ::toolbar::addseparator $tb1
274
275    ::toolbar::addbutton $tb1 -image [::Bitmap::get "delete"] \
276      -statuswidget $widgets(sb,path) \
277      -tooltip [mc "Delete all the messages of the window of output"] \
278      -command [list ::BayesText::DeleteAll $widgets(output)]
279
280    ## 4) Pack the toolbar inside the toolbar frame...
281    pack $tb1 -side left -fill y
282
283  ## 5) Pack the toolbar frame in our window...
284
285  # Si empacabamos la barra de botones debajo del editor de la ventana eval,
286  # cuando la ventana de Eval se hacía pequeña, la barra botones desaparecía
287  # Con la opción -before se evita esto
288
289  pack $sw1 -expand true -fill both -padx 0 -pady 0
290  pack $TF  -side top -fill both -padx 0 -pady 0 -before $sw1
291
292  $sw1 setwidget $w_eval
293}
294
295
296#/////////////////////////////////////////////////////////////////////////////
297proc ::TolConsole::OnControlKey {keysym keycode} {
298#
299# PURPOSE: Controla es uso de teclas rápidas para le ejecución de funciones
300#
301# PARAMETERS: keysym -> The keysym corresponding to the event,
302#                       substituted as a textual string
303#             keycode -> The keycode field from the event
304#
305#///////////////////////////////////////////////////////////////////////////
306  variable widgets
307  switch [string toupper $keysym] {
308    A { ShowWindow "eval"   }
309    O { ShowWindow "output" }
310    I { ShowWindow "info"   }
311  }
312}
313
314#///////////////////////////////////////////////////////////////////////////
315proc ::TolConsole::ShowWindow {win} {
316#///////////////////////////////////////////////////////////////////////////
317  variable widgets
318  #win can have values "eval" "output" "info"
319  switch -exact $win  {
320    "eval"   {
321      $widgets(tabset) select 0
322      $widgets(eval) mark set anchor insert
323    }
324    "output" {
325      $widgets(tabset) select 1
326    }
327    "info"   {
328      $widgets(tabset) select 2
329    }
330  }
331
332}
333
334#/////////////////////////////////////////////////////////////////////////////     
335proc ::TolConsole::Configure {} {
336# 
337#/////////////////////////////////////////////////////////////////////////////       
338  OptionsApplyDefDates
339}
340
341#/////////////////////////////////////////////////////////////////////////////
342  proc ::TolConsole::postIncluded {m {ord 0}} {
343#
344# PURPOSE: Fills a menu with the last included files from TolBase, according
345#          to information of 'data' variable.
346#
347# PARAMETERS:
348#   m  -> menu's path that will have the list of last included files
349#   ord -> flag that indicates if files must be shown sorted
350#
351#/////////////////////////////////////////////////////////////////////////////
352  variable data
353  $m delete 0 end
354  if $data(chIncluded) {
355    set data(included) [lrange $data(included) 0 [expr $data(numRecent)-1]]
356    if $ord {
357      set lst [lsort -ascii $data(included)]
358    } else {
359      set lst $data(included)
360    }
361    foreach w $lst {
362      #set w [lindex $w 0]
363      $m add command -label $w -command [list ::TolConsole::IncludeCmd $w]
364    }
365    if [llength $lst] {
366       $m add separator
367       $m add command -label [mc "Clear"]\
368             -command [list ::TolConsole::clearRecent]
369    }
370}
371}
372
373#/////////////////////////////////////////////////////////////////////////////
374  proc ::TolConsole::clearRecent {} {
375#
376# PURPOSE: Clears the list of last Recent files
377#
378#/////////////////////////////////////////////////////////////////////////////
379  variable data
380  set data(included) ""
381  ::iniFile::Write TolConsole recent       data(included)
382  ::iniFile::Flush
383}
384
385
386#/////////////////////////////////////////////////////////////////////////////
387  proc ::TolConsole::Format {value} {
388#
389# PURPOSE: Receives a value and if it's double, formats it according to
390#          the information of 'data' variable.
391#
392# PARAMETERS:
393#   value  -> value to format
394#
395# RETURN:  The value formated
396#
397#/////////////////////////////////////////////////////////////////////////////
398  variable data
399  set val $value
400  if [string is double -strict $value] {
401    if {$data(chExponential) &&
402       ![catch {expr log10($value) >= $data(numExponential)} result]} {
403      if $result {
404        if $data(chDecimals) {
405          set val [format %.$data(chDecimals)e $value]
406        } else {
407          set val [format %e $value]
408        }
409      } else  {
410        if $data(chDecimals) {
411          set val [format "%.$data(numDecimals)f" $value]
412        }
413      }
414    } else {
415      if $data(chDecimals) {
416        set val [format "%.$data(numDecimals)f" $value]
417      }
418    }
419  }
420  return $val
421}
422
423#/////////////////////////////////////////////////////////////////////////////     
424proc ::TolConsole::OnInfo { args } {
425# 
426#/////////////////////////////////////////////////////////////////////////////       
427  variable widgets
428 
429  set w_info $widgets(info)
430  set w_tabset $widgets(tabset)
431  $w_info configure -state normal
432  $w_info delete 1.0 end
433  switch [llength $args] {
434    0 {
435    }
436    1 {
437      #$w_info configure -wrap word
438      $w_info insert end [lindex $args 0]
439      $w_tabset select 2
440    }
441    default {
442      #$w_info configure -wrap none
443      foreach {icon grammar name value path desc} $args {}
444        foreach {prop val} [list "Grammar: " $grammar "Name: " $name "Value: " $value "Path: " $path] {
445        set idx_start [$w_info index "end -1 chars"]
446        $w_info insert end $prop
447        set idx_end   [$w_info index "end -1 chars"]
448        $w_info tag add tagLabel $idx_start $idx_end
449        if {[string equal $prop "Grammar: "]} {
450          $w_info image create end -image $icon
451          $w_info insert end "  "
452        }
453        $w_info insert end "$val\n"
454        $w_info tag add tagValue $idx_end [$w_info index "end -1 chars"]
455      }
456      $w_info tag configure tagLabel -font fnBold
457      $w_info tag configure tagValue -wrap none
458      if { [string length $desc] } {
459        set idx_start [$w_info index "end -1 chars"]
460        $w_info insert end "Description\n"
461        set idx_end [$w_info index "end -1 chars"]
462        $w_info tag add tagPropLabel $idx_start $idx_end
463        $w_info insert end $desc
464        $w_info tag add tagPropValue $idx_end [$w_info index "end -1 chars"]
465        $w_info tag configure tagPropLabel -font fnBold -underline 1
466        #$w_info tag configure tagPropValue -wrap word
467      }
468      $w_tabset select 2
469    }
470  }
471  $w_info configure -state disabled
472}
473
474#/////////////////////////////////////////////////////////////////////////////     
475proc ::TolConsole::Include {file} {
476# 
477#/////////////////////////////////////////////////////////////////////////////       
478  #::LoadStatus::Show $file
479
480  ::TolInspector::Busy
481  update
482  ::tol::include $file
483  ::TolInspector::UpdateFileRoot
484  ::TolInspector::NotBusy
485  #::LoadStatus::Hide
486}
487
488
489#/////////////////////////////////////////////////////////////////////////////
490proc ::TolConsole::Compile { } {
491#
492# PURPOSE: Compiles text of eval window. If any text is selected, then only
493#          selection is compiled, else all text is compiled.
494#
495#/////////////////////////////////////////////////////////////////////////////
496  variable widgets
497  set w_eval $widgets(eval)
498 
499  set tolexpr [::BayesText::GetSelectionOrAll $w_eval]
500  EvalExpr $tolexpr
501}
502
503#/////////////////////////////////////////////////////////////////////////////
504proc ::TolConsole::EvalExpr {tolexpr} {
505#
506# PURPOSE: Compiles a TOL expresion in TOL console
507#
508#/////////////////////////////////////////////////////////////////////////////
509  ::TolInspector::Busy
510  Tolcon_Trace "tolexpr = $tolexpr"
511  if { [string length $tolexpr] } {
512    ::tol::console eval $tolexpr
513    SaveEval $tolexpr
514  }
515  ::TolInspector::UpdateConsoleObj
516  ::TolInspector::NotBusy
517}
518
519#/////////////////////////////////////////////////////////////////////////////     
520proc ::TolConsole::SaveEval {txt} {
521# 
522#/////////////////////////////////////////////////////////////////////////////       
523  global home_path
524  set evalFile [file join $home_path "eval.tol"]
525
526  set texto ""
527  if { [file exists $evalFile] } {
528    set fd [open $evalFile r]
529    set texto [read -nonewline $fd]
530    close $fd
531  }
532  set fd [open $evalFile w]
533  set txt "// [::tol::date now {%W, %Y/%m/%d %h:%i:%s}]\n$txt\n\n"
534  puts -nonewline $fd $txt
535  puts -nonewline $fd $texto
536  close $fd
537}
538
539#/////////////////////////////////////////////////////////////////////////////     
540proc ::TolConsole::OpenEval {} {
541# 
542#/////////////////////////////////////////////////////////////////////////////       
543  global home_path
544  set evalFile [file join $home_path "eval.tol"]
545  if { ![file exists $evalFile] } {
546    set fd [open $evalFile w]
547    close $fd
548  }
549  ::Editor::Open $evalFile
550}
551
552#/////////////////////////////////////////////////////////////////////////////     
553proc ::TolConsole::OnConnect {alias user pass datasource} {
554# 
555#/////////////////////////////////////////////////////////////////////////////       
556  set name [GetUniqueName Real]
557  ::tol::console eval "Real $name = DBOpen(\"$alias\",\"$user\",\"$pass\");"
558  ::tol::console stack release $name
559}
560
561#/////////////////////////////////////////////////////////////////////////////     
562proc ::TolConsole::OnDisconnect {alias user pass datasource} {
563# 
564#/////////////////////////////////////////////////////////////////////////////       
565  set name [GetUniqueName Real]
566  ::tol::console eval "Real $name = DBClose(\"$alias\");"
567  ::tol::console stack release $name
568}
569
570#/////////////////////////////////////////////////////////////////////////////     
571proc ::TolConsole::DBConnect {} {
572# 
573#/////////////////////////////////////////////////////////////////////////////       
574  ::ODBCDialog::Create $::project::widgets(mainframe) "" "" "" \
575  ::TolConsole::OnConnect ::TolConsole::OnDisconnect
576}
577
578#/////////////////////////////////////////////////////////////////////////////     
579proc ::TolConsole::ClearConsole { } {
580# 
581#/////////////////////////////////////////////////////////////////////////////       
582  ::TolInspector::ClearConsoleObj
583  ::TolInspector::UpdateConsoleObj
584}
585
586#/////////////////////////////////////////////////////////////////////////////     
587proc ::TolConsole::OnBusy { state } {
588# 
589#/////////////////////////////////////////////////////////////////////////////       
590    variable widgets
591   
592    if { $state } {
593        $widgets(eval) configure -cursor watch
594        $widgets(tabset) configure -cursor watch
595       #  ::blt::busy hold .       
596    } else {
597        $widgets(eval) configure -cursor xterm
598        $widgets(tabset) configure -cursor ""
599      #  ::blt::busy release .     
600    }
601}
602
603
604#/////////////////////////////////////////////////////////////////////////////
605  proc ::TolConsole::ToEvalWindow { message } {
606#
607# PURPOSE: Writes a message in eval window and selects this tab (eval window)
608#
609# PARAMETERS:
610#   message -> Message to write in eval window
611#
612#/////////////////////////////////////////////////////////////////////////////
613  upvar \#0 ::TolConsole::widgets(tabset) w_tabset
614  upvar \#0 ::TolConsole::widgets(eval) w_eval
615
616  $w_eval insert end "$message\n"
617  $w_tabset select 0
618  $w_eval see end
619}
620
621#/////////////////////////////////////////////////////////////////////////////
622proc ::TolConsole::HciWriter { message } {
623# 
624#/////////////////////////////////////////////////////////////////////////////
625  variable widgets
626  variable data
627  variable time
628 
629  upvar \#0 ::TolConsole::widgets(tabset) w_tabset
630  upvar \#0 ::TolConsole::widgets(output) w_output
631  if $data(chWrite) {
632    $w_output configure -state normal
633    set tr_message [string trim $message]
634    # {<([^>]+)>([^<]+)</([^>]+)>}
635    if { [regexp -- {^<([^>]+)>(.+)</(.+)>} $tr_message -> start content end] } {
636      if {($start ne $end) || (($start ne "E") && ($start ne "W"))} {
637        $w_output insert end "$message"
638      } else {
639        set idx_start [$w_output index "end -1 char"]
640        $w_output insert end "$content\n"
641        set idx_end [$w_output index "end -1 char"]
642        $w_output tag add $data(output,TAG,$start) $idx_start $idx_end
643      }
644    } else {
645      $w_output insert end "$message"
646    }
647    $w_output configure -state disabled
648  }
649 
650  switch $data(updateType) {
651    always {
652      if $data(chWrite) {
653        $w_tabset select 1
654        $w_output see end     
655      }
656      update
657    }
658    each   {
659      set time_now [clock clicks -milliseconds]
660      set dif [expr $time_now - $time]
661      if { $dif >= $data(updateSec) } {
662        set time $time_now
663        if $data(chWrite) {
664          $w_tabset select 1
665          $w_output see end
666        }
667        update
668      }
669    }
670    never  { }
671  }
672}
673
674#/////////////////////////////////////////////////////////////////////////////
675proc ::Tol_HciWriter { message } {
676# 
677#/////////////////////////////////////////////////////////////////////////////
678  ::TolConsole::HciWriter $message
679}
680
681#/////////////////////////////////////////////////////////////////////////////
682proc ::TolConsole::Recover {editor} {
683# 
684#/////////////////////////////////////////////////////////////////////////////
685  set state [$editor cget -state]
686  $editor configure -state normal
687  $editor delete 1.0 end
688
689  set cmd "Text $nRes = PutDumpFile(\"\");"
690  ::tol::console eval $cmd
691  array set inf [TclInfoVar Text $nRes]
692  eval "set file $inf(CONTENT)"
693  ::tol::console stack release $nRes
694   
695  if { ![catch {set fd [open $file r] } msgerr] } {
696    $editor insert 1.0 [read -nonewline $fd]
697    #HciWriter [read -nonewline $fd]
698    close $fd
699  }
700  tk::TextSetCursor $editor end
701  $editor configure -state $state
702}
703
704#/////////////////////////////////////////////////////////////////////////////
705proc ::TolConsole::MainFrame { w {tolcon 1} } {
706# 
707#/////////////////////////////////////////////////////////////////////////////
708  variable widgets
709  variable data
710
711  #bind ::project::widgets(mainframe) <Destroy> +[list ::TolConsole::Exit]
712  bind . <Destroy> +[list ::TolConsole::Exit %W]
713
714  # Aqui deberiamos llamar a la inicializacion tcl del proyecto.
715  # solo si el proyecto ha puesto menus poner el de tolcon.
716  project::OnExit ::TolConsole::BeforeExit
717
718  #Creamos StatusBar antes de ButtonBar
719  set sb [::TolConsole::CreateStatusBar]
720  #Creamos ButtonBar
721  set bb [::TolConsole::CreateButtonBar $tolcon]
722  #Empacamos ButtonBar
723  #if { [lsearch {left right} $data(toolbars,side)] ne -1 } {
724  #  ::toolbar::SetOrientation $bb V
725  #}
726  if { $tolcon } {
727    #Creamos inspector+Ventanas
728    set widgets(inspector) [Create $w]
729    bind $widgets(inspector) <F6> "::TolConsole::ApplyViewMode ; break"
730    Tolcon_Trace "widgets(inspector): $widgets(inspector)"
731  } else {
732   # ::TolConsole::OptionsApplyDefDates
733  }
734 
735  # VISUALIZAMOS O NO EL INSPECTOR DE OBJETOS
736  ::TolConsole::ObjectInspectorShow
737 
738  project::raiseSplash
739  return $w
740}
741
742
743#/////////////////////////////////////////////////////////////////////////////
744proc ::TolConsole::RaiseInspector {} {
745#/////////////////////////////////////////////////////////////////////////////
746  $::project::widgets(mainmdi).slave1 restore
747  $::project::widgets(mainmdi).slave1 raise
748}
749
750
751#pedro-start
752#/////////////////////////////////////////////////////////////////////////////
753proc ::TolConsole::NewToolFrame { name { first 1 }} {
754#  Crea una nueva ToolFrame para Toolbars
755#/////////////////////////////////////////////////////////////////////////////
756  variable widgets
757  variable data
758 
759  switch $first {
760    1 {
761      set commandAux "toolbarFrame_${name}"
762      set newTFname $commandAux
763    }
764    2 {
765      set commandAux $name
766      set newTFname  $name
767    }
768    default {
769      set newTFname "toolbarFrame_${name}"
770      set commandAux $::project::widgets(mainframe).${newTFname}
771    }
772  }
773  # create a toolframe new 
774  Tolcon_Trace "ToolFrame sale-----> $commandAux"
775  set TF [::toolbar::ToolbarFrame $commandAux]
776  #Añadimos como objetivo de Drop (tkdnd)
777  dnd bindtarget $TF text/plain <Drop> "::TolConsole::TMotion %W %D $newTFname"
778  #empacamos
779  #pack $TF -side top -fill y
780  pack $TF -side $data(toolbars,side) \
781    -before $::project::widgets(mainmdi) \
782    -anchor nw -fill $data(toolbars,fill)
783  #añadimos Botones por defecto
784  #if { $first } {
785  #::TolConsole::NewToolBarB $TF $name
786  #}
787  switch $first {
788    1 {
789      ::TolConsole::NewToolBarB $commandAux $name
790    }
791    2 {
792      #
793    }
794    default {
795      ::TolConsole::NewToolBarB $TF $name
796    }
797  }
798  return $TF
799}
800
801
802#/////////////////////////////////////////////////////////////////////////////
803proc ::TolConsole::NewToolBarB { parentTF name { jump 0 } {Child 0} {ini 0}} {
804#  Crea una nueva toolbar para botones dentro del frame parentTF
805#  parentTF : Frame papa
806#  jump     : Opcion utilizada en caso de adopcion. (cambio de frame padre).
807#  loopyPath: Contiene los parametros de creacion de TODOS los botones
808#             de un toolbar, se recorre cuando jump es 1.
809#/////////////////////////////////////////////////////////////////////////////
810  variable widgets
811  variable data
812   
813  switch $ini {
814    1 {
815      set data(tolbase,original) 0
816      set newName $name
817      set largo   [string length $newName]
818      set newName [string range $newName 0 [expr $largo - 2]]
819      set newTb   [::toolbar::create "$parentTF.$newName"]
820    }
821    2 {
822      set newName [lindex [split $Child .] 3]
823      set largo   [string length $newName]
824      set newName [string range $newName 0 [expr $largo - 1]]
825      if {[winfo exists $parentTF.$newName]} {
826        set data(tolbase,original) 1
827        } else {
828        set data(tolbase,original) 0
829        set newTb   [::toolbar::create "$parentTF.$newName"]
830      }
831    }
832    default {
833      set data(tolbase,original) 0
834      set newName "tb_${name}"
835      set newTb [::toolbar::create "$parentTF.$newName"]
836    }
837  }
838 
839  #if { $ini } {
840  #  set newName $name
841  #  Tolcon_Trace "newName -> $newName"
842  #  set largo   [string length $newName]
843  #  set newName [string range $newName 0 [expr $largo - 2]]
844  #  set newTb   [::toolbar::create "$parentTF.$newName"]
845  #} else {
846  #  set newName "tb_${name}"
847  #  Tolcon_Trace "newName -> $newName"
848  #  set newTb [::toolbar::create "$parentTF.$newName"]
849  #}
850 
851  if { $jump } {
852    set test "\{"
853    foreach path $widgets(createScript,$Child) {
854      set Apic  [lindex $path 1]
855      set Ahelp [lindex $path 2]
856      set Acmd  [lindex $path 3]
857      if { [string index $Acmd 0] == $test } {
858        set largo  [string length $Acmd]
859        set newCmd [string range  $Acmd 1 [expr $largo - 2]]
860      } else {
861        set newCmd $Acmd
862      }
863      #creamos botones exactamente iguales y en el mismo orden sobre nuevo
864      #parent
865      if {$data(tolbase,original) == 0} {
866        ::TolConsole::NewButtonB $newTb $Apic $Ahelp $newCmd $parentTF
867      }
868     
869    }
870   Tolcon_Trace "/n COMPLETE DUMP ---> $widgets(createScript,$Child)"
871  }
872 
873 
874  #empacamos
875  if {$data(tolbase,original)} {
876    dnd bindsource $parentTF.$newName text/plain "return $parentTF.$newName"
877    pack $parentTF.$newName -side left -anchor w \
878              -fill x
879    return $parentTF.$newName
880  } else {
881    #Drag-n-Drop para mover a diferentes toolframes
882    dnd bindsource $newTb text/plain "return $newTb"
883    pack $newTb -side left -anchor w \
884              -fill x -in $parentTF
885    return $newTb
886  }
887}
888
889
890#/////////////////////////////////////////////////////////////////////////////
891proc ::TolConsole::NewButtonB { Tb pic help cmd parentTF} {
892#  --- Crea un nuevo boton en la toolbar parametro ---
893#
894#  pathToolbar : Ruta completa al toolbar padre que tendra el boton
895#  pic    : Imagen del Boton
896#  prueba : Introducir boton de prueba (llevar a 0 para no empacar
897#           dos botones por llamada.
898#  help   : Ayuda del Boton Custom
899#  cmd    :comando a ejecutar por el boton
900#/////////////////////////////////////////////////////////////////////////////
901  variable widgets
902  variable data
903
904  # imagen ?
905  if { $pic == "" } {
906    set pic index
907  }
908  # exists imagen ?
909  if {[catch {::Bitmap::get $pic}]} {
910    # no exists
911    Tolcon_Trace "La imagen asociada al comando no existe. \
912      No se mostrara el botón: imagen: $pic - comando: $help"
913  } else {
914    # exists
915    set but [::toolbar::addbutton $Tb -image [::Bitmap::get $pic] \
916      -tooltip [mc $help] -command $cmd]
917    #event add <<TMotion_1>> <Button1-Motion>
918    bind $but <<TMotion_1>> "dnd drag $Tb"
919    bind $but <ButtonPress-2> "::toolbar::ButtonMenu"
920    dnd bindsource $Tb text/plain "return $Tb"
921    #guardamos parametros del create del boton, si es el primer boton,
922    #iniciamos la matriz.
923    if { [info exists widgets(createScript,$Tb)] } {
924      lappend widgets(createScript,$Tb) "$Tb $pic [list $help] [list $cmd] $parentTF"
925    } else {
926      set     widgets(createScript,$Tb) "{$Tb $pic [list $help] [list $cmd] $parentTF}"
927    }
928    if { ![regexp "$Tb $pic [list $help] [list $cmd] $parentTF" "$data(tolbase,lsttoolbars)" ] } {
929      lappend data(tolbase,lsttoolbars) "$Tb $pic [list $help] [list $cmd] $parentTF"
930    }
931  }
932  return
933}
934
935
936#/////////////////////////////////////////////////////////////////////////////
937proc ::TolConsole::TMotion { targetTF newChild name} {
938#  Mueve Toolbar de un Frame a otro cuando ocurre un DND
939#/////////////////////////////////////////////////////////////////////////////
940  variable widgets
941  variable data
942  set test [winfo parent $newChild]
943
944  if { $targetTF != $test } {
945    pack forget $newChild
946
947    set data(tolbase,lsttoolbars) \
948      [lsub $data(tolbase,lsttoolbars) $widgets(createScript,$newChild)]
949     
950    if {$data(tolbase,ini)} {
951      ::TolConsole::NewToolBarB $targetTF $name 1 $newChild 2
952    } else {
953      ::TolConsole::NewToolBarB $targetTF $name 1 $newChild 2
954    }   
955  } else {
956    pack $newChild -in $targetTF -side left -anchor w \
957                -fill x
958  }
959 return
960}
961
962
963#/////////////////////////////////////////////////////////////////////////////
964proc ::TolConsole::CreateButtonBar { {tolcon 1} } {
965# 
966#/////////////////////////////////////////////////////////////////////////////
967  variable widgets
968  variable data
969 
970  set TF {}
971  if {![llength $data(tolbase,lsttoolbars)]} {
972    #Creamos ToolFrame Principal para botones por defecto.
973    set TF [set widgets(toolbar,main) [::TolConsole::NewToolFrame 0 0]]
974   
975    # 2) Separamos Botones en diferentes Toolframes
976    #Grupo Botones Inspector
977    set tb1 [::TolConsole::NewToolBarB $TF "tb1"]
978    #Show Inspector Window
979    ::TolConsole::NewButtonB $tb1 insobj [mc "TOL Inspector"] \
980      "$::project::widgets(mainmdi).slave1 restore; $::project::widgets(mainmdi).slave1 raise" $TF
981    #Show Eval Window
982    ::TolConsole::NewButtonB $tb1 evalwin [mc "Show Eval Window"] \
983    [list ::TolConsole::ShowWindow "eval"] $TF
984     #Show Output Window
985     ::TolConsole::NewButtonB $tb1 outputwin [mc "Show Output Window"] \
986     [list ::TolConsole::ShowWindow "output"] $TF
987     #Show Info
988     ::TolConsole::NewButtonB $tb1 infowin [mc "Show Info Window"] \
989     [list ::TolConsole::ShowWindow info] $TF
990       #Show ViewMode   
991     ::TolConsole::NewButtonB $tb1 changeview [mc "Change View Mode"] \
992     [list ::TolConsole::ApplyViewMode] $TF
993   
994    #Grupo Botones para Mostrar Acciones
995     set tbExe [::TolConsole::NewToolBarB $TF "tbExe"]
996     #New Editor Dialog
997     ::TolConsole::NewButtonB $tbExe newfile [mc "New TOL file"] \
998     [list ::Editor::New] $TF
999     #Open TOL File
1000       ::TolConsole::NewButtonB $tbExe openfile [mc "Open TOL file"] \
1001     [list ::Editor::Open] $TF
1002     #New Table Dialog
1003     ::TolConsole::NewButtonB $tbExe newtable [mc "New Table"] \
1004     [list ::TolConsole::TableNew] $TF
1005     #Open Table Dialog
1006     ::TolConsole::NewButtonB $tbExe opentable [mc "Open Table"] \
1007     [list ::TolConsole::TableOpen] $TF
1008
1009     #New Project
1010     ::TolConsole::NewButtonB $tbExe newproject [mc "New Project"] \
1011     [list ::TolProject::New] $TF
1012     #Open Project
1013     ::TolConsole::NewButtonB $tbExe openprj [mc "Open Project"] \
1014     [list ::TolProject::Open] $TF
1015   
1016      #Grupo Botones para Herramientas
1017     set tbTool [::TolConsole::NewToolBarB $TF "tbTool"]
1018     #DB Connection
1019       ::TolConsole::NewButtonB $tbTool db [mc "Connection to database"] \
1020     [list $::project::data(bodbc) showdialog]  $TF
1021     #Function Search
1022       ::TolConsole::NewButtonB $tbTool funsearch [mc "Functions Search"] \
1023     [list ::funcSearch::Show] $TF
1024     #SQL
1025     ::TolConsole::NewButtonB $tbTool bysSql [mc "Bayes SQL"] \
1026     [list ::SQLTable::TableBayesSQL] $TF
1027     #Calendar
1028     ::TolConsole::NewButtonB $tbTool TimeSet [mc "Calendar Expert"] \
1029     [list ::CalendarTms::ViewTimeSet] $TF
1030     #Calendar
1031     ::TolConsole::NewButtonB $tbTool tools [mc Options] \
1032     [list ::TolConsole::OptionsCreate] $TF
1033   
1034      #Grupo Botones para Distribucion de Ventanas y Ayuda Visual
1035     set tbHelp [::TolConsole::NewToolBarB $TF "tbHelp"]
1036     #Cascade
1037     ::TolConsole::NewButtonB $tbHelp cascade [mc "Cascade"] \
1038     [list $::project::widgets(mainmdi) arrange cascade] $TF
1039       #Horizontal
1040     ::TolConsole::NewButtonB $tbHelp tilehor [mc "Tile Horizontal"] \
1041     [list $::project::widgets(mainmdi) arrange hor] $TF
1042       #Vertical
1043     ::TolConsole::NewButtonB $tbHelp tilever [mc "Tile Vertical"] \
1044     [list $::project::widgets(mainmdi) arrange ver] $TF
1045       #About
1046     ::TolConsole::NewButtonB $tbHelp about [mc "About"] \
1047       [list ::TolConsole::AboutShow] $TF
1048     set widgets(tb1,path) $tb1
1049     set widgets(tbExe,path) $tbExe
1050     set widgets(tbTool,path) $tbTool
1051     set widgets(tbHelp,path) $tbHelp
1052     set widgets(toolbar,frame) $TF
1053  } else {
1054    #aqui creamos las barras de botones que hemos recuperado del INI
1055    set tfgitb [::TolConsole::GlobalIniToolbarsButtons]
1056    set TF [set widgets(toolbar,main) [lindex $tfgitb 0]]
1057  }
1058  # toolbar by default, in order to add bellboys from the outside
1059  if {![string length $TF]} {
1060    # if not exists, create new
1061    set TF [::TolConsole::NewToolFrame 0 0]
1062  }
1063  set widgets(tbCustom,path) [::TolConsole::NewToolBarB $TF "tbCustom"]
1064  return
1065}
1066
1067
1068#/////////////////////////////////////////////////////////////////////////////
1069proc ::TolConsole::GlobalIniToolbarsButtons {} {
1070# 
1071#/////////////////////////////////////////////////////////////////////////////
1072  variable widgets
1073  variable data
1074 
1075  set data(tolbase,ini) 1
1076  set lstToolFrames {}
1077  set lstFrames {}
1078  set lstFrameBut {}
1079  set i 1
1080  foreach item $data(tolbase,lsttoolbars) {
1081    lappend lstFrameBut   $item
1082    lappend lstToolFrames [lindex $item 4]
1083    lappend lstFrames     [list [lindex $item 0] [lindex $item 4]]
1084    incr i
1085  }
1086  set lstFrames     [lsort -unique $lstFrames]
1087  set lstFrameBut   [lsort -unique $lstFrameBut]
1088  set lstToolFramesAux {}
1089  foreach it $lstToolFrames {
1090    puts $it
1091    if {!([lsearch -exact $lstToolFramesAux $it ] >= 0)} {
1092      lappend lstToolFramesAux $it
1093    }
1094  }
1095  set tfaux {}
1096  foreach toolFrame $lstToolFramesAux {
1097    set tfaux [::TolConsole::NewToolFrame "$toolFrame" 2]
1098  }
1099  set lstFramesAux {}
1100  foreach it $lstFrames {
1101    puts $it
1102    if {!([lsearch -exact $lstFramesAux $it ] >= 0)} {
1103      lappend lstFramesAux $it
1104    }
1105  }
1106  foreach toolBar $lstFrames {
1107    ::TolConsole::NewToolBarB  [lindex $toolBar 1] [lindex [split $toolBar .] 3] 0 0 1
1108  }
1109  foreach but $lstFrameBut {
1110    ::TolConsole::NewButtonB [lindex $but 0] [lindex $but 1] \
1111      [lindex $but 2] [lindex $but 3] [lindex $but 4]
1112  }
1113  return $tfaux
1114}
1115
1116
1117#/////////////////////////////////////////////////////////////////////////////
1118proc ::TolConsole::CreateStatusBar {} {
1119# 
1120#/////////////////////////////////////////////////////////////////////////////
1121  variable widgets
1122 
1123  set widgets(sb,path) [statusbar .sbar]
1124  .sbar add statTime -image [::Bitmap::get tinyclock]
1125  ::TolConsole::UpdateTime
1126if {0} {
1127  variable widgets
1128  # frame y label para barra de estado
1129  set widgets(sb,path) [set sf [frame $w.sb]]
1130  set widgets(sb,lInfo)   [label $sf.info   -anchor w -relief sunken]
1131  set widgets(sb,lTime)   [label $sf.cursor -anchor w -relief sunken]
1132  # empaquetamos los label de la barra de estado
1133  grid $w.sb.info   -row 0 -column 0 -sticky ew -padx 2
1134  grid $w.sb.cursor -row 0 -column 1 -sticky w  -padx 2
1135  grid columnconfigure $sf 0 -weight 1
1136  UpdateTime
1137  return $w.sb
1138}
1139}
1140
1141#/////////////////////////////////////////////////////////////////////////////
1142proc ::TolConsole::UpdateTime {} {
1143#
1144# PURPOSE: Updates time in status bar
1145#
1146#/////////////////////////////////////////////////////////////////////////////
1147  variable widgets
1148  $widgets(sb,path) itemconf statTime \
1149    -text [clock format [clock seconds] -format {%H:%M:%S }]
1150  after 1000 ::TolConsole::UpdateTime
1151if {0} {
1152  variable widgets
1153  $widgets(sb,lTime) configure\
1154      -text [clock format [clock seconds] -format {%H:%M:%S }]
1155  after 1000 ::TolConsole::UpdateTime
1156}
1157}
1158
1159
1160#/////////////////////////////////////////////////////////////////////////////
1161proc ::TolConsole::ApplyViewMode {{change 1}} {
1162#
1163# PURPOSE: Changes heights of inspector and eval/output/info windows
1164#
1165#/////////////////////////////////////////////////////////////////////////////
1166  variable data
1167  variable widgets
1168
1169  set state $data(viewmode)
1170  set states [list middle max min middle]
1171  if {$change} {
1172    set idx [lsearch -exact $states $state]
1173    set state [lindex $states [expr $idx+1]]
1174  }
1175  ::PanedWindow::MoveSash $widgets(pw) 1 y $state
1176  set data(viewmode) $state
1177}
1178
1179
1180#/////////////////////////////////////////////////////////////////////////////
1181  proc ::TolConsole::AboutShow {} {
1182#
1183# PURPOSE: Shows the function search dialog
1184#
1185#/////////////////////////////////////////////////////////////////////////////
1186  set path .__about
1187
1188  if ![winfo exist $path] {
1189    ::TolConsole::About $path
1190  }
1191  wm state $path normal
1192}
1193
1194#/////////////////////////////////////////////////////////////////////////////
1195  proc ::TolConsole::TolBaseHelp {} {
1196#
1197# PURPOSE: Shows the home page of help of Tolbase
1198#
1199#/////////////////////////////////////////////////////////////////////////////
1200  ShowHelp "Tb4Mai"
1201}
1202
1203
1204#/////////////////////////////////////////////////////////////////////////////
1205  proc ::TolConsole::About { w } {
1206#
1207# PURPOSE: Shows a dialog that shows information about TolBase and Bayes.
1208#
1209#/////////////////////////////////////////////////////////////////////////////
1210  global toltk_library
1211  global GuiVersionInfo
1212
1213  set imgfile [file join $toltk_library toltk images splash.gif]
1214  set img [image create photo -file $imgfile]
1215  toplevel $w
1216  wm title $w "[mc About] TOLBase"
1217  wm withdraw $w
1218  wm transient $w .
1219  wm iconbitmap $w [wm iconbitmap .]
1220  wm resizable $w 0 0
1221  label $w.lsplash -image $img -relief ridge -bd 2
1222  array set TolVersionInfo [::tol::info version]
1223  label $w.lversion -bg black -fg white -text \
1224    "[mc {TOL Version}]: $TolVersionInfo(major).$TolVersionInfo(minor).$TolVersionInfo(release) ($TolVersionInfo(comment))"
1225  label $w.laddress -bg black -fg white -text {
1226    Bayes Forecast: dynamic modelling of operations and markets
1227    Voice: (+34) 91.5327440; Fax: (+34) 91.5322636
1228    e-Mail: request@bayesinf.com; URL: http://www.tol-project.org
1229  }
1230 
1231  button $w.bc -text [mc Close] -command [list destroy $w]
1232  grid $w.lsplash
1233  grid $w.lversion -sticky "ew"
1234  grid $w.laddress -sticky "ew"
1235  grid $w.bc -padx 2 -pady 5 -sticky ns
1236  update
1237  # Aqui deberiamos invocar a un proc CenterWindow
1238  wm geometry $w +[expr ([winfo vrootw .]-[winfo reqwidth $w])/2]+[expr ([winfo vrooth .]-[winfo reqheight $w])/2]
1239  update
1240  wm withdraw $w
1241  wm deiconify $w
1242  update
1243}
1244
1245#/////////////////////////////////////////////////////////////////////////////     
1246proc ::TolConsole::IncludeCmd {{path ""} } {
1247# 
1248#/////////////////////////////////////////////////////////////////////////////       
1249  variable data
1250  set types {
1251    {{Tol Files}  {.tol .bst .bsi .bst .bdt}}
1252    {{Text Files}  {.txt}}
1253    {{All Files}  *}
1254  }
1255
1256  if {$path == ""} {
1257    if { [catch {tk_getOpenFile -filetypes $types \
1258                   -initialdir $data(path) \
1259                   -title "Source File"} fn] || [string match {} $fn] } {
1260      return
1261    }   
1262  } else  {
1263    set fn $path
1264  }
1265  UpdateListIncluded $fn
1266  Include $fn
1267   
1268
1269}
1270
1271#/////////////////////////////////////////////////////////////////////////////     
1272proc ::TolConsole::UpdateListIncluded {path} {
1273# 
1274#/////////////////////////////////////////////////////////////////////////////       
1275  variable data
1276  # guardamos el ultimo directorio abierto
1277  set data(path) [file dirname $path]
1278  if { [set idx [lsearch $data(included) $path]] == -1 } {
1279    set data(included) [linsert $data(included) 0 $path]
1280  } else {
1281    set ll ""
1282    lappend ll $path
1283    set i 0
1284    foreach f $data(included) {
1285      if  {$i != $idx} {
1286        lappend ll $f
1287      }
1288      incr i
1289    }
1290    set data(included) $ll
1291  }
1292  set data(included) [lrange $data(included) 0 [expr $data(numRecent)-1]]
1293}
1294
1295#/////////////////////////////////////////////////////////////////////////////
1296proc ::TolConsole::Exit { w } {
1297#
1298#/////////////////////////////////////////////////////////////////////////////
1299  variable data
1300  variable widgets
1301
1302  if {$w eq "."} {
1303    ProcessPendingTasks
1304   
1305    # Options project
1306    if {[info exists data(proc,OnOptionDestroy)] && \
1307            [string length $data(proc,OnOptionDestroy)]} {
1308      foreach f $data(proc,OnOptionDestroy) {
1309        $f
1310      }
1311    }
1312    WriteIni
1313  }
1314}
1315
1316#/////////////////////////////////////////////////////////////////////////////
1317proc ::TolConsole::BeforeExit { } {
1318#
1319#/////////////////////////////////////////////////////////////////////////////
1320  variable data
1321  variable widgets
1322
1323  # check all ...
1324  set okEdi ok
1325  set okETr ok
1326  set okTPr ok
1327  catch {set okEdi [::Editor::CheckAll]}
1328  catch {set okETa [::EditTable::CheckAll]}
1329  catch {set okTPr [::TolProject::CheckAll]}
1330
1331  if {[string eq $okEdi cancel] || [string eq $okETa cancel] || \
1332      [string eq $okTPr cancel]} {
1333    return cancel
1334  }
1335  # exit
1336  if { [info exists widgets(inspector)] } {
1337    foreach a {x y width height} {
1338      set data(geometry,$a) [winfo $a $widgets(inspector)]
1339    }
1340    set data(geometry,wtop) [winfo height $widgets(panes,top)]
1341    set data(geometry,wbottom) [winfo height $widgets(panes,bottom)]
1342    set data(geometry,wleft) [::TolInspector::GetWeight left]
1343    set data(geometry,wright) [::TolInspector::GetWeight right]
1344    set data(font,eval) [$widgets(eval) cget -font]
1345    set data(font,output) [$widgets(output) cget -font]
1346    set data(font,info) [$widgets(info) cget -font]
1347  }
1348  return "ok"
1349}
1350
1351#/////////////////////////////////////////////////////////////////////////////
1352proc ::TolConsole::ProcessPendingTasks {} {
1353#
1354#/////////////////////////////////////////////////////////////////////////////
1355  # para que este procedimiento?
1356  return
1357  foreach id [after info] {
1358    set aft_info [after info $id]
1359    after cancel $id
1360    eval [lindex $aft_info 0]
1361  }
1362}
1363
1364#///////////////////////////////////////////////////////////////////////////// 
1365proc ::TolConsole::OptionsCreate { {tabinit ""} } {
1366#
1367# PURPOSE: Create the dialog of options of TolBase
1368#
1369# PARAMETERS:
1370#   tabinit -> Tab where is focused the dialog when it's displayed (Optional).
1371#
1372#///////////////////////////////////////////////////////////////////////////// 
1373  variable widgets
1374  variable data
1375
1376  set path $widgets(inspector)
1377
1378  set dialog [Dialog $path.t -title [mc "TOLBase Options"]\
1379              -parent $path -default 0 -cancel 1 -modal local] 
1380  wm protocol $dialog WM_DELETE_WINDOW \
1381    [list ::TolConsole::OptionsDestroy $dialog]
1382  set w [$dialog getframe]
1383 
1384  wm resizable $dialog 0 0
1385  # TabSet TolBase
1386  set w_ts [::blt::tabset $w.ts -relief flat -highlightthickness 0 -bd 0 \
1387    -outerpad 0 -tier 2 -slant both -textside right -side left -rotate 90 ]
1388  #insertar tabset
1389  $w_ts insert end TolBase
1390  set f0 [frame $w_ts.f0] 
1391  $w_ts tab configure "TolBase" -text "TolBase" \
1392    -window $f0 -fill both -padx 0 -selectbackground \#d9d9d9 -bg gray75 
1393 
1394  # TabSet Options
1395  set w_tabset [::blt::tabset $f0.ts -relief flat -highlightthickness 0\
1396    -bd 0 -outerpad 0 -tier 2 -slant right -textside right ]
1397 
1398  $w_tabset insert end TOL Output Precision Paths Others
1399  set f1 [frame $w_tabset.f1]
1400  set f2 [frame $w_tabset.f2]
1401  set f3 [frame $w_tabset.f3]
1402  set f4 [frame $w_tabset.f4]
1403  set f5 [frame $w_tabset.f5]
1404
1405  $w_tabset tab configure "TOL" -text [mc "TOL"] -window $f1\
1406       -fill both -padx 0 -selectbackground \#d9d9d9 -bg gray75
1407  $w_tabset tab configure "Output" -text [mc "Output"] -window $f2\
1408       -fill both -padx 0 -selectbackground \#d9d9d9 -bg gray75
1409  $w_tabset tab configure "Precision" -text [mc "Precision"] -window $f3\
1410       -fill both -padx 0 -selectbackground \#d9d9d9 -bg gray75
1411  $w_tabset tab configure "Paths" -text [mc "Paths"] -window $f5\
1412       -fill both -padx 0 -selectbackground \#d9d9d9 -bg gray75
1413  $w_tabset tab configure "Others" -text [mc "Others"] -window $f4\
1414       -fill both -padx 0 -selectbackground \#d9d9d9 -bg gray75
1415
1416  OptionsGet
1417  OptionsCreateTOL        $f1
1418  OptionsCreateOutput     $f2
1419  OptionsCreatePrecision  $f3
1420  OptionsCreatePaths      $f5
1421  OptionsCreateOthers     $f4
1422 
1423  # Options project
1424  if {[info exists data(proc,OnOptionCreate)] && \
1425      [string length $data(proc,OnOptionCreate)]} {
1426    foreach f $data(proc,OnOptionCreate) {
1427      $f $w_ts
1428    }
1429  }
1430
1431  OptionsCheck
1432
1433  set w_bbox \
1434          [ButtonBox $w.bb -orient horizontal -spacing 10 -padx 0 -pady 0 \
1435          -homogeneous false]
1436  $w_bbox add -text [mc "Accept"] -relief link \
1437          -helptext [mc "Make the changes and leave the dialog"] \
1438          -image [::Bitmap::get accept] -compound left -padx 5 -pady 1 \
1439          -command [list ::TolConsole::OptionsOK $dialog]
1440  $w_bbox add -text [mc "Cancel"] -relief link \
1441          -helptext [mc "Leave the dialog without apply any change"] \
1442          -image [::Bitmap::get cancelx] -compound left -padx 5 -pady 1 \
1443          -command [list ::TolConsole::OptionsDestroy $dialog]
1444  $w_bbox add -text [mc "Apply"] -relief link \
1445          -helptext [mc "Make the changes without leave the dialog"] \
1446          -image [::Bitmap::get apply] -compound left -padx 5 -pady 1 \
1447          -command ::TolConsole::OptionsApply
1448
1449  pack $w_bbox   -side bottom -expand no  -fill x
1450  pack $w_tabset -side top    -expand yes -fill both
1451  pack $w_ts -expand yes -fill both ;#-sticky news
1452 
1453  if {!($tabinit eq "")} {
1454    switch -exact $tabinit  {
1455      "TOL" {
1456        $w_tabset select 0
1457      }
1458      "Output" {
1459        $w_tabset select 1
1460      }
1461      "Precision" {
1462        $w_tabset select 2
1463      }
1464      "Paths" {
1465        $w_tabset select 3
1466      }
1467      "Others" {
1468        $w_tabset select 4
1469      }     
1470    }
1471  }
1472  bind $dialog <F1> "ShowHelp Tb4Opc"
1473  $dialog draw
1474}
1475
1476
1477#///////////////////////////////////////////////////////////////////////////// 
1478proc ::TolConsole::OptionsCreateTOL {w} {
1479#
1480#///////////////////////////////////////////////////////////////////////////// 
1481  variable tmpOpt
1482
1483  #TitleFrame $w.tf1 -text [mc "--"]
1484  #set f1 [$w.tf1 getframe]
1485
1486  TitleFrame $w.tf2 -text [mc "Default dates"]
1487  set f2 [$w.tf2 getframe]
1488
1489  label $f2.lFirstDate -text [mc "First date"]:
1490  ::Objects::ChooseDateCreate ::TolConsole::tmpOpt(var,DefFirst) $f2.cFD
1491
1492  label $f2.lLastDate -text [mc "Last date"]:
1493  ::Objects::ChooseDateCreate ::TolConsole::tmpOpt(var,DefLast) $f2.cLD
1494
1495  frame $f2.f -width 25
1496
1497  grid $f2.f $f2.lFirstDate $f2.cFD $f2.lLastDate $f2.cLD -sticky nw -padx 2
1498  grid rowconfigure    $f2 0 -weight 1
1499  grid columnconfigure $f2 4 -weight 1
1500  grid columnconfigure $f2 2 -pad 10
1501 
1502
1503  #grid $w.tf1 -sticky news -padx 2
1504  grid $w.tf2 -sticky news -padx 2
1505     
1506  grid rowconfigure    $w 0 -weight 1
1507  grid rowconfigure    $w 1 -weight 3
1508  grid columnconfigure $w 0 -weight 1
1509
1510}
1511
1512#/////////////////////////////////////////////////////////////////////////////   
1513proc ::TolConsole::OptionsCreateOutput {w} {
1514# 
1515#/////////////////////////////////////////////////////////////////////////////   
1516  global toltk_options
1517  variable tmpOpt
1518
1519  TitleFrame $w.tf1 -text [mc "Write"]
1520  set f1 [$w.tf1 getframe]
1521
1522  checkbutton $f1.chWrite -text [mc "Write messages in output window"]\
1523      -variable ::TolConsole::tmpOpt(var,chWrite)
1524  label $f1.lColorErr -text [mc "Errors color"]:
1525  bcolor $f1.fColorErr -variable ::TolConsole::tmpOpt(var,colorErr)
1526  #::Objects::ColorCreate ::TolConsole::tmpOpt(var,colorErr) $f1.fColorErr
1527  label $f1.lColorWar -text [mc "Warnings color"]:
1528  ::Objects::ColorCreate ::TolConsole::tmpOpt(var,colorWar) $f1.fColorWar
1529
1530  frame $f1.f  -width 20
1531  grid $f1.f $f1.chWrite   -             -             -             -sticky nw -padx 2
1532  grid ^     $f1.lColorErr $f1.fColorErr $f1.lColorWar $f1.fColorWar -sticky nw -padx 2
1533
1534  grid rowconfigure    $f1 1 -weight 1
1535  grid columnconfigure $f1 4 -weight 1
1536  grid columnconfigure $f1 2 -pad 20
1537
1538
1539  TitleFrame $w.tf2 -text [mc "Update"]
1540  set f2 [$w.tf2 getframe]
1541
1542  label $f2.lUpdateType -text [mc "Update options"]:
1543  frame $f2.f1 -width 15
1544  radiobutton $f2.rbAlways -text [mc "Update always"]\
1545     -value always -highlightthickness 0 -pady 0\
1546     -variable ::TolConsole::tmpOpt(var,updateType)\
1547     -command ::TolConsole::OptionsCheckUpdateType
1548  radiobutton $f2.rbEach   -text [mc "Update each"]\
1549     -value each   -highlightthickness 0 -pady 0\
1550     -variable ::TolConsole::tmpOpt(var,updateType)\
1551     -command ::TolConsole::OptionsCheckUpdateType
1552  radiobutton $f2.rbNever -text [mc "Don't update until the end"]\
1553     -value never  -highlightthickness 0 -pady 0\
1554     -variable ::TolConsole::tmpOpt(var,updateType)\
1555     -command ::TolConsole::OptionsCheckUpdateType
1556  set tmpOpt(widget,updateSec) [SpinBox $f2.sbSeconds -justify right -width 4 \
1557      -editable 0 -range {0 2000 20} \
1558      -textvariable ::TolConsole::tmpOpt(var,updateSec)]
1559  label $f2.lSeconds -text [mc milliseconds]
1560
1561  frame $f2.f -width 20
1562  grid $f2.f $f2.lUpdateType -     -             -             -sticky nw -padx 2
1563  grid ^     $f2.f1  $f2.rbAlways  -             -             -sticky nw -padx 2
1564  grid ^     ^       $f2.rbEach    $f2.sbSeconds $f2.lSeconds  -sticky nw -padx 2
1565  grid ^     ^       $f2.rbNever   -             -             -sticky nw -padx 2
1566
1567  grid rowconfigure    $f2 3 -weight 1
1568  grid columnconfigure $f2 4 -weight 1
1569 
1570  grid $w.tf1 -sticky news -padx 2
1571  grid $w.tf2 -sticky news -padx 2
1572  grid rowconfigure    $w 1 -weight 1
1573  grid columnconfigure $w 0 -weight 1
1574}
1575
1576#/////////////////////////////////////////////////////////////////////////////     
1577proc ::TolConsole::OptionsCreatePrecision {w} {
1578# 
1579#/////////////////////////////////////////////////////////////////////////////     
1580  variable tmpOpt
1581
1582  TitleFrame $w.tf1 -text [mc "Precision"]
1583  set f1 [$w.tf1 getframe]
1584
1585  checkbutton $f1.chDecimals -text [mc "Reduce decimal digits to"]\
1586      -variable ::TolConsole::tmpOpt(var,chDecimals)\
1587      -command ::TolConsole::OptionsCheckDecimals
1588  set tmpOpt(widget,decimals) [SpinBox $f1.sbDecimals -justify right -width 4 \
1589      -editable 0 -range {0 10} \
1590      -textvariable ::TolConsole::tmpOpt(var,numDecimals)]
1591  label $f1.lDecimals -text [mc digits]
1592   
1593  checkbutton $f1.chExponential \
1594      -text [mc "Use exponential notation when number has more than"]\
1595      -variable ::TolConsole::tmpOpt(var,chExponential)\
1596      -command ::TolConsole::OptionsCheckExponential
1597  set tmpOpt(widget,exponential) [SpinBox $f1.sbExponential -justify right -width 4 \
1598      -editable 0 -range {0 10} \
1599      -textvariable ::TolConsole::tmpOpt(var,numExponential)]
1600  label $f1.lExponential -text [mc digits]
1601
1602  frame $f1.f -width 25
1603
1604  grid $f1.f $f1.chDecimals    $f1.sbDecimals    $f1.lDecimals    -sticky nw -padx 2
1605  grid ^     $f1.chExponential $f1.sbExponential $f1.lExponential -sticky nw -padx 2
1606  grid rowconfigure    $f1 1 -weight 1
1607  grid columnconfigure $f1 3 -weight 1     
1608 
1609  grid $w.tf1 -sticky news -padx 2
1610  #grid $w.tf2 -sticky news -padx 2
1611     
1612  grid rowconfigure    $w 0 -weight 1
1613  #grid rowconfigure    $w 1 -weight 2
1614  grid columnconfigure $w 0 -weight 1
1615}
1616
1617#/////////////////////////////////////////////////////////////////////////////     
1618proc ::TolConsole::OptionsCreatePaths {w} {
1619#
1620#/////////////////////////////////////////////////////////////////////////////       
1621  variable tmpOpt
1622
1623  TitleFrame $w.tf -text [mc "Paths"]
1624  set f [$w.tf getframe]
1625
1626  label $f.lPathBrowser   -text [mc "Browser path"]
1627  label $f.lPathPDFViewer -text [mc "PDF viewer path"]
1628  label $f.lPathHelp      -text [mc "Help path"]
1629  Entry $f.ePathBrowser   -state normal -width 30 \
1630    -textvariable ::TolConsole::tmpOpt(var,pathBrowser) \
1631    -helptext [mc pathexplanation]
1632  Entry $f.ePathPDFViewer -state normal -width 30 \
1633    -textvariable ::TolConsole::tmpOpt(var,pathPDFViewer)  \
1634    -helptext [mc pathexplanation]
1635  Entry $f.ePathHelp -state normal -width 30 \
1636    -textvariable ::TolConsole::tmpOpt(var,pathHelp) 
1637  Button $f.bPathBrowser -compound left -padx 10 \
1638    -height 16 -relief link \
1639    -helptext [mc "Search the program path"] \
1640    -image [Bitmap::get bopen] \
1641    -command {::TolConsole::OptionsCreatePath "Browser"}
1642  Button $f.bPathPDFViewer -compound left -padx 10 \
1643    -height 16 -relief link \
1644    -helptext [mc "Search the program path"] \
1645    -image [Bitmap::get bopen] \
1646    -command {::TolConsole::OptionsCreatePath "PDFViewer"}
1647  Button $f.bPathHelp -compound left -padx 10 \
1648    -height 16 -relief link \
1649    -helptext [mc "Search the folder"] \
1650    -image [Bitmap::get bopen] \
1651    -command  {set tmp [tk_chooseDirectory -initialdir $::TolConsole::tmpOpt(var,pathHelp) -mustexist 1]
1652               if {!($tmp eq "")} {
1653                 set ::TolConsole::tmpOpt(var,pathHelp) $tmp
1654               } }
1655
1656  grid $f.lPathBrowser   -row 0 -column 0 -sticky nw  -padx 5 -pady 5
1657  grid $f.lPathPDFViewer -row 1 -column 0 -sticky nw  -padx 5 -pady 5
1658  grid $f.lPathHelp      -row 2 -column 0 -sticky nw  -padx 5 -pady 5
1659  grid $f.ePathBrowser   -row 0 -column 1 -sticky new -padx 5 -pady 5
1660  grid $f.ePathPDFViewer -row 1 -column 1 -sticky new -padx 5 -pady 5
1661  grid $f.ePathHelp      -row 2 -column 1 -sticky new -padx 5 -pady 5
1662  grid $f.bPathBrowser   -row 0 -column 2 -sticky e   -padx 5 -pady 5
1663  grid $f.bPathPDFViewer -row 1 -column 2 -sticky e   -padx 5 -pady 5
1664  grid $f.bPathHelp      -row 2 -column 2 -sticky e   -padx 5 -pady 5
1665
1666  grid columnconfigure $f 1  -weight 1
1667  grid rowconfigure    $f 10 -weight 1
1668 
1669  grid $w.tf -sticky news
1670 
1671  grid columnconfigure $w 0 -weight 1
1672  grid rowconfigure    $w 0 -weight 1
1673}
1674
1675#/////////////////////////////////////////////////////////////////////////////     
1676proc ::TolConsole::OptionsCreatePath { type } {
1677#
1678# PURPOSE: Executes the command associated to the create path buttons:
1679#          Shows a dialog OpenFile with the directory and the appropriate
1680#          file type according to the operating system
1681#
1682# PARAMETERS: Type of path. Allowed values "Browser" "PDFViewer"
1683#
1684# TODO: For linux, to verify that the file is executable
1685#
1686#/////////////////////////////////////////////////////////////////////////////         
1687  variable tmpOpt
1688 
1689  if { $::tcl_platform(platform) == "windows" } {
1690    # get the "Program Files" directory
1691    set dirProgramFiles [registry get \
1692      {HKEY_LOCAL_MACHINE\SYSTEM\ControlSet001\Control\Session Manager\SFC} \
1693      ProgramFilesDir]
1694    set txtExecFileType "\{\{\{[mc {Executable files} ]\} .exe\}\}"
1695    set commandFile "tk_getOpenFile \
1696      -initialdir [list $dirProgramFiles] -f $txtExecFileType"
1697  } else {  ;# linux
1698    set commandFile "tk_getOpenFile -initialdir \\"
1699  }
1700 
1701  #set ::TolConsole::tmpOpt(var,path$type) [eval $commandFile]
1702  set tmp [eval $commandFile]
1703  if { !($tmp eq "") } {
1704     set ::TolConsole::tmpOpt(var,path$type) $tmp
1705  } 
1706}
1707 
1708#/////////////////////////////////////////////////////////////////////////////     
1709proc ::TolConsole::OptionsCreateOthers {w} {
1710# 
1711#/////////////////////////////////////////////////////////////////////////////       
1712  variable tmpOpt
1713  variable languages
1714
1715  TitleFrame $w.tf1 -text [mc "General Options"]
1716  set f1 [$w.tf1 getframe]
1717
1718  label $f1.lRecent -text [mc "Number of last edited files"]
1719
1720  set tmpOpt(widget,recent) [SpinBox $f1.sbRecent -justify right -width 4 \
1721      -editable 0 -range {0 10} \
1722      -textvariable ::TolConsole::tmpOpt(var,numRecent)]
1723  label $f1.lFiles -text [mc files]
1724
1725  radiobutton $f1.rbOrdDate -text [mc "Order by date"]\
1726     -value date -highlightthickness 0 -pady 0\
1727     -variable ::TolConsole::tmpOpt(var,ordRecent)
1728  radiobutton $f1.rbOrdAsc   -text [mc "Order alphabetically"]\
1729     -value asc   -highlightthickness 0 -pady 0\
1730     -variable ::TolConsole::tmpOpt(var,ordRecent)
1731  radiobutton $f1.rbOrdDesc -text [mc "Order reverse alphabetically"]\
1732     -value desc  -highlightthickness 0 -pady 0\
1733     -variable ::TolConsole::tmpOpt(var,ordRecent)
1734   
1735  frame $f1.f -width 25
1736
1737  grid $f1.f $f1.lRecent   $f1.sbRecent $f1.lFiles -sticky nw -padx 2
1738  grid ^     $f1.rbOrdDate -            -          -sticky nw -padx 2
1739  grid ^     $f1.rbOrdAsc  -            -          -sticky nw -padx 2
1740  grid ^     $f1.rbOrdDesc -            -          -sticky nw -padx 2
1741
1742  grid rowconfigure    $f1 0 -weight 1
1743  grid rowconfigure    $f1 1 -weight 1
1744 
1745  grid rowconfigure    $f1 2 -weight 1
1746 
1747  grid columnconfigure $f1 3 -weight 1
1748  grid columnconfigure $f1 4 -weight 1
1749 
1750  TitleFrame $w.tf2 -text [mc "Language"]
1751  set f2 [$w.tf2 getframe]
1752
1753  label $f2.lLanguage -text [mc "Choose language"]:
1754  foreach {key value} $languages {
1755    lappend values [mc $value]
1756  }
1757
1758  ComboBox $f2.cbLanguages -width 12 -height 5 -editable false -justify right -values $values\
1759   -modifycmd   [list ::Objects::ComboUnTranslateDbl $f2.cbLanguages $languages\
1760       ::TolConsole::tmpOpt(var,language)]
1761  ::Objects::ComboSetIniDbl $f2.cbLanguages $languages ::TolConsole::tmpOpt(var,language)
1762 
1763
1764  label $f2.lLangExp -text ([mc "Language is set when you restart interface"])
1765  frame $f2.f -width 25
1766  grid $f2.f $f2.lLanguage $f2.cbLanguages -sticky nw -padx 2
1767  grid ^     $f2.lLangExp  -               -sticky nw -padx 2
1768  grid rowconfigure    $f2 1 -weight 1
1769  grid columnconfigure $f2 2 -weight 1
1770 
1771  TitleFrame $w.tf3 -text [mc "Object Inspector"]
1772  set f3 [$w.tf3 getframe]
1773  checkbutton $f3.chObjIns -text [mc "Show Object Inspector"]\
1774      -variable ::TolConsole::tmpOpt(var,chObjIns)
1775 
1776  label $f3.lObjIns -text ([mc "Object Inspector visualization is set when you restart interface"])
1777 
1778  grid $f3.chObjIns -sticky nw -padx 2
1779  grid $f3.lObjIns  -sticky nw -padx 2
1780  grid rowconfigure    $f3 1 -weight 1
1781  grid columnconfigure $f3 2 -weight 1
1782 
1783 
1784  grid $w.tf1 -sticky news -padx 2
1785  grid $w.tf2 -sticky news -padx 2
1786  grid $w.tf3 -sticky news -padx 2
1787     
1788  grid rowconfigure    $w 0 -weight 1
1789  grid rowconfigure    $w 1 -weight 1
1790  grid rowconfigure    $w 2 -weight 1
1791  grid columnconfigure $w 0 -weight 1
1792}
1793
1794#/////////////////////////////////////////////////////////////////////////////     
1795proc ::TolConsole::OptionsGet {} {
1796# 
1797#/////////////////////////////////////////////////////////////////////////////       
1798  variable data
1799  variable tmpOpt
1800  set tmpOpt(var,numRecent)      $data(numRecent)
1801  set tmpOpt(var,ordRecent)      $data(ordRecent)
1802  set tmpOpt(var,language)       $data(language)
1803  set tmpOpt(var,chDecimals)     $data(chDecimals)
1804  set tmpOpt(var,numDecimals)    $data(numDecimals)
1805  set tmpOpt(var,chExponential)  $data(chExponential)
1806  set tmpOpt(var,numExponential) $data(numExponential)
1807  set tmpOpt(var,DefFirst)       $data(DefFirst)
1808  set tmpOpt(var,DefLast)        $data(DefLast)
1809  set tmpOpt(var,colorErr)       $data(colorErr)
1810  set tmpOpt(var,colorWar)       $data(colorWar)
1811  set tmpOpt(var,chWrite)        $data(chWrite)
1812  set tmpOpt(var,updateType)     $data(updateType)
1813  set tmpOpt(var,updateSec)      $data(updateSec)
1814  set tmpOpt(var,showODBC)       $data(showODBC)
1815  set tmpOpt(var,pathBrowser)    $data(pathBrowser)
1816  set tmpOpt(var,pathPDFViewer)  $data(pathPDFViewer)
1817  set tmpOpt(var,pathHelp)       $data(pathHelp)
1818  set tmpOpt(var,chObjIns)       $data(chObjIns)
1819 
1820 
1821}
1822
1823#/////////////////////////////////////////////////////////////////////////////     
1824proc ::TolConsole::OptionsSet {} {
1825# 
1826#/////////////////////////////////////////////////////////////////////////////       
1827  variable data
1828  variable tmpOpt
1829   
1830  regsub -all var, [array names ::TolConsole::tmpOpt var,*] "" optNames
1831   
1832  foreach it $optNames {
1833    set data($it) $tmpOpt(var,$it)
1834  }
1835}
1836
1837#/////////////////////////////////////////////////////////////////////////////     
1838proc ::TolConsole::OptionsCheck {} {
1839# 
1840#/////////////////////////////////////////////////////////////////////////////       
1841  OptionsCheckUpdateType
1842  OptionsCheckDecimals
1843  OptionsCheckExponential
1844}
1845
1846#/////////////////////////////////////////////////////////////////////////////     
1847proc ::TolConsole::OptionsCheckDecimals {} {
1848# 
1849#/////////////////////////////////////////////////////////////////////////////       
1850  variable tmpOpt
1851  if {!$tmpOpt(var,chDecimals)} {
1852    $tmpOpt(widget,decimals) configure -state disabled
1853  } else  {
1854    $tmpOpt(widget,decimals) configure -state normal
1855  }
1856}
1857
1858#/////////////////////////////////////////////////////////////////////////////     
1859proc ::TolConsole::OptionsCheckExponential {} {
1860# 
1861#/////////////////////////////////////////////////////////////////////////////       
1862  variable tmpOpt
1863  if {!$tmpOpt(var,chExponential)} {
1864    $tmpOpt(widget,exponential) configure -state disabled
1865  } else  {
1866    $tmpOpt(widget,exponential) configure -state normal
1867  }
1868}
1869
1870#/////////////////////////////////////////////////////////////////////////////     
1871proc ::TolConsole::OptionsCheckUpdateType {} {
1872# 
1873#/////////////////////////////////////////////////////////////////////////////       
1874  variable tmpOpt
1875
1876  switch $tmpOpt(var,updateType) {
1877    always {
1878      $tmpOpt(widget,updateSec) configure -state disabled
1879    }
1880    each {
1881      $tmpOpt(widget,updateSec) configure -state normal
1882    }
1883    never {
1884      $tmpOpt(widget,updateSec) configure -state disabled
1885    }
1886  }
1887}
1888
1889#/////////////////////////////////////////////////////////////////////////////     
1890proc ::TolConsole::OptionsDestroy {dialog} {
1891# 
1892#/////////////////////////////////////////////////////////////////////////////       
1893  #variable data
1894  variable tmpOpt
1895
1896  array unset tmpOpt
1897  destroy $dialog
1898}
1899
1900#/////////////////////////////////////////////////////////////////////////////     
1901proc ::TolConsole::OptionsApply {} {
1902# 
1903#/////////////////////////////////////////////////////////////////////////////
1904  variable data
1905  # Apply
1906  OptionsSet
1907  OptionsApplyLanguage
1908  OptionsApplyDefDates
1909  OptionsApplyColors
1910  # Options project Apply
1911  if {[info exists data(proc,OnOptionApply)] && \
1912      [string length $data(proc,OnOptionApply)]} {
1913    foreach f $data(proc,OnOptionApply) {
1914      $f
1915    }
1916  }
1917  # Write INI
1918  WriteIni
1919}
1920
1921#/////////////////////////////////////////////////////////////////////////////     
1922proc ::TolConsole::OptionsApplyLanguage {} {
1923# 
1924#/////////////////////////////////////////////////////////////////////////////       
1925  global toltk_script_path
1926  variable data
1927
1928  ::tol::language $data(language)
1929  ::msgcat::mclocale $data(language)
1930  ::msgcat::mcload [file join $toltk_script_path msgs]
1931}
1932
1933#/////////////////////////////////////////////////////////////////////////////     
1934proc ::TolConsole::OptionsApplyDefDates {} {
1935# 
1936#/////////////////////////////////////////////////////////////////////////////       
1937  variable data
1938  set expr "Date PutDefaultDates([DateTol $data(DefFirst)],[DateTol $data(DefLast)]);"
1939  #Tolcon_Trace "$expr"
1940  ::tol::console eval $expr
1941}
1942
1943#/////////////////////////////////////////////////////////////////////////////     
1944proc ::TolConsole::OptionsApplyColors {} {
1945# 
1946#/////////////////////////////////////////////////////////////////////////////       
1947  variable data
1948  variable widgets
1949
1950  $widgets(output) tag configure errorTag   -foreground $data(colorErr)
1951  $widgets(output) tag configure warningTag -foreground $data(colorWar)
1952}
1953
1954#/////////////////////////////////////////////////////////////////////////////     
1955proc ::TolConsole::OptionsOK {dialog} {
1956# 
1957#/////////////////////////////////////////////////////////////////////////////       
1958  OptionsApply
1959  OptionsDestroy $dialog
1960}
1961
1962#/////////////////////////////////////////////////////////////////////////////
1963  proc ::TolConsole::ReadIni {} {
1964#
1965# PURPOSE: Reads general TolBase options from .ini file.
1966#
1967#/////////////////////////////////////////////////////////////////////////////
1968  global toltk_script_path
1969  global toltk_options
1970  variable data
1971  set rini ::iniFile::Read
1972 
1973  #inicializo variable necesaria para las toolbars
1974  set data(tolbase,lsttoolbars) [$rini TolConsole listtoolbars]
1975  if {![llength $data(tolbase,lsttoolbars)]} {
1976    set data(tolbase,lsttoolbars) {}
1977  }
1978   
1979  set data(path)           [$rini TolConsole path       $toltk_script_path]
1980  set data(included)       [$rini TolConsole recent     {}]
1981  set data(chIncluded)     [$rini TolConsole saveRecent 1]
1982  set data(numRecent)      [$rini TolConsole numRecent  8]
1983  set data(ordRecent)      [$rini TolConsole ordRecent  "date"]
1984  set data(tabRecent)      [$rini TolConsole tabRecent  {}]
1985  set data(prjRecent)      [$rini TolConsole prjRecent  {}]
1986  set data(incRecent)      [$rini TolConsole incRecent  {}]
1987  set data(ediRecent)      [$rini TolConsole ediRecent  {}] 
1988  set data(font,eval)      [$rini TolConsole evalFont   \
1989    $toltk_options(fonts,Fixed)]
1990  set data(font,output)    [$rini TolConsole outputFont \
1991    $toltk_options(fonts,Fixed)]
1992  set data(font,info)      [$rini TolConsole infoFont   \
1993    $toltk_options(fonts,Fixed)]
1994  set data(language)       [$rini TolConsole language   es]
1995  set data(chDecimals)     [$rini TolConsole redDecimals    0]
1996  set data(numDecimals)    [$rini TolConsole numDecimals    4]
1997  set data(chExponential)  [$rini TolConsole useExponential 0]
1998  set data(numExponential) [$rini TolConsole numExponential 8]
1999  set data(DefFirst)       [$rini TolConsole DefFirst [::tol::date first]]
2000  set data(DefLast)        [$rini TolConsole DefLast  [::tol::date last ]]
2001  set data(colorWar)       [$rini TolConsole colorWar blue]
2002  set data(colorErr)       [$rini TolConsole colorErr red]
2003  set data(chWrite)        [$rini TolConsole writeOutput 1]
2004  set data(updateType)     [$rini TolConsole updateType always]
2005  set data(updateSec)      [$rini TolConsole updateSec 200]
2006  set data(showODBC)       [$rini TolConsole ShowODBCDialog 0]
2007 
2008  # program paths
2009  set data(pathBrowser)   [$rini TolConsole pathBrowser {}]
2010  set data(pathPDFViewer) [$rini TolConsole pathPDFViewer {}]
2011  set data(pathHelp)      [$rini TolConsole pathHelp {}]
2012 
2013  # Object Inspector visualization
2014  set data(chObjIns)      [$rini TolConsole chObjIns {}]
2015 
2016  # geometry
2017
2018#  set data(geometry,x) [$rini TolConsole geometry:x -1]
2019#  set data(geometry,y) [$rini TolConsole geometry:y -1]
2020#  set data(geometry,width) [$rini TolConsole geometry:width -1]
2021#  set data(geometry,height) [$rini TolConsole geometry:height -1]
2022  set data(geometry,wtop)    [$rini TolConsole geometry:wtop 5]
2023  set data(geometry,wbottom) [$rini TolConsole geometry:wbottom 1]
2024  set data(geometry,wleft)   [$rini TolConsole geometry:wleft 3]
2025  set data(geometry,wright)  [$rini TolConsole geometry:wright 7]
2026  set data(viewmode)         [$rini TolConsole viewmode middle]
2027 
2028  #cargamos los parametros de las toolbars
2029  set data(toolbars,side) [$rini ToolBars side top]
2030  set data(toolbars,fill) [$rini ToolBars fill x]
2031  set data(toolbars,buttonbar,side) [$rini ToolBars buttonbar:side left]
2032  set data(toolbars,buttonbar,fill) [$rini ToolBars buttonbar:fill y]
2033 
2034  set data(tolbase,ini) 0
2035  set data(tolbase,original) 0
2036}
2037
2038#/////////////////////////////////////////////////////////////////////////////
2039proc ::TolConsole::WriteIni {} {
2040#
2041# PURPOSE: Writes general TolBase options to .ini file.
2042#
2043#/////////////////////////////////////////////////////////////////////////////
2044  variable data
2045  variable widgets
2046
2047  set wini ::iniFile::Write
2048  $wini TolConsole path           $data(path)
2049  $wini TolConsole recent         $data(included)
2050  $wini TolConsole saveRecent     $data(chIncluded)
2051  $wini TolConsole numRecent      $data(numRecent)
2052  $wini TolConsole ordRecent      $data(ordRecent)
2053  $wini TolConsole evalFont       $data(font,eval)
2054  $wini TolConsole outputFont     $data(font,output)
2055  $wini TolConsole infoFont       $data(font,info)
2056  $wini TolConsole language       $data(language)
2057  $wini TolConsole redDecimals    $data(chDecimals)
2058  $wini TolConsole numDecimals    $data(numDecimals)
2059  $wini TolConsole useExponential $data(chExponential)
2060  $wini TolConsole numExponential $data(numExponential)
2061  $wini TolConsole DefFirst       $data(DefFirst)
2062  $wini TolConsole DefLast        $data(DefLast)
2063  $wini TolConsole colorWar       $data(colorWar)
2064  $wini TolConsole colorErr       $data(colorErr)
2065  $wini TolConsole writeOutput    $data(chWrite)
2066  $wini TolConsole updateType     $data(updateType)
2067  $wini TolConsole updateSec      $data(updateSec)
2068  $wini TolConsole ShowODBCDialog $data(showODBC)
2069  $wini TolConsole tabRecent      $data(tabRecent)
2070  $wini TolConsole prjRecent      $data(prjRecent)
2071  $wini TolConsole incRecent      $data(incRecent)
2072  $wini TolConsole ediRecent      $data(ediRecent)
2073
2074  # program paths
2075  $wini TolConsole pathBrowser    $data(pathBrowser)
2076  $wini TolConsole pathPDFViewer  $data(pathPDFViewer)
2077  $wini TolConsole pathHelp       $data(pathHelp)
2078 
2079  # Object Inspector visualization
2080  $wini TolConsole chObjIns       $data(chObjIns)
2081 
2082  # geometry configuration
2083  #  $wini TolConsole geometry:x $data(geometry,x)
2084  #  $wini TolConsole geometry:y $data(geometry,y)
2085  #  $wini TolConsole geometry:width $data(geometry,width)
2086  #  $wini TolConsole geometry:height $data(geometry,height)
2087  $wini TolConsole geometry:wtop    $data(geometry,wtop)
2088  $wini TolConsole geometry:wbottom $data(geometry,wbottom)
2089  $wini TolConsole geometry:wleft   $data(geometry,wleft)
2090  $wini TolConsole geometry:wright  $data(geometry,wright)
2091  $wini TolConsole viewmode         $data(viewmode)
2092  #::iniFile::Flush
2093 
2094  # escribimos las opciones para las barra de botones
2095  if { [winfo exists ${::project::widgets(mainframe)}.toolbarFrame]} {
2096    set packopts [pack info ${::project::widgets(mainframe)}.toolbarFrame]
2097    array set packoptsarray $packopts
2098    $wini ToolBars side $packoptsarray(-side)
2099        $wini ToolBars fill $packoptsarray(-fill)
2100    #set packopts [pack info ${::project::widgets(mainframe)}.toolbarFrame.tb1]
2101    #array set packoptsarray $packopts
2102    #$wini ToolBars buttonbar:side $packoptsarray(-side)
2103        #$wini ToolBars buttonbar:fill $packoptsarray(-fill)
2104  }
2105 
2106  # escribimos las opciones de los documentos abiertos
2107  $::project::widgets(mainmdi) writeDocsIni
2108 
2109  # escribilos las barras de botones que tenemos creadas
2110  # clear the bars created by code
2111  if {[info exists widgets(tbCustom,path)]} {
2112    set lsttollbarsaux {}
2113    foreach ltb $data(tolbase,lsttoolbars) {
2114      if {![string eq $widgets(tbCustom,path) [lindex $ltb 0]]} {
2115        lappend lsttollbarsaux $ltb
2116      } 
2117    }
2118    $wini TolConsole listtoolbars  $lsttollbarsaux
2119  }
2120}
2121
2122#/////////////////////////////////////////////////////////////////////////////
2123  proc ::TolConsole::ODBCShow {} {
2124#
2125# PURPOSE: Show the connection ODBC dialog
2126#
2127#/////////////////////////////////////////////////////////////////////////////
2128  variable data
2129  if {$data(showODBC)} {
2130    set values [::ODBCDialog::ReadIni] 
2131    ::ODBCDialog::Create $::project::widgets(mainframe) \
2132      [lindex $values 0] [lindex $values 1] "" \
2133      ::TolConsole::OnConnect ::TolConsole::OnDisconnect
2134  }
2135}
2136
2137#/////////////////////////////////////////////////////////////////////////////
2138  proc ::TolConsole::ObjectInspectorShow {} {
2139#
2140# PURPOSE: Show Object inspector
2141#
2142#/////////////////////////////////////////////////////////////////////////////
2143  variable data
2144  if {$data(chObjIns) ne "" &&
2145      [string is boolean $data(chObjIns)] && !$data(chObjIns)} {
2146    $::TolConsole::widgets(inspector) withdraw
2147  }
2148}
2149
2150#/////////////////////////////////////////////////////////////////////////////
2151  proc ::TolConsole::GetGCFFile {} {
2152#
2153# PURPOSE: Obtain the GCFFile file of .ini and showed to message in the
2154#          window output
2155#
2156#/////////////////////////////////////////////////////////////////////////////
2157  # GCFFile
2158  set gcfFile [::iniFile::Read SeriesGraph GCFFile {}]
2159  if {[string length $gcfFile]} {
2160    ::tol::console eval "Text (GCFFile := \"$gcfFile\");"
2161    ::TolConsole::HciWriter "Text GCFFile = \"$gcfFile\"\n"
2162  }
2163}
2164
2165
2166#/////////////////////////////////////////////////////////////////////////////
2167  proc ::TolConsole::MenuMDI { } {
2168#
2169# PURPOSE: Crea un menu para mdi
2170#
2171#/////////////////////////////////////////////////////////////////////////////
2172  #cargo la lista de formularios
2173  set ::toolbar::data(toolbar,tolbase,lstcmd) {}
2174 
2175  set md [.mainmenu cget -definition]
2176  set hook $::project::data(menuhook)
2177  set hookhelp $::project::data(menuhookhelp)
2178
2179  set id [$md insert $hook cascade -label [mc &File]]
2180
2181  set cid [$md add $id cascade -label [mc &New] ]
2182  $md add $cid command -label [mc "TOL &file"] \
2183      -command "::Editor::New"
2184  $md add $cid command -label [mc "&Table"] \
2185      -command "::TolConsole::TableNew"
2186  $md add $cid command -label [mc "&Project"] \
2187      -command "::TolProject::New"
2188 
2189  set cid [$md add $id cascade -label [mc &Open] ]
2190  $md add $cid command -label [mc "TOL &file"] \
2191      -command "::Editor::Open"
2192  $md add $cid command -label [mc "&Table"] \
2193      -command "::TolConsole::TableOpen"
2194  $md add $cid command -label [mc "&Project"] \
2195      -command "::TolProject::Open"
2196 
2197  $md add $id command -label [mc &Include] -command "::TolConsole::IncludeCmd"
2198 
2199  $md add $id separator
2200 
2201  set cid [$md add $id cascade -label [mc "&Recent files"] ]
2202  $md add $cid cascade -label [mc "TOL &files"] \
2203      -postcommand "::Editor::postEdited %W"
2204  $md add $cid cascade -label [mc "&Tables"] \
2205      -postcommand "::TolConsole::TableRecent %W"
2206  $md add $cid cascade -label [mc "&Projects"] \
2207      -postcommand "::TolProject::postEdited %W"
2208  $md add $cid cascade -label [mc "&Included"] \
2209      -postcommand "::TolConsole::postIncluded %W"
2210
2211  $md add $id separator
2212 
2213  #$md add $id command -label [mc E&xit] -command "::project::Exit"
2214  #$md add $id command -label [mc E&xit] -command "::TolConsole::Exit"
2215  $md add $id command -label [mc E&xit] -command "::project::OnDelete"
2216
2217 
2218  set id [$md insert $hook cascade -label [mc &Tools]]
2219  set ::project::data(menu,tools) $id
2220   
2221  set cid [$md add $id cascade -label [mc "TOL &Editor"]]
2222  $md add $cid cascade -label [mc "&Recent files"] \
2223      -postcommand "::Editor::postEdited %W"
2224  $md add $cid command -label [mc "&New TOL file"] \
2225      -command "::Editor::New"
2226  $md add $cid command -label [mc "&Open TOL file"] \
2227      -command "::Editor::Open"
2228 
2229  set cid [$md add $id cascade -label [mc "TOL &Table Editor"]]
2230  $md add $cid cascade -label [mc "&Recent files"] \
2231      -postcommand "::TolConsole::TableRecent %W"
2232  $md add $cid command -label [mc "&New Table"] \
2233      -command "::TolConsole::TableNew"
2234  $md add $cid command -label [mc "&Open Table"] \
2235      -command "::TolConsole::TableOpen"
2236 
2237  set cid [$md add $id cascade -label [mc "TOL &Project Editor"]]
2238  $md add $cid cascade -label [mc "&Recent files"] \
2239      -postcommand "::TolProject::postEdited %W"
2240  $md add $cid command -label [mc "&New Project"] \
2241      -command "::TolProject::New"
2242  $md add $cid command -label [mc "&Open Project"] \
2243      -command "::TolProject::Open"
2244 
2245  $md add $id separator
2246  set cid [$md add $id cascade -label [mc "Analysis Tools"]]
2247  set cid2 [$md add $cid cascade -label [mc "ARIMA"]]
2248  $md add $cid2 command -label [mc "Draw ACF and PACF of ARIMA Models"] \
2249      -command "::drawArima::Show"
2250  $md add $id separator
2251 
2252  $md add $id command -label [mc "TOL Inspector"] \
2253    -command "$::project::widgets(mainmdi).slave1 restore; $::project::widgets(mainmdi).slave1 raise"
2254  $md add $id command -label [mc "&Functions Search"] \
2255      -command "::funcSearch::Show"
2256  $md add $id command -label [mc "&Calendar Expert"] \
2257      -command "::CalendarTms::ViewTimeSet"
2258  $md add $id command -label [mc "&Bayes SQL"] \
2259      -command "::SQLTable::TableBayesSQL"
2260 
2261  $md add $id separator
2262 
2263  $md add $id command -label [mc "C&onnection to database"] \
2264      -command "$::project::data(bodbc) showdialog"
2265
2266  $md add $id command -label [mc "&Options"] \
2267      -command "::TolConsole::OptionsCreate"
2268
2269  return $md
2270}
2271
2272#/////////////////////////////////////////////////////////////////////////////
2273  proc ::TolConsole::TableNew { } {
2274#
2275# PURPOSE: Creates a new table
2276#
2277#/////////////////////////////////////////////////////////////////////////////
2278  set tl [::project::CreateForm -type Tables \
2279            -width 400 -height 180 \
2280            -iniconfig Tables -helpkey "Tb4Edt"]
2281  set tlf [$tl getframe]
2282  # configuration
2283  btable $tlf.t -parent $tl \
2284                -posteditcmd [list ::TolConsole::TableRecentUpdate $tlf.t] \
2285                -iniconfig btable
2286  pack $tlf.t -fill both -expand yes
2287  $tl bind <Control-F4> [list $tl kill]
2288  #pedro
2289 
2290}
2291
2292#/////////////////////////////////////////////////////////////////////////////
2293  proc ::TolConsole::TableOpen { {path ""} } {
2294#
2295# PURPOSE: Opens a table
2296# PARAMETERS:
2297#   path   -> path of the file to be opened, if no file is given an Openfile
2298#             dialogs is shown
2299#
2300#/////////////////////////////////////////////////////////////////////////////
2301  set tl [::project::CreateForm -type Tables \
2302            -width 400 -height 180 \
2303            -iniconfig Tables -helpkey "Tb4Edt"]
2304  set tlf [$tl getframe]
2305  $tl configure -state withdrawn
2306  # configuration
2307  btable $tlf.t -parent $tl \
2308                -posteditcmd [list ::TolConsole::TableRecentUpdate $tlf.t] \
2309                -iniconfig btable
2310  if { $path == "" } {
2311    $tlf.t cmdOpen
2312    $tl configure -state normal
2313    if { [$tlf.t cget -path] == "" } {
2314      $tl kill
2315    } else {
2316      pack $tlf.t -fill both -expand yes
2317      $tl bind <Control-F4> [list $tl kill]
2318    }
2319  } else {
2320    $tlf.t configure -path $path
2321    $tl configure -state normal
2322    pack $tlf.t -fill both -expand yes
2323    $tl bind <Control-F4> [list $tl kill] 
2324  }
2325}
2326
2327#/////////////////////////////////////////////////////////////////////////////
2328  proc ::TolConsole::TableRecentUpdate { w args } {
2329#
2330# PURPOSE: Updates the last edited files when a table is closed
2331#
2332# PARAMETERS:
2333#   m   -> menu's path that will have the list of last table edited files
2334#   ord -> flag that indicates if files must be shown sorted
2335#
2336#/////////////////////////////////////////////////////////////////////////////
2337  variable data
2338
2339  set newfile [$w cget -path]
2340  set pos [lsearch $data(tabRecent) $newfile]
2341
2342  if { $pos == -1 } {
2343    set data(tabRecent) [linsert $data(tabRecent) 0 $newfile]
2344  } else {
2345    set data(tabRecent) [lreplace $data(tabRecent) $pos $pos]
2346    set data(tabRecent) [linsert $data(tabRecent) 0 $newfile]   
2347  }
2348  if { $data(numRecent) <= [llength $data(tabRecent)] } {
2349    set data(tabRecent) [lreplace $data(tabRecent) $data(numRecent) end]   
2350  }
2351}
2352
2353#/////////////////////////////////////////////////////////////////////////////
2354  proc ::TolConsole::TableRecent { m } {
2355#
2356# PURPOSE: Fills a menu with the last table edited files, according to the
2357#          information of 'options' variable.
2358#
2359# PARAMETERS:
2360#   m   -> menu's path that will have the list of last table edited files
2361#   ord -> flag that indicates if files must be shown sorted
2362#
2363#/////////////////////////////////////////////////////////////////////////////
2364  variable data
2365 
2366  set data(tabRecent) [lrange $data(tabRecent) 0 [expr $data(numRecent)-1]]
2367 
2368  $m delete 0 end
2369  if { $data(ordRecent) == "asc" } {
2370    set lst [lsort -ascii $data(tabRecent)]
2371  } elseif { $data(ordRecent) == "desc" } {
2372    set lst [lsort -ascii -decreasing $data(tabRecent)]
2373  } else {
2374    set lst $data(tabRecent)
2375  }
2376  foreach w $lst {
2377    $m add command -label $w -command [list ::TolConsole::TableOpen $w]
2378  }
2379  if [llength $lst] {
2380    $m add separator
2381    $m add command -label [mc "Clear"]\
2382          -command [list ::TolConsole::TableRecentClear]
2383  }
2384}
2385
2386#/////////////////////////////////////////////////////////////////////////////
2387  proc ::TolConsole::TableRecentClear { } {
2388#
2389# PURPOSE: Clears the list of last edited files
2390#
2391#/////////////////////////////////////////////////////////////////////////////
2392  variable data
2393  set data(tabRecent) ""
2394}
Note: See TracBrowser for help on using the repository browser.