beta2 #8

Merged
svk merged 49 commits from beta2 into master 2026-01-28 12:45:48 +03:00
11 changed files with 471 additions and 56 deletions
Showing only changes of commit aaa027398a - Show all commits

View File

@@ -363,15 +363,21 @@ namespace eval Editor {
} }
} }
proc SelectionGet {txt} { proc SelectionGet {{txt ""}} {
variable selectionText global nbEditor
variable selectionText ""
if {$txt eq ""} {
DebugPuts "Editor::SelectionGet: [focus]"
set txt [focus]
}
set selBegin [lindex [$txt tag ranges sel] 0] set selBegin [lindex [$txt tag ranges sel] 0]
set selEnd [lindex [$txt tag ranges sel] 1] set selEnd [lindex [$txt tag ranges sel] 1]
if {$selBegin ne "" && $selEnd ne ""} { if {$selBegin ne "" && $selEnd ne ""} {
set selectionText [$txt get $selBegin $selEnd] set selectionText [$txt get $selBegin $selEnd]
} }
return $selectionText
} }
proc SelectionHighlight {txt} { proc SelectionHighlight {txt} {
variable selectionText variable selectionText
$txt tag remove lightSelected 1.0 end $txt tag remove lightSelected 1.0 end

View File

@@ -11,7 +11,7 @@ namespace eval Tools {} {
} }
set ::toolsDefault "\[VisualRegexp\] set ::toolsDefault "\[VisualRegexp\]
commandString=tkregexp % commandString=tkregexp %s
description'A graphical front-end to write/debug regular expression description'A graphical front-end to write/debug regular expression
icon= icon=
shortCut= shortCut=
@@ -125,7 +125,7 @@ proc Tools::GetMenu {m} {
} }
proc Tools::Execute {toolName} { proc Tools::Execute {toolName} {
global cfgVariables toolsVariables global cfgVariables toolsVariables tree
if ![dict exists $::toolsVariables $toolName commandString] { if ![dict exists $::toolsVariables $toolName commandString] {
DebugPuts "Tools::Execute: command for $toolName not found" DebugPuts "Tools::Execute: command for $toolName not found"
return return
@@ -133,18 +133,36 @@ proc Tools::Execute {toolName} {
set command [dict get $::toolsVariables $toolName commandString] set command [dict get $::toolsVariables $toolName commandString]
DebugPuts "Tools::Execute: command for $toolName as $command" DebugPuts "Tools::Execute: command for $toolName as $command"
} }
# 1. Определять текущий файл
set fullCommand $command
# 2. Определять выделен ли текст в открытом редакторе # 2. Определять выделен ли текст в открытом редакторе
set selectedText [Editor::SelectionGet]
if {$selectedText ne ""} {
regsub -all "%s" $command "$selectedText" fullCommand
DebugPuts "Tools::Execute: selected text \"$selectedText\", command \"$fullCommand\""
}
# 1. Определять текущий файл
# 3. Опеределять сколько файлов выделено в дереве # 3. Опеределять сколько файлов выделено в дереве
# 4. Заменяем знак %f на имя текущего файла (файлов) # 4. Заменяем знак %f на имя текущего файла (файлов)
# regsub -all "%f" $command "$filePath" fullCommand # 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 на выделенный в редакторе текст # 5. Заменяем %s на выделенный в редакторе текст
# 6. Заменяем %d на текущий каталог(и), если он выделен в дереве, # 6. Заменяем %d на текущий каталог(и), если он выделен в дереве,
# и если не выделено то корневой открытый в дереве # и если не выделено то корневой открытый в дереве
# 7. Проверять команды на доступность в системе и подставлять полный путь к команде # 7. Проверять команды на доступность в системе и подставлять полный путь к команде
# если в конфиге не указан полный путь. # если в конфиге не указан полный путь.
set pipe [open "|$command" "r"] set pipe [open "|$fullCommand" "r"]
fileevent $pipe readable fileevent $pipe readable
fconfigure $pipe -buffering none -blocking no fconfigure $pipe -buffering none -blocking no
} }

View File

@@ -99,6 +99,7 @@ namespace eval Tree {
proc PressItem {tree} { proc PressItem {tree} {
global nbEditor lexers editors activeProject global nbEditor lexers editors activeProject
set id [$tree selection] set id [$tree selection]
if {[llength $id] > 1} {return}
$tree tag remove selected $tree tag remove selected
$tree item $id -tags selected $tree item $id -tags selected
SetActiveProject [GetItemID $tree [GetUpperItem $tree $id]] SetActiveProject [GetItemID $tree [GetUpperItem $tree $id]]
@@ -160,5 +161,12 @@ namespace eval Tree {
GetUpperItem $tree $parent GetUpperItem $tree $parent
} }
} }
proc GetSelectedItemValues {tree} {
set valuesList ""
foreach itemID [$tree selection] {
lappend valuesList [GetItemID $tree $itemID]
}
return $valuesList
}
} }