Добавлен диалог поиска строки в файлах в текущем каталоге. Используется 'grep -r'.

This commit is contained in:
svkalinin 2022-09-22 16:42:48 +03:00
parent 48588bda9a
commit 32013d87a7
6 changed files with 280 additions and 12 deletions

View File

@ -850,7 +850,9 @@ namespace eval Editor {
# $txt mark set insert $pos # $txt mark set insert $pos
if {[lindex $lstFindIndex 0] ne "" } { if {[lindex $lstFindIndex 0] ne "" } {
$txt see [lindex $lstFindIndex 0] # $txt see [lindex $lstFindIndex 0]
$txt mark set insert [lindex $lstFindIndex 0]
$text see insert
} }
# puts $pos # puts $pos
# # highlight the found word # # highlight the found word
@ -996,6 +998,13 @@ namespace eval Editor {
$w.panelTxt add $frmText -weight 1 $w.panelTxt add $frmText -weight 1
$frmText.t see [$w.frmText.t index insert] $frmText.t see [$w.frmText.t index insert]
# $frmText.t mark set insert [$w.frmText.t index insert]
}
proc GoToLineNumber {text lineNumber} {
# puts "\n\n\t>>>>$text $lineNumber\n\n"
$text mark set insert $lineNumber.0
$text see insert
} }
proc EditorWidget {fr fileType} { proc EditorWidget {fr fileType} {

View File

@ -282,8 +282,44 @@ namespace eval FileOper {
$nbEditor select $itemName $nbEditor select $itemName
Editor::ReadStructure $itemName.frmText.t $treeItemName Editor::ReadStructure $itemName.frmText.t $treeItemName
GetVariablesFromFile $fileFullPath GetVariablesFromFile $fileFullPath
$itemName.frmText.t.t mark set insert 1.0
$itemName.frmText.t.t see 1.0
focus -force $itemName.frmText.t.t focus -force $itemName.frmText.t.t
return $itemName return $itemName
} }
proc FindInFiles {} {
global nbEditor activeProject
set res ""
set txt ""
set str ""
set nbEditorItem [$nbEditor select]
if {$nbEditorItem ne ""} {
# set txt $nbEditorItem.frmText.t
set txt [focus]
set selIndex [$txt tag ranges sel]
if {$selIndex ne ""} {
set selBegin [lindex [$txt tag ranges sel] 0]
set selEnd [lindex [$txt tag ranges sel] 1]
set str [$txt get $selBegin $selEnd]
puts $str
set res [SearchStringInFolder $str]
}
}
FindInFilesDialog $txt $res
.find.entryFind delete 0 end
.find.entryFind insert end $str
}
proc ReplaceInFiles {} {
global nbEditor
return
# set selIndex [$txt tag ranges sel]
# set selBegin [lindex [$txt tag ranges sel] 0]
# set selEnd [lindex [$txt tag ranges sel] 1]
# puts [$txt get [$txt tag ranges sel]]
# }
} }

View File

