From 8619e3e1f40a00ce4e129fd9ecbd5c0f9eaeb2a9 Mon Sep 17 00:00:00 2001 From: Sergey Kalinin Date: Wed, 29 Oct 2025 19:59:57 +0300 Subject: [PATCH] =?UTF-8?q?=D0=94=D0=BE=D0=B1=D0=B0=D0=B2=D0=B8=D0=BB=20?= =?UTF-8?q?=D0=BF=D1=81=D0=B5=D0=B2=D0=B4=D0=BE-=D1=82=D0=B5=D1=80=D0=BC?= =?UTF-8?q?=D0=B8=D0=BD=D0=B0=D0=BB,=20=D0=B8=20=D0=BA=D0=BE=D0=BC=D0=B0?= =?UTF-8?q?=D0=BD=D0=B4=D1=8B=20=D0=B7=D0=B0=D0=BF=D1=83=D1=81=D0=BA=D0=B0?= =?UTF-8?q?=20=D1=84=D0=B0=D0=B9=D0=BB=D0=BE=D0=B2.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- TODO | 5 +- lib/editor.tcl | 60 +++++++++- lib/gui.tcl | 15 ++- lib/image_library.tcl | 17 ++- lib/menu.tcl | 2 +- lib/msgs/en.msg | 2 +- lib/msgs/ru.msg | 1 + lib/procedure.tcl | 269 ++++++++++++++++++++++++++++++++++++++++++ tkregexp.tcl | 2 - 9 files changed, 357 insertions(+), 16 deletions(-) diff --git a/TODO b/TODO index 0110303..9872303 100644 --- a/TODO +++ b/TODO @@ -7,7 +7,7 @@ --- Ansible --- 1. Определение всех переменных в отдельный список - - внутри файла, конструкции вида: +- внутри файла, конструкции вида: set_fact: varName: value set_fact varName value @@ -18,5 +18,4 @@ - var1.yml - var2.yml -3. Если используется роль и переменная не найдена в плэйбуке то искать в роли (не факт что требуется) - +3. Если используется роль и переменная не найдена в плэйбуке diff --git a/lib/editor.tcl b/lib/editor.tcl index df01414..dc592a0 100644 --- a/lib/editor.tcl +++ b/lib/editor.tcl @@ -786,8 +786,11 @@ namespace eval Editor { bind $txt Quit bind $txt "Editor::SelectionPaste $txt" bind $txt "Editor::SelectionPaste $txt" + bind $txt "Editor::SelectionPaste $txt" bind $txt "SearchVariable $txt; break" + bind $txt "SearchVariable $txt; break" bind $txt "ImageBase64Encode $txt" + bind $txt "ImageBase64Encode $txt" bind $txt "Editor::InsertTabular $txt" bind $txt "Editor::DeleteTabular $txt" bind $txt "Editor::Comment $txt $fileType" @@ -797,25 +800,35 @@ namespace eval Editor { bind $txt "Editor::SearchBrackets $txt" bind $txt "Editor::SelectionHighlight $txt" bind $txt <> "SetModifiedFlag $w $nb" - bind $txt ImageBase64Encode bind $txt "Editor::SearchBrackets %W" + bind $txt "Editor::SearchBrackets %W" bind $txt "catch {Editor::GoToFunction $txt}" bind $txt "catch {Editor::GoToFunction $txt}; break" + bind $txt "catch {Editor::GoToFunction $txt}; break" bind $txt "$txt delete {insert wordstart} {insert wordend}" bind $txt "$txt delete {insert wordstart} {insert wordend}" + bind $txt "$txt delete {insert wordstart} {insert wordend}" bind $txt "$txt delete {insert linestart} {insert lineend + 1char}" bind $txt "$txt delete {insert linestart} {insert lineend + 1char}" + bind $txt "$txt delete {insert linestart} {insert lineend + 1char}" bind $txt "$txt delete {insert linestart} insert" + bind $txt "$txt delete {insert linestart} insert" bind $txt "$txt delete insert {insert lineend}" + bind $txt "$txt delete insert {insert lineend}" bind $txt "Editor::SplitEditorH $w $fileType" bind $txt "Editor::SplitEditorH $w $fileType" + bind $txt "Editor::SplitEditorH $w $fileType" bind $txt "Editor::TextCopy $txt" + bind $txt "Editor::TextCopy $txt" bind $txt "Editor::GoToLineNumberDialog $txt" + bind $txt "Editor::GoToLineNumberDialog $txt" bind $txt "Editor::FindDialog $w" bind $txt "Editor::FindDialog $txt" + bind $txt "Editor::FindDialog $txt" bind $txt "Editor::FindDialog $txt" bind $txt FileOper::Close bind $txt FileOper::Close + bind $txt FileOper::Close bind $txt { set filePath [FileOper::OpenDialog] if {$filePath != ""} { @@ -830,6 +843,16 @@ namespace eval Editor { } break } + bind $txt { + set filePath [FileOper::OpenDialog] + if {$filePath != ""} { + FileOper::Edit $filePath + } + break + } + bind $txt "Editor::SplitEditorForExecute $w $fileType $nb " + bind $txt "Editor::SplitEditorForExecute $w $fileType $nb " + # bind $txt.t "Editor::ReleaseKey %K $txt.t $fileType" # bind $txt.t "Editor::PressKey %K $txt.t" # bind $txt "Editor::Key %k %K" @@ -939,7 +962,7 @@ namespace eval Editor { # set fileName untitled-$untitledNumber set fileFullPath untitled-$untitledNumber #puts [Tree::InsertItem $tree {} $fileFullPath "file" $fileName] - set nbEditorItem [NB::InsertItem $nbEditor $fileFullPath "file"] + set nbEditorItem [NB::InsertItem $nbEditor $fileFullPath "file"] # puts "$nbEditorItem, $nbEditor" Editor $fileFullPath $nbEditor $nbEditorItem SetModifiedFlag $nbEditorItem $nbEditor @@ -1367,7 +1390,7 @@ namespace eval Editor { proc SplitEditorV {fileFullPath} { global cfgVariables - regsub -all {\.|/|\\|\s} $fileFullPath "_" itemName + regsub -all {\.|/|\\|\s|:} $fileFullPath "_" itemName set itemName ".frmWork.nbEditor2.$itemName" # puts $itemName if {[winfo exists $itemName] == 1} { @@ -1390,8 +1413,6 @@ namespace eval Editor { # grid rowconfigure .frmWork .frmWork.nbEditor2 -weight 1 .frmWork.panelNB add .frmWork.nbEditor2 -weight 0 puts [FileOper::Edit $fileFullPath .frmWork.nbEditor2] - - } proc GoToLineNumber {text lineNumber} { @@ -1537,9 +1558,13 @@ namespace eval Editor { -command "Editor::SplitEditorH $fr $fileType $nb" ttk::button $fr.header.$btnSplitV -image split_vertical_11x11 \ -command "Editor::SplitEditorV $fileFullPath" + + set btnSplitExecute "btnSplitExec[string range $itemName [expr [string last "." $itemName] +1] end]" + ttk::button $fr.header.$btnSplitExecute -image execute_11x11 \ + -command "Editor::SplitEditorForExecute $fr $fileType $nb $fileFullPath" # 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.$btnSplitV $fr.header.$btnSplitH $fr.header.$btnSplitExecute -side right pack $fr.header -side top -fill x @@ -1557,4 +1582,27 @@ namespace eval Editor { return $fr } + + proc SplitEditorForExecute {w fileType nb {fileFullPath ""}} { + global cfgVariables tree + if {$fileFullPath eq ""} { + set treeItem "file::[string range $w [expr [string last "." $w] +1] end ]" + set fileFullPath [Tree::GetItemID $tree $treeItem] + puts $fileFullPath + } + # puts [$w.panelTxt panes] + puts "$w $fileType $nb $fileFullPath" + if [winfo exists $w.frmText2] { + $w.panelTxt forget $w.frmText2 + destroy $w.frmText2 + focus -force $w.frmText.t.t + return + } + + set frmText [ttk::frame $w.frmText2 -border 1] + $w.panelTxt add $frmText -weight 1 + # focus -force $frmText.t.t + Execute $fileFullPath $frmText + } + } diff --git a/lib/gui.tcl b/lib/gui.tcl index bd0a668..385e65b 100644 --- a/lib/gui.tcl +++ b/lib/gui.tcl @@ -23,12 +23,14 @@ wm overrideredirect . 0 bind . Quit bind . Quit +bind . Quit bind . Quit bind . Add bind . Del bind . ShowHelpDialog bind . Editor::New bind . Editor::New +bind . Editor::New bind . { set filePath [FileOper::OpenDialog] if {$filePath != ""} { @@ -41,21 +43,30 @@ bind . { FileOper::Edit $filePath } } -bind . { +bind . { set folderPath [FileOper::OpenFolderDialog] if {$folderPath != ""} { FileOper::ReadFolder $folderPath } } -bind . { +bind . { set folderPath [FileOper::OpenFolderDialog] if {$folderPath != ""} { FileOper::ReadFolder $folderPath } } +bind . { + set folderPath [FileOper::OpenFolderDialog] + if {$folderPath != ""} { + FileOper::ReadFolder $folderPath + } +} + bind . {FileOper::Save} bind . {FileOper::Save} +bind . {FileOper::Save} bind . {ViewFilesTree true} +bind . {ViewFilesTree true} bind . {catch [PopupMenu %X %Y]} #ttk::style configure TPanedwindow -background blue diff --git a/lib/image_library.tcl b/lib/image_library.tcl index 3d24098..359b909 100644 --- a/lib/image_library.tcl +++ b/lib/image_library.tcl @@ -1912,4 +1912,19 @@ image create photo j2_16x12 -data { waYDtkPwRhMJCQAAcy6XQBVVAwTH2sGQ25vNaAwYtjCvkcjhE5Ysd1Cwe/gmifh0nQMAwBvJ5H54 5nEG7+28M9SARyoW37c7A72MxzFpr/Dd1sUKRxpZbJg7joMDAwDgDzlS9ta5m7mUAAAAAElFTkSu QmCC -} +} +image create photo execute_11x11 -data { + iVBORw0KGgoAAAANSUhEUgAAAAsAAAALCAYAAACprHcmAAABg2lDQ1BJQ0MgcHJvZmlsZQAAKJF9 + kT1Iw1AUhU9TpVIqDnYQUclQneyiIo5ahSJUCLVCqw4mL/2DJg1Jiouj4Fpw8Gex6uDirKuDqyAI + /oC4C06KLlLifUmhRYwPLu/jvHcO990HCI0K06yuWUDTbTOdTIjZ3KoYekUYw1QjiMrMMuYkKQXf + 9XWPAN/v4jzL/96fq1fNWwwIiMSzzDBt4g3i6U3b4LxPHGUlWSU+Jx43qUHiR64rHr9xLros8Myo + mUnPE0eJxWIHKx3MSqZGPEUcUzWd8oWsxyrnLc5apcZaffIXRvL6yjLXqYaQxCKWIEGEghrKqMBG + nHadFAtpOk/4+Addv0QuhVxlMHIsoAoNsusH/4Pfs7UKkxNeUiQBdL84zscoENoFmnXH+T52nOYJ + EHwGrvS2v9oAZj5Jr7e12BHQtw1cXLc1ZQ+43AEGngzZlF0pSCUUCsD7GX1TDui/BcJr3txa5zh9 + ADI0q9QNcHAIjBUpe93n3T2dc/v3Tmt+P5frcrXBnzRwAAAABmJLR0QA/wD/AP+gvaeTAAAACXBI + WXMAAC4jAAAuIwF4pT92AAAAB3RJTUUH6QodCiMdxWTpZwAAABl0RVh0Q29tbWVudABDcmVhdGVk + IHdpdGggR0lNUFeBDhcAAABHSURBVBjTjY/BDQAwCAKNUzleux1b2Y+PxgiRJ7kjalYBkADSRLwX + SvCpZIKzlUlwdWMXJFw5Kzgi7mr5A/XyBI4wA9kzFHrskxvBNKQinAAAAABJRU5ErkJggg== +} + + diff --git a/lib/menu.tcl b/lib/menu.tcl index 008c530..94de67a 100644 --- a/lib/menu.tcl +++ b/lib/menu.tcl @@ -33,7 +33,7 @@ proc GetFileMenu {m} { $m add separator - $m add command -label [::msgcat::mc "Open folder"] -accelerator "Ctrl+K" -command { + $m add command -label [::msgcat::mc "Open folder"] -accelerator "Alt+K" -command { set folderPath [FileOper::OpenFolderDialog] if {$folderPath != ""} { # set activeProject $folderPath diff --git a/lib/msgs/en.msg b/lib/msgs/en.msg index 2c93b2b..1840432 100644 --- a/lib/msgs/en.msg +++ b/lib/msgs/en.msg @@ -59,6 +59,7 @@ ::msgcat::mcset en "Editor font bold" ::msgcat::mcset en "Error open URL" ::msgcat::mcset en "Editor settings" +::msgcat::mcset en "Enter command for execute file" ::msgcat::mcset en "Exit" ::msgcat::mcset en "File" ::msgcat::mcset en "File already exists. Overwrite?" @@ -185,4 +186,3 @@ - diff --git a/lib/msgs/ru.msg b/lib/msgs/ru.msg index 1d55188..bed78a8 100644 --- a/lib/msgs/ru.msg +++ b/lib/msgs/ru.msg @@ -77,6 +77,7 @@ ::msgcat::mcset ru "Editor settings" "Настройки редактора" ::msgcat::mcset ru "Editor helpers" "Подсказки при вводе" ::msgcat::mcset ru "Encode" "Перекодировка" +::msgcat::mcset ru "Enter command for execute file" "Введите команду для запуска текущего файла" ::msgcat::mcset ru "Authorisation required" "Требуется авторизация" ::msgcat::mcset ru "Error open URL" "Ошибка открытия URL" ::msgcat::mcset ru "Exit" "Выход" diff --git a/lib/procedure.tcl b/lib/procedure.tcl index 0e310c0..65888ee 100644 --- a/lib/procedure.tcl +++ b/lib/procedure.tcl @@ -714,3 +714,272 @@ proc AddRecentEditedFolder {path} { } .frmMenu.mnuFile.m.openRecent add command -label $path -command [list OpenRecentProject $path] } + +# ================== OLD ==================== +proc launchBrowser {url} { + global tcl_platform + if {$tcl_platform(platform) eq "windows"} { + set command [list {*}[auto_execok start] {}] + if {[file isdirectory $url]} { + set url [file nativename [file join $url .]] + } + } elseif {$tcl_platform(os) eq "Darwin"} { + set command [list open] + } else { + set command [list xdg-open] + } + exec {*}$command $url & +} +## EXEC EXTERNAL BROWSER AND GOTO URL ## +proc GoToURL {url} { + global env tcl_platform + if {$tcl_platform(platform) == "windows"} { + set pipe [open "|iexplore $url" "r"] + } elseif {$tcl_platform(platform) == "mac"} { + set pipe [open "|iexplore $url" "r"] + } elseif {$tcl_platform(platform) == "unix"} { + #$env(BROWSER) + #set pipe [open "|$env(BROWSER) $url" "r"] + launchBrowser $url + return + } + fileevent $pipe readable + fconfigure $pipe -buffering none -blocking no +} +## MAKING TAR ARCHIVE ## +proc MakeTGZ {} { + global activeProject tgzDir tgzNamed workDir projDir env tcl_platform + if {$activeProject == ""} { + set answer [tk_messageBox\ + -message [::msgcat::mc "Not found active project"]\ + -type ok -icon warning\ + -title [::msgcat::mc "Warning"]] + case $answer { + ok {return 0} + } + } + FileDialog tree save_all + set file [open [file join $workDir $activeProject.proj] r] + while {[gets $file line]>=0} { + scan $line "%s" keyWord + set string [string range $line [string first "\"" $line] [string last "\"" $line]] + set string [string trim $string "\""] + if {$keyWord == "ProjectDirName"} { + set dir "$string" + } + if {$keyWord == "ProjectVersion"} { + set version "$string" + } + if {$keyWord == "ProjectRelease"} { + set release "$string" + } + } + close $file + set res [split $tgzNamed "-"] + set name [lindex $res 0] + set ver [lindex $res 1] + set rel [lindex $res 2] + if {$name == "projectName"} { + set name $activeProject + } + if {$ver == "version"} { + append name "-$version" + } + if {$rel == "release"} { + append name "-$release" + } + # multiplatform featuring # + if {$tcl_platform(platform) == "windows"} { + append name ".zip" + } elseif {$tcl_platform(platform) == "mac"} { + append name ".zip" + } elseif {$tcl_platform(platform) == "unix"} { + append name ".tar.gz" + } + catch {cd $projDir} res + if {[file exists [file join $tgzDir $name]] == 1} { + set answer [tk_messageBox\ + -message "[::msgcat::mc "File already exists. Overwrite?"] \"$name\" ?"\ + -type yesno -icon question -default yes\ + -title [::msgcat::mc "Question"]] + case $answer { + yes {file delete [file join $tgzDir $name]} + no {return 0} + } + } + # multiplatform featuring # + if {$tcl_platform(platform) == "windows"} { + catch [exec pkzip -r -p [file join $tgzDir $name] [file join $activeProject *]] err + } elseif {$tcl_platform(platform) == "mac"} { + catch [exec zip -c [file join $tgzDir $name] $activeProject] err + } elseif {$tcl_platform(platform) == "unix"} { + catch [exec tar -czvf [file join $tgzDir $name] $activeProject] err + } + # message dialog # + set msg "[::msgcat::mc "Archive created in"] [file join $tgzDir $name]" + set icon info + set answer [tk_messageBox\ + -message "$msg"\ + -type ok -icon $icon] + case $answer { + ok {return 0} + } +} + +## MAKE PROJ PROCEDURE (RUNNING PROJECT) ## +proc Execute {filePath w} { + global activeProject cfgVariables + if {$activeProject == ""} { + set answer [tk_messageBox\ + -message "[::msgcat::mc "Not found active project"]"\ + -type ok -icon warning\ + -title [::msgcat::mc "Warning"]] + case $answer { + ok {return 0} + } + } + FileOper::Save + set file $filePath + set action run + # if {$action == "compile"} { + + # if {$t == "proj"} { + # set prog [file join $projDirName $projFileName.java] + # } elseif {$t == "file"} { + # set node [$tree selection get] + # set fullPath [$tree itemcget $node -data] + # set dir [file dirname $fullPath] + # set file [file tail $fullPath] + # set prog $fullPath + # } + # } elseif {$action == "run"} { + # if {$t == "proj"} { + # set prog [file join $projDirName $projFileName] + # } elseif {$t == "file"} { + # set node [$tree selection get] + # set fullPath [$tree itemcget $node -data] + # set dir [file dirname $fullPath] + # set file [file tail $fullPath] + # set prog $fullPath + # } + # } + + # set node "debug" + # if {[$noteBook index $node] != -1} { + # $noteBook delete debug + # } + # set w [$noteBook insert end $node -text [::msgcat::mc "Running project"]] + # create array with file names # + frame $w.frame -borderwidth 2 -relief ridge -background $cfgVariables(backGround) + pack $w.frame -side top -fill both -expand true + + + text $w.frame.text -yscrollcommand "$w.frame.yscroll set" \ + -bg $cfgVariables(backGround) -fg $cfgVariables(foreground) \ + -relief sunken -wrap word -highlightthickness 0 -font $cfgVariables(font)\ + -selectborderwidth 0 -selectbackground $cfgVariables(selectbg) -width 10 -height 10 + scrollbar $w.frame.yscroll -relief sunken -borderwidth {1} -width {10} -takefocus 0 \ + -command "$w.frame.text yview" -background $cfgVariables(backGround) + + pack $w.frame.text -side left -fill both -expand true + pack $w.frame.yscroll -side left -fill y + + # frame $w.frmBtn -borderwidth 2 -relief ridge -bg $cfgVariables(backGround) + # pack $w.frmBtn -side top -fill x + # button $w.frmBtn.btnOk -text [::msgcat::mc "Close"] -borderwidth {1} \ + # -bg $cfgVariables(backGround) -fg $cfgVariables(backGround) -command { + # $noteBook delete debug + # $noteBook raise [$noteBook page end] + # return 0 + # } + # pack $w.frmBtn.btnOk -pady 2 + # key bindings # + # bind $w.frmBtn.btnOk { + # $noteBook delete debug + # $noteBook raise [$noteBook page end] + # # return 0 + # } + + bind $w.frame.text [list Run $w $filePath] + bind $w.frame.text [list destroy $w] + bind $w.frame.text [list destroy $w] + # focus -force $w.frmBtn.btnOk + # $noteBook raise $node + # insert debug data into text widget # + $w.frame.text tag configure bold -font $cfgVariables(fontBold) + $w.frame.text tag configure error -font $cfgVariables(fontBold) -foreground red + $w.frame.text tag add bold 0.0 0.end + # if {$action == "compile"} { + # $w.frame.text insert end "[::msgcat::mc "Compile project"] - $activeProject\n" + # $w.frame.text insert end "[::msgcat::mc "Compile"] - $prog\n\n" + # } elseif {$action == "run"} { + # $w.frame.text insert end "[::msgcat::mc "Running project"] - $activeProject\n" + # $w.frame.text insert end "[::msgcat::mc "Run"] - $prog\n\n" + # } + $w.frame.text insert end "[::msgcat::mc "Enter command for execute file"] $filePath >\n" + set pos [$w.frame.text index insert] + set lineNum [lindex [split $pos "."] 0] + $w.frame.text insert 0.0 "^^^^^^^^^^^^^^^^^^^^^ [::msgcat::mc "Programm output"] ^^^^^^^^^^^^^^^^^\n" + $w.frame.text tag add bold $lineNum.0 $lineNum.end + focus -force $w.frame.text + # open and manipulate executed program chanel # + # cd $projDirName + # if {$action == "compile"} { + # set cmdCompile "" + # CompileOption "$projCompiler $prog" + # vwait cmdCompile + # puts "string - $projCompiler $prog" ;# debug info + # set pipe [open "|$cmdCompile 2> [file join $projDirName errors]" "r"] + # set f [open [file join $projDirName errors] "r"] + # } elseif {$action == "run"} { + # set pipe [open "|$command $filePath" "r"] + # set f [open [file join $projDirName errors] "r"] + # } + + +} + +proc Run {w filePath} { + # Получаем индекс конца последней строки + set endIndex [$w.frame.text index "end-1c"]; # или "end-1l lineend" + + # Получаем индекс начала последней строки + set startIndex [$w.frame.text index "end-1l linestart"] + + set command [$w.frame.text get $startIndex $endIndex end] + set pipe [open "|$command $filePath 2> [file join [file dirname $filePath] errors]" "r"] + set f [open [file join [file dirname $filePath] errors] "r"] + + # set pipe [open "|$command $filePath" "r"] + # set f [open [file join ~ tmp errors] "r"] + fileevent $pipe readable [list DebugInfo $w.frame.text $pipe $f] + fconfigure $pipe -buffering none -blocking no +} + +## INSERT DEBUG INFORMATION INTO TEXT WIDGET ## +proc DebugInfo {widget file f} { + $widget configure -state normal + if {[eof $file]} { + catch [close $file] msg + if {$msg != ""} { + puts $msg + $widget insert "end-4l linestart" "[::msgcat::mc "Program failed"]: $msg\n"; + } else { + puts $msg + $widget see "end-1l lineend" + $widget delete "end-1l lineend" end + # $widget insert end "\n-------------------------------------------------\n" + # $widget insert end "[::msgcat::mc "Program finished successfully"]\n" + } + } else { + $widget insert "end-4l linestart" [read $file] + } + while {[gets $f line]>=0} { + $widget insert "end-4l linestart" "$line\n" + puts $line + } + # close $f + $widget see end + $widget tag add error 0.0 0.end + # $widget configure -state disabled +} diff --git a/tkregexp.tcl b/tkregexp.tcl index 4f00829..63e2b92 100755 --- a/tkregexp.tcl +++ b/tkregexp.tcl @@ -1365,5 +1365,3 @@ proc make-regexp::make-regexp {words} { set regexp } #============================================================================================== - -