diff --git a/CHANGELOG b/CHANGELOG index 377eac8..734a7c5 100644 --- a/CHANGELOG +++ b/CHANGELOG @@ -54,4 +54,10 @@ - Added some files icon - Fix finded procedure (function) (tree click) - Fix showing position in statusbar + +12/08/2022 + - Fixed comment/uncomment procedure depending on the file type + - Added About dialog + - Fixed read structure (procedure names like Proc:Name) + diff --git a/lib/editor.tcl b/lib/editor.tcl index 128073d..437c034 100644 --- a/lib/editor.tcl +++ b/lib/editor.tcl @@ -9,11 +9,25 @@ namespace eval Editor { variable selectionTex - proc Comment {txt} { + proc Comment {txt fileType} { set selIndex [$txt tag ranges sel] set pos [$txt index insert] set lineNum [lindex [split $pos "."] 0] set PosNum [lindex [split $pos "."] 1] + switch $fileType { + TCL { + set symbol "#" + } + GO { + set symbol "//" + } + Unknown { + set symbol "#" + } + default { + set symbol "#" + } + } puts "Select : $selIndex" if {$selIndex != ""} { set lineBegin [lindex [split [lindex $selIndex 0] "."] 0] @@ -26,22 +40,29 @@ namespace eval Editor { 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] "# " + $txt insert $i.[lindex [split $v2] 0] "$symbol " } $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 - $txt insert $lineNum.[lindex [split $v2] 0] "# " + $txt insert $lineNum.[lindex [split $v2] 0] "$symbol " $txt tag add comments $lineNum.0 $lineNum.end $txt tag raise comments } } - proc Uncomment {txt} { + proc Uncomment {txt fileType} { set selIndex [$txt tag ranges sel] set pos [$txt index insert] set lineNum [lindex [split $pos "."] 0] set posNum [lindex [split $pos "."] 1] + + if {[info procs GetComment:$fileType] ne ""} { + set commentProcedure "GetComment:$fileType" + } else { + set commentProcedure {GetComment:Unknown} + } + # puts "$fileType, $commentProcedure" if {$selIndex != ""} { set lineBegin [lindex [split [lindex $selIndex 0] "."] 0] set lineEnd [lindex [split [lindex $selIndex 1] "."] 0] @@ -52,25 +73,48 @@ namespace eval Editor { } 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 v3]} { - $txt delete $i.[lindex [split $v2] 0] $i.[lindex [split $v3] 0] + set commentSymbolIndex [$commentProcedure $str] + if {$commentSymbolIndex != 0} { + $txt delete $i.[lindex $commentSymbolIndex 0] $i.[lindex $commentSymbolIndex 1] } } $txt tag remove comments $lineBegin.0 $lineEnd.end $txt tag add sel $lineBegin.0 $lineEnd.end $txt highlight $lineBegin.0 $lineEnd.end } else { - #set posNum [lindex [split $pos "."] 1] + set posNum [lindex [split $pos "."] 1] set str [$txt get $lineNum.0 $lineNum.end] - if {[regexp -nocase -indices -- {(^| )(#\s)(.+)} $str match v1 v2 v3]} { - puts ">>>>> $v1, $v2, $v3" - $txt delete $lineNum.[lindex [split $v2] 0] $lineNum.[lindex [split $v3] 0] - #$txt insert $i.0 $v3 + set commentSymbolIndex [$commentProcedure $str] + if {$commentSymbolIndex != 0} { + $txt delete $lineNum.[lindex $commentSymbolIndex 0] $lineNum.[lindex $commentSymbolIndex 1] } $txt tag remove comments $lineNum.0 $lineNum.end $txt highlight $lineNum.0 $lineNum.end } } + 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 + } + } proc InsertTabular {txt} { global cfgVariables @@ -302,7 +346,7 @@ namespace eval Editor { if {$key == 63 || $key == 107 || $key == 108 || $key == 112} {return "true"} } - proc BindKeys {w} { + proc BindKeys {w fileType} { global cfgVariables # variable txt set txt $w.frmText.t @@ -341,8 +385,8 @@ namespace eval Editor { bind $txt "Editor::InsertTabular $txt" bind $txt "Editor::DeleteTabular $txt" - bind $txt "Editor::Comment $txt" - bind $txt "Editor::Uncomment $txt" + bind $txt "Editor::Comment $txt $fileType" + bind $txt "Editor::Uncomment $txt $fileType" bind $txt Find #bind . PageTab #bind . PageTab @@ -414,7 +458,7 @@ namespace eval Editor { for {set lineNumber 0} {$lineNumber <= [$txt count -lines 0.0 end]} {incr lineNumber} { set line [$txt get $lineNumber.0 $lineNumber.end] # TCL procedure - if {[regexp -nocase -all -- {^\s*?(proc) (::|)(\w+)(::|)(\w+)\s*?(\{|\()(.*)(\}|\)) \{} $line match v1 v2 v3 v4 v5 v6 params v8]} { + if {[regexp -nocase -all -- {^\s*?(proc) (::|)(\w+)(::|:|)(\w+)\s*?(\{|\()(.*)(\}|\)) \{} $line match v1 v2 v3 v4 v5 v6 params v8]} { set procName "$v2$v3$v4$v5" # lappend procList($activeProject) [list $procName [string trim $params]] # puts "$treeItemName proc $procName $params" @@ -496,6 +540,8 @@ namespace eval Editor { $txt configure -linemap 0 } set fileType [string toupper [string trimleft [file extension $fileFullPath] "."]] + if {$fileType eq ""} {set fileType "Unknown"} + # puts ">$fileType<" # puts [info procs Highlight::GO] if {[info procs ::Highlight::$fileType] ne ""} { @@ -504,7 +550,7 @@ namespace eval Editor { Highlight::Default $txt } - BindKeys $itemName + BindKeys $itemName $fileType # bind $txt { # regexp {^(\s*)} [%W get "insert linestart" end] -> spaceStart # %W insert insert "\n$spaceStart" diff --git a/lib/readstructure.tcl b/lib/readstructure.tcl new file mode 100644 index 0000000..88c961e --- /dev/null +++ b/lib/readstructure.tcl @@ -0,0 +1,96 @@ +###################################################### +# ProjMan 2 +# Distributed under GNU Public License +# Author: Sergey Kalinin svk@nuk-svk.ru +# Copyright (c) "", 2022, https://nuk-svk.ru +###################################################### +# +# Module for read files structure into directory +# +###################################################### +package require fileutil +package require Thread + +# TCL procedure +proc ReadFileStructureTCL {fileFullName} { + global procList + set f [open "$fileFullName" r] + while {[gets $f line] >=0} { + if {[regexp -nocase -all -- {^\s*?(proc) (::|)(\w+)(::|:|)(\w+)\s*?(\{|\()(.*)(\}|\)) \{} $line match v1 v2 v3 v4 v5 v6 params v8]} { + set procName "$v2$v3$v4$v5" + lappend procList($fileFullName) [list $procName $params] + } + } + close $f +} + + # GO function +proc ReadFileStructureGO {fileName} { + if {[regexp -nocase -all -- {^\s*?func\s*?\((\w+\s*?\*\w+)\)\s*?(\w+)\((.*?)\)\s*?(\(\w+\)|\w+|)\s*?\{} $line match v1 funcName params returns]} { + # set procName "$v2$v3$v4$v5" + # lappend procList($activeProject) [list $procName [string trim $params]] + if {$v1 ne ""} { + set linkName [lindex [split $v1 " "] 1] + set functionName "\($linkName\).$funcName" + } + + # tree parent item type text + lappend procList($fuleFullName) [list $functionName $params] + } + if {[regexp -nocase -all -- {^\s*?func\s*?(\w+)\((.*?)\) (\(\w+\)|\w+|)\s*?\{} $line match funcName params returns]} { + lappend procList($fuleFullName) [list $functonName $params] + } +} + +proc ReadFilesFromDirectory {directory} { + global procList + puts $directory + foreach fileName [fileutil::findByPattern $directory *.tcl] { + puts "Find file: $fileName" + ReadFileStructureTCL $fileName + } + set f [open "/tmp/test" w] + foreach name [array names procList] { + puts $f "$name: $procList($name)" + } +} + + +# set threadID [thread::create { + # proc runCommand {ID command} { + # set result [eval $command] + # eval [subst {thread::send -async $ID \ + # {::printResult [list $result]}}] + # } + # thread::wait +# }] +# +proc Accept { dirLib directory } { + global dir + puts $dir(lib) + puts $dirLib + # переменная с указанием ваших действия перед порождением потока + set threadinit { + # если необходимо, загружаем исходный tcl код, расположенный в других файлах + foreach { s } { readstructure } { + # uplevel #0 source [file join /home/svkalinin/Проекты/projman/lib $s.tcl] + uplevel #0 source [file join $dirLib $s.tcl] + } + # не завершаем поток, ибо будет запущен событийный сокетный обработчик + thread::wait + } + + # порождаем поток, выполнив предварительные действия, описанные в переменной threadinit + set tid [thread::create $threadinit] + + # thread::transfer $tid + # запускаем поток в асинхронном режиме + thread::send -async $tid [list ReadFilesFromDirectory $directory] +} + + +# процедура завершения потока +proc Exit:Thread { } { + # уничтожаем, останавливаем поток + thread::release +}