1proc insTag { tag_name args } { 2 set widget [gui::data get currentTextWidget] 3 set xml [widgetData $widget get xml] 4 set tag_type [simxml::dtdTypeTag $xml $tag_name] 5 set cur_tag [Cursor $widget get TAG] 6 set cur_tag_type [simxml::nodeInfo $xml $cur_tag type] 7 set cur_index [$widget index [Cursor $widget get]] 8 set paramInsertTag [lindex $args [expr [lsearch $args "-paramInsert"] + 1] ] 9 set text_sel "" 10 set tag_extra "" 11 12 if [string equal $tag_name #PCDATA] { 13 set tag_type TEXT 14 set tag_name {} 15 set text_sel {} 16 } ;# if 17 18 if [string equal $tag_name #COMMAND] { 19 set tag_type TEXT 20 set tag_name {} 21 set text_sel {} 22 set tag_extra CDATA 23 } ;# if 24 25 if { ([string equal $tag_type TEXT]) && 26 ([string equal $text_sel {} ]) } { 27 gui::msgDebug "EMPTY TEXT in TEXT" 28 } ;# if 29 30 switch -- $paramInsertTag { 31 before - 32 after { 33 switch -- $cur_tag_type { 34 TEXT { 35 set new_tag [simxml::add $xml {} $tag_name -type $tag_type -text $text_sel \ 36 -position [list $paramInsertTag \ 37 [simxml::nodeInfo $xml $cur_tag parent]] \ 38 -extra $tag_extra] 39 } 40 TAG { 41 set new_tag [simxml::add $xml {} $tag_name -type $tag_type -text $text_sel\ 42 -position [list $paramInsertTag $cur_tag] \ 43 -extra $tag_extra] 44 } 45 } ;# switch 46 updateWidget $widget [simxml::nodeInfo $xml $new_tag parent] 47 # FAST update 48 #updateWidget $widget $new_tag 49 set type empty 50 if { [string equal $tag_type TEXT] } { set type text } 51 Cursor $widget set "[lindex [richtext::tagIndex $widget $new_tag -type $type] 0] + 1 chars" 52 $widget see insert 53 } 54 inside { 55 switch -- $cur_tag_type { 56 TEXT { 57 #set cur_start [lindex [$widget tag ranges $cur_tag:text] 0] 58 #set cur_end [lindex [$widget tag ranges $cur_tag:text] 1] 59 foreach { cur_start cur_end } [richtext::tagIndex $widget $cur_tag -type text] { break } 60 set text_sel {} 61 62 if {[llength [set cur_sel [selection $widget get index]]] > 0 } { 63 # SELECTION 64 # BUG!!!! error if selection have any tag inside 65 set sel_start [lindex $cur_sel 0] 66 set sel_end [lindex $cur_sel 1] 67 set text_sel [$widget get $sel_start $sel_end] 68 gui::msgDebug "SELECTION: ($text_sel) | $tag_type" 69 set text_start [$widget get $cur_start $sel_start ] 70 set text_end [$widget get $sel_end $cur_end ] 71 } else { 72 set text_start [$widget get $cur_start $cur_index ] 73 set text_end [$widget get $cur_index $cur_end ] 74 } ;# if-else SELECTION 75 76 simxml::setParam $xml $cur_tag -text $text_start 77 set new_tag [simxml::add $xml {} $tag_name -type $tag_type -text $text_sel \ 78 -position [list after $cur_tag] ] 79 simxml::add $xml {} {} -type TEXT -text $text_end \ 80 -position [list after $new_tag] 81 if { ! [string equal $text_sel {}] } { 82 simxml::add $xml $new_tag {} -type TEXT -text $text_sel -position {end} 83 } ;# if 84 85 if { [string equal $cur_tag_type TEXT] } { 86 updateWidget $widget [simxml::nodeInfo $xml $new_tag parent] 87 } else { 88 # FAST update 89 updateWidget $widget $new_tag 90 } ;# if-else TEXT tag 91 92 Cursor $widget set $cur_index -no-event true 93 $widget see insert 94 } 95 TAG { 96 set new_tag [simxml::add $xml $cur_tag $tag_name \ 97 -type $tag_type ] 98 updateWidget $widget $cur_tag 99 Cursor $widget set "[lindex [richtext::tagIndex $widget $new_tag -type empty] 0] + 1 chars" 100 $widget see insert 101 102 } 103 } ;# switch 104 } 105 } ;# switch $::paramInsertTag 106 107 gui::TreeExpressFill $new_tag 108} ;# proc insTag 109 110 111