2022-07-21 10:56:46 +03:00
|
|
|
#!/usr/bin/wish
|
|
|
|
######################################################
|
|
|
|
# ProjMan 2
|
2018-02-08 16:37:50 +03:00
|
|
|
# Distributed under GNU Public License
|
2022-07-21 10:56:46 +03:00
|
|
|
# Author: Sergey Kalinin svk@nuk-svk.ru
|
|
|
|
# Copyright (c) "", 2022, https://nuk-svk.ru
|
|
|
|
######################################################
|
2018-02-08 16:37:50 +03:00
|
|
|
#
|
2022-07-21 10:56:46 +03:00
|
|
|
# Tree widget working module
|
2018-02-08 16:37:50 +03:00
|
|
|
#
|
2022-07-21 10:56:46 +03:00
|
|
|
######################################################
|
2018-02-08 16:37:50 +03:00
|
|
|
|
2022-07-21 10:56:46 +03:00
|
|
|
|
|
|
|
namespace eval Tree {
|
|
|
|
proc InsertItem {tree parent item type text} {
|
|
|
|
# set img [GetImage $fileName]
|
|
|
|
set dot "_"
|
2022-08-03 12:21:28 +03:00
|
|
|
# puts "$tree $parent $item $type $text"
|
2022-07-21 10:56:46 +03:00
|
|
|
switch $type {
|
|
|
|
file {
|
|
|
|
regsub -all {\.|/|\\|\s} $item "_" subNode
|
2022-08-03 12:21:28 +03:00
|
|
|
# puts "Inserted tree node: $subNode"
|
2022-08-01 16:24:42 +03:00
|
|
|
set fileExt [string trimleft [file extension $text] "."]
|
|
|
|
set findImg [::FindImage $fileExt]
|
2022-08-03 12:21:28 +03:00
|
|
|
# puts "Extention $fileExt, find image: $findImg"
|
2022-08-01 16:24:42 +03:00
|
|
|
if {$fileExt ne "" && $findImg ne ""} {
|
|
|
|
set image $findImg
|
|
|
|
} else {
|
|
|
|
set image imgFile
|
|
|
|
}
|
2018-02-08 16:37:50 +03:00
|
|
|
}
|
2022-07-21 10:56:46 +03:00
|
|
|
directory {
|
|
|
|
regsub -all {\.|/|\\|\s} $item "_" subNode
|
2022-08-03 12:21:28 +03:00
|
|
|
# puts $subNode
|
|
|
|
set image pixel
|
2018-02-08 16:37:50 +03:00
|
|
|
}
|
2022-08-01 16:24:42 +03:00
|
|
|
func {
|
|
|
|
regsub -all {:} $item "_" subNode
|
2022-08-03 12:21:28 +03:00
|
|
|
# puts $subNode
|
|
|
|
set image proc_10x10
|
|
|
|
}
|
|
|
|
procedure {
|
|
|
|
regsub -all {:} $item "_" subNode
|
|
|
|
# puts $subNode
|
2022-08-01 16:24:42 +03:00
|
|
|
set image proc_10x10
|
|
|
|
}
|
2018-02-08 16:37:50 +03:00
|
|
|
}
|
2022-07-21 10:56:46 +03:00
|
|
|
append id $type "::" $subNode
|
2022-08-01 16:24:42 +03:00
|
|
|
puts "Tree ID: $id, tree item: $item"
|
2022-07-21 10:56:46 +03:00
|
|
|
if ![$tree exists $id] {
|
2022-08-01 16:24:42 +03:00
|
|
|
$tree insert $parent end -id "$id" -text " $text" -values "$item" -image $image
|
2022-07-21 10:56:46 +03:00
|
|
|
}
|
2022-08-01 16:24:42 +03:00
|
|
|
return "$id"
|
2018-02-08 16:37:50 +03:00
|
|
|
}
|
2022-07-21 10:56:46 +03:00
|
|
|
proc DoublePressItem {tree} {
|
|
|
|
set id [$tree selection]
|
|
|
|
$tree tag remove selected
|
|
|
|
$tree item $id -tags selected
|
2018-02-24 18:31:18 +03:00
|
|
|
|
2022-07-21 10:56:46 +03:00
|
|
|
set values [$tree item $id -values]
|
|
|
|
set key [lindex [split $id "::"] 0]
|
|
|
|
if {$values eq "" || $key eq ""} {return}
|
|
|
|
|
|
|
|
puts "$key $tree $values"
|
|
|
|
switch $key {
|
|
|
|
directory {
|
|
|
|
FileOper::ReadFolder $values
|
2018-02-08 16:37:50 +03:00
|
|
|
}
|
2022-07-21 10:56:46 +03:00
|
|
|
file {
|
|
|
|
FileOper::Edit $values
|
|
|
|
# $tree item $id -open false
|
2018-02-08 16:37:50 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-07-21 10:56:46 +03:00
|
|
|
proc PressItem {tree} {
|
2022-08-03 12:21:28 +03:00
|
|
|
global nbEditor
|
2022-07-21 10:56:46 +03:00
|
|
|
set id [$tree selection]
|
|
|
|
$tree tag remove selected
|
|
|
|
$tree item $id -tags selected
|
|
|
|
|
|
|
|
set values [$tree item $id -values]
|
|
|
|
set key [lindex [split $id "::"] 0]
|
|
|
|
if {$values eq "" || $key eq ""} {return}
|
|
|
|
|
2022-08-03 12:21:28 +03:00
|
|
|
# puts "$key $tree $values"
|
2022-07-21 10:56:46 +03:00
|
|
|
switch $key {
|
|
|
|
directory {
|
|
|
|
FileOper::ReadFolder $values
|
|
|
|
# $tree item $id -open false
|
|
|
|
}
|
|
|
|
file {
|
|
|
|
FileOper::Edit $values
|
2018-02-08 16:37:50 +03:00
|
|
|
}
|
2022-08-03 12:21:28 +03:00
|
|
|
func {
|
|
|
|
set parentItem [$tree parent $id]
|
2022-08-03 13:00:34 +03:00
|
|
|
puts $values
|
2022-08-03 12:21:28 +03:00
|
|
|
$nbEditor select $nbEditor.[string range $parentItem [expr [string last "::" $parentItem] + 2] end]
|
2022-08-03 13:00:34 +03:00
|
|
|
Editor::FindFunction "func.*?$values"
|
2022-08-03 12:21:28 +03:00
|
|
|
}
|
|
|
|
procedure {
|
|
|
|
set parentItem [$tree parent $id]
|
|
|
|
$nbEditor select $nbEditor.[string range $parentItem [expr [string last "::" $parentItem] + 2] end]
|
|
|
|
Editor::FindFunction "proc $values"
|
|
|
|
}
|
2018-02-08 16:37:50 +03:00
|
|
|
}
|
2022-08-03 12:21:28 +03:00
|
|
|
}
|
2018-02-08 16:37:50 +03:00
|
|
|
|
2022-07-21 10:56:46 +03:00
|
|
|
proc GetItemID {tree item} {
|
|
|
|
if [$tree exists $item] {
|
|
|
|
return [$tree item $item -values]
|
2018-03-15 16:22:57 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|