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] "."]
|
2022-08-26 12:29:19 +03:00
|
|
|
#set fileName [string trimleft [file extension $text] "."]
|
2022-08-01 16:24:42 +03:00
|
|
|
set findImg [::FindImage $fileExt]
|
2022-08-03 12:21:28 +03:00
|
|
|
# puts "Extention $fileExt, find image: $findImg"
|
2022-08-26 12:29:19 +03:00
|
|
|
# puts ">>>>>>>>>>> [string tolower $text]; [string match {*docker*} [string tolower $text]]"
|
|
|
|
if {[string match {*docker*} [string tolower $text]]} {
|
|
|
|
set findImg [::FindImage docker]
|
2022-09-01 16:54:34 +03:00
|
|
|
} elseif {[string match {*gitlab*} [string tolower $text]]} {
|
|
|
|
set findImg [::FindImage gitlab]
|
|
|
|
} elseif {[string match {*bitbucket*} [string tolower $text]]} {
|
|
|
|
set findImg [::FindImage bitbucket]
|
2022-12-07 09:08:43 +03:00
|
|
|
} elseif {[string match {\.git*} [string tolower $text]]} {
|
|
|
|
set findImg [::FindImage git]
|
2022-08-26 12:29:19 +03:00
|
|
|
}
|
|
|
|
if {$fileExt ne "" || $findImg ne ""} {
|
2022-08-01 16:24:42 +03:00
|
|
|
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
|
2022-08-26 16:25:19 +03:00
|
|
|
if {[string match {*debian*} [string tolower [file tail $item]]]} {
|
2022-08-26 12:29:19 +03:00
|
|
|
set image [::FindImage debian]
|
2022-08-26 16:25:19 +03:00
|
|
|
} elseif {[string match {*redhat*} [string tolower [file tail $item]]]} {
|
2022-08-26 12:29:19 +03:00
|
|
|
set image [::FindImage redhat]
|
2022-09-01 16:54:34 +03:00
|
|
|
} elseif {[string match {*gitlab*} [string tolower [file tail $item]]]} {
|
|
|
|
set image [::FindImage gitlab]
|
2022-12-07 09:08:43 +03:00
|
|
|
} elseif {[string match {.git} [string tolower [file tail $item]]]} {
|
|
|
|
set image [::FindImage git]
|
2022-08-26 12:29:19 +03:00
|
|
|
} else {
|
|
|
|
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 {
|
2022-09-02 17:01:53 +03:00
|
|
|
regsub -all {\.|/|\\|\s|"|\{|\}|\(|\)} $item "_" subNode
|
2022-08-03 12:21:28 +03:00
|
|
|
# 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-09-14 16:31:50 +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
|
2022-11-11 16:22:50 +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}
|
|
|
|
|
2022-12-07 16:00:04 +03:00
|
|
|
# puts "$key $tree $values"
|
2022-07-21 10:56:46 +03:00
|
|
|
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-11-24 13:28:11 +03:00
|
|
|
global nbEditor lexers editors activeProject
|
2022-07-21 10:56:46 +03:00
|
|
|
set id [$tree selection]
|
|
|
|
$tree tag remove selected
|
|
|
|
$tree item $id -tags selected
|
2022-11-24 13:28:11 +03:00
|
|
|
SetActiveProject [GetItemID $tree [GetUpperItem $tree $id]]
|
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}
|
|
|
|
|
2022-12-07 16:00:04 +03:00
|
|
|
# puts "$key $tree $values"
|
2022-09-08 17:01:18 +03:00
|
|
|
switch -regexp $key {
|
2022-07-21 10:56:46 +03:00
|
|
|
directory {
|
|
|
|
FileOper::ReadFolder $values
|
|
|
|
# $tree item $id -open false
|
|
|
|
}
|
|
|
|
file {
|
2022-12-01 12:37:13 +03:00
|
|
|
set v [FileOper::Edit $values $nbEditor]
|
2022-09-19 15:00:05 +03:00
|
|
|
if {$v eq false} {
|
|
|
|
$tree delete $id
|
|
|
|
}
|
|
|
|
unset v
|
2018-02-08 16:37:50 +03:00
|
|
|
}
|
2022-09-08 17:01:18 +03:00
|
|
|
I[0-9]*? {
|
|
|
|
destroy .findVariables
|
2022-12-01 12:37:13 +03:00
|
|
|
FileOper::Edit [lindex $values 2] $nbEditor
|
2022-09-08 17:01:18 +03:00
|
|
|
}
|
2022-08-24 15:04:19 +03:00
|
|
|
default {
|
2022-08-03 12:21:28 +03:00
|
|
|
set parentItem [$tree parent $id]
|
2022-08-24 15:04:19 +03:00
|
|
|
# puts $values
|
|
|
|
set nbItem "$nbEditor.[string range $parentItem [expr [string last "::" $parentItem] + 2] end]"
|
|
|
|
$nbEditor select $nbItem
|
|
|
|
set txt $nbItem.frmText.t
|
2022-08-25 16:39:50 +03:00
|
|
|
set findString [dict get $lexers [dict get $editors $txt fileType] procFindString]
|
|
|
|
regsub -all {PROCNAME} $findString $values str
|
|
|
|
|
2022-09-21 14:38:31 +03:00
|
|
|
Editor::FindFunction $txt "$str"
|
2022-08-03 12:21:28 +03:00
|
|
|
}
|
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
|
|
|
}
|
|
|
|
}
|
2022-11-23 11:14:03 +03:00
|
|
|
|
|
|
|
proc SelectItem {treeItemName} {
|
|
|
|
global tree
|
|
|
|
if [$tree exists $treeItemName] {
|
|
|
|
$tree see $treeItemName
|
|
|
|
$tree selection set $treeItemName
|
|
|
|
}
|
|
|
|
}
|
2022-11-24 13:28:11 +03:00
|
|
|
|
|
|
|
proc GetUpperItem {tree item} {
|
|
|
|
set parent [$tree parent $item]
|
|
|
|
if {$parent eq ""} {
|
|
|
|
return $item
|
|
|
|
} else {
|
|
|
|
GetUpperItem $tree $parent
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-03-15 16:22:57 +03:00
|
|
|
}
|