2022-07-21 10:56:46 +03:00
|
|
|
|
######################################################
|
|
|
|
|
# ProjMan 2
|
|
|
|
|
# Distributed under GNU Public License
|
|
|
|
|
# Author: Sergey Kalinin svk@nuk-svk.ru
|
|
|
|
|
# Copyright (c) "SVK", 2022, https://nuk-svk.ru
|
|
|
|
|
######################################################
|
|
|
|
|
# Editor module
|
|
|
|
|
######################################################
|
2018-02-05 11:24:14 +03:00
|
|
|
|
|
2022-07-21 10:56:46 +03:00
|
|
|
|
namespace eval Editor {
|
|
|
|
|
variable selectionTex
|
2022-08-30 16:44:28 +03:00
|
|
|
|
# Set the editor option
|
|
|
|
|
proc SetOption {optionName value} {
|
|
|
|
|
global cfgVariables nbEditor
|
|
|
|
|
# apply changes for opened tabs
|
|
|
|
|
foreach node [$nbEditor tabs] {
|
|
|
|
|
$node.frmText.t configure -$optionName $value
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
# Comment one string or selected string
|
2022-08-12 15:24:39 +03:00
|
|
|
|
proc Comment {txt fileType} {
|
2022-08-24 15:53:57 +03:00
|
|
|
|
global lexers
|
2022-07-21 10:56:46 +03:00
|
|
|
|
set selIndex [$txt tag ranges sel]
|
|
|
|
|
set pos [$txt index insert]
|
|
|
|
|
set lineNum [lindex [split $pos "."] 0]
|
|
|
|
|
set PosNum [lindex [split $pos "."] 1]
|
2022-08-30 16:44:28 +03:00
|
|
|
|
|
2022-08-24 15:53:57 +03:00
|
|
|
|
if [dict exists $lexers $fileType commentSymbol] {
|
|
|
|
|
set symbol [dict get $lexers $fileType commentSymbol]
|
|
|
|
|
} else {
|
|
|
|
|
set symbol "#"
|
2022-08-12 15:24:39 +03:00
|
|
|
|
}
|
2022-07-21 10:56:46 +03:00
|
|
|
|
puts "Select : $selIndex"
|
|
|
|
|
if {$selIndex != ""} {
|
|
|
|
|
set lineBegin [lindex [split [lindex $selIndex 0] "."] 0]
|
|
|
|
|
set lineEnd [lindex [split [lindex $selIndex 1] "."] 0]
|
|
|
|
|
set posBegin [lindex [split [lindex $selIndex 1] "."] 0]
|
|
|
|
|
set posEnd [lindex [split [lindex $selIndex 1] "."] 1]
|
2022-07-25 16:04:25 +03:00
|
|
|
|
if {$lineEnd == $lineNum && $posEnd == 0} {
|
2022-07-21 10:56:46 +03:00
|
|
|
|
set lineEnd [expr $lineEnd - 1]
|
2018-02-05 11:24:14 +03:00
|
|
|
|
}
|
2022-07-21 10:56:46 +03:00
|
|
|
|
for {set i $lineBegin} {$i <=$lineEnd} {incr i} {
|
|
|
|
|
#$txt insert $i.0 "# "
|
|
|
|
|
regexp -nocase -indices -- {^(\s*)(.*?)} [$txt get $i.0 $i.end] match v1 v2
|
2022-08-12 15:24:39 +03:00
|
|
|
|
$txt insert $i.[lindex [split $v2] 0] "$symbol "
|
2018-02-05 11:24:14 +03:00
|
|
|
|
}
|
2022-07-21 10:56:46 +03:00
|
|
|
|
$txt tag add comments $lineBegin.0 $lineEnd.end
|
|
|
|
|
$txt tag raise comments
|
|
|
|
|
} else {
|
|
|
|
|
regexp -nocase -indices -- {^(\s*)(.*?)} [$txt get $lineNum.0 $lineNum.end] match v1 v2
|
2022-08-12 15:24:39 +03:00
|
|
|
|
$txt insert $lineNum.[lindex [split $v2] 0] "$symbol "
|
2022-07-21 10:56:46 +03:00
|
|
|
|
$txt tag add comments $lineNum.0 $lineNum.end
|
|
|
|
|
$txt tag raise comments
|
2018-02-05 11:24:14 +03:00
|
|
|
|
}
|
2022-07-21 10:56:46 +03:00
|
|
|
|
}
|
2022-08-30 16:44:28 +03:00
|
|
|
|
|
|
|
|
|
# Uncomment one string selected strings
|
2022-08-12 15:24:39 +03:00
|
|
|
|
proc Uncomment {txt fileType} {
|
2022-07-21 10:56:46 +03:00
|
|
|
|
set selIndex [$txt tag ranges sel]
|
|
|
|
|
set pos [$txt index insert]
|
|
|
|
|
set lineNum [lindex [split $pos "."] 0]
|
|
|
|
|
set posNum [lindex [split $pos "."] 1]
|
2022-08-12 15:24:39 +03:00
|
|
|
|
|
|
|
|
|
if {[info procs GetComment:$fileType] ne ""} {
|
|
|
|
|
set commentProcedure "GetComment:$fileType"
|
|
|
|
|
} else {
|
|
|
|
|
set commentProcedure {GetComment:Unknown}
|
|
|
|
|
}
|
2022-08-24 15:53:57 +03:00
|
|
|
|
# set commentProcedure "GetComment"
|
|
|
|
|
|
2022-08-12 15:24:39 +03:00
|
|
|
|
# puts "$fileType, $commentProcedure"
|
2022-07-21 10:56:46 +03:00
|
|
|
|
if {$selIndex != ""} {
|
|
|
|
|
set lineBegin [lindex [split [lindex $selIndex 0] "."] 0]
|
|
|
|
|
set lineEnd [lindex [split [lindex $selIndex 1] "."] 0]
|
|
|
|
|
set posBegin [lindex [split [lindex $selIndex 1] "."] 0]
|
|
|
|
|
set posEnd [lindex [split [lindex $selIndex 1] "."] 1]
|
2022-07-27 16:55:04 +03:00
|
|
|
|
if {$lineEnd == $lineNum && $posEnd == 0} {
|
2022-07-21 10:56:46 +03:00
|
|
|
|
set lineEnd [expr $lineEnd - 1]
|
|
|
|
|
}
|
|
|
|
|
for {set i $lineBegin} {$i <=$lineEnd} {incr i} {
|
|
|
|
|
set str [$txt get $i.0 $i.end]
|
2022-08-12 15:24:39 +03:00
|
|
|
|
set commentSymbolIndex [$commentProcedure $str]
|
|
|
|
|
if {$commentSymbolIndex != 0} {
|
|
|
|
|
$txt delete $i.[lindex $commentSymbolIndex 0] $i.[lindex $commentSymbolIndex 1]
|
2018-02-05 11:24:14 +03:00
|
|
|
|
}
|
|
|
|
|
}
|
2022-08-24 15:53:57 +03:00
|
|
|
|
$txt tag remove comments $lineBegin.0 $lineEnd.end
|
|
|
|
|
$txt tag add sel $lineBegin.0 $lineEnd.end
|
|
|
|
|
$txt highlight $lineBegin.0 $lineEnd.end
|
2022-07-21 10:56:46 +03:00
|
|
|
|
} else {
|
2022-08-12 15:24:39 +03:00
|
|
|
|
set posNum [lindex [split $pos "."] 1]
|
2022-07-21 10:56:46 +03:00
|
|
|
|
set str [$txt get $lineNum.0 $lineNum.end]
|
2022-08-12 15:24:39 +03:00
|
|
|
|
set commentSymbolIndex [$commentProcedure $str]
|
|
|
|
|
if {$commentSymbolIndex != 0} {
|
|
|
|
|
$txt delete $lineNum.[lindex $commentSymbolIndex 0] $lineNum.[lindex $commentSymbolIndex 1]
|
2022-07-21 10:56:46 +03:00
|
|
|
|
}
|
|
|
|
|
$txt tag remove comments $lineNum.0 $lineNum.end
|
|
|
|
|
$txt highlight $lineNum.0 $lineNum.end
|
2018-02-05 11:24:14 +03:00
|
|
|
|
}
|
|
|
|
|
}
|
2022-08-24 15:53:57 +03:00
|
|
|
|
proc GetComment {fileType str} {
|
|
|
|
|
global lexers
|
|
|
|
|
puts [dict get $lexers $fileType commentSymbol]
|
|
|
|
|
if {[dict exists $lexers $fileType commentSymbol] == 0} {
|
|
|
|
|
return
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if {[regexp -nocase -indices -- {(^| )([dict get $lexers $fileType commentSymbol]\s)(.+)} $str match v1 v2 v3]} {
|
|
|
|
|
puts "$match, $v1, $v2, $v3"
|
|
|
|
|
return [list [lindex [split $v2] 0] [lindex [split $v3] 0]]
|
|
|
|
|
} else {
|
|
|
|
|
return 0
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2022-08-12 15:24:39 +03:00
|
|
|
|
proc GetComment:TCL {str} {
|
|
|
|
|
if {[regexp -nocase -indices -- {(^| )(#\s)(.+)} $str match v1 v2 v3]} {
|
|
|
|
|
return [list [lindex [split $v2] 0] [lindex [split $v3] 0]]
|
|
|
|
|
} else {
|
|
|
|
|
return 0
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
proc GetComment:GO {str} {
|
|
|
|
|
# puts ">>>>>>>$str"
|
|
|
|
|
if {[regexp -nocase -indices -- {(^| |\t)(//\s)(.+)} $str match v1 v2 v3]} {
|
|
|
|
|
# puts ">>>> $match $v1 $v2 $v3"
|
|
|
|
|
return [list [lindex [split $v2] 0] [lindex [split $v3] 0]]
|
|
|
|
|
} else {
|
|
|
|
|
return 0
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
proc GetComment:Unknown {str} {
|
|
|
|
|
if {[regexp -nocase -indices -- {(^| )(#\s)(.+)} $str match v1 v2 v3]} {
|
|
|
|
|
return [list [lindex [split $v2] 0] [lindex [split $v3] 0]]
|
|
|
|
|
} else {
|
|
|
|
|
return 0
|
|
|
|
|
}
|
|
|
|
|
}
|
2018-02-05 11:24:14 +03:00
|
|
|
|
|
2022-07-21 10:56:46 +03:00
|
|
|
|
proc InsertTabular {txt} {
|
2022-09-02 17:01:53 +03:00
|
|
|
|
global cfgVariables lexers editors
|
2022-07-21 10:56:46 +03:00
|
|
|
|
set selIndex [$txt tag ranges sel]
|
|
|
|
|
set pos [$txt index insert]
|
|
|
|
|
set lineNum [lindex [split $pos "."] 0]
|
2022-09-02 17:01:53 +03:00
|
|
|
|
set fileType [dict get $editors $txt fileType]
|
|
|
|
|
if {[dict exists $lexers $fileType tabSize] != 0 } {
|
|
|
|
|
set tabSize [dict get $lexers $fileType tabSize]
|
|
|
|
|
} else {
|
|
|
|
|
set tabSize $cfgVariables(tabSize)
|
|
|
|
|
}
|
2022-08-26 15:43:56 +03:00
|
|
|
|
# puts "Select : $selIndex"
|
2022-09-02 17:01:53 +03:00
|
|
|
|
for {set i 0} {$i < $tabSize} { incr i} {
|
2022-07-21 10:56:46 +03:00
|
|
|
|
append tabInsert " "
|
2018-02-05 11:24:14 +03:00
|
|
|
|
}
|
2022-08-26 15:43:56 +03:00
|
|
|
|
# puts ">$tabInsert<"
|
2022-07-21 10:56:46 +03:00
|
|
|
|
if {$selIndex != ""} {
|
|
|
|
|
set lineBegin [lindex [split [lindex $selIndex 0] "."] 0]
|
|
|
|
|
set lineEnd [lindex [split [lindex $selIndex 1] "."] 0]
|
|
|
|
|
set posBegin [lindex [split [lindex $selIndex 1] "."] 0]
|
|
|
|
|
set posEnd [lindex [split [lindex $selIndex 1] "."] 1]
|
|
|
|
|
# if {$lineBegin == $lineNum} {
|
|
|
|
|
# set lineBegin [expr $lineBegin + 1]
|
|
|
|
|
# }
|
|
|
|
|
if {$lineEnd == $lineNum || $posEnd == 0} {
|
|
|
|
|
set lineEnd [expr $lineEnd - 1]
|
|
|
|
|
}
|
2022-08-26 15:43:56 +03:00
|
|
|
|
# puts "Pos: $pos, Begin: $lineBegin, End: $lineEnd"
|
2022-07-21 10:56:46 +03:00
|
|
|
|
for {set i $lineBegin} {$i <=$lineEnd} {incr i} {
|
|
|
|
|
#$txt insert $i.0 "# "
|
|
|
|
|
regexp -nocase -indices -- {^(\s*)(.*?)} [$txt get $i.0 $i.end] match v1 v2
|
|
|
|
|
$txt insert $i.[lindex [split $v2] 0] $tabInsert
|
|
|
|
|
}
|
|
|
|
|
$txt tag remove sel $lineBegin.$posBegin $lineEnd.$posEnd
|
|
|
|
|
$txt tag add sel $lineBegin.0 $lineEnd.end
|
|
|
|
|
$txt highlight $lineBegin.0 $lineEnd.end
|
2018-02-05 11:24:14 +03:00
|
|
|
|
} else {
|
2022-07-21 10:56:46 +03:00
|
|
|
|
# set pos [$txt index insert]
|
|
|
|
|
# set lineNum [lindex [split $pos "."] 0]
|
|
|
|
|
regexp -nocase -indices -- {^(\s*)(.*?)} [$txt get $lineNum.0 $lineNum.end] match v1 v2
|
2022-08-26 15:43:56 +03:00
|
|
|
|
# puts "$v1<>$v2"
|
2022-07-21 10:56:46 +03:00
|
|
|
|
$txt insert $lineNum.[lindex [split $v2] 0] $tabInsert
|
2018-02-05 11:24:14 +03:00
|
|
|
|
}
|
2022-07-21 10:56:46 +03:00
|
|
|
|
}
|
|
|
|
|
proc DeleteTabular {txt} {
|
2022-09-02 17:01:53 +03:00
|
|
|
|
global cfgVariables lexers editors
|
2022-07-21 10:56:46 +03:00
|
|
|
|
set selIndex [$txt tag ranges sel]
|
|
|
|
|
set pos [$txt index insert]
|
2022-09-02 17:01:53 +03:00
|
|
|
|
set fileType [dict get $editors $txt fileType]
|
|
|
|
|
if {[dict exists $lexers $fileType tabSize] != 0 } {
|
|
|
|
|
set tabSize [dict get $lexers $fileType tabSize]
|
|
|
|
|
} else {
|
|
|
|
|
set tabSize $cfgVariables(tabSize)
|
|
|
|
|
}
|
2022-07-21 10:56:46 +03:00
|
|
|
|
set lineNum [lindex [split $pos "."] 0]
|
|
|
|
|
if {$selIndex != ""} {
|
|
|
|
|
set lineBegin [lindex [split [lindex $selIndex 0] "."] 0]
|
|
|
|
|
set lineEnd [lindex [split [lindex $selIndex 1] "."] 0]
|
|
|
|
|
set posBegin [lindex [split [lindex $selIndex 1] "."] 0]
|
|
|
|
|
set posEnd [lindex [split [lindex $selIndex 1] "."] 1]
|
|
|
|
|
if {$lineEnd == $lineNum && $posEnd == 0} {
|
|
|
|
|
set lineEnd [expr $lineEnd - 1]
|
|
|
|
|
}
|
|
|
|
|
for {set i $lineBegin} {$i <=$lineEnd} {incr i} {
|
|
|
|
|
set str [$txt get $i.0 $i.end]
|
|
|
|
|
if {[regexp -nocase -indices -- {(^\s*)(.*?)} $str match v1 v2]} {
|
|
|
|
|
set posBegin [lindex [split $v1] 0]
|
|
|
|
|
set posEnd [lindex [split $v1] 1]
|
2022-09-02 17:01:53 +03:00
|
|
|
|
if {[expr $posEnd + 1] >= $tabSize} {
|
|
|
|
|
$txt delete $i.$posBegin $i.$tabSize
|
2022-07-21 10:56:46 +03:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
$txt tag remove sel $lineBegin.$posBegin $lineEnd.$posEnd
|
|
|
|
|
$txt tag add sel $lineBegin.0 $lineEnd.end
|
|
|
|
|
$txt highlight $lineBegin.0 $lineEnd.end
|
2018-02-05 11:24:14 +03:00
|
|
|
|
} else {
|
2022-07-21 10:56:46 +03:00
|
|
|
|
set str [$txt get $lineNum.0 $lineNum.end]
|
2022-08-26 15:43:56 +03:00
|
|
|
|
puts ">>>>> $str"
|
2022-07-21 10:56:46 +03:00
|
|
|
|
if {[regexp -nocase -indices -- {(^\s*)(.*?)} $str match v1]} {
|
|
|
|
|
set posBegin [lindex [split $v1] 0]
|
|
|
|
|
set posEnd [lindex [split $v1] 1]
|
2022-09-02 17:01:53 +03:00
|
|
|
|
if {[expr $posEnd + 1] >= $tabSize} {
|
|
|
|
|
$txt delete $lineNum.$posBegin $lineNum.$tabSize
|
2022-07-21 10:56:46 +03:00
|
|
|
|
}
|
|
|
|
|
}
|
2018-02-05 11:24:14 +03:00
|
|
|
|
}
|
|
|
|
|
}
|
2022-07-21 10:56:46 +03:00
|
|
|
|
## TABULAR INSERT (auto indent)##
|
|
|
|
|
proc Indent {txt} {
|
2022-09-02 17:01:53 +03:00
|
|
|
|
global cfgVariables lexers editors
|
2022-07-21 10:56:46 +03:00
|
|
|
|
# set tabSize 4
|
2022-09-02 17:01:53 +03:00
|
|
|
|
set fileType [dict get $editors $txt fileType]
|
|
|
|
|
if {[dict exists $lexers $fileType tabSize] != 0 } {
|
|
|
|
|
set tabSize [dict get $lexers $fileType tabSize]
|
|
|
|
|
} else {
|
|
|
|
|
set tabSize $cfgVariables(tabSize)
|
|
|
|
|
}
|
|
|
|
|
set indentSize $tabSize
|
2022-07-21 10:56:46 +03:00
|
|
|
|
set pos [$txt index insert]
|
|
|
|
|
set lineNum [lindex [split $pos "."] 0]
|
|
|
|
|
set posNum [lindex [split $pos "."] 1]
|
|
|
|
|
puts "$pos"
|
|
|
|
|
if {$lineNum > 1} {
|
|
|
|
|
# get current text
|
|
|
|
|
set curText [$txt get $lineNum.0 "$lineNum.0 lineend"]
|
|
|
|
|
#get text of prev line
|
|
|
|
|
set prevLineNum [expr {$lineNum - 1}]
|
|
|
|
|
set prevText [$txt get $prevLineNum.0 "$prevLineNum.0 lineend"]
|
|
|
|
|
#count first spaces in current line
|
|
|
|
|
set spaces ""
|
|
|
|
|
regexp "^| *" $curText spaces
|
|
|
|
|
#count first spaces in prev line
|
|
|
|
|
set prevSpaces ""
|
|
|
|
|
regexp "^( |\t)*" $prevText prevSpaces
|
|
|
|
|
set len [string length $prevSpaces]
|
|
|
|
|
set shouldBeSpaces 0
|
|
|
|
|
for {set i 0} {$i < $len} {incr i} {
|
|
|
|
|
if {[string index $prevSpaces $i] == "\t"} {
|
2022-09-02 17:01:53 +03:00
|
|
|
|
incr shouldBeSpaces $tabSize
|
2022-07-21 10:56:46 +03:00
|
|
|
|
} else {
|
|
|
|
|
incr shouldBeSpaces
|
|
|
|
|
}
|
2018-02-05 11:24:14 +03:00
|
|
|
|
}
|
2022-07-21 10:56:46 +03:00
|
|
|
|
#see last symbol in the prev String.
|
|
|
|
|
set lastSymbol [string index $prevText [expr {[string length $prevText] - 1}]]
|
|
|
|
|
# is it open brace?
|
|
|
|
|
if {$lastSymbol == ":" || $lastSymbol == "\\"} {
|
|
|
|
|
incr shouldBeSpaces $indentSize
|
2018-02-08 11:07:14 +03:00
|
|
|
|
}
|
2022-07-21 10:56:46 +03:00
|
|
|
|
if {$lastSymbol == "\{"} {
|
|
|
|
|
incr shouldBeSpaces $indentSize
|
2018-02-08 11:07:14 +03:00
|
|
|
|
}
|
2022-07-21 10:56:46 +03:00
|
|
|
|
set a ""
|
|
|
|
|
regexp "^| *\}" $curText a
|
|
|
|
|
if {$a != ""} {
|
|
|
|
|
# make unindent
|
|
|
|
|
if {$shouldBeSpaces >= $indentSize} {
|
|
|
|
|
set shouldBeSpaces [expr {$shouldBeSpaces - $indentSize}]
|
|
|
|
|
}
|
2018-02-05 11:24:14 +03:00
|
|
|
|
}
|
2022-07-21 10:56:46 +03:00
|
|
|
|
if {$lastSymbol == "\["} {
|
|
|
|
|
incr shouldBeSpaces $indentSize
|
|
|
|
|
}
|
|
|
|
|
set a ""
|
|
|
|
|
regexp "^| *\]" $curText a
|
|
|
|
|
if {$a != ""} {
|
|
|
|
|
# make unindent
|
|
|
|
|
if {$shouldBeSpaces >= $indentSize} {
|
|
|
|
|
set shouldBeSpaces [expr {$shouldBeSpaces - $indentSize}]
|
2018-02-05 11:24:14 +03:00
|
|
|
|
}
|
|
|
|
|
}
|
2022-07-21 10:56:46 +03:00
|
|
|
|
if {$lastSymbol == "\("} {
|
|
|
|
|
incr shouldBeSpaces $indentSize
|
|
|
|
|
}
|
|
|
|
|
set a ""
|
|
|
|
|
regexp {^| *\)} $curText a
|
|
|
|
|
if {$a != ""} {
|
|
|
|
|
# make unindent
|
|
|
|
|
if {$shouldBeSpaces >= $indentSize} {
|
|
|
|
|
set shouldBeSpaces [expr {$shouldBeSpaces - $indentSize}]
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
set spaceNum [string length $spaces]
|
|
|
|
|
if {$shouldBeSpaces > $spaceNum} {
|
|
|
|
|
#insert spaces
|
|
|
|
|
set deltaSpace [expr {$shouldBeSpaces - $spaceNum}]
|
|
|
|
|
set incSpaces ""
|
|
|
|
|
for {set i 0} {$i < $deltaSpace} {incr i} {
|
|
|
|
|
append incSpaces " "
|
2018-02-05 11:24:14 +03:00
|
|
|
|
}
|
2022-07-21 10:56:46 +03:00
|
|
|
|
$txt insert $lineNum.0 $incSpaces
|
|
|
|
|
} elseif {$shouldBeSpaces < $spaceNum} {
|
|
|
|
|
#delete spaces
|
|
|
|
|
set deltaSpace [expr {$spaceNum - $shouldBeSpaces}]
|
|
|
|
|
$txt delete $lineNum.0 $lineNum.$deltaSpace
|
|
|
|
|
}
|
2018-02-05 11:24:14 +03:00
|
|
|
|
}
|
|
|
|
|
}
|
2022-07-21 10:56:46 +03:00
|
|
|
|
proc SelectionPaste {txt} {
|
|
|
|
|
set selBegin [lindex [$txt tag ranges sel] 0]
|
|
|
|
|
set selEnd [lindex [$txt tag ranges sel] 1]
|
|
|
|
|
if {$selBegin ne ""} {
|
|
|
|
|
$txt delete $selBegin $selEnd
|
|
|
|
|
$txt highlight $selBegin $selEnd
|
|
|
|
|
#tk_textPaste $txt
|
2018-02-05 11:24:14 +03:00
|
|
|
|
}
|
|
|
|
|
}
|
2022-08-16 15:23:12 +03:00
|
|
|
|
|
2022-07-21 10:56:46 +03:00
|
|
|
|
proc SelectionGet {txt} {
|
|
|
|
|
variable selectionText
|
|
|
|
|
set selBegin [lindex [$txt tag ranges sel] 0]
|
|
|
|
|
set selEnd [lindex [$txt tag ranges sel] 1]
|
|
|
|
|
if {$selBegin ne "" && $selEnd ne ""} {
|
|
|
|
|
set selectionText [$txt get $selBegin $selEnd]
|
|
|
|
|
}
|
2018-02-05 12:08:16 +03:00
|
|
|
|
}
|
2022-08-16 15:23:12 +03:00
|
|
|
|
|
|
|
|
|
proc SelectionHighlight {txt} {
|
|
|
|
|
variable selectionText
|
|
|
|
|
|
|
|
|
|
$txt tag remove lightSelected 1.0 end
|
|
|
|
|
|
|
|
|
|
set selBegin [lindex [$txt tag ranges sel] 0]
|
|
|
|
|
set selEnd [lindex [$txt tag ranges sel] 1]
|
|
|
|
|
if {$selBegin ne "" && $selEnd ne ""} {
|
|
|
|
|
set selectionText [$txt get $selBegin $selEnd]
|
|
|
|
|
# set selBeginRow [lindex [split $selBegin "."] 1]
|
|
|
|
|
# set selEndRow [lindex [split $selEnd "."] 1]
|
|
|
|
|
# puts "$selBegin, $selBeginRow; $selEnd, $selEndRow"
|
|
|
|
|
# set symNumbers [expr $selEndRow - $selBeginRow]
|
|
|
|
|
set symNumbers [expr [lindex [split $selEnd "."] 1] - [lindex [split $selBegin "."] 1]]
|
|
|
|
|
# puts "Selection $selectionText"
|
2022-09-01 16:54:34 +03:00
|
|
|
|
if [string match "-*" $selectionText] {
|
|
|
|
|
set selectionText "\$selectionText"
|
2022-08-16 15:23:12 +03:00
|
|
|
|
}
|
|
|
|
|
set lstFindIndex [$txt search -all "$selectionText" 0.0]
|
|
|
|
|
foreach ind $lstFindIndex {
|
|
|
|
|
set selFindLine [lindex [split $ind "."] 0]
|
|
|
|
|
set selFindRow [lindex [split $ind "."] 1]
|
|
|
|
|
set endInd "$selFindLine.[expr $selFindRow + $symNumbers]"
|
|
|
|
|
# puts "$ind; $symNumbers; $selFindLine, $selFindRow; $endInd "
|
|
|
|
|
$txt tag add lightSelected $ind $endInd
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
}
|
2022-11-03 15:58:07 +03:00
|
|
|
|
proc VarHelperKey { widget K A } {
|
|
|
|
|
set win .varhelper
|
2022-11-08 12:54:28 +03:00
|
|
|
|
# if { [winfo exists $win] == 0 } { return }
|
2022-11-03 15:58:07 +03:00
|
|
|
|
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]]
|
2022-11-08 12:54:28 +03:00
|
|
|
|
# eval [bind VarHelperBind <Escape>]
|
|
|
|
|
Editor::VarHelperEscape $widget
|
2022-11-03 15:58:07 +03:00
|
|
|
|
}
|
|
|
|
|
default {
|
|
|
|
|
$widget insert "insert" $A
|
2022-11-08 12:54:28 +03:00
|
|
|
|
# eval [bind VarHelperBind <Escape>]
|
|
|
|
|
Editor::VarHelperEscape $widget
|
2022-11-03 15:58:07 +03:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
} ;# proc auto_completition_key
|
2022-11-08 12:54:28 +03:00
|
|
|
|
proc VarHelperEscape {w} {
|
|
|
|
|
puts "VarHelperEscape"
|
|
|
|
|
bindtags $w.t [list [winfo parent $w.t] $w.t Text sysAfter all]
|
|
|
|
|
bindtags $w [list [winfo toplevel $w] $w Ctext sysAfter all]
|
|
|
|
|
catch { destroy .varhelper }
|
|
|
|
|
puts [bindtags $w]
|
|
|
|
|
puts [bind $w]
|
|
|
|
|
puts [bindtags $w.t]
|
|
|
|
|
puts [bind $w.t]
|
|
|
|
|
}
|
2022-08-16 15:23:12 +03:00
|
|
|
|
|
2022-11-08 12:54:28 +03:00
|
|
|
|
proc VarHelper {x y w word wordType} {
|
2022-10-28 13:27:54 +03:00
|
|
|
|
global editors lexers variables
|
|
|
|
|
variable txt
|
|
|
|
|
variable win
|
|
|
|
|
# set txt $w.frmText.t
|
2022-11-11 12:41:52 +03:00
|
|
|
|
# блокировка открытия диалога если запущен другой
|
|
|
|
|
if [winfo exists .findVariables] {
|
|
|
|
|
return
|
|
|
|
|
}
|
2022-10-28 13:27:54 +03:00
|
|
|
|
set txt $w
|
|
|
|
|
set win .varhelper
|
2022-11-08 12:54:28 +03:00
|
|
|
|
puts "$x $y $w $word $wordType"
|
|
|
|
|
set fileType [dict get $editors $txt fileType]
|
|
|
|
|
|
2022-11-03 15:58:07 +03:00
|
|
|
|
if {[dict exists $editors $txt variableList] != 0} {
|
|
|
|
|
set varList [dict get $editors $txt variableList]
|
2022-11-08 12:54:28 +03:00
|
|
|
|
# puts $varList
|
2022-11-03 15:58:07 +03:00
|
|
|
|
}
|
|
|
|
|
if {[dict exists $editors $txt procedureList] != 0} {
|
|
|
|
|
set procList [dict get $editors $txt procedureList]
|
|
|
|
|
}
|
2022-11-08 12:54:28 +03:00
|
|
|
|
# puts $procList
|
|
|
|
|
# puts ">>>>>>>[dict get $lexers $fileType commands]"
|
|
|
|
|
if {[dict exists $lexers $fileType commands] !=0} {
|
|
|
|
|
foreach i [dict get $lexers $fileType commands] {
|
|
|
|
|
# puts $i
|
|
|
|
|
lappend procList $i
|
|
|
|
|
}
|
2022-11-03 15:58:07 +03:00
|
|
|
|
}
|
2022-11-08 12:54:28 +03:00
|
|
|
|
|
|
|
|
|
# if {[dict exists $editors $txt variableList] == 0 && [dict exists $editors $txt procedureList] == 0} {
|
|
|
|
|
# return
|
|
|
|
|
# }
|
2022-10-28 13:27:54 +03:00
|
|
|
|
set findedVars ""
|
2022-11-08 12:54:28 +03:00
|
|
|
|
switch -- $wordType {
|
|
|
|
|
vars {
|
|
|
|
|
foreach i [lsearch -nocase -all $varList $word*] {
|
|
|
|
|
# puts [lindex $varList $i]
|
|
|
|
|
set item [lindex [lindex $varList $i] 0]
|
|
|
|
|
# puts $item
|
|
|
|
|
if {[lsearch $findedVars $item] eq "-1"} {
|
|
|
|
|
lappend findedVars $item
|
|
|
|
|
# puts $item
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
procedure {
|
|
|
|
|
foreach i [lsearch -nocase -all $procList $word*] {
|
|
|
|
|
# puts [lindex $varList $i]
|
|
|
|
|
set item [lindex [lindex $procList $i] 0]
|
|
|
|
|
# puts $item
|
|
|
|
|
if {[lsearch $findedVars $item] eq "-1"} {
|
|
|
|
|
lappend findedVars $item
|
|
|
|
|
# puts $item
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
default {
|
|
|
|
|
foreach i [lsearch -nocase -all $varList $word*] {
|
|
|
|
|
# puts [lindex $varList $i]
|
|
|
|
|
set item [lindex [lindex $varList $i] 0]
|
|
|
|
|
# puts $item
|
|
|
|
|
if {[lsearch $findedVars $item] eq "-1"} {
|
|
|
|
|
lappend findedVars $item
|
|
|
|
|
# puts $item
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
foreach i [lsearch -nocase -all $procList $word*] {
|
|
|
|
|
# puts [lindex $varList $i]
|
|
|
|
|
set item [lindex [lindex $procList $i] 0]
|
|
|
|
|
# puts $item
|
|
|
|
|
if {[lsearch $findedVars $item] eq "-1"} {
|
|
|
|
|
lappend findedVars $item
|
|
|
|
|
# puts $item
|
|
|
|
|
}
|
|
|
|
|
}
|
2022-10-28 13:27:54 +03:00
|
|
|
|
}
|
|
|
|
|
}
|
2022-11-08 12:54:28 +03:00
|
|
|
|
# unset item
|
|
|
|
|
# puts $findedVars
|
|
|
|
|
bindtags $txt [list VarHelperBind [winfo toplevel $txt] $txt Ctext sysAfter all]
|
|
|
|
|
# bindtags $txt.t [list VarHelperBind [winfo parent $txt.t] $txt.t Text sysAfter all]
|
|
|
|
|
bind VarHelperBind <Escape> "Editor::VarHelperEscape $txt; break"
|
|
|
|
|
# bindtags $txt.t {[list [winfo parent $txt.t] $txt.t Text sysAfter all]};
|
|
|
|
|
# bindtags $txt {[list [winfo toplevel $txt] $txt Ctext sysAfter all]};
|
|
|
|
|
# catch { destroy .varhelper }"
|
|
|
|
|
bind VarHelperBind <Key> {Editor::VarHelperKey $Editor::txt %K %A; break}
|
2022-11-03 15:58:07 +03:00
|
|
|
|
|
2022-10-28 13:27:54 +03:00
|
|
|
|
if { [winfo exists $win] } { destroy $win }
|
|
|
|
|
if {$findedVars eq ""} {
|
|
|
|
|
return
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
toplevel $win
|
|
|
|
|
wm transient $win .
|
|
|
|
|
wm overrideredirect $win 1
|
|
|
|
|
|
2022-11-08 12:54:28 +03:00
|
|
|
|
listbox $win.lBox -width 30 -border 0
|
2022-10-28 13:27:54 +03:00
|
|
|
|
pack $win.lBox -expand true -fill y -side left
|
|
|
|
|
|
2022-11-08 12:54:28 +03:00
|
|
|
|
foreach { item } $findedVars {
|
|
|
|
|
$win.lBox insert end $item
|
2022-10-28 13:27:54 +03:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
catch { $win.lBox activate 0 ; $win.lBox selection set 0 0 }
|
|
|
|
|
|
|
|
|
|
if { [set height [llength $findedVars]] > 10 } { set height 10 }
|
|
|
|
|
$win.lBox configure -height $height
|
2022-11-03 15:58:07 +03:00
|
|
|
|
|
2022-10-28 16:45:33 +03:00
|
|
|
|
bind $win <Escape> {
|
2022-10-28 13:27:54 +03:00
|
|
|
|
destroy $Editor::win
|
|
|
|
|
focus -force $Editor::txt.t
|
|
|
|
|
break
|
|
|
|
|
}
|
|
|
|
|
bind $win.lBox <Escape> {
|
|
|
|
|
destroy $Editor::win
|
|
|
|
|
focus -force $Editor::txt.t
|
|
|
|
|
break
|
|
|
|
|
}
|
2022-11-03 15:58:07 +03:00
|
|
|
|
# bind $win.lBox <Return> {
|
|
|
|
|
# set findString [dict get $lexers [dict get $editors $Editor::txt fileType] procFindString]
|
|
|
|
|
# set values [.varhelper.lBox get [.varhelper.lBox curselection]]
|
|
|
|
|
# regsub -all {PROCNAME} $findString $values str
|
|
|
|
|
# Editor::FindFunction $Editor::txt "$str"
|
|
|
|
|
# destroy .varhelper.lBox
|
|
|
|
|
# # focus $Editor::txt.t
|
2022-10-28 16:45:33 +03:00
|
|
|
|
# break
|
|
|
|
|
# }
|
2022-11-01 11:23:54 +03:00
|
|
|
|
|
2022-10-28 13:27:54 +03:00
|
|
|
|
# Определям расстояние до края экрана (основного окна) и если
|
|
|
|
|
# оно меньше размера окна со списком то сдвигаем его вверх
|
2022-11-01 11:23:54 +03:00
|
|
|
|
set winGeomY [winfo reqheight $win]
|
|
|
|
|
set winGeomX [winfo reqwidth $win]
|
|
|
|
|
|
2022-10-28 13:27:54 +03:00
|
|
|
|
set topHeight [winfo height .]
|
2022-11-01 11:23:54 +03:00
|
|
|
|
set topWidth [winfo width .]
|
|
|
|
|
set topLeftUpperX [winfo x .]
|
|
|
|
|
set topLeftUpperY [winfo y .]
|
|
|
|
|
set topRightLowerX [expr $topLeftUpperX + $topWidth]
|
|
|
|
|
set topRightLowerY [expr $topLeftUpperY + $topHeight]
|
|
|
|
|
|
|
|
|
|
if {[expr [expr $x + $winGeomX] > $topRightLowerX]} {
|
|
|
|
|
set x [expr $x - $winGeomX]
|
2022-10-28 13:27:54 +03:00
|
|
|
|
}
|
2022-11-01 11:23:54 +03:00
|
|
|
|
if {[expr [expr $y + $winGeomY] > $topRightLowerY]} {
|
|
|
|
|
set y [expr $y - $winGeomY]
|
|
|
|
|
}
|
|
|
|
|
|
2022-10-28 13:27:54 +03:00
|
|
|
|
wm geom $win +$x+$y
|
|
|
|
|
}
|
|
|
|
|
|
2022-11-01 14:50:20 +03:00
|
|
|
|
proc ReleaseKey {k txt fileType} {
|
|
|
|
|
global cfgVariables lexers
|
2022-08-03 12:21:28 +03:00
|
|
|
|
set pos [$txt index insert]
|
2022-10-28 13:27:54 +03:00
|
|
|
|
set lineNum [lindex [split $pos "."] 0]
|
|
|
|
|
set posNum [lindex [split $pos "."] 1]
|
2022-11-01 16:21:02 +03:00
|
|
|
|
set box [$txt bbox insert]
|
|
|
|
|
set box_x [expr [lindex $box 0] + [winfo rootx $txt] ]
|
|
|
|
|
set box_y [expr [lindex $box 1] + [winfo rooty $txt] + [lindex $box 3] ]
|
2022-08-15 11:07:47 +03:00
|
|
|
|
SearchBrackets $txt
|
2022-11-01 16:21:02 +03:00
|
|
|
|
set lpos [split $pos "."]
|
|
|
|
|
set lblText "[::msgcat::mc "Row"]: [lindex $lpos 0], [::msgcat::mc "Column"]: [lindex $lpos 1]"
|
|
|
|
|
.frmStatus.lblPosition configure -text $lblText
|
|
|
|
|
unset lpos
|
2022-11-03 09:57:39 +03:00
|
|
|
|
$txt tag remove lightSelected 1.0 end
|
|
|
|
|
|
2022-11-08 12:54:28 +03:00
|
|
|
|
if { [winfo exists .varhelper] } { destroy .varhelper }
|
2022-11-11 12:41:52 +03:00
|
|
|
|
puts $k
|
2022-07-21 10:56:46 +03:00
|
|
|
|
switch $k {
|
|
|
|
|
Return {
|
|
|
|
|
regexp {^(\s*)} [$txt get [expr $lineNum - 1].0 [expr $lineNum - 1].end] -> spaceStart
|
2022-10-28 13:27:54 +03:00
|
|
|
|
# puts "$pos, $lineNum, $posNum, >$spaceStart<"
|
2022-07-21 10:56:46 +03:00
|
|
|
|
$txt insert insert $spaceStart
|
|
|
|
|
Editor::Indent $txt
|
2018-02-05 12:08:16 +03:00
|
|
|
|
}
|
2022-11-01 16:21:02 +03:00
|
|
|
|
Up {
|
|
|
|
|
return
|
|
|
|
|
}
|
|
|
|
|
Down {
|
|
|
|
|
return
|
|
|
|
|
}
|
|
|
|
|
Left {
|
|
|
|
|
return
|
|
|
|
|
}
|
|
|
|
|
Right {
|
|
|
|
|
return
|
|
|
|
|
}
|
2022-11-11 12:41:52 +03:00
|
|
|
|
# Shift_L {
|
|
|
|
|
# return
|
|
|
|
|
# }
|
|
|
|
|
# Shift_R {
|
|
|
|
|
# return
|
|
|
|
|
# }
|
|
|
|
|
Control_L {
|
|
|
|
|
return
|
|
|
|
|
}
|
|
|
|
|
Control_R {
|
2022-11-03 09:57:39 +03:00
|
|
|
|
return
|
|
|
|
|
}
|
2022-11-11 12:41:52 +03:00
|
|
|
|
Alt_L {
|
2022-11-03 09:57:39 +03:00
|
|
|
|
return
|
|
|
|
|
}
|
2022-11-11 12:41:52 +03:00
|
|
|
|
Alt_R {
|
2022-11-03 09:57:39 +03:00
|
|
|
|
return
|
|
|
|
|
}
|
2022-11-01 16:21:02 +03:00
|
|
|
|
}
|
|
|
|
|
# set lineStart [$txt index "$pos linestart"]
|
|
|
|
|
# puts "$pos $lineStart"
|
|
|
|
|
if {$cfgVariables(variableHelper) eq "true"} {
|
|
|
|
|
if {[dict exists $lexers $fileType variableSymbol] != 0} {
|
|
|
|
|
set varSymbol [dict get $lexers $fileType variableSymbol]
|
|
|
|
|
set lastSymbol [string last $varSymbol [$txt get $lineNum.0 $pos]]
|
|
|
|
|
if {$lastSymbol ne "-1"} {
|
|
|
|
|
set word [string trim [$txt get $lineNum.[expr $lastSymbol + 1] $pos]]
|
2022-11-08 12:54:28 +03:00
|
|
|
|
Editor::VarHelper $box_x $box_y $txt $word vars
|
2022-11-01 16:21:02 +03:00
|
|
|
|
}
|
|
|
|
|
} else {
|
|
|
|
|
set ind [$txt search -backwards -regexp {\W} $pos {insert linestart}]
|
|
|
|
|
if {$ind ne ""} {
|
|
|
|
|
set _ [split $ind "."]
|
|
|
|
|
set ind [lindex $_ 0].[expr [lindex $_ 1] + 1]
|
|
|
|
|
set word [$txt get $ind $pos]
|
2022-11-03 09:57:39 +03:00
|
|
|
|
} else {
|
2022-11-01 16:21:02 +03:00
|
|
|
|
# set ind [$txt search -backwards -regexp {^} $pos {insert linestart}]
|
|
|
|
|
set word [$txt get {insert linestart} $pos]
|
2022-11-03 09:57:39 +03:00
|
|
|
|
}
|
|
|
|
|
if {$word ne ""} {
|
2022-11-08 12:54:28 +03:00
|
|
|
|
Editor::VarHelper $box_x $box_y $txt $word {}
|
2022-11-01 16:21:02 +03:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if {$cfgVariables(procedureHelper) eq "true"} {
|
2022-11-08 12:54:28 +03:00
|
|
|
|
set ind [$txt search -backwards -regexp {\W} $pos {insert linestart}]
|
|
|
|
|
if {$ind ne ""} {
|
|
|
|
|
set _ [split $ind "."]
|
|
|
|
|
set ind [lindex $_ 0].[expr [lindex $_ 1] + 1]
|
|
|
|
|
set word [$txt get $ind $pos]
|
|
|
|
|
} else {
|
|
|
|
|
# set ind [$txt search -backwards -regexp {^} $pos {insert linestart}]
|
|
|
|
|
set word [$txt get {insert linestart} $pos]
|
|
|
|
|
}
|
|
|
|
|
if {$word ne ""} {
|
|
|
|
|
Editor::VarHelper $box_x $box_y $txt $word procedure
|
|
|
|
|
}
|
2018-02-05 12:08:16 +03:00
|
|
|
|
}
|
2022-07-21 10:56:46 +03:00
|
|
|
|
}
|
2022-08-26 15:43:56 +03:00
|
|
|
|
|
2022-07-21 10:56:46 +03:00
|
|
|
|
proc PressKey {k txt} {
|
2022-11-22 13:10:03 +03:00
|
|
|
|
# puts [Editor::Key $k ""]
|
2022-07-21 10:56:46 +03:00
|
|
|
|
switch $k {
|
2022-08-26 15:43:56 +03:00
|
|
|
|
apostrophe {
|
2022-07-21 10:56:46 +03:00
|
|
|
|
QuotSelection $txt {'}
|
2018-02-07 15:49:20 +03:00
|
|
|
|
}
|
2022-07-21 10:56:46 +03:00
|
|
|
|
quotedbl {
|
|
|
|
|
QuotSelection $txt {"}
|
|
|
|
|
}
|
|
|
|
|
grave {
|
|
|
|
|
QuotSelection $txt {`}
|
|
|
|
|
}
|
2022-11-25 12:51:21 +03:00
|
|
|
|
underscore {
|
|
|
|
|
QuotSelection $txt {_}
|
|
|
|
|
}
|
2022-07-21 10:56:46 +03:00
|
|
|
|
parenleft {
|
|
|
|
|
# QuotSelection $txt {)}
|
|
|
|
|
}
|
|
|
|
|
bracketleft {
|
|
|
|
|
# QuotSelection $txt {]}
|
|
|
|
|
}
|
|
|
|
|
braceleft {
|
|
|
|
|
# {QuotSelection} $txt {\}}
|
2018-02-07 15:49:20 +03:00
|
|
|
|
}
|
2022-08-26 15:43:56 +03:00
|
|
|
|
parentright {
|
|
|
|
|
if [string is space [$txt get {insert linestart} {insert - 1c}]] {
|
|
|
|
|
Editor::DeleteTabular $txt
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
bracketright {
|
|
|
|
|
if [string is space [$txt get {insert linestart} {insert - 1c}]] {
|
|
|
|
|
Editor::DeleteTabular $txt
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
braceright {
|
|
|
|
|
if [string is space [$txt get {insert linestart} {insert - 1c}]] {
|
|
|
|
|
Editor::DeleteTabular $txt
|
|
|
|
|
}
|
|
|
|
|
}
|
2018-02-07 15:49:20 +03:00
|
|
|
|
}
|
2018-02-05 12:08:16 +03:00
|
|
|
|
}
|
2022-07-21 10:56:46 +03:00
|
|
|
|
## GET KEYS CODE ##
|
|
|
|
|
proc Key {key str} {
|
|
|
|
|
puts "Pressed key code: $key, $str"
|
|
|
|
|
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"}
|
|
|
|
|
}
|
2022-11-22 13:10:03 +03:00
|
|
|
|
proc TextCopy {txt} {
|
|
|
|
|
# $txt tag remove sel 1.0 end
|
|
|
|
|
$txt tag add sel {insert linestart} {insert lineend + 1char}
|
|
|
|
|
tk_textCopy $txt
|
|
|
|
|
$txt tag remove sel {insert linestart} {insert lineend + 1char}
|
|
|
|
|
return
|
|
|
|
|
}
|
2022-12-01 12:37:13 +03:00
|
|
|
|
proc BindKeys {w txt fileType nb} {
|
2022-07-21 10:56:46 +03:00
|
|
|
|
global cfgVariables
|
|
|
|
|
# variable txt
|
2022-09-14 16:31:50 +03:00
|
|
|
|
# set txt $w.frmText.t
|
2022-11-08 12:54:28 +03:00
|
|
|
|
bind $txt <KeyRelease> "catch {Editor::ReleaseKey %K $txt $fileType}"
|
2022-07-21 10:56:46 +03:00
|
|
|
|
bind $txt <KeyPress> "Editor::PressKey %K $txt"
|
|
|
|
|
bind $txt <Control-igrave> "Editor::SelectionPaste $txt"
|
|
|
|
|
bind $txt <Control-v> "Editor::SelectionPaste $txt"
|
2022-11-11 12:41:52 +03:00
|
|
|
|
bind $txt <Control-l> "SearchVariable $txt; break"
|
2022-07-21 10:56:46 +03:00
|
|
|
|
bind $txt <Control-i> "ImageBase64Encode $txt"
|
2022-08-30 16:44:28 +03:00
|
|
|
|
bind $txt <Control-bracketleft> "Editor::InsertTabular $txt"
|
|
|
|
|
bind $txt <Control-bracketright> "Editor::DeleteTabular $txt"
|
2022-08-12 15:24:39 +03:00
|
|
|
|
bind $txt <Control-comma> "Editor::Comment $txt $fileType"
|
|
|
|
|
bind $txt <Control-period> "Editor::Uncomment $txt $fileType"
|
2022-07-21 10:56:46 +03:00
|
|
|
|
bind $txt <Control-eacute> Find
|
|
|
|
|
bind $txt <Insert> {OverWrite}
|
2022-08-15 11:07:47 +03:00
|
|
|
|
bind $txt <ButtonRelease-1> "Editor::SearchBrackets $txt"
|
2022-08-16 15:23:12 +03:00
|
|
|
|
bind $txt <Button-1><ButtonRelease-1> "Editor::SelectionHighlight $txt"
|
2022-12-01 12:37:13 +03:00
|
|
|
|
bind $txt <<Modified>> "SetModifiedFlag $w $nb"
|
2022-08-01 16:24:42 +03:00
|
|
|
|
bind $txt <Control-i> ImageBase64Encode
|
2022-08-15 11:07:47 +03:00
|
|
|
|
bind $txt <Control-u> "Editor::SearchBrackets %W"
|
2022-09-21 14:38:31 +03:00
|
|
|
|
bind $txt <Control-J> "catch {Editor::GoToFunction $txt}"
|
|
|
|
|
bind $txt <Control-j> "catch {Editor::GoToFunction $txt}; break"
|
2022-11-22 13:10:03 +03:00
|
|
|
|
bind $txt <Alt-w> "$txt delete {insert wordstart} {insert wordend}"
|
|
|
|
|
bind $txt <Alt-odiaeresis> "$txt delete {insert wordstart} {insert wordend}"
|
|
|
|
|
bind $txt <Alt-r> "$txt delete {insert linestart} {insert lineend + 1char}"
|
|
|
|
|
bind $txt <Alt-ecircumflex> "$txt delete {insert linestart} {insert lineend + 1char}"
|
2022-08-26 15:43:56 +03:00
|
|
|
|
bind $txt <Alt-b> "$txt delete {insert linestart} insert"
|
|
|
|
|
bind $txt <Alt-e> "$txt delete insert {insert lineend}"
|
2022-11-22 13:10:03 +03:00
|
|
|
|
bind $txt <Alt-s> "Editor::SplitEditorH $w $fileType"
|
|
|
|
|
bind $txt <Alt-ucircumflex> "Editor::SplitEditorH $w $fileType"
|
|
|
|
|
bind $txt <Alt-y> "Editor::TextCopy $txt"
|
2022-11-11 12:41:52 +03:00
|
|
|
|
bind $txt <Control-g> "Editor::GoToLineNumberDialog $txt"
|
|
|
|
|
bind $txt <Control-agrave> "Editor::FindDialog $w"
|
|
|
|
|
bind $txt <Control-f> "Editor::FindDialog $txt"
|
|
|
|
|
bind $txt <Control-F> "Editor::FindDialog $txt"
|
|
|
|
|
bind $txt <Control-odiaeresis> FileOper::Close
|
|
|
|
|
bind $txt <Control-w> FileOper::Close
|
2022-10-28 16:45:33 +03:00
|
|
|
|
bind $txt <Control-o> {
|
|
|
|
|
set filePath [FileOper::OpenDialog]
|
|
|
|
|
if {$filePath != ""} {
|
|
|
|
|
FileOper::Edit $filePath
|
|
|
|
|
}
|
|
|
|
|
break
|
|
|
|
|
}
|
|
|
|
|
bind $txt <Control-O> {
|
|
|
|
|
set filePath [FileOper::OpenDialog]
|
|
|
|
|
if {$filePath != ""} {
|
|
|
|
|
FileOper::Edit $filePath
|
|
|
|
|
}
|
|
|
|
|
break
|
|
|
|
|
}
|
2022-11-11 12:41:52 +03:00
|
|
|
|
# bind $txt.t <KeyRelease> "Editor::ReleaseKey %K $txt.t $fileType"
|
|
|
|
|
# bind $txt.t <KeyPress> "Editor::PressKey %K $txt.t"
|
|
|
|
|
# bind $txt <KeyRelease> "Editor::Key %k %K"
|
|
|
|
|
#$txt tag bind Sel <Control-/> {puts ">>>>>>>>>>>>>>>>>>>"}
|
|
|
|
|
#bind $txt <Control-slash> {puts "/////////////////"}
|
|
|
|
|
# #bind $txt <Control-g> GoToLine
|
|
|
|
|
# bind $txt <F3> {FindNext $w.text 1}
|
|
|
|
|
# bind $txt <Control-ecircumflex> ReplaceDialog
|
|
|
|
|
# bind $txt <Control-r> ReplaceDialog
|
|
|
|
|
# bind $txt <F4> {ReplaceCommand $w.text 1}
|
|
|
|
|
# bind $txt <Control-ucircumflex> {FileDialog [$noteBookFiles raise] save}
|
|
|
|
|
# bind $txt <Control-s> {FileDialog [$noteBookFiles raise] save}
|
|
|
|
|
# bind $txt <Control-ocircumflex> {FileDialog [$noteBookFiles raise] save_as}
|
|
|
|
|
# bind $txt <Shift-Control-s> {FileDialog [$noteBookFiles raise] save_as}
|
|
|
|
|
# bind $txt <Control-division> "tk_textCut $w.text;break"
|
|
|
|
|
# bind $txt <Control-x> "tk_textCut $w.text;break"
|
|
|
|
|
# bind $txt <Control-ntilde> "tk_textCopy $txt"
|
|
|
|
|
# bind $txt <Control-c> "tk_textCopy $txt"
|
|
|
|
|
|
|
|
|
|
#bind $txt <Control-adiaeresis> "auto_completition $txt"
|
|
|
|
|
# bind $txt <Control-icircumflex> ""
|
|
|
|
|
# bind $txt <Control-j> ""
|
|
|
|
|
#bind . <Control-m> PageTab
|
|
|
|
|
#bind . <Control-udiaeresis> PageTab
|
|
|
|
|
# bind <Button-1> [bind sysAfter <Any-Key>]
|
|
|
|
|
# bind $txt <Button-3> {catch [PopupMenuEditor %X %Y]}
|
|
|
|
|
# bind $txt <Button-4> "%W yview scroll -3 units"
|
|
|
|
|
# bind $txt <Button-5> "%W yview scroll 3 units"
|
|
|
|
|
#bind $txt <Shift-Button-4> "%W xview scroll -2 units"
|
|
|
|
|
#bind $txt <Shift-Button-5> "%W xview scroll 2 units"
|
|
|
|
|
# bind $txt <<Selection>> "Editor::SelectionHighlight $txt"
|
|
|
|
|
# bind $txt <<Selection>> "Editor::SelectionGet $txt"
|
2018-02-20 14:13:47 +03:00
|
|
|
|
}
|
2022-08-15 11:07:47 +03:00
|
|
|
|
|
|
|
|
|
proc SearchBrackets {txt} {
|
|
|
|
|
set i -1
|
|
|
|
|
catch {
|
|
|
|
|
switch -- [$txt get "insert - 1 chars"] {
|
|
|
|
|
\{ {set i [Editor::_searchCloseBracket $txt \{ \} insert end]}
|
|
|
|
|
\[ {set i [Editor::_searchCloseBracket $txt \[ \] insert end]}
|
|
|
|
|
( {set i [Editor::_searchCloseBracket $txt ( ) insert end]}
|
|
|
|
|
\} {set i [Editor::_searchOpenBracket $txt \{ \} insert 1.0]}
|
|
|
|
|
\] {set i [Editor::_searchOpenBracket $txt \[ \] insert 1.0]}
|
|
|
|
|
) {set i [Editor::_searchOpenBracket $txt ( ) insert 1.0]}
|
|
|
|
|
} ;# switch
|
|
|
|
|
catch { $txt tag remove lightBracket 1.0 end }
|
|
|
|
|
if { $i != -1 } {
|
|
|
|
|
# puts $i
|
|
|
|
|
$txt tag add lightBracket "$i - 1 chars" $i
|
|
|
|
|
};#if
|
|
|
|
|
};#catch
|
|
|
|
|
}
|
|
|
|
|
|
2022-07-21 10:56:46 +03:00
|
|
|
|
proc QuotSelection {txt symbol} {
|
|
|
|
|
variable selectionText
|
|
|
|
|
set selIndex [$txt tag ranges sel]
|
|
|
|
|
set pos [$txt index insert]
|
|
|
|
|
set lineNum [lindex [split $pos "."] 0]
|
|
|
|
|
set posNum [lindex [split $pos "."] 1]
|
|
|
|
|
set symbol [string trim [string trimleft $symbol "\\"]]
|
|
|
|
|
# puts "Selindex : $selIndex, cursor position: $pos"
|
|
|
|
|
if {$selIndex != ""} {
|
|
|
|
|
set lineBegin [lindex [split [lindex $selIndex 0] "."] 0]
|
|
|
|
|
set posBegin [lindex [split [lindex $selIndex 0] "."] 1]
|
|
|
|
|
set lineEnd [lindex [split [lindex $selIndex 1] "."] 0]
|
|
|
|
|
set posEnd [lindex [split [lindex $selIndex 1] "."] 1]
|
|
|
|
|
# set selText [$txt get $lineBegin.$posBegin $lineEnd.$posEnd]
|
|
|
|
|
set selText $selectionText
|
2022-08-26 15:43:56 +03:00
|
|
|
|
# puts "Selected text: $selText, pos: $pos, lineBegin: $lineBegin, posBegin: $posBegin, pos end: $posEnd"
|
2022-07-21 10:56:46 +03:00
|
|
|
|
if {$posNum == $posEnd} {
|
|
|
|
|
$txt insert $lineBegin.$posBegin "$symbol"
|
|
|
|
|
}
|
|
|
|
|
if {$posNum == $posBegin} {
|
|
|
|
|
$txt insert $lineBegin.$posEnd "$symbol"
|
2018-03-06 12:55:04 +03:00
|
|
|
|
}
|
2022-07-21 10:56:46 +03:00
|
|
|
|
$txt highlight $lineBegin.$posBegin $lineEnd.end
|
|
|
|
|
# $txt insert $lineBegin.[expr $posBegin + 1] "$symbol"
|
|
|
|
|
} else {
|
2022-07-21 16:41:45 +03:00
|
|
|
|
# $txt insert $lineNum.[expr $posNum + 1] "$symbol"
|
|
|
|
|
# $txt mark set insert $lineNum.[expr $posNum - 1]
|
|
|
|
|
# # $txt see $lineNum.[expr $posNum - 1]
|
|
|
|
|
# $txt see insert
|
|
|
|
|
# $txt highlight $lineNum.$posNum $lineNum.end
|
2018-02-20 14:13:47 +03:00
|
|
|
|
}
|
|
|
|
|
}
|
2022-07-21 10:56:46 +03:00
|
|
|
|
|
|
|
|
|
# Create editor for new file (Ctrl+N)
|
|
|
|
|
proc New {} {
|
|
|
|
|
global nbEditor tree untitledNumber
|
|
|
|
|
if [info exists untitledNumber] {
|
|
|
|
|
incr untitledNumber 1
|
|
|
|
|
} else {
|
|
|
|
|
set untitledNumber 0
|
|
|
|
|
}
|
2022-07-27 16:55:04 +03:00
|
|
|
|
# set filePath untitled-$untitledNumber
|
|
|
|
|
# set fileName untitled-$untitledNumber
|
2022-07-21 10:56:46 +03:00
|
|
|
|
set fileFullPath untitled-$untitledNumber
|
|
|
|
|
#puts [Tree::InsertItem $tree {} $fileFullPath "file" $fileName]
|
|
|
|
|
set nbEditorItem [NB::InsertItem $nbEditor $fileFullPath "file"]
|
2022-07-27 16:55:04 +03:00
|
|
|
|
# puts "$nbEditorItem, $nbEditor"
|
2022-07-21 10:56:46 +03:00
|
|
|
|
Editor $fileFullPath $nbEditor $nbEditorItem
|
2022-07-25 16:04:25 +03:00
|
|
|
|
SetModifiedFlag $nbEditorItem
|
2022-07-21 10:56:46 +03:00
|
|
|
|
}
|
2022-08-01 16:24:42 +03:00
|
|
|
|
|
|
|
|
|
proc ReadStructure {txt treeItemName} {
|
2022-08-24 15:04:19 +03:00
|
|
|
|
global tree nbEditor editors lexers
|
|
|
|
|
set fileType [dict get $editors $txt fileType]
|
2022-09-02 17:01:53 +03:00
|
|
|
|
set procList ""
|
|
|
|
|
set varList ""
|
|
|
|
|
set params ""
|
2022-08-24 15:04:19 +03:00
|
|
|
|
if {[dict exists $lexers $fileType] == 0} {return}
|
2022-08-01 16:24:42 +03:00
|
|
|
|
for {set lineNumber 0} {$lineNumber <= [$txt count -lines 0.0 end]} {incr lineNumber} {
|
|
|
|
|
set line [$txt get $lineNumber.0 $lineNumber.end]
|
2022-09-02 17:01:53 +03:00
|
|
|
|
# Выбираем процедуры (функции, классы и т.д.)
|
2022-08-24 15:53:57 +03:00
|
|
|
|
if {[dict exists $lexers $fileType procRegexpCommand] != 0 } {
|
|
|
|
|
if {[eval [dict get $lexers $fileType procRegexpCommand]]} {
|
2022-08-26 12:29:19 +03:00
|
|
|
|
set procName_ [string trim $procName]
|
2022-09-21 14:38:31 +03:00
|
|
|
|
if {$treeItemName ne ""} {
|
|
|
|
|
puts [Tree::InsertItem $tree $treeItemName $procName_ "procedure" "$procName_ ($params)"]
|
|
|
|
|
}
|
2022-09-02 17:01:53 +03:00
|
|
|
|
lappend procList [list $procName_ $params]
|
|
|
|
|
unset procName_
|
2022-08-24 15:53:57 +03:00
|
|
|
|
}
|
2022-09-02 17:01:53 +03:00
|
|
|
|
}
|
|
|
|
|
# Выбираем переменные
|
|
|
|
|
if {[dict exists $lexers $fileType varRegexpCommand] != 0 } {
|
|
|
|
|
if {[eval [dict get $lexers $fileType varRegexpCommand]]} {
|
2022-09-08 17:01:18 +03:00
|
|
|
|
if [info exists varName] {
|
|
|
|
|
set varName [string trim $varName]
|
|
|
|
|
} else {
|
|
|
|
|
set varName ""
|
|
|
|
|
}
|
|
|
|
|
if [info exists varValue] {
|
|
|
|
|
set varValue [string trim $varValue]
|
|
|
|
|
} else {
|
|
|
|
|
set varValue ""
|
|
|
|
|
}
|
|
|
|
|
if [info exists varType] {
|
|
|
|
|
set varType [string trim $varType]
|
|
|
|
|
} else {
|
|
|
|
|
set varType ""
|
|
|
|
|
}
|
|
|
|
|
puts "variable: $varName, value: $varValue, type: $varType"
|
2022-09-02 17:01:53 +03:00
|
|
|
|
lappend varList [list $varName $varValue]
|
|
|
|
|
}
|
|
|
|
|
}
|
2022-08-01 16:24:42 +03:00
|
|
|
|
}
|
2022-09-02 17:01:53 +03:00
|
|
|
|
dict set editors $txt procedureList $procList
|
|
|
|
|
dict set editors $txt variableList $varList
|
2022-08-01 16:24:42 +03:00
|
|
|
|
}
|
2022-10-17 16:55:22 +03:00
|
|
|
|
|
2022-09-21 14:38:31 +03:00
|
|
|
|
proc FindFunction {txt findString} {
|
2022-11-24 10:46:30 +03:00
|
|
|
|
puts "txt: $txt, $findString"
|
2022-08-03 12:21:28 +03:00
|
|
|
|
set pos "0.0"
|
|
|
|
|
$txt see $pos
|
|
|
|
|
set line [lindex [split $pos "."] 0]
|
|
|
|
|
set x [lindex [split $pos "."] 1]
|
2022-11-24 10:46:30 +03:00
|
|
|
|
set pattern "$findString\(\\W\|\$\)"
|
2022-11-18 11:43:57 +03:00
|
|
|
|
set pos [$txt search -nocase -regexp $pattern $line.$x end]
|
2022-08-03 12:21:28 +03:00
|
|
|
|
$txt mark set insert $pos
|
|
|
|
|
$txt see $pos
|
|
|
|
|
set line [lindex [split $pos "."] 0]
|
|
|
|
|
$txt tag remove sel 1.0 end
|
|
|
|
|
$txt tag add sel $pos $line.end
|
|
|
|
|
$txt tag raise sel
|
2022-08-24 15:04:19 +03:00
|
|
|
|
focus -force $txt.t
|
2022-08-03 12:21:28 +03:00
|
|
|
|
return 1
|
|
|
|
|
}
|
2022-11-18 11:43:57 +03:00
|
|
|
|
|
|
|
|
|
# "Alexander Dederer (aka Korwin)
|
2022-08-15 11:07:47 +03:00
|
|
|
|
## Search close bracket in editor widget
|
|
|
|
|
proc _searchCloseBracket { widget o_bracket c_bracket start_pos end_pos } {
|
|
|
|
|
# puts "_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
|
|
|
|
|
|
|
|
|
|
# "Alexander Dederer (aka Korwin)
|
|
|
|
|
## Search open bracket in editor widget
|
|
|
|
|
proc _searchOpenBracket { widget o_bracket c_bracket start_pos end_pos } {
|
|
|
|
|
# puts "_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]
|
|
|
|
|
# puts "$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}
|
2022-08-24 15:04:19 +03:00
|
|
|
|
if {($found == 1) && ($o_count == $c_count) } { return [$widget index "$pos + 1 chars"]}
|
2022-08-15 11:07:47 +03:00
|
|
|
|
set found 0
|
|
|
|
|
set start_pos "$pos - 0 chars"
|
|
|
|
|
set pos [$widget search -backward -regexp -- $pattern $start_pos $end_pos]
|
|
|
|
|
} ;# while search
|
|
|
|
|
return -1
|
2022-08-24 15:04:19 +03:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
# ----------------------------------------------------------------------
|
|
|
|
|
# Вызов диалога со списком процедур или функций присутствующих в тексте
|
2022-09-14 16:31:50 +03:00
|
|
|
|
proc GoToFunction { w } {
|
2022-08-24 15:04:19 +03:00
|
|
|
|
global tree editors
|
2022-09-21 14:38:31 +03:00
|
|
|
|
puts $w
|
|
|
|
|
# set txt $w.frmText.t
|
|
|
|
|
set txt $w
|
2022-08-24 15:04:19 +03:00
|
|
|
|
set box [$txt bbox insert]
|
|
|
|
|
set box_x [expr [lindex $box 0] + [winfo rootx $txt] ]
|
|
|
|
|
set box_y [expr [lindex $box 1] + [winfo rooty $txt] + [lindex $box 3] ]
|
|
|
|
|
set l ""
|
2022-09-21 14:38:31 +03:00
|
|
|
|
# puts "--$txt"
|
|
|
|
|
# puts $editors($txt)
|
2022-08-24 15:04:19 +03:00
|
|
|
|
foreach item [dict get $editors $txt procedureList] {
|
2022-09-21 14:38:31 +03:00
|
|
|
|
puts $item
|
2022-08-24 15:04:19 +03:00
|
|
|
|
lappend l [lindex $item 0]
|
|
|
|
|
}
|
|
|
|
|
if {$l ne ""} {
|
|
|
|
|
eval GotoFunctionDialog $w $box_x $box_y [lsort $l]
|
|
|
|
|
focus .gotofunction.lBox
|
|
|
|
|
}
|
|
|
|
|
}
|
2022-08-15 11:07:47 +03:00
|
|
|
|
|
2022-09-01 16:54:34 +03:00
|
|
|
|
#---------------------------------------------------------
|
|
|
|
|
# Поиск по списку по первой букве
|
|
|
|
|
# Richard Suchenwirth 2001-03-1
|
|
|
|
|
# https://wiki.tcl-lang.org/page/Listbox+navigation+by+keyboard
|
|
|
|
|
proc ListBoxSearch {w key} {
|
|
|
|
|
if [regexp {[-A-Za-z0-9_]} $key] {
|
|
|
|
|
set n 0
|
|
|
|
|
foreach i [$w get 0 end] {
|
|
|
|
|
if [string match -nocase $key* $i] {
|
|
|
|
|
$w see $n
|
|
|
|
|
$w selection clear 0 end
|
|
|
|
|
$w selection set $n
|
|
|
|
|
$w activate $n
|
|
|
|
|
break
|
|
|
|
|
} else {
|
|
|
|
|
incr n
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
2022-08-24 15:04:19 +03:00
|
|
|
|
# ------------------------------------------------------------------------
|
|
|
|
|
# Диалоговое окно со списком процедур или функций в редактируемом тексте
|
|
|
|
|
proc GotoFunctionDialog {w x y args} {
|
|
|
|
|
global editors lexers
|
|
|
|
|
variable txt
|
2022-08-25 16:39:50 +03:00
|
|
|
|
variable win
|
2022-09-21 14:38:31 +03:00
|
|
|
|
# set txt $w.frmText.t
|
|
|
|
|
set txt $w
|
2022-08-24 15:04:19 +03:00
|
|
|
|
set win .gotofunction
|
|
|
|
|
|
2022-09-21 14:38:31 +03:00
|
|
|
|
if { [winfo exists $win] } { destroy $win }
|
2022-08-24 15:04:19 +03:00
|
|
|
|
toplevel $win
|
|
|
|
|
wm transient $win .
|
|
|
|
|
wm overrideredirect $win 1
|
|
|
|
|
|
|
|
|
|
listbox $win.lBox -width 30 -border 2 -yscrollcommand "$win.yscroll set" -border 1
|
2022-08-25 16:39:50 +03:00
|
|
|
|
ttk::scrollbar $win.yscroll -orient vertical -command "$win.lBox yview"
|
2022-08-24 15:04:19 +03:00
|
|
|
|
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
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
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
|
|
|
|
|
|
2022-09-21 14:38:31 +03:00
|
|
|
|
bind $win <Escape> {
|
2022-08-25 16:39:50 +03:00
|
|
|
|
destroy $Editor::win
|
|
|
|
|
focus -force $Editor::txt.t
|
|
|
|
|
break
|
|
|
|
|
}
|
|
|
|
|
bind $win.lBox <Escape> {
|
|
|
|
|
destroy $Editor::win
|
|
|
|
|
focus -force $Editor::txt.t
|
|
|
|
|
break
|
|
|
|
|
}
|
2022-08-24 15:04:19 +03:00
|
|
|
|
bind $win.lBox <Return> {
|
2022-08-25 16:39:50 +03:00
|
|
|
|
set findString [dict get $lexers [dict get $editors $Editor::txt fileType] procFindString]
|
|
|
|
|
set values [.gotofunction.lBox get [.gotofunction.lBox curselection]]
|
|
|
|
|
regsub -all {PROCNAME} $findString $values str
|
2022-09-21 14:38:31 +03:00
|
|
|
|
Editor::FindFunction $Editor::txt "$str"
|
2022-08-24 15:04:19 +03:00
|
|
|
|
destroy .gotofunction
|
|
|
|
|
$Editor::txt tag remove sel 1.0 end
|
|
|
|
|
# focus $Editor::txt.t
|
|
|
|
|
break
|
|
|
|
|
}
|
2022-09-01 16:54:34 +03:00
|
|
|
|
bind $win.lBox <Any-Key> {Editor::ListBoxSearch %W %A}
|
|
|
|
|
# Определям расстояние до края экрана (основного окна) и если
|
|
|
|
|
# оно меньше размера окна со списком то сдвигаем его вверх
|
|
|
|
|
set winGeom [winfo reqheight $win]
|
|
|
|
|
set topHeight [winfo height .]
|
|
|
|
|
# puts "$x, $y, $winGeom, $topHeight"
|
|
|
|
|
if [expr [expr $topHeight - $y] < $winGeom] {
|
|
|
|
|
set y [expr $topHeight - $winGeom]
|
|
|
|
|
}
|
2022-08-24 15:04:19 +03:00
|
|
|
|
wm geom $win +$x+$y
|
|
|
|
|
}
|
2022-10-17 16:55:22 +03:00
|
|
|
|
|
|
|
|
|
proc FindReplaceText {txt findString replaceString regexp} {
|
2022-08-31 17:00:51 +03:00
|
|
|
|
global nbEditor
|
2022-09-21 14:38:31 +03:00
|
|
|
|
puts [focus]
|
|
|
|
|
# set txt [$nbEditor select].frmText.t
|
2022-09-01 16:54:34 +03:00
|
|
|
|
$txt tag remove sel 1.0 end
|
2022-08-31 17:00:51 +03:00
|
|
|
|
# $txt see $pos
|
|
|
|
|
# set pos [$txt search -nocase $findString $line.$x end]
|
|
|
|
|
set options ""
|
|
|
|
|
# $txt see 1.0
|
|
|
|
|
set pos [$txt index insert]
|
|
|
|
|
set allLines [$txt count -lines 1.0 end]
|
2022-09-01 16:54:34 +03:00
|
|
|
|
# puts "$pos $allLines"
|
2022-08-31 17:00:51 +03:00
|
|
|
|
set line [lindex [split $pos "."] 0]
|
|
|
|
|
|
|
|
|
|
if [expr $line == $allLines] {
|
|
|
|
|
set pos "0.0"
|
|
|
|
|
set line [lindex [split $pos "."] 0]
|
|
|
|
|
}
|
|
|
|
|
set x [lindex [split $pos "."] 1]
|
|
|
|
|
# incr x $incr
|
|
|
|
|
|
2022-09-01 16:54:34 +03:00
|
|
|
|
# puts "$findString -> $replaceString, $regexp, $pos, $line.$x"
|
|
|
|
|
set matchIndexPair ""
|
|
|
|
|
if {$regexp eq "-regexp"} {
|
|
|
|
|
# puts "$txt search -all -nocase -regexp {$findString} $line.$x end"
|
|
|
|
|
set lstFindIndex [$txt search -all -nocase -regexp -count matchIndexPair "$findString" $line.$x end]
|
|
|
|
|
} else {
|
|
|
|
|
# puts "$txt search -all -nocase {$findString} $line.$x end"
|
|
|
|
|
set lstFindIndex [$txt search -all -nocase -count matchIndexPair $findString $line.$x end]
|
|
|
|
|
# set symNumbers [string length "$findString"]
|
|
|
|
|
}
|
2022-09-23 12:33:22 +03:00
|
|
|
|
# puts $lstFindIndex
|
|
|
|
|
# puts $matchIndexPair
|
2022-09-01 16:54:34 +03:00
|
|
|
|
# set lstFindIndex [$txt search -all "$selectionText" 0.0]
|
|
|
|
|
set i 0
|
|
|
|
|
foreach ind $lstFindIndex {
|
|
|
|
|
set selFindLine [lindex [split $ind "."] 0]
|
|
|
|
|
set selFindRow [lindex [split $ind "."] 1]
|
|
|
|
|
# set endInd "$selFindLine.[expr $selFindRow + $symNumbers]"
|
|
|
|
|
set endInd "$selFindLine.[expr [lindex $matchIndexPair $i] + $selFindRow]"
|
2022-09-23 12:33:22 +03:00
|
|
|
|
# puts "$ind; $selFindLine, $selFindRow; $endInd "
|
2022-09-01 16:54:34 +03:00
|
|
|
|
if {$replaceString ne ""} {
|
|
|
|
|
$txt replace $ind $endInd $replaceString
|
|
|
|
|
}
|
|
|
|
|
$txt tag add sel $ind $endInd
|
|
|
|
|
incr i
|
2022-08-31 17:00:51 +03:00
|
|
|
|
}
|
2022-09-15 12:35:05 +03:00
|
|
|
|
.finddialog.lblCounter configure -text "[::msgcat::mc "Finded"]: $i"
|
|
|
|
|
|
2022-08-31 17:00:51 +03:00
|
|
|
|
# set pos [$txt search $options $findString $pos end]
|
2022-09-01 16:54:34 +03:00
|
|
|
|
|
2022-08-31 17:00:51 +03:00
|
|
|
|
|
2022-09-01 16:54:34 +03:00
|
|
|
|
# $txt mark set insert $pos
|
2022-09-15 12:35:05 +03:00
|
|
|
|
if {[lindex $lstFindIndex 0] ne "" } {
|
2022-09-22 16:42:48 +03:00
|
|
|
|
# $txt see [lindex $lstFindIndex 0]
|
|
|
|
|
$txt mark set insert [lindex $lstFindIndex 0]
|
2022-09-23 12:33:22 +03:00
|
|
|
|
$txt see insert
|
2022-09-15 12:35:05 +03:00
|
|
|
|
}
|
2022-09-01 16:54:34 +03:00
|
|
|
|
# puts $pos
|
|
|
|
|
# # highlight the found word
|
|
|
|
|
# set line [lindex [split $pos "."] 0]
|
2022-08-31 17:00:51 +03:00
|
|
|
|
# set x [lindex [split $pos "."] 1]
|
|
|
|
|
# set x [expr {$x + [string length $findString]}]
|
|
|
|
|
# $txt tag remove sel 1.0 end
|
|
|
|
|
# $txt tag add sel $pos $line.end
|
|
|
|
|
# #$text tag configure sel -background $editor(selectbg) -foreground $editor(fg)
|
2022-09-01 16:54:34 +03:00
|
|
|
|
$txt tag raise sel
|
|
|
|
|
# # focus -force $txt.t
|
|
|
|
|
# # Position
|
|
|
|
|
# return 1
|
2022-08-31 17:00:51 +03:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
# Find and replace text dialog
|
|
|
|
|
proc FindDialog {w} {
|
2022-09-01 16:54:34 +03:00
|
|
|
|
global editors lexers nbEditor regexpSet
|
2022-08-31 17:00:51 +03:00
|
|
|
|
variable txt
|
|
|
|
|
variable win
|
|
|
|
|
variable show
|
|
|
|
|
set findString ""
|
|
|
|
|
set replaceString ""
|
2022-09-23 12:33:22 +03:00
|
|
|
|
|
|
|
|
|
if {$w ne ""} {
|
|
|
|
|
set txt $w
|
|
|
|
|
} else {
|
|
|
|
|
if {[$nbEditor select] ne ""} {
|
|
|
|
|
set txt [$nbEditor select].frmText.t
|
|
|
|
|
puts $txt
|
|
|
|
|
} else {
|
|
|
|
|
return
|
|
|
|
|
}
|
|
|
|
|
}
|
2022-09-21 14:38:31 +03:00
|
|
|
|
# set txt $w.frmText.t
|
2022-08-31 17:00:51 +03:00
|
|
|
|
set win .finddialog
|
|
|
|
|
set regexpSet ""
|
2022-09-15 12:35:05 +03:00
|
|
|
|
set searchAll "-all"
|
2022-08-31 17:00:51 +03:00
|
|
|
|
|
2022-11-18 16:43:14 +03:00
|
|
|
|
if { [winfo exists $win] } { destroy $win }
|
2022-08-31 17:00:51 +03:00
|
|
|
|
toplevel $win
|
|
|
|
|
wm transient $win .
|
|
|
|
|
wm overrideredirect $win 1
|
|
|
|
|
|
|
|
|
|
ttk::entry $win.entryFind -width 30 -textvariable findString
|
|
|
|
|
ttk::entry $win.entryReplace -width 30 -textvariable replaceString
|
|
|
|
|
|
|
|
|
|
set show($win.entryReplace) false
|
|
|
|
|
|
|
|
|
|
|
2022-09-01 16:54:34 +03:00
|
|
|
|
ttk::button $win.bForward -image forward_20x20 -command {
|
2022-09-21 14:38:31 +03:00
|
|
|
|
Editor::FindReplaceText $Editor::txt "$findString" "" $regexpSet
|
2022-09-01 16:54:34 +03:00
|
|
|
|
}
|
|
|
|
|
ttk::button $win.bBackward -state disable -image backward_20x20 -command "puts $replaceString"
|
|
|
|
|
ttk::button $win.bDone -image done_20x20 -state disable -command {
|
|
|
|
|
puts "$findString -> $replaceString, $regexpSet"
|
|
|
|
|
}
|
|
|
|
|
ttk::button $win.bDoneAll -image doneall_20x20 -command {
|
2022-09-21 14:38:31 +03:00
|
|
|
|
Editor::FindReplaceText $Editor::txt "$findString" "$replaceString" $regexpSet
|
2022-08-31 17:00:51 +03:00
|
|
|
|
}
|
|
|
|
|
ttk::button $win.bReplace -image replace_20x20 \
|
|
|
|
|
-command {
|
2022-09-21 14:38:31 +03:00
|
|
|
|
# puts $Editor::show($Editor::win.entryReplace)
|
2022-08-31 17:00:51 +03:00
|
|
|
|
if {$Editor::show($Editor::win.entryReplace) eq "false"} {
|
2022-09-15 12:35:05 +03:00
|
|
|
|
grid $Editor::win.entryReplace -row 1 -column 0 -columnspan 3 -sticky nsew
|
2022-08-31 17:00:51 +03:00
|
|
|
|
grid $Editor::win.bDone -row 1 -column 3 -sticky e
|
|
|
|
|
grid $Editor::win.bDoneAll -row 1 -column 4 -sticky e
|
|
|
|
|
set Editor::show($Editor::win.entryReplace) "true"
|
|
|
|
|
} else {
|
|
|
|
|
grid remove $Editor::win.entryReplace $Editor::win.bDone $Editor::win.bDoneAll
|
|
|
|
|
set Editor::show($Editor::win.entryReplace) "false"
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
ttk::checkbutton $win.chkRegexp -text "Regexp" \
|
|
|
|
|
-variable regexpSet -onvalue "-regexp" -offvalue ""
|
2022-09-15 12:35:05 +03:00
|
|
|
|
ttk::checkbutton $win.chkAll -text "All" -state disable\
|
|
|
|
|
-variable searchAll -onvalue "-all" -offvalue ""
|
|
|
|
|
ttk::label $win.lblCounter -justify right -anchor e -text ""
|
|
|
|
|
|
|
|
|
|
grid $win.entryFind -row 0 -column 0 -columnspan 3 -sticky nsew
|
2022-08-31 17:00:51 +03:00
|
|
|
|
grid $win.bForward -row 0 -column 3 -sticky e
|
|
|
|
|
grid $win.bBackward -row 0 -column 4 -sticky e
|
|
|
|
|
grid $win.bReplace -row 0 -column 5 -sticky e
|
|
|
|
|
grid $win.chkRegexp -row 2 -column 0 -sticky w
|
2022-09-15 12:35:05 +03:00
|
|
|
|
# grid $win.chkAll -row 2 -column 1 -sticky w
|
|
|
|
|
grid $win.lblCounter -row 2 -column 2 -sticky we
|
2022-08-31 17:00:51 +03:00
|
|
|
|
|
2022-09-01 16:54:34 +03:00
|
|
|
|
# set reqWidth [winfo reqwidth $win]
|
2022-09-23 12:33:22 +03:00
|
|
|
|
set boxX [expr [winfo rootx $txt] + [expr [winfo width $nbEditor] - 350]]
|
|
|
|
|
set boxY [expr [winfo rooty $txt] + 10]
|
2022-08-31 17:00:51 +03:00
|
|
|
|
|
|
|
|
|
bind $win <Escape> {
|
|
|
|
|
destroy $Editor::win
|
|
|
|
|
focus -force $Editor::txt.t
|
|
|
|
|
break
|
|
|
|
|
}
|
|
|
|
|
bind $win.entryFind <Escape> {
|
|
|
|
|
destroy $Editor::win
|
|
|
|
|
focus -force $Editor::txt.t
|
|
|
|
|
break
|
|
|
|
|
}
|
|
|
|
|
bind $win.entryFind <Return> {
|
2022-09-21 14:38:31 +03:00
|
|
|
|
Editor::FindReplaceText $Editor::txt "$findString" "" $regexpSet
|
2022-08-31 17:00:51 +03:00
|
|
|
|
break
|
|
|
|
|
}
|
|
|
|
|
bind $win.entryReplace <Return> {
|
2022-09-21 14:38:31 +03:00
|
|
|
|
Editor::FindReplaceText $Editor::txt "$findString" "$replaceString" $regexpSet
|
2022-08-31 17:00:51 +03:00
|
|
|
|
break
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
wm geom $win +$boxX+$boxY
|
|
|
|
|
focus -force $win.entryFind
|
|
|
|
|
}
|
|
|
|
|
|
2022-09-21 14:38:31 +03:00
|
|
|
|
# Horizontal split the Editor text widget
|
2022-12-01 12:37:13 +03:00
|
|
|
|
proc SplitEditorH {w fileType nb} {
|
2022-09-14 16:31:50 +03:00
|
|
|
|
global cfgVariables
|
|
|
|
|
puts [$w.panelTxt panes]
|
|
|
|
|
if [winfo exists $w.frmText2] {
|
|
|
|
|
$w.panelTxt forget $w.frmText2
|
|
|
|
|
destroy $w.frmText2
|
2022-09-15 12:35:05 +03:00
|
|
|
|
focus -force $w.frmText.t.t
|
2022-09-14 16:31:50 +03:00
|
|
|
|
return
|
|
|
|
|
}
|
2022-12-01 12:37:13 +03:00
|
|
|
|
set frmText [Editor::EditorWidget $w $fileType $nb]
|
2022-09-14 16:31:50 +03:00
|
|
|
|
$frmText.t insert end [$w.frmText.t get 0.0 end]
|
2022-09-08 17:01:18 +03:00
|
|
|
|
|
2022-09-14 16:31:50 +03:00
|
|
|
|
# $w.panelTxt add $w.frmText -weight 0
|
2022-09-14 16:56:15 +03:00
|
|
|
|
$w.panelTxt add $frmText -weight 1
|
|
|
|
|
|
2022-09-15 09:36:53 +03:00
|
|
|
|
$frmText.t see [$w.frmText.t index insert]
|
2022-09-21 14:38:31 +03:00
|
|
|
|
ReadStructure $frmText.t ""
|
2022-09-15 09:36:53 +03:00
|
|
|
|
focus -force $frmText.t.t
|
|
|
|
|
}
|
2022-12-01 12:37:13 +03:00
|
|
|
|
|
|
|
|
|
proc SplitEditorV {fileFullPath} {
|
2022-09-15 09:36:53 +03:00
|
|
|
|
global cfgVariables
|
2022-12-01 12:37:13 +03:00
|
|
|
|
regsub -all {\.|/|\\|\s} $fileFullPath "_" itemName
|
|
|
|
|
set itemName ".frmWork.nbEditor2.$itemName"
|
|
|
|
|
# puts $itemName
|
|
|
|
|
if {[winfo exists $itemName] == 1} {
|
|
|
|
|
.frmWork.nbEditor2 forget $itemName
|
|
|
|
|
destroy $itemName
|
|
|
|
|
if {[llength [.frmWork.nbEditor2 tabs]] == 0} {
|
|
|
|
|
if [lsearch -exact [.frmWork.panelNB panes] .frmWork.nbEditor2] {
|
|
|
|
|
grid forget .frmWork.nbEditor2
|
|
|
|
|
.frmWork.panelNB forget .frmWork.nbEditor2
|
|
|
|
|
}
|
|
|
|
|
}
|
2022-09-15 09:36:53 +03:00
|
|
|
|
return
|
|
|
|
|
}
|
2022-12-01 12:37:13 +03:00
|
|
|
|
pack .frmWork.nbEditor2 -side left -fill both -expand true
|
|
|
|
|
pack propagate .frmWork.nbEditor2 false
|
|
|
|
|
# grid .frmWork.nbEditor2 -row 0 -column 1 -sticky nsew
|
|
|
|
|
# grid columnconfigure .frmWork .frmWork.nbEditor -weight 1
|
|
|
|
|
# grid rowconfigure .frmWork .frmWork.nbEditor -weight 1
|
|
|
|
|
# grid columnconfigure .frmWork .frmWork.nbEditor2 -weight 1
|
|
|
|
|
# grid rowconfigure .frmWork .frmWork.nbEditor2 -weight 1
|
|
|
|
|
.frmWork.panelNB add .frmWork.nbEditor2 -weight 0
|
|
|
|
|
puts [FileOper::Edit $fileFullPath .frmWork.nbEditor2]
|
|
|
|
|
|
2022-09-15 09:36:53 +03:00
|
|
|
|
|
2022-09-22 16:42:48 +03:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
proc GoToLineNumber {text lineNumber} {
|
|
|
|
|
# puts "\n\n\t>>>>$text $lineNumber\n\n"
|
|
|
|
|
$text mark set insert $lineNumber.0
|
|
|
|
|
$text see insert
|
2022-09-08 17:01:18 +03:00
|
|
|
|
}
|
2022-09-21 14:38:31 +03:00
|
|
|
|
|
2022-11-10 15:36:34 +03:00
|
|
|
|
proc GoToLineNumberDialog {w} {
|
|
|
|
|
global editors lexers
|
|
|
|
|
variable txt
|
|
|
|
|
variable win
|
|
|
|
|
# set txt $w.frmText.t
|
|
|
|
|
set txt $w
|
|
|
|
|
set win .gotoline
|
|
|
|
|
set box [$txt bbox insert]
|
|
|
|
|
set x [expr [lindex $box 0] + [winfo rootx $txt] ]
|
|
|
|
|
set y [expr [lindex $box 1] + [winfo rooty $txt] + [lindex $box 3] ]
|
|
|
|
|
|
|
|
|
|
if { [winfo exists $win] } { destroy $win }
|
|
|
|
|
toplevel $win
|
|
|
|
|
wm transient $win .
|
|
|
|
|
wm overrideredirect $win 1
|
|
|
|
|
|
|
|
|
|
ttk::entry $win.ent
|
2022-11-10 15:42:47 +03:00
|
|
|
|
pack $win.ent -expand true -fill y -side left -padx 3 -pady 3
|
2022-11-10 15:36:34 +03:00
|
|
|
|
|
|
|
|
|
bind $win <Escape> {
|
|
|
|
|
destroy $Editor::win
|
|
|
|
|
focus -force $Editor::txt.t
|
|
|
|
|
break
|
|
|
|
|
}
|
|
|
|
|
bind $win.ent <Escape> {
|
|
|
|
|
destroy $Editor::win
|
|
|
|
|
focus -force $Editor::txt.t
|
|
|
|
|
break
|
|
|
|
|
}
|
|
|
|
|
bind $win.ent <Return> {
|
|
|
|
|
set lineNumber [.gotoline.ent get]
|
|
|
|
|
# $txt see insert $lineNumber
|
|
|
|
|
puts $Editor::txt
|
|
|
|
|
$Editor::txt mark set insert $lineNumber.0
|
|
|
|
|
$Editor::txt see insert
|
|
|
|
|
focus $Editor::txt.t
|
|
|
|
|
destroy .gotoline
|
|
|
|
|
break
|
|
|
|
|
}
|
|
|
|
|
# Определям расстояние до края экрана (основного окна) и если
|
|
|
|
|
# оно меньше размера окна со списком то сдвигаем его вверх
|
|
|
|
|
set winGeom [winfo reqheight $win]
|
|
|
|
|
set topHeight [winfo height .]
|
|
|
|
|
# puts "$x, $y, $winGeom, $topHeight"
|
|
|
|
|
if [expr [expr $topHeight - $y] < $winGeom] {
|
|
|
|
|
set y [expr $topHeight - $winGeom]
|
|
|
|
|
}
|
|
|
|
|
wm geom $win +$x+$y
|
|
|
|
|
focus $win.ent
|
|
|
|
|
}
|
|
|
|
|
|
2022-12-01 12:37:13 +03:00
|
|
|
|
proc EditorWidget {fr fileType nb} {
|
2022-08-24 15:04:19 +03:00
|
|
|
|
global cfgVariables editors
|
2022-09-14 16:31:50 +03:00
|
|
|
|
|
|
|
|
|
if [winfo exists $fr.frmText] {
|
|
|
|
|
set frmText [ttk::frame $fr.frmText2 -border 1]
|
2022-07-27 16:55:04 +03:00
|
|
|
|
} else {
|
2022-09-14 16:31:50 +03:00
|
|
|
|
set frmText [ttk::frame $fr.frmText -border 1]
|
2022-07-21 10:56:46 +03:00
|
|
|
|
}
|
|
|
|
|
set txt $frmText.t
|
2022-09-08 17:01:18 +03:00
|
|
|
|
|
|
|
|
|
# set frmText [ttk::frame $fr.frmText -border 1]
|
|
|
|
|
# set txt $frmText.t
|
|
|
|
|
|
|
|
|
|
pack $frmText -side top -expand true -fill both
|
|
|
|
|
|
2022-08-30 16:44:28 +03:00
|
|
|
|
pack [ttk::scrollbar $frmText.v -command "$frmText.t yview"] -side right -fill y
|
|
|
|
|
ttk::scrollbar $frmText.h -orient horizontal -command "$frmText.t xview"
|
|
|
|
|
ctext $txt -xscrollcommand "$frmText.h set" -yscrollcommand "$frmText.v set" \
|
|
|
|
|
-font $cfgVariables(font) -relief flat -wrap $cfgVariables(editorWrap) \
|
2022-08-24 15:04:19 +03:00
|
|
|
|
-linemapfg $cfgVariables(lineNumberFG) -linemapbg $cfgVariables(lineNumberBG) \
|
2022-08-30 16:44:28 +03:00
|
|
|
|
-tabs "[expr {4 * [font measure $cfgVariables(font) 0]}] left" -tabstyle tabular -undo true
|
2022-08-03 12:21:28 +03:00
|
|
|
|
|
2022-07-21 10:56:46 +03:00
|
|
|
|
pack $txt -fill both -expand 1
|
2022-09-15 09:36:53 +03:00
|
|
|
|
if {$cfgVariables(editorWrap) eq "none"} {
|
|
|
|
|
pack $frmText.h -side bottom -fill x
|
|
|
|
|
}
|
2022-07-27 16:55:04 +03:00
|
|
|
|
# puts ">>>>>>> [bindtags $txt]"
|
2022-07-21 10:56:46 +03:00
|
|
|
|
if {$cfgVariables(lineNumberShow) eq "false"} {
|
|
|
|
|
$txt configure -linemap 0
|
|
|
|
|
}
|
2022-08-17 16:52:22 +03:00
|
|
|
|
$txt tag configure lightBracket -background $cfgVariables(selectLightBg) -foreground #00ffff
|
|
|
|
|
$txt tag configure lightSelected -background $cfgVariables(selectLightBg) -foreground #00ffff
|
2022-08-16 15:23:12 +03:00
|
|
|
|
|
2022-07-22 16:00:59 +03:00
|
|
|
|
# puts ">$fileType<"
|
|
|
|
|
# puts [info procs Highlight::GO]
|
2022-08-24 15:04:19 +03:00
|
|
|
|
dict set editors $txt fileType $fileType
|
|
|
|
|
dict set editors $txt procedureList [list]
|
|
|
|
|
|
2022-09-21 14:38:31 +03:00
|
|
|
|
puts ">>[dict get $editors $txt fileType]"
|
|
|
|
|
puts ">>[dict get $editors $txt procedureList]"
|
2022-08-24 15:04:19 +03:00
|
|
|
|
# puts ">>>>> $editors"
|
|
|
|
|
|
2022-09-22 16:42:48 +03:00
|
|
|
|
if {[info procs ::Highlight::$fileType] ne ""} {
|
2022-07-21 10:56:46 +03:00
|
|
|
|
Highlight::$fileType $txt
|
|
|
|
|
} else {
|
|
|
|
|
Highlight::Default $txt
|
|
|
|
|
}
|
2022-12-01 12:37:13 +03:00
|
|
|
|
BindKeys $fr $txt $fileType $nb
|
2022-09-14 16:31:50 +03:00
|
|
|
|
return $frmText
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
proc Editor {fileFullPath nb itemName} {
|
|
|
|
|
global cfgVariables editors
|
2022-11-10 14:53:58 +03:00
|
|
|
|
set imageType {
|
|
|
|
|
PNG
|
|
|
|
|
JPG
|
|
|
|
|
JPEG
|
|
|
|
|
WEBP
|
|
|
|
|
GIF
|
|
|
|
|
TIFF
|
|
|
|
|
JP2
|
|
|
|
|
ICO
|
|
|
|
|
XPM
|
|
|
|
|
}
|
2022-09-14 16:31:50 +03:00
|
|
|
|
set fr $itemName
|
|
|
|
|
if ![string match "*untitled*" $itemName] {
|
|
|
|
|
set lblText $fileFullPath
|
|
|
|
|
} else {
|
|
|
|
|
set lblText ""
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
set fileType [string toupper [string trimleft [file extension $fileFullPath] "."]]
|
|
|
|
|
if {$fileType eq ""} {set fileType "Unknown"}
|
2022-07-21 10:56:46 +03:00
|
|
|
|
|
2022-09-14 16:31:50 +03:00
|
|
|
|
ttk::frame $fr.header
|
|
|
|
|
set lblName "lbl[string range $itemName [expr [string last "." $itemName] +1] end]"
|
|
|
|
|
ttk::label $fr.header.$lblName -text $lblText
|
|
|
|
|
# pack $fr.$lblName -side top -anchor w -fill x
|
|
|
|
|
|
|
|
|
|
set btnSplitV "btnSplitV[string range $itemName [expr [string last "." $itemName] +1] end]"
|
|
|
|
|
set btnSplitH "btnSplitH[string range $itemName [expr [string last "." $itemName] +1] end]"
|
|
|
|
|
ttk::button $fr.header.$btnSplitH -image split_horizontal_11x11 \
|
2022-12-01 12:37:13 +03:00
|
|
|
|
-command "Editor::SplitEditorH $fr $fileType $nb"
|
2022-09-14 16:31:50 +03:00
|
|
|
|
ttk::button $fr.header.$btnSplitV -image split_vertical_11x11 \
|
2022-12-01 12:37:13 +03:00
|
|
|
|
-command "Editor::SplitEditorV $fileFullPath"
|
2022-09-14 16:31:50 +03:00
|
|
|
|
# pack $fr.$btnSplitH $fr.$btnSplitV -side right -anchor e
|
|
|
|
|
pack $fr.header.$lblName -side left -expand true -fill x
|
|
|
|
|
pack $fr.header.$btnSplitV $fr.header.$btnSplitH -side right
|
|
|
|
|
|
|
|
|
|
pack $fr.header -side top -fill x
|
|
|
|
|
|
|
|
|
|
ttk::panedwindow $fr.panelTxt -orient vertical -style TPanedwindow
|
|
|
|
|
pack propagate $fr.panelTxt false
|
|
|
|
|
pack $fr.panelTxt -side top -fill both -expand true
|
|
|
|
|
|
2022-11-10 14:53:58 +03:00
|
|
|
|
if {[lsearch -exact $imageType $fileType] != -1} {
|
|
|
|
|
ImageViewer $fileFullPath $itemName $fr
|
|
|
|
|
} else {
|
2022-12-01 12:37:13 +03:00
|
|
|
|
set frmText [Editor::EditorWidget $fr $fileType $nb]
|
2022-11-10 14:53:58 +03:00
|
|
|
|
}
|
2022-09-14 16:31:50 +03:00
|
|
|
|
$fr.panelTxt add $frmText -weight 0
|
2018-03-06 12:55:04 +03:00
|
|
|
|
|
2022-07-21 10:56:46 +03:00
|
|
|
|
return $fr
|
|
|
|
|
}
|
2022-07-21 10:37:19 +03:00
|
|
|
|
}
|