From aaa027398aab807014261f07bf715b813480477c Mon Sep 17 00:00:00 2001 From: svk Date: Tue, 27 Jan 2026 14:22:55 +0300 Subject: [PATCH] =?UTF-8?q?=D0=A1=D0=B4=D0=B5=D0=BB=D0=B0=D0=BD=D0=B0=20?= =?UTF-8?q?=D0=BE=D0=B1=D1=80=D0=B0=D0=B1=D0=BE=D1=82=D0=BA=D0=B0=20=D1=88?= =?UTF-8?q?=D0=B0=D0=B1=D0=BB=D0=BE=D0=BD=D0=BE=D0=B2=20=D0=BA=D0=BE=D0=BC?= =?UTF-8?q?=D0=B0=D0=BD=D0=B4=D0=BD=D0=BE=D0=B9=20=D1=81=D1=82=D1=80=D0=BE?= =?UTF-8?q?=D0=BA=D0=B8=20=D0=B8=20=D0=B7=D0=B0=D0=BF=D1=83=D1=81=D0=BA=20?= =?UTF-8?q?=D0=B2=D0=BD=D0=B5=D1=88=D0=BD=D0=B8=D1=85=20=D0=B8=D0=BD=D1=81?= =?UTF-8?q?=D1=82=D1=80=D1=83=D0=BC=D0=B5=D0=BD=D1=82=D0=BE=D0=B2.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- lib/editor.tcl | 12 +++++++++--- lib/tools.tcl | 28 +++++++++++++++++++++++----- lib/tree.tcl | 10 +++++++++- 3 files changed, 41 insertions(+), 9 deletions(-) diff --git a/lib/editor.tcl b/lib/editor.tcl index 7e585ee..09a0e08 100644 --- a/lib/editor.tcl +++ b/lib/editor.tcl @@ -363,15 +363,21 @@ namespace eval Editor { } } - proc SelectionGet {txt} { - variable selectionText + proc SelectionGet {{txt ""}} { + global nbEditor + variable selectionText "" + if {$txt eq ""} { + DebugPuts "Editor::SelectionGet: [focus]" + set txt [focus] + } 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] } + return $selectionText } - + proc SelectionHighlight {txt} { variable selectionText $txt tag remove lightSelected 1.0 end diff --git a/lib/tools.tcl b/lib/tools.tcl index 4be511d..68a467e 100644 --- a/lib/tools.tcl +++ b/lib/tools.tcl @@ -11,7 +11,7 @@ namespace eval Tools {} { } set ::toolsDefault "\[VisualRegexp\] -commandString=tkregexp % +commandString=tkregexp %s description'A graphical front-end to write/debug regular expression icon= shortCut= @@ -125,7 +125,7 @@ proc Tools::GetMenu {m} { } proc Tools::Execute {toolName} { - global cfgVariables toolsVariables + global cfgVariables toolsVariables tree if ![dict exists $::toolsVariables $toolName commandString] { DebugPuts "Tools::Execute: command for $toolName not found" return @@ -133,18 +133,36 @@ proc Tools::Execute {toolName} { set command [dict get $::toolsVariables $toolName commandString] DebugPuts "Tools::Execute: command for $toolName as $command" } - # 1. Определять текущий файл + + set fullCommand $command + # 2. Определять выделен ли текст в открытом редакторе + set selectedText [Editor::SelectionGet] + if {$selectedText ne ""} { + regsub -all "%s" $command "$selectedText" fullCommand + DebugPuts "Tools::Execute: selected text \"$selectedText\", command \"$fullCommand\"" + } + + # 1. Определять текущий файл # 3. Опеределять сколько файлов выделено в дереве # 4. Заменяем знак %f на имя текущего файла (файлов) # regsub -all "%f" $command "$filePath" fullCommand + set filesList [Tree::GetSelectedItemValues $tree] + if {$filesList ne ""} { + foreach file $filesList { + # Если больше нет %f для замены, выходим из цикла + if {![string match "*%f*" $fullCommand]} break + set fullCommand [regsub {%f} $fullCommand $file] + } + DebugPuts "Tools::Execute: $fullCommand" + } + # 5. Заменяем %s на выделенный в редакторе текст # 6. Заменяем %d на текущий каталог(и), если он выделен в дереве, # и если не выделено то корневой открытый в дереве # 7. Проверять команды на доступность в системе и подставлять полный путь к команде # если в конфиге не указан полный путь. - set pipe [open "|$command" "r"] + set pipe [open "|$fullCommand" "r"] fileevent $pipe readable fconfigure $pipe -buffering none -blocking no } - diff --git a/lib/tree.tcl b/lib/tree.tcl index 920c63a..2fc99ab 100644 --- a/lib/tree.tcl +++ b/lib/tree.tcl @@ -99,6 +99,7 @@ namespace eval Tree { proc PressItem {tree} { global nbEditor lexers editors activeProject set id [$tree selection] + if {[llength $id] > 1} {return} $tree tag remove selected $tree item $id -tags selected SetActiveProject [GetItemID $tree [GetUpperItem $tree $id]] @@ -160,5 +161,12 @@ namespace eval Tree { GetUpperItem $tree $parent } } - + + proc GetSelectedItemValues {tree} { + set valuesList "" + foreach itemID [$tree selection] { + lappend valuesList [GetItemID $tree $itemID] + } + return $valuesList + } }