diff --git a/lib/editor.tcl b/lib/editor.tcl index d8e3272..ac9912c 100644 --- a/lib/editor.tcl +++ b/lib/editor.tcl @@ -594,9 +594,22 @@ namespace eval Editor { # Выбираем переменные if {[dict exists $lexers $fileType varRegexpCommand] != 0 } { if {[eval [dict get $lexers $fileType varRegexpCommand]]} { - set varName [string trim $varName] - set varValue [string trim $varValue] - puts "variable: $varName, value: $varValue" + 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" lappend varList [list $varName $varValue] } } @@ -979,6 +992,21 @@ proc FindFunction {findString} { focus -force $win.entryFind } + proc SplitEditor {w orient} { + ttk::panedwindow $w.panelTxt -orient horizontal -style TPanedwindow + pack propagate $w.panelTxt false + set frmText [ttk::frame $w.frmText2 -border 1] + + pack $frmText -side top -expand true -fill both + ctext $frmText.t2 + pack $frmText.t2 -fill both -expand 1 + $frmText.t2 insert end [$w.frmText.t get 0.0 end] + + $w.panelTxt add $w.frmText -weight 0 + $w.panelTxt add $w.frmText2 -weight 1 + + } + proc Editor {fileFullPath nb itemName} { global cfgVariables editors set fr $itemName @@ -988,15 +1016,34 @@ proc FindFunction {findString} { set lblText "" } - - set lblName "lbl[string range $itemName [expr [string last "." $itemName] +1] end]" - ttk::label $fr.$lblName -text $lblText - pack $fr.$lblName -side top -anchor w -fill x + ttk::frame $fr.header set frmText [ttk::frame $fr.frmText -border 1] set txt $frmText.t + + 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 \ + -command "Editor::SplitEditor $fr horizontal" + ttk::button $fr.header.$btnSplitV -image split_vertical_11x11 \ + -command "Editor::SplitEditor $fr vertical" -state disable + # 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 + + # set frmText [ttk::frame $fr.frmText -border 1] + # set txt $frmText.t + + + pack $frmText -side top -expand true -fill both - pack $frmText -side top -expand true -fill both + 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" \ diff --git a/lib/files.tcl b/lib/files.tcl index e0d7439..6dc04b1 100644 --- a/lib/files.tcl +++ b/lib/files.tcl @@ -253,7 +253,7 @@ namespace eval FileOper { } $nbEditor select $itemName Editor::ReadStructure $itemName.frmText.t $treeItemName - + GetVariablesFromFile $fileFullPath focus -force $itemName.frmText.t.t return $itemName diff --git a/lib/image_library.tcl b/lib/image_library.tcl index 307e24c..b0b62c7 100644 --- a/lib/image_library.tcl +++ b/lib/image_library.tcl @@ -1042,4 +1042,30 @@ image create photo rb_16x12 -data { CzIvGoj4DsCkhTmmAGBW62A4o6kV1jF1u6krFMRBLrRt+RN/zRuAsFTFUDTjWwAAAABJRU5ErkJg gg== } - +image create photo split_horizontal_11x11 -data { + iVBORw0KGgoAAAANSUhEUgAAAAsAAAALCAYAAACprHcmAAABhWlDQ1BJQ0MgcHJvZmlsZQAAKJF9 + kT1Iw0AcxV9TtVUqDhYUcchQnSyKijhqFYpQIdQKrTqYXPohNGlIUlwcBdeCgx+LVQcXZ10dXAVB + 8APE0clJ0UVK/F9TaBHjwXE/3t173L0DhGqRaVbbGKDptpmMx8R0ZkUMvKITQXRgFH0ys4xZSUrA + c3zdw8fXuyjP8j735+hWsxYDfCLxDDNMm3ideGrTNjjvE4dZQVaJz4lHTLog8SPXFZffOOfrLPDM + sJlKzhGHicV8CystzAqmRjxJHFE1nfKFtMsq5y3OWrHMGvfkLwxl9eUlrtMcRBwLWIQEEQrK2EAR + NqK06qRYSNJ+zMM/UPdL5FLItQFGjnmUoEGu+8H/4He3Vm5i3E0KxYD2F8f5GAICu0Ct4jjfx45T + OwH8z8CV3vSXqsD0J+mVphY5Anq2gYvrpqbsAZc7QP+TIZtyXfLTFHI54P2MvikD9N4CXatub419 + nD4AKeoqcQMcHALDecpe83h3sLW3f880+vsBV4RynDgDEA4AAAAGYktHRAAAAAAAAPlDu38AAAAJ + cEhZcwAALiMAAC4jAXilP3YAAAAHdElNRQfmCQgGNhfKL3ChAAAAGXRFWHRDb21tZW50AENyZWF0 + ZWQgd2l0aCBHSU1QV4EOFwAAAE5JREFUGNNjnDlz5n8GIkB6ejojEwPxoJwFSWcjNhUzZ86shzI5 + WdDkJjIwMPxAE4MpZmBBM6EenztIcTMDKW5mGCRuZoQFOAMDAychxQAqohbDLvYTmQAAAABJRU5E + rkJggg== +} +image create photo split_vertical_11x11 -data { + iVBORw0KGgoAAAANSUhEUgAAAAsAAAALCAYAAACprHcmAAABhWlDQ1BJQ0MgcHJvZmlsZQAAKJF9 + kT1Iw0AcxV9TtVUqDhYUcchQnSyKijhqFYpQIdQKrTqYXPohNGlIUlwcBdeCgx+LVQcXZ10dXAVB + 8APE0clJ0UVK/F9TaBHjwXE/3t173L0DhGqRaVbbGKDptpmMx8R0ZkUMvKITQXRgFH0ys4xZSUrA + c3zdw8fXuyjP8j735+hWsxYDfCLxDDNMm3ideGrTNjjvE4dZQVaJz4lHTLog8SPXFZffOOfrLPDM + sJlKzhGHicV8CystzAqmRjxJHFE1nfKFtMsq5y3OWrHMGvfkLwxl9eUlrtMcRBwLWIQEEQrK2EAR + NqK06qRYSNJ+zMM/UPdL5FLItQFGjnmUoEGu+8H/4He3Vm5i3E0KxYD2F8f5GAICu0Ct4jjfx45T + OwH8z8CV3vSXqsD0J+mVphY5Anq2gYvrpqbsAZc7QP+TIZtyXfLTFHI54P2MvikD9N4CXatub419 + nD4AKeoqcQMcHALDecpe83h3sLW3f880+vsBV4RynDgDEA4AAAAGYktHRAAAAAAAAPlDu38AAAAJ + cEhZcwAALiMAAC4jAXilP3YAAAAHdElNRQfmCQgGNTatazM8AAAAGXRFWHRDb21tZW50AENyZWF0 + ZWQgd2l0aCBHSU1QV4EOFwAAAEdJREFUGNNjnDlz5n8GIkB6ejojEwPxoJwJSWdjenp6Iy4+AwMD + J7rJE/Hx0RX/wMcnxc00VMxIQjg3kmYyLMAZGBg4CSkGAHuPE34LukmBAAAAAElFTkSuQmCC +} diff --git a/lib/lexers.tcl b/lib/lexers.tcl index 1841322..3585b96 100644 --- a/lib/lexers.tcl +++ b/lib/lexers.tcl @@ -15,7 +15,7 @@ dict set lexers TCL varRegexpCommand {regexp -nocase -all -- {^\s*?set\s+([a-zA- dict set lexers GO commentSymbol {//} dict set lexers GO procFindString {func.*?PROCNAME} dict set lexers GO procRegexpCommand {regexp -nocase -all -- {\s*?func\s*?(\(\w+\s*?\**?\w+\)|)\s*?(\w+)\((.*?)\)\s+?([a-zA-Z0-9\{\}\[\]\(\)-_.]*?|)\s*?\{} $line match linkName procName params returns} - +dict set lexers GO varRegexpCommand {regexp -nocase -all -line -- {^\s*?var\s+([a-zA-Z0-9\-_$]+)\s+(.+?)(\s*$)} $line match varName varType lineEnd} #-------------------------------------------------- # SHELL (Bash) dict set lexers SH commentSymbol {#} @@ -41,7 +41,7 @@ dict set lexers YML commentSymbol {#} dict set lexers YML tabSize 2 dict set lexers YML procFindString {(- name:)\s*?PROCNAME} dict set lexers YML procRegexpCommand {regexp -nocase -all -- {^\s*?- (name):\s(.+?)$} $line match keyWord procName} -dict set lexers YML varRegexpCommand {regexp -nocase -all -- {^\s*?([a-zA-Z0-9\-_$]+):\s+(.+?)(\s*$)} $line match varName varValue lineEnd} +dict set lexers YML varRegexpCommand {regexp -nocase -all -- {^(\s*?)([a-zA-Z0-9\-_$]+):\s+(.+?)(\s*$)} $line match indent varName varValue lineEnd} +dict set lexers YML varRegexpCommandMultiline {regexp -all -line -- {^(\s*)(set_fact|vars):$} $line match indent keyWord} dict set lexers ALL varDirectory {variables vars group_vars host_vars} - diff --git a/lib/procedure.tcl b/lib/procedure.tcl index dafde27..52aaa35 100644 --- a/lib/procedure.tcl +++ b/lib/procedure.tcl @@ -150,11 +150,17 @@ proc SearchVariable {txt} { puts "------$b -- [lindex $b 0]" if {$varName eq [lindex $b 0]} { puts "УРААААААА $varName = $b в файле $a \n\t [lindex $b 0]" - FindVariablesDialog $txt "$varName: $a" + # FindVariablesDialog $txt "$varName: \[...\][file tail $a]" + lappend l [list $varName [lindex $b 1] $a] } } } } + if [info exists l] { + FindVariablesDialog $txt $l + } else { + return + } } proc FindVariablesDialog {txt args} { global editors lexers @@ -172,18 +178,42 @@ proc FindVariablesDialog {txt args} { wm transient $win . wm overrideredirect $win 1 - listbox $win.lBox -width 50 -border 2 -yscrollcommand "$win.yscroll set" -border 1 - ttk::scrollbar $win.yscroll -orient vertical -command "$win.lBox yview" - pack $win.lBox -expand true -fill y -side left - pack $win.yscroll -side left -expand false -fill y - + # listbox $win.lBox -width 50 -border 2 -yscrollcommand "$win.yscroll set" -border 1 + ttk::treeview $win.lBox -show headings -height 5\ + -columns "variable value path" -displaycolumns "variable value path"\ + -yscrollcommand [list $win.v set] -xscrollcommand [list $win.h set] + + + ttk::scrollbar $win.v -orient vertical -command "$win.lBox yview" + ttk::scrollbar $win.h -orient horizontal -command "$win.lBox xview" + # pack $win.lBox -expand true -fill y -side left + # pack $win.yscroll -side left -expand false -fill y + # pack $win.xscroll -side bottom -expand false -fill x + + grid $win.lBox -row 0 -column 0 -sticky nsew + grid $win.v -row 0 -column 1 -sticky nsew + grid $win.h -row 1 -column 0 -sticky nsew + grid columnconfigure $win 0 -weight 1 + grid rowconfigure $win 0 -weight 1 + + $win.lBox heading variable -text [::msgcat::mc "Variable"] + $win.lBox heading value -text [::msgcat::mc "Value"] + $win.lBox heading path -text [::msgcat::mc "File path"] + set height 0 foreach { word } $args { - $win.lBox insert end $word + foreach lst $word { + # set l [split $lst " "] + puts "[lindex $lst 0] -[lindex $lst 1] -[lindex $lst 2]" + # lappend l2 [lindex $l 0] [lindex $l 1] [file tail [lindex $l 2]] + $win.lBox insert {} end -values $lst -text {1 2 3} + # $win.lBox insert end $word + incr height + } } + $win.lBox selection set I001 + # catch { $win.lBox activate 0 ; $win.lBox selection set 0 0 } - catch { $win.lBox activate 0 ; $win.lBox selection set 0 0 } - - if { [set height [llength $args]] > 10 } { set height 10 } + if { $height > 10 } { set height 10 } $win.lBox configure -height $height bind $win { @@ -198,15 +228,25 @@ proc FindVariablesDialog {txt args} { } bind $win.lBox { # set findString [dict get $lexers [dict get $editors $Editor::txt fileType] procFindString] - set values [.findVariables.lBox get [.findVariables.lBox curselection]] + set id [$win.lBox selection] + set values [$win.lBox item $id -values] + set key [lindex [split $id "::"] 0] + puts "- $id - $values - $key" # regsub -all {PROCNAME} $findString $values str # Editor::FindFunction "$str" destroy .findVariables + FileOper::Edit [lindex $values 2] # $txt tag remove sel 1.0 end # focus $Editor::txt.t break } - bind $win.lBox {Editor::ListBoxSearch %W %A} + # bind $win.lBox {Tree::DoublePressItem $win.lBox} + bind $win.lBox { + Tree::PressItem $win.lBox + break + } + + # bind $win.lBox {Editor::ListBoxSearch %W %A} # Определям расстояние до края экрана (основного окна) и если # оно меньше размера окна со списком то сдвигаем его вверх set winGeom [winfo reqheight $win] @@ -216,6 +256,8 @@ proc FindVariablesDialog {txt args} { set y [expr $topHeight - $winGeom] } wm geom $win +$x+$y + focus -force $win.lBox + $win.lBox focus I001 } diff --git a/lib/readstructure.tcl b/lib/readstructure.tcl index be95341..c306adb 100644 --- a/lib/readstructure.tcl +++ b/lib/readstructure.tcl @@ -19,6 +19,78 @@ proc GetVariablesFromFile {fileName} { set procList "" set varList "" set params "" + set varsBegin false + puts $fileName + set f [open "$fileName" r] + if {[dict exists $lexers $fileType] == 0} {return} + while {[gets $f line] >=0 } { + if {[dict exists $lexers $fileType varRegexpCommandMultiline] != 0 } { + if {[eval [dict get $lexers $fileType varRegexpCommandMultiline]]} { + if [info exists indent] { + set indentSize [string length $indent] + } else { + set indentSize 0 + } + set varsBegin true + puts "====== $varsBegin $indentSize" + continue + # lappend varList [list $varName $varValue] + } + } + if {$varsBegin eq "true"} { + set l [GetVarFromLine $line $fileType] + if {$line eq ""} { + set varsBegin false + puts "====== $varsBegin $indentSize [lindex $l 3]" + continue + } + if {[lindex $l 3] ne ""} { + if [expr [lindex $l 3] <= $indentSize] { + set varsBegin false + puts "====== $varsBegin $indentSize >[lindex $l 3]<" + continue + } + } + lappend varList [list [lindex $l 0] [lindex $l 1] [lindex $l 2]] + } + } + # puts $procList + # puts $varList + close $f + return $varList +} +proc GetVarFromLine {line fileType} { + global lexers + if {[dict exists $lexers $fileType varRegexpCommand] != 0 } { + if {[eval [dict get $lexers $fileType varRegexpCommand]]} { + 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 "" + } + set indentLength [string length $indent] + puts "variable: $varName, value: $varValue, type: $varType, indent: >$indent< $indentLength" + return [list $varName $varValue $varType $indentLength] + } + } +} +proc GetVariablesFromVarFile {fileName} { + global tree nbEditor editors lexers project + set fileType [string toupper [string trimleft [file extension $fileName] "."]] + set procList "" + set varList "" + set params "" + puts $fileName set f [open "$fileName" r] if {[dict exists $lexers $fileType] == 0} {return} while {[gets $f line] >=0 } { @@ -32,22 +104,13 @@ proc GetVariablesFromFile {fileName} { # } # } # Выбираем переменные - if {[dict exists $lexers $fileType varRegexpCommand] != 0 } { - if {[eval [dict get $lexers $fileType varRegexpCommand]]} { - set varName [string trim $varName] - set varValue [string trim $varValue] - # puts "variable: $varName, value: $varValue" - lappend varList [list $varName $varValue] - } - } + lappend varList [GetVarFromLine $line $fileType] } # puts $procList - # puts $varList + # puts $varList close $f return $varList } - - proc ReadFilesFromDirectory {directory root {type ""}} { global procList project lexers variables @@ -66,13 +129,31 @@ proc ReadFilesFromDirectory {directory root {type ""}} { } elseif {[file isdirectory $fileName] == 1} { # set type "" ReadFilesFromDirectory [file join $directory $fileName] $root - } - if {$type eq "var"} { + } + if {[string match {*inventory*} [string tolower $fileName]]} { + lappend project($root) [file join $root $directory $fileName] + set variables([file join $root $directory $fileName]) [GetVariablesFromVarFile [file join $root $directory $fileName]] + } + if {[string tolower $fileName] eq "ansible.cfg"} { + # puts "find ansible.cfg [file join $root $directory $fileName]" + set f [open [file join $root $directory $fileName] r] + while {[gets $f line] >= 0} { + # puts "\t$line" + if [regexp -nocase -all -- {^\s*inventory\s*=\s*(.+?)$} $line match fileName] { + # puts "Inventory file is a: $line" + lappend project($root) [file join $root $directory $fileName] + set variables([file join $root $directory $fileName]) [GetVariablesFromVarFile [file join $root $directory $fileName]] + } + } + close $f + } + + if {$type eq "var" && [file isdirectory [file join $root $directory $fileName]] != 1} { # puts ">>>>>$root $fileName" # puts "[GetVariablesFromFile $fileName]" # dict set project $root [file join $root $directory $fileName];# "[GetVariablesFromFile $fileName]" lappend project($root) [file join $root $directory $fileName] - set variables([file join $root $directory $fileName]) [GetVariablesFromFile $fileName] + set variables([file join $root $directory $fileName]) [GetVariablesFromVarFile [file join $root $directory $fileName]] # puts "[file join $root $directory $fileName]---$variables([file join $root $directory $fileName])" } } diff --git a/lib/tree.tcl b/lib/tree.tcl index 99d53ac..1d008c3 100644 --- a/lib/tree.tcl +++ b/lib/tree.tcl @@ -100,8 +100,8 @@ namespace eval Tree { set key [lindex [split $id "::"] 0] if {$values eq "" || $key eq ""} {return} - # puts "$key $tree $values" - switch $key { + puts "$key $tree $values" + switch -regexp $key { directory { FileOper::ReadFolder $values # $tree item $id -open false @@ -109,6 +109,10 @@ namespace eval Tree { file { FileOper::Edit $values } + I[0-9]*? { + destroy .findVariables + FileOper::Edit [lindex $values 2] + } default { set parentItem [$tree parent $id] # puts $values diff --git a/projman.tcl b/projman.tcl index 83445bf..2462990 100755 --- a/projman.tcl +++ b/projman.tcl @@ -10,7 +10,7 @@ exec wish "$0" -- "$@" ###################################################### # Version: 2.0.0 # Release: alpha -# Build: 02092022214055 +# Build: 05092022090515 ###################################################### # определим текущую версию, релиз и т.д.