2018-02-08 16:37:50 +03:00
|
|
|
|
#####################################################
|
|
|
|
|
# Tcl/Tk Project Manager
|
|
|
|
|
# Distributed under GNU Public License
|
|
|
|
|
# Author: Sergey Kalinin s.v.kalinin28@gmail.com
|
|
|
|
|
# Copyright (c) "https://nuk-svk.ru", 2018
|
|
|
|
|
# Git repo: https://bitbucket.org/svk28/projman
|
|
|
|
|
####################################################
|
|
|
|
|
#
|
|
|
|
|
# Procedure for operation wwith Tree widget
|
|
|
|
|
#
|
|
|
|
|
####################################################
|
|
|
|
|
|
2018-02-24 18:03:35 +03:00
|
|
|
|
proc GetAllDirs {treeFiles} {
|
|
|
|
|
global projDir workDir fontNormal imgDir module env
|
2018-02-08 16:37:50 +03:00
|
|
|
|
set rList ""
|
|
|
|
|
set rootDir $env(HOME)
|
|
|
|
|
if {[catch {cd $rootDir}] != 0} {
|
|
|
|
|
return ""
|
|
|
|
|
}
|
2018-02-18 15:01:56 +03:00
|
|
|
|
set rootNode [$treeFiles insert end root $rootDir -text "$rootDir" -font $fontNormal \
|
|
|
|
|
-data "dir_root" -open 1\
|
|
|
|
|
-image [Bitmap::get [file join $imgDir folder.gif]]]
|
2018-02-08 16:37:50 +03:00
|
|
|
|
|
2018-02-24 18:03:35 +03:00
|
|
|
|
GetFiles $treeFiles $rootNode [file join $rootDir]
|
2018-02-08 16:37:50 +03:00
|
|
|
|
$treeFiles configure -redraw 1
|
|
|
|
|
}
|
|
|
|
|
proc GetFilesSubdir {tree node dir} {
|
2018-02-24 18:03:35 +03:00
|
|
|
|
global fontNormal projDir workDir activeProject imgDir
|
2018-02-08 16:37:50 +03:00
|
|
|
|
global backUpFileShow dotFileShow
|
|
|
|
|
set rList ""
|
2018-02-24 18:03:35 +03:00
|
|
|
|
puts "$tree $node $dir"
|
2018-02-08 16:37:50 +03:00
|
|
|
|
if {[catch {cd $dir}] != 0} {
|
|
|
|
|
return ""
|
|
|
|
|
}
|
|
|
|
|
if {$dotFileShow eq "Yes"} {
|
|
|
|
|
foreach file [lsort [glob -nocomplain .*]] {
|
2018-02-24 18:03:35 +03:00
|
|
|
|
if {$file != "." || $file != ".."} {
|
2018-02-08 16:37:50 +03:00
|
|
|
|
lappend rList [list [file join $dir $file]]
|
2018-02-24 18:03:35 +03:00
|
|
|
|
set fileName [file join $dir $file]
|
|
|
|
|
GetFile $tree $fileName $parent
|
2018-02-08 16:37:50 +03:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
foreach file [lsort [glob -nocomplain *]] {
|
|
|
|
|
lappend rList [list [file join $dir $file]]
|
2018-02-24 18:03:35 +03:00
|
|
|
|
set fileName [file join $dir $file]
|
|
|
|
|
GetFile $tree $fileName $parent
|
2018-02-08 16:37:50 +03:00
|
|
|
|
}
|
|
|
|
|
$tree itemconfigure $node -open 1
|
|
|
|
|
}
|
|
|
|
|
## GETTING FILES FROM PROJECT DIR AND INSERT INTO TREE WIDGET ##
|
2018-02-24 18:03:35 +03:00
|
|
|
|
proc GetFile {tree fileName parent} {
|
|
|
|
|
global fontNormal backUpFileShow dotFileShow imgDir
|
|
|
|
|
set img [GetImage $fileName]
|
|
|
|
|
set dot "_"
|
|
|
|
|
regsub -all {\.|/|\\} $fileName "_" subNode
|
|
|
|
|
puts $subNode
|
|
|
|
|
if {[$tree exists $subNode] != 1} {
|
|
|
|
|
$tree insert end $parent $subNode -text [file tail $fileName] \
|
|
|
|
|
-data $fileName -open 1\
|
|
|
|
|
-image [Bitmap::get [file join $imgDir $img.gif]]\
|
|
|
|
|
-font $fontNormal
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
proc GetFiles {tree parent dir} {
|
|
|
|
|
global fontNormal backUpFileShow dotFileShow imgDir
|
2018-02-08 16:37:50 +03:00
|
|
|
|
set rList ""
|
2018-02-24 18:03:35 +03:00
|
|
|
|
puts "$dir $parent $tree"
|
2018-02-08 16:37:50 +03:00
|
|
|
|
if {[catch {cd $dir}] != 0} {
|
|
|
|
|
return ""
|
|
|
|
|
}
|
|
|
|
|
if {$dotFileShow eq "Yes"} {
|
|
|
|
|
foreach file [lsort [glob -nocomplain .*]] {
|
2018-02-24 18:03:35 +03:00
|
|
|
|
if {$file != "." || $file != ".."} {
|
2018-02-08 16:37:50 +03:00
|
|
|
|
lappend rList [list [file join $dir $file]]
|
2018-02-24 18:03:35 +03:00
|
|
|
|
set fileName [file join $dir $file]
|
|
|
|
|
|
|
|
|
|
GetFile $tree $fileName $parent
|
2018-02-08 16:37:50 +03:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
foreach file [lsort [glob -nocomplain *]] {
|
|
|
|
|
lappend rList [list [file join $dir $file]]
|
2018-02-24 18:03:35 +03:00
|
|
|
|
set fileName [file join $dir $file]
|
|
|
|
|
GetFile $tree $fileName $parent
|
2018-02-08 16:37:50 +03:00
|
|
|
|
}
|
|
|
|
|
$tree configure -redraw 1
|
|
|
|
|
}
|
2018-02-24 18:03:35 +03:00
|
|
|
|
|
2018-02-08 16:37:50 +03:00
|
|
|
|
## GETTING PROJECT NAMES FROM DIR AND PUTS INTO
|
|
|
|
|
proc GetProj {tree} {
|
|
|
|
|
global projDir workDir fontNormal imgDir module
|
2018-02-24 18:31:18 +03:00
|
|
|
|
set rList ""
|
|
|
|
|
#set tree .frmBody.frmCat.noteBook.fprojects.frmTree.tree
|
|
|
|
|
|
2018-02-08 16:37:50 +03:00
|
|
|
|
if {[catch {cd $workDir}] != 0} {
|
|
|
|
|
return ""
|
|
|
|
|
}
|
|
|
|
|
foreach proj [lsort [glob -nocomplain *.proj]] {
|
|
|
|
|
lappend rList [list [file join $workDir $proj]]
|
|
|
|
|
set projFile [open [file join $workDir $proj] r]
|
|
|
|
|
set prjName [file rootname $proj]
|
|
|
|
|
while {[gets $projFile line]>=0} {
|
|
|
|
|
scan $line "%s" keyWord
|
|
|
|
|
set string [string range $line [string first "\"" $line] [string last "\"" $line]]
|
|
|
|
|
set string [string trim $string "\""]
|
|
|
|
|
if {$keyWord == "ProjectName"} {
|
|
|
|
|
regsub -all " " $string "_" project
|
|
|
|
|
set projName "$string"
|
|
|
|
|
}
|
|
|
|
|
if {$keyWord == "ProjectDirName"} {
|
|
|
|
|
set projList($prjName) [file dirname $string]
|
2018-02-24 18:31:18 +03:00
|
|
|
|
#puts "$tree $projList($prjName) - $prjName - $string"
|
2018-02-08 16:37:50 +03:00
|
|
|
|
$tree insert end root $prjName -text "$projName" -font $fontNormal \
|
|
|
|
|
-data "prj_$prjName" -open 0\
|
|
|
|
|
-image [Bitmap::get [file join $imgDir folder.gif]]
|
2018-02-24 18:31:18 +03:00
|
|
|
|
#puts "GetFiles $tree $prjName $string"
|
|
|
|
|
GetFiles $tree $prjName $string
|
2018-02-24 18:03:35 +03:00
|
|
|
|
#$tree itemconfigure $prjName -open 1
|
|
|
|
|
|
2018-02-08 16:37:50 +03:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
$tree configure -redraw 1
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
## SHOW PUP-UP MENUS ##
|
2018-02-17 20:25:02 +03:00
|
|
|
|
proc PopupMenuFileTree {treeFiles x y} {
|
2018-02-22 15:45:46 +03:00
|
|
|
|
if {[$treeFiles selection get] != ""} {
|
|
|
|
|
set node [$treeFiles selection get]
|
|
|
|
|
$treeFiles selection set $node
|
|
|
|
|
} else {
|
|
|
|
|
return
|
|
|
|
|
}
|
2018-02-17 20:25:02 +03:00
|
|
|
|
if {[info exists fileList($node)] != 1} {
|
|
|
|
|
tk_popup .popupFile $x $y
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2018-02-08 16:37:50 +03:00
|
|
|
|
proc PopupMenuTree {x y} {
|
|
|
|
|
global tree fontNormal fontBold imgDir activeProject
|
2018-02-22 15:45:46 +03:00
|
|
|
|
if {[$tree selection get] != ""} {
|
|
|
|
|
set node [$tree selection get]
|
|
|
|
|
$tree selection set $node
|
|
|
|
|
} else {
|
|
|
|
|
return
|
2018-02-08 16:37:50 +03:00
|
|
|
|
}
|
2018-02-22 15:45:46 +03:00
|
|
|
|
|
|
|
|
|
#$tree selection set $node
|
2018-02-08 16:37:50 +03:00
|
|
|
|
set item [$tree itemcget $node -data]
|
|
|
|
|
if {[string range $item 0 2] == "prj"} {
|
|
|
|
|
set activeProject [string range $item 4 end]
|
|
|
|
|
.frmStatus.frmActive.lblActive configure -text [$tree itemcget $node -text] -font $fontBold
|
|
|
|
|
tk_popup .popupProj $x $y
|
|
|
|
|
return
|
|
|
|
|
}
|
|
|
|
|
if {[info exists fileList($node)] != 1} {
|
|
|
|
|
# set fileList($node) $item
|
|
|
|
|
tk_popup .popupFile $x $y
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2018-02-17 20:25:02 +03:00
|
|
|
|
|
2018-02-08 16:37:50 +03:00
|
|
|
|
## OPEN TREE PROCEDURE
|
|
|
|
|
proc TreeOpen {node} {
|
|
|
|
|
global fontNormal tree projDir workDir activeProject fileList noteBook findString imgDir fontBold
|
2018-02-22 15:45:46 +03:00
|
|
|
|
set tree [GetTreeForNode $node]
|
2018-02-08 16:37:50 +03:00
|
|
|
|
$tree selection set $node
|
|
|
|
|
set item [$tree itemcget $node -data]
|
|
|
|
|
if {[string range $item 0 2] == "prj"} {
|
|
|
|
|
set activeProject [string range $item 4 end]
|
2018-02-17 20:25:02 +03:00
|
|
|
|
#puts $activeProject
|
2018-02-08 16:37:50 +03:00
|
|
|
|
.frmStatus.frmActive.lblActive configure -text [$tree itemcget $node -text] -font $fontBold
|
|
|
|
|
$tree itemconfigure $node -image [Bitmap::get [file join $imgDir openfold.gif]]
|
|
|
|
|
if {[file exists [file join $workDir $activeProject.tags]] == 1} {
|
|
|
|
|
GetTagList [file join $workDir $activeProject.tags] ;# geting tag list
|
|
|
|
|
} else {
|
|
|
|
|
DoModule ctags
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
if {[info exists fileList($node)] != 1} {
|
|
|
|
|
set fileList($node) $item
|
|
|
|
|
if {[file isdirectory $item] == 1} {
|
|
|
|
|
$tree itemconfigure $node -image [Bitmap::get [file join $imgDir openfold.gif]]
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
## CLOSE TREE PROCEDURE ##
|
|
|
|
|
proc TreeClose {node} {
|
|
|
|
|
global fontNormal tree projDir workDir activeProject fileList noteBook findString imgDir fontBold
|
2018-02-22 15:45:46 +03:00
|
|
|
|
set tree [GetTreeForNode $node]
|
2018-02-08 16:37:50 +03:00
|
|
|
|
$tree selection set $node
|
|
|
|
|
set item [$tree itemcget $node -data]
|
|
|
|
|
if {[string range $item 0 2] == "prj"} {
|
|
|
|
|
$tree itemconfigure $node -image [Bitmap::get [file join $imgDir folder.gif]]
|
|
|
|
|
}
|
|
|
|
|
if {[info exists fileList($node)] != 1} {
|
|
|
|
|
if {[file isdirectory $item] == 1} {
|
|
|
|
|
$tree itemconfigure $node -image [Bitmap::get [file join $imgDir folder.gif]]
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
## TREE ONE CLICK PROCEDURE ##
|
|
|
|
|
proc TreeOneClick {tree node} {
|
2018-02-24 18:03:35 +03:00
|
|
|
|
global noteBook fontNormal projDir workDir activeProject fileList noteBook findString imgDir fontBold
|
2018-02-17 20:25:02 +03:00
|
|
|
|
$tree selection get
|
|
|
|
|
$tree selection set $node
|
2018-02-08 16:37:50 +03:00
|
|
|
|
set item [$tree itemcget $node -data]
|
|
|
|
|
if {[string range $item 0 2] == "prj"} {
|
|
|
|
|
set activeProject [string range $item 4 end]
|
|
|
|
|
.frmStatus.frmActive.lblActive configure -text [$tree itemcget $node -text] -font $fontBold
|
|
|
|
|
if {[file exists [file join $workDir $activeProject.tags]] == 1} {
|
|
|
|
|
GetTagList [file join $workDir $activeProject.tags] ;# geting tag list
|
|
|
|
|
}
|
|
|
|
|
return
|
2018-02-24 18:03:35 +03:00
|
|
|
|
} elseif {[file isdirectory $item] == 1} {
|
|
|
|
|
if {[$noteBook index $node] == -1} {
|
2018-02-08 16:37:50 +03:00
|
|
|
|
return
|
2018-02-24 18:03:35 +03:00
|
|
|
|
}
|
|
|
|
|
} elseif {[file isfile $item] == 1 } {
|
2018-02-24 19:42:49 +03:00
|
|
|
|
LabelUpdate .frmStatus.frmHelp.lblHelp [FileAttr $item]
|
2018-02-24 18:03:35 +03:00
|
|
|
|
if {[$noteBook index $node] != -1} {
|
2018-02-24 19:42:49 +03:00
|
|
|
|
PageRaise $tree $node
|
2018-02-08 16:37:50 +03:00
|
|
|
|
if {[file exists $item] == 1} {
|
|
|
|
|
}
|
|
|
|
|
}
|
2018-02-24 18:03:35 +03:00
|
|
|
|
} elseif {[string range $item 0 2] == "prc"} {
|
2018-02-08 16:37:50 +03:00
|
|
|
|
set parent [$tree parent $node]
|
|
|
|
|
set file [$tree itemcget $parent -data]
|
|
|
|
|
set fileExt [string range [file extension $file] 1 end]
|
|
|
|
|
if {[info exists fileList($parent)] == 0} {
|
|
|
|
|
EditFile $parent $file
|
|
|
|
|
}
|
|
|
|
|
PageRaise $tree $parent
|
|
|
|
|
$tree selection set $node
|
|
|
|
|
set text "$noteBook.f$parent.text"
|
|
|
|
|
set index1 [expr [string first "_" $item]+1]
|
|
|
|
|
set index2 [expr [string last "_" $item]11]
|
|
|
|
|
if {$fileExt == "java" || $fileExt == "ja"} {
|
|
|
|
|
set findString "class [string range $item $index1 $index2] "
|
|
|
|
|
} elseif {$fileExt == "perl" || $fileExt == "pl"} {
|
|
|
|
|
set findString "sub [string range $item $index1 $index2]"
|
|
|
|
|
} elseif {$fileExt == "ml" || $fileExt == "mli"} {
|
|
|
|
|
set findString "let [string range $item $index1 $index2]"
|
|
|
|
|
} elseif {$fileExt == "php" || $fileExt == "phtml"} {
|
|
|
|
|
set findString "function [string range $item $index1 $index2]"
|
2018-02-17 20:25:02 +03:00
|
|
|
|
#puts $findString
|
2018-02-08 16:37:50 +03:00
|
|
|
|
#return
|
|
|
|
|
} elseif {$fileExt == "rb"} {
|
|
|
|
|
set findString "class [string range $item $index1 $index2]"
|
|
|
|
|
} else {
|
|
|
|
|
set findString "proc [string range $item $index1 $index2] "
|
|
|
|
|
}
|
|
|
|
|
FindProc $text $findString $node
|
|
|
|
|
focus -force $text
|
|
|
|
|
}
|
|
|
|
|
}
|
2018-02-24 18:03:35 +03:00
|
|
|
|
|
2018-02-08 16:37:50 +03:00
|
|
|
|
## TREE DOUBLE CLICK PROCEDURE ##
|
|
|
|
|
proc TreeDoubleClick {tree node} {
|
2018-02-24 18:03:35 +03:00
|
|
|
|
global fontNormal projDir workDir activeProject fileList noteBook findString imgDir fontBold noteBook
|
2018-02-08 16:37:50 +03:00
|
|
|
|
$tree selection set $node
|
|
|
|
|
set item [$tree itemcget $node -data]
|
2018-02-24 18:03:35 +03:00
|
|
|
|
|
|
|
|
|
if {[$tree itemcget $node -open ] == 1} {
|
|
|
|
|
puts " $item $tree itemcget $node -open"
|
|
|
|
|
$tree closetree $node
|
|
|
|
|
} elseif {[$tree itemcget $node -open ] == 0} {
|
|
|
|
|
puts " $item $tree itemcget $node -open"
|
|
|
|
|
$tree opentree $node
|
|
|
|
|
}
|
|
|
|
|
$tree opentree $node
|
2018-02-08 16:37:50 +03:00
|
|
|
|
if {[string range $item 0 2] == "prj"} {
|
2018-02-24 18:03:35 +03:00
|
|
|
|
# node is project
|
2018-02-08 16:37:50 +03:00
|
|
|
|
set activeProject [string range $item 4 end]
|
|
|
|
|
.frmStatus.frmActive.lblActive configure -text [$tree itemcget $node -text] -font $fontBold
|
2018-02-24 18:03:35 +03:00
|
|
|
|
#GetFilesSubdir $tree $node $item
|
|
|
|
|
} elseif {[file isdirectory $item] ==1} {
|
|
|
|
|
# node is directory
|
|
|
|
|
GetFiles $tree $node $item
|
|
|
|
|
puts "GetFiles $tree $node $item"
|
|
|
|
|
} elseif {[string range $item 0 2] == "prc"} {
|
|
|
|
|
# node is procedure (class, function, etc)
|
2018-02-08 16:37:50 +03:00
|
|
|
|
$tree selection set $node
|
|
|
|
|
set parent [$tree parent $node]
|
|
|
|
|
if {[info exists fileList($parent)] != 1} {
|
|
|
|
|
set file [$tree itemcget $parent -data]
|
|
|
|
|
EditFile $parent $file
|
|
|
|
|
$noteBook raise $parent
|
|
|
|
|
} else {
|
|
|
|
|
$noteBook raise $parent
|
|
|
|
|
}
|
|
|
|
|
set text "$noteBook.f$parent.text"
|
|
|
|
|
set index1 [expr [string first "_" $item]+1]
|
|
|
|
|
set index2 [expr [string last "_" $item]11]
|
|
|
|
|
set findString "proc [string range $item $index1 $index2] "
|
|
|
|
|
FindProc $text $findString $node
|
|
|
|
|
focus -force $text
|
2018-02-24 18:03:35 +03:00
|
|
|
|
} elseif {[file isfile $item] == 1} {
|
|
|
|
|
#puts [$noteBook index $node]
|
|
|
|
|
if {[$noteBook index $node] != -1} {
|
|
|
|
|
puts "File тута $node"
|
|
|
|
|
puts "fileList($node) $fileList($node)"
|
|
|
|
|
} else {
|
|
|
|
|
EditFile $tree $node $item
|
|
|
|
|
}
|
|
|
|
|
} else {
|
|
|
|
|
return
|
2018-02-08 16:37:50 +03:00
|
|
|
|
}
|
2018-02-24 18:03:35 +03:00
|
|
|
|
|
2018-02-08 16:37:50 +03:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
## UPDATE TREE ##
|
|
|
|
|
proc UpdateTree {} {
|
|
|
|
|
global tree
|
|
|
|
|
$tree delete [$tree nodes root]
|
|
|
|
|
GetProj $tree
|
|
|
|
|
}
|
|
|
|
|
|
2018-02-13 13:23:40 +03:00
|
|
|
|
proc GetTreeForNode {node} {
|
|
|
|
|
if {[.frmBody.frmCat.noteBook.ffiles.frmTreeFiles.treeFiles exists $node] ==1} {
|
|
|
|
|
return .frmBody.frmCat.noteBook.ffiles.frmTreeFiles.treeFiles
|
|
|
|
|
} elseif {[.frmBody.frmCat.noteBook.fprojects.frmTree.tree exists $node] ==1} {
|
|
|
|
|
return .frmBody.frmCat.noteBook.fprojects.frmTree.tree
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
}
|
2018-02-22 15:45:46 +03:00
|
|
|
|
proc FileNotePageRaise {nb s} {
|
|
|
|
|
global workingTree
|
|
|
|
|
if {$nb eq "files"} {
|
|
|
|
|
set workingTree .frmBody.frmCat.noteBook.ffiles.frmTreeFiles.treeFiles
|
|
|
|
|
} elseif {$nb eq "projects"} {
|
|
|
|
|
set workingTree .frmBody.frmCat.noteBook.fprojects.frmTree.tree
|
|
|
|
|
} else {
|
|
|
|
|
puts "Error node"
|
|
|
|
|
return
|
|
|
|
|
}
|
|
|
|
|
}
|
2018-02-18 15:01:56 +03:00
|
|
|
|
|
2018-02-24 12:22:08 +03:00
|
|
|
|
|
2018-02-24 18:31:18 +03:00
|
|
|
|
|
|
|
|
|
|
2018-02-24 19:42:49 +03:00
|
|
|
|
|