Исправлен поиск процедуры в тексте по клику в дереве. Исправлено отображение позиции курсора в строке статуса

This commit is contained in:
svkalinin 2022-08-03 12:21:28 +03:00
parent 7215c537a8
commit 70a731d402
8 changed files with 97 additions and 42 deletions

View File

@ -49,3 +49,9 @@
- Added GUI font, and GUI foreground color setting - Added GUI font, and GUI foreground color setting
- Added tcl and go files images - Added tcl and go files images
- Added image for file type (extention) - Added image for file type (extention)
03/08/2022
- Added some files icon
- Fix finded procedure (function) (tree click)
- Fix showing position in statusbar

View File

@ -252,9 +252,9 @@ namespace eval Editor {
} }
} }
proc ReleaseKey {k txt} { proc ReleaseKey {k txt} {
set pos [$txt index insert]
switch $k { switch $k {
Return { Return {
set pos [$txt index insert]
set lineNum [lindex [split $pos "."] 0] set lineNum [lindex [split $pos "."] 0]
set posNum [lindex [split $pos "."] 1] set posNum [lindex [split $pos "."] 1]
regexp {^(\s*)} [$txt get [expr $lineNum - 1].0 [expr $lineNum - 1].end] -> spaceStart regexp {^(\s*)} [$txt get [expr $lineNum - 1].0 [expr $lineNum - 1].end] -> spaceStart
@ -263,6 +263,10 @@ namespace eval Editor {
Editor::Indent $txt Editor::Indent $txt
} }
} }
set lpos [split $pos "."]
set lblText "[::msgcat::mc "Row"]: [lindex $lpos 0], [::msgcat::mc "Column"]: [lindex $lpos 1]"
.frmStatus.lblPosition configure -text $lblText
unset lpos
} }
proc PressKey {k txt} { proc PressKey {k txt} {
# puts [Editor::Key $k] # puts [Editor::Key $k]
@ -413,24 +417,24 @@ namespace eval Editor {
if {[regexp -nocase -all -- {^\s*?(proc) (::|)(\w+)(::|)(\w+)\s*?(\{|\()(.*)(\}|\)) \{} $line match v1 v2 v3 v4 v5 v6 params v8]} { if {[regexp -nocase -all -- {^\s*?(proc) (::|)(\w+)(::|)(\w+)\s*?(\{|\()(.*)(\}|\)) \{} $line match v1 v2 v3 v4 v5 v6 params v8]} {
set procName "$v2$v3$v4$v5" set procName "$v2$v3$v4$v5"
# lappend procList($activeProject) [list $procName [string trim $params]] # lappend procList($activeProject) [list $procName [string trim $params]]
puts "$treeItemName proc $procName $params" # puts "$treeItemName proc $procName $params"
# tree parent item type text # tree parent item type text
puts [Tree::InsertItem $tree $treeItemName $procName "func" "$procName ($params)"] puts [Tree::InsertItem $tree $treeItemName $procName "procedure" "$procName ($params)"]
} }
# GO function # GO function
if {[regexp -nocase -all -- {^\s*?func\s*?\((\w+\s*?\*\w+)\)\s*?(\w+)\((.*?)\)\s*?\((.*?)\)} $line match v1 funcName params returns]} { if {[regexp -nocase -all -- {^\s*?func\s*?\((\w+\s*?\*\w+)\)\s*?(\w+)\((.*?)\)\s*?(\(\w+\)|\w+|)\s*?\{} $line match v1 funcName params returns]} {
# set procName "$v2$v3$v4$v5" # set procName "$v2$v3$v4$v5"
# lappend procList($activeProject) [list $procName [string trim $params]] # lappend procList($activeProject) [list $procName [string trim $params]]
if {$v1 ne ""} { if {$v1 ne ""} {
set linkName [lindex [split $v1 " "] 1] set linkName [lindex [split $v1 " "] 1]
set funcName "\($linkName\).$funcName" set functionName "\($linkName\).$funcName"
} }
puts "$treeItemName proc $funcName $params" # puts "$treeItemName func $funcName $params"
# tree parent item type text # tree parent item type text
puts [Tree::InsertItem $tree $treeItemName $funcName "func" "$funcName ($params)"] puts [Tree::InsertItem $tree $treeItemName $funcName "func" "$functionName ($params)"]
} }
if {[regexp -nocase -all -- {^\s*?func\s*?(\w+)\((.*?)\) (\(\w+\)|\w+|)\s*?\{} $line match funcName params returns]} { if {[regexp -nocase -all -- {^\s*?func\s*?(\w+)\((.*?)\) (\(\w+\)|\w+|)\s*?\{} $line match funcName params returns]} {
puts "$treeItemName proc $funcName $params" # puts "$treeItemName func $funcName $params"
# tree parent item type text # tree parent item type text
puts [Tree::InsertItem $tree $treeItemName $funcName "func" "$funcName ($params)"] puts [Tree::InsertItem $tree $treeItemName $funcName "func" "$funcName ($params)"]
} }
@ -438,6 +442,32 @@ namespace eval Editor {
} }
} }
proc FindFunction {findString} {
global nbEditor
puts $findString
set pos "0.0"
set txt [$nbEditor select].frmText.t
$txt see $pos
set line [lindex [split $pos "."] 0]
set x [lindex [split $pos "."] 1]
# set pos [$txt search -nocase $findString $line.$x end]
set pos [$txt search -nocase -regexp $findString $line.$x end]
$txt mark set insert $pos
$txt see $pos
puts $pos
# highlight the found word
set line [lindex [split $pos "."] 0]
# set x [lindex [split $pos "."] 1]
# set x [expr {$x + [string length $findString]}]
$txt tag remove sel 1.0 end
$txt tag add sel $pos $line.end
# #$text tag configure sel -background $editor(selectbg) -foreground $editor(fg)
$txt tag raise sel
focus -force $txt
# Position
return 1
}
proc Editor {fileFullPath nb itemName} { proc Editor {fileFullPath nb itemName} {
global cfgVariables global cfgVariables
set fr $itemName set fr $itemName
@ -458,7 +488,8 @@ namespace eval Editor {
pack $frmText -side top -expand true -fill both pack $frmText -side top -expand true -fill both
pack [ttk::scrollbar $frmText.s -command "$frmText.t yview"] -side right -fill y pack [ttk::scrollbar $frmText.s -command "$frmText.t yview"] -side right -fill y
ctext $txt -yscrollcommand "$frmText.s set" -font $cfgVariables(font) -linemapfg $cfgVariables(lineNumberFG) \ ctext $txt -yscrollcommand "$frmText.s set" -font $cfgVariables(font) -linemapfg $cfgVariables(lineNumberFG) \
-tabs "[expr {4 * [font measure $cfgVariables(font) 0]}] left" -tabstyle tabular -undo true -tabs "[expr {4 * [font measure $cfgVariables(font) 0]}] left" -tabstyle tabular -undo true
pack $txt -fill both -expand 1 pack $txt -fill both -expand 1
# puts ">>>>>>> [bindtags $txt]" # puts ">>>>>>> [bindtags $txt]"
if {$cfgVariables(lineNumberShow) eq "false"} { if {$cfgVariables(lineNumberShow) eq "false"} {

View File

@ -68,7 +68,7 @@ if [info exists cfgVariables(theme)] {
frame .frmMenu -border 1 -relief raised -highlightthickness 0 frame .frmMenu -border 1 -relief raised -highlightthickness 0
frame .frmBody -border 1 -relief raised -highlightthickness 0 frame .frmBody -border 1 -relief raised -highlightthickness 0
frame .frmStatus -border 1 -relief sunken ttk::frame .frmStatus -border 0 -relief sunken
pack .frmMenu -side top -padx 1 -fill x pack .frmMenu -side top -padx 1 -fill x
pack .frmBody -side top -padx 1 -fill both -expand true pack .frmBody -side top -padx 1 -fill both -expand true
pack .frmStatus -side top -padx 1 -fill x pack .frmStatus -side top -padx 1 -fill x
@ -76,7 +76,7 @@ pack .frmStatus -side top -padx 1 -fill x
# pack .panel -expand true -fill both # pack .panel -expand true -fill both
# pack propagate .panel false # pack propagate .panel false
#pack [label .frmMenu.lbl -text "ddd"] #pack [label .frmMenu.lbl -text "ddd"]
pack [label .frmStatus.lbl2 -text "ddd"] pack [ttk::label .frmStatus.lblPosition -justify right] -side right
menubutton .frmMenu.mnuFile -text [::msgcat::mc "File"] -menu .frmMenu.mnuFile.m menubutton .frmMenu.mnuFile -text [::msgcat::mc "File"] -menu .frmMenu.mnuFile.m
GetFileMenu [menu .frmMenu.mnuFile.m] GetFileMenu [menu .frmMenu.mnuFile.m]
@ -100,7 +100,7 @@ pack propagate .frmBody.panel false
pack .frmBody.frmTool -side left -fill y pack .frmBody.frmTool -side left -fill y
pack .frmBody.panel -side left -fill both -expand true pack .frmBody.panel -side left -fill both -expand true
ttk::button $frmTool.btn_tree -command ViewFilesTree -image tree_32x32 ttk::button $frmTool.btn_tree -command ViewFilesTree -image tree_24x24
pack $frmTool.btn_tree -side top -padx 1 -pady 1 pack $frmTool.btn_tree -side top -padx 1 -pady 1
# #label $frmTool.lbl_logo -image tcl # #label $frmTool.lbl_logo -image tcl
@ -110,17 +110,20 @@ pack $frmTool.btn_tree -side top -padx 1 -pady 1
# # Дерево с полосами прокрутки # # Дерево с полосами прокрутки
set frmTree [ttk::frame .frmBody.frmTree] set frmTree [ttk::frame .frmBody.frmTree]
ttk::scrollbar $frmTree.hsb1 -orient horizontal -command {$frmTree.tree xview}
ttk::scrollbar $frmTree.vsb1 -orient vertical -command [list $frmTree.tree yview]
set tree [ttk::treeview $frmTree.tree -show tree \ set tree [ttk::treeview $frmTree.tree -show tree \
-xscrollcommand {$frmTree.hsb1 set} -yscrollcommand [list $frmTree.vsb1 set]] -xscrollcommand [list .frmBody.frmTree.h set] -yscrollcommand [list .frmBody.frmTree.v set]]
ttk::scrollbar $frmTree.h -orient horizontal -command [list $frmTree.tree xview]
ttk::scrollbar $frmTree.v -orient vertical -command [list $frmTree.tree yview]
bind $tree <Double-ButtonPress-1> {Tree::DoublePressItem $tree} bind $tree <Double-ButtonPress-1> {Tree::DoublePressItem $tree}
bind $tree <ButtonRelease> {Tree::PressItem $tree} bind $tree <ButtonRelease> {Tree::PressItem $tree}
grid $tree -row 0 -column 0 -sticky nsew grid $tree -row 0 -column 0 -sticky nsew
grid $frmTree.vsb1 -row 0 -column 1 -sticky nsew grid $frmTree.v -row 0 -column 1 -sticky nsew
grid $frmTree.hsb1 -row 1 -column 0 -sticky nsew # grid $frmTree.h -row 1 -column 0 -sticky nsew
grid columnconfigure $frmTree 0 -weight 1 grid columnconfigure $frmTree 0 -weight 1
grid rowconfigure $frmTree 0 -weight 1 grid rowconfigure $frmTree 0 -weight 1

View File

@ -25,6 +25,7 @@
::msgcat::mcset ru "Comments" "Коментарии" ::msgcat::mcset ru "Comments" "Коментарии"
::msgcat::mcset ru "Comment selected" "Закоментировать" ::msgcat::mcset ru "Comment selected" "Закоментировать"
::msgcat::mcset ru "Uncomment selected" "Раскоментировать" ::msgcat::mcset ru "Uncomment selected" "Раскоментировать"
::msgcat::mcset ru "Column" "Столбец"
::msgcat::mcset ru "Company" "Компания" ::msgcat::mcset ru "Company" "Компания"
::msgcat::mcset ru "Compiler" "Компилятор" ::msgcat::mcset ru "Compiler" "Компилятор"
::msgcat::mcset ru "Compile" "Компиляция" ::msgcat::mcset ru "Compile" "Компиляция"
@ -153,6 +154,7 @@
::msgcat::mcset ru "Release" "Выпуск" ::msgcat::mcset ru "Release" "Выпуск"
::msgcat::mcset ru "RPM directory" "Каталог RPM" ::msgcat::mcset ru "RPM directory" "Каталог RPM"
::msgcat::mcset ru "RPM file mask" "Маска RPM" ::msgcat::mcset ru "RPM file mask" "Маска RPM"
::msgcat::mcset ru "Row" "Строка"
::msgcat::mcset ru "Run" "Выполнить" ::msgcat::mcset ru "Run" "Выполнить"
::msgcat::mcset ru "Run file" "Запустить файл" ::msgcat::mcset ru "Run file" "Запустить файл"
::msgcat::mcset ru "Running project" "Выполнение проекта" ::msgcat::mcset ru "Running project" "Выполнение проекта"
@ -185,10 +187,9 @@
::msgcat::mcset ru "Version" "Версия" ::msgcat::mcset ru "Version" "Версия"
::msgcat::mcset ru "View" "Вид" ::msgcat::mcset ru "View" "Вид"
::msgcat::mcset ru "View files tree" "Показывать дерево файлов" ::msgcat::mcset ru "View files tree" "Показывать дерево файлов"
::msgcat::mcset ru "View line numers" "Показывать номера строк" ::msgcat::mcset ru "View line numbers" "Показывать номера строк"
::msgcat::mcset ru "Warning" "Внимание" ::msgcat::mcset ru "Warning" "Внимание"
::msgcat::mcset ru "Was replacement" "Было заменено" ::msgcat::mcset ru "Was replacement" "Было заменено"
::msgcat::mcset ru "Word wrapping" "Перенос слов" ::msgcat::mcset ru "Word wrapping" "Перенос слов"
::msgcat::mcset ru "Work dir" "Рабочий каталог" ::msgcat::mcset ru "Work dir" "Рабочий каталог"
::msgcat::mcset ru "Yes" "Да" ::msgcat::mcset ru "Yes" "Да"

View File

@ -10,7 +10,6 @@
###################################################### ######################################################
namespace eval NB { namespace eval NB {
proc InsertItem {nb item type} { proc InsertItem {nb item type} {
switch $type { switch $type {
file { file {

View File

@ -98,7 +98,7 @@ proc ImageBase64Encode {} {
proc FindImage {ext} { proc FindImage {ext} {
foreach img [image names] { foreach img [image names] {
if [regexp -nocase -all -- "^($ext)(_)" $img match v1 v2] { if [regexp -nocase -all -- "^($ext)(_)" $img match v1 v2] {
puts "\nFindinig images: $img \n" # puts "\nFindinig images: $img \n"
return $img return $img
} }
} }

View File

@ -15,14 +15,14 @@ namespace eval Tree {
proc InsertItem {tree parent item type text} { proc InsertItem {tree parent item type text} {
# set img [GetImage $fileName] # set img [GetImage $fileName]
set dot "_" set dot "_"
puts "$tree $parent $item $type $text" # puts "$tree $parent $item $type $text"
switch $type { switch $type {
file { file {
regsub -all {\.|/|\\|\s} $item "_" subNode regsub -all {\.|/|\\|\s} $item "_" subNode
puts "Inserted tree node: $subNode" # puts "Inserted tree node: $subNode"
set fileExt [string trimleft [file extension $text] "."] set fileExt [string trimleft [file extension $text] "."]
set findImg [::FindImage $fileExt] set findImg [::FindImage $fileExt]
puts "Extention $fileExt, find image: $findImg" # puts "Extention $fileExt, find image: $findImg"
if {$fileExt ne "" && $findImg ne ""} { if {$fileExt ne "" && $findImg ne ""} {
set image $findImg set image $findImg
} else { } else {
@ -31,12 +31,17 @@ namespace eval Tree {
} }
directory { directory {
regsub -all {\.|/|\\|\s} $item "_" subNode regsub -all {\.|/|\\|\s} $item "_" subNode
puts $subNode # puts $subNode
set image folder set image pixel
} }
func { func {
regsub -all {:} $item "_" subNode regsub -all {:} $item "_" subNode
puts $subNode # puts $subNode
set image proc_10x10
}
procedure {
regsub -all {:} $item "_" subNode
# puts $subNode
set image proc_10x10 set image proc_10x10
} }
} }
@ -69,6 +74,7 @@ namespace eval Tree {
} }
proc PressItem {tree} { proc PressItem {tree} {
global nbEditor
set id [$tree selection] set id [$tree selection]
$tree tag remove selected $tree tag remove selected
$tree item $id -tags selected $tree item $id -tags selected
@ -77,7 +83,7 @@ namespace eval Tree {
set key [lindex [split $id "::"] 0] set key [lindex [split $id "::"] 0]
if {$values eq "" || $key eq ""} {return} if {$values eq "" || $key eq ""} {return}
puts "$key $tree $values" # puts "$key $tree $values"
switch $key { switch $key {
directory { directory {
FileOper::ReadFolder $values FileOper::ReadFolder $values
@ -86,9 +92,18 @@ namespace eval Tree {
file { file {
FileOper::Edit $values FileOper::Edit $values
} }
func {
set parentItem [$tree parent $id]
$nbEditor select $nbEditor.[string range $parentItem [expr [string last "::" $parentItem] + 2] end]
Editor::FindFunction "func $values"
}
procedure {
set parentItem [$tree parent $id]
$nbEditor select $nbEditor.[string range $parentItem [expr [string last "::" $parentItem] + 2] end]
Editor::FindFunction "proc $values"
}
} }
# }
}
proc GetItemID {tree item} { proc GetItemID {tree item} {
if [$tree exists $item] { if [$tree exists $item] {

View File

@ -93,31 +93,31 @@ namespace eval ttk::theme::dark {
-fieldbackground $colors(-lightframe) -fieldbackground $colors(-lightframe)
ttk::style configure Text \ ttk::style configure Text \
-linemapbg [list active $colors(-frame)]\ -linemapbg [list active $colors(-lightframe)]\
-linemapbg [list active $colors(-disabledfg)]\ -linemapbg [list active $colors(-disabledfg)]\
-background [list active $colors(-lighter)] \ -background [list active $colors(-lighter)] \
-foreground [list disabled $colors(-disabledfg)] -foreground [list disabled $colors(-disabledfg)]
ttk::style configure TLabel -foreground $colors(-disabledfg) -padding {2 0} ttk::style configure TLabel -foreground $colors(-disabledfg) -padding {2 0}
# ttk::style configure TreeCtrl \ # ttk::style configure TreeCtrl \
# -background gray30 -itembackground {gray60 gray50} \ # -background gray30 -itembackground {gray60 gray50} \
# -itemfill #ffffff -itemaccentfill yellow # -itemfill #ffffff -itemaccentfill yellow
option add *Toplevel.Background $colors(-dark) interactive option add *Toplevel.Background $colors(-dark) interactive
option add *Text.Foreground $colors(-foreground) interactive option add *Text.Foreground $colors(-foreground) interactive
option add *Text.Background $colors(-frame) interactive option add *Text.Background $colors(-frame) interactive
# option add *Text.Insertbackground yellow interactive option add *Text.Insertbackground yellow interactive
# option add *Text.BorderWidth -2 interactive # option add *Text.BorderWidth -2 interactive
# option add *Text.selectBorderWidth -2 interactive # option add *Text.selectBorderWidth -2 interactive
# option add *Text.Relief flat interactive # option add *Text.Relief flat interactive
option add *Text.Font "{Noto Sans Mono} 10" interactive # option add *Text.Font "{Noto Sans Mono} 10" interactive
#option add *BorderWidth -2 interactive #option add *BorderWidth -2 interactive
} }
#option add *Treeview.Background red interactive # option add *Treeview.Background red interactive
# option add *Frame.Background $colors(-frame) interactive # option add *Frame.Background $colors(-frame) interactive
# option add *Label.Background $colors(-frame) interactive # option add *Label.Background $colors(-frame) interactive
# option add *Label.Foreground $colors(-foreground) interactive # option add *Label.Foreground $colors(-foreground) interactive
# option add *Entry.Background $colors(-frame) interactive # option add *Entry.Background $colors(-frame) interactive
# option add *Entry.Foreground $colors(-foreground) interactive # option add *Entry.Foreground $colors(-foreground) interactive
} }