From b1d3d2b75c83d6552b6a963a72b8dcaa85575dfa Mon Sep 17 00:00:00 2001 From: svkalinin Date: Mon, 15 Aug 2022 11:07:47 +0300 Subject: [PATCH] =?UTF-8?q?=D0=94=D0=BE=D0=B1=D0=B0=D0=B2=D0=BB=D0=B5?= =?UTF-8?q?=D0=BD=D0=B0=20=D0=BF=D0=BE=D0=B4=D1=81=D0=B2=D0=B5=D1=82=D0=BA?= =?UTF-8?q?=D0=B0=20=D1=81=D0=BA=D0=BE=D0=B1=D0=BE=D0=BA?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- CHANGELOG | 4 ++- COPYING | 6 ---- lib/editor.tcl | 75 ++++++++++++++++++++++++++++++++++++++++++++++++-- projman.tcl | 2 +- 4 files changed, 76 insertions(+), 11 deletions(-) delete mode 100644 COPYING diff --git a/CHANGELOG b/CHANGELOG index 734a7c5..ef52dca 100644 --- a/CHANGELOG +++ b/CHANGELOG @@ -60,4 +60,6 @@ - Added About dialog - Fixed read structure (procedure names like Proc:Name) - +15/08/2022 + - Added open/close braces highlight + diff --git a/COPYING b/COPYING deleted file mode 100644 index 42a501e..0000000 --- a/COPYING +++ /dev/null @@ -1,6 +0,0 @@ -###################################################### -# Tcl/Tk Project manager 2.0 -# Distributed under GNU Public License -# Author: Sergey Kalinin svk@nuk-svl.ru -# Home page: https://nuk-svk.ru -###################################################### diff --git a/lib/editor.tcl b/lib/editor.tcl index 437c034..246ba35 100644 --- a/lib/editor.tcl +++ b/lib/editor.tcl @@ -297,6 +297,7 @@ namespace eval Editor { } proc ReleaseKey {k txt} { set pos [$txt index insert] + SearchBrackets $txt switch $k { Return { set lineNum [lindex [split $pos "."] 0] @@ -391,7 +392,8 @@ namespace eval Editor { #bind . PageTab #bind . PageTab bind $txt {OverWrite} - bind $txt [] + bind $txt "Editor::SearchBrackets $txt" + # bind [bind sysAfter ] # bind $txt {catch [PopupMenuEditor %X %Y]} # bind $txt "%W yview scroll -3 units" # bind $txt "%W yview scroll 3 units" @@ -400,8 +402,28 @@ namespace eval Editor { bind $txt <> "SetModifiedFlag $w" bind $txt <> "Editor::SelectionGet $txt" bind $txt ImageBase64Encode + bind $txt "Editor::SearchBrackets %W" } - + + 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 + } + proc QuotSelection {txt symbol} { variable selectionText set selIndex [$txt tag ranges sel] @@ -458,7 +480,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" @@ -511,7 +533,53 @@ namespace eval Editor { # Position return 1 } + # "Alexander Dederer (aka Korwin) + ## 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} + 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 Editor {fileFullPath nb itemName} { global cfgVariables set fr $itemName @@ -539,6 +607,7 @@ namespace eval Editor { if {$cfgVariables(lineNumberShow) eq "false"} { $txt configure -linemap 0 } + $txt tag configure lightBracket -background #000000 -foreground #00ffff set fileType [string toupper [string trimleft [file extension $fileFullPath] "."]] if {$fileType eq ""} {set fileType "Unknown"} diff --git a/projman.tcl b/projman.tcl index 8e0283f..47af2ac 100755 --- a/projman.tcl +++ b/projman.tcl @@ -10,7 +10,7 @@ exec wish "$0" -- "$@" ###################################################### # Version: 2.0.0 # Release: alpha -# Build: 12082022153746 +# Build: 15082022110520 ###################################################### # определим текущую версию, релиз и т.д.