@ -57,9 +57,9 @@ proc GetEditMenu {m} {
$m add command -label [::msgcat::mc "Replace"] -command Replace\ $m add command -label [::msgcat::mc "Replace"] -command Replace\
-accelerator "Ctrl+R" -accelerator "Ctrl+R"
$m add separator $m add separator
$m add command -label [::msgcat::mc "Find in files"] -command File::Find\ $m add command -label [::msgcat::mc "Find in files"] -command "FileOper::FindInFiles"\
-accelerator "Ctrl+Shift+F" -accelerator "Ctrl+Shift+F"
$m add command -label [::msgcat::mc "Replace in files"] -command File::Replace\ $m add command -label [::msgcat::mc "Replace in files"] -command FileOper::ReplaceInFiles\
-accelerator "Ctrl+Shift+RV" -accelerator "Ctrl+Shift+RV"
$m add separator $m add separator
$m add command -label [::msgcat::mc "Insert image"] -accelerator "Ctrl+I"\ $m add command -label [::msgcat::mc "Insert image"] -accelerator "Ctrl+I"\

View File

@ -70,14 +70,14 @@
::msgcat::mcset ru "Error open URL" "Ошибка открытия URL" ::msgcat::mcset ru "Error open URL" "Ошибка открытия URL"
::msgcat::mcset ru "Exit" "Выход" ::msgcat::mcset ru "Exit" "Выход"
::msgcat::mcset ru "File" "Файл" ::msgcat::mcset ru "File" "Файл"
::msgcat::mcset ru "Files" "Файлы" ::msgcat::mcset ru "Files" "Файлах"
::msgcat::mcset ru "File already exists. Overwrite?" "Файл уже существует. Переписать?" ::msgcat::mcset ru "File already exists. Overwrite?" "Файл уже существует. Переписать?"
::msgcat::mcset ru "File was modifyed. Close?" "Файл был изменен. Закрыть?" ::msgcat::mcset ru "File was modifyed. Close?" "Файл был изменен. Закрыть?"
::msgcat::mcset ru "File was modifyed" "Файл был изменен" ::msgcat::mcset ru "File was modifyed" "Файл был изменен"
::msgcat::mcset ru "File modify" "Файл изменен" ::msgcat::mcset ru "File modify" "Файл изменен"
::msgcat::mcset ru "File saved" "Файл сохранен" ::msgcat::mcset ru "File saved" "Файл сохранен"
::msgcat::mcset ru "Find" "Найти" ::msgcat::mcset ru "Find" "Найти"
::msgcat::mcset ru "Finded" "Найдено" ::msgcat::mcset ru "Found" "Найдено"
::msgcat::mcset ru "Find in files" "Найти в файлах" ::msgcat::mcset ru "Find in files" "Найти в файлах"
::msgcat::mcset ru "Font normal" "Нормальный шрифт" ::msgcat::mcset ru "Font normal" "Нормальный шрифт"
::msgcat::mcset ru "Font bold" "Жирный шрифт" ::msgcat::mcset ru "Font bold" "Жирный шрифт"
@ -92,6 +92,7 @@
::msgcat::mcset ru "Indent foreground" "Подсветка отступа" ::msgcat::mcset ru "Indent foreground" "Подсветка отступа"
::msgcat::mcset ru "Indent background" "Подсветка отступа" ::msgcat::mcset ru "Indent background" "Подсветка отступа"
::msgcat::mcset ru "Insert" "Вставка" ::msgcat::mcset ru "Insert" "Вставка"
::msgcat::mcset ru "In" "В"
::msgcat::mcset ru "Insert image" "Вставить изображение" ::msgcat::mcset ru "Insert image" "Вставить изображение"
::msgcat::mcset ru "Interface language" "Язык интерфейса" ::msgcat::mcset ru "Interface language" "Язык интерфейса"
::msgcat::mcset ru "Interpetator" "Интерпретатор" ::msgcat::mcset ru "Interpetator" "Интерпретатор"
@ -106,6 +107,7 @@
::msgcat::mcset ru "Make backup files" "Создавать временные файлы" ::msgcat::mcset ru "Make backup files" "Создавать временные файлы"
::msgcat::mcset ru "Main" "Общие" ::msgcat::mcset ru "Main" "Общие"
::msgcat::mcset ru "Main settings" "Общие настройки" ::msgcat::mcset ru "Main settings" "Общие настройки"
::msgcat::mcset ru "Matches" "Совпадений"
::msgcat::mcset ru "Modules" "Модули" ::msgcat::mcset ru "Modules" "Модули"
::msgcat::mcset ru "Modifying the Registry..." "Внесение изменений в реестр" ::msgcat::mcset ru "Modifying the Registry..." "Внесение изменений в реестр"
::msgcat::mcset ru "Must be one file select!" "Вы должны выбрать только один файл" ::msgcat::mcset ru "Must be one file select!" "Вы должны выбрать только один файл"

View File

@ -164,8 +164,8 @@ proc SearchVariable {txt} {
} }
proc GetVariableFilePath {txt} { proc GetVariableFilePath {txt} {
set str [$txt get {insert linestart} {insert lineend}] set str [$txt get {insert linestart} {insert lineend}]
if [regexp -nocase -all -- {^([0-9A-Za-z\-_:]*?) :: (.*?) :: (.*?)$} $str match vName vValue vPath] { if [regexp -nocase -all -- {^([0-9A-Za-z\-_:]*?) > (.*?) > (.*?)$} $str match vName vValue vPath] {
return [list $vName $vPath] return [list $vName $vPath $vValue]
} }
} }
proc FindVariablesDialog {txt args} { proc FindVariablesDialog {txt args} {
@ -216,7 +216,7 @@ proc FindVariablesDialog {txt args} {
puts "[lindex $lst 0] -[lindex $lst 1] -[lindex $lst 2]" puts "[lindex $lst 0] -[lindex $lst 1] -[lindex $lst 2]"
# lappend l2 [lindex $l 0] [lindex $l 1] [file tail [lindex $l 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 -values $lst -text {1 2 3}
$win.lBox insert end "[lindex $lst 0] :: [lindex $lst 1] :: [lindex $lst 2]\n" $win.lBox insert end "[lindex $lst 0] > [lindex $lst 1] > [lindex $lst 2]\n"
# $win.lBox insert end $word # $win.lBox insert end $word
incr height incr height
} }
@ -282,13 +282,234 @@ proc FindVariablesDialog {txt args} {
if [expr [expr $topHeight - $y] < $winGeom] { if [expr [expr $topHeight - $y] < $winGeom] {
set y [expr $topHeight - $winGeom] set y [expr $topHeight - $winGeom]
} }
ctext::addHighlightClassForRegexp $win.lBox namespaces #4f64ff {::} ctext::addHighlightClassForSpecialChars $win.lBox namespaces #4f64ff {>}
$win.lBox highlight 1.0 end $win.lBox highlight 1.0 end
wm geom $win +$x+$y wm geom $win +$x+$y
$win.lBox mark set insert 1.0
$win.lBox see 1.0 $win.lBox see 1.0
focus -force $win.lBox.t focus -force $win.lBox.t
# $win.lBox focus I001 # $win.lBox focus I001
} }
## Search string into all files from directory
proc SearchStringInFolder {str} {
global cfgVariables activeProject tcl_platform
set res ""
if {$tcl_platform(platform) == "windows"} {
} elseif {$tcl_platform(platform) == "mac"} {
} elseif {$tcl_platform(platform) == "unix"} {
puts "$cfgVariables(searchCommand) $cfgVariables(searchCommandOptions) $str $activeProject"
# Составляем строку (точнее список) для запуска команды
set cmd exec
regsub -all {\[} $str {\\[} str
regsub -all {\]} $str {\\]} str
lappend cmd $cfgVariables(searchCommand)
foreach o [split $cfgVariables(searchCommandOptions) " "] {
lappend cmd $o
}
lappend cmd $str
lappend cmd $activeProject
# запускаем
# puts $cmd
catch $cmd pipe
# puts $pipe
# fileevent $pipe readable
# fconfigure $pipe -buffering none -blocking no
}
# while {[chan gets $pipe line] >= 0} {
# puts "--> $line"
# }
foreach line [split $pipe "\n"] {
if [regexp -nocase -all -line -- {^((\/[\w\-_\.\s]+)+):([0-9]+):\s*(.+?)} $line match fullPath fileName lineNumber fullString] {
# puts "$fullPath $fileName $lineNumber $fullString"
lappend res [list $lineNumber $fullPath $fullString]
}
}
if {$res ne ""} {
return $res
} else {
return false
}
}
proc InsertListIntoText {win lst} {
set height 0
set fCount 0
set fName ""
# puts $lst
foreach { word } $lst {
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 "[lindex $lst 0] > [lindex $lst 1] > [lindex $lst 2]\n"
# $win.lBox insert end $word
incr height
if {$fName ne [lindex $lst 1]} {
set fName [lindex $lst 1]
incr fCount
}
}
}
set rows $height
if { $height > 10 } { set height 10 }
$win.lBox configure -height $height
unset height
return [list $rows $fCount]
}
proc FindInFilesDialog {txt {args ""}} {
global editors lexers cfgVariables
# variable txt
variable win
variable t $txt
variable lblText "[::msgcat::mc "Found"] %s\
[::msgcat::mc "Matches"]\
[::msgcat::mc "In"] %s\
[::msgcat::mc "Files"]"
# puts $txt
# set txt $w.frmText.t
if {$txt ne ""} {
set box [$txt bbox insert]
set x [expr [lindex $box 0] + [winfo rootx $txt] ]
set y [expr [lindex $box 1] + [winfo rooty $txt] + [lindex $box 3] ]
} else {
set txt .frmWork
set x [winfo rootx .frmWork]
set y [winfo rooty .frmWork]
}
set win .find
if { [winfo exists $win] } { destroy $win }
toplevel $win
wm transient $win .
wm overrideredirect $win 1
# set win [canvas $win.c -yscrollcommand "$win.v set" -xscrollcommand "$win.h set"]
ttk::entry $win.entryFind -width 30 -textvariable findString
ttk::entry $win.entryReplace -width 30 -textvariable replaceString
set cmd {
$win.lBox delete 1.0 end
set res [list [SearchStringInFolder $findString]]
set rows [InsertListIntoText $win $res]
set lblText "[::msgcat::mc "Found"] [lindex $rows 0]\
[::msgcat::mc "Matches"]\
[::msgcat::mc "In"] [lindex $rows 1]\
[::msgcat::mc "Files"]"
.find.lblCounter configure -text $lblText
# unset lblText
ctext::addHighlightClassForSpecialChars $win.lBox namespaces #4f64ff {>}
$win.lBox highlight 1.0 end
$win.lBox mark set insert 1.0
$win.lBox see 1.0
focus -force $win.lBox.t
}
ttk::button $win.bForward -image forward_20x20 -command $cmd
ttk::button $win.bDoneAll -image doneall_20x20 -command {
# Editor::FindReplaceText $Editor::txt "$findString" "$replaceString" $regexpSet
}
ttk::label $win.lblCounter -justify right -anchor w -text ""
ctext $win.lBox -height 5 -font $cfgVariables(font) -wrap none \
-yscrollcommand [list $win.v set] -xscrollcommand [list $win.h set] \
-linemapfg $cfgVariables(lineNumberFG) -linemapbg $cfgVariables(lineNumberBG)
ttk::scrollbar $win.v -orient vertical -command "$win.lBox yview"
ttk::scrollbar $win.h -orient horizontal -command "$win.lBox xview"
bind $win.entryFind <Return> $cmd
grid $win.entryFind -row 0 -column 0 -sticky nsew
grid $win.entryReplace -row 1 -column 0 -sticky nsew
grid $win.bForward -row 0 -column 1 -sticky e
grid $win.bDoneAll -row 1 -column 1 -sticky e
# grid $win.chkRegexp -row 2 -column 0 -sticky w
# grid $win.chkAll -row 2 -column 1 -sticky w
grid $win.lblCounter -row 2 -column 0 -columnspan 2 -sticky we
grid $win.lBox -row 3 -column 0 -columnspan 2 -sticky nsew
grid $win.v -row 3 -column 2 -sticky nsew
grid $win.h -row 4 -column 0 -sticky nsew
grid columnconfigure $win 0 -weight 1
grid rowconfigure $win 0 -weight 1
if {$args ne ""} {
set rows [InsertListIntoText $win $args]
set lblText [format $lblText [lindex $rows 0] [lindex $rows 1]]
# focus -force $win.lBox.t
} else {
set lblText ""
# focus -force $win.entryFind
}
.find.lblCounter configure -text $lblText
unset lblText
# $win.lBox selection set I001
# catch { $win.lBox activate 0 ; $win.lBox selection set 0 0 }
bind $win <Escape> {
destroy $win
focus -force $t
break
}
bind $win.lBox <Escape> {
destroy $win
focus -force $t
break
}
bind $win.lBox <Return> {
set _v [GetVariableFilePath $win.lBox]
set lineNum [lindex $_v 0]
set path [lindex $_v 2]
unset _v
# puts "$lineNum $path"
if {$path ne ""} {
destroy .find
set fr [FileOper::Edit $path]
Editor::GoToLineNumber $fr.frmText.t.t $lineNum
}
break
}
# bind $win.lBox <Double-ButtonPress-1> {Tree::DoublePressItem $win.lBox}
bind $win.lBox <ButtonRelease-1> {
set _v [GetVariableFilePath $win.lBox]
set lineNum [lindex $_v 0]
set path [lindex $_v 2]
unset _v
# puts "$lineNum $path"
if {$path ne ""} {
destroy .find
set fr [FileOper::Edit $path]
Editor::GoToLineNumber $fr.frmText.t.t $lineNum
}
break
}
# bind $win.lBox <Any-Key> {Editor::ListBoxSearch %W %A}
# Определям расстояние до края экрана (основного окна) и если
# оно меньше размера окна со списком то сдвигаем его вверх
set winGeom [winfo reqheight $win]
set topHeight [winfo height .]
# puts "$x, $y, $winGeom, $topHeight"
if [expr [expr $topHeight - $y] < $winGeom] {
set y [expr $topHeight - $winGeom]
}
ctext::addHighlightClassForSpecialChars $win.lBox namespaces #4f64ff {>}
$win.lBox highlight 1.0 end
wm geom $win +$x+$y
$win.lBox mark set insert 1.0
$win.lBox see 1.0
if {$args ne ""} {
focus -force $win.lBox.t
} else {
focus -force $win.entryFind
}
# $win.lBox focus I001
}

View File

@ -10,7 +10,7 @@ exec wish "$0" -- "$@"
###################################################### ######################################################
# Version: 2.0.0 # Version: 2.0.0
# Release: alpha # Release: alpha
# Build: 21092022142626 # Build: 22092022163933
###################################################### ######################################################
# определим текущую версию, релиз и т.д. # определим текущую версию, релиз и т.д.