Initial commit
This commit is contained in:
53
lib/modules/about.tcl
Executable file
53
lib/modules/about.tcl
Executable file
@@ -0,0 +1,53 @@
|
||||
########################################################
|
||||
# Tk LaTeX Editor
|
||||
# Distributed under GNU Public License
|
||||
# Author: Sergey Kalinin banzaj@lrn.ru
|
||||
# Copyright (c) "CONERO lab", 2002, http://conero.lrn.ru
|
||||
########################################################
|
||||
|
||||
## ABOUT DIALOG ##
|
||||
proc AboutDialog {} {
|
||||
global dir tree nb ver font release
|
||||
|
||||
set w .about
|
||||
if {[winfo exists $w]} {
|
||||
destroy $w
|
||||
}
|
||||
toplevel $w
|
||||
wm title $w [::msgcat::mc "About ..."]
|
||||
#wm resizable $w 0 0
|
||||
wm transient $w .
|
||||
|
||||
frame $w.frmImg -borderwidth 2 -relief ridge -background black
|
||||
image create photo imgAbout -format gif -file [file join $dir(img) tle.gif]
|
||||
image create photo imgConero -format gif -file [file join $dir(img) conero.gif]
|
||||
|
||||
label $w.frmImg.lblImg -image imgAbout -background black
|
||||
|
||||
pack $w.frmImg.lblImg -side top -fill x
|
||||
|
||||
frame $w.frmlbl -borderwidth 2 -relief ridge -background "#8700d1"
|
||||
label $w.frmlbl.lblVersion -text "[::msgcat::mc Version] $ver$release"\
|
||||
-background "#8700d1" -foreground black
|
||||
label $w.frmlbl.lblAuthorName -text "[::msgcat::mc Authors]:"\
|
||||
-background "#8700d1" -foreground black
|
||||
label $w.frmlbl.lblAuthor1 -text "Sergey Kalinin (aka BanZaj), banzaj@lrn.ru"\
|
||||
-background "#8700d1" -foreground black
|
||||
label $w.frmlbl.lblAuthor2 -text "Constantin I Makhailenko (aka Const), const@mail.ru"\
|
||||
-background "#8700d1" -foreground black
|
||||
|
||||
pack $w.frmlbl.lblVersion $w.frmlbl.lblAuthorName $w.frmlbl.lblAuthor1 $w.frmlbl.lblAuthor2 -side top -padx 5
|
||||
pack $w.frmImg -side top -fill x
|
||||
pack $w.frmlbl -side top -expand true -fill both
|
||||
|
||||
bind $w <Escape> "destroy .about"
|
||||
bind $w <Return> "destroy .about"
|
||||
#
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
234
lib/modules/addtext.tcl
Executable file
234
lib/modules/addtext.tcl
Executable file
@@ -0,0 +1,234 @@
|
||||
######################################################
|
||||
# TkTeXEditor
|
||||
# Distributed under GNU Public License
|
||||
# Author: Sergey Kalinin (BanZaj) banzaj@lrn.ru
|
||||
# Copyright (c) "CONERO lab", 2002, http://conero.lrn.ru
|
||||
######################################################
|
||||
|
||||
proc AddText {action} {
|
||||
global dir font color nb
|
||||
set node [$nb raise]
|
||||
if {$node == "" || $node == "debug"} {return}
|
||||
set text "$nb.f$node.f.text"
|
||||
set pos [$text index insert]
|
||||
set curLine [lindex [split $pos "."] 0]
|
||||
set cursor [lindex [split $pos "."] 1]
|
||||
set editLine [$text get $curLine.0 $pos]
|
||||
set types {
|
||||
{"EPS" {.eps}}
|
||||
{"PDF" {.pdf}}
|
||||
{"PNG" {.png}}
|
||||
{"JPG" {.jpg}}
|
||||
{"GIF" {.gif}}
|
||||
}
|
||||
set selIndex [$text tag ranges sel]
|
||||
if {$selIndex != ""} {
|
||||
set posBegin [lindex $selIndex 0]
|
||||
set posEnd [lindex $selIndex 1]
|
||||
set curLine [string range $posBegin 0 [expr [string first "\." $posBegin] - 1]]
|
||||
set cursor [string range $posBegin [expr [string first "\." $posBegin] + 1] end]
|
||||
set endLine [string range $posEnd 0 [expr [string first "\." $posEnd] - 1]]
|
||||
set endCur [string range $posEnd [expr [string first "\." $posBegin] + 1] end]
|
||||
set selText [$text get $posBegin $posEnd]
|
||||
} else {
|
||||
set posBegin "$curLine.$cursor"
|
||||
set endLine [expr $curLine +1]
|
||||
set endCur 0
|
||||
}
|
||||
switch -- $action {
|
||||
enumerate {
|
||||
#insert - 1 chars wordstart" "insert wordend - 1 chars"
|
||||
$text insert $posBegin "\\begin\{enumerate\}\n"
|
||||
$text insert [expr $curLine +1].0 "\\item \n"
|
||||
$text insert [expr $curLine +2].0 "\\end\{enumerate\}"
|
||||
set t [$text get $posBegin $curLine.end]
|
||||
set curPos "[expr $curLine + 1]\.end"
|
||||
}
|
||||
image {
|
||||
set file [tk_getOpenFile -initialdir $dir(doc) -filetypes $types -parent .\
|
||||
-title "[::msgcat::mc "Select image"]"]
|
||||
#set fileName [file tail $file]
|
||||
if {$file == ""} {
|
||||
return
|
||||
}
|
||||
$text insert $posBegin "\\includegraphics\[\]\{$file\}\n"
|
||||
set t [$text get $posBegin $curLine.end]
|
||||
set curPos "$curLine\.[string last "\\" $t]"
|
||||
}
|
||||
itemize {
|
||||
$text insert $posBegin "\\begin\{itemize\}\n"
|
||||
$text insert [expr $curLine +1].0 "\\item \n"
|
||||
$text insert [expr $curLine +2].0 "\\end\{itemize\}"
|
||||
set t [$text get $posBegin $curLine.end]
|
||||
set curPos "[expr $curLine +1]\.end"
|
||||
}
|
||||
item {
|
||||
set editLine [$text get [expr $curLine - 1].0 $pos]
|
||||
if [regexp -nocase -all -- {(\\item)} $editLine match v1] {
|
||||
$text insert $curLine.0 "\\item "
|
||||
set curPos "$curLine\.6"
|
||||
} else {
|
||||
return
|
||||
}
|
||||
}
|
||||
date {
|
||||
set editLine [$text get [expr $curLine - 1].0 $pos]
|
||||
set unixTime [exec date +%s]
|
||||
set dateTime [clock format $unixTime -format "%d.%m.%Y, %H:%M:%S"]
|
||||
$text insert $curLine.0 "$dateTime"
|
||||
set curPos "$curLine\.end"
|
||||
}
|
||||
}
|
||||
$text mark set insert $curPos
|
||||
$text see insert
|
||||
}
|
||||
|
||||
######################################################
|
||||
|
||||
proc AddTextFont {action} {
|
||||
global dir font color nb
|
||||
set node [$nb raise]
|
||||
if {$node == "" || $node == "debug"} {return}
|
||||
set text "$nb.f$node.f.text"
|
||||
set pos [$text index insert]
|
||||
set curLine [lindex [split $pos "."] 0]
|
||||
set cursor [lindex [split $pos "."] 1]
|
||||
set editLine [$text get $curLine.0 $pos]
|
||||
set selIndex [$text tag ranges sel]
|
||||
if {$selIndex != ""} {
|
||||
set posBegin [lindex $selIndex 0]
|
||||
set posEnd [lindex $selIndex 1]
|
||||
set curLine [string range $posBegin 0 [expr [string first "\." $posBegin] - 1]]
|
||||
set cursor [string range $posBegin [expr [string first "\." $posBegin] + 1] end]
|
||||
set endLine [string range $posEnd 0 [expr [string first "\." $posEnd] - 1]]
|
||||
set endCur [string range $posEnd [expr [string first "\." $posBegin] + 1] end]
|
||||
set selText [$text get $posBegin $posEnd]
|
||||
$text insert $endLine.$endCur "\}"
|
||||
$text insert $posBegin "\\$action\{"
|
||||
set t [$text get $posBegin $curLine.end]
|
||||
set curPos "$endLine\.end"
|
||||
$text mark set insert $curPos
|
||||
} else {
|
||||
set posBegin "$curLine.$cursor"
|
||||
set endLine [expr $curLine +0]
|
||||
$text insert $posBegin "\\$action\{\}"
|
||||
$text mark set insert "$endLine.end - 1 chars"
|
||||
}
|
||||
$text see insert
|
||||
}
|
||||
|
||||
proc AddTextCommand {action} {
|
||||
global dir font color nb
|
||||
set node [$nb raise]
|
||||
if {$node == "" || $node == "debug"} {return}
|
||||
set text "$nb.f$node.f.text"
|
||||
set pos [$text index insert]
|
||||
set curLine [lindex [split $pos "."] 0]
|
||||
set cursor [lindex [split $pos "."] 1]
|
||||
set editLine [$text get $curLine.0 $pos]
|
||||
set selIndex [$text tag ranges sel]
|
||||
if {$selIndex != ""} {
|
||||
set posBegin [lindex $selIndex 0]
|
||||
set posEnd [lindex $selIndex 1]
|
||||
set curLine [string range $posBegin 0 [expr [string first "\." $posBegin] - 1]]
|
||||
set cursor [string range $posBegin [expr [string first "\." $posBegin] + 1] end]
|
||||
set endLine [string range $posEnd 0 [expr [string first "\." $posEnd] - 1]]
|
||||
set endCur [string range $posEnd [expr [string first "\." $posBegin] + 1] end]
|
||||
set selText [$text get $posBegin $posEnd]
|
||||
$text insert $posBegin "\\$action "
|
||||
set t [$text get $posBegin $curLine.end]
|
||||
set curPos "$endLine\.end"
|
||||
$text mark set insert $curPos
|
||||
} else {
|
||||
set posBegin "$curLine.$cursor"
|
||||
set endLine [expr $curLine +0]
|
||||
$text insert $posBegin "\\$action "
|
||||
$text mark set insert "$endLine.end"
|
||||
}
|
||||
$text see insert
|
||||
}
|
||||
|
||||
proc AddTextDouble {beginText endText} {
|
||||
global dir font color nb
|
||||
set node [$nb raise]
|
||||
if {$node == "" || $node == "debug"} {return}
|
||||
set text "$nb.f$node.f.text"
|
||||
set pos [$text index insert]
|
||||
set curLine [lindex [split $pos "."] 0]
|
||||
set cursor [lindex [split $pos "."] 1]
|
||||
set editLine [$text get $curLine.0 $pos]
|
||||
set selIndex [$text tag ranges sel]
|
||||
|
||||
if {$selIndex != ""} {
|
||||
set posBegin [lindex $selIndex 0]
|
||||
set posEnd [lindex $selIndex 1]
|
||||
set curLine [string range $posBegin 0 [expr [string first "\." $posBegin] - 1]]
|
||||
set cursor [string range $posBegin [expr [string first "\." $posBegin] + 1] end]
|
||||
set endLine [string range $posEnd 0 [expr [string first "\." $posEnd] - 1]]
|
||||
set endCur [string range $posEnd [expr [string first "\." $posBegin] + 1] end]
|
||||
set selText [$text get $posBegin $posEnd]
|
||||
if {[string range $endText 0 1] == "\n"} {
|
||||
$text insert $endLine.$endCur " \\$endText"
|
||||
} else {
|
||||
$text insert $endLine.$endCur "\n\\[string trim $endText "\n"]"
|
||||
}
|
||||
$text insert $posBegin "\\$beginText "
|
||||
} else {
|
||||
set posBegin "$curLine.$cursor"
|
||||
if {[string range $endText 0 1] == "\n"} {
|
||||
$text insert $posBegin "\\$beginText \\$endText"
|
||||
} else {
|
||||
$text insert $posBegin "\\$beginText \n\\[string trim $endText "\n"]"
|
||||
puts "$beginText $endText"
|
||||
}
|
||||
}
|
||||
|
||||
set ind [expr [string length $beginText] + 2]
|
||||
set curPos "$posBegin + $ind chars"
|
||||
$text mark set insert $curPos
|
||||
$text see insert
|
||||
}
|
||||
|
||||
proc AddTextMath {beginText endText} {
|
||||
global dir font color nb
|
||||
set node [$nb raise]
|
||||
if {$node == "" || $node == "debug"} {return}
|
||||
set text "$nb.f$node.f.text"
|
||||
set pos [$text index insert]
|
||||
set curLine [lindex [split $pos "."] 0]
|
||||
set cursor [lindex [split $pos "."] 1]
|
||||
set editLine [$text get $curLine.0 $pos]
|
||||
set selIndex [$text tag ranges sel]
|
||||
|
||||
if {$selIndex != ""} {
|
||||
set posBegin [lindex $selIndex 0]
|
||||
set posEnd [lindex $selIndex 1]
|
||||
set curLine [string range $posBegin 0 [expr [string first "\." $posBegin] - 1]]
|
||||
set cursor [string range $posBegin [expr [string first "\." $posBegin] + 1] end]
|
||||
set endLine [string range $posEnd 0 [expr [string first "\." $posEnd] - 1]]
|
||||
set endCur [string range $posEnd [expr [string first "\." $posBegin] + 1] end]
|
||||
set selText [$text get $posBegin $posEnd]
|
||||
if {[string range $endText 0 1] == "\n"} {
|
||||
$text insert $endLine.$endCur " $endText"
|
||||
} else {
|
||||
$text insert $endLine.$endCur "[string trim $endText "\n"]"
|
||||
}
|
||||
$text insert $posBegin "$beginText "
|
||||
} else {
|
||||
set posBegin "$curLine.$cursor"
|
||||
if {[string range $endText 0 1] == "\n"} {
|
||||
$text insert $posBegin "$beginText \\$endText"
|
||||
} else {
|
||||
$text insert $posBegin "$beginText [string trim $endText "\n"]"
|
||||
}
|
||||
}
|
||||
set ind [expr [string length $beginText] + 2]
|
||||
set curPos "$posBegin + $ind chars"
|
||||
$text mark set insert $curPos
|
||||
$text see insert
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
84
lib/modules/baloon.tcl
Executable file
84
lib/modules/baloon.tcl
Executable file
@@ -0,0 +1,84 @@
|
||||
#######################################################################
|
||||
# Baloon help
|
||||
# Author: Alexander Dederer
|
||||
# Usage:
|
||||
# Set balloon tips to widget:
|
||||
# balloon $widget set "Hello World"
|
||||
# balloon [button .exit -text "exit" -command exit] set "Hello world"
|
||||
#
|
||||
# Clear ballon tips from widget:
|
||||
# balloon $widget clear
|
||||
#
|
||||
# Show balloon tips on widget:
|
||||
# balloon $widget show "Hello World"
|
||||
#######################################################################
|
||||
|
||||
proc balloon { widget action args } {
|
||||
global BALLOON font
|
||||
|
||||
switch -- $action {
|
||||
set {
|
||||
if { $args != {{}} } {
|
||||
balloon $widget clear
|
||||
#bind $widget <Any-Enter> "after 1000 [list balloon %W show $args mousepointer %X %Y]"
|
||||
#bind $widget <Any-Leave> "catch { destroy %W.balloon }"
|
||||
bind $widget <Enter> " balloon $widget show $args "
|
||||
bind $widget <Leave> " wm withdraw .bubble "
|
||||
}
|
||||
}
|
||||
show {
|
||||
if ![winfo exists .bubble] {
|
||||
toplevel .bubble -relief flat -background black -bd 1
|
||||
wm withdraw .bubble
|
||||
update
|
||||
array set attrFont [font actual fixed]
|
||||
set attrFont(-size) [expr $attrFont(-size) - 2]
|
||||
eval pack [message .bubble.txt -aspect 5000 -bg lightyellow \
|
||||
-font $font(normal) -text [lindex $args 0]]
|
||||
pack .bubble.txt
|
||||
wm transient .bubble .
|
||||
wm overrideredirect .bubble 1
|
||||
bind .bubble <Enter> "wm withdraw .bubble"
|
||||
}
|
||||
|
||||
if {$args == ""} { wm withdraw .bubble }
|
||||
set text [lindex $args 0]
|
||||
|
||||
set BALLOON $text
|
||||
switch $text {
|
||||
"" { wm withdraw .bubble ; update }
|
||||
"default" {
|
||||
after 1000 "raise_balloon $widget {$text}"
|
||||
after 7000 "if { \$BALLOON == {$text} } { wm withdraw .bubble ; update }"
|
||||
}
|
||||
} ;# switch
|
||||
}
|
||||
clear {
|
||||
catch { destroy .balloon }
|
||||
bind $widget <Enter> {}
|
||||
bind $widget <Leave> {}
|
||||
}
|
||||
} ;# switch action
|
||||
} ;# proc balloon
|
||||
|
||||
|
||||
proc raise_balloon {widget text} {
|
||||
global BALLOON
|
||||
|
||||
if { $BALLOON != $text } { wm withdraw .bubble ; update ; return }
|
||||
set cur_widget [winfo containing [winfo pointerx .] [winfo pointery .]]
|
||||
if { $cur_widget != $widget } { return }
|
||||
|
||||
raise .bubble
|
||||
.bubble.txt configure -text $text
|
||||
set b_x [expr [winfo pointerx .] - [winfo reqwidth .bubble]/2]
|
||||
set b_y [expr [winfo pointery .] + 15]
|
||||
wm geometry .bubble +$b_x+$b_y
|
||||
wm deiconify .bubble
|
||||
update
|
||||
} ;# proc raise_balloon
|
||||
|
||||
|
||||
|
||||
|
||||
|
163
lib/modules/completition.tcl
Executable file
163
lib/modules/completition.tcl
Executable file
@@ -0,0 +1,163 @@
|
||||
###########################################################
|
||||
# Tcl/Tk Project Manager #
|
||||
# Distrubuted under GPL #
|
||||
# Copyright (c) "CONERO lab", 2002, http://conero.lrn.ru #
|
||||
# Author: Sergey Kalinin (aka BanZaj) banzaj@lrn.ru #
|
||||
###########################################################
|
||||
# AutoCompletition Procedure #
|
||||
# Author Alex DEDERER #
|
||||
# Modify by Sergey (BanZaj) Kalinin 23.05.2002 #
|
||||
###########################################################
|
||||
|
||||
proc auto_completition { widget } {
|
||||
set start_word [$widget get "insert - 1 chars wordstart" insert]
|
||||
set box [$widget bbox insert]
|
||||
set box_x [expr [lindex $box 0] + [winfo rootx $widget] ]
|
||||
set box_y [expr [lindex $box 1] + [winfo rooty $widget] + [lindex $box 3] ]
|
||||
|
||||
set cnt 0
|
||||
set pos "1.0"
|
||||
set last_pos ""
|
||||
set pattern "$start_word\\w*"
|
||||
|
||||
set list_word($start_word) 1
|
||||
while { ([set start [$widget search -count cnt -regexp -- $pattern $pos end]] != "") } {
|
||||
set word [$widget get $start "$start + $cnt chars"]
|
||||
if { ![string equal $start_word $word] } { set list_word($word) 1 }
|
||||
set pos [$widget index "$pos + [expr $cnt + 1] chars"]
|
||||
if { [string equal $last_pos $pos] } { break }
|
||||
set last_pos $pos
|
||||
} ;# while
|
||||
|
||||
bindtags $widget [list CompletitionBind [winfo toplevel $widget] $widget Text sysAfter all]
|
||||
bind CompletitionBind <Escape> "bindtags $widget {[list [winfo toplevel $widget] $widget Text sysAfter all]}; catch { destroy .aCompletition }"
|
||||
bind CompletitionBind <Key> { auto_completition_key %W %K %A ; break}
|
||||
eval auto_completition_win $box_x $box_y [array names list_word]
|
||||
} ;# proc auto_completition
|
||||
|
||||
## PROCEDURE LIST ##
|
||||
## by BanZaj ##
|
||||
proc AutoComplit {} {
|
||||
global cmd activeFile nb
|
||||
set node $activeFile
|
||||
if {$node == ""} {return}
|
||||
set widget "$nb.f$node.f.text"
|
||||
|
||||
set start_word [$widget get "insert - 1 chars wordstart" insert]
|
||||
set box [$widget bbox insert]
|
||||
set box_x [expr [lindex $box 0] + [winfo rootx $widget] ]
|
||||
set box_y [expr [lindex $box 1] + [winfo rooty $widget] + [lindex $box 3] ]
|
||||
|
||||
set cnt 0
|
||||
set pos "1.0"
|
||||
set last_pos ""
|
||||
set pattern "$start_word\\w*"
|
||||
set i 0
|
||||
|
||||
for {set j 0} {$j <= [llength $cmd(all)]} {incr j} {
|
||||
set line [lindex $cmd(all) $j]
|
||||
if [regexp -nocase -all -- {(\\)([a-zA-Z]*)(\{\})} $line word] {
|
||||
set word [string trim $word "\\"]
|
||||
if {[string match "$start_word*" $word]} {
|
||||
set list_word($word) $word
|
||||
incr i
|
||||
}
|
||||
}
|
||||
if {[string match "$start_word*" $line]} {
|
||||
set list_word($line) $line
|
||||
incr i
|
||||
}
|
||||
}
|
||||
if {[array names list_word] == ""} {
|
||||
return
|
||||
}
|
||||
bindtags $widget [list CompletitionBind [winfo toplevel $widget] $widget Text sysAfter all]
|
||||
bind CompletitionBind <Escape> "bindtags $widget {[list [winfo toplevel $widget] $widget Text sysAfter all]}; catch { destroy .aCompletition }"
|
||||
bind CompletitionBind <Key> {auto_completition_key %W %K %A ; break}
|
||||
eval auto_completition_win $box_x $box_y [array names list_word]
|
||||
} ;# proc auto_completition_proc
|
||||
|
||||
|
||||
proc auto_completition_win { x y args} {
|
||||
set win .aCompletition
|
||||
if { [winfo exists $win] } { destroy $win }
|
||||
toplevel $win
|
||||
wm transient $win .
|
||||
wm overrideredirect $win 1
|
||||
|
||||
listbox $win.lBox -width 30 -border 2 -yscrollcommand "$win.yscroll set" -border 1
|
||||
scrollbar $win.yscroll -orient vertical -command "$win.lBox yview" -width 13 -border 1
|
||||
pack $win.lBox -expand true -fill y -side left
|
||||
pack $win.yscroll -side left -expand false -fill y
|
||||
|
||||
foreach { word } $args {
|
||||
$win.lBox insert end $word
|
||||
} ;# foreach | insert all word
|
||||
|
||||
catch { $win.lBox activate 0 ; $win.lBox selection set 0 0 }
|
||||
|
||||
if { [set height [llength $args]] > 10 } { set height 10 }
|
||||
$win.lBox configure -height $height
|
||||
|
||||
bind $win <Escape> " destroy $win "
|
||||
bind $win.lBox <Escape> " destroy $win "
|
||||
|
||||
wm geom $win +$x+$y
|
||||
} ;# auto_completition_win
|
||||
|
||||
|
||||
|
||||
proc auto_completition_key { widget K A } {
|
||||
set win .aCompletition
|
||||
set ind [$win.lBox curselection]
|
||||
|
||||
switch -- $K {
|
||||
Prior {
|
||||
set up [expr [$win.lBox index active] - [$win.lBox cget -height]]
|
||||
if { $up < 0 } { set up 0 }
|
||||
$win.lBox activate $up
|
||||
$win.lBox selection clear 0 end
|
||||
$win.lBox selection set $up $up
|
||||
}
|
||||
Next {
|
||||
set down [expr [$win.lBox index active] + [$win.lBox cget -height]]
|
||||
if { $down >= [$win.lBox index end] } { set down end }
|
||||
$win.lBox activate $down
|
||||
$win.lBox selection clear 0 end
|
||||
$win.lBox selection set $down $down
|
||||
}
|
||||
Up {
|
||||
set up [expr [$win.lBox index active] - 1]
|
||||
if { $up < 0 } { set up 0 }
|
||||
$win.lBox activate $up
|
||||
$win.lBox selection clear 0 end
|
||||
$win.lBox selection set $up $up
|
||||
}
|
||||
Down {
|
||||
set down [expr [$win.lBox index active] + 1]
|
||||
if { $down >= [$win.lBox index end] } { set down end }
|
||||
$win.lBox activate $down
|
||||
$win.lBox selection clear 0 end
|
||||
$win.lBox selection set $down $down
|
||||
}
|
||||
Return {
|
||||
$widget delete "insert - 1 chars wordstart" "insert wordend - 1 chars"
|
||||
$widget insert "insert" [$win.lBox get [$win.lBox curselection]]
|
||||
#$widget mark set insert "insert wordend - 1 chars"
|
||||
#$widget see insert
|
||||
eval [bind CompletitionBind <Escape>]
|
||||
}
|
||||
default {
|
||||
$widget insert "insert" $A
|
||||
eval [bind CompletitionBind <Escape>]
|
||||
}
|
||||
}
|
||||
} ;# proc auto_completition_key
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
252
lib/modules/convert.tcl
Executable file
252
lib/modules/convert.tcl
Executable file
@@ -0,0 +1,252 @@
|
||||
######################################################
|
||||
# Tk LaTeX Editor
|
||||
# Distributed under GNU Public License
|
||||
# Author: Sergey Kalinin (BanZaj) banzaj@lrn.ru
|
||||
# Copyright (c) "CONERO lab", 2002, http://conero.lrn.ru
|
||||
######################################################
|
||||
|
||||
|
||||
proc Latex2Html {} {
|
||||
global tree module cmdString
|
||||
set selFiles [$tree selection get]
|
||||
if {[llength $selFiles] == 0} {
|
||||
set answer [tk_messageBox\
|
||||
-message "[::msgcat::mc "Don't selected file"]"\
|
||||
-type ok -icon warning\
|
||||
-title [::msgcat::mc "Warning"]]
|
||||
case $answer {
|
||||
ok {return 0}
|
||||
}
|
||||
}
|
||||
if {[llength $selFiles] == 1} {
|
||||
if {$selFiles != ""} {
|
||||
set file [$tree itemcget $selFiles -data]
|
||||
}
|
||||
CommandStringDialog $file
|
||||
}
|
||||
#puts $command
|
||||
}
|
||||
proc ConvertDialog {action} {
|
||||
global nb files font color cmdString module tcl_platform module convert_cmd activeFile act
|
||||
set act $action
|
||||
if [info exists activeFile] {
|
||||
set nod $activeFile
|
||||
} else {
|
||||
return
|
||||
}
|
||||
if {[info exists files($nod)] == 0} {
|
||||
return
|
||||
}
|
||||
set file [lindex $files($nod) 0]
|
||||
|
||||
set w .cmd
|
||||
# destroy the find window if it already exists
|
||||
if {[winfo exists $w]} {
|
||||
destroy $w
|
||||
}
|
||||
|
||||
toplevel $w
|
||||
wm title $w [::msgcat::mc "Command options"]
|
||||
wm resizable $w 0 0
|
||||
wm transient $w .
|
||||
frame $w.frmCombo -borderwidth 1 -background $color(bg)
|
||||
frame $w.frmBtn -borderwidth 1 -background $color(bg)
|
||||
pack $w.frmCombo $w.frmBtn -side top -fill x
|
||||
|
||||
# set combo [entry $w.frmCombo.entFind]
|
||||
label $w.frmCombo.lblModule -text "[::msgcat::mc "Convert to"] \"$action\"" -background $color(bg)
|
||||
label $w.frmCombo.lblFile -text "[::msgcat::mc "File"] \"$file\"" -background $color(bg)
|
||||
set combo [entry $w.frmCombo.txtString]
|
||||
|
||||
pack $w.frmCombo.lblModule $w.frmCombo.lblFile $combo -fill x -padx 2 -pady 2 -side top
|
||||
|
||||
button $w.frmBtn.btnFind -text [::msgcat::mc "Run"]\
|
||||
-font $font(normal) -width 12 -relief groove -background $color(bg)\
|
||||
-command {
|
||||
set convert_cmd($act) [.cmd.frmCombo.txtString get]
|
||||
Convert $act
|
||||
destroy .cmd
|
||||
}
|
||||
button $w.frmBtn.btnCancel -text [::msgcat::mc "Close"]\
|
||||
-relief groove -width 12 -font $font(normal) -background $color(bg)\
|
||||
-command "destroy $w"
|
||||
pack $w.frmBtn.btnFind $w.frmBtn.btnCancel -fill x -padx 2 -pady 2 -side left
|
||||
|
||||
bind $w <Return> {
|
||||
set convert_cmd($act) [.cmd.frmCombo.txtString get]
|
||||
Convert $act
|
||||
destroy .cmd
|
||||
}
|
||||
bind $w <Escape> "destroy $w"
|
||||
$combo insert end "$convert_cmd($action)"
|
||||
focus -force $combo
|
||||
|
||||
}
|
||||
|
||||
proc Convert {action} {
|
||||
global dir nb files font activeFile tcl_platform module convert_cmd makeThread tree
|
||||
set curDir [pwd]
|
||||
#set node [$nb raise]
|
||||
if [info exists activeFile] {
|
||||
set nod $activeFile
|
||||
while {[set parentNode [$tree parent $nod]] != "root"} {
|
||||
set nod $parentNode
|
||||
}
|
||||
} else {
|
||||
return
|
||||
}
|
||||
if {[info exists files($nod)] == 0} {
|
||||
return
|
||||
}
|
||||
if {$module(convert_$action) == ""} {
|
||||
set answer [tk_messageBox\
|
||||
-message "[::msgcat::mc "Don't find programm"] $convert_cmd($action)"\
|
||||
-type ok -icon warning\
|
||||
-title [::msgcat::mc "Warning"]]
|
||||
case $answer {
|
||||
ok {return 0}
|
||||
}
|
||||
}
|
||||
|
||||
set text "$nb.f$nod.f.text"
|
||||
set fullPath [lindex $files($nod) 0]
|
||||
set folder [file dirname $fullPath]
|
||||
set file [file tail $fullPath]
|
||||
set ext [string trim [file extension $file] {.}]
|
||||
set name [file rootname $file]
|
||||
|
||||
##
|
||||
set node "debug"
|
||||
if {[$nb index $node] != -1} {
|
||||
$nb delete debug
|
||||
}
|
||||
set w [$nb insert end $node -text [::msgcat::mc "Running project"]]
|
||||
# create array with file names #
|
||||
set w [frame $w.f]
|
||||
pack $w -side top -fill both -expand true
|
||||
|
||||
frame $w.frame -borderwidth 2 -relief ridge
|
||||
pack $w.frame -side top -fill both -expand true
|
||||
|
||||
|
||||
text $w.frame.text -yscrollcommand "$w.frame.yscroll set" \
|
||||
-relief sunken -wrap word -highlightthickness 0 -font $font(normal)\
|
||||
-selectborderwidth 0 -selectbackground #55c4d1 -width 10 -height 10
|
||||
scrollbar $w.frame.yscroll -relief sunken -borderwidth {1} -width {10} -takefocus 0 \
|
||||
-command "$w.frame.text yview"
|
||||
|
||||
pack $w.frame.text -side left -fill both -expand true
|
||||
pack $w.frame.yscroll -side left -fill y
|
||||
|
||||
## READLINE WIDGET ##
|
||||
frame $w.frmReadline -borderwidth 2 -relief ridge -height 5
|
||||
pack $w.frmReadline -side top -fill x
|
||||
text $w.frmReadline.text2 -yscrollcommand "$w.frmReadline.yscroll2 set" \
|
||||
-relief sunken -wrap word -highlightthickness 0 -font $font(normal)\
|
||||
-selectborderwidth 0 -selectbackground #55c4d1 -width 10 -height 5
|
||||
scrollbar $w.frmReadline.yscroll2 -relief sunken -borderwidth {1} -width {10} -takefocus 0 \
|
||||
-command "$w.frmReadline.text2 yview"
|
||||
pack $w.frmReadline.text2 -side left -fill both -expand true
|
||||
pack $w.frmReadline.yscroll2 -side left -fill y
|
||||
|
||||
bind $w.frmReadline.text2 <Return> ReadLine
|
||||
|
||||
balloon $w.frmReadline.text2 set [::msgcat::mc "Enter LaTeX command here and push Enter"]
|
||||
|
||||
pane::create $w.frame $w.frmReadline -orient horizontal -percent 0.9
|
||||
|
||||
|
||||
# key bindings #
|
||||
|
||||
$nb raise $node
|
||||
#insert debug data into text widget #
|
||||
set pos [$w.frame.text index insert]
|
||||
set lineNum [lindex [split $pos "."] 0]
|
||||
$w.frame.text insert end "[::msgcat::mc "Work with file"] $fullPath\n"
|
||||
|
||||
if {[catch {cd $folder}] != 0} {return ""}
|
||||
FileDialog save
|
||||
set cmdString $convert_cmd($action)
|
||||
if [regexp -nocase "%dirName" $convert_cmd($action) v] {
|
||||
regsub -all -- {%dirName} $cmdString $folder cmdString
|
||||
puts "$cmdString"
|
||||
}
|
||||
if [regexp -nocase "%fileName" $convert_cmd($action) v] {
|
||||
regsub -all -- {%fileName} $cmdString $name cmdString
|
||||
puts "$cmdString"
|
||||
} else {
|
||||
set cmdString "$convert_cmd($action) $fullPath"
|
||||
}
|
||||
puts "$cmdString"
|
||||
$w.frame.text insert end "[::msgcat::mc "Make"] $action [::msgcat::mc "file"]\n"
|
||||
$w.frame.text insert end "$cmdString\n\n"
|
||||
|
||||
set pipe [open "|$cmdString" "w+"]
|
||||
set makeThread $pipe
|
||||
|
||||
$w.frame.text insert end "----------------- [::msgcat::mc "Programm output"] -----------------\n"
|
||||
$w.frame.text tag add bold $lineNum.0 $lineNum.end
|
||||
|
||||
focus -force $w.frmReadline.text2
|
||||
|
||||
fileevent $pipe readable [list DebugInfo $w.frame.text $pipe $folder]
|
||||
fconfigure $pipe -buffering none -blocking no
|
||||
catch {cd $curDir}
|
||||
}
|
||||
|
||||
proc ReadLine {} {
|
||||
global makeThread
|
||||
set pos [.frmBody.frmEditor.noteBook.fdebug.f.frmReadline.text2 index insert]
|
||||
set lineNumber [lindex [split $pos "."] 0]
|
||||
set cmd [.frmBody.frmEditor.noteBook.fdebug.f.frmReadline.text2 get $lineNumber.0 $lineNumber.end]
|
||||
puts $cmd
|
||||
fileevent $makeThread writable
|
||||
if [info exists makeThread] {
|
||||
puts $makeThread "$cmd"
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
proc ConvertImage {file} {
|
||||
global dir convert_cmd render activeFile files nb thumb
|
||||
set file [string trimleft [string trimright $file "\}"] "\{"]
|
||||
set inFormat [GetExtention $file]
|
||||
set name [file rootname [file tail $file]]
|
||||
set imgFile "$name.$thumb(format)"
|
||||
puts "$file\t$imgFile"
|
||||
set _dir [file join [file dirname $file] .thumb]
|
||||
|
||||
if {[file exists $_dir] == 0} { file mkdir $_dir }
|
||||
if [file exists [file join $_dir $imgFile]] {
|
||||
puts "File exists [file join $_dir $imgFile]"
|
||||
return "[file join $_dir $imgFile]"
|
||||
} else {
|
||||
puts "$convert_cmd(img) +adjoin +antialias -quality 10 -transparent $render(bg) -density $render(res) $file $_dir/$imgFile"
|
||||
}
|
||||
|
||||
#set file [file tail $file]
|
||||
if {$render(trans) == 1} {
|
||||
if {$render(aa) == 1} {
|
||||
catch [exec $convert_cmd(img) +adjoin -antialias -quality 10 -transparent $render(bg) -scale $thumb(resolution) $file [file join $_dir $imgFile]] err
|
||||
} else {
|
||||
catch [exec $convert_cmd(img) +adjoin +antialias -quality 10 -transparent $render(bg) -scale $thumb(resolution) $file [file join $_dir $imgFile]] err
|
||||
}
|
||||
} else {
|
||||
if {$render(aa) == 1} {
|
||||
catch [exec $convert_cmd(img) +adjoin -antialias -quality 10 -scale $thumb(resolution) $file [file join $_dir $imgFile]] err
|
||||
} else {
|
||||
catch [exec $convert_cmd(img) +adjoin +antialias -quality 10 -scale $thumb(resolution) $file [file join $_dir $imgFile]] err
|
||||
}
|
||||
}
|
||||
if {$err != ""} {
|
||||
set answer [tk_messageBox -message "$err"\
|
||||
-type ok -icon warning -title [::msgcat::mc "Warning"]]
|
||||
case $answer {
|
||||
ok {return}
|
||||
}
|
||||
puts $err
|
||||
}
|
||||
return "[file join $_dir $imgFile]"
|
||||
}
|
||||
|
||||
|
674
lib/modules/editor.tcl
Executable file
674
lib/modules/editor.tcl
Executable file
@@ -0,0 +1,674 @@
|
||||
#########################################################
|
||||
# TkTeXeditor
|
||||
# Distributed under GNU Public License
|
||||
# Author: Sergey Kalinin (BanZaj) banzaj@lrn.ru
|
||||
# Copyright (c) "CONERO lrn", 2000, http//conero.lrn.ru
|
||||
#########################################################
|
||||
|
||||
|
||||
## FILE EDITOR WINDOW ##
|
||||
proc EditFile {file} {
|
||||
global dir font tree nb files color files index status activeFile treeStruct ver
|
||||
global editor backup status replace sysenc release
|
||||
wm title . "TkLaTeXEditor $ver$release - $file"
|
||||
|
||||
if {[file exists $file] == 0} {
|
||||
set answer [tk_messageBox -message "$f [::msgcat::mc "File not found"]"\
|
||||
-type ok -icon warning -title [::msgcat::mc "Warning"]]
|
||||
case $answer {
|
||||
ok {return}
|
||||
}
|
||||
}
|
||||
|
||||
set fileName [file tail $file]
|
||||
set fileDir [file dirname $file]
|
||||
set dir(current) $fileDir
|
||||
puts "============ $fileName $fileDir"
|
||||
set node [InsertTreeNode $fileName $fileDir]
|
||||
#set node [NodeInsert $fileName $fileDir ""]
|
||||
set activeFile $node
|
||||
set replace 0 ;# for Overwrite procedure# execute external editor #
|
||||
if {$editor(extern)=="Yes"} {
|
||||
set pipe [open "|$editor(prog) $file" "r"]
|
||||
fileevent $pipe readable
|
||||
fconfigure $pipe -buffering none -blocking no
|
||||
return
|
||||
}
|
||||
## check active file and if them don't exists return 0
|
||||
if {[info exists files($node)] != 1} {
|
||||
set files($node) [list $file 0]
|
||||
set w [$nb insert end $node -text "$fileName"]
|
||||
} else {
|
||||
# puts "$file - already opened"
|
||||
return
|
||||
}
|
||||
## update statusbar info
|
||||
$status(fileAttr) configure -text "[FileAttr $file]"
|
||||
$status(fileSize) configure -text "[file size $file] b."
|
||||
$status(encode) configure -text "[lindex $files($node) 2]"
|
||||
|
||||
## create frames and text widget #
|
||||
frame $w.f -borderwidth 2 -relief ridge
|
||||
pack $w.f -side top -fill both -expand true
|
||||
|
||||
#supertext::text
|
||||
supertext::text $w.f.text -yscrollcommand "$w.f.yscroll set" \
|
||||
-relief sunken -wrap $editor(wrap) -highlightthickness 0 -font $font(editNormal)\
|
||||
-background $color(editBg) -foreground $color(editFg)\
|
||||
-selectborderwidth 0 -selectbackground $color(selectbg) -width 10
|
||||
# lines numbering
|
||||
|
||||
#set txtLineNumber [text $w.f.text_lines -yscrollcommand "$w.f.yscroll set" \
|
||||
#-relief sunken -wrap $editor(wrap) -highlightthickness 0 -font $font(editNormal)\
|
||||
#-background $color(lineNumberBg) -foreground $color(lineNumberFg)\
|
||||
#-selectborderwidth 0 -selectbackground $color(selectbg) -width 5]
|
||||
|
||||
scrollbar $w.f.yscroll -relief sunken -borderwidth {1} -width {10} -takefocus 0 \
|
||||
-command "$w.f.text yview"
|
||||
|
||||
#pack $w.f.text_lines -side left -fill y
|
||||
pack $w.f.text -side left -fill both -expand true
|
||||
pack $w.f.yscroll -side left -fill y
|
||||
|
||||
$nb raise $node
|
||||
## loadig tags for highlight procedure
|
||||
LoadTag $w.f.text
|
||||
#puts $w.f.text
|
||||
## BACKUP FILE CREATED ##
|
||||
if {$backup(create) == "Yes"} {
|
||||
file copy -force -- $file [file join $dir(tmp) $fileName~]
|
||||
}
|
||||
## OPENED FILE ##
|
||||
set fHandle [open "$file" r]
|
||||
set sourceEnc [DocRecode $fHandle]
|
||||
if {$sourceEnc == ""} {
|
||||
set sourceEnc [encoding system]
|
||||
}
|
||||
lappend files($node) "$sourceEnc" ;# added encoding information
|
||||
$status(encode) configure -text "[lindex $files($node) 2]"
|
||||
|
||||
set lineNumber 1
|
||||
$treeStruct delete [$treeStruct nodes root] ;# delete all info about old structure
|
||||
while {[gets $fHandle line]>=0} {
|
||||
set line [encoding convertfrom $sourceEnc $line]
|
||||
$w.f.text insert end "[string trimright $line]\n"
|
||||
InsertStruct $node $line $lineNumber $fileDir
|
||||
HighLightTEX $w.f.text $line $lineNumber $node
|
||||
#$txtLineNumber insert end "$lineNumber\n"
|
||||
incr lineNumber
|
||||
}
|
||||
close $fHandle
|
||||
# key bindings #
|
||||
set text $w.f.text
|
||||
bind $text <Control-G> GoToLine
|
||||
bind $text <Control-g> GoToLine
|
||||
bind $text <Control-F> Find
|
||||
bind $text <Control-f> Find
|
||||
#bind $text <F2> SplitWindow
|
||||
#bind $text <F6> {ConvertDialog ps}
|
||||
#bind $text <F7> {ConvertDialog pdf}
|
||||
|
||||
bind $text <Control-R> ReplaceDialog
|
||||
bind $text <Control-r> ReplaceDialog
|
||||
#bind $text <F4> {ReplaceCommand $w.frame.text 1}
|
||||
bind $text <Control-S> {FileDialog save}
|
||||
bind $text <Control-s> {FileDialog save}
|
||||
bind $text <Control-A> {FileDialog save_as}
|
||||
bind $text <Control-a> {FileDialog save_as}
|
||||
bind $text <Control-W> {FileDialog close}
|
||||
bind $text <Control-w> {FileDialog close}
|
||||
bind $text <Control-X> "tk_textCut $w.f.text;break"
|
||||
bind $text <Control-x> "tk_textCut $w.f.text;break"
|
||||
bind $text <Control-C> "tk_textCopy $w.f.text;break"
|
||||
bind $text <Control-c> "tk_textCopy $w.f.text;break"
|
||||
bind $text <Control-V> "tk_textPaste $w.f.text;break"
|
||||
bind $text <Control-v> "tk_textPaste $w.f.text;break"
|
||||
bind $text <Control-q> exit
|
||||
bind $text <Control-Q> exit
|
||||
bind $text <Control-z> "$text undo"
|
||||
bind $text <Control-Z> "$text undo"
|
||||
bind $text <Alt-c> AutoComplit
|
||||
bind $text <Alt-C> AutoComplit
|
||||
bind $text <Alt-f> "GenerateFormula math"
|
||||
bind $text <Alt-F> "GenerateFormula math"
|
||||
bind $text <Alt-t> "GenerateFormula text"
|
||||
bind $text <Alt-T> "GenerateFormula text"
|
||||
bind $text <ButtonRelease-1> {$status(pos) configure -text [%W index insert]}
|
||||
bind $text <Insert> {OverWrite}
|
||||
bind $text <Button-3> {catch [PopupMenu %W %X %Y]}
|
||||
bind $text <KeyRelease-Return> {
|
||||
AddText item
|
||||
set pos [%W index insert]
|
||||
set line [lindex [split $pos "."] 0]
|
||||
set editLine [%W get $line.0 $pos]
|
||||
HighLightTEX %W $editLine $line [$nb raise]
|
||||
set node [$nb raise]
|
||||
if {$node == "" || $node == "debug" || $node == "settings" || $node == "about"} {return 1}
|
||||
if {[lindex $files($node) 1] == 0} {
|
||||
set files($node) [list [lindex $files($node) 0] 1 [lindex $files($node) 2]]
|
||||
$status(active) configure -text [::msgcat::mc "File modify"]
|
||||
$nb itemconfigure $node -foreground $color(editTitleModify)
|
||||
}
|
||||
}
|
||||
|
||||
bind $text <KeyRelease> {
|
||||
set node [$nb raise]
|
||||
if {$node == "" || $node == "debug" || $node == "settings" || $node == "about"} {return 1}
|
||||
set text "$nb.f$node.f.text"
|
||||
set pos [$text index insert]
|
||||
set line [lindex [split $pos "."] 0]
|
||||
set symbol [lindex [split $pos "."] 1]
|
||||
set editLine [$text get $line.0 $pos]
|
||||
HighLightTEX $text $editLine $line $node
|
||||
$status(pos) configure -text [$text index insert];# cursor position
|
||||
if {$symbol >= $editor(strLen)} {
|
||||
if {[Key %k] == "true"} {
|
||||
|
||||
if {$editor(strWrap) == "Yes"} {
|
||||
#$text insert $line.end "\n"
|
||||
set p [$text search -backward -regexp -- {\s} $pos $line.0]
|
||||
if {$p !=""} {
|
||||
$text insert "$p + 1 chars" "\n"
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
if {[Key %k] == "true"} {
|
||||
if {[lindex $files($node) 1] == 0} {
|
||||
set files($node) [list [lindex $files($node) 0] 1 [lindex $files($node) 2]]
|
||||
$status(active) configure -text [::msgcat::mc "File modify"]
|
||||
$nb itemconfigure $node -foreground $color(editTitleModify)
|
||||
}
|
||||
}
|
||||
}
|
||||
bind $text <KeyPress> {
|
||||
if {[Key %k] == "true"} {
|
||||
ReplaceChar %W
|
||||
}
|
||||
set node [$nb raise]
|
||||
if {$node == "" || $node == "debug" || $node == "settings" || $node == "about"} {return 1}
|
||||
set text "$nb.f$node.f.text"
|
||||
set pos [$text index insert]
|
||||
set line [lindex [split $pos "."] 0]
|
||||
set symbol [lindex [split $pos "."] 1]
|
||||
set editLine [$text get $line.0 $pos]
|
||||
HighLightTEX $text $editLine $line $node
|
||||
$status(pos) configure -text [$text index insert];# cursor position
|
||||
if {$symbol >= $editor(strLen)} {
|
||||
if {[Key %k] == "true"} {
|
||||
if {$editor(strWrap) == "Yes"} {
|
||||
#$text insert $line.end "\n"
|
||||
set p [$text search -backward -regexp -- {\s} $pos $line.0]
|
||||
if {$p !=""} {
|
||||
$text insert "$p + 1 chars" "\n"
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
bind $text <KeyPress-space> {
|
||||
if {[Key %k] == "true"} {
|
||||
ReplaceChar %W
|
||||
}
|
||||
}
|
||||
bind $text <KeyRelease-space> {
|
||||
set node [$nb raise]
|
||||
if {$node == "" || $node == "debug" || $node == "settings" || $node == "about"} {return 1}
|
||||
if {[lindex $files($node) 1] == 0} {
|
||||
set files($node) [list [lindex $files($node) 0] 1 [lindex $files($node) 2]]
|
||||
$status(active) configure -text [::msgcat::mc "File modify"]
|
||||
$nb itemconfigure $node -foreground $color(editTitleModify)
|
||||
}
|
||||
}
|
||||
bind $text <Control-u> {
|
||||
set i -1
|
||||
switch -- [%W get "insert - 1 chars"] {
|
||||
\{ {set i [_searchCloseBracket %W \{ \} insert end]}
|
||||
\[ {set i [_searchCloseBracket %W \[ \] insert end]}
|
||||
( {set i [_searchCloseBracket %W ( ) insert end]}
|
||||
\} {set i [_searchOpenBracket %W \{ \} insert 1.0]}
|
||||
\] {set i [_searchOpenBracket %W \[ \] insert 1.0]}
|
||||
) {set i [_searchOpenBracket %W ( ) insert 1.0]}
|
||||
} ;# switch
|
||||
if { $i != -1 } {
|
||||
%W mark set insert $i
|
||||
%W see insert
|
||||
}
|
||||
} ;# bind
|
||||
bindtags $text [list [winfo toplevel $text] $text Text sysAfter all]
|
||||
bind sysAfter <Any-Key> {+ set i -1
|
||||
catch {
|
||||
switch -- [%W get "insert - 1 chars"] {
|
||||
\{ {set i [_searchCloseBracket %W \{ \} insert end]}
|
||||
\[ {set i [_searchCloseBracket %W \[ \] insert end]}
|
||||
( {set i [_searchCloseBracket %W ( ) insert end]}
|
||||
\} {set i [_searchOpenBracket %W \{ \} insert 1.0]}
|
||||
\] {set i [_searchOpenBracket %W \[ \] insert 1.0]}
|
||||
) {set i [_searchOpenBracket %W ( ) insert 1.0]}
|
||||
} ;# switch
|
||||
catch { %W tag remove lightBracket 1.0 end }
|
||||
if { $i != -1 } {%W tag add lightBracket "$i - 1 chars" $i}
|
||||
}
|
||||
} ;# bind sysAfter
|
||||
|
||||
bind sysAfter <Button-1> [bind sysAfter <Any-Key>]
|
||||
focus -force $w.f.text
|
||||
|
||||
Timer $file "refresh"
|
||||
if {$backup(autosave) == "Yes"} {
|
||||
Timer $file "autosave"
|
||||
}
|
||||
|
||||
|
||||
|
||||
};# proc EditFile
|
||||
|
||||
proc _searchCloseBracket { widget o_bracket c_bracket start_pos end_pos } {
|
||||
set o_count 1
|
||||
set c_count 0
|
||||
set found 0
|
||||
set pattern "\[\\$o_bracket\\$c_bracket\]"
|
||||
set pos [$widget search -regexp -- $pattern $start_pos $end_pos]
|
||||
while { ! [string equal $pos {}] } {
|
||||
set char [$widget get $pos]
|
||||
#tk_messageBox -title $pattern -message "char: $char; $pos; o_count=$o_count; c_count=$c_count"
|
||||
if {[string equal $char $o_bracket]} {incr o_count ; set found 1}
|
||||
if {[string equal $char $c_bracket]} {incr c_count ; set found 1}
|
||||
if {($found == 1) && ($o_count == $c_count) } { return [$widget index "$pos + 1 chars"] }
|
||||
set found 0
|
||||
set start_pos "$pos + 1 chars"
|
||||
set pos [$widget search -regexp -- $pattern $start_pos $end_pos]
|
||||
} ;# while search
|
||||
return -1
|
||||
} ;# proc _searchCloseBracket
|
||||
|
||||
# DEDERER
|
||||
## Search open bracket in editor widget
|
||||
proc _searchOpenBracket { widget o_bracket c_bracket start_pos end_pos } {
|
||||
set o_count 0
|
||||
set c_count 1
|
||||
set found 0
|
||||
set pattern "\[\\$o_bracket\\$c_bracket\]"
|
||||
set pos [$widget search -backward -regexp -- $pattern "$start_pos - 1 chars" $end_pos]
|
||||
while { ! [string equal $pos {}] } {
|
||||
set char [$widget get $pos]
|
||||
#tk_messageBox -title $pattern -message "char: $char; $pos; o_count=$o_count; c_count=$c_count"
|
||||
if {[string equal $char $o_bracket]} {incr o_count ; set found 1}
|
||||
if {[string equal $char $c_bracket]} {incr c_count ; set found 1}
|
||||
if {($found == 1) && ($o_count == $c_count) } { return [$widget index "$pos + 1 chars"] }
|
||||
set found 0
|
||||
set start_pos "$pos - 0 chars"
|
||||
set pos [$widget search -backward -regexp -- $pattern $start_pos $end_pos]
|
||||
} ;# while search
|
||||
return -1
|
||||
} ;# proc _searchOpenBracket
|
||||
|
||||
proc GoToLine {} {
|
||||
global nb files font color
|
||||
set node [$nb raise]
|
||||
if {$node == "newproj" || $node == "settings" || $node == "about" || $node == ""} {
|
||||
return
|
||||
}
|
||||
set file $files($node)
|
||||
set w $nb.f$node.goto
|
||||
set text "$nb.f$node.f.text"
|
||||
# destroy the find window if it already exists
|
||||
if {[winfo exists $w]} {
|
||||
destroy $w
|
||||
}
|
||||
# create the new "goto" window
|
||||
toplevel $w
|
||||
wm title $w [::msgcat::mc "Goto line"]
|
||||
wm resizable $w 0 0
|
||||
wm transient $w $nb.f$node
|
||||
|
||||
label $w.text -text [::msgcat::mc "Line number"] -font $font(normal) -background $color(bg)
|
||||
entry $w.entGoTo -width 6 -validate key -validatecommand "ValidNumber %W %P"
|
||||
pack $w.text $w.entGoTo -side left -anchor nw -padx 2 -pady 2
|
||||
set line [$w.entGoTo get]
|
||||
bind $w.entGoTo <Return> "+GoToLineNumber $text $nb.f$node"
|
||||
|
||||
bind $w.entGoTo <Escape> "destroy $w"
|
||||
focus -force $w.entGoTo
|
||||
}
|
||||
## Check input number ##
|
||||
proc ValidNumber {w value} {
|
||||
if [string is integer $value] {
|
||||
return 1
|
||||
} else {
|
||||
bell
|
||||
return 0
|
||||
}
|
||||
}
|
||||
## GOTO LINE ##
|
||||
proc GoToLineNumber {text w} {
|
||||
global status
|
||||
set lineNumber [$w.goto.entGoTo get]
|
||||
destroy $w.goto
|
||||
catch {
|
||||
$text mark set insert $lineNumber.0
|
||||
$text see insert
|
||||
}
|
||||
$status(pos) configure -text [$text index insert];# cursor position
|
||||
}
|
||||
|
||||
## SEARCH DIALOG FORM ##
|
||||
set findHistory ""
|
||||
set findString ""
|
||||
set replaceString ""
|
||||
proc Find {} {
|
||||
global nb files font findHistory findString color
|
||||
|
||||
set node [$nb raise]
|
||||
if {$node == "newproj" || $node == "settings" || $node == "about" || $node == ""} {
|
||||
return
|
||||
}
|
||||
set file $files($node)
|
||||
set w $nb.f$node.find
|
||||
set text "$nb.f$node.f.text"
|
||||
set findString ""
|
||||
# destroy the find window if it already exists
|
||||
if {[winfo exists $w]} {
|
||||
destroy $w
|
||||
}
|
||||
|
||||
toplevel $w
|
||||
wm title $w [::msgcat::mc "Find"]
|
||||
wm resizable $w 0 0
|
||||
wm transient $w $nb.f$node
|
||||
frame $w.frmCombo -borderwidth 1 -background $color(bg)
|
||||
frame $w.frmBtn -borderwidth 1 -background $color(bg)
|
||||
pack $w.frmCombo $w.frmBtn -side top -fill x
|
||||
|
||||
# set combo [entry $w.frmCombo.entFind]
|
||||
set combo [ComboBox $w.frmCombo.txtLocale\
|
||||
-textvariable findString -background $color(bg)\
|
||||
-selectbackground "#55c4d1" -selectborderwidth 0\
|
||||
-values $findHistory]
|
||||
|
||||
pack $combo -fill x -padx 2 -pady 2
|
||||
|
||||
button $w.frmBtn.btnFind -text "[::msgcat::mc "Find"] - F3"\
|
||||
-font $font(normal) -width 12 -relief groove -background $color(bg)\
|
||||
-command "FindCommand $text $w"
|
||||
button $w.frmBtn.btnCancel -text "[::msgcat::mc "Close"] - Esc"\
|
||||
-relief groove -width 12 -font $font(normal) -background $color(bg)\
|
||||
-command "destroy $w"
|
||||
pack $w.frmBtn.btnFind $w.frmBtn.btnCancel -fill x -padx 2 -pady 2 -side left
|
||||
|
||||
bind $w <Return> "FindCommand $text $w"
|
||||
bind $w <F3> "FindCommand $text $w"
|
||||
bind $w <Escape> "destroy $w"
|
||||
focus -force $combo
|
||||
|
||||
# set findIndex [lsearch -exact $findHistory "$findString"]
|
||||
$combo setvalue @0
|
||||
}
|
||||
|
||||
proc FindCommand {text w} {
|
||||
global findString findHistory
|
||||
# set findString [$entry get]
|
||||
destroy $w
|
||||
# if null string? do nothing
|
||||
if {$findString == ""} {
|
||||
return
|
||||
}
|
||||
# search "again" (starting from current position)
|
||||
FindNext $text 0
|
||||
}
|
||||
|
||||
proc FindNext {text {incr 1}} {
|
||||
global findString findHistory
|
||||
set t $text
|
||||
# append find string into find history list #
|
||||
if {[lsearch -exact $findHistory $findString] == -1} {
|
||||
set findHistory [linsert $findHistory 0 $findString]
|
||||
}
|
||||
|
||||
set pos [$t index insert]
|
||||
set line [lindex [split $pos "."] 0]
|
||||
set x [lindex [split $pos "."] 1]
|
||||
incr x $incr
|
||||
|
||||
set pos [$t search -nocase $findString $line.$x end]
|
||||
|
||||
# if found then move the insert cursor to that position, otherwise beep
|
||||
if {$pos != ""} {
|
||||
$t mark set insert $pos
|
||||
$t see $pos
|
||||
|
||||
# highlight the found word
|
||||
set line [lindex [split $pos "."] 0]
|
||||
set x [lindex [split $pos "."] 1]
|
||||
set x [expr {$x + [string length $findString]}]
|
||||
$t tag remove sel 1.0 end
|
||||
$t tag add sel $pos $line.$x
|
||||
focus -force $t
|
||||
return 1
|
||||
} else {
|
||||
bell
|
||||
return 0
|
||||
}
|
||||
catch [$status(pos) configure -text [%W index insert]] ;# cursor position
|
||||
|
||||
}
|
||||
## FIND FUNCTION PROCEDURE ##
|
||||
proc FindProc {text findString node} {
|
||||
global nb status
|
||||
|
||||
set pos "0.0"
|
||||
$text see $pos
|
||||
set line [lindex [split $pos "."] 0]
|
||||
set x [lindex [split $pos "."] 1]
|
||||
|
||||
set pos [$text search -nocase $findString $line.$x end]
|
||||
$text mark set insert $pos
|
||||
$text see $pos
|
||||
|
||||
# highlight the found word
|
||||
set line [lindex [split $pos "."] 0]
|
||||
set x [lindex [split $pos "."] 1]
|
||||
set x [expr {$x + [string length $findString]}]
|
||||
$text tag remove sel 1.0 end
|
||||
$text tag add sel $pos $line.$x
|
||||
focus -force $text
|
||||
catch [$status(pos) configure -text [$text index insert]] ;# cursor position
|
||||
return 1
|
||||
}
|
||||
|
||||
#3 REPLACE DIALOG FORM ##
|
||||
proc ReplaceDialog {} {
|
||||
global nb font files findString replaceString text color
|
||||
set node [$nb raise]
|
||||
if {$node == "newproj" || $node == "settings" || $node == "about" || $node == ""} {
|
||||
return
|
||||
}
|
||||
#set file $files($node)
|
||||
set w .replace
|
||||
set text "$nb.f$node.f.text"
|
||||
# set findString ""
|
||||
# destroy the find window if it already exists
|
||||
if {[winfo exists $w]} {
|
||||
destroy $w
|
||||
}
|
||||
|
||||
# create the new "find" window
|
||||
toplevel $w
|
||||
wm transient $w $nb.f$node
|
||||
wm title $w [::msgcat::mc "Replace"]
|
||||
wm resizable $w 0 0
|
||||
|
||||
set f1 [frame $w.frmFind -background $color(bg)]
|
||||
set f2 [frame $w.frmReplace -background $color(bg)]
|
||||
set f3 [frame $w.frmBtn -borderwidth 1 -background $color(bg)]
|
||||
pack $f1 $f2 $f3 -side top -fill x -expand true
|
||||
|
||||
label $f1.lblFind -text [::msgcat::mc "Find"] -font $font(normal) -width 15 -anchor w -background $color(bg)
|
||||
entry $f1.entFind -width 30
|
||||
pack $f1.lblFind $f1.entFind -side left -padx 2 -pady 2
|
||||
pack $f1.entFind -side left -fill x -expand true -padx 2 -pady 2
|
||||
|
||||
label $f2.lblReplace -text [::msgcat::mc "Replace with"] -font $font(normal) -width 15 -anchor w -background $color(bg)
|
||||
entry $f2.entReplace -width 30
|
||||
pack $f2.lblReplace $f2.entReplace -side left -padx 2 -pady 2
|
||||
pack $f2.entReplace -side left -fill x -expand true -padx 2 -pady 2
|
||||
|
||||
button $f3.btnFind -text "[::msgcat::mc "Find"] - Enter" -width 12 -pady 0 -font $font(normal) -relief groove -background $color(bg)\
|
||||
-command "ReplaceCommand $text $w $f1.entFind $f2.entReplace find"
|
||||
button $f3.btnReplace -text "[::msgcat::mc "Replace"] - F4" -width 12 -pady 0\
|
||||
-font $font(normal) -relief groove -background $color(bg)\
|
||||
-command {
|
||||
ReplaceCommand $text $w .replace.frmFind.entFind .replace.frmReplace.entReplace replace
|
||||
focus -force .replace
|
||||
}
|
||||
button $f3.btnReplaceAll -text [::msgcat::mc "Replace all"] -width 12 -pady 0\
|
||||
-font $font(normal) -relief groove -background $color(bg)\
|
||||
-command "ReplaceCommand $text $w $f1.entFind $f2.entReplace replace_all"
|
||||
button $f3.btnCancel -text "[::msgcat::mc "Cancel"] - Esc" -command "destroy $w"\
|
||||
-width 12 -pady 0 -font $font(normal) -relief groove -background $color(bg)
|
||||
pack $f3.btnFind $f3.btnReplace $f3.btnReplaceAll $f3.btnCancel\
|
||||
-side left -padx 2 -pady 2 -fill x
|
||||
|
||||
bind $w <Return> "ReplaceCommand $text $w $f1.entFind $f2.entReplace find"
|
||||
bind $w <F4> "ReplaceCommand $text $w $f1.entFind $f2.entReplace replace"
|
||||
bind $w <Escape> "destroy $w"
|
||||
focus -force $f1.entFind
|
||||
|
||||
if {$findString != ""} {
|
||||
$f1.entFind insert end $findString
|
||||
}
|
||||
if {$replaceString != ""} {
|
||||
$f2.entReplace insert end $replaceString
|
||||
}
|
||||
}
|
||||
## REPLACE COMMAND ##
|
||||
proc ReplaceCommand {text w entFind entReplace command} {
|
||||
global nb font files findString replaceString
|
||||
set node [$nb raise]
|
||||
|
||||
set findString [$entFind get]
|
||||
set replaceString [$entReplace get]
|
||||
|
||||
switch -- $command {
|
||||
"find" {
|
||||
FindNext $text 1
|
||||
focus -force .replace
|
||||
}
|
||||
"replace" {
|
||||
if {[Replace $text 0]} {
|
||||
FindNext $text 1
|
||||
if {[lindex $files($node) 1] == 0} {
|
||||
set files($node) [list [lindex $files($node) 0] 1 [lindex $files($node) 2]]
|
||||
}
|
||||
focus -force .replace
|
||||
}
|
||||
}
|
||||
"replace_all" {
|
||||
set stringsReplace 0
|
||||
if {[Replace $text 0]} {
|
||||
if {[lindex $files($node) 1] == 0} {
|
||||
set files($node) [list [lindex $files($node) 0] 1 [lindex $files($node) 2]]
|
||||
}
|
||||
incr stringsReplace
|
||||
while {[Replace $text 1]} {
|
||||
incr stringsReplace
|
||||
}
|
||||
}
|
||||
tk_messageBox -icon info -title [::msgcat::mc "Replace"]\
|
||||
-parent $text -message\
|
||||
"[::msgcat::mc "Was replacement"] $stringsReplace."
|
||||
destroy $w
|
||||
}
|
||||
}
|
||||
}
|
||||
## REPLACE ONE WORD PROCEDURE ##
|
||||
proc Replace {text incr} {
|
||||
global nb font files findString replaceString
|
||||
|
||||
if {[FindNext $text $incr]} {
|
||||
set selected [$text tag ranges sel]
|
||||
set start [lindex $selected 0]
|
||||
set end [lindex $selected 1]
|
||||
$text delete $start $end
|
||||
$text insert [$text index insert] $replaceString
|
||||
return 1
|
||||
} else {
|
||||
return 0
|
||||
}
|
||||
# focus -force .replace
|
||||
}
|
||||
|
||||
## OVERWRITE SYMBOL PROCEDURE ##
|
||||
proc OverWrite {} {
|
||||
global replace fontNormal status
|
||||
if {$replace == 1} {
|
||||
set replace 0
|
||||
$status(ovwrt) configure -text [::msgcat::mc "Insert"] -foreground black
|
||||
} else {
|
||||
set replace 1
|
||||
$status(ovwrt) configure -text [::msgcat::mc "Overwrite"] -foreground red
|
||||
}
|
||||
}
|
||||
|
||||
proc ReplaceChar {text} {
|
||||
global replace
|
||||
set pos [$text index insert]
|
||||
set posY [lindex [split $pos "."] 0]
|
||||
set posX [lindex [split $pos "."] 1]
|
||||
if {$replace == 1} {
|
||||
$text delete $posY.$posX $posY.[expr $posX + 1]
|
||||
}
|
||||
}
|
||||
|
||||
## GET KEYS CODE ##
|
||||
proc Key {key} {
|
||||
#puts $key ;#debug
|
||||
if {$key >= 10 && $key <= 22} {return "true"}
|
||||
if {$key >= 24 && $key <= 36} {return "true"}
|
||||
if {$key >= 38 && $key <= 50} {return "true"}
|
||||
if {$key >= 51 && $key <= 61 && $key != 58} {return "true"}
|
||||
if {$key >= 79 && $key <= 91} {return "true"}
|
||||
if {$key == 63 || $key == 107 || $key == 108 || $key == 112} {return "true"}
|
||||
if {$key == 98 || $key == 100 || $key == 102 || $key == 104} {return "false"}
|
||||
}
|
||||
|
||||
## SPLIT EDITOR WINDOW PROCEDURE ##
|
||||
set split 0
|
||||
proc SplitWindow {} {
|
||||
global color font editor nb activeFile split
|
||||
|
||||
if [info exists activeFile] {
|
||||
set w $nb.f$activeFile
|
||||
} else {
|
||||
return
|
||||
}
|
||||
if {$split == 0} {
|
||||
frame $w.f1 -borderwidth 2 -relief ridge
|
||||
pack $w.f1 -side top -fill both -expand true
|
||||
#supertext::text
|
||||
supertext::text $w.f1.text -yscrollcommand "$w.f1.yscroll set" \
|
||||
-relief sunken -wrap $editor(wrap) -highlightthickness 0 -font $font(editNormal)\
|
||||
-background $color(editBg) -foreground $color(editFg)\
|
||||
-selectborderwidth 0 -selectbackground $color(selectbg) -width 10
|
||||
scrollbar $w.f1.yscroll -relief sunken -borderwidth {1} -width {10} -takefocus 0 \
|
||||
-command "$w.f1.text yview"
|
||||
pack $w.f1.text -side left -fill both -expand true
|
||||
pack $w.f1.yscroll -side left -fill y
|
||||
##############################################
|
||||
pane::create $w.f $w.f1 -orient horizontal -percent 0.5
|
||||
set split 1
|
||||
} elseif {$split == 1} {
|
||||
destroy $w.f1
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
238
lib/modules/encode.tcl
Executable file
238
lib/modules/encode.tcl
Executable file
@@ -0,0 +1,238 @@
|
||||
###########################################################
|
||||
# Tcl/Tk project Manager
|
||||
# Distributed under GNU Public License
|
||||
# Author: Sergey Kalinin banzaj@lrn.ru
|
||||
# Copyright (c) "CONERO lab", 2002, http://conero.lrn.ru
|
||||
###########################################################
|
||||
|
||||
###########################################################
|
||||
# ENCODING files procedure #
|
||||
###########################################################
|
||||
|
||||
proc GetCorrectEncode {latexEncode} {
|
||||
global files dir activeFile files
|
||||
set f [open "[file join $dir(work) encode.lst]" r]
|
||||
set encodeList [encoding names]
|
||||
while {[gets $f line]} {
|
||||
if {[string index [string trim $line] 0] == "#"} {
|
||||
continue
|
||||
}
|
||||
scan $line "%s%s" texEnc tclEnc
|
||||
#puts "$texEnc $tclEnc"
|
||||
|
||||
if {$texEnc == $latexEncode} {
|
||||
close $f
|
||||
return $tclEnc
|
||||
} else {
|
||||
set ind [lsearch -exact $encodeList $latexEncode]
|
||||
#puts $latexEncode
|
||||
if {$ind == -1} {
|
||||
set answer [tk_messageBox\
|
||||
-message "[lindex $files($activeFile) 0] [::msgcat::mc "Don't find any system encoding for"] $latexEncode \
|
||||
[::msgcat::mc "You must write correctly encode name in"] [file join $dir(work) encode.lst] [::msgcat::mc "file"]"\
|
||||
-type ok -icon warning\
|
||||
-title [::msgcat::mc "Warning"]]
|
||||
case $answer {
|
||||
ok {return}
|
||||
}
|
||||
close $f
|
||||
return $latexEncode
|
||||
} else {
|
||||
close $f
|
||||
return $latexEncode
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
proc EncodeDialog {type} {
|
||||
global color files activeFile
|
||||
set w .encode
|
||||
# destroy the find window if it already exists
|
||||
if {[winfo exists .encode]} {
|
||||
destroy .encode
|
||||
}
|
||||
|
||||
toplevel .encode
|
||||
wm title .encode [::msgcat::mc "Encoding"]
|
||||
wm resizable .encode 0 0
|
||||
wm transient .encode .
|
||||
|
||||
frame .encode.encodings -width 10
|
||||
eval {
|
||||
listbox .encode.encodings.list -height 10 -width 20 -selectbackground $color(selectbg)\
|
||||
-selectborderwidth 0 -yscrollcommand {.encode.encodings.yscroll set}
|
||||
}
|
||||
eval {scrollbar .encode.encodings.yscroll -orient vertical -command {.encode.encodings.list yview}}
|
||||
pack .encode.encodings.list -side left -expand true -fill y
|
||||
pack .encode.encodings.yscroll -side left -expand false -fill y
|
||||
pack .encode.encodings -side top -expand true -fill both
|
||||
|
||||
canvas .encode.line -border 0 -height 1 -background black -width 10
|
||||
pack .encode.line -side top -expand true -fill x
|
||||
|
||||
frame .encode.command -width 10
|
||||
if {$type == "file"} {
|
||||
eval {
|
||||
button .encode.command.ok -text [::msgcat::mc "Ok"] -command {
|
||||
SetEncode [.encode.encodings.list get [.encode.encodings.list curselection]]
|
||||
}
|
||||
}
|
||||
} else {
|
||||
eval {
|
||||
button .encode.command.ok -text [::msgcat::mc "Ok"] -command {
|
||||
TextRecode [.encode.encodings.list get [.encode.encodings.list curselection]]
|
||||
}
|
||||
}
|
||||
}
|
||||
eval {button .encode.command.cancel -text [::msgcat::mc "Cancel"] -command {destroy .encode }}
|
||||
grid .encode.command.ok -row 0 -column 0 -sticky e -pady 2 -padx 2
|
||||
grid .encode.command.cancel -row 0 -column 1 -sticky w -pady 2 -padx 2
|
||||
pack .encode.command -side top -expand true -fill x
|
||||
|
||||
bind .encode.encodings.list <Double-1> {eval [.encode.command.ok cget -command]}
|
||||
bind .encode.encodings.list <Return> {eval [.encode.command.ok cget -command]}
|
||||
bind .encode <Escape> {eval [.encode.command.cancel cget -command]}
|
||||
|
||||
set i 0 ; set cur_encoding [encoding system]
|
||||
foreach { name_encodings } [lsort [encoding names] ] {
|
||||
.encode.encodings.list insert end $name_encodings
|
||||
if { $name_encodings == $cur_encoding } { set enc_pos $i }
|
||||
incr i
|
||||
} ;# foreach encoding names
|
||||
|
||||
wm resizable .encode 0 0
|
||||
.encode.encodings.list activate $enc_pos
|
||||
.encode.encodings.list selection set $enc_pos $enc_pos
|
||||
.encode.encodings.list see $enc_pos
|
||||
focus -force .encode.encodings.list
|
||||
}
|
||||
|
||||
|
||||
## Source encode ##
|
||||
proc DocRecode {pipe} {
|
||||
global files tree activeFile
|
||||
set parentNode [$tree parent $activeFile]
|
||||
if [info exists files($parentNode)] {
|
||||
set sourceEnc [lindex $files($parentNode) 2]
|
||||
} else {
|
||||
set sourceEnc [encoding system] ;#[EncodeDialog]
|
||||
}
|
||||
puts $sourceEnc
|
||||
while {[gets $pipe line]>=0} {
|
||||
if [regexp -nocase -all -- {(\\)(usepackage)(\[)(.*?)(\])(\{)inputenc(\})} $line match v1 v2 v3 sourceEnc v5 v6 v7] {
|
||||
if [set ind [string last "," $sourceEnc]] {
|
||||
set sourceEnc [string range $sourceEnc [expr $ind + 1] end]
|
||||
}
|
||||
puts "<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> $sourceEnc"
|
||||
set sourceEnc [GetCorrectEncode $sourceEnc]
|
||||
puts "<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> $sourceEnc"
|
||||
|
||||
}
|
||||
}
|
||||
fconfigure $pipe -encoding binary
|
||||
seek $pipe 0 start
|
||||
return $sourceEnc
|
||||
}
|
||||
|
||||
## CHANGE SOURCE FIELE ENCODING ##
|
||||
proc SetEncode {encode} {
|
||||
global files activeFile status nb
|
||||
destroy .encode
|
||||
set files($activeFile) [list [lindex $files($activeFile) 0] [lindex $files($activeFile) 1] "$encode"]
|
||||
#puts $files($activeFile)
|
||||
$status(encode) configure -text "[lindex $files($activeFile) 2]"
|
||||
}
|
||||
|
||||
## Reencoding text ##
|
||||
proc TextRecode {encode} {
|
||||
global files activeFile status nb
|
||||
destroy .encode
|
||||
set text $nb.f$activeFile.f.text
|
||||
set contents [$text get 0.0 end]
|
||||
#puts "[lindex $files($activeFile) 2] $encode"
|
||||
set contents [encoding convertto [lindex $files($activeFile) 2] $contents]
|
||||
set contents [encoding convertfrom $encode $contents]
|
||||
$text delete 0.0 end
|
||||
$text insert end $contents
|
||||
unset text
|
||||
SetEncode $encode
|
||||
}
|
||||
|
||||
proc CheckEncoding {text} {
|
||||
global files activeFile
|
||||
set sourceEnc "" ;#[EncodeDialog]
|
||||
set line [$text get 0.0 end]
|
||||
if [regexp -nocase -all -- {(\\)(usepackage)(\[)(.*?)(\])(\{)inputenc(\})} $line match v1 v2 v3 sourceEnc v5 v6 v7] {
|
||||
#break
|
||||
if {$sourceEnc != "[lindex $files($activeFile) 2]"} {
|
||||
set answer [tk_messageBox -message "[::msgcat::mc "Don't correctly setting document encoding! Save anyway?"]"\
|
||||
-type yesno -icon warning\
|
||||
-title [::msgcat::mc "Warning"]]
|
||||
case $answer {
|
||||
yes {return 1}
|
||||
no {return 0}
|
||||
}
|
||||
}
|
||||
puts "DocEnc-$sourceEnc ViewEnc-[lindex $files($activeFile) 2]"
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
## clipboard encode ##
|
||||
|
||||
set xselection ""
|
||||
proc EncodeTextSelection {txt offset len} {
|
||||
set ::xselection [eval $txt get [$txt tag ranges sel]]
|
||||
encoding convertto \
|
||||
[crange $::xselection $offset [expr $offset + $len - 1]]
|
||||
}
|
||||
|
||||
proc EncodeEntrySelection {txt offset len} {
|
||||
if [$txt selection present] {
|
||||
set idx1 [$txt index sel.first]
|
||||
set idx2 [$txt index sel.last]
|
||||
set ::xselection [string range [$txt get] $idx1 $idx2]
|
||||
encoding convertto \
|
||||
[crange $::xselection $offset [expr $offset + $len - 1]]
|
||||
} else {
|
||||
set ::xselection ""
|
||||
}
|
||||
}
|
||||
|
||||
if {$tcl_platform(platform) == "win"} {
|
||||
bind Text <Map> { selection handle %W "EncodeTextSelection %W"}
|
||||
bind Entry <Map> { selection handle %W "EncodeEntrySelection %W"}
|
||||
bind Text <Unmap> { selection handle %W {}}
|
||||
bind Entry <Unmap> { selection handle %W {}}
|
||||
|
||||
bind Text <ButtonRelease-2> {
|
||||
if [catch {set sel [selection get]}] continue
|
||||
if {[selection own] == ""} {
|
||||
set sel [encoding convertfrom $sel]
|
||||
} else {
|
||||
set sel $xselection
|
||||
}
|
||||
%W insert current $sel
|
||||
}
|
||||
bind Entry <ButtonRelease-2> {
|
||||
if [catch {set sel [selection get]}] continue
|
||||
if {[selection own] == ""} {
|
||||
set sel [encoding convertfrom $sel]
|
||||
} else {
|
||||
set sel $xselection
|
||||
}
|
||||
%W insert insert $sel
|
||||
}
|
||||
}
|
||||
#set class Text
|
||||
#bind $class <Map> "selection handle %W \"unix::Encode${class}Selection %W\""
|
||||
#bind $class <Unmap> { selection handle %W {}}
|
||||
#proc EncodeTextSelection {txt offset len} {encoding convertto [eval $txt get [$txt tag ranges sel]]}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
402
lib/modules/file.tcl
Executable file
402
lib/modules/file.tcl
Executable file
@@ -0,0 +1,402 @@
|
||||
######################################################
|
||||
# TkTeXeditor
|
||||
# Distributed under GNU Public License
|
||||
# Author: Sergey Kalinin (BanZaj) banzaj@lrn.ru
|
||||
# Copyright (c) "CONERO lrn", 2000, http//conero.lrn.ru
|
||||
######################################################
|
||||
set types {
|
||||
{"TeX files" {.tex}}
|
||||
{"Html files" {.html}}
|
||||
{"Text files" {.txt}}
|
||||
{"All files" *}
|
||||
}
|
||||
set typeImage {
|
||||
{"GIF files" {.gif}}
|
||||
{"PNG files" {.png}}
|
||||
{"JPEG files" {.jpeg}}
|
||||
{"All files" *}
|
||||
}
|
||||
|
||||
proc FileDialog {operation} {
|
||||
global dir font tree nb files treeStruct in lastNode \
|
||||
activeFile color status lblList ver sysenc release types
|
||||
## settings variable for tree section ##
|
||||
set in(c) 0 ;# chapter counter
|
||||
set in(p) 0 ;# part counter
|
||||
set in(s) 0 ;# section counter
|
||||
set in(ss) 0 ;# subsection counter
|
||||
set in(sss) 0 ;# subsubsection counter
|
||||
set in(par) 0 ;# paragraph cponter
|
||||
set in(spar) 0 ;# subparagraph cponter
|
||||
set lastNode "root"
|
||||
|
||||
|
||||
if {$operation == "new"} {
|
||||
NewFileDialog
|
||||
} elseif {$operation == "new_templ"} {
|
||||
TemplateDialog
|
||||
} elseif {$operation == "open"} {
|
||||
set file [tk_getOpenFile -initialdir $dir(current) -filetypes $types -parent .]
|
||||
#puts "$file"
|
||||
if {$file == ""} {return}
|
||||
# call EditFile procedure
|
||||
EditFile $file
|
||||
} elseif {$operation == "save"} {
|
||||
if [info exists activeFile] {
|
||||
set node $activeFile
|
||||
} else {
|
||||
#set node [$nb raise]
|
||||
return
|
||||
}
|
||||
if {$node == "newproj" || $node == "" || $node == "debug"} {
|
||||
return
|
||||
}
|
||||
if {[info exists files($node)] == 0} {
|
||||
return
|
||||
}
|
||||
|
||||
set text "$nb.f$node.f.text"
|
||||
set fullPath [lindex $files($node) 0]
|
||||
set encode [lindex $files($node) 2] ;# document encoding
|
||||
set folder [file dirname $fullPath]
|
||||
set file [file tail $fullPath]
|
||||
#set contents [encoding convertfrom $sysenc [$text get 0.0 end]]
|
||||
#set contents [encoding convertto $encode [$text get 0.0 end]]
|
||||
if {[CheckEncoding $text] == 0} {
|
||||
return
|
||||
}
|
||||
set contents [$text get 0.0 end]
|
||||
set fhandle [open [file join $folder $file] "w"]
|
||||
fconfigure $fhandle -encoding $encode
|
||||
puts $fhandle $contents nonewline
|
||||
close $fhandle
|
||||
|
||||
#UpdateStruct $fullPath
|
||||
if {[lindex $files($node) 1] == 1} {
|
||||
set files($node) [list [lindex $files($node) 0] 0 [lindex $files($node) 2]]
|
||||
$status(active) configure -text [::msgcat::mc "File saved"]
|
||||
$nb itemconfigure $node -foreground $color(editTitleNormal)
|
||||
}
|
||||
UpdateStruct $fullPath $node
|
||||
} elseif {$operation == "save_as"} {
|
||||
if [info exists activeFile] {
|
||||
set node $activeFile
|
||||
#set node [$nb raise]
|
||||
} else {
|
||||
return
|
||||
}
|
||||
if {$node == "newproj" || $node == "settings" || $node == "about" || $node == ""} {
|
||||
return
|
||||
}
|
||||
if {[info exists files($node)] == 0} {
|
||||
return
|
||||
}
|
||||
set fullPath [lindex $files($node) 0]
|
||||
set folder [file dirname $fullPath]
|
||||
set file [file tail $fullPath]
|
||||
set encode [lindex $files($node) 2] ;# document encoding
|
||||
set file [tk_getSaveFile -initialdir $dir(current) -filetypes $types -parent .\
|
||||
-initialfile $file -defaultextension .tex]
|
||||
if {$file == ""} {return}
|
||||
set text "$nb.f$node.f.text"
|
||||
set contents [$text get 0.0 end]
|
||||
set fhandle [open [file join $folder $file] "w"]
|
||||
fconfigure $fhandle -encoding $encode
|
||||
|
||||
puts $fhandle $contents nonewline
|
||||
close $fhandle
|
||||
if {[lindex $files($node) 1] == 1} {
|
||||
set files($node) [list [lindex $files($node) 0] 0 $encode]
|
||||
$status(active) configure -text [::msgcat::mc "File saved"]
|
||||
$nb itemconfigure $node -foreground $color(editTitleNormal)
|
||||
}
|
||||
UpdateStruct $fullPath $node
|
||||
} elseif {$operation == "save_all"} {
|
||||
# SAVE ALL PROCEDURE
|
||||
set i 0
|
||||
set nodeList [$nb pages 0 end]
|
||||
set length [llength $nodeList]
|
||||
while {$i < $length} {
|
||||
set nbNode [lindex $nodeList $i]
|
||||
if {$nbNode != "debug"} {
|
||||
set text "$nb.f$nbNode.f.text"
|
||||
set savedFile [lindex $files($nbNode) 0]
|
||||
set encode [lindex $files($nbNode) 2] ;# document encoding
|
||||
set contents [$text get 0.0 end]
|
||||
set fhandle [open $savedFile "w"]
|
||||
fconfigure $fhandle -encoding $encode
|
||||
puts $fhandle $contents nonewline
|
||||
close $fhandle
|
||||
if {[lindex $files($nbNode) 1] == 1} {
|
||||
set files($nbNode) [list [lindex $files($nbNode) 0] 0 $encode]
|
||||
$status(active) configure -text [::msgcat::mc "File saved"]
|
||||
$nb itemconfigure $nbNode -foreground $color(editTitleNormal)
|
||||
}
|
||||
}
|
||||
incr i
|
||||
}
|
||||
Timer "empty" "autosave"
|
||||
} elseif {$operation == "close"} {
|
||||
set node [$nb raise]
|
||||
if {$node == ""} {return}
|
||||
if {$node == "debug"} {
|
||||
$nb delete $node
|
||||
$nb raise [$nb page 0]
|
||||
return
|
||||
}
|
||||
set childrenNode [$tree nodes $node]
|
||||
# <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD> <20><> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD> <20> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD> <20><><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD>
|
||||
if {$childrenNode != ""} {
|
||||
for {set i 0} {$i <= [llength $childrenNode]} {incr i} {
|
||||
if {[info exists files([lindex $childrenNode $i])] == 1} {
|
||||
CloseNode [lindex $childrenNode $i]
|
||||
}
|
||||
}
|
||||
}
|
||||
CloseNode $node
|
||||
} elseif {$operation == "close_all"} {
|
||||
set nodeList [$nb pages 0 end]
|
||||
$nb raise [$nb page 0]
|
||||
set nbNode [$nb raise]
|
||||
while {$nbNode != ""} {
|
||||
if {[info exists files($nbNode)] == 1} {
|
||||
if {[lindex $files($nbNode) 1] == 1} {
|
||||
set f [lindex $files($nbNode) 0]
|
||||
set f [file tail $f]
|
||||
set answer [tk_messageBox\
|
||||
-message "$f [::msgcat::mc "File was modifyed. Save?"]"\
|
||||
-type yesnocancel -icon warning\
|
||||
-title [::msgcat::mc "Warning"]]
|
||||
case $answer {
|
||||
yes {FileDialog save}
|
||||
no {}
|
||||
cancel {return}
|
||||
}
|
||||
}
|
||||
}
|
||||
$tree delete $nbNode
|
||||
$nb delete $nbNode
|
||||
$nb raise [$nb page 0]
|
||||
set nbNode [$nb raise]
|
||||
}
|
||||
} elseif {$operation == "quit_close_all"} {
|
||||
set nodeList [$nb pages 0 end]
|
||||
$nb raise [$nb page 0]
|
||||
set nbNode [$nb raise]
|
||||
set fhandle [open [file join $dir(work) bookmarks] "w"]
|
||||
while {$nbNode != ""} {
|
||||
if {[info exists files($nbNode)] == 1} {
|
||||
set f [lindex $files($nbNode) 0]
|
||||
puts $f
|
||||
# <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
||||
set text "$nb.f$nbNode.f.text"
|
||||
puts $fhandle "$f [$text index insert]"
|
||||
puts "$f [$text index insert]"
|
||||
if {[lindex $files($nbNode) 1] == 1} {
|
||||
set f [file tail $f]
|
||||
set answer [tk_messageBox\
|
||||
-message "$f [::msgcat::mc "File was modifyed. Save?"]"\
|
||||
-type yesnocancel -icon warning\
|
||||
-title [::msgcat::mc "Warning"]]
|
||||
case $answer {
|
||||
yes {FileDialog save}
|
||||
no {}
|
||||
cancel {return 0}
|
||||
}
|
||||
}
|
||||
}
|
||||
$tree delete $nbNode
|
||||
$nb delete $nbNode
|
||||
$nb raise [$nb page 0]
|
||||
set nbNode [$nb raise]
|
||||
}
|
||||
close $fhandle
|
||||
}
|
||||
}
|
||||
proc NewFile {fileName} {
|
||||
global dir workDir tree nb font
|
||||
destroy .addtoproj
|
||||
|
||||
set type [string trim [file extension $fileName] {.}]
|
||||
if {$type == "tcl"} {
|
||||
set img "tcl"
|
||||
} elseif {$type == "tk"} {
|
||||
set img "tk"
|
||||
} elseif {$type == "txt"} {
|
||||
set img "file"
|
||||
} elseif {$type == "html"} {
|
||||
set img "html"
|
||||
} else {
|
||||
set img "file"
|
||||
}
|
||||
#set subNode [InsertTreeNode $fileName $dir(doc)]
|
||||
if [info exists dir(current)] {
|
||||
set file [file join $dir(current) $fileName]
|
||||
} else {
|
||||
set file [file join $dir(doc) $fileName]
|
||||
}
|
||||
|
||||
#puts $file
|
||||
#InsertTitle $file $type
|
||||
if {[file exists $file] == 0} {
|
||||
set fHandle [open "$file" a+]
|
||||
close $fHandle
|
||||
}
|
||||
EditFile $file
|
||||
}
|
||||
## ADD FILE INTO PROJECT DIALOG##
|
||||
proc NewFileDialog {} {
|
||||
global dir
|
||||
set w .addtoproj
|
||||
if {[winfo exists $w]} {
|
||||
destroy $w
|
||||
}
|
||||
# create the new "goto" window
|
||||
toplevel $w
|
||||
wm title $w [::msgcat::mc "Create new file"]
|
||||
wm resizable $w 0 0
|
||||
wm transient $w .
|
||||
|
||||
frame $w.frmCanv -border 1 -relief sunken
|
||||
frame $w.frmBtn -border 1 -relief sunken
|
||||
pack $w.frmCanv -side top -fill both -padx 1 -pady 1
|
||||
pack $w.frmBtn -side top -fill x
|
||||
|
||||
label $w.frmCanv.lblImgTcl -text [::msgcat::mc "Input file name"]
|
||||
entry $w.frmCanv.entImgTcl
|
||||
pack $w.frmCanv.lblImgTcl $w.frmCanv.entImgTcl -expand true -padx 5 -pady 5 -side top
|
||||
|
||||
button $w.frmBtn.btnOk -text [::msgcat::mc "Create"] -relief groove -command {
|
||||
NewFile [.addtoproj.frmCanv.entImgTcl get]
|
||||
}
|
||||
button $w.frmBtn.btnCancel -text [::msgcat::mc "Close"] -command "destroy $w" -relief groove
|
||||
pack $w.frmBtn.btnOk $w.frmBtn.btnCancel -padx 2 -pady 2 -fill x -side left
|
||||
|
||||
bind $w <Escape> "destroy .addtoproj"
|
||||
bind $w.frmCanv.entImgTcl <Return> {
|
||||
NewFile [.addtoproj.frmCanv.entImgTcl get]
|
||||
}
|
||||
focus -force $w.frmCanv.entImgTcl
|
||||
$w.frmCanv.entImgTcl insert 0 "name.tex"
|
||||
}
|
||||
|
||||
proc FileAttr {file} {
|
||||
global tcl_platform
|
||||
set fileAttribute ""
|
||||
# get file modify time
|
||||
if {$tcl_platform(platform) == "windows"} {
|
||||
|
||||
} elseif {$tcl_platform(platform) == "mac"} {
|
||||
|
||||
} elseif {$tcl_platform(platform) == "unix"} {
|
||||
set unixTime [file mtime $file]
|
||||
set modifyTime [clock format $unixTime -format "%d/%m/%Y, %H:%M"]
|
||||
append fileAttribute $modifyTime
|
||||
}
|
||||
# get file size
|
||||
set size [file size $file]
|
||||
if {$size < 1024} {
|
||||
set fileSize "$size b"
|
||||
}
|
||||
if {$size >= 1024} {
|
||||
set s [expr ($size.0) / 1024]
|
||||
set dot [string first "\." $s]
|
||||
set int [string range $s 0 [expr $dot - 1]]
|
||||
set dec [string range $s [expr $dot + 1] [expr $dot + 2]]
|
||||
set fileSize "$int.$dec Kb"
|
||||
}
|
||||
if {$size >= 1048576} {
|
||||
set s [expr ($size.0) / 1048576]
|
||||
set dot [string first "\." $s]
|
||||
set int [string range $s 0 [expr $dot - 1]]
|
||||
set dec [string range $s [expr $dot + 1] [expr $dot + 2]]
|
||||
set fileSize "$int.$dec Mb"
|
||||
}
|
||||
append fileAttribute ", $fileSize"
|
||||
}
|
||||
|
||||
## REMOVED SELECTED TEXT INTO FILE AND INCLUDE THEM ##
|
||||
proc SaveToFile {action} {
|
||||
global nb activeFile files dir types typeImage
|
||||
set text $nb.f$activeFile.f.text
|
||||
set selIndex [$text tag ranges sel]
|
||||
if {$selIndex != ""} {
|
||||
set posBegin [lindex $selIndex 0]
|
||||
set posEnd [lindex $selIndex 1]
|
||||
set contents [$text get $posBegin $posEnd]
|
||||
} else {
|
||||
return
|
||||
}
|
||||
|
||||
set enc "[lindex $files($activeFile) 2]"
|
||||
set contents [encoding convertto $enc $contents]
|
||||
set contents [encoding convertfrom $enc $contents]
|
||||
|
||||
if {$action == "image"} {
|
||||
set file [tk_getSaveFile -initialdir $dir(current) -filetypes $typeImage -parent .\
|
||||
-title [::msgcat::mc "Save as"] -initialfile new_name.gif -defaultextension .gif]
|
||||
if {$file == ""} {return}
|
||||
Render $contents text $file
|
||||
} else {
|
||||
set file [tk_getSaveFile -initialdir $dir(current) -filetypes $types -parent .\
|
||||
-title [::msgcat::mc "Save as"] -initialfile new_name.tex -defaultextension .tex]
|
||||
if {$file == ""} {return}
|
||||
set fHandle [open $file w]
|
||||
puts $fHandle $contents
|
||||
close $fHandle
|
||||
}
|
||||
if {$action == "remove"} {
|
||||
$text delete $posBegin $posEnd
|
||||
$text insert $posBegin "\n\\input\{[file rootname $file]\}\n"
|
||||
}
|
||||
PageRaise $activeFile
|
||||
}
|
||||
|
||||
proc CloseNode {node} {
|
||||
global dir font tree nb files treeStruct in lastNode activeFile color status lblList ver sysenc release types
|
||||
if {$node == "debug"} {$nb delete $node; $nb raise [$nb page 0]; set node [$nb raise]; return}
|
||||
|
||||
if {[info exists files($node)] == 1} {
|
||||
if {[lindex $files($node) 1] == 1} {
|
||||
set f [lindex $files($node) 0]
|
||||
set f [file tail $f]
|
||||
set answer [tk_messageBox\
|
||||
-message "$f [::msgcat::mc "File was modifyed. Save?"]"\
|
||||
-type yesnocancel -icon warning\
|
||||
-title [::msgcat::mc "Warning"]]
|
||||
case $answer {
|
||||
yes {FileDialog save}
|
||||
no {}
|
||||
cancel {return}
|
||||
}
|
||||
}
|
||||
}
|
||||
PageTab -1
|
||||
$nb delete $node
|
||||
unset files($node)
|
||||
set parentNode [$tree parent $node]
|
||||
set curNode [$tree selection get]
|
||||
if {[$tree parent $node] == "root"} {
|
||||
if {[$tree exists $node] == 1} {
|
||||
$tree delete $node
|
||||
}
|
||||
}
|
||||
#$nb raise [$nb page 0]
|
||||
#set node [$nb raise]
|
||||
ClickTab $node
|
||||
$treeStruct delete [$treeStruct nodes root]
|
||||
$lblList delete [$lblList item 0 end]
|
||||
wm title . "TkLaTeXEditor $ver\($release\)"
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
575
lib/modules/gui.tcl
Executable file
575
lib/modules/gui.tcl
Executable file
@@ -0,0 +1,575 @@
|
||||
######################################################
|
||||
# TkTeXeditor
|
||||
# Distributed under GNU Public License
|
||||
# Author: Sergey Kalinin (BanZaj) banzaj@lrn.ru
|
||||
# Copyright (c) "CONERO lrn", 2000, http//conero.lrn.ru
|
||||
######################################################
|
||||
|
||||
######################################################
|
||||
# #
|
||||
# Programms main interface window #
|
||||
# #
|
||||
######################################################
|
||||
|
||||
|
||||
## MAIN INTERFACE WINDOW ##
|
||||
wm geometry . $gui(geometry)
|
||||
set activeFile ""
|
||||
wm title . "TkLaTeXEditor $ver$release"
|
||||
wm iconname . "TkTeXEditor $ver$release"
|
||||
wm protocol . WM_DELETE_WINDOW Quit
|
||||
wm overrideredirect . 0
|
||||
wm positionfrom . user
|
||||
#wm resizable . 0 0
|
||||
|
||||
## main frames
|
||||
frame .frmMenu -border 1 -relief raised -background $color(bg)
|
||||
frame .frmTool -border 1 -relief raised -background $color(bg)
|
||||
frame .frmToolEdit -border 1 -relief raised -background $color(bg)
|
||||
frame .frmBody -border 1 -relief raised -background $color(bg)
|
||||
frame .frmStatus -border 1 -relief sunken -background $color(bg)
|
||||
pack .frmMenu -side top -padx 1 -fill x
|
||||
pack .frmTool -side top -padx 1 -fill x
|
||||
pack .frmToolEdit -side top -padx 1 -fill x
|
||||
pack .frmBody -side top -padx 1 -fill both -expand true
|
||||
pack .frmStatus -side top -padx 1 -fill x
|
||||
|
||||
## MENU ##
|
||||
menubutton .frmMenu.mnuFile -text [::msgcat::mc "File"] -menu .frmMenu.mnuFile.m -font $font(normal) -background $color(bg)
|
||||
set m [menu .frmMenu.mnuFile.m -background $color(bg)]
|
||||
$m add cascade -label [::msgcat::mc "New"] -menu $m.new -font $font(normal)
|
||||
set mn [menu $m.new -background $color(bg)]
|
||||
$mn add command -label [::msgcat::mc "New file"] -command {FileDialog new}\
|
||||
-font $font(normal) -accelerator "Ctrl+N"
|
||||
$mn add command -label [::msgcat::mc "Create from template"] -command {FileDialog new_templ}\
|
||||
-font $font(normal)
|
||||
$mn add command -label [::msgcat::mc "New project"] -command {NewProj add ""}\
|
||||
-font $font(normal) -state disable
|
||||
$m add command -label [::msgcat::mc "Open"] -command {FileDialog open}\
|
||||
-font $font(normal) -accelerator "Ctrl+O"
|
||||
$m add command -label [::msgcat::mc "Save"] -command {FileDialog save}\
|
||||
-font $font(normal) -accelerator "Ctrl+S"
|
||||
$m add command -label [::msgcat::mc "Save as"] -command {FileDialog save_as}\
|
||||
-font $font(normal) -accelerator "Ctrl+A"
|
||||
$m add command -label [::msgcat::mc "Save all"] -command {FileDialog save_all}\
|
||||
-font $font(normal)
|
||||
$m add command -label [::msgcat::mc "Close"] -command {FileDialog close}\
|
||||
-font $font(normal) -accelerator "Ctrl+W"
|
||||
$m add command -label [::msgcat::mc "Close all"] -command {FileDialog close_all}\
|
||||
-font $font(normal)
|
||||
$m add command -label [::msgcat::mc "Delete"] -command {FileDialog delete}\
|
||||
-font $font(normal) -accelerator "Ctrl+D"
|
||||
$m add separator
|
||||
$m add command -label [::msgcat::mc "Print"] -command {PrintDialog print}\
|
||||
-font $font(normal) -accelerator "Ctrl+P" -state normal
|
||||
#$m add separator
|
||||
#$m add command -label [::msgcat::mc "Settings"] -command Settings -font $font(normal)
|
||||
$m add separator
|
||||
$m add command -label [::msgcat::mc "Exit"] -command Quit -font $font(normal) -accelerator "Ctrl+Q"
|
||||
|
||||
### DOCUMENT MENU ####
|
||||
menubutton .frmMenu.mnuDoc -text [::msgcat::mc "Document"] -menu .frmMenu.mnuDoc.m -font $font(normal) -background $color(bg)
|
||||
|
||||
set m [menu .frmMenu.mnuDoc.m -background $color(bg)]
|
||||
#$m add command -label [::msgcat::mc "Included packages"] -command {PackageDialog}\
|
||||
#-font $font(normal) -state disable
|
||||
# "convert to" submenu ##
|
||||
$m add cascade -label "[::msgcat::mc "Convert to"] ..." -menu $m.convert -font $font(normal) -state normal
|
||||
set mn [menu $m.convert -background $color(bg)]
|
||||
$mn add command -label [::msgcat::mc "DVI"] -font $font(normal) -accelerator "F5" -state normal\
|
||||
-command {ConvertDialog dvi}
|
||||
$mn add command -label [::msgcat::mc "PS"] -font $font(normal) -accelerator "F6" -state normal\
|
||||
-command {ConvertDialog ps}
|
||||
$mn add command -label [::msgcat::mc "PDF"] -font $font(normal) -accelerator "F7" -state normal\
|
||||
-command {ConvertDialog pdf}
|
||||
$mn add command -label "HTML" -font $font(normal) -command {ConvertDialog html}\
|
||||
|
||||
$mn add separator
|
||||
## "preview" submenu ##
|
||||
$m add cascade -label [::msgcat::mc "Preview"] -menu $m.preview -font $font(normal) -state normal
|
||||
set mn [menu $m.preview -background $color(bg)]
|
||||
$mn add command -label "DVI" -command {Preview dvi} -font $font(normal)
|
||||
$mn add command -label "PS" -command {Preview ps} -font $font(normal)
|
||||
$mn add command -label "PDF" -command {Preview pdf} -font $font(normal)
|
||||
$mn add command -label "HTML" -command {Preview html} -font $font(normal)
|
||||
|
||||
$m add separator
|
||||
$m add command -label [::msgcat::mc "Spell check"] -font $font(normal) -state normal\
|
||||
-command {
|
||||
SpellCheck $nb.f[$nb raise].f.text
|
||||
}
|
||||
$m add command -label [::msgcat::mc "Encoding"] -font $font(normal) -state normal\
|
||||
-command {EncodeDialog file}
|
||||
|
||||
$m add command -label [::msgcat::mc "Syntax check"] -command {DoModule syntax}\
|
||||
-font $font(normal) -state disable
|
||||
|
||||
##.frmMenu 'EDIT' ##
|
||||
menubutton .frmMenu.mnuEdit -text [::msgcat::mc "Edit"] -menu .frmMenu.mnuEdit.m -font $font(normal) -background $color(bg)
|
||||
set m [menu .frmMenu.mnuEdit.m -background $color(bg)]
|
||||
$m add command -label [::msgcat::mc "Undo"] -font $font(normal) -accelerator "Ctrl+Z"\
|
||||
-state normal -command "CutPast undo"
|
||||
$m add separator
|
||||
$m add command -label [::msgcat::mc "Copy"] -font $font(normal) -accelerator "Ctrl+C"\
|
||||
-command "CutPast copy"
|
||||
$m add command -label [::msgcat::mc "Paste"] -font $font(normal) -accelerator "Ctrl+V"\
|
||||
-command "CutPast paste"
|
||||
$m add command -label [::msgcat::mc "Cut"] -font $font(normal) -accelerator "Ctrl+X"\
|
||||
-command "CutPast cut"
|
||||
$m add separator
|
||||
$m add command -label [::msgcat::mc "Select All"] -command {Select all} -font $font(normal) -accelerator "Ctrl+/"
|
||||
$m add command -label [::msgcat::mc "Remove selection"] -command {Select remove} -font $font(normal)\
|
||||
-accelerator "Ctrl+\\"
|
||||
$m add separator
|
||||
$m add command -label [::msgcat::mc "Goto line"] -command GoToLine -font $font(normal)\
|
||||
-accelerator "Ctrl+G"
|
||||
$m add command -label [::msgcat::mc "Find"] -command Find -font $font(normal) -accelerator "Ctrl+F"
|
||||
$m add command -label [::msgcat::mc "Replace"] -command ReplaceDialog -font $font(normal)\
|
||||
-accelerator "Ctrl+R"
|
||||
$m add separator
|
||||
$m add cascade -label "[::msgcat::mc "Custom operations"] ..." -menu $m.hotkeys -font $font(normal) -state normal
|
||||
menu $m.hotkeys -background $color(bg)
|
||||
|
||||
## MENU for selected text ##
|
||||
set m [menu .frmMenu.mnuEdit.m.selection -background $color(bg)]
|
||||
$m add command -label [::msgcat::mc "Select All"] -command {Select all} -font $font(normal) -accelerator "Ctrl+/"
|
||||
$m add command -label [::msgcat::mc "Remove selection"] -command {Select remove} -font $font(normal)\
|
||||
-accelerator "Ctrl+\\"
|
||||
$m add separator
|
||||
$m add command -label [::msgcat::mc "Copy"] -font $font(normal) -accelerator "Ctrl+C"\
|
||||
-command "CutPast copy"
|
||||
$m add command -label [::msgcat::mc "Paste"] -font $font(normal) -accelerator "Ctrl+V"\
|
||||
-command "CutPast paste"
|
||||
$m add command -label [::msgcat::mc "Cut"] -font $font(normal) -accelerator "Ctrl+X"\
|
||||
-command "CutPast cut"
|
||||
$m add separator
|
||||
$m add command -label [::msgcat::mc "Preview formula"] -command {GenerateFormula math} -font $font(normal)\
|
||||
-accelerator "Alt+F"
|
||||
$m add command -label [::msgcat::mc "Preview text"] -command {GenerateFormula text} -font $font(normal)\
|
||||
-accelerator "Alt+T"
|
||||
$m add separator
|
||||
$m add command -label [::msgcat::mc "Remove to file"] -command {SaveToFile remove} -font $font(normal)
|
||||
$m add command -label [::msgcat::mc "Save as file"] -command {SaveToFile file} -font $font(normal)
|
||||
$m add command -label [::msgcat::mc "Save as image"] -command {SaveToFile image} -font $font(normal)
|
||||
|
||||
|
||||
## VIEW MENU ##
|
||||
menubutton .frmMenu.mnuView -text [::msgcat::mc "View"] -menu .frmMenu.mnuView.m -font $font(normal) -state normal -background $color(bg)
|
||||
set m [menu .frmMenu.mnuView.m -background $color(bg)]
|
||||
$m add cascade -label [::msgcat::mc "Toolbar"] -menu $m.tool -font $font(normal)
|
||||
set mn [menu $m.tool]
|
||||
|
||||
#$mn add command -label [::msgcat::mc "Create from template"] -command {FileDialog new_templ}\
|
||||
#-font $font(normal)
|
||||
|
||||
$m add separator
|
||||
$m add command -label [::msgcat::mc "Split window"] -font $font(normal) -accelerator "F2" -state disable\
|
||||
-command {SplitWindow}
|
||||
$m add command -label [::msgcat::mc "Encoding"] -font $font(normal) -state normal\
|
||||
-command {EncodeDialog view}
|
||||
|
||||
## MODULES MENU ##
|
||||
menubutton .frmMenu.mnuModule -text [::msgcat::mc "Modules"] -menu .frmMenu.mnuModule.m \
|
||||
-underline 0 -font $font(normal) -background $color(bg)
|
||||
|
||||
## HELP MENU ##
|
||||
menubutton .frmMenu.mnuHelp -text [::msgcat::mc "Help"] -menu .frmMenu.mnuHelp.m \
|
||||
-underline 0 -font $font(normal) -background $color(bg)
|
||||
set m [menu .frmMenu.mnuHelp.m -background $color(bg)]
|
||||
$m add command -label [::msgcat::mc "Help"] -command ShowHelp \
|
||||
-accelerator F1 -font $font(normal)
|
||||
$m add command -label [::msgcat::mc "About ..."] -command AboutDialog \
|
||||
-font $font(normal)
|
||||
|
||||
pack .frmMenu.mnuFile .frmMenu.mnuEdit .frmMenu.mnuDoc .frmMenu.mnuView .frmMenu.mnuModule -side left
|
||||
pack .frmMenu.mnuHelp -side right
|
||||
|
||||
|
||||
###############################################
|
||||
frame .frmBody.frmList -background $color(bg)
|
||||
frame .frmBody.frmEditor -background $color(bg)
|
||||
pack .frmBody.frmList .frmBody.frmEditor -side left -fill both
|
||||
|
||||
## SPLIT BAR ##
|
||||
pane::create .frmBody.frmList .frmBody.frmEditor
|
||||
|
||||
## TREE FRAME ##
|
||||
|
||||
set nbTree [NoteBook .frmBody.frmList.nBook -font $font(normal) -side $gui(tabsLabel) -background $color(bg)]
|
||||
pack $nbTree -fill both -expand true -padx 2 -pady 2
|
||||
|
||||
set f [$nbTree insert end fileTree -text [::msgcat::mc "Files"] -background $color(bg)]
|
||||
set fTree [ScrolledWindow $f.f -background $color(bg)]
|
||||
pack $fTree -side top -fill both -expand yes -padx 0 -pady 0
|
||||
set tree [Tree $fTree.tree \
|
||||
-relief sunken -borderwidth 1 -width 1 -height 1 -highlightthickness 1\
|
||||
-redraw 0 -dropenabled 1 -dragenabled 1 -dragevent 3 \
|
||||
-background $color(editBg) -selectbackground $color(selectbg) \
|
||||
-droptypes {TREE_NODE {copy {} move {} link {}}
|
||||
LISTBOX_ITEM {copy {} move {} link {}}} -opencmd {} -closecmd {}]
|
||||
$fTree setwidget $tree
|
||||
#pack $tree -side left -fill both -expand yes
|
||||
###############################################
|
||||
set fStruct [$nbTree insert end fileStruct -text [::msgcat::mc "Document"] -background $color(bg)]
|
||||
set fTreeStruct [ScrolledWindow $fStruct.fs -background $color(bg)]
|
||||
pack $fTreeStruct -side top -fill both -expand yes
|
||||
set treeStruct [Tree $fTreeStruct.treeStruct \
|
||||
-relief sunken -borderwidth 1 -width 1 -height 1 -highlightthickness 1\
|
||||
-redraw 0 -dropenabled 0 -dragenabled 0 -dragevent 3 \
|
||||
-background $color(editBg) -selectbackground $color(selectbg) \
|
||||
-showlines 1 -droptypes {
|
||||
TREE_NODE {copy {} move {} link {}}
|
||||
LISTBOX_ITEM {copy {} move {} link {}}
|
||||
}]
|
||||
$fTreeStruct setwidget $treeStruct
|
||||
#pack $treeStruct -side left -fill both -expand yes
|
||||
###############################################
|
||||
set f [$nbTree insert end lblList -text [::msgcat::mc "Labels"] -background $color(bg)]
|
||||
set fList [ScrolledWindow $f.f -background $color(bg)]
|
||||
set lblList [ListBox $fList.list -font $font(normal) -relief sunken -borderwidth 1 -width 1 -height 1 -highlightthickness 1 -background $color(editBg) -selectbackground $color(selectbg)]
|
||||
#pack $lblList -side left -fill both -expand yes
|
||||
$fList setwidget $lblList
|
||||
pack $fList -side top -fill both -expand yes
|
||||
###############################################
|
||||
set nb [NoteBook .frmBody.frmEditor.noteBook -font $font(normal) -side $gui(tabsLabel) -background $color(bg)]
|
||||
pack $nb -fill both -expand true -padx 2 -pady 2
|
||||
###############################################
|
||||
|
||||
set m .popupTabs
|
||||
menu $m -font $font(normal)
|
||||
$m add command -label [::msgcat::mc "Close"] -command {FileDialog close}\
|
||||
-font $font(normal) -accelerator "Ctrl+W"
|
||||
$m add command -label [::msgcat::mc "Close all"] -command {FileDialog close_all}\
|
||||
-font $font(normal)
|
||||
|
||||
## KEYS BINDINGS ##
|
||||
|
||||
$tree bindText <Button-1> "TreeOneClick [$tree selection get]"
|
||||
$tree bindImage <Button-1> "TreeOneClick [$tree selection get]"
|
||||
$tree bindText <Shift-Button-1> {$tree selection add [$tree selection get]}
|
||||
$tree bindImage <Shift-Button-1> {$tree selection add [$tree selection get]}
|
||||
$treeStruct bindText <Button-1> "TreeStructOneClick [$treeStruct selection get]"
|
||||
$treeStruct bindImage <Button-1> "TreeStructOneClick [$treeStruct selection get]"
|
||||
|
||||
$nb bindtabs <ButtonRelease> "ClickTab"
|
||||
$nb bindtabs <Button-3> {catch [PopupMenuTab .popupTabs %X %Y]}
|
||||
|
||||
## MOUSE WHEEL BINDING ##
|
||||
bind $fTree.tree.c <Button-4> "$tree yview scroll -3 units"
|
||||
bind $fTree.tree.c <Button-5> "$tree yview scroll 3 units"
|
||||
bind $fTree.tree.c <Shift-Button-4> "$tree xview scroll -2 units"
|
||||
bind $fTree.tree.c <Shift-Button-5> "$tree xview scroll 2 units"
|
||||
bind $fTree.tree.c <Button-3> {catch [tk_popup .frmMenu.mnuFile.m %X %Y]}
|
||||
|
||||
bind $fTreeStruct.treeStruct.c <Button-4> "$treeStruct yview scroll -3 units"
|
||||
bind $fTreeStruct.treeStruct.c <Button-5> "$treeStruct yview scroll 3 units"
|
||||
bind $fTreeStruct.treeStruct.c <Shift-Button-4> "$treeStruct xview scroll -2 units"
|
||||
bind $fTreeStruct.treeStruct.c <Shift-Button-5> "$treeStruct xview scroll 2 units"
|
||||
|
||||
$lblList bindImage <ButtonRelease-1> "FindLabel [$lblList selection get]"
|
||||
$lblList bindText <ButtonRelease-1> "FindLabel [$lblList selection get]"
|
||||
|
||||
bind $lblList.c <Button-4> "$lblList yview scroll -3 units"
|
||||
bind $lblList.c <Button-5> "$lblList yview scroll 3 units"
|
||||
bind $lblList.c <Shift-Button-4> "$lblList xview scroll -2 units"
|
||||
bind $lblList.c <Shift-Button-5> "$lblList xview scroll 2 units"
|
||||
|
||||
bind . <Control-q> Quit
|
||||
bind . <Control-Q> Quit
|
||||
bind . <F1> ShowHelp
|
||||
bind . <F5> {ConvertDialog dvi}
|
||||
bind . <F6> {ConvertDialog ps}
|
||||
bind . <F7> {ConvertDialog pdf}
|
||||
|
||||
bind . <Control-Next> {PageTab 1}
|
||||
bind . <Control-Prior> {PageTab -1}
|
||||
|
||||
###############################################
|
||||
## CREATE TOOLBARs ##
|
||||
###############################################
|
||||
set btnNum 0
|
||||
proc CreateToolButton {frame command image hint keys} {
|
||||
global dir btnNum color relief
|
||||
if {$frame == "main"} {
|
||||
set frm frmTool
|
||||
} else {
|
||||
set frm frmToolEdit
|
||||
}
|
||||
set comm [string trim $command "\""]
|
||||
set btn [Button .$frm.$frame.btn_$btnNum -relief $relief(btn) -bd 1\
|
||||
-command $comm -background $color(bg)]
|
||||
image create photo img_$btnNum -format gif -file [file join $dir(img) $image]
|
||||
$btn configure -image img_$btnNum
|
||||
if {$keys != ""} {
|
||||
set keys [string trim $keys "\""]
|
||||
#puts "$keys - $comm"
|
||||
bind . <$keys> "$comm"
|
||||
}
|
||||
|
||||
pack $btn -side left
|
||||
balloon $btn set [::msgcat::mc [string trim $hint "\""]]
|
||||
incr btnNum
|
||||
}
|
||||
proc ReadToolBarFile {_dir} {
|
||||
global dir font color file frm frame tool
|
||||
foreach file [lsort [glob -nocomplain [file join $_dir toolbar *]]] {
|
||||
puts "Found toolbar file - \'$file\'"
|
||||
set frame [file tail $file]
|
||||
if {$frame == "main"} {
|
||||
set frm frmTool
|
||||
} else {
|
||||
set frm frmToolEdit
|
||||
}
|
||||
AddCheckBox .frmMenu.mnuView.m.tool $frame $file $frm
|
||||
if {$tool($frame) == 1} {
|
||||
ReadToolBar $file
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
proc AddCheckBox {m frame file frm} {
|
||||
global font color tool
|
||||
$m add checkbutton -label [::msgcat::mc "$frame"] -font $font(normal) -state normal\
|
||||
-offvalue 0 -onvalue 1 -variable tool($frame) -selectcolor $color(selectbg)\
|
||||
-command "ToolBar $frm $frame $file"\
|
||||
-background $color(bg)
|
||||
}
|
||||
|
||||
proc ReadToolBar {file} {
|
||||
global dir font color
|
||||
set frame [file tail $file]
|
||||
puts "Create toolbar \'$frame\' from file \'$file\'"
|
||||
|
||||
if {$frame == "main"} {
|
||||
set frm frmTool
|
||||
} else {
|
||||
set frm frmToolEdit
|
||||
}
|
||||
pack [frame .$frm.$frame -background $color(bg)] -side left -fill x
|
||||
set fHandle [open $file]
|
||||
while {[gets $fHandle line]>=0} {
|
||||
set line [string trim $line]
|
||||
set kw [string range $line 0 [expr [string first " " $line]-1]]
|
||||
set l [string range $line [expr [string first " " $line] +1] end]
|
||||
if {$kw == "button"} {
|
||||
if [regexp -- {(\".*?\") (.*?) (\".*?\") (\".*?\")} $l m cmd img hint keys] {
|
||||
#puts "$frame $cmd $img $hint"
|
||||
CreateToolButton $frame $cmd $img $hint $keys
|
||||
} elseif [regexp -- {(\".*?\") (.*?) (\".*?\")} $l m cmd img hint] {
|
||||
CreateToolButton $frame $cmd $img $hint ""
|
||||
}
|
||||
}
|
||||
if {$l == "Separator"} {
|
||||
CreateSeparator $frame
|
||||
}
|
||||
if {$kw == "menu"} {
|
||||
if [regexp -- {(.*?) (\".*?\")} $l m img hint] {
|
||||
set menu [CreateToolMenu $frame $img $hint]
|
||||
}
|
||||
}
|
||||
if {$kw == "cmd"} {
|
||||
|
||||
if [regexp -- {(\".*?\") (\".*?\") (\".*?\")} $l m cmd hint keys] {
|
||||
InsertCommand $menu $cmd $hint "" $keys
|
||||
} elseif [regexp -- {(\".*?\") (\".*?\")} $l m cmd hint] {
|
||||
InsertCommand $menu $cmd $hint "" ""
|
||||
}
|
||||
|
||||
if [regexp -- {separator} $l m] {
|
||||
InsertSeparator $menu
|
||||
}
|
||||
}
|
||||
if {$kw == "imagecmd"} {
|
||||
if [regexp -- {(\".*?\") (\".*?\") (.*?)\.gif} $l m cmd hint im] {
|
||||
InsertCommand $menu $cmd $hint $im ""
|
||||
}
|
||||
if [regexp -- {(\".*?\") (\".*?\") (.*?)\.gif (\".*?\")} $l m cmd hint im keys] {
|
||||
InsertCommand $menu $cmd $hint $im $keys
|
||||
}
|
||||
}
|
||||
}
|
||||
close $fHandle
|
||||
}
|
||||
|
||||
set mnuNum 0
|
||||
proc CreateToolMenu {frame image hint} {
|
||||
global dir font mnuNum color relief
|
||||
if {$frame == "main"} {
|
||||
set frm frmTool
|
||||
} else {
|
||||
set frm frmToolEdit
|
||||
}
|
||||
image create photo img_mnu$mnuNum -format gif -file [file join $dir(img) $image]
|
||||
menubutton .$frm.$frame.m$mnuNum -image img_mnu$mnuNum -border 0\
|
||||
-menu .$frm.$frame.m$mnuNum.m -background $color(bg) -relief $relief(menu)
|
||||
|
||||
set menu [menu .$frm.$frame.m$mnuNum.m -background $color(bg)]
|
||||
pack .$frm.$frame.m$mnuNum -side left
|
||||
balloon .$frm.$frame.m$mnuNum set [::msgcat::mc [string trim $hint "\""]]
|
||||
incr mnuNum
|
||||
return $menu
|
||||
}
|
||||
set cmdNum 0
|
||||
proc InsertCommand {m cmd hint image keys} {
|
||||
global font dir cmdNum color
|
||||
set comm [string trim $cmd "\""]
|
||||
set hint [string trim $hint "\""]
|
||||
#puts "Create cmd - $m - $cmd $hint $image"
|
||||
|
||||
if {$keys != ""} {
|
||||
set keys [string trim $keys "\""]
|
||||
#puts "$keys - $comm"
|
||||
bind . <$keys> "$comm"
|
||||
if {$image != ""} {
|
||||
set image [string trim $image]
|
||||
image create photo img_$cmdNum -format gif -file [file join $dir(img) $image.gif]
|
||||
$m add command -label [::msgcat::mc $hint] -font $font(normal) -state normal\
|
||||
-command $comm -image img_$cmdNum -background $color(bg) -accelerator "$keys"
|
||||
} else {
|
||||
$m add command -label [::msgcat::mc $hint] -font $font(normal) -state normal\
|
||||
-command $comm -background $color(bg) -accelerator "$keys"
|
||||
}
|
||||
} else {
|
||||
if {$image != ""} {
|
||||
set image [string trim $image]
|
||||
image create photo img_$cmdNum -format gif -file [file join $dir(img) $image.gif]
|
||||
$m add command -label [::msgcat::mc $hint] -font $font(normal) -state normal\
|
||||
-command $comm -image img_$cmdNum -background $color(bg)
|
||||
} else {
|
||||
$m add command -label [::msgcat::mc $hint] -font $font(normal) -state normal\
|
||||
-command $comm -background $color(bg)
|
||||
}
|
||||
}
|
||||
incr cmdNum
|
||||
}
|
||||
proc InsertSeparator {m} {
|
||||
$m add separator
|
||||
}
|
||||
|
||||
proc CreateSeparator {frame} {
|
||||
global dir btnNum color relief
|
||||
if {$frame == "main"} {
|
||||
set frm frmTool
|
||||
} else {
|
||||
set frm frmToolEdit
|
||||
}
|
||||
set btn [frame .$frm.$frame.btn_$btnNum -width 10 -background $color(bg) -borderwidth 0]
|
||||
#set btn [Button .$frm.$frame.btn_$btnNum -relief $relief(btn) -bd 2 -background $color(bg) -width 0 -state disable]
|
||||
pack $btn -side left -fill y -expand 1
|
||||
incr btnNum
|
||||
}
|
||||
|
||||
proc ToolBar {frm frame file} {
|
||||
global tool
|
||||
if {$tool($frame) == 0} {
|
||||
#set tool($frame) 0
|
||||
if {$frame == "main"} {
|
||||
destroy .$frm.$frame
|
||||
.frmTool configure -height 1
|
||||
} else {
|
||||
destroy .$frm.$frame
|
||||
.frmToolEdit configure -height 1
|
||||
}
|
||||
return
|
||||
} elseif {$tool($frame) == 1} {
|
||||
#set tool($frame) 1
|
||||
ReadToolBar $file
|
||||
return
|
||||
}
|
||||
}
|
||||
|
||||
###############################################
|
||||
proc CutPast {action} {
|
||||
global nb
|
||||
set node [$nb raise]
|
||||
if {$node == "newproj" || $node == "settings" || $node == "about" || $node == ""} {
|
||||
return
|
||||
}
|
||||
|
||||
set text $nb.f$node.f.text
|
||||
switch -- $action {
|
||||
"copy" {
|
||||
tk_textCopy $text
|
||||
}
|
||||
"cut" {
|
||||
tk_textCut $text
|
||||
}
|
||||
"paste" {
|
||||
tk_textPaste $text
|
||||
}
|
||||
"undo" {
|
||||
$text undo
|
||||
}
|
||||
}
|
||||
}
|
||||
proc Select {type} {
|
||||
global nb activeFile
|
||||
set text $nb.f$activeFile.f.text
|
||||
if {$type == "all"} {
|
||||
$text tag remove sel 1.0 end
|
||||
$text tag add sel 1.0 end
|
||||
} elseif {$type == "remove"} {
|
||||
$text tag remove sel 1.0 end
|
||||
}
|
||||
}
|
||||
|
||||
proc PopupMenu {text x y} {
|
||||
set selIndex [$text tag ranges sel]
|
||||
if {$selIndex != ""} {
|
||||
tk_popup .frmMenu.mnuEdit.m.selection $x $y
|
||||
} else {
|
||||
tk_popup .frmMenu.mnuEdit.m $x $y
|
||||
}
|
||||
}
|
||||
proc PopupMenuTab {menu x y} {
|
||||
tk_popup $menu $x $y
|
||||
}
|
||||
|
||||
###########
|
||||
## STATUS BAR ##
|
||||
set frm1 [frame .frmStatus.frmFileAttr -background $color(bg)]
|
||||
set frm2 [frame .frmStatus.frmActive -background $color(bg)]
|
||||
set frm3 [frame .frmStatus.frmFileSize -relief sunken -background $color(bg)]
|
||||
set frm4 [frame .frmStatus.frmPos -background $color(bg)]
|
||||
set frm5 [frame .frmStatus.frmFile -background $color(bg)]
|
||||
set frm6 [frame .frmStatus.frmOvwrt -background $color(bg)]
|
||||
set frm7 [frame .frmStatus.frmOther -background $color(bg)]
|
||||
pack $frm1 $frm4 $frm6 $frm2 $frm5 $frm3 -side left -fill x
|
||||
pack $frm7 -side left -fill x -expand true
|
||||
set status(fileAttr) [label $frm1.lblFileAttr -width 30 -relief sunken -font $font(normal) -anchor w -background $color(bg)]
|
||||
pack $frm1.lblFileAttr -fill x
|
||||
set status(pos) [label $frm4.lblPos -width 10 -relief sunken -font $font(bold) -anchor w -background $color(bg)]
|
||||
pack $frm4.lblPos -fill x
|
||||
set status(ovwrt) [label $frm6.lblOvwrt -width 10 -relief sunken -font $font(normal) -anchor center -background $color(bg)]
|
||||
pack $frm6.lblOvwrt -fill x
|
||||
set status(active) [label $frm2.lblActive -width 25 -relief sunken -font $font(normal) -anchor center -background $color(bg) ]
|
||||
pack $frm2.lblActive -fill x
|
||||
set status(fileSize) [label $frm3.lblFileSize -width 10 -relief sunken -font $font(normal) -anchor w -background $color(bg)]
|
||||
pack $frm3.lblFileSize -fill x
|
||||
set status(encode) [label $frm5.lblFile -width 10 -relief sunken -font $font(normal) -anchor w -background $color(bg)]
|
||||
pack $frm5.lblFile -fill x
|
||||
set status(other) [label $frm7.lblOther -width 10 -relief sunken -font $font(normal) -anchor w -background $color(bg)]
|
||||
pack $frm7.lblOther -fill x
|
||||
|
||||
#######
|
||||
bind . <Control-n> {FileDialog new}
|
||||
bind . <Control-ograve> {FileDialog new}
|
||||
bind . <Control-o> {FileDialog open}
|
||||
bind . <Control-ugrave> {FileDialog open}
|
||||
|
||||
$nbTree raise fileTree
|
||||
############
|
||||
$status(ovwrt) configure -text [::msgcat::mc "Insert"]
|
||||
|
||||
ReadToolBarFile $dir(gui) ;# system toolbars
|
||||
ReadToolBarFile $dir(work_gui) ;# user toolbars
|
||||
ReadHotKeysFile $dir(gui) ;# system hotkeys
|
||||
ReadHotKeysFile $dir(work_gui) ;# users hotkeys
|
||||
|
||||
## FINDE EXTERNAL MODULES ##
|
||||
FindModule
|
||||
|
||||
|
||||
|
||||
|
||||
|
333
lib/modules/help.tcl
Executable file
333
lib/modules/help.tcl
Executable file
@@ -0,0 +1,333 @@
|
||||
#########################################################
|
||||
# Tk LaTeX Editor
|
||||
# Distributed under GNU Public License
|
||||
# Author: Sergey Kalinin (BanZaj) banzaj@lrn.ru
|
||||
# Copyright (c) "CONERO lab", 2002, http://conero.lrn.ru
|
||||
#########################################################
|
||||
proc ShowHelp {} {
|
||||
if {[winfo exists .help] == 1} {
|
||||
focus -force .help
|
||||
raise .help
|
||||
} else {
|
||||
TopLevelHelp
|
||||
}
|
||||
if {[catch {set word [selection get]} error] != 0} {
|
||||
set word " "
|
||||
} else {
|
||||
puts $word
|
||||
TopLevelHelp
|
||||
SearchWord $word
|
||||
}
|
||||
}
|
||||
|
||||
proc HlpTreeOneClick {node} {
|
||||
global font(normal) hlpTree wordList hlpNoteBook findString dir(img) font
|
||||
global lstSearch nodeParent
|
||||
$hlpTree selection set $node
|
||||
set nodeParent [$hlpTree parent $node]
|
||||
set item [$hlpTree itemcget $node -data]
|
||||
set file [string range $item 4 end]
|
||||
#puts "$file" ;#debuf info
|
||||
if {[string range $item 0 2] == "toc"} {
|
||||
# $hlpTree configure
|
||||
}
|
||||
if {[$hlpTree itemcget $node -open] == 1} {
|
||||
$hlpTree itemconfigure $node -open 0
|
||||
} elseif {[$hlpTree itemcget $node -open] == 0} {
|
||||
$hlpTree itemconfigure $node -open 1
|
||||
}
|
||||
if {[string range $item 0 2] == "doc"} {
|
||||
GetContent $file
|
||||
}
|
||||
}
|
||||
## GETTING TABLE OF CONTENT ##
|
||||
proc GetTOC {} {
|
||||
global dir hlpTree dir font lstSearch arr help locale
|
||||
foreach dirHlp [lsort [glob -nocomplain [file join $dir(hlp) *]]] {
|
||||
if {[file isdirectory $dirHlp] == 1} {
|
||||
set dirHlp [file join $dir(hlp) $locale]
|
||||
puts $dirHlp
|
||||
} else {
|
||||
set dirHlp $dir(hlp)
|
||||
}
|
||||
}
|
||||
if {[info exists dirHlp] != 1} {set dirHlp $dir(hlp)}
|
||||
puts $dirHlp
|
||||
foreach file [lsort [glob -nocomplain [file join $dirHlp *toc.html]]] {
|
||||
set fileName [file join $file]
|
||||
set tocFile [open $fileName r]
|
||||
fconfigure $tocFile -encoding binary
|
||||
|
||||
set dot "_"
|
||||
set nodeParent [file dirname $fileName]
|
||||
while {[gets $tocFile line]>=0} {
|
||||
set a ""
|
||||
set b ""
|
||||
set line [encoding convertfrom $help(encode) $line]
|
||||
if {[regexp -nocase "<title>.+\</title>" $line a]} {
|
||||
if {[regexp ">.+\<" $line a]} {
|
||||
set length [string length $a]
|
||||
set title [string range $a 1 [expr $length-2]]
|
||||
#puts $nodeParent ;# debug info
|
||||
$hlpTree insert end root $nodeParent -text "$title" -font $font(normal) \
|
||||
-data "toc_$nodeParent" -open 0\
|
||||
-image [Bitmap::get [file join $dir(img) books.gif]]
|
||||
}
|
||||
} elseif {[regexp "\".+\"" $line a]} {
|
||||
set data [string range $a 1 [expr [string last "\"" $a]-1]]
|
||||
if {[regexp ">.+\<" $line b]} {
|
||||
set line [string range $b 1 [expr [string first "<" $b]-1]]
|
||||
regsub -all {[ :]} $line "_" subNode
|
||||
#regsub -all ":" $ubNode "_" node
|
||||
set subNode "$nodeParent$dot$subNode"
|
||||
if {[info exists arr($subNode)] == 0} {
|
||||
set arr($subNode) [file join $dirHlp $data]
|
||||
}
|
||||
set data [file join $dirHlp $data]
|
||||
#puts "$subNode" ;# debug info
|
||||
$hlpTree insert end "$nodeParent" $subNode -text "$line"\
|
||||
-font $font(normal) -data "doc_$data" -open 0\
|
||||
-image [Bitmap::get [file join $dir(img) file.gif]]
|
||||
$lstSearch insert end $line
|
||||
}
|
||||
} else {
|
||||
break
|
||||
}
|
||||
}
|
||||
}
|
||||
$hlpTree configure -redraw 1
|
||||
}
|
||||
proc SearchWord {word} {
|
||||
global arr nBookTree
|
||||
set word [string tolower [string trim $word]]
|
||||
puts $word
|
||||
$nBookTree raise hlpSearch
|
||||
# InsertEnt .help.frmBody.frmCat.nBookTree.fhlpSearch.frmScrhEnt.entSearch $word
|
||||
foreach wrd [array names arr] {
|
||||
set name "[file rootname [file tail $arr($wrd)]]"
|
||||
set file "$arr($wrd)"
|
||||
if {[string match "$word*" [string tolower $name]] == 1} {
|
||||
GetContent $file
|
||||
}
|
||||
}
|
||||
}
|
||||
## GETTING CONTENT FROM FILES ##
|
||||
proc GetContent {file} {
|
||||
global dir hlpNoteBook font help
|
||||
$hlpNoteBook raise [$hlpNoteBook page 0]
|
||||
set node [$hlpNoteBook raise]
|
||||
if {$node != ""} {
|
||||
$hlpNoteBook delete hlpHTML
|
||||
}
|
||||
set nbTitle ""
|
||||
set html ""
|
||||
set file [open $file r]
|
||||
fconfigure $file -encoding binary
|
||||
while {[gets $file line]>=0} {
|
||||
# if {$line == ""} {
|
||||
# set html "<h1><3E><><EFBFBD><EFBFBD> $file <20><> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD></h1>"
|
||||
# }
|
||||
set line [encoding convertfrom $help(encode) $line]
|
||||
if {[regexp -nocase "<title>.+\</title>" $line a]} {
|
||||
if {[regexp ">.+\<" $a a]} {
|
||||
set length [string length $a]
|
||||
set nbTitle [string range $a 1 [expr $length-2]]
|
||||
#puts $nbTitle
|
||||
#puts $a
|
||||
}
|
||||
}
|
||||
append html $line
|
||||
}
|
||||
set frmHTML [$hlpNoteBook insert end hlpHTML -text $nbTitle]
|
||||
set txt [text $frmHTML.txtHTML -yscrollcommand "$frmHTML.yscroll set" \
|
||||
-relief sunken -wrap word -highlightthickness 0 -font $font(normal)\
|
||||
-selectborderwidth 0 -selectbackground #55c4d1 -width 10]
|
||||
scrollbar $frmHTML.yscroll -relief sunken -borderwidth {1} -width {10} -takefocus 0\
|
||||
-command "$frmHTML.txtHTML yview"
|
||||
|
||||
pack $txt -side left -fill both -expand true
|
||||
pack $frmHTML.yscroll -side left -fill y
|
||||
$hlpNoteBook raise hlpHTML
|
||||
focus -force $txt
|
||||
HMinit_win $txt
|
||||
#HMlink_callback LinkCallback
|
||||
HMset_state $txt -size 0
|
||||
HMset_indent $txt 1.2
|
||||
HMparse_html $html "HMrender $txt"
|
||||
#HM::tag_title .help "Help - $nbTitle"
|
||||
$txt configure -state disabled
|
||||
|
||||
}
|
||||
## GOTO URL PROCEDURE ##
|
||||
proc LinkCallback {w url} {
|
||||
global dir nodeParent
|
||||
set url "[file join $dir(hlp) $nodeParent $url]"
|
||||
if {[catch {open $url r} oHTML]} {
|
||||
tk_messageBox -title "[::msgcat::mc "Error open URL"]"\
|
||||
-message "[::msgcat::mc "Can't found file:"] $url"\
|
||||
-icon error -type ok
|
||||
} else {
|
||||
GetContent $url
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
## autor DEDERER ##
|
||||
proc LinkCallback_ {w url} {
|
||||
global dir
|
||||
set url "[file join $dir(hlp) $url]"
|
||||
if {[catch {open $url r} oHTML]} {
|
||||
tk_messageBox -title "[::msgcat::mc "Error open URL"]"\
|
||||
-message "[::msgcat::mc "Can't founf file: $url"]"\
|
||||
-icon error -type ok
|
||||
} else {
|
||||
set html [read $oHTML]
|
||||
$w configure -state normal
|
||||
HMreset_win $w
|
||||
HMparse_html $html "HMrender $w"
|
||||
$w configure -state disable
|
||||
}
|
||||
#HMrender [winfo toplevel $w] $url
|
||||
}
|
||||
|
||||
## MAIN HELP WINDOW ##
|
||||
proc TopLevelHelp {} {
|
||||
global font hlpTree hlpNoteBook nBookTree homeDir dir lstSearch w frmSrchList
|
||||
set w .help
|
||||
set w_exist [winfo exists $w]
|
||||
if !$w_exist {
|
||||
toplevel $w
|
||||
# wm resizable .help 0 0
|
||||
wm geometry $w 600x400+0+0
|
||||
wm title $w [::msgcat::mc "Help"]
|
||||
# wm protocol $w WM_DELETE_WINDOW {destroy .msg .help}
|
||||
#wm geometry . 600x400+0+0
|
||||
wm title $w [::msgcat::mc "Help"]
|
||||
|
||||
frame $w.frmMenu -border 1 -relief raised
|
||||
frame $w.frmTool -border 1 -relief raised
|
||||
frame $w.frmBody -border 1 -relief raised
|
||||
frame $w.frmStatus -border 1 -relief sunken
|
||||
pack $w.frmMenu -side top -padx 1 -fill x
|
||||
pack $w.frmTool -side top -padx 1 -fill x
|
||||
pack $w.frmBody -side top -padx 1 -fill both -expand true
|
||||
pack $w.frmStatus -side top -padx 1 -fill x
|
||||
|
||||
|
||||
button $w.frmTool.btnBack -relief groove -font $font(bold) -command Back -state disable
|
||||
button $w.frmTool.btnForward -relief groove -font $font(bold) -command Forward -state disable
|
||||
button $w.frmTool.btnRefresh -relief groove -font $font(bold) -command Refresh -state disable
|
||||
button $w.frmTool.btnPrint -relief groove -font $font(bold) -command Print -state disable
|
||||
image create photo imgBack -format gif -file [file join $dir(img) back.gif]
|
||||
image create photo imgForward -format gif -file [file join $dir(img) forward.gif]
|
||||
image create photo imgRefresh -format gif -file [file join $dir(img) refresh.gif]
|
||||
image create photo imgPrint -format gif -file [file join $dir(img) printer.gif]
|
||||
$w.frmTool.btnBack configure -image imgBack
|
||||
$w.frmTool.btnForward configure -image imgForward
|
||||
$w.frmTool.btnRefresh configure -image imgRefresh
|
||||
$w.frmTool.btnPrint configure -image imgPrint
|
||||
pack $w.frmTool.btnBack $w.frmTool.btnForward $w.frmTool.btnRefresh $w.frmTool.btnPrint\
|
||||
-side left -fill x
|
||||
|
||||
|
||||
set frmCat [frame $w.frmBody.frmCat -border 1 -relief sunken]
|
||||
pack $frmCat -side left -fill y
|
||||
set frmWork [frame $w.frmBody.frmWork -border 1 -relief sunken]
|
||||
pack $frmWork -side left -fill both -expand true
|
||||
|
||||
set nBookTree [NoteBook $frmCat.nBookTree -font $font(normal)]
|
||||
pack $nBookTree -fill both -expand true -padx 2 -pady 2
|
||||
set frmTreeNb [$nBookTree insert end hlpTree -text "[::msgcat::mc "Contents"]"]
|
||||
set frmSearch [$nBookTree insert end hlpSearch -text "[::msgcat::mc "Search"]"]
|
||||
$nBookTree raise hlpTree
|
||||
|
||||
set frmScrlX [frame $frmTreeNb.frmScrlX -border 0 -relief sunken]
|
||||
set frmTree [frame $frmTreeNb.frmTree -border 1 -relief sunken]
|
||||
set hlpTree [Tree $frmTree.tree \
|
||||
-relief sunken -borderwidth 1 -width 20 -highlightthickness 0\
|
||||
-redraw 0 -dropenabled 1 -dragenabled 1 -dragevent 3 \
|
||||
-yscrollcommand {.help.frmBody.frmCat.nBookTree.fhlpTree.frmTree.scrlY set} \
|
||||
-xscrollcommand {.help.frmBody.frmCat.nBookTree.fhlpTree.frmScrlX.scrlX set} \
|
||||
-background "#d3d3d3" -selectbackground "#55c4d1" \
|
||||
-droptypes {
|
||||
TREE_NODE {copy {} move {} link {}}
|
||||
LISTBOX_ITEM {copy {} move {} link {}}
|
||||
} -opencmd "" -closecmd ""]
|
||||
|
||||
pack $frmTree -side top -fill y -expand true
|
||||
pack $frmScrlX -side top -fill x
|
||||
|
||||
scrollbar $frmTree.scrlY -command {$hlpTree yview} \
|
||||
-borderwidth {1} -width {10} -takefocus 0
|
||||
pack $hlpTree $frmTree.scrlY -side left -fill y
|
||||
|
||||
scrollbar $frmScrlX.scrlX -command {$hlpTree xview} \
|
||||
-orient horizontal -borderwidth {1} -width {10} -takefocus 0
|
||||
pack $frmScrlX.scrlX -fill x -expand true
|
||||
|
||||
set frmSrchList [frame $frmSearch.frmScrhList -border 0 -relief sunken]
|
||||
set frmSrchEnt [frame $frmSearch.frmScrhEnt -border 0 -relief sunken]
|
||||
set frmSrchScrollX [frame $frmSearch.frmScrhScrollX -border 0 -relief sunken]
|
||||
pack $frmSrchEnt -side top -fill x
|
||||
pack $frmSrchList -side top -fill both -expand true
|
||||
pack $frmSrchScrollX -side top -fill x
|
||||
|
||||
entry $frmSrchEnt.entSearch
|
||||
set lstSearch [listbox $frmSrchList.lstSearch -font $font(normal)\
|
||||
-yscrollcommand\
|
||||
{.help.frmBody.frmCat.nBookTree.fhlpSearch.frmScrhList.scrListY set}\
|
||||
-xscrollcommand\
|
||||
{.help.frmBody.frmCat.nBookTree.fhlpSearch.frmScrhScrollX.scrListX set}\
|
||||
-selectmode single -selectbackground #55c4d1\
|
||||
-selectborderwidth 0]
|
||||
scrollbar $frmSrchList.scrListY -command\
|
||||
{$frmSrchList.lstSearch yview} -borderwidth {1} -width {10} -takefocus 0
|
||||
|
||||
pack $frmSrchEnt.entSearch -side top -fill x -expand true
|
||||
|
||||
pack $frmSrchList.lstSearch -side left -fill both -expand true
|
||||
pack $frmSrchList.scrListY -side left -fill y
|
||||
|
||||
scrollbar $frmSrchScrollX.scrListX -orient horizontal -command\
|
||||
{$frmSrchList.lstSearch xview} -borderwidth {1} -width {10} -takefocus 0
|
||||
pack $frmSrchScrollX.scrListX -fill x
|
||||
# $hlpTree bindText <ButtonRelease-4> [puts %k]
|
||||
# $hlpTree bindText <ButtonRelease-3> [puts %k]
|
||||
# bind $frmTree <ButtonPress-4> {$frmSrchList.lstSearch xview}
|
||||
# $hlpTree bindText <Double-ButtonPress-1> "HlpTreeDoubleClick [$hlpTree selection get]"
|
||||
# $hlpTree bindImage <Double-ButtonPress-1> "HlpTreeDoubleClick [$hlpTree selection get]"
|
||||
$hlpTree bindText <ButtonPress-1> "HlpTreeOneClick [$hlpTree selection get]"
|
||||
$hlpTree bindImage <ButtonPress-1> "HlpTreeOneClick [$hlpTree selection get]"
|
||||
bind .help <Escape> "destroy .help"
|
||||
|
||||
# bind $frmSrchEnt.entSearch <KeyRelease>\
|
||||
# {SearchWord [Text .help.frmBody.frmCat.nBookTree.fhlpSearch.frmScrhEnt.entSearch]}
|
||||
|
||||
#bind $w <Escape> exit
|
||||
#bind $frmTree <Down> {TreeClick [$hlpTree selection get]}
|
||||
#bind $frmTree <Up> {TreeClick [$hlpTree selection get]}
|
||||
#bind $frmTree <Return> {TreeClick [$hlpTree selection get]}
|
||||
bind $frmTree.tree.c <Button-4> "$hlpTree yview scroll -3 units"
|
||||
bind $frmTree.tree.c <Button-5> "$hlpTree yview scroll 3 units"
|
||||
bind $frmTree.tree.c <Shift-Button-4> "$hlpTree xview scroll -2 units"
|
||||
bind $frmTree.tree.c <Shift-Button-5> "$hlpTree xview scroll 2 units"
|
||||
|
||||
set hlpNoteBook [NoteBook $frmWork.hlpNoteBook -font $font(normal)]
|
||||
pack $hlpNoteBook -fill both -expand true -padx 2 -pady 2
|
||||
GetTOC
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
##################################################
|
||||
#TopLevelHelp
|
||||
#GetTOC
|
||||
|
||||
#GetContent $dir(hlp)/tcl.toc.html
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
61
lib/modules/hotkeys.tcl
Executable file
61
lib/modules/hotkeys.tcl
Executable file
@@ -0,0 +1,61 @@
|
||||
######################################################
|
||||
# Tk LaTeX Editor
|
||||
# Distributed under GNU Public License
|
||||
# Author: Sergey Kalinin (aka BanZaj) banzaj@lrn.ru
|
||||
# Copyright (c) "CONERO lab", 2004, http://conero.lrn.ru
|
||||
######################################################
|
||||
|
||||
proc ReadHotKeysFile {_dir} {
|
||||
global dir
|
||||
foreach file [lsort [glob -nocomplain [file join $_dir hotkeys *]]] {
|
||||
puts "Found hotkeys file - \'$file\'"
|
||||
ReadHotKeys $file
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
set mnum 0
|
||||
proc ReadHotKeys {file} {
|
||||
global dir font mnum
|
||||
set menu_root ".frmMenu.mnuEdit.m.hotkeys"
|
||||
set menu $menu_root
|
||||
puts "Read HotKeys settings from \'$file\'"
|
||||
|
||||
set fHandle [open $file]
|
||||
while {[gets $fHandle line]>=0} {
|
||||
set line [string trim $line]
|
||||
set kw [string range $line 0 [expr [string first " " $line]-1]]
|
||||
set l [string range $line [expr [string first " " $line] +1] end]
|
||||
if {$l == "Separator"} {
|
||||
CreateSeparator $frame
|
||||
}
|
||||
if {$kw == "menu"} {
|
||||
if [regexp -- {(.*?) (\".*?\")} $l m img hint] {
|
||||
$menu_root add cascade -label $hint -menu $menu.m_$mnum -font $font(normal)
|
||||
set menu [menu $menu.m_$mnum]
|
||||
incr mnum
|
||||
}
|
||||
}
|
||||
if {$kw == "cmd"} {
|
||||
if [regexp -- {(\".*?\") (\".*?\") (\".*?\")} $l m cmd hint keys] {
|
||||
InsertCommand $menu $cmd $hint "" $keys
|
||||
} elseif [regexp -- {(\".*?\") (\".*?\")} $l m cmd hint] {
|
||||
InsertCommand $menu $cmd $hint "" ""
|
||||
}
|
||||
if [regexp -- {separator} $l m] {
|
||||
InsertSeparator $menu
|
||||
}
|
||||
}
|
||||
if {$kw == "imagecmd"} {
|
||||
if [regexp -- {(\".*?\") (\".*?\") (.*?)\.gif} $l m cmd hint im] {
|
||||
InsertCommand $menu $cmd $hint $im ""
|
||||
}
|
||||
if [regexp -- {(\".*?\") (\".*?\") (.*?)\.gif (\".*?\")} $l m cmd hint im keys] {
|
||||
InsertCommand $menu $cmd $hint $im $keys
|
||||
}
|
||||
}
|
||||
}
|
||||
close $fHandle
|
||||
|
||||
}
|
||||
|
1485
lib/modules/htmllib.tcl
Executable file
1485
lib/modules/htmllib.tcl
Executable file
File diff suppressed because it is too large
Load Diff
459
lib/modules/htmltable.tcl
Executable file
459
lib/modules/htmltable.tcl
Executable file
@@ -0,0 +1,459 @@
|
||||
set HMtable(unique) 0
|
||||
set HMtable(level) 0
|
||||
|
||||
;# RCSID: $Header: /home/clif.clif/CVS_ROOT/TclXexample/htmltable.tcl,v 1.6 1999/02/01 05:00:18 clif Exp $
|
||||
proc HMTBL_insert_FromMap { win text id } {
|
||||
global HMtag_map HMinsert_map HMlist_elements HMtable
|
||||
|
||||
upvar #0 HM$win var
|
||||
|
||||
# insert white space (with current font)
|
||||
# adding white space can get a bit tricky. This isn't quite right
|
||||
|
||||
set bad [catch {$win insert $var(S_insert) $HMinsert_map($id) "space $var(font)"}]
|
||||
|
||||
if {!$bad && [lindex $var(fill) end]} {
|
||||
set text [string trimleft $text]
|
||||
}
|
||||
|
||||
if {[info exists HMinsert_map($id)] && [string match $HMinsert_map($id) "\n"]} {
|
||||
$win insert $var(S_insert) "\t"
|
||||
for {set i 0} {$i < $HMtable(column)} {incr i} {
|
||||
$win insert $var(S_insert) "\t"
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
################################################################
|
||||
# proc HMtag_table {win param text}--
|
||||
# Process the <TABLE> tag - Called from html_library
|
||||
# Creates a new text widget to hold the table
|
||||
# Creates HM.WindowName state variables with default values
|
||||
# Sets HM.win(divert) to point to the new window so that
|
||||
# all text being processed is directed to the table text widget.
|
||||
#
|
||||
# Arguments
|
||||
# win The window that will hold everything
|
||||
# param Any parameters in the <TABLE ...> tag
|
||||
# text The name of a variable with associated text
|
||||
# Results
|
||||
#
|
||||
#
|
||||
proc HMtag_table {win param text} {
|
||||
global HMtable
|
||||
|
||||
upvar #0 HM$win var
|
||||
|
||||
# This tracks the level of tables being rendered -
|
||||
# When it returns to 0, we can reset the HM_insert_FromMap to the
|
||||
# original value.
|
||||
|
||||
if {$HMtable(level) == 0} {
|
||||
rename HMinsert_FromMap HM_ORIG_insert_FromMap
|
||||
rename HMTBL_insert_FromMap HMinsert_FromMap
|
||||
}
|
||||
incr HMtable(level)
|
||||
|
||||
# Define a unique name for the text widget
|
||||
# that will contain this table
|
||||
|
||||
set newTable .txt_$HMtable(unique)
|
||||
|
||||
# Divert output to the new window.
|
||||
|
||||
set var(divert) $newTable
|
||||
|
||||
# Make a new global state variable for the new text widget
|
||||
|
||||
upvar #0 HM$newTable newvar
|
||||
|
||||
# and initialize it
|
||||
|
||||
HMinit_state $newTable
|
||||
set newvar(family) times
|
||||
set newvar(size) 12
|
||||
set newvar(weight) normal
|
||||
set newvar(style) roman
|
||||
set newvar(indent) 0
|
||||
set newvar(stop) 0
|
||||
set newvar(S_insert) end
|
||||
set newvar(oldWindow) $win
|
||||
|
||||
# Create the new text widget
|
||||
update; update idle;
|
||||
# puts "PARENT: ($win) [expr [$win cget -width] -2]"
|
||||
# puts "PARENT: ($win) [expr [$win cget -insertwidth] -2]"
|
||||
# puts "PARENT: ($win) [winfo width $win] "
|
||||
# puts "GRID: [wm grid .]"
|
||||
set curFont [HMx_font times $newvar(size) medium r]
|
||||
# puts "curFont: $curFont"
|
||||
text $newTable -width [expr [$win cget -width] -2] -background white \
|
||||
-font $curFont -wrap none
|
||||
|
||||
# puts "TEXT GRID: [catch {wm grid $newTable} xx]"
|
||||
# puts "$xx"
|
||||
# puts "TEXT: ($newTable) [winfo width $newTable] "
|
||||
# Set the row and column descriptors.
|
||||
|
||||
set HMtable(row) 0
|
||||
set HMtable(column) 0
|
||||
set HMtable(maxCol) 0
|
||||
|
||||
# increment the unique number pointer so that the next table will
|
||||
# get a new text widget name.
|
||||
|
||||
incr HMtable(unique)
|
||||
}
|
||||
|
||||
|
||||
|
||||
################################################################
|
||||
# proc HMtag_/table {win param text}--
|
||||
# Process the </TABLE> tag
|
||||
# This procedure resets the window to receive text to the master
|
||||
# window.
|
||||
# Arguments
|
||||
#
|
||||
# table The window that holds the table
|
||||
# param Any parameters in the </TABLE ...> tag
|
||||
# text The name of a variable with associated text
|
||||
#
|
||||
# Results
|
||||
# Maps the new window into the master text window.
|
||||
# Sets tab locations in new window
|
||||
#
|
||||
proc HMtag_/table {table param text} {
|
||||
global HMtable errorInfo
|
||||
|
||||
# Set the var pointer for the table text widget
|
||||
upvar #0 HM$table varTbl
|
||||
|
||||
# This tracks the level of tables being rendered -
|
||||
# When it returns to 0, we can reset the HM_insert_FromMap to the
|
||||
# original value.
|
||||
|
||||
incr HMtable(level) -1
|
||||
if {$HMtable(level) == 0} {
|
||||
rename HMinsert_FromMap HMTBL_insert_FromMap
|
||||
rename HM_ORIG_insert_FromMap HMinsert_FromMap
|
||||
}
|
||||
incr HMtable(level)
|
||||
|
||||
|
||||
# Set the win and var variables to point to the master text widget,
|
||||
# instead of the table text widget.
|
||||
set win $varTbl(oldWindow)
|
||||
upvar #0 HM$win var
|
||||
|
||||
# unset var(divert) so that text will no longer be diverted to
|
||||
# the table window
|
||||
unset var(divert)
|
||||
|
||||
# Get the list of tags - to make the loop faster
|
||||
set alltags [$table tag names]
|
||||
|
||||
set maxFont 10;
|
||||
foreach tag $alltags {
|
||||
if {[string first "font:" $tag] == 0} {
|
||||
set fontlst [split $tag ":"]
|
||||
set size [lindex $fontlst 2]
|
||||
set family [lindex $fontlst 1]
|
||||
if {($size >= $maxFont) && ([string match $family "courier"])} {
|
||||
set maxFont $size
|
||||
set maxFamily $family
|
||||
set txtfont [list [lindex $fontlst 1] [lindex $fontlst 2] [lindex $fontlst 3]]
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
;# set f [catch {eval HMx_font $txtfont} rslt]
|
||||
;# puts "F: $f rslt: $rslt"
|
||||
;# puts "Plus scaling: [eval HMx_font $txtfont]"
|
||||
|
||||
set txtfont [eval HMx_font $txtfont];
|
||||
set maxFont [lindex $txtfont 1]
|
||||
|
||||
|
||||
# puts "txtfont: $txtfont maxFont: $maxFont xfont: $var(xfont) $varTbl(xfont)"
|
||||
# puts "[$table dump 1.0 20.0]"
|
||||
|
||||
# Reset the height of the table text widget to match the number of
|
||||
# rows actually used and insert it into the master text widget
|
||||
|
||||
set numrow [lindex [split [$table index end] .] 0]
|
||||
|
||||
$table configure -height [expr 1 + $numrow] -font $txtfont
|
||||
$win window create $var(S_insert) -window $table
|
||||
update; update idle;
|
||||
|
||||
# puts "[$table dump 0.0 end]"
|
||||
# puts "INDEX: [$table index end]"
|
||||
|
||||
set parentPixelWidth [winfo width $win]
|
||||
set tablePixelWidth [winfo width $table]
|
||||
|
||||
set tableCharWidth [$table cget -width]
|
||||
incr tableCharWidth -1
|
||||
|
||||
$table configure -width $tableCharWidth
|
||||
update; update idle;
|
||||
set tablePixelWidth2 [winfo width $table]
|
||||
|
||||
set charPixelWidth [expr $tablePixelWidth - $tablePixelWidth2]
|
||||
|
||||
# Now, I know the width of a char in this font window, calc
|
||||
# how many chars wide to match the parent
|
||||
|
||||
set newCharWidth [expr $parentPixelWidth/$charPixelWidth -2]
|
||||
$table configure -width $newCharWidth
|
||||
|
||||
# Make a simple little ruler for debugging help.
|
||||
# canvas .c932 -height 30 -width $tablePixelWidth -background yellow
|
||||
# for {set i 0} {$i < $tablePixelWidth} {incr i 50} {
|
||||
# if {($i % 100) == 50} {
|
||||
# .c932 create line $i 0 $i 15 -fill green
|
||||
# } else {
|
||||
# .c932 create line $i 0 $i 30 -fill blue
|
||||
# }
|
||||
# }
|
||||
# $table window create 2.0 -window .c932
|
||||
|
||||
# while {$tablePixelWidth > $parentPixelWidth} {
|
||||
# incr charWidth -1
|
||||
# # puts "$tablePixelWidth $parentPixelWidth $charWidth"
|
||||
# $table configure -width $charWidth
|
||||
# set tablePixelWidth [winfo width $table]
|
||||
# update; update idle;
|
||||
# }
|
||||
|
||||
|
||||
# Clear out the bogus newlines
|
||||
|
||||
# for {set i 0} {$i <= $HMtable(row)} {incr i} {
|
||||
# for {set j 0} {$j < $HMtable(maxCol)} {incr j} {
|
||||
#
|
||||
# # A cell may be blank. Check for a tag before proceeding
|
||||
#
|
||||
# if {[lsearch $alltags tbl.$i.$j] != -1} {
|
||||
# set range [$table tag ranges tbl.$i.$j]
|
||||
# # Delete the trailing \n that was added by html_lib.tcl.
|
||||
# $table delete "[lindex $range 0] lineend"
|
||||
# }
|
||||
# }
|
||||
# }
|
||||
|
||||
# Find the longest string in each column to set the column width.
|
||||
|
||||
# Initialize the sizes for the columns to 0
|
||||
|
||||
for {set j 0} {$j < $HMtable(maxCol)} {incr j} {
|
||||
set colSize($j) 0;
|
||||
}
|
||||
|
||||
|
||||
set curCol 0;
|
||||
|
||||
# Go through the dump of the text widget looking for text, and font
|
||||
# and table entry tags.
|
||||
# We track the current font and table cell so that when text comes in
|
||||
# we can calculate the size in the current font, and compare that to
|
||||
# the previous largest size.
|
||||
|
||||
foreach {id data index} [$table dump 0.0 end] {
|
||||
|
||||
switch $id {
|
||||
"tagon" {
|
||||
switch -glob -- $data {
|
||||
"font:*" {
|
||||
set lst [split $data ":"]
|
||||
set txtfont [list [lindex $lst 1] [lindex $lst 2] [lindex $lst 3]]
|
||||
set txtfont [eval HMx_font $txtfont];
|
||||
}
|
||||
"tbl.*" {
|
||||
set lst [split $data "."]
|
||||
set curCol [lindex $lst 2]
|
||||
}
|
||||
}
|
||||
}
|
||||
"text" {
|
||||
set line [string trim $data]
|
||||
# Adding a few extra chars seems to take care of
|
||||
# some slack where it appears that htmllib is
|
||||
# adding some unexpected spaces
|
||||
set line "--$line"
|
||||
set len [font measure $txtfont $line ]
|
||||
|
||||
if {$len > $colSize($curCol) } {
|
||||
set colSize($curCol) $len
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
# for {set j 0} {$j < $HMtable(maxCol)} {incr j} {
|
||||
# puts "$j: $colSize($j)"
|
||||
# }
|
||||
|
||||
|
||||
|
||||
# Define the tab stops to the maximum
|
||||
# size for each column.
|
||||
#
|
||||
# The pad value of 8 is to separate the columns
|
||||
#
|
||||
# If the toplevel window is gridded, divide the
|
||||
# tab position by the grid width
|
||||
#
|
||||
|
||||
set gridWidth [lindex [wm grid .] 2]
|
||||
|
||||
set gridWidth [lindex [wm grid .] 2]
|
||||
if {$gridWidth == ""} {set gridWidth 1}
|
||||
|
||||
set tabStops 0;
|
||||
set totl 0;
|
||||
|
||||
for {set i 0; set j 1} {$j < $HMtable(maxCol)} {incr j; incr i} {
|
||||
set wid [expr ($colSize($i) + 8)/$gridWidth]
|
||||
lappend tabStops [expr $wid + $totl]
|
||||
incr totl $wid
|
||||
}
|
||||
|
||||
# and set the tab stops.
|
||||
|
||||
$table configure -tabs $tabStops
|
||||
|
||||
# Wipe the first character - a bare (and useless) newline.
|
||||
|
||||
$table delete 1.0
|
||||
# foreach {o t th} [$table dump 0.0 end] { puts [format "%8s %7s .%-50s." $o $th $t]}
|
||||
# foreach {o t th} [$win dump 0.0 3.0] { puts "$o $t $th"}
|
||||
|
||||
}
|
||||
|
||||
################################################################
|
||||
# proc HMtag_tr {win param text}--
|
||||
# Process the <TR> tag
|
||||
# This begins a new row by setting the row and column values.
|
||||
# Arguments
|
||||
#
|
||||
# win The window that holds the table
|
||||
# param Any parameters in the </TR ...> tag
|
||||
# text The name of a variable with associated text
|
||||
#
|
||||
# Results
|
||||
# Increments the row position.
|
||||
# Sets the column to 0.
|
||||
#
|
||||
proc HMtag_tr {win param text} {
|
||||
global HMtable
|
||||
incr HMtable(row)
|
||||
set HMtable(column) 0
|
||||
}
|
||||
|
||||
|
||||
################################################################
|
||||
# proc HMtag_td {win param text}--
|
||||
# Process the <TD> tag
|
||||
# Arguments
|
||||
#
|
||||
# win The window that holds the table
|
||||
# param Any parameters in the <TD ...> tag
|
||||
# text The name of a variable with associated text
|
||||
#
|
||||
# Results
|
||||
# Sets a tag for the start of this table entry to be used to
|
||||
# set tab positions
|
||||
#
|
||||
proc HMtag_td {win param text} {
|
||||
global HMtable
|
||||
|
||||
upvar $text t
|
||||
set t "\t[string trim $t]"
|
||||
|
||||
upvar #0 HM$win var
|
||||
set var(Ttab) tbl.$HMtable(row).$HMtable(column)
|
||||
}
|
||||
|
||||
################################################################
|
||||
# proc HMtag_/td {win param text}--
|
||||
#
|
||||
# Arguments
|
||||
#
|
||||
# win The window that holds the table
|
||||
# param Any parameters in the </TD ...> tag
|
||||
# text The name of a variable with associated text
|
||||
#
|
||||
# Results
|
||||
# Increments the column position.
|
||||
# If there are more columns in this table row than in previous
|
||||
# rows, set the max column
|
||||
|
||||
proc HMtag_/td {win param text} {
|
||||
global HMtable
|
||||
|
||||
upvar $text t
|
||||
set t "[string trim $t]"
|
||||
|
||||
incr HMtable(column)
|
||||
if {$HMtable(column) > $HMtable(maxCol)} {
|
||||
set HMtable(maxCol) $HMtable(column)
|
||||
}
|
||||
}
|
||||
|
||||
################################################################
|
||||
# proc HMlink_callback {win href}--
|
||||
# This proc is called by the html_library code to parse a
|
||||
# hypertext reference.
|
||||
#
|
||||
# Arguments
|
||||
# win The text window that is used by the html_library to
|
||||
# display the text
|
||||
# href A hypertext reference to use for the next hypertext.
|
||||
#
|
||||
# Results
|
||||
# This example simply replaces the contents of the display with
|
||||
# hardcoded new text.
|
||||
|
||||
proc HMlink_callback {win href} {
|
||||
global newHTMLtxt
|
||||
|
||||
puts "HMlink_callback was invoked with WIN: $win HREF: $href"
|
||||
|
||||
# Clear the old contents from the window.
|
||||
|
||||
HMreset_win $win
|
||||
|
||||
# Display the new text.
|
||||
|
||||
HMparse_html $newHTMLtxt "HMrender $win"
|
||||
}
|
||||
|
||||
################################################################
|
||||
# proc HMset_image {win handle src}--
|
||||
# Acquire image data, create a Tcl image object,
|
||||
# and return the image handle.
|
||||
#
|
||||
# Arguments
|
||||
# win The text window in which the html is rendered.
|
||||
# handle A handle to return to the html library with the image handle
|
||||
# src The description of the image from: <IMG src=XX>
|
||||
#
|
||||
# Results
|
||||
# This example creates a hardcoded image. and then invokes
|
||||
# HMgot_image with the handle for that image.
|
||||
|
||||
proc HMset_image {win handle src} {
|
||||
global logo
|
||||
puts "HMset_image was invoked with WIN: $win HANDLE: $handle SRC: $src"
|
||||
|
||||
# In a real application this would parse the src, and load the
|
||||
# appropriate image data.
|
||||
|
||||
set img [image create photo -data $logo]
|
||||
|
||||
HMgot_image $handle $img
|
||||
|
||||
return ""
|
||||
}
|
||||
|
60
lib/modules/imgviewer.tcl
Executable file
60
lib/modules/imgviewer.tcl
Executable file
@@ -0,0 +1,60 @@
|
||||
package require Img
|
||||
|
||||
|
||||
proc ImageViewer {f w node} {
|
||||
global tab_label noteBook factor im1 im2
|
||||
set factor($node) 1.0
|
||||
frame $w.f
|
||||
pack $w.f -side left -fill both -expand true
|
||||
canvas $w.f.c -xscrollcommand "$w.f.x set" -yscrollcommand "$w.y set"
|
||||
scrollbar $w.f.x -ori hori -command "$w.f.c xview"
|
||||
scrollbar $w.y -ori vert -command "$w.f.c yview"
|
||||
|
||||
pack $w.f.c -side top -fill both -expand true
|
||||
pack $w.f.x -side top -fill x
|
||||
pack $w.y -side left -fill y
|
||||
bind $w.f.c <Button-4> "%W yview scroll -3 units"
|
||||
bind $w.f.c <Button-5> "%W yview scroll 3 units"
|
||||
bind $w.f.c <Shift-Button-4> "%W xview scroll -2 units"
|
||||
bind $w.f.c <Shift-Button-5> "%W xview scroll 2 units"
|
||||
bind $w.f.c <Control-Button-4> "scale $w.f.c 0.5 $node"
|
||||
bind $w.f.c <Control-Button-5> "scale $w.f.c 2 $node"
|
||||
#$w.scrwin setwidget $w.scrwin.f
|
||||
openImg $f $w.f.c $node
|
||||
set tab_label [$noteBook itemcget $node -text]
|
||||
balloon $w.f.c set "Mouse wheel up/down - verti<EFBFBD>al scrolling the image\n\
|
||||
Shift + mouse wheel up/down - horizontal image scrolling\n\
|
||||
Control + mouse wheel up/down is a scale image -/+"
|
||||
}
|
||||
|
||||
proc openImg {fn w node} {
|
||||
global im1
|
||||
set im1 [image create photo -file $fn]
|
||||
#scale $w
|
||||
list [file size $fn] bytes, [image width $im1]x[image height $im1]
|
||||
$w create image 1 1 -image $im1 -anchor nw -tag img
|
||||
}
|
||||
|
||||
proc scale {w {n 1} node} {
|
||||
global im1 im2 factor noteBook tab_label
|
||||
set factor($node) [expr {$factor($node) * $n}]
|
||||
$w delete img
|
||||
catch {image delete $im2}
|
||||
set im2 [image create photo]
|
||||
if {$factor($node)>=1} {
|
||||
set f [expr int($factor($node))]
|
||||
$im2 copy $im1 -zoom $f $f
|
||||
} else {
|
||||
set f [expr round(1./$factor($node))]
|
||||
$im2 copy $im1 -subsample $f $f
|
||||
}
|
||||
$w create image 1 1 -image $im2 -anchor nw -tag img
|
||||
$noteBook itemconfigure $node -text "$tab_label (size x$factor($node))"
|
||||
$w config -scrollregion [$w bbox all]
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
74
lib/modules/latex2html.tcl
Executable file
74
lib/modules/latex2html.tcl
Executable file
@@ -0,0 +1,74 @@
|
||||
######################################################
|
||||
# Tk LaTeX Editor
|
||||
# Distributed under GNU Public License
|
||||
# Author: Sergey Kalinin (BanZaj) banzaj@lrn.ru
|
||||
# Copyright (c) "CONERO lab", 2002, http://conero.lrn.ru
|
||||
######################################################
|
||||
|
||||
|
||||
proc Latex2Html {} {
|
||||
global tree module cmdString
|
||||
set selFiles [$tree selection get]
|
||||
if {[llength $selFiles] == 0} {
|
||||
set answer [tk_messageBox\
|
||||
-message "[::msgcat::mc "Don't selected file"]"\
|
||||
-type ok -icon warning\
|
||||
-title [::msgcat::mc "Warning"]]
|
||||
case $answer {
|
||||
ok {return 0}
|
||||
}
|
||||
}
|
||||
if {[llength $selFiles] == 1} {
|
||||
if {$selFiles != ""} {
|
||||
set file [$tree itemcget $selFiles -data]
|
||||
}
|
||||
CommandStringDialog $file
|
||||
}
|
||||
#puts $command
|
||||
}
|
||||
proc CommandStringDialog {file} {
|
||||
global nb files font color cmdString module
|
||||
set w .cmd
|
||||
# destroy the find window if it already exists
|
||||
if {[winfo exists $w]} {
|
||||
destroy $w
|
||||
}
|
||||
|
||||
toplevel $w
|
||||
wm title $w [::msgcat::mc "Command options"]
|
||||
wm resizable $w 0 0
|
||||
wm transient $w .
|
||||
frame $w.frmCombo -borderwidth 1 -background $color(bg)
|
||||
frame $w.frmBtn -borderwidth 1 -background $color(bg)
|
||||
pack $w.frmCombo $w.frmBtn -side top -fill x
|
||||
|
||||
# set combo [entry $w.frmCombo.entFind]
|
||||
label $w.frmCombo.lblModule -text $module(latex2html) -background $color(bg)
|
||||
set combo [entry $w.frmCombo.txtString]
|
||||
|
||||
pack $w.frmCombo.lblModule $combo -fill x -padx 2 -pady 2 -side top
|
||||
|
||||
button $w.frmBtn.btnFind -text [::msgcat::mc "Run"]\
|
||||
-font $font(normal) -width 12 -relief groove -background $color(bg)\
|
||||
-command {
|
||||
RunConverter [.cmd.frmCombo.txtString get]
|
||||
}
|
||||
button $w.frmBtn.btnCancel -text [::msgcat::mc "Close"]\
|
||||
-relief groove -width 12 -font $font(normal) -background $color(bg)\
|
||||
-command "destroy $w"
|
||||
pack $w.frmBtn.btnFind $w.frmBtn.btnCancel -fill x -padx 2 -pady 2 -side left
|
||||
|
||||
bind $w <Return> {RunConverter [.cmd.frmCombo.txtString get]}
|
||||
bind $w <Escape> "destroy $w"
|
||||
$combo insert end "-no_navigation -split 0 $file"
|
||||
focus -force $combo
|
||||
}
|
||||
|
||||
proc RunConverter {string} {
|
||||
global module
|
||||
destroy .cmd
|
||||
set pipe [open "|$module(latex2html) $string" "r"]
|
||||
fileevent $pipe readable [list EndProc latex2html $pipe]
|
||||
fconfigure $pipe -buffering none -blocking no
|
||||
}
|
||||
|
79
lib/modules/make.tcl
Executable file
79
lib/modules/make.tcl
Executable file
@@ -0,0 +1,79 @@
|
||||
#########################################################
|
||||
# TkTeXEditor
|
||||
# Distributed under GNU Public License
|
||||
# Author: Sergey Kalinin (BanZaj) banzaj@lrn.ru
|
||||
# Copyright (c) "CONERO lab", 2002, http://conero.lrn.ru
|
||||
#########################################################
|
||||
|
||||
## INSERT DEBUG INFORMATION INTO TEXT WIDGET ##
|
||||
proc DebugInfo {widget file folder} {
|
||||
global font nb w errLine activeFile
|
||||
set w $widget
|
||||
$widget configure -state normal
|
||||
if {[winfo depth $nb] > 1} {
|
||||
set bold "-background blue -foreground white -relief raised -borderwidth 1"
|
||||
set normal "-background {} -foreground blue -relief flat"
|
||||
} else {
|
||||
set bold "-foreground white -background black"
|
||||
set normal "-foreground {} -background {}"
|
||||
}
|
||||
|
||||
$widget tag configure error -font $font(bold) -foreground red
|
||||
$widget tag configure erName -font $font(bold) -foreground blue
|
||||
$widget tag bind erName <Any-Enter> "$widget tag configure erName $bold; $widget configure -cursor hand2"
|
||||
$widget tag bind erName <Any-Leave> "$widget tag configure erName $normal; $widget configure -cursor xterm"
|
||||
|
||||
if {[eof $file]} {
|
||||
catch {close $file} msg
|
||||
if {$msg != ""} {
|
||||
# puts $msg
|
||||
$widget insert end "[::msgcat::mc "Program failed"]: $msg\n";
|
||||
} else {
|
||||
# puts $msg
|
||||
$widget insert end "\n-----------------------------------------------\n"
|
||||
$widget insert end "[::msgcat::mc "Program finished successfully"]\n"
|
||||
TempFilesDel $folder
|
||||
}
|
||||
} else {
|
||||
set line [read $file]
|
||||
set index [string first "!" $line]
|
||||
$widget insert end $line
|
||||
set pos [$widget index insert]
|
||||
set lineNumber [lindex [split $pos "."] 0]
|
||||
if {$index != -1} {
|
||||
set p [$widget search -backward -- "!" $pos 0.0]
|
||||
set l [lindex [split $p "."] 0]
|
||||
set c [lindex [split $p "."] 1]
|
||||
|
||||
$widget tag add error $l.0 $l.end
|
||||
set errLine [expr $l + 1]
|
||||
$widget tag add erName $errLine.0 $errLine.end
|
||||
$widget tag bind erName <ButtonPress-1> {ErrorFind}
|
||||
}
|
||||
}
|
||||
$widget see end
|
||||
$widget configure -state disabled
|
||||
}
|
||||
|
||||
## FIND COMPILE ERROR INTO TEXT BUFFER ##
|
||||
proc ErrorFind {} {
|
||||
global font nb w errLine activeFile
|
||||
set word [$w get $errLine.0 $errLine.end]
|
||||
set error [string range $word 2 [string first " " $word]]
|
||||
set text "$nb.f$activeFile.f.text"
|
||||
focus -force $text
|
||||
$text mark set insert [string trim $error].0
|
||||
$text see insert
|
||||
}
|
||||
|
||||
|
||||
## DELETE TEMPORARY FILES ##
|
||||
proc TempFilesDel {folder} {
|
||||
foreach ext {log bak tmp} {
|
||||
foreach file [lsort [glob -nocomplain [file join $folder *.$ext]]] {
|
||||
file delete -- $file
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
144
lib/modules/module.tcl
Executable file
144
lib/modules/module.tcl
Executable file
@@ -0,0 +1,144 @@
|
||||
#########################################################
|
||||
# Tk LaTeX Editor
|
||||
# Distributed under GNU Public License
|
||||
# Author: Sergey Kalinin (BanZaj) banzaj@lrn.ru
|
||||
# Copyright (c) "CONERO lab", 2002, http://conero.lrn.ru
|
||||
#########################################################
|
||||
|
||||
proc FindModule {} {
|
||||
global module dir font tcl_platform color preview_cmd convert_cmd
|
||||
set menu [menu .frmMenu.mnuModule.m -background $color(bg)]
|
||||
set moduleName ""
|
||||
|
||||
foreach m {tkcvs tkdiff dvi ps pdf html} {
|
||||
if [info exists convert_cmd($m)] {
|
||||
scan $convert_cmd($m) "%s" moduleName
|
||||
FindExtMod_ convert_$m $moduleName
|
||||
}
|
||||
if [info exists preview_cmd($m)] {
|
||||
scan $preview_cmd($m) "%s" moduleName
|
||||
FindExtMod_ preview_$m $moduleName
|
||||
} else {
|
||||
FindExtMod $m $m
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
## Find external programms ##
|
||||
proc FindExtMod {m cmd} {
|
||||
global module dir font tcl_platform color preview_cmd convert_cmd
|
||||
if {$tcl_platform(platform) == "unix"} {
|
||||
set string [exec whereis $cmd]
|
||||
scan $string "%s%s" v module($m)
|
||||
if {[info exists module($m)] && [file isdirectory $module($m)] == 0} {
|
||||
puts "Find external programm $module($m)"
|
||||
.frmMenu.mnuModule.m add command -label [::msgcat::mc "$m"] -command "DoModule $m" \
|
||||
-font $font(normal)
|
||||
} else {
|
||||
set module($m) ""
|
||||
}
|
||||
} elseif {$tcl_platform(platform) == "mac"} {
|
||||
set module($m) $cmd
|
||||
} elseif {$tcl_platform(platform) == "windows"} {
|
||||
set module($m) $cmd
|
||||
}
|
||||
}
|
||||
proc FindExtMod_ {m cmd} {
|
||||
global module dir font tcl_platform color preview_cmd convert_cmd
|
||||
if {$tcl_platform(platform) == "unix"} {
|
||||
set string [exec whereis $cmd]
|
||||
scan $string "%s%s" v module($m)
|
||||
if {[info exists module($m)] && [file isdirectory $module($m)] == 0} {
|
||||
puts "Find external programm $module($m)"
|
||||
} else {
|
||||
set module($m) ""
|
||||
}
|
||||
} elseif {$tcl_platform(platform) == "mac"} {
|
||||
set module($m) $cmd
|
||||
} elseif {$tcl_platform(platform) == "windows"} {
|
||||
set module($m) $cmd
|
||||
}
|
||||
}
|
||||
|
||||
## RUNNING MODULE ##
|
||||
proc DoModule {mod} {
|
||||
global tcl_platform
|
||||
global module dir tree
|
||||
case $mod {
|
||||
tkcvs {
|
||||
set pipe [open "|$module(tkcvs) -dir $dir(doc)" "r"]
|
||||
fileevent $pipe readable
|
||||
fconfigure $pipe -buffering none -blocking no
|
||||
}
|
||||
tkdiff {
|
||||
set selFiles [$tree selection get]
|
||||
if {[llength $selFiles] == 0} {
|
||||
set answer [tk_messageBox\
|
||||
-message "[::msgcat::mc "Don't selected file"]"\
|
||||
-type ok -icon warning\
|
||||
-title [::msgcat::mc "Warning"]]
|
||||
case $answer {
|
||||
ok {return 0}
|
||||
}
|
||||
}
|
||||
if {[llength $selFiles] == 1} {
|
||||
if {$selFiles != ""} {
|
||||
set file1 [$tree itemcget $selFiles -data]
|
||||
}
|
||||
set command "-r $file1"
|
||||
}
|
||||
if {[llength $selFiles] == 2} {
|
||||
if {[lindex $selFiles 0] != ""} {
|
||||
set file1 [$tree itemcget [lindex $selFiles 0] -data]
|
||||
}
|
||||
if {[lindex $selFiles 1] != ""} {
|
||||
set file2 [$tree itemcget [lindex $selFiles 1] -data]
|
||||
}
|
||||
set command "$file1 $file2"
|
||||
}
|
||||
if {[llength $selFiles] > 2} {
|
||||
set answer [tk_messageBox\
|
||||
-message "[::msgcat::mc "Must be one or two file select!"]"\
|
||||
-type ok -icon info\
|
||||
-title [::msgcat::mc "Warning"]]
|
||||
case $answer {
|
||||
ok {return 0}
|
||||
}
|
||||
}
|
||||
set pipe [open "|$module(tkdiff) $command" "r"]
|
||||
fileevent $pipe readable
|
||||
fconfigure $pipe -buffering none -blocking no
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
proc EndProc {module file} {
|
||||
if {[eof $file]} {
|
||||
catch [close $file] msg
|
||||
if {$msg != ""} {
|
||||
puts $msg
|
||||
Message "$module\n [::msgcat::mc "Program failed"]: $msg\n";
|
||||
} else {
|
||||
Message "$module\n [::msgcat::mc "Program finished successfully"]\n"
|
||||
}
|
||||
} else {
|
||||
read $file
|
||||
}
|
||||
}
|
||||
|
||||
proc Message {message} {
|
||||
global font
|
||||
set answer [MessageDlg .msg -parent .\
|
||||
-message "$message"\
|
||||
-type ok -icon warning\
|
||||
-font $font(normal)\
|
||||
-title [::msgcat::mc "Warning"]]
|
||||
case $answer {
|
||||
ok {return 0}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
72
lib/modules/package.tcl
Executable file
72
lib/modules/package.tcl
Executable file
@@ -0,0 +1,72 @@
|
||||
######################################################
|
||||
# TkTeXEditor
|
||||
# Distributed under GNU Public License
|
||||
# Author: Sergey Kalinin (BanZaj) banzaj@lrn.ru
|
||||
# Copyright (c) "CONERO lab", 2002, http://conero.lrn.ru
|
||||
######################################################
|
||||
|
||||
proc GetPackage {_dir} {
|
||||
global nb dir cmd
|
||||
foreach file [lsort [glob -nocomplain [file join $_dir *.lst]]] {
|
||||
puts "Load commands from $file"
|
||||
set pkgName [file rootname [file tail $file]]
|
||||
set cmd($pkgName) ""
|
||||
#set cmd(all) ""
|
||||
set f [open $file r]
|
||||
while {[gets $f line] >= 0} {
|
||||
if {[string range $line 0 0] != "#"} {
|
||||
if [info exists cmd($pkgName)] {
|
||||
lappend cmd($pkgName) $line
|
||||
lappend cmd(all) $line
|
||||
} else {
|
||||
set cmd($pkgName) [list $line]
|
||||
set cmd(all) [list $line]
|
||||
}
|
||||
}
|
||||
}
|
||||
close $f
|
||||
}
|
||||
puts "<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> - [llength $cmd(all)]" ;# debug info
|
||||
}
|
||||
|
||||
proc PackageDialog {} {
|
||||
global nb font dir color
|
||||
set w .frmBody.packages
|
||||
# destroy the find window if it already exists
|
||||
if {[winfo exists $w]} {
|
||||
destroy $w
|
||||
}
|
||||
|
||||
toplevel $w
|
||||
wm title $w [::msgcat::mc "Pakages"]
|
||||
wm resizable $w 0 0
|
||||
#wm transient .
|
||||
|
||||
label $w.text -text [::msgcat::mc "Included packages"] -font $font(bold)\
|
||||
-relief groove -border 1
|
||||
frame $w.frmPkg -relief groove -border 1 -background $color(bg)
|
||||
frame $w.frmBtn -background $color(bg)
|
||||
pack $w.text -side top -anchor nw -fill x
|
||||
pack $w.frmPkg -side top -fill both -expand 1
|
||||
pack $w.frmBtn -side top -fill x
|
||||
|
||||
foreach pkg [GetPackage] {
|
||||
checkbutton $w.frmPkg.chk_$pkg -text $pkg -font $font(normal) -background $color(bg)
|
||||
pack $w.frmPkg.chk_$pkg -side top -anchor w -padx 2
|
||||
}
|
||||
|
||||
button $w.frmBtn.btnOk -text [::msgcat::mc "Save"] -relief groove -font $font(normal)\
|
||||
-command { } -background $color(bg)
|
||||
button $w.frmBtn.btnCancel -text [::msgcat::mc "Close"] -relief groove -font $font(normal)\
|
||||
-command "destroy $w" -background $color(bg)
|
||||
pack $w.frmBtn.btnOk $w.frmBtn.btnCancel -padx 2 -pady 2 -fill x -side left
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
112
lib/modules/pane.tcl
Executable file
112
lib/modules/pane.tcl
Executable file
@@ -0,0 +1,112 @@
|
||||
######################################################
|
||||
# TkTeXEditor
|
||||
# Distributed under GNU Public License
|
||||
# Author: Sergey Kalinin (BanZaj) banzaj@lrn.ru
|
||||
# Copyright (c) "CONERO lab", 2002, http://conero.lrn.ru
|
||||
######################################################
|
||||
|
||||
######################################################
|
||||
# Create split pane widget procedure #
|
||||
# Author Alex Dederer (aka Korwin) #
|
||||
######################################################
|
||||
|
||||
package provide pane 1.0
|
||||
|
||||
namespace eval pane {
|
||||
|
||||
namespace export create
|
||||
|
||||
proc create { f1 f2 args } {
|
||||
set t(-orient) vertical
|
||||
set t(-percent) 0.27
|
||||
set t(-gripcolor) gray75
|
||||
set t(-gripposition) 0.93
|
||||
set t(-gripcursor) crosshair
|
||||
set t(-in) [winfo parent $f1]
|
||||
array set t $args
|
||||
|
||||
set master $t(-in)
|
||||
upvar #0 [namespace current]::Pane$master pane
|
||||
array set pane [array get t]
|
||||
|
||||
if {! [string match v* $pane(-orient)] } {
|
||||
set pane(-gripcursor) sb_v_double_arrow
|
||||
set height 5 ; set width 3000
|
||||
} else {
|
||||
set pane(-gripcursor) sb_h_double_arrow
|
||||
set height 3000 ; set width 5
|
||||
}
|
||||
|
||||
set pane(1) $f1
|
||||
set pane(2) $f2
|
||||
set pane(grip) [frame $master.grip -background $pane(-gripcolor) \
|
||||
-width $width -height $height \
|
||||
-bd 1 -relief raised -cursor $pane(-gripcursor)]
|
||||
|
||||
if {! [string match v* $pane(-orient)] } {
|
||||
set pane(D) Y
|
||||
place $pane(1) -in $master -x 0 -rely 0.0 -anchor nw -relwidth 1.0 -height -1
|
||||
place $pane(2) -in $master -x 0 -rely 1.0 -anchor sw -relwidth 1.0 -height -1
|
||||
place $pane(grip) -in $master -anchor c -relx $pane(-gripposition)
|
||||
} else {
|
||||
set pane(D) X
|
||||
place $pane(1) -in $master -relx 0.0 -y 0 -anchor nw -relheight 1.0 -width -1
|
||||
place $pane(2) -in $master -relx 1.0 -y 0 -anchor ne -relheight 1.0 -width -1
|
||||
place $pane(grip) -in $master -anchor c -rely 0 ;#$pane(-gripposition)
|
||||
}
|
||||
$master configure -background gray50
|
||||
|
||||
bind $master <Configure> [list [namespace current]::PaneGeometry $master]
|
||||
bind $pane(grip) <ButtonPress-1> \
|
||||
[list [namespace current]::PaneDrag $master %$pane(D)]
|
||||
bind $pane(grip) <B1-Motion> \
|
||||
[list [namespace current]::PaneDrag $master %$pane(D)]
|
||||
bind $pane(grip) <ButtonRelease-1> \
|
||||
[list [namespace current]::PaneStop $master]
|
||||
|
||||
[namespace current]::PaneGeometry $master
|
||||
}
|
||||
|
||||
proc PaneDrag { master D } {
|
||||
upvar #0 [namespace current]::Pane$master pane
|
||||
if {[info exists pane(lastD)]} {
|
||||
set delta [expr double($pane(lastD) - $D) \
|
||||
/ $pane(size)]
|
||||
set pane(-percent) [expr $pane(-percent) - $delta]
|
||||
if {$pane(-percent) < 0.0} {
|
||||
set pane(-percent) 0.0
|
||||
} elseif {$pane(-percent) > 1.0} {
|
||||
set pane(-percent) 1.0
|
||||
}
|
||||
[namespace current]::PaneGeometry $master
|
||||
}
|
||||
set pane(lastD) $D
|
||||
}
|
||||
|
||||
proc PaneStop { master } {
|
||||
upvar #0 [namespace current]::Pane$master pane
|
||||
catch {unset pane(lastD)}
|
||||
}
|
||||
|
||||
proc PaneGeometry { master } {
|
||||
upvar #0 [namespace current]::Pane$master pane
|
||||
if {$pane(D) == "X"} {
|
||||
place $pane(1) -relwidth $pane(-percent)
|
||||
place $pane(2) -relwidth [expr 1.0 - $pane(-percent)]
|
||||
place $pane(grip) -relx $pane(-percent)
|
||||
set pane(size) [winfo width $master]
|
||||
} else {
|
||||
place $pane(1) -relheight $pane(-percent)
|
||||
place $pane(2) -relheight [expr 1.0 - $pane(-percent)]
|
||||
place $pane(grip) -rely $pane(-percent)
|
||||
set pane(size) [winfo height $master]
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
138
lib/modules/print.tcl
Executable file
138
lib/modules/print.tcl
Executable file
@@ -0,0 +1,138 @@
|
||||
######################################################
|
||||
# TkTeXEditor
|
||||
# Distributed under GNU Public License
|
||||
# Author: Sergey Kalinin (BanZaj) banzaj@lrn.ru
|
||||
# Copyright (c) "CONERO lab", 2002, http://conero.lrn.ru
|
||||
######################################################
|
||||
|
||||
proc PrintDialog {action} {
|
||||
global dir font nb files activeFile tcl_platform
|
||||
|
||||
if [info exists activeFile] {
|
||||
set node $activeFile
|
||||
} else {
|
||||
return
|
||||
}
|
||||
if {$node == "newproj" || $node == "settings" || $node == "about" || $node == ""} {
|
||||
return
|
||||
}
|
||||
if {[info exists files($node)] == 0} {
|
||||
return
|
||||
}
|
||||
switch -- $action {
|
||||
"print" {
|
||||
PrintForm
|
||||
}
|
||||
"set" {
|
||||
}
|
||||
"preview" {
|
||||
set text "$nb.f$node.f.text"
|
||||
set fullPath [lindex $files($node) 0]
|
||||
set folder [file dirname $fullPath]
|
||||
set file [file tail $fullPath]
|
||||
set ext [string trim [file extension $file] {.}]
|
||||
set name [file rootname $file]
|
||||
set file [file join $folder $name.ps]
|
||||
|
||||
if {$tcl_platform(platform) == "unix"} {
|
||||
set pipe [open "|gv $file" "r"]
|
||||
} elseif {$tcl_platform(platform) == "mac"} {
|
||||
|
||||
} elseif {$tcl_platform(platform) == "windows"} {
|
||||
set pipe [open "|gsview32 $file" "r"]
|
||||
}
|
||||
|
||||
fileevent $pipe readable
|
||||
fconfigure $pipe -buffering none -blocking no
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
proc PrintForm {} {
|
||||
global font selectPrint color
|
||||
set wp .print
|
||||
# destroy the print window if it already exists
|
||||
if {[winfo exists $wp]} {
|
||||
destroy $wp
|
||||
}
|
||||
|
||||
toplevel $wp
|
||||
wm transient $wp .
|
||||
wm title $wp [::msgcat::mc "Print ..."]
|
||||
wm resizable $wp 0 0
|
||||
frame $wp.frmLbl -background $color(bg)
|
||||
frame $wp.frmEnt -background $color(bg)
|
||||
frame $wp.frmField -background $color(bg)
|
||||
frame $wp.frmBtn -background $color(bg)
|
||||
pack $wp.frmLbl $wp.frmEnt $wp.frmField $wp.frmBtn -side top -fill x
|
||||
label $wp.frmLbl.lblPrint -text [::msgcat::mc "Print command"] -font $font(normal) -background $color(bg)
|
||||
pack $wp.frmLbl.lblPrint -fill x -expand true -padx 2
|
||||
entry $wp.frmEnt.entPrint -font $font(normal)
|
||||
pack $wp.frmEnt.entPrint -fill x -expand true -padx 2
|
||||
|
||||
checkbutton $wp.frmField.chkSelect -text [::msgcat::mc "Print selected text"] -variable selectPrint\
|
||||
-font $font(normal) -onvalue true -offvalue false\
|
||||
-background $color(bg) -selectcolor $color(selectbg);#-command Check
|
||||
pack $wp.frmField.chkSelect -fill x -expand true -padx 2 -anchor w
|
||||
|
||||
button $wp.frmBtn.btnPrint -text [::msgcat::mc "Print"] -font $font(normal) -width 12\
|
||||
-relief groove -background $color(bg)\
|
||||
-command {
|
||||
Print [.print.frmEnt.entPrint get]
|
||||
destroy .print
|
||||
}
|
||||
button $wp.frmBtn.btnCancel -text [::msgcat::mc "Cancel"] -font $font(normal) -width 12 -relief groove\
|
||||
-command "destroy .print" -background $color(bg)
|
||||
pack $wp.frmBtn.btnPrint $wp.frmBtn.btnCancel -side left -padx 2 -pady 2 -fill x -expand true
|
||||
$wp.frmEnt.entPrint insert 0 "lpr"
|
||||
bind $wp <Escape> "destroy .print"
|
||||
}
|
||||
|
||||
proc Preview {action} {
|
||||
global dir font nb files activeFile tcl_platform preview_cmd module tree
|
||||
if [info exists activeFile] {
|
||||
set node $activeFile
|
||||
while {[set parentNode [$tree parent $node]] != "root"} {
|
||||
set node $parentNode
|
||||
}
|
||||
} else {
|
||||
return
|
||||
}
|
||||
if {$node == "newproj" || $node == "settings" || $node == "about" || $node == ""} {
|
||||
return
|
||||
}
|
||||
if {[info exists files($node)] == 0} {
|
||||
return
|
||||
}
|
||||
if {$module(preview_$action) == ""} {
|
||||
set answer [tk_messageBox\
|
||||
-message "[::msgcat::mc "Don't find programm"] $preview_cmd($action)"\
|
||||
-type ok -icon warning\
|
||||
-title [::msgcat::mc "Warning"]]
|
||||
case $answer {
|
||||
ok {return 0}
|
||||
}
|
||||
}
|
||||
set text "$nb.f$node.f.text"
|
||||
set fullPath [lindex $files($node) 0]
|
||||
set file [file tail $fullPath]
|
||||
set ext [string trim [file extension $file] {.}]
|
||||
set name [file rootname $file]
|
||||
if {$action == "html"} {
|
||||
set folder [file join [file dirname $fullPath] $name]
|
||||
} else {
|
||||
set folder [file dirname $fullPath]
|
||||
}
|
||||
|
||||
set pipe [open "|$preview_cmd($action) [file join $folder $name.$action]" "r"]
|
||||
puts "$preview_cmd($action) [file join $folder $name.$action]"
|
||||
fileevent $pipe readable
|
||||
fconfigure $pipe -buffering none -blocking no
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
124
lib/modules/proc.tcl
Executable file
124
lib/modules/proc.tcl
Executable file
@@ -0,0 +1,124 @@
|
||||
######################################################
|
||||
# TkTeXEditor
|
||||
# Distributed under GNU Public License
|
||||
# Author: Sergey Kalinin (BanZaj) banzaj@lrn.ru
|
||||
# Copyright (c) "CONERO lab", 2002, http://conero.lrn.ru
|
||||
######################################################
|
||||
|
||||
######################################################
|
||||
# #
|
||||
# Notebook tabs procedures and other #
|
||||
# #
|
||||
######################################################
|
||||
|
||||
|
||||
## CLICKING TUBULAR HEADER PROCEDURE ##
|
||||
proc ClickTab {node} {
|
||||
global nb files activeFile tree ver files status release
|
||||
set node [$nb raise]
|
||||
if {($node == "") || ($node == "debug")} {return}
|
||||
set activeFile $node
|
||||
set text "$nb.f$node.f.text"
|
||||
set fullPath [lindex $files($node) 0]
|
||||
wm title . "TkLaTeXEditor $ver$release - $fullPath"
|
||||
set folder [file dirname $fullPath]
|
||||
set file [file tail $fullPath]
|
||||
set ext [string trim [file extension $file] {.}]
|
||||
set name [file rootname $file]
|
||||
$tree selection set $node
|
||||
$tree see $node
|
||||
UpdateStruct $fullPath $node
|
||||
focus -force $text
|
||||
unset text fullPath folder file ext name
|
||||
## status bar information update ##
|
||||
$status(fileAttr) configure -text "[FileAttr [lindex $files($node) 0]]"
|
||||
$status(fileSize) configure -text "[file size [lindex $files($node) 0]] b."
|
||||
$status(encode) configure -text "[lindex $files($node) 2]"
|
||||
$status(pos) configure -text [$nb.f$node.f.text index insert];# cursor position
|
||||
}
|
||||
|
||||
## NOTEBOOK PAGE SWITCHER ##
|
||||
proc PageTab {key} {
|
||||
global nb
|
||||
set len [llength [$nb pages]]
|
||||
if {$len > 0} {
|
||||
set newIndex [expr [$nb index [$nb raise]] + $key]
|
||||
if {$newIndex < 0} {
|
||||
set newIndex [expr $len - 1]
|
||||
} elseif {$newIndex >= $len} {
|
||||
set newIndex 0
|
||||
}
|
||||
$nb see [lindex [$nb pages] $newIndex]
|
||||
$nb raise [lindex [$nb pages] $newIndex]
|
||||
PageRaise [lindex [$nb pages] $newIndex]
|
||||
}
|
||||
}
|
||||
## RAISED NOTEBOOK TAB IF CLICK MOUSE BUTTON ##
|
||||
proc PageRaise {node} {
|
||||
global nb tree files status activeFile ver release
|
||||
set parentNode [$tree parent $node]
|
||||
if {$node == "debug"} {return}
|
||||
if {[$tree exists $node] ==1 && [info exists files($node)] != 1} {
|
||||
EditFile [$tree itemcget $node -data] ;# open editor if file don't open
|
||||
} elseif {[$tree exists $node] ==0} {
|
||||
set file [file tail [lindex $files($node) 0]]
|
||||
set fileDir [file dirname [lindex $files($node) 0]]
|
||||
set node [InsertTreeSubNode "$file" $parentNode $fileDir]
|
||||
}
|
||||
$nb raise $node
|
||||
|
||||
set activeFile $node
|
||||
#puts "node - $node\nparent - $parentNode"
|
||||
$tree selection set $node
|
||||
$tree see $node
|
||||
set item [$tree itemcget $node -data]
|
||||
focus -force $nb.f$node.f.text
|
||||
catch [$status(pos) configure -text [$nb.f$node.f.text index insert]] ;# cursor position
|
||||
## status bar information update ##
|
||||
$status(fileAttr) configure -text "[FileAttr $item]"
|
||||
$status(fileSize) configure -text "[file size $item] b."
|
||||
$status(encode) configure -text "[lindex $files($node) 2]"
|
||||
$status(pos) configure -text [$nb.f$node.f.text index insert];# cursor position
|
||||
UpdateStruct [lindex $files($node) 0] $node;# exec structure updating
|
||||
wm title . "TkLaTeXEditor $ver$release - [lindex $files($node) 0]"
|
||||
unset item
|
||||
}
|
||||
|
||||
|
||||
## CLOSE PROGRAMM PROCEDURE ##
|
||||
proc Quit {} {
|
||||
if {[FileDialog quit_close_all] == 0} {
|
||||
return
|
||||
} else {
|
||||
exit
|
||||
}
|
||||
}
|
||||
|
||||
## AUTOSAVE AND AUTOREFRESH TIMERS PROCEDURE ##
|
||||
set activeTimer(refresh) ""
|
||||
set activeTimer(autosave) ""
|
||||
proc Timer {file type} {
|
||||
global timers activeFile activeTimer
|
||||
if [info exists activeFile] {
|
||||
} else {
|
||||
return
|
||||
}
|
||||
if {$type == "refresh"} {
|
||||
after cancel $activeTimer(refresh) ;# close previouse task
|
||||
set activeTimer(refresh) [after $timers(refresh) {UpdateStruct $file $activeFile}]
|
||||
} elseif {$type == "autosave"} {
|
||||
after cancel $activeTimer(autosave) ;# close previouse task
|
||||
set activeTimer(autosave) [after $timers(autosave) {FileDialog save_all}]
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
proc GetExtention {file} {
|
||||
global fileList
|
||||
set ext [string range [file extension [file tail $file]] 1 end]
|
||||
return $ext
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
164
lib/modules/render.tcl
Executable file
164
lib/modules/render.tcl
Executable file
@@ -0,0 +1,164 @@
|
||||
#############################################################
|
||||
# TkTeXEditor
|
||||
# Distributed under GNU Public License
|
||||
# Author: Sergey Kalinin (BanZaj) banzaj@lrn.ru
|
||||
# Copyright (c) "CONERO lab", 2002, http://conero.lrn.ru
|
||||
#############################################################
|
||||
|
||||
#############################################################
|
||||
# Converts LaTeX formulas and texts to pixel graphics #
|
||||
# #
|
||||
# Required software: latex, convert (image magic) #
|
||||
# to get color, the latex color package is required #
|
||||
#############################################################
|
||||
# Idea By Alex Dederer (aka Korwin) #
|
||||
#############################################################
|
||||
|
||||
## SELECTED TEXT EXTRACT ##
|
||||
proc GenerateFormula {type} {
|
||||
global dir nb activeFile convert_cmd
|
||||
set text $nb.f$activeFile.f.text
|
||||
set pos [$text index insert]
|
||||
set curLine [lindex [split $pos "."] 0]
|
||||
set cursor [lindex [split $pos "."] 1]
|
||||
set selIndex [$text tag ranges sel]
|
||||
if {$selIndex != ""} {
|
||||
set posBegin [lindex $selIndex 0]
|
||||
set posEnd [lindex $selIndex 1]
|
||||
set formula [$text get $posBegin $posEnd]
|
||||
} else {
|
||||
return
|
||||
}
|
||||
#set cmdString "$convert_cmd(img) -o [file join $dir(tmp) formula.gif] $formula"
|
||||
#catch [exec $convert_cmd(img) -o [file join $dir(tmp) formula.gif] $formula] err
|
||||
#if {$err != ""} {puts $err}
|
||||
|
||||
Render "$formula" $type ""
|
||||
PreviewFormula
|
||||
}
|
||||
## PREVIEW CONVERTED IMAGE ##
|
||||
proc PreviewFormula {} {
|
||||
global nb font files color dir render
|
||||
set node [$nb raise]
|
||||
if {$node == "debug" || $node == ""} {
|
||||
return
|
||||
}
|
||||
set w .formula
|
||||
set text "$nb.f$node.f.text"
|
||||
set pos [$nb.f[$nb raise].f.text index insert]
|
||||
# set findString ""
|
||||
# destroy the find window if it already exists
|
||||
if {[winfo exists $w]} {
|
||||
destroy $w
|
||||
}
|
||||
# create the new "find" window
|
||||
toplevel $w
|
||||
wm transient $w $nb.f$node
|
||||
wm overrideredirect $w 1
|
||||
set b_x [winfo pointerx .]
|
||||
set b_y [expr [winfo pointery .] - 200]
|
||||
wm geometry $w +$b_x+$b_y
|
||||
|
||||
set f1 [frame $w.frmFind -background $color(bg)]
|
||||
pack $f1 -side top -fill x -expand true
|
||||
|
||||
image create photo formula -format gif -file [file join $dir(tmp) tle_render.gif]
|
||||
|
||||
label $f1.lblFind -background $color(bg) -image formula -relief ridge
|
||||
pack $f1.lblFind -side left -padx 0 -pady 0
|
||||
bind $w <Escape> "$text mark set insert $pos; $text see $pos; focus -force $text; destroy $w"
|
||||
bind $w <Button-1> "$text mark set insert $pos; $text see $pos; focus -force $text; destroy $w"
|
||||
focus -force $w
|
||||
|
||||
|
||||
unset text pos w
|
||||
}
|
||||
## DOCUMENT HEADER READER ##
|
||||
proc ReadHeader {widget} {
|
||||
set posBegin [$widget search -regexp -- {\\documentclass} 0.0 end]
|
||||
if {$posBegin != ""} {
|
||||
set posEnd [$widget search -regexp -- {\\begin\{document\}} $posBegin end]
|
||||
#puts "$posBegin - $posEnd"; return;# debug
|
||||
if {$posEnd != ""} {
|
||||
set text [$widget get $posBegin $posEnd]
|
||||
} else {
|
||||
set text ""
|
||||
}
|
||||
} else {
|
||||
set text ""
|
||||
}
|
||||
return $text
|
||||
}
|
||||
|
||||
## IMAGE GENERATOR WITH MATHEMATICS FORMALS AND TEXTS ##
|
||||
proc Render {text type fileName} {
|
||||
global dir convert_cmd render activeFile files nb
|
||||
# Names for input and output files
|
||||
set enc "[lindex $files($activeFile) 2]"
|
||||
|
||||
puts $files($activeFile) ;# debug
|
||||
|
||||
if {$fileName == ""} {
|
||||
set name tle_render
|
||||
set texFile $name.tex
|
||||
set imgFile $name.$render(format)
|
||||
set _dir $dir(tmp)
|
||||
} else {
|
||||
set imgFile [file tail $fileName]
|
||||
set name [file rootname $imgFile]
|
||||
set texFile $name.tex
|
||||
set _dir [file dirname $fileName]
|
||||
}
|
||||
set txt $nb.f$activeFile.f.text
|
||||
set header [ReadHeader $txt]
|
||||
if {$header == ""} {
|
||||
set header "\\documentclass\[12pt\]\{article\}\n\\usepackage\[$enc\]\{inputenc\}\n\\usepackage\[english,russian\]\{babel\}"
|
||||
|
||||
}
|
||||
if {$type == "math"} {
|
||||
append header "\\usepackage\{color\}\n\\pagestyle\{empty\}\n\\pagecolor\{$render(bg)\}\n"
|
||||
append header "\\begin\{document\}\n\\begin\{eqnarray\*\}\n\{\n\\color\{$render(fg)\}"
|
||||
set footer "\}\n\\end\{eqnarray*\}\n\\end\{document\}"
|
||||
} elseif {$type == "text"} {
|
||||
append header "\\usepackage\{color\}\n\n\\pagestyle\{empty\}\n"
|
||||
append header "\\pagecolor\{$render(bg)\}\n\\begin\{document\}\n"
|
||||
set footer "\\end\{document\}"
|
||||
}
|
||||
puts $header
|
||||
set f [open [file join $dir(tmp) $texFile] w]
|
||||
puts $f $header
|
||||
puts $f $text
|
||||
puts $f $footer
|
||||
close $f
|
||||
|
||||
set err ""
|
||||
catch [cd $dir(tmp)]
|
||||
catch [exec $convert_cmd(dvi) -interaction=batchmode [file join $dir(tmp) $texFile]] err
|
||||
catch [exec dvips -o $dir(tmp)/$name.eps -E $dir(tmp)/$name.dvi 2> /dev/null] err
|
||||
# Transparent background
|
||||
if {$render(trans) == 1} {
|
||||
if {$render(aa) == 1} {
|
||||
catch [exec $convert_cmd(img) +adjoin -antialias -transparent $render(bg) -density $render(res) $dir(tmp)/$name.eps $_dir/$imgFile] err
|
||||
} else {
|
||||
catch [exec $convert_cmd(img) +adjoin +antialias -transparent $render(bg) -density $render(res) $dir(tmp)/name.eps $_dir/$imgFile] err
|
||||
}
|
||||
} else {
|
||||
if {$render(aa) == 1} {
|
||||
catch [exec $convert_cmd(img) +adjoin -antialias -density $render(res) $dir(tmp)/$name.eps $_dir/$imgFile] err
|
||||
} else {
|
||||
catch [exec $convert_cmd(img) +adjoin +antialias -density $render(res) $dir(tmp)/$name.eps $_dir/$imgFile] err
|
||||
}
|
||||
}
|
||||
if {$err != ""} {
|
||||
set answer [tk_messageBox -message "$err"\
|
||||
-type ok -icon warning -title [::msgcat::mc "Warning"]]
|
||||
case $answer {
|
||||
ok {return}
|
||||
}
|
||||
puts $err
|
||||
}
|
||||
catch [cd $dir(current)]
|
||||
}
|
||||
|
||||
|
||||
|
216
lib/modules/spellcheck.tcl
Executable file
216
lib/modules/spellcheck.tcl
Executable file
@@ -0,0 +1,216 @@
|
||||
#########################################################
|
||||
# Tk LaTeX Editor
|
||||
# Distributed under GNU Public License
|
||||
# Author: Sergey Kalinin (BanZaj) banzaj@lrn.ru
|
||||
# Copyright (c) "CONERO lab", 2002, http://conero.lrn.ru
|
||||
#########################################################
|
||||
# Spell Checking procedure
|
||||
# required Ispell, Msgcat
|
||||
# Author: Victor Wagner (Vitus) http://www.ice.ru/~vitus
|
||||
#
|
||||
# Usage: "SpellCheck text_widget"
|
||||
#########################################################
|
||||
|
||||
|
||||
proc SpellCheck {text} {
|
||||
global ispell_lib ispell_language ispell_startindex nb color font
|
||||
set node [$nb raise]
|
||||
if {[winfo exists .spell]} {
|
||||
return
|
||||
}
|
||||
|
||||
if {$node == "newproj" || $node == "settings" || $node == "about" || $node == ""} {
|
||||
return
|
||||
}
|
||||
# Build dictionary list
|
||||
foreach dict [glob [file join $ispell_lib *.hash]] {
|
||||
file stat $dict foo
|
||||
set lang [file rootname [file tail $dict]]
|
||||
if {$lang == "default"} {
|
||||
set default_inode $foo(ino)
|
||||
} else {
|
||||
lappend langs $lang
|
||||
set lang_nodes($foo(ino)) $lang;
|
||||
}
|
||||
}
|
||||
if {![info exists ispell_language]} {
|
||||
if {[info exists default_inode ]&&[info exists lang_nodes($default_inode)]} {
|
||||
set ispell_language $lang_nodes($default_inode)
|
||||
} else {
|
||||
set ispell_language [lindex $langs 0]
|
||||
}
|
||||
}
|
||||
toplevel .spell -class Notepad
|
||||
wm title .spell [::msgcat::mc "Spell check"]
|
||||
wm transient .spell .
|
||||
wm resizable .spell 0 0
|
||||
|
||||
frame .spell.lang -relief raised -borderwidth 1 -background $color(bg)
|
||||
label .spell.lang.l -text [::msgcat::mc "Language"] -background $color(bg) -font $font(normal)
|
||||
eval tk_optionMenu .spell.lang.m ispell_language $langs -background $color(bg) -font $font(normal)
|
||||
pack .spell.lang.l .spell.lang.m -side left -padx 5
|
||||
pack .spell.lang.m -side left -padx 5 -fill x -expand 1
|
||||
frame .spell.start -relief raised -borderwidth 1 -background $color(bg)
|
||||
radiobutton .spell.start.all -text [::msgcat::mc "Entire file"] -background $color(bg)\
|
||||
-variable ispell_startindex -value "1.0" -anchor w -font $font(normal)
|
||||
radiobutton .spell.start.ins -text [::msgcat::mc "From cursor"] -background $color(bg)\
|
||||
-variable ispell_startindex -value insert -anchor w -font $font(normal)
|
||||
pack .spell.start.all .spell.start.ins -side top -pady 1 -expand y -fill x
|
||||
frame .spell.b -relief raised -borderwidth 1 -background $color(bg)
|
||||
button .spell.b.ok -text [::msgcat::mc "Start"] -relief groove -background $color(bg)\
|
||||
-command "DoSpellCheck $text" -font $font(normal)
|
||||
button .spell.b.cancel -text [::msgcat::mc "Cancel"] -relief groove -background $color(bg)\
|
||||
-command "destroy .spell" -font $font(normal)
|
||||
pack .spell.b.ok .spell.b.cancel -side left -padx 10
|
||||
pack .spell.lang -side top -fill x
|
||||
pack .spell.start -side top -fill both -expand 1
|
||||
pack .spell.b -side top -fill x
|
||||
bind .spell <Escape> "destroy .spell"
|
||||
}
|
||||
|
||||
proc DoSpellCheck {text} {
|
||||
global ispell_file ispell_startindex ispell_language spellAddWords color font
|
||||
eval destroy [winfo children .spell]
|
||||
wm transient .spell .
|
||||
entry .spell.word -exportselection false
|
||||
listbox .spell.misses -yscrollcommand ".spell.y set" -exportselection false -background $color(bg)
|
||||
scrollbar .spell.y -command ".spell.misses yview" -background $color(bg)
|
||||
button .spell.ok -text [::msgcat::mc "Accept"] -command "SpellOk $text" -background $color(bg) \
|
||||
-font $font(normal)
|
||||
button .spell.accept -text [::msgcat::mc "Next"] -command "SpellAccept @" -background $color(bg) \
|
||||
-font $font(normal)
|
||||
button .spell.adddict -text [::msgcat::mc "Add to dict"] -command "SpellAccept *" -background $color(bg) \
|
||||
-font $font(normal)
|
||||
button .spell.adddict2 -text [::msgcat::mc "Add lowercase"] -command "SpellAccept &" -background $color(bg) \
|
||||
-font $font(normal)
|
||||
button .spell.stop -text [::msgcat::mc "Stop checking"] -command "SpellStop $text" -background $color(bg) \
|
||||
-font $font(normal)
|
||||
grid .spell.word - - -sticky news -padx 5 -pady 5
|
||||
grid .spell.misses .spell.y .spell.ok -sticky news
|
||||
grid x x .spell.accept -sticky news
|
||||
grid x x .spell.adddict -sticky news
|
||||
grid x x .spell.adddict2 -sticky news
|
||||
grid x x .spell.stop -sticky news
|
||||
grid configure .spell.ok .spell.accept .spell.adddict .spell.adddict2 .spell.stop -padx 5 -pady 3
|
||||
grid configure .spell.misses .spell.y -rowspan 5
|
||||
focus .spell.word
|
||||
wm protocol .spell WM_DELETE_WINDOW "SpellStop $text"
|
||||
|
||||
set ispell_file [open "|ispell -a -d $ispell_language" w+]
|
||||
fconfigure $ispell_file -buffering none -blocking yes
|
||||
gets $ispell_file
|
||||
puts $ispell_file "!"
|
||||
set spellAddWords {}
|
||||
|
||||
$text mark set insert $ispell_startindex
|
||||
while {[SpellNextLine $text]} {
|
||||
while {[gets $ispell_file responce]>0} {
|
||||
switch -exact -- [string range $responce 0 0] {
|
||||
"*" -
|
||||
"+" -
|
||||
"-" {continue}
|
||||
"&" -
|
||||
"?" {regexp {^. +([^ ]+) +[0-9]+ +([0-9]+):(.*)$} $responce foo \
|
||||
orig offset guesses
|
||||
SpellInteract $orig $offset $guesses $text
|
||||
}
|
||||
"#" {regexp {^. +([^ ]+) +([0-9]+)} $responce foo orig offset
|
||||
SpellInteract $orig $offset {} $text
|
||||
}
|
||||
}
|
||||
}
|
||||
$text mark set insert "spellstart linestart + 1 lines"
|
||||
}
|
||||
close $ispell_file
|
||||
eval destroy [winfo children .spell]
|
||||
label .spell.l -text [::msgcat::mc "Checking complete"] -background $color(bg)
|
||||
button .spell.ok -text [::msgcat::mc "Ok"] -command {destroy .spell} -background $color(bg)
|
||||
wm protocol .spell WM_DELETE_WINDOW {destroy .spell}
|
||||
pack .spell.l .spell.ok -side top -padx 5 -pady 10
|
||||
}
|
||||
|
||||
|
||||
proc SpellNextLine {text} {
|
||||
global spellOffset ispell_file spellAddWords
|
||||
set spellOffset -1
|
||||
$text see insert
|
||||
$text mark set spellstart insert
|
||||
set line [$text get insert "insert lineend"]
|
||||
if [$text compare insert >= "end-1char"] {
|
||||
return 0
|
||||
}
|
||||
foreach word $spellAddWords {
|
||||
puts "Adding to dictionary $word"
|
||||
puts $ispell_file $word
|
||||
}
|
||||
set spellAddWords {}
|
||||
puts $ispell_file "^$line"
|
||||
return 1
|
||||
}
|
||||
|
||||
proc SpellInteract {word offset guesses text} {
|
||||
.spell.word delete 0 end
|
||||
.spell.word insert 0 $word
|
||||
$text tag remove sel 0.0 end
|
||||
global spellOffset
|
||||
incr offset $spellOffset
|
||||
$text tag add sel "spellstart+$offset chars" "spellstart+[expr $offset+\
|
||||
[string length $word]] chars"
|
||||
global spellHighlight
|
||||
set spellHighlight [$text tag ranges sel]
|
||||
$text see sel.first
|
||||
$text mark set insert sel.first
|
||||
.spell.misses delete 0 end
|
||||
if [string length $guesses] {
|
||||
foreach miss [split $guesses ","] {
|
||||
.spell.misses insert end [string trim $miss]
|
||||
}
|
||||
}
|
||||
global spellInteractResult
|
||||
vwait spellInteractResult
|
||||
return -code $spellInteractResult
|
||||
}
|
||||
|
||||
proc SpellOk {text} {
|
||||
# <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> .spell.word <20><><EFBFBD> .spell.misses
|
||||
global spellInteractResult spellHighlight
|
||||
if [llength [.spell.misses curselection]] {
|
||||
set word [.spell.misses get [.spell.misses curselection]]
|
||||
} else {
|
||||
set word [.spell.word get]
|
||||
}
|
||||
if {![llength [$text tag ranges sel]]} {
|
||||
global spellHighilight
|
||||
eval $text tag add sel $spellHighlight
|
||||
}
|
||||
set oldword [$text get sel.first sel.last]
|
||||
if {[string compare $oldword $word]} {
|
||||
$text delete sel.first sel.last
|
||||
$text insert insert $word sel
|
||||
global changed spellOffset
|
||||
set changed 1
|
||||
incr spellOffset [expr [string length $word]-[string length $oldword]]
|
||||
}
|
||||
set spellInteractResult ok
|
||||
}
|
||||
|
||||
proc SpellAccept {cmd} {
|
||||
global spellAddWords spellInteractResult
|
||||
lappend spellAddWords "$cmd[.spell.word get]"
|
||||
set spellInteractResult ok
|
||||
}
|
||||
|
||||
proc SpellStop {text} {
|
||||
global ispell_file
|
||||
$text mark unset spellstart
|
||||
catch {close $ispell_file}
|
||||
destroy .spell
|
||||
set spellInteractResult return
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
59
lib/modules/splashscreen.tcl
Executable file
59
lib/modules/splashscreen.tcl
Executable file
@@ -0,0 +1,59 @@
|
||||
######################################################
|
||||
# Tk LaTeX Editor
|
||||
# Distributed under GNU Public License
|
||||
# Author: Sergey Kalinin (aka BanZaj) banzaj@lrn.ru
|
||||
# Copyright (c) "CONERO lab", 2004, http://conero.lrn.ru
|
||||
######################################################
|
||||
|
||||
proc ShowSplashScreen {} {
|
||||
global font
|
||||
global dir tree nb ver font release
|
||||
set max 200
|
||||
set w .about
|
||||
if {[winfo exists $w]} {
|
||||
destroy $w
|
||||
}
|
||||
toplevel $w
|
||||
wm title $w [::msgcat::mc "Strting Tk LaTeX Editor ..."]
|
||||
#wm resizable $w 0 0
|
||||
wm transient $w .
|
||||
|
||||
frame $w.frmImg -borderwidth 2 -relief ridge -background black
|
||||
image create photo imgAbout -format gif -file [file join $dir(img) tle.gif]
|
||||
image create photo imgConero -format gif -file [file join $dir(img) conero.gif]
|
||||
|
||||
label $w.frmImg.lblImg -image imgAbout -background black
|
||||
|
||||
pack $w.frmImg.lblImg -side top -fill x
|
||||
|
||||
frame $w.frmlbl -borderwidth 2 -relief ridge -background "#8700d1"
|
||||
label $w.frmlbl.lblVersion -text "[::msgcat::mc Version] $ver$release"\
|
||||
-background "#8700d1" -foreground black
|
||||
label $w.frmlbl.lblAuthorName -text "[::msgcat::mc Authors]:"\
|
||||
-background "#8700d1" -foreground black
|
||||
label $w.frmlbl.lblAuthor1 -text "Sergey Kalinin (aka BanZaj), banzaj@lrn.ru"\
|
||||
-background "#8700d1" -foreground black
|
||||
label $w.frmlbl.lblAuthor2 -text "Constantin I Makhailenko (aka Const), const@mail.ru"\
|
||||
-background "#8700d1" -foreground black
|
||||
|
||||
|
||||
frame $w.frame
|
||||
|
||||
|
||||
ProgressBar $w.frame.bar \
|
||||
-variable splash_count -width 100 -height 10 -maximum $max
|
||||
label $w.frame.info -textvariable info
|
||||
|
||||
pack $w.frmlbl.lblVersion $w.frmlbl.lblAuthorName $w.frmlbl.lblAuthor1 $w.frmlbl.lblAuthor2 -side top -padx 5
|
||||
pack $w.frmImg -side top -fill x
|
||||
pack $w.frmlbl -side top -expand true -fill both
|
||||
|
||||
pack $w.frame.bar $w.frame.info -side top -expand true -fill x
|
||||
|
||||
bind $w <Escape> "destroy .about"
|
||||
bind $w <Return> "destroy .about"
|
||||
#
|
||||
}
|
||||
|
||||
#ShowSplashScreen
|
||||
|
291
lib/modules/struct.tcl
Executable file
291
lib/modules/struct.tcl
Executable file
@@ -0,0 +1,291 @@
|
||||
######################################################
|
||||
# TkTeXEditor
|
||||
# Distributed under GNU Public License
|
||||
# Author: Sergey Kalinin (BanZaj) banzaj@lrn.ru
|
||||
# Copyright (c) "CONERO lab", 2002, http://conero.lrn.ru
|
||||
######################################################
|
||||
|
||||
######################################################
|
||||
# #
|
||||
# Document structure module (insert\update\deleted #
|
||||
# #
|
||||
######################################################
|
||||
|
||||
set in(c) 0 ;# chapter counter
|
||||
set in(p) 0 ;# part counter
|
||||
set in(s) 0 ;# section counter
|
||||
set in(ss) 0 ;# subsection counter
|
||||
set in(sss) 0 ;# subsubsection counter
|
||||
set in(par) 0 ;# paragraph cponter
|
||||
set in(spar) 0 ;# subparagraph cponter
|
||||
set in(lbl) 0 ;# label cuonter
|
||||
set in(ref) 0 ;# ref counter
|
||||
set in(pageref) 0 ;# ref counter
|
||||
set in(include) 0
|
||||
set in(input) 0
|
||||
set in(cite) 0
|
||||
set in(bibitem) 0
|
||||
set in(image) 0
|
||||
set lastPart "root"
|
||||
set lastChapter "root"
|
||||
set lastSection "root"
|
||||
set lastSSection "root"
|
||||
set lastSSSection "root"
|
||||
set lastPar "root"
|
||||
set lastSubPar "root"
|
||||
|
||||
## INSERT STRUCT PROCEDURE ##
|
||||
## reading and parsing string from surce file
|
||||
## and execute procedures for inserted required structure into structure tree
|
||||
proc InsertStruct {node line lineNumber fileDir } {
|
||||
global tree treeStruct dir font color in lastNode activeFile
|
||||
global lastPart lastChapter lastSection lastSSection lastSSSection
|
||||
global lastPar lastSubPar lastLabel files nb thumbnail thumb
|
||||
#puts $fileDir
|
||||
if [regexp -nocase -all -- {(\\part)(\*|)(\[.*?\])*(\{.*?\})} $line struct v1 v1_5 v2 v3] {
|
||||
incr in(p)
|
||||
InsertNode "part_$in(p)" "root" "[string trimleft [string trimright $v1_5$v3 "\}"] "\{"]" part $lineNumber
|
||||
set lastPart "part_$in(p)"
|
||||
}
|
||||
if [regexp -nocase -all -- {(\\chapter)(\*|)(\[.*?\])*(\{.*?\})} $line struct v1 v1_5 v2 v3] {
|
||||
incr in(c)
|
||||
InsertNode "chapter_$in(c)" "$lastPart" "[string trimleft [string trimright $v1_5$v3 "\}"] "\{"]" chapter $lineNumber
|
||||
set lastChapter chapter_$in(c)
|
||||
}
|
||||
if [regexp -nocase -all -- {(\\section)(\*|)(\[.*?\])*(\{.*?\})} $line struct v1 v1_5 v2 v3] {
|
||||
incr in(s)
|
||||
InsertNode "section_$in(s)" "$lastChapter" "[string trimleft [string trimright $v1_5$v3 "\}"] "\{"]" section $lineNumber
|
||||
set lastSection "section_$in(s)"
|
||||
}
|
||||
if [regexp -nocase -all -- {(\\subsection)(\*|)(\[.*?\])*(\{.*?\})} $line struct v1 v1_5 v2 v3] {
|
||||
incr in(ss)
|
||||
InsertNode "subsection_$in(ss)" "$lastSection" "[string trimleft [string trimright $v1_5$v3 "\}"] "\{"]" ssection $lineNumber
|
||||
set lastSSection "subsection_$in(ss)"
|
||||
}
|
||||
if [regexp -nocase -all -- {(\\subsubsection)(\*|)(\[.*?\])*(\{.*?\})} $line struct v1 v1_5 v2 v3] {
|
||||
incr in(sss)
|
||||
InsertNode "subsubsection_$in(sss)" "$lastSSection" "[string trimleft [string trimright $v1_5$v3 "\}"] "\{"]" sssection $lineNumber
|
||||
set lastSSSection "subsubsection_$in(sss)"
|
||||
}
|
||||
if [regexp -nocase -all -- {(\\paragraph)(\*|)(\[.*?\])*(\{.*?\})} $line struct v1 v1_5 v2 v3] {
|
||||
incr in(par)
|
||||
InsertNode "paragraph_$in(par)" "$lastSSSection" "[string trimleft [string trimright $v1_5$v3 "\}"] "\{"]" paragraph $lineNumber
|
||||
set lastPar "paragraph_$in(par)"
|
||||
}
|
||||
if [regexp -nocase -all -- {(\\subparagraph)(\*|)(\[.*?\])*(\{.*?\})} $line struct v1 v1_5 v2 v3] {
|
||||
incr in(spar)
|
||||
InsertNode "subparagraph_$in(spar)" "$lastPar" "[string trimleft [string trimright $v1_5$v3 "\}"] "\{"]" subparagraph $lineNumber
|
||||
set lastSubPar "subparagraph_$in(spar)"
|
||||
}
|
||||
if [regexp -nocase -all -- {(\\label)(\{.*?\})} $line struct v1 v2] {
|
||||
incr in(lbl)
|
||||
InsertLabel "label_$in(lbl)" "$v2" "label"
|
||||
}
|
||||
if [regexp -nocase -all -- {(\\ref)(\{.*?\})} $line struct v1 v2] {
|
||||
incr in(ref)
|
||||
InsertRef "ref_$in(ref)" "$v2"
|
||||
}
|
||||
if [regexp -nocase -all -- {(\\pageref)(\{.*?\})} $line struct v1 v2] {
|
||||
incr in(pageref)
|
||||
InsertPageref "pageref_$in(pageref)" "$v2"
|
||||
}
|
||||
if [regexp -nocase -all -- {(\\cite)(\{.*?\})} $line struct v1 v2] {
|
||||
incr in(cite)
|
||||
InsertLabel "cite_$in(cite)" "$v2" "cite"
|
||||
}
|
||||
if [regexp -nocase -all -- {(\\bibitem)(\{.*?\})} $line struct v1 v2] {
|
||||
incr in(bibitem)
|
||||
InsertLabel "bibitem_$in(bibitem)" "$v2" "bibitem"
|
||||
}
|
||||
|
||||
if { [regexp -nocase -all -- {(\\input)(\{.*?\})} $line struct v1 v2] || [regexp -nocase -all -- {(\\include)(\{.*?\})} $line struct v1 v2] } {
|
||||
incr in(input)
|
||||
set fullPath [string trimleft [string trimright $v2 "\}"] "\{"]
|
||||
set dirName [file dirname $fullPath]
|
||||
# <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
||||
if [info exists activeFile] {
|
||||
#puts $activeFile
|
||||
# set nod $activeFile
|
||||
#while {[set parentNode [$tree parent $nod]] != "root"} {set nod $parentNode}
|
||||
} else {
|
||||
#return
|
||||
}
|
||||
set rootPath [file dirname [$tree itemcget $node -data]]
|
||||
|
||||
set file [file tail $fullPath]
|
||||
|
||||
if {$dirName != "."} {
|
||||
set dirName [string range $dirName [expr [string first "/" $dirName]+1] end]
|
||||
set fileDir [file join $rootPath $dirName]
|
||||
} else {
|
||||
set fileDir $rootPath
|
||||
}
|
||||
puts "fullPath - $fullPath\nrootPath - $rootPath\n dirName-$dirName\nfile=$file\nfilrDir-$fileDir"
|
||||
set subNode [InsertTreeSubNode "$file" "$activeFile" $fileDir]
|
||||
#puts "InsertStruct: node - $subNode\tparent - $node"
|
||||
#return
|
||||
if [info exists files($subNode)] {
|
||||
#puts "$subNode"
|
||||
#puts "<22><><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD> [lindex $files($subNode) 0]"
|
||||
InsertTreeSubNode $file $node $dirName
|
||||
UpdateStruct [lindex $files($subNode) 0] $subNode
|
||||
}
|
||||
set ext [file extension $file]
|
||||
if {$ext == ""} {
|
||||
set ext "tex"
|
||||
}
|
||||
if {[file exists [file join $fileDir $file.$ext]] == 0} {
|
||||
$tree itemconfigure $subNode -image [Bitmap::get [file join $dir(img) error.gif]]
|
||||
}
|
||||
}
|
||||
if {[regexp -nocase -all -- {(\\includegraphics)(\{.*?\})} $line struct v1 v2] ==1 || \
|
||||
[regexp -nocase -all -- {(\\includegraphics)(\[.*?\])(\{.*?\})} $line struct v1 v3 v2] ==1} {
|
||||
if {[string tolower $thumb(show)] == "no"} {
|
||||
return
|
||||
}
|
||||
incr in(image)
|
||||
set imagePath [file dirname $v2]
|
||||
set rootPath [file dirname [$tree itemcget $node -data]]
|
||||
|
||||
if {$imagePath == "."} {
|
||||
set fullPathToFile [file join $rootPath [string trimleft [string trimright $v2 "\}"] "\{"]]
|
||||
}
|
||||
set fullPathToFile [file join $rootPath [string trimleft [string trimright $v2 "\}"] "\{"]]
|
||||
set subNode [InsertTreeSubNode [file tail $fullPathToFile] $node [file dirname $fullPathToFile]]
|
||||
$tree itemconfigure $subNode -image [Bitmap::get [file join $dir(img) img.gif]]
|
||||
|
||||
puts "$imagePath - $rootPath"
|
||||
set imgFile [ConvertImage $fullPathToFile]
|
||||
if {[info exists thumbnail($imgFile)] == 0} {
|
||||
set thumbnail($imgFile) [image create photo -file $imgFile]
|
||||
$nb.f$activeFile.f.text image create $lineNumber.end -image $thumbnail($imgFile)
|
||||
puts "Image $thumbnail($imgFile) was create"
|
||||
} else {
|
||||
if [lsearch [$nb.f$activeFile.f.text image names ] $thumbnail($imgFile)] {
|
||||
puts "$thumbnail($imgFile) - Image already created"
|
||||
} else {
|
||||
#$nb.f$activeFile.f.text image create $lineNumber.end -image $thumbnail($imgFile)
|
||||
}
|
||||
#puts "image - $thumbnail($imgFile)\n lists - [$nb.f$activeFile.f.text image names ]"
|
||||
}
|
||||
}
|
||||
}
|
||||
## UPDATE DOCUMENT STRUCTURE PROCEDURE ##
|
||||
proc UpdateStruct {file node} {
|
||||
#puts $file
|
||||
#puts $node
|
||||
global tree treeStruct dir font color lblList files
|
||||
global lastPart lastChapter lastSection lastSSection lastSSSection
|
||||
global lastPar lastSubPar in nb dir activeFile
|
||||
if [info exists files($node)] {
|
||||
Timer $file "refresh"
|
||||
} else {
|
||||
return
|
||||
}
|
||||
#FileDialog save
|
||||
# <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD> <20><><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
||||
set dirName [file dirname $file]
|
||||
set file [file tail $file]
|
||||
set text "$nb.f$node.f.text"
|
||||
set contents [$text get 0.0 end]
|
||||
set fhandle [open [file join $dir(tmp) $file.bak] "w"]
|
||||
puts $fhandle $contents nonewline
|
||||
close $fhandle
|
||||
|
||||
|
||||
set in(c) 0 ;# chapter counter
|
||||
set in(p) 0 ;# part counter
|
||||
set in(s) 0 ;# section counter
|
||||
set in(ss) 0 ;# subsection counter
|
||||
set in(sss) 0 ;# subsubsection counter
|
||||
set in(par) 0 ;# paragraph cponter
|
||||
set in(spar) 0 ;# subparagraph cponter
|
||||
set in(lbl) 0 ;# label cuonter
|
||||
set in(ref) 0 ;# ref counter
|
||||
set in(pageref) 0 ;# ref counter
|
||||
set in(include) 0
|
||||
set in(input) 0
|
||||
set in(cite) 0
|
||||
set in(bibitem) 0
|
||||
set lastPart "root"
|
||||
set lastChapter "root"
|
||||
set lastSection "root"
|
||||
set lastSSection "root"
|
||||
set lastSSSection "root"
|
||||
set lastPar "root"
|
||||
set lastSubPar "root"
|
||||
## check if file was deleted from declaration \input and \include
|
||||
## adding new node into file tree
|
||||
#set node $activeFile
|
||||
set parentNode [$tree parent $node]
|
||||
|
||||
#puts "UpdateStruct: node - $node\tparent - $parentNode"
|
||||
|
||||
if [$tree exists $node] {
|
||||
$tree delete [$tree nodes $node] ;# delete all info about old structure
|
||||
} else {
|
||||
set file [file tail [lindex $files($node) 0]]
|
||||
set fileDir [file dirname [lindex $files($node) 0]]
|
||||
InsertTreeSubNode "$file" $parentNode $fileDir
|
||||
}
|
||||
$treeStruct delete [$treeStruct nodes root] ;# delete all info about old structure
|
||||
$lblList delete [$lblList item 0 end] ;# deleted all old labels from label list
|
||||
set fHandle [open [file join $dir(tmp) $file.bak] "r"]
|
||||
set lineNumber 1
|
||||
while {[gets $fHandle line]>=0} {
|
||||
InsertStruct $node $line $lineNumber $dirName
|
||||
incr lineNumber
|
||||
}
|
||||
unset dirName text contents
|
||||
}
|
||||
|
||||
proc InsertLabel {node label img} {
|
||||
global tree treeStruct lblList dir
|
||||
set label [string trimleft $label "\{"]
|
||||
set label [string trimright $label "\}"]
|
||||
$lblList insert end $node -text "$label" -image [Bitmap::get [file join $dir(img) $img.gif]]
|
||||
unset label
|
||||
}
|
||||
proc InsertRef {node label} {
|
||||
global tree treeStruct lblList dir
|
||||
set label [string trimleft $label "\{"]
|
||||
set label [string trimright $label "\}"]
|
||||
$lblList insert end $node -text "$label" -image [Bitmap::get [file join $dir(img) ref.gif]]
|
||||
unset label
|
||||
}
|
||||
proc InsertPageref {node label} {
|
||||
global tree treeStruct lblList dir
|
||||
set label [string trimleft $label "\{"]
|
||||
set label [string trimright $label "\}"]
|
||||
$lblList insert end $node -text "$label" -image [Bitmap::get [file join $dir(img) pageref.gif]]
|
||||
unset label
|
||||
}
|
||||
proc FindLabel {node} {
|
||||
global nb activeFile lblList status
|
||||
$lblList selection set $node
|
||||
set t [$lblList itemcget $node -text]
|
||||
set text [string range $node 0 [expr [string first "_" $node]-1]]
|
||||
set findString "$text\{$t\}"
|
||||
set text "$nb.f$activeFile.f.text"
|
||||
FindProc $text $findString $activeFile
|
||||
$status(pos) configure -text [$text index insert];# cursor position
|
||||
unset text t findString
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
390
lib/modules/supertext.tcl
Executable file
390
lib/modules/supertext.tcl
Executable file
@@ -0,0 +1,390 @@
|
||||
# supertext.tcl v1.01
|
||||
#
|
||||
# Copyright (c) 1998 Bryan Oakley
|
||||
# All Rights Reserved
|
||||
#
|
||||
# this code is freely distributable, but is provided as-is with
|
||||
# no waranty expressed or implied.
|
||||
|
||||
# send comments to oakley@channelpoint.com
|
||||
|
||||
# What is this?
|
||||
#
|
||||
# This is a replacement for (or superset of , or subclass of, ...)
|
||||
# the tk text widget. Its big feature is that it supports unlimited
|
||||
# undo. It also has two poorly documented options: -preproc and
|
||||
# -postproc.
|
||||
|
||||
# The entry point to this widget is supertext::text; it takes all of
|
||||
# the same arguments as the standard text widget and exhibits all of
|
||||
# the same behaviors. The proc supertext::overrideTextCommand may be
|
||||
# called to have the supertext widget be used whenever the command
|
||||
# "text" is used (ie: it imports supertext::text as the command "text").
|
||||
# Use at your own risk...
|
||||
|
||||
# To access the undo feature, use ".widget undo". It will undo the
|
||||
# most recent insertion or deletion. On windows and the mac
|
||||
# this command is bound to <Control-z>; on unix it is bound to
|
||||
# <Control-_>
|
||||
|
||||
# if you are lucky, you might find documentation here:
|
||||
# http://www1.clearlight.com/~oakley/tcl/supertext.html
|
||||
|
||||
package provide supertext 1.01
|
||||
|
||||
namespace eval supertext {
|
||||
variable undo
|
||||
variable undoIndex
|
||||
variable text "::text"
|
||||
variable preProc
|
||||
variable postProc
|
||||
namespace export text
|
||||
}
|
||||
|
||||
# this proc is probably attempting to be more clever than it should...
|
||||
# When called, it will (*gasp*) rename the tk command "text" to "_text_",
|
||||
# then import our text command into the global scope.
|
||||
#
|
||||
# Use at your own risk!
|
||||
|
||||
proc supertext::overrideTextCommand {} {
|
||||
variable text
|
||||
set text "::_text_"
|
||||
rename ::text $text
|
||||
uplevel #0 namespace import supertext::text
|
||||
}
|
||||
|
||||
proc supertext::text {w args} {
|
||||
variable text
|
||||
variable undo
|
||||
variable undoIndex
|
||||
variable preProc
|
||||
variable postProc
|
||||
|
||||
# this is what we will rename our widget proc to...
|
||||
set original __$w
|
||||
|
||||
# do we have any of our custom options? If so, process them and
|
||||
# strip them out before sending them to the real text command
|
||||
if {[set i [lsearch -exact $args "-preproc"]] >= 0} {
|
||||
set j [expr $i + 1]
|
||||
set preProc($original) [lindex $args $j]
|
||||
set args [lreplace $args $i $j]
|
||||
} else {
|
||||
set preProc($original) {}
|
||||
}
|
||||
|
||||
if {[set i [lsearch -exact $args "-postproc"]] >= 0} {
|
||||
set j [expr $i + 1]
|
||||
set postProc($original) [lindex $args $j]
|
||||
set args [lreplace $args $i $j]
|
||||
} else {
|
||||
set postProc($original) {}
|
||||
}
|
||||
|
||||
# let the text command create the widget...
|
||||
eval $text $w $args
|
||||
|
||||
# now, rename the resultant widget proc so we can create our own
|
||||
rename ::$w $original
|
||||
|
||||
# here's where we create our own widget proc.
|
||||
proc ::$w {command args} \
|
||||
"namespace eval supertext widgetproc $w $original \$command \$args"
|
||||
|
||||
# set up platform-specific binding for undo; the only one I'm
|
||||
# really sure about is winders; the rest will stay the same for
|
||||
# now until someone has a better suggestion...
|
||||
switch $::tcl_platform(platform) {
|
||||
unix {
|
||||
event add <<Undo>> <Control-z>
|
||||
event add <<Undo>> <Control-Z>
|
||||
}
|
||||
windows {
|
||||
event add <<Undo>> <Control-z>
|
||||
event add <<Undo>> <Control-Z>
|
||||
}
|
||||
macintosh {
|
||||
event add <<Undo>> <Control-z>
|
||||
event add <<Undo>> <Control-Z>
|
||||
}
|
||||
}
|
||||
bind $w <<Undo>> "$w undo"
|
||||
|
||||
set undo($original) {}
|
||||
set undoIndex($original) -1
|
||||
set clones($original) {}
|
||||
|
||||
return $w
|
||||
}
|
||||
|
||||
# this is the command that we associate with a supertext widget.
|
||||
proc supertext::widgetproc {this w command args} {
|
||||
|
||||
variable undo
|
||||
variable undoIndex
|
||||
variable preProc
|
||||
variable postProc
|
||||
|
||||
# these will be the arguments to the pre and post procs
|
||||
set originalCommand $command
|
||||
set originalArgs $args
|
||||
|
||||
# is there a pre-proc? If so, run it. If there is a problem,
|
||||
# die. This is potentially bad, because once there is a problem
|
||||
# in a preproc the user must fix the preproc -- there is no
|
||||
# way to unconfigure the preproc. Oh well. The other choice
|
||||
# is to ignore errors, but then how will the caller know if
|
||||
# the proc fails?
|
||||
if {[info exists preProc($w)] && $preProc($w) != ""} {
|
||||
if {[catch "$preProc($w) command args" error]} {
|
||||
return -code error "error during processing of -preproc: $error"
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
# if the command is "undo", we need to morph it into the appropriate
|
||||
# command for undoing the last item on the stack
|
||||
if {$command == "undo"} {
|
||||
|
||||
if {$undoIndex($w) == ""} {
|
||||
# ie: last command was anything _but_ an undo...
|
||||
set undoIndex($w) [expr [llength $undo($w)] -1]
|
||||
}
|
||||
|
||||
# if the index is pointing to a valid list element,
|
||||
# lets undo it...
|
||||
if {$undoIndex($w) < 0} {
|
||||
# nothing to undo...
|
||||
bell
|
||||
|
||||
} else {
|
||||
|
||||
# data is a list comprised of a command token
|
||||
# (i=insert, d=delete) and parameters related
|
||||
# to that token
|
||||
set data [lindex $undo($w) $undoIndex($w)]
|
||||
|
||||
if {[lindex $data 0] == "d"} {
|
||||
set command "delete"
|
||||
} else {
|
||||
set command "insert"
|
||||
}
|
||||
set args [lrange $data 1 end]
|
||||
|
||||
# adjust the index
|
||||
incr undoIndex($w) -1
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
# now, process the command (either the original one, or the morphed
|
||||
# undo command
|
||||
switch $command {
|
||||
|
||||
reset_undo {
|
||||
set undo($w) ""
|
||||
set undoIndex($w) ""
|
||||
set result {}
|
||||
}
|
||||
|
||||
configure {
|
||||
# we have to deal with configure specially, since the
|
||||
# user could try to configure the -preproc or -postproc
|
||||
# options...
|
||||
|
||||
if {[llength $args] == 0} {
|
||||
# first, the case where they just type "configure"; lets
|
||||
# get it out of the way
|
||||
set list [$w configure]
|
||||
lappend list [list -preproc preproc Preproc {} $preProc($w)]
|
||||
lappend list [list -postproc postproc Postproc {} $postProc($w)]
|
||||
set result $list
|
||||
|
||||
|
||||
} elseif {[llength $args] == 1} {
|
||||
# this means they are wanting specific configuration
|
||||
# information
|
||||
set option [lindex $args 0]
|
||||
if {$option == "-preproc"} {
|
||||
set result [list -preproc preproc Preproc {} $preProc($w)]
|
||||
|
||||
} elseif {$option == "-postproc"} {
|
||||
set result [list -postproc postproc Postproc {} $postProc($w)]
|
||||
|
||||
} else {
|
||||
if {[catch "$w $command $args" result]} {
|
||||
regsub $w $result $this result
|
||||
return -code error $result
|
||||
}
|
||||
}
|
||||
|
||||
} else {
|
||||
# ok, the user is actually configuring something...
|
||||
# we'll deal with our special options first
|
||||
if {[set i [lsearch -exact $args "-preproc"]] >= 0} {
|
||||
set j [expr $i + 1]
|
||||
set preProc($w) [lindex $args $j]
|
||||
set args [lreplace $args $i $j]
|
||||
set result {}
|
||||
}
|
||||
|
||||
if {[set i [lsearch -exact $args "-postproc"]] >= 0} {
|
||||
set j [expr $i + 1]
|
||||
set postProc($w) [lindex $args $j]
|
||||
set args [lreplace $args $i $j]
|
||||
set result {}
|
||||
}
|
||||
|
||||
# now, process any remaining args
|
||||
if {[llength $args] > 0} {
|
||||
if {[catch "$w $command $args" result]} {
|
||||
regsub $w $result $this result
|
||||
return -code error $result
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
undo {
|
||||
# if an undo command makes it to here, that means there
|
||||
# wasn't anything to undo; this effectively becomes a
|
||||
# no-op
|
||||
set result {}
|
||||
}
|
||||
|
||||
insert {
|
||||
|
||||
if {[catch {set index [text_index $w [lindex $args 0]]}]} {
|
||||
set index [lindex $args 0]
|
||||
}
|
||||
|
||||
# since the insert command can have an arbitrary number
|
||||
# of strings and possibly tags, we need to ferret that out
|
||||
# now... what a pain!
|
||||
set myargs [lrange $args 1 end]
|
||||
set length 0
|
||||
while {[llength $myargs] > 0} {
|
||||
incr length [string length [lindex $myargs 0]]
|
||||
if {[llength $myargs] > 1} {
|
||||
# we have a tag...
|
||||
set myargs [lrange $myargs 2 end]
|
||||
} else {
|
||||
set myargs [lrange $myargs 1 end]
|
||||
}
|
||||
}
|
||||
|
||||
# now, let the real widget command do the dirty work
|
||||
# of inserting the text. If we fail, do some munging
|
||||
# of the error message so the right widget name appears...
|
||||
|
||||
if {[catch "$w $command $args" result]} {
|
||||
regsub $w $result $this result
|
||||
return -code error $result
|
||||
}
|
||||
|
||||
# we need this for the undo stack; index2 couldn't be
|
||||
# computed until after we inserted the data...
|
||||
set index2 [text_index $w "$index + $length chars"]
|
||||
|
||||
if {$originalCommand == "undo"} {
|
||||
# let's do a "see" so what we just did is visible;
|
||||
# also, we'll move the insertion cursor to the end
|
||||
# of what we just did...
|
||||
$w see $index2
|
||||
$w mark set insert $index2
|
||||
|
||||
} else {
|
||||
# since the original command wasn't undo, we need
|
||||
# to reset the undoIndex. This means that the next
|
||||
# time an undo is called for we'll start at the
|
||||
# end of the stack
|
||||
set undoIndex($w) ""
|
||||
}
|
||||
|
||||
# add a delete command on the undo stack.
|
||||
lappend undo($w) "d $index $index2"
|
||||
|
||||
}
|
||||
|
||||
delete {
|
||||
|
||||
# this converts the insertion index into an absolute address
|
||||
set index [text_index $w [lindex $args 0]]
|
||||
|
||||
# lets get the data we are about to delete; we'll need
|
||||
# it to be able to undo it (obviously. Duh.)
|
||||
set data [eval $w get $args]
|
||||
|
||||
# add an insert on the undo stack
|
||||
lappend undo($w) [list "i" $index $data]
|
||||
|
||||
if {$originalCommand == "undo"} {
|
||||
# let's do a "see" so what we just did is visible;
|
||||
# also, we'll move the insertion cursor to a suitable
|
||||
# spot
|
||||
$w see $index
|
||||
$w mark set insert $index
|
||||
|
||||
} else {
|
||||
# since the original command wasn't undo, we need
|
||||
# to reset the undoIndex. This means that the next
|
||||
# time an undo is called for we'll start at the
|
||||
# end of the stack
|
||||
set undoIndex($w) ""
|
||||
}
|
||||
|
||||
# let the real widget command do the actual deletion. If
|
||||
# we fail, do some munging of the error message so the right
|
||||
# widget name appears...
|
||||
if {[catch "$w $command $args" result]} {
|
||||
regsub $w $result $this result
|
||||
return -code error $result
|
||||
}
|
||||
}
|
||||
|
||||
default {
|
||||
# if the command wasn't one of the special commands above,
|
||||
# just pass it on to the real widget command as-is. If
|
||||
# we fail, do some munging of the error message so the right
|
||||
# widget name appears...
|
||||
if {[catch "$w $command $args" result]} {
|
||||
regsub $w $result $this result
|
||||
return -code error $result
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
# is there a post-proc? If so, run it.
|
||||
if {[info exists postProc($w)] && $postProc($w) != ""} {
|
||||
if {[catch "$postProc($w) originalCommand originalArgs" error]} {
|
||||
return -code error "error during processing of -postproc: $error"
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
# we're outta here! (I think this is faster than a
|
||||
# return, though I'm not 100% sure on this...)
|
||||
set result $result
|
||||
}
|
||||
|
||||
# this returns a normalized index (ie: line.column), with special
|
||||
# handling for the index "end"; to undo something we pretty much
|
||||
# _have_ to have a precise row and column number.
|
||||
proc supertext::text_index {w i} {
|
||||
if {$i == "end"} {
|
||||
set index [$w index "end-1c"]
|
||||
} else {
|
||||
set index [$w index $i]
|
||||
}
|
||||
|
||||
return $index
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
147
lib/modules/table.tcl
Executable file
147
lib/modules/table.tcl
Executable file
@@ -0,0 +1,147 @@
|
||||
######################################################
|
||||
# Tk LaTeX Editor
|
||||
# Distributed under GNU Public License
|
||||
# Author: Sergey Kalinin (BanZaj) banzaj@lrn.ru
|
||||
# Copyright (c) "CONERO lab", 2002, http://conero.lrn.ru
|
||||
######################################################
|
||||
|
||||
proc InsertTableDialog {} {
|
||||
global nb font files findString replaceString text dir color
|
||||
set node [$nb raise]
|
||||
if {$node == "newproj" || $node == "settings" || $node == "about" || $node == ""} {
|
||||
return
|
||||
}
|
||||
#set file $files($node)
|
||||
set w .table
|
||||
set text "$nb.f$node.f.text"
|
||||
# set findString ""
|
||||
# destroy the find window if it already exists
|
||||
if {[winfo exists $w]} {
|
||||
destroy $w
|
||||
}
|
||||
set colNum 1
|
||||
set posTable "center"
|
||||
set align "center"
|
||||
set line "full"
|
||||
toplevel $w
|
||||
wm transient $w $nb.f$node
|
||||
wm title $w [::msgcat::mc "Add table"]
|
||||
wm resizable $w 0 0
|
||||
|
||||
set f1 [frame $w.frmAlign -borderwidth 1 -relief raised -background $color(bg)]
|
||||
set f2 [frame $w.frmTable -borderwidth 1 -relief raised -background $color(bg)]
|
||||
set f3 [frame $w.frmBtn -borderwidth 1 -background $color(bg)]
|
||||
set f4 [frame $w.frmCol -borderwidth 1 -relief raised -background $color(bg)]
|
||||
set f5 [frame $w.frmPos -borderwidth 1 -relief raised -background $color(bg)]
|
||||
pack $f4 $f1 $f2 $f5 $f3 -side top -fill x -expand true
|
||||
|
||||
label $f4.lblCol -text [::msgcat::mc "Input number of columns"] -background $color(bg)
|
||||
SpinBox $f4.spinCol -textvariable colNum -range {1 100 1} -helptext "Columns" -background $color(bg)
|
||||
pack $f4.lblCol $f4.spinCol -side top -fill x -pady 2 -padx 2
|
||||
|
||||
label $f1.lbl -text [::msgcat::mc "Alignment"] -background $color(bg)
|
||||
pack $f1.lbl -side top -fill x
|
||||
foreach btn {center left right} {
|
||||
radiobutton $f1.btn$btn -text [::msgcat::mc "Align $btn"] -variable align\
|
||||
-value $btn -font $font(normal) -selectcolor $color(selectbg) -background $color(bg)
|
||||
pack $f1.btn$btn -side top -anchor w
|
||||
}
|
||||
|
||||
label $f5.lblPos -text [::msgcat::mc "Table position"] -background $color(bg)
|
||||
pack $f5.lblPos -side top -fill x
|
||||
foreach tbl {top bottom center} {
|
||||
image create photo img_$tbl -file [file join $dir(img) table_$tbl.gif]
|
||||
radiobutton $f5.btn$tbl -variable table -indicatoron 0 -background $color(bg)\
|
||||
-font $font(normal) -image img_$tbl -value $tbl -selectcolor $color(selectbg)
|
||||
pack $f5.btn$tbl -side left -anchor n -pady 2
|
||||
}
|
||||
|
||||
label $f2.lblLine -text [::msgcat::mc "Line type"] -background $color(bg)
|
||||
pack $f2.lblLine -side top -fill x
|
||||
foreach tbl {empty full double cols lines} {
|
||||
image create photo img_$tbl -file [file join $dir(img) table_$tbl.gif]
|
||||
radiobutton $f2.btn$tbl -variable line -indicatoron 0 -background $color(bg)\
|
||||
-font $font(normal) -image img_$tbl -value $tbl -selectcolor $color(selectbg)
|
||||
pack $f2.btn$tbl -side left -anchor n -pady 2
|
||||
}
|
||||
|
||||
|
||||
button $f3.btnAdd -text "[::msgcat::mc "Insert"] - Enter" -font $font(normal)\
|
||||
-relief groove -background $color(bg) -command {
|
||||
InsertTable $colNum $table $line $align
|
||||
destroy .table
|
||||
}
|
||||
button $f3.btnCancel -text "[::msgcat::mc "Cancel"] - Esc" -command "destroy $w"\
|
||||
-font $font(normal) -relief groove -background $color(bg)
|
||||
pack $f3.btnAdd $f3.btnCancel\
|
||||
-side left -padx 2 -pady 2 -fill x
|
||||
|
||||
bind $w <Return> ""
|
||||
bind $w <F4> ""
|
||||
bind $w <Escape> "destroy $w"
|
||||
}
|
||||
|
||||
proc InsertTable {colNum posTable line align} {
|
||||
global dir font color nb
|
||||
set node [$nb raise]
|
||||
if {$node == ""} {return}
|
||||
set text "$nb.f$node.f.text"
|
||||
set pos [$text index insert]
|
||||
set curLine [lindex [split $pos "."] 0]
|
||||
set cursor [lindex [split $pos "."] 1]
|
||||
set editLine [$text get $curLine.0 $pos]
|
||||
set header "\\begin\{tabular\}"
|
||||
set footer "\\end\{tabular\}"
|
||||
|
||||
if {$line == "double"} {
|
||||
set split "||"
|
||||
set lineEnd "\\\\ \\hline\n"
|
||||
} elseif {$line == "full"} {
|
||||
set split "|"
|
||||
set lineEnd "\\\\ \\hline\n"
|
||||
} elseif {$line == "empty"} {
|
||||
set split " "
|
||||
set lineEnd "\\\\\n"
|
||||
} elseif {$line == "cols"} {
|
||||
set split "|"
|
||||
set lineEnd "\\\\\n"
|
||||
} elseif {$line == "lines"} {
|
||||
set split " "
|
||||
set lineEnd "\\\\ \\hline\n"
|
||||
} else {
|
||||
set split " "
|
||||
set lineEnd "\\\\\n"
|
||||
}
|
||||
switch -- $posTable {
|
||||
top {set position "t"}
|
||||
bottom {set position "b"}
|
||||
center {set position "c"}
|
||||
}
|
||||
switch -- $align {
|
||||
center {set colAlign "c"}
|
||||
left {set colAlign "l"}
|
||||
right {set colAlign "r"}
|
||||
}
|
||||
set count 0
|
||||
set count_ 0
|
||||
while {$colNum > $count} {
|
||||
append columns "$split$colAlign"
|
||||
incr count
|
||||
}
|
||||
while {$colNum > [expr $count_+1]} {
|
||||
append body "& "
|
||||
incr count_
|
||||
}
|
||||
|
||||
append columns $split
|
||||
|
||||
$text insert $pos "$header\[$position\]\{$columns\} $lineEnd\t$body$lineEnd$footer"
|
||||
$text mark set insert [expr $curLine +1].1
|
||||
$text see insert
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
126
lib/modules/template.tcl
Executable file
126
lib/modules/template.tcl
Executable file
@@ -0,0 +1,126 @@
|
||||
######################################################
|
||||
# TkTeXEditor
|
||||
# Distributed under GNU Public License
|
||||
# Author: Sergey Kalinin (aka BanZaj) banzaj@lrn.ru
|
||||
# Copyright (c) "CONERO lrn", 2002, http://conero.lrn.ru
|
||||
######################################################
|
||||
|
||||
proc TemplateDialog {} {
|
||||
global dir nb tmpl font color relief
|
||||
set w .template
|
||||
if {[winfo exists $w]} {
|
||||
destroy $w
|
||||
}
|
||||
# create the new "goto" window
|
||||
toplevel $w
|
||||
wm title $w [::msgcat::mc "Create new file"]
|
||||
#wm resizable $w 0 0
|
||||
wm geometry $w 550x300
|
||||
wm transient $w .
|
||||
|
||||
frame $w.frmCanv -border 1 -relief sunken
|
||||
frame $w.frmBtn -border 1 -relief sunken
|
||||
frame $w.frmTxt -border 1 -relief sunken
|
||||
pack $w.frmCanv -side top -fill both -padx 1 -pady 1 -expand 1 -fill both
|
||||
pack $w.frmTxt -side top -fill x
|
||||
pack $w.frmBtn -side top -fill x
|
||||
|
||||
set fList [ScrolledWindow $w.frmCanv.f -background $color(bg)]
|
||||
set list [ListBox $fList.list -font $font(normal)\
|
||||
-relief sunken -borderwidth 1 -width 1 -height 1 -highlightthickness 1\
|
||||
-background $color(editBg) -selectbackground $color(selectbg)]
|
||||
pack $list -side left -fill both -expand yes
|
||||
$fList setwidget $list
|
||||
pack $fList -side left -fill both -expand yes
|
||||
|
||||
|
||||
set fText [ScrolledWindow $w.frmCanv.f1 -background $color(bg)]
|
||||
set text [supertext::text $fText.txtTemplate -width 5 -height 5 -yscrollcommand "$w.frmCanv.yScrText set" \
|
||||
-wrap none -state disable -background $color(editBg) -foreground $color(editFg)\
|
||||
-selectborderwidth 0 -selectbackground $color(selectbg)]
|
||||
$fText setwidget $text
|
||||
pack $fText -side left -fill both -expand 1
|
||||
#pack $text -side left -fill both -expand 1
|
||||
#return
|
||||
|
||||
## SPLIT BAR ##
|
||||
pane::create $fList $fText
|
||||
|
||||
label $w.frmTxt.lblFile -text [::msgcat::mc "Input file name"] -font $font(normal)
|
||||
entry $w.frmTxt.entFile
|
||||
pack $w.frmTxt.lblFile $w.frmTxt.entFile -side left -padx 2
|
||||
pack $w.frmTxt.entFile -side left -padx 1 -fill x -expand true
|
||||
$w.frmTxt.entFile insert 0 "name.tex"
|
||||
|
||||
button $w.frmBtn.btnOk -text [::msgcat::mc "Create"] -relief groove -font $font(normal) -command {
|
||||
set file [.template.frmTxt.entFile get]
|
||||
file copy -force $tmpl [file join $dir(current) $file]
|
||||
EditFile [file join $dir(current) $file]
|
||||
destroy .template
|
||||
}
|
||||
|
||||
button $w.frmBtn.btnCancel -text [::msgcat::mc "Close"] -command "destroy $w" -relief groove -font $font(normal)
|
||||
pack $w.frmBtn.btnOk $w.frmBtn.btnCancel -padx 2 -pady 2 -fill x -side left
|
||||
|
||||
bind $w <Escape> "destroy .template"
|
||||
focus -force $list
|
||||
$list bindImage <ButtonRelease-1> "ReadTemplateDescr [$list selection get]"
|
||||
$list bindText <ButtonRelease-1> "ReadTemplateDescr [$list selection get]"
|
||||
bind $list.c <Button-4> "$list yview scroll -3 units"
|
||||
bind $list.c <Button-5> "$list yview scroll 3 units"
|
||||
bind $list.c <Shift-Button-4> "$list xview scroll -2 units"
|
||||
bind $list.c <Shift-Button-5> "$list xview scroll 2 units"
|
||||
|
||||
GetTemplateList $list
|
||||
}
|
||||
|
||||
proc GetTemplateList {list} {
|
||||
global dir
|
||||
set ind 0
|
||||
foreach file [lsort [glob -nocomplain [file join $dir(tmpl) *.tex]]] {
|
||||
if {[file isdirectory $file] == 0} {
|
||||
#$list insert end $file
|
||||
$list insert end tmpl_$ind -text [file tail $file] \
|
||||
-image [Bitmap::get [file join $dir(img) tex_tmpl.gif]] \
|
||||
-data $file
|
||||
#$list insert end [file tail $file]
|
||||
#ReadTemplate $file $text
|
||||
incr ind
|
||||
}
|
||||
}
|
||||
foreach file [lsort [glob -nocomplain [file join $dir(work_tmpl) *.tex]]] {
|
||||
if {[file isdirectory $file] == 0} {
|
||||
$list insert end tmpl_$ind -text [file tail $file] \
|
||||
-image [Bitmap::get [file join $dir(img) tex_tmpl.gif]] \
|
||||
-data $file
|
||||
incr ind
|
||||
#$list insert end $file
|
||||
#$list insert end [file tail $file]
|
||||
#ReadTemplate $file $text
|
||||
}
|
||||
}
|
||||
#catch {cd ..}
|
||||
}
|
||||
proc ReadTemplateDescr {node} {
|
||||
global dir tmpl
|
||||
set text .template.frmCanv.f1.txtTemplate
|
||||
$text configure -state normal
|
||||
$text delete 0.0 end
|
||||
.template.frmCanv.f.list selection set $node
|
||||
|
||||
#$w select set anchor [$w nearest $y]
|
||||
#set file [$w get [$w curselection]]
|
||||
set file [.template.frmCanv.f.list itemcget $node -data]
|
||||
|
||||
set tmpl $file
|
||||
set fHandle [open $file]
|
||||
fconfigure $fHandle -encoding koi8-r
|
||||
while {[gets $fHandle line]>=0} {
|
||||
if {[string range [string trim $line] 0 0] != "%"} {return}
|
||||
$text insert end "$line\n"
|
||||
}
|
||||
close $fHandle
|
||||
$text configure -state disable
|
||||
}
|
||||
|
||||
|
118
lib/modules/tex.tcl
Executable file
118
lib/modules/tex.tcl
Executable file
@@ -0,0 +1,118 @@
|
||||
###########################################################
|
||||
# Tcl/Tk Project Manager #
|
||||
# version 0.0.1 #
|
||||
# TCL highlight file #
|
||||
# Copyright (c) "CONERO lab", 2001, http://conero.lrn.ru #
|
||||
# Author: Sergey Kalinin (aka BanZaj) banzaj@lrn.ru #
|
||||
###########################################################
|
||||
|
||||
proc LoadTag {text} {
|
||||
global font color
|
||||
$text tag configure bold -font $font(bold)
|
||||
$text tag configure operator -foreground $color(operator)
|
||||
$text tag configure param -foreground $color(param)
|
||||
$text tag configure subParam -foreground $color(subParam)
|
||||
$text tag configure keyWord -foreground $color(keyWord)
|
||||
$text tag configure comments -foreground $color(comments)
|
||||
$text tag configure variable -foreground $color(var)
|
||||
$text tag configure string -foreground $color(string)
|
||||
$text tag configure brace -foreground $color(brace)
|
||||
$text tag configure percent -foreground $color(percent)
|
||||
$text tag configure bindKey -foreground $color(bindKey)
|
||||
$text tag configure lightBracket -background $color(braceBG) -foreground $color(braceFG)
|
||||
}
|
||||
|
||||
proc HighLightTEX {text line lineNumber node} {
|
||||
global font tree color nb
|
||||
|
||||
set startIndex 0
|
||||
|
||||
set keyWord [info commands]
|
||||
# for OOP extention
|
||||
foreach n {class method attribute constructor destructor invariant attribute binding new delete} {
|
||||
lappend keyWord $n
|
||||
}
|
||||
set startPos 0
|
||||
set workLine $line
|
||||
|
||||
regexp -nocase -all -- {(\\)([a-zA-Z])*} string match v1 v2
|
||||
while {$workLine != ""} {
|
||||
if {[regexp -nocase -all {(\\)([a-zA-Z])*} $workLine a b c]} {
|
||||
set start [string first $a $workLine]
|
||||
set end $start
|
||||
incr end [string length $a]
|
||||
set workLine [string range $workLine $end end]
|
||||
incr start $startPos
|
||||
incr end $startPos
|
||||
$text tag add operator $lineNumber.$start $lineNumber.$end
|
||||
set startPos $end
|
||||
} else {
|
||||
break
|
||||
}
|
||||
}
|
||||
# string " " highlight
|
||||
set startPos 0
|
||||
set workLine $line
|
||||
while {$workLine != ""} {
|
||||
if {[regexp "\".*?\"" $workLine a b]} {
|
||||
set start [string first $a $workLine]
|
||||
set end $start
|
||||
incr end [string length $a]
|
||||
set workLine [string range $workLine $end end]
|
||||
incr start $startPos
|
||||
incr end $startPos
|
||||
$text tag add string $lineNumber.$start $lineNumber.$end
|
||||
set startPos $end
|
||||
} else {
|
||||
break
|
||||
}
|
||||
}
|
||||
set startPos 0
|
||||
set workLine $line
|
||||
while {$workLine != ""} {
|
||||
if {[regexp {\{.*?\}} $workLine a b]} {
|
||||
set start [string first $a $workLine]
|
||||
set end $start
|
||||
incr end [string length $a]
|
||||
set workLine [string range $workLine $end end]
|
||||
incr start [expr $startPos +1]
|
||||
incr end [expr $startPos - 1]
|
||||
$text tag add param $lineNumber.$start $lineNumber.$end
|
||||
set startPos $end
|
||||
} else {
|
||||
break
|
||||
}
|
||||
}
|
||||
set startPos 0
|
||||
set workLine $line
|
||||
while {$workLine != ""} {
|
||||
if {[regexp {\[.*?\]} $workLine a b]} {
|
||||
set start [string first $a $workLine]
|
||||
set end $start
|
||||
incr end [string length $a]
|
||||
set workLine [string range $workLine $end end]
|
||||
incr start [expr $startPos + 1]
|
||||
incr end [expr $startPos - 1]
|
||||
$text tag add subParam $lineNumber.$start $lineNumber.$end
|
||||
set startPos $end
|
||||
} else {
|
||||
break
|
||||
}
|
||||
}
|
||||
# add comment #
|
||||
set workLine [$text get $lineNumber.0 $lineNumber.end]
|
||||
if {[regexp -indices "(^|\t|;| )%" $workLine pos]} {
|
||||
set cur [lindex $pos 1]
|
||||
$text tag add comments $lineNumber.$cur $lineNumber.end
|
||||
return 0
|
||||
} else {
|
||||
$text tag remove comments $lineNumber.0 $lineNumber.end
|
||||
return 0
|
||||
}
|
||||
|
||||
####################
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
181
lib/modules/tree.tcl
Executable file
181
lib/modules/tree.tcl
Executable file
@@ -0,0 +1,181 @@
|
||||
######################################################
|
||||
# TkTeXEditor
|
||||
# Distributed under GNU Public License
|
||||
# Author: Sergey Kalinin (BanZaj) banzaj@lrn.ru
|
||||
# Copyright (c) "CONERO lab", 2002, http://conero.lrn.ru
|
||||
######################################################
|
||||
|
||||
######################################################
|
||||
# #
|
||||
# Working with trees (insert\update\deleted) nodes #
|
||||
# #
|
||||
######################################################
|
||||
|
||||
## PROJECTS & FILE TREE ##
|
||||
proc InsertTreeNode {file dirName} {
|
||||
global tree font dir
|
||||
set dot "_"
|
||||
set name [file rootname $file]
|
||||
set ext [string range [file extension $file] 1 end]
|
||||
regsub -all -nocase -- {/| |\.} $dirName $dot nodeEnd
|
||||
regsub -all -nocase -- { |\.} $name $dot name
|
||||
set subNode "$nodeEnd$dot$name$dot$ext"
|
||||
|
||||
if {[$tree exists $subNode] == 1} {
|
||||
return $subNode
|
||||
}
|
||||
$tree insert end root $subNode -text $file \
|
||||
-data [file join $dirName $file] -open 1\
|
||||
-image [Bitmap::get [file join $dir(img) tex.gif]]\
|
||||
-font $font(normal)
|
||||
$tree configure -redraw 1
|
||||
return $subNode
|
||||
|
||||
}
|
||||
|
||||
## INSERT NODE INTO FILES TREE FOR INCLUDED FILES
|
||||
proc InsertTreeSubNode {file rootNode dirName} {
|
||||
global tree font dir files
|
||||
set dot "_"
|
||||
set name [file rootname $file]
|
||||
set ext [string range [file extension $file] 1 end]
|
||||
if {$ext == ""} {
|
||||
#puts "$file - <20><><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>"
|
||||
set ext "tex"
|
||||
set file $file.$ext
|
||||
#puts $file
|
||||
}
|
||||
|
||||
regsub -all -nocase -- {/| |\.} $dirName $dot nodeEnd
|
||||
regsub -all -nocase -- { |\.} $name $dot name
|
||||
set subNode "$nodeEnd$dot$name$dot$ext"
|
||||
#set subNode "$nodeEnd$dot$ext"
|
||||
#puts "file - $file\n"
|
||||
#puts "dirName - $dirName\n"
|
||||
#puts "rootNode - $rootNode\n"
|
||||
#puts "nodeEnd - $nodeEnd\n"
|
||||
#puts "name - $name\n"
|
||||
#puts "subnode - $subNode\n"
|
||||
if {[$tree exists $subNode] == 1} {
|
||||
if {[$tree parent $subNode] == "root"} {
|
||||
$tree delete $subNode
|
||||
} else {
|
||||
return
|
||||
}
|
||||
}
|
||||
$tree insert end $rootNode $subNode -text $file \
|
||||
-data [file join $dirName $file] -open 1\
|
||||
-image [Bitmap::get [file join $dir(img) tex.gif]]\
|
||||
-font $font(normal)
|
||||
$tree configure -redraw 1
|
||||
return $subNode
|
||||
}
|
||||
## DOCUMENT STRUCTURE TREE ##
|
||||
proc InsertNode {node parentNode text image lineNumber} {
|
||||
global treeStruct font dir
|
||||
set dot "_"
|
||||
$treeStruct insert end $parentNode $node -text [string trimleft $text "\*\{"] \
|
||||
-data " $lineNumber$dot$text" -open 1\
|
||||
-font $font(normal)\
|
||||
-image [Bitmap::get [file join $dir(img) $image.gif]]
|
||||
$treeStruct configure -redraw 1
|
||||
#return $subNode
|
||||
}
|
||||
|
||||
## TREE ONE CLICKING PROCEDURE ##
|
||||
proc TreeOneClick {node} {
|
||||
global dir nb tree activeFile status files
|
||||
$tree selection set $node
|
||||
set activeFile $node
|
||||
|
||||
set file [$tree itemcget $node -data]
|
||||
#puts "TreeOneClick - $file";# debug
|
||||
if {[file exists $file] == 0} {
|
||||
set answer [tk_messageBox -message "$file [::msgcat::mc "File not found"]"\
|
||||
-type ok -icon warning -title [::msgcat::mc "Warning"]]
|
||||
case $answer {
|
||||
ok {return}
|
||||
}
|
||||
}
|
||||
|
||||
$status(fileAttr) configure -text [FileAttr [$tree itemcget $node -data]]
|
||||
#$status(encode) configure -text "[lindex $files($activeFile) 2]"
|
||||
PageRaise $node
|
||||
puts "$node\nnodes - [$tree nodes $node]"
|
||||
}
|
||||
|
||||
proc TreeStructOneClick {node} {
|
||||
global dir nb treeStruct activeFile status files ver release
|
||||
$treeStruct selection set $node
|
||||
set findString [$treeStruct itemcget $node -data]
|
||||
set star [string range $findString [expr [string first "_" $findString] + 1] [expr [string first "_" $findString] + 1]]
|
||||
set lineNumber [string range $findString 0 [expr [string first "_" $findString]-1]]
|
||||
set str [string range $node 0 [expr [string first "_" $node]-1]]
|
||||
if {$star == "\*"} {
|
||||
set findString [string range $findString [expr [string first "_" $findString]+2] end]
|
||||
set findString "$str\*$findString\}"
|
||||
} else {
|
||||
set findString [string range $findString [expr [string first "_" $findString]+1] end]
|
||||
set findString "$str\{$findString\}"
|
||||
}
|
||||
#$treeStruct selection get $node
|
||||
set text "$nb.f$activeFile.f.text"
|
||||
wm title . "TkLaTeXEditor $ver$release - [lindex $files($activeFile) 0]"
|
||||
|
||||
FindProc $text $findString $node
|
||||
$status(pos) configure -text [$text index insert];# cursor position
|
||||
}
|
||||
|
||||
proc TreeDoubleClick {} {
|
||||
|
||||
}
|
||||
|
||||
proc NodeInsert {file} {
|
||||
global tree font dir files
|
||||
set dot "_"
|
||||
# <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
||||
set dirName [file dirname $file]
|
||||
# <20><><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD>
|
||||
set name [file rootname $file]
|
||||
# <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
||||
set ext [string range [file extension $file] 1 end]
|
||||
if {$ext == ""} {
|
||||
#puts "$file - <20><><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>"
|
||||
set ext "tex"
|
||||
set file $file.$ext
|
||||
#puts $file
|
||||
}
|
||||
|
||||
regsub -all -nocase -- {/| |\.} $dirName $dot nodeEnd
|
||||
regsub -all -nocase -- { |\.} $name $dot name
|
||||
|
||||
if {} {
|
||||
|
||||
}
|
||||
|
||||
set subNode "$nodeEnd$dot$name$dot$ext"
|
||||
#set subNode "$nodeEnd$dot$ext"
|
||||
#puts "file - $file\n"
|
||||
#puts "dirName - $dirName\n"
|
||||
#puts "rootNode - $rootNode\n"
|
||||
#puts "nodeEnd - $nodeEnd\n"
|
||||
#puts "name - $name\n"
|
||||
#puts "subnode - $subNode\n"
|
||||
if {[$tree exists $subNode] == 1} {
|
||||
if {[$tree parent $subNode] == "root"} {
|
||||
$tree delete $subNode
|
||||
} else {
|
||||
return
|
||||
}
|
||||
}
|
||||
$tree insert end $rootNode $subNode -text $file \
|
||||
-data [file join $dirName $file] -open 1\
|
||||
-image [Bitmap::get [file join $dir(img) tex.gif]]\
|
||||
-font $font(normal)
|
||||
$tree configure -redraw 1
|
||||
return $subNode
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
Reference in New Issue
Block a user