1#!/usr/bin/wish
2
3proc updateInsertTag { Text xml enTagName lAllowNode paramInsertTag } {
4  tset cur_node [richtext::Cursor $Text get TAG]
5  switch -- $paramInsertTag {
6    before -
7    after  {
8      if {[simxml::nodeInfo $xml [tset cur_node] type] == "TEXT" } {
9        tset cur_node [simxml::nodeInfo $xml [tset cur_node] parent]
10      } ;# if
11      if { [tset cur_node] != [simxml::root get $xml] } {
12        tset cur_node [simxml::nodeInfo $xml [tset cur_node] parent]
13      } ;# if
14      tset cur_node [simxml::nodeInfo $xml [tset cur_node] name]
15      tset listTag [simxml::dtdListTag $xml [tset cur_node]]
16    }
17    inside {
18      if {[simxml::nodeInfo $xml [tset cur_node] type] == "TEXT" } {
19        tset cur_node [simxml::nodeInfo $xml [tset cur_node] parent]
20      } ;# if
21      tset cur_node [simxml::nodeInfo $xml [tset cur_node] name]
22      tset listTag [simxml::dtdListTag $xml [tset cur_node]]
23    }
24  } ;# switch ( before | inside | after )
25
26  if { [lsearch [tset listTag] _ALL_] != -1 } {
27    $enTagName configure -state normal
28    tset listTag [lreplace [tset listTag] [lsearch [tset listTag] _ALL_] [lsearch [tset listTag] _ALL_]]
29  } else {
30    $enTagName configure -state normal
31  } ;# if-else
32  $lAllowNode delete 0 end
33  eval $lAllowNode insert 0 [tset listTag]
34  tunset listTag
35} ;# updateInsertTag
36
37
38
39
40#============================================================================
41#============================================================================
42#============================================================================
43proc gui::prNewFile {} {
44         set Text [gui::data get currentTextWidget]
45
46         set info_doc [gui::Dialog [gui::data get guiXML] newXMLDocument]
47
48         if { [string equal $info_doc {}] } { return }
49         catch { gui::prCloseFile }
50         set xml  [simxml::create -encoding [lindex $info_doc 1]]
51         simxml::add $xml {} [lindex $info_doc 0] -type TAG
52         set html [simxml::root get $xml ]
53         set css  [simcss::create ]
54
55         richtext::widgetData $Text set auto-indent 10
56         richtext::widgetData $Text set css         $css
57         richtext::widgetData $Text set xml         $xml
58         richtext::widgetData $Text set xml_root    $html
59         richtext::widgetData $Text set textModify  1
60         focus $Text
61         wm title . "New XML document | [gui::data get tkXMLiVEversion]"
62         .menubar.file entryconfigure [gui::menuGet .menubar.file close]  -state normal
63         .menubar.file entryconfigure [gui::menuGet .menubar.file save]   -state disabled
64         .menubar.file entryconfigure [gui::menuGet .menubar.file saveAs] -state normal
65         .menubar.file entryconfigure [gui::menuGet .menubar.file xslTransform] -state normal
66         .menubar.file entryconfigure [gui::menuGet .menubar.file saveDTD]   -state normal
67
68         set fileCSSName [lindex $info_doc 2]
69         if { ![string equal $fileCSSName {}] } {
70           simxml::PrCommand $xml set XML-STYLESHEET [list type text/css href $fileCSSName]
71#           set css  [simcss::create -file $fileCSSName]
72           gui::prOpenStyle $fileCSSName
73         } ;# if
74
75  gui::TreeExpressFill
76  richtext::updateWidget $Text {}
77} ;# proc gui::prNewFile
78
79proc gui::prOpenFile {} {
80      set Text     [gui::data get currentTextWidget]
81
82      if { [richtext::widgetData $Text get textModify] } {
83        switch -- [gui::Dialog {} dlg_WarmCloseFile] {
84          1  {  gui::prSaveFile }
85          -1 {  return          }
86        } ;# switch
87      } ;# if
88
89
90         set fileName [tk_getOpenFile -title [mc "Open XML file"]  -filetypes { \
91                      {{XML documents} {.xml .XML}}
92                      {{XSL documents} {.xsl .XSL .xslt .XSLT}}
93                      {{All documents} {*}}}];
94
95         if { ![string equal $fileName {}] } {
96           richtext::widgetData $Text set textModify 0
97           set isClose 0
98           catch { gui::prCloseFile    } isClose
99           if { $isClose == -1 } { return }
100           catch { simxml::delete $xml }
101
102           set xml  [simxml::parseXML -file $fileName]
103           set html [simxml::root get $xml ]
104           set css  [simcss::create]
105           richtext::widgetData $Text set auto-indent 10
106           richtext::widgetData $Text set textModify  0
107
108# BUG !!!!!!!!!!!! need if check PrCommand
109           set fileCSSName {}
110           catch {
111             foreach { tmp } [simxml::PrCommand $xml get XML-STYLESHEET] {
112               array set tmp_style $tmp
113               set fileCSSName [file join [file dirname $fileName] $tmp_style(href)]
114             } ;# foreach
115           } ;# catch
116
117           richtext::widgetData   $Text set css      $css
118           richtext::widgetData   $Text set xml      $xml
119           richtext::widgetData   $Text set xml_root $html
120           focus $Text
121           wm title . "[simxml::xmlInfo $xml get file] | [gui::data get tkXMLiVEversion]"
122           .menubar.file entryconfigure [gui::menuGet .menubar.file close]  -state normal
123           .menubar.file entryconfigure [gui::menuGet .menubar.file save]   -state normal
124           .menubar.file entryconfigure [gui::menuGet .menubar.file saveAs] -state normal
125           .menubar.file entryconfigure [gui::menuGet .menubar.file xslTransform] -state normal
126           .menubar.file entryconfigure [gui::menuGet .menubar.file saveDTD]   -state normal
127           gui::msgDebug "USED style: $fileCSSName"
128           if { ! [string equal $fileCSSName {}] } {
129             gui::prOpenStyle $fileCSSName
130           } else {
131             richtext::updateWidget $Text {}
132           } ;# if-else
133        }
134      gui::TreeExpressFill
135} ;# proc gui::prOpenFile
136
137
138proc gui::prSaveFile { args } {
139      set Text     [gui::data get currentTextWidget]
140      set xml      [richtext::widgetData $Text get xml]
141      set fileName [simxml::xmlInfo $xml get file]
142
143      if { ! [string equal [lindex $args 0] {}] } {
144        set fileName [lindex $args 0]
145      } ;# if
146
147      if { [string equal $fileName {}] } {
148        gui::prSaveAsFile
149        return
150      } ;# if
151
152      if { [catch {open $fileName w} OUT] } {
153        gui::msgDebug "Error write file $fileName"
154      } else {
155        set Text [gui::data get currentTextWidget]
156        set xml  [richtext::widgetData $Text get xml]
157        fconfigure $OUT -encoding [simxml::xmlInfo $xml get encoding]
158          puts $OUT [simxml::debug $xml {} -recurse true]
159        close $OUT
160        richtext::widgetData $Text set textModify 0
161      } ;# if
162} ;# proc gui::prSaveFile
163
164
165proc gui::prSaveAsFile {} {
166      set fileName [tk_getSaveFile -title [mc "Save as... XML file"]  -filetypes { \
167                                           {{XML documents}  {.xml .XML}}
168                                           {{XSLT documents} {.xsl .XSL .xslt .XSLT}}
169                                           {{All documents}  {*}}}]
170      gui::prSaveFile $fileName
171} ;# proc gui::prSaveAsFile
172
173
174proc gui::prCloseFile {} {
175      set Text [gui::data get currentTextWidget]
176      set xml  [richtext::widgetData $Text get xml]
177
178      if { [richtext::widgetData $Text get textModify] } {
179        switch -- [gui::Dialog {} dlg_WarmCloseFile] {
180          1  {  gui::prSaveFile }
181          -1 {  return -1       }
182        } ;# switch
183      } ;# if
184
185      eval {$Text mark unset} [$Text mark names]
186      simxml::delete $xml
187      $Text delete 1.0 end
188      richtext::widgetData $Text set xml         {}
189      richtext::widgetData $Text set css         {}
190      richtext::widgetData $Text set textModify  0
191      set xml {}
192      wm title . [gui::data get tkXMLiVEversion]
193      .menubar.file entryconfigure [gui::menuGet .menubar.file close]  -state disabled
194      .menubar.file entryconfigure [gui::menuGet .menubar.file save]   -state disabled
195      .menubar.file entryconfigure [gui::menuGet .menubar.file saveAs] -state disabled
196      .menubar.file entryconfigure [gui::menuGet .menubar.file xslTransform] -state disabled
197      .menubar.file entryconfigure [gui::menuGet .menubar.file saveDTD]   -state disabled
198
199      $::Tree delete [$::Tree nodes root]
200      return 1
201} ;# proc gui::prCloseFile
202
203
204proc gui::prOpenStyle { args } {
205        set fileName [lindex $args 0]
206
207        if { [string equal $fileName {}] } {
208          set fileName [tk_getOpenFile -title "Open XML file" \
209                                       -filetypes {{{CSS files}  {.css}} \
210                                                  {{All files} {*}} \
211                                     }]
212        } ;# if
213
214        if { ![string equal $fileName {}] } {
215          set styleName [file tail [file rootname $fileName]]
216          set menu_attr [list name     style$::countStyle \
217                              label    $styleName \
218                              accel    Control-$::countStyle \
219                              command  "gui::prSetStyle $fileName"]
220          set newXML [simxml::create]
221            set new_node [simxml::add $newXML {} COMMAND -type element -attribute $menu_attr]
222            gui::menuAdd .menubar.style $newXML $new_node
223          simxml::delete $newXML
224
225          incr ::countStyle
226          set ::varShowTAG OFF
227          gui::prSetStyle $fileName
228        } ;# if fileName != ""
229} ;# proc gui::prOpenStyle
230
231
232proc gui::prSetStyle { fileName } {
233    set Text [gui::data get currentTextWidget]
234    if { ![string equal $fileName {}] } {
235      set css  [simcss::create -file $fileName]
236      richtext::widgetData $Text set auto-indent 0
237      richtext::widgetData $Text set show-tag    OFF
238      richtext::widgetData $Text set css         $css
239      gui::msgDebug "UPDATE TIME: [time {richtext::updateWidget $Text {}}]"
240    } ;# if
241} ;# proc gui::prSetStyle
242
243
244proc gui::prDefaultStyle {} {
245    set Text [gui::data get currentTextWidget]
246    set css  [simcss::create]
247    richtext::widgetData $Text set auto-indent 10
248    richtext::widgetData $Text set show-tag    AUTO
249    richtext::widgetData $Text set css         $css
250    richtext::updateWidget $Text {}
251} ;# proc gui::prDefaultStyle
252
253
254proc gui::prChangeXMLWidget { param value } {
255    set Text [gui::data get currentTextWidget]
256    richtext::widgetData $Text set $param $value
257    set cur_pos [$Text index [richtext::Cursor $Text get]]
258    richtext::updateWidget $Text {}
259    richtext::Cursor $Text set $cur_pos
260    $Text see insert
261} ;# proc gui::prChangeXMLWidget
262
263
264proc gui::prXSLTransform {} {
265  gui::Dialog {} dlg_XSLTransform
266} ;# proc gui::prXSLTransform
267
268
269proc gui::TreeFill { widget xml node_id font } {
270  set node_parent [simxml::nodeInfo $xml $node_id parent]
271  set node_name   [simxml::nodeInfo $xml $node_id name]
272  set node_type   [simxml::nodeInfo $xml $node_id type]
273  set text        $node_name
274
275  set node_children [simxml::children $xml $node_id -verbose expanded]
276  if { [set child_index [lsearch -glob $node_children *TITLE]] != -1 } {
277    set children [lindex $node_children [expr $child_index - 1]]
278    set text "$text ([simxml::getText $xml $children])"
279  } ;# if
280
281  switch -- $node_type {
282    ELEMENT -
283    TAG     {
284      if { [string equal $node_parent {}] } { set node_parent root }
285      $widget insert end $node_parent $node_id -text $text -open 0 -font $font
286    }
287  } ;# switch
288} ;# proc gui::TreeFill
289
290
291proc gui::TreeNodeClick { widget node } {
292  richtext::Cursor [gui::data get currentTextWidget] set TAG $node
293  [gui::data get currentTextWidget] see insert
294  $widget selection set $node
295  focus [gui::data get currentTextWidget]
296} ;# proc gui::TreeNodeClick
297
298
299proc gui::TreeNodeDClick { widget node } {
300  richtext::Cursor [gui::data get currentTextWidget] set TAG $node
301  [gui::data get currentTextWidget] see insert
302  if { [$widget itemcget $node -open] == 0 } {
303    $widget itemconfigure $node -open 1
304  } else {
305    $widget itemconfigure $node -open 0
306  } ;# if
307  $widget selection set $node
308  focus [gui::data get currentTextWidget]
309} ;# proc gui::TreeNodeDClick
310
311
312proc gui::TreeNodeEnter { widget w node } {
313  #set text [$widget itemcget $node -text]
314  #gui::balloon $w show "$text"
315} ;# proc gui::TreeNodeEnter
316
317
318proc gui::TreeNodeLeave { widget w node } {
319} ;# proc gui::TreeNodeLeave
320
321
322proc gui::TreeExpressFill { args } {
323  set Text [gui::data get currentTextWidget]
324  set xml  [richtext::widgetData $Text get xml]
325  $::Tree delete [$::Tree nodes root]
326  simxml::recurseTree $xml -root {} \
327                      -command [list gui::TreeFill $::Tree %XML %NODE_ID {Arial 9}]
328
329  if  { [string equal [lindex $args 0] {}] } {
330    set xml_root [richtext::widgetData $Text get xml_root]
331  } else {
332    set xml_root [lindex $args 0]
333  }
334
335  foreach { node } [simxml::listNodePath $xml $xml_root] {
336    $::Tree itemconfigure $node -open 1
337  } ;# foreach
338
339  $::Tree selection set $xml_root
340  $::Tree see $xml_root
341} ;# proc gui::TreeExpressFill
342
343
344proc gui::TreeUpdate { xml node action } {
345  switch -- [simxml::nodeInfo $xml $node type] {
346    TEXT {  set node [simxml::nodeInfo $xml $node parent]  }
347  } ;# switch
348
349  foreach { tnode } [simxml::listNodePath $xml $node] {
350    catch {
351      if { [$::Tree itemcget $tnode -open] == 0 } {  break  } ;# if
352    }
353  } ;# foreach
354  $::Tree selection set $tnode
355  $::Tree see $tnode
356} ;# proc gui::TreeUpdate
357
358
359proc gui::prChangeShowDebug { } {
360  if { $::varShowDebug == "ON" } {
361    pack [ gui::data get debugWidget ] -side top  -fill x
362  } else {
363    pack forget [ gui::data get debugWidget ]
364  };# if
365} ;# proc gui::prChangeShowDebug
366
367
368
369
370#=================================
371#=================================
372#=================================
373
374
375$splash.status configure -text [mc "Loading GUI XML..."]
376update idletasks
377set guiXML [simxml::parseXML -file gui/gui.xml]
378
379
380set ButtonBox [frame .bbox -height 32  -borderwidth 1 -relief groove -background #EEEEEE]
381
382$splash.status configure -text [mc "Create ToolBar..."]
383update idletasks
384gui::toolbarCreate $ButtonBox -xml $guiXML
385pack $ButtonBox -side top -expand false -fill x
386
387
388$splash.status configure -text [mc "Create User Interface..."]
389update idletasks
390set wRoot [gui::createUI . -xml $guiXML]
391pack [lindex $wRoot 0] -side top -fill both
392
393
394
395gui::data set currentTextWidget $Text
396set paramInsertTag inside
397set countStyle     1
398set varShowTAG     AUTO
399set varShowDebug   ON
400set varFontSize    Normal
401set varIndentSize  Normal
402
403gui::prChangeShowDebug
404
405
406gui::menuCreate . $guiXML menubar
407SetResource .
408
409
410;# =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
411;#                         USER DEFINED EVENTS
412;# =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
413if { 1 == 1} {
414richtext::Bind $Text after <<CursorMove>> {
415  richtext::wRTStatus:extStatus [richtext::Cursor %W get TAG]
416} ;# BIND after <<CursorMove>
417
418richtext::Bind $Text after <<CursorMove>> {
419# HightLight position
420    %W tag remove hightlightBorder 1.0 end
421    tset node_cur    [richtext::Cursor %W get TAG]
422    switch -- [simxml::nodeInfo [richtext::widgetData %W get xml] \
423                                [tset node_cur] type] {
424      ELEMENT {
425        tset node_index [richtext::tagIndex %W [tset node_cur] -type element]
426        %W tag add hightlightBorder [lindex [tset node_index] 0] \
427                                    [lindex [tset node_index] 1]
428        %W tag raise hightlightBorder
429      }
430      TEXT {
431        tset node_index [richtext::tagIndex %W [tset node_cur] -type text]
432        %W tag add hightlightBorder [lindex [tset node_index] 0] \
433                                    [lindex [tset node_index] 1]
434        %W tag raise hightlightBorder
435      }
436      TAG {
437        tset node_start [richtext::tagIndex %W [tset node_cur] -type open]
438        tset node_end   [richtext::tagIndex %W [tset node_cur] -type close]
439        %W tag add hightlightBorder [lindex [tset node_start] 0] \
440                                    [lindex [tset node_end  ] 1]
441        %W tag raise hightlightBorder
442      }
443    } ;# switch
444    updateInsertTag %W [richtext::widgetData %W get xml] \
445                    $::enTagName  $::lAllowNode  $::paramInsertTag
446
447  gui::TreeUpdate [richtext::widgetData %W get xml] [tset node_cur] {}
448} ;# BIND after <<CursorMove>
449} ;# if COMMENT
450
451
452
453
454
455
456
457
458