tree.tcl 21 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721
  1. ###########################################################
  2. # Name: tree.tcl
  3. # Author: Daniele Bonini (posta@elettronica.lol)
  4. # Date: 05/12/2023
  5. # Desc: Tree namespace of RadXIDE.
  6. #
  7. # Tree namespace and most of code
  8. # here presented and distributed contain excerpts
  9. # from [alited](https://github.com/aplsimple/alited
  10. # by Alex Plotnikov and contributors to the project.
  11. # The original code of these excerpts could be
  12. # borrowed from other sources which the author
  13. # and the contributors to this RadXIDE have no
  14. # knowledge about.
  15. #
  16. # License: MIT. Copyrights 5 Mode (Last implementation and adaptations.)
  17. # Copyright (c) 2021-2023 Alex Plotnikov https://aplsimple.github.io (original scaffolding and excerpts.)
  18. #
  19. ###########################################################
  20. namespace eval tree {
  21. # ________________________ AddItem _________________________ #
  22. proc addFile {{ID ""}} {
  23. # Adds a new item to the tree.
  24. # ID - an item's ID where the new item will be added (for the file tree).
  25. namespace upvar ::radxide dan dan
  26. set tree $dan(TREEVIEW)
  27. lassign [$tree item $ID -values] -> fname isfile
  28. set destfolder $fname
  29. if {!$isfile} {
  30. #tk_messageBox -title $dan(TITLE) -icon error -message $destfolder
  31. ::radxide::filelib::createFile $destfolder
  32. # Refreshing TreeView
  33. ::radxide::tree::create
  34. }
  35. }
  36. # ________________________ addTags _________________________ #
  37. proc addTags {tree} {
  38. # Creates tags for the tree.
  39. # tree - the tree's path
  40. namespace upvar ::radxide dan dan
  41. #lassign [::hl_tcl::addingColors {} -AddTags] - - fgbr - - fgred - - - fgtodo
  42. $tree tag configure tagNorm -foreground $dan(FG)
  43. $tree tag configure tagSel -foreground $dan(fgred)
  44. $tree tag configure tagBold -foreground $dan(fgbold)
  45. $tree tag configure tagTODO -foreground $dan(fgtodo)
  46. $tree tag configure tagBranch -foreground $dan(fgbranch)
  47. }
  48. # ________________________ AddToDirContents _________________________ #
  49. proc addToDirContent {lev isfile fname iroot} {
  50. # Adds an item to a list of directory's contents.
  51. # lev - level in the directory hierarchy
  52. # isfile - a flag "file" (if yes) or "directory" (if no)
  53. # fname - a file name to be added
  54. # iroot - index of the directory's parent or -1
  55. namespace upvar ::radxide dan dan _dirtree _dirtree
  56. set dllen [llength $_dirtree]
  57. if {$dllen < $dan(MAXFILES)} {
  58. lappend _dirtree [list $lev $isfile $fname 0 $iroot]
  59. if {$iroot>-1} {
  60. lassign [lindex $_dirtree $iroot] lev isfile fname fcount sroot
  61. set _dirtree [lreplace $_dirtree $iroot $iroot \
  62. [list $lev $isfile $fname [incr fcount] $sroot]]
  63. }
  64. }
  65. return $dllen
  66. }
  67. # ________________________ buttonPress _________________________ #
  68. proc buttonPress {but x y X Y} {
  69. # Handles a mouse clicking the tree.
  70. # but - mouse button
  71. # x - x-coordinate to identify an item
  72. # y - y-coordinate to identify an item
  73. # X - x-coordinate of the click
  74. # Y - x-coordinate of the click
  75. namespace upvar ::radxide dan dan menu menu
  76. set tree $dan(TREEVIEW)
  77. set ID [$tree identify item $x $y]
  78. set region [$tree identify region $x $y]
  79. #set al(movID) [set al(movWin) {}]
  80. if {![$tree exists $ID] || $region ni {tree cell}} {
  81. return ;# only tree items are processed
  82. }
  83. #tk_messageBox -title $dan(TITLE) -icon error -message $but
  84. switch $but {
  85. {3} {
  86. if {[llength [$tree selection]]<2} {
  87. $tree selection set $ID
  88. }
  89. showPopupMenu $ID $X $Y
  90. }
  91. {1} {
  92. #::radxide::tree::openFile $ID
  93. lassign [$tree item $ID -values] -> fname isfile
  94. if {$isfile} {
  95. $menu(FILE) entryconfigure $menu(ADD_FILE_ENTRY_IDX) -state disabled
  96. } else {
  97. $menu(FILE) entryconfigure $menu(ADD_FILE_ENTRY_IDX) -state normal
  98. }
  99. }
  100. }
  101. }
  102. # ________________________ buttonRelease _________________________ #
  103. proc buttonRelease {but s x y X Y} {
  104. # Handles a mouse button releasing on the tree, at moving an item.
  105. # but - mouse button
  106. # s - state (ctrl/alt/shift)
  107. # x - x-coordinate to identify an item
  108. # y - y-coordinate to identify an item
  109. # X - x-coordinate of the click
  110. # Y - x-coordinate of the click
  111. namespace upvar ::radxide dan dan
  112. set tree $dan(TREEVIEW)
  113. set ID [$tree identify item $x $y]
  114. #DestroyMoveWindow no
  115. #set msec [clock milliseconds]
  116. #set ctrl [expr {$s & 0b100}]
  117. #if {([info exists al(_MSEC)] && [expr {($msec-$al(_MSEC))<400}]) || $ctrl} {
  118. # SelectUnits $wtree $ctrl
  119. # set al(movWin) {}
  120. # return
  121. #}
  122. #if {[$tree exists $ID] && [info exists al(movID)] && \
  123. #$al(movID) ne {} && $ID ne {} && $al(movID) ne $ID && \
  124. #[$wtree identify region $x $y] eq {tree}} {
  125. # if {$al(TREE,isunits)} {
  126. # alited::unit::MoveUnits $wtree move $al(movID) $ID
  127. # } else {
  128. # alited::file::MoveFiles $wtree move $al(movID) $ID
  129. # }
  130. #}
  131. #DestroyMoveWindow yes
  132. }
  133. # ________________________ clearTree _________________________ #
  134. proc clearTree {TreeView item} {
  135. # Removes recursively an item and its children from the tree.
  136. # TreeView - the tree widget's path
  137. # item - ID of the item to be deleted.
  138. foreach child [$TreeView children $item] {
  139. clearTree $TreeView $child
  140. }
  141. if {$item ne {}} {$TreeView delete $item}
  142. }
  143. # ________________________ create _________________________ #
  144. proc create {} {
  145. # Creates a tree of files, at need.
  146. namespace upvar ::radxide dan dan menu menu
  147. set tree $dan(TREEVIEW)
  148. # for file tree: get its current "open branch" flags
  149. # in order to check them in createFilesTree
  150. set dan(SAVED_FILE_TREE) [list]
  151. foreach item [getTree] {
  152. lassign $item - - ID - values
  153. lassign $values -> fname isfile
  154. if {[string is false -strict $isfile]} {
  155. lappend dan(SAVED_FILE_TREE) [list $fname [$tree item $ID -open]]
  156. }
  157. }
  158. #set TID [alited::bar::CurrentTabID]
  159. delete $tree {}
  160. addTags $tree
  161. bind $tree "<ButtonPress>" {after idle {::radxide::tree::buttonPress %b %x %y %X %Y}}
  162. #bind $tree "<ButtonRelease>" {after idle {::radxide::tree::buttonRelease %b %s %x %y %X %Y}}
  163. bind $tree "<Double-Button-1>" {after idle {::radxide::tree::dblClick %b %x %y %X %Y}}
  164. #bind $tree "<Motion>" {after idle {::radxide::tree::ButtonMotion %b %s %x %y %X %Y}}
  165. #bind $tree "<ButtonRelease>" {alited::tree::DestroyMoveWindow no}
  166. #bind $tree "<Leave>" {alited::tree::DestroyMoveWindow yes}
  167. #bind $tree "<F2>" {alited::file::RenameFileInTree 0 -}
  168. #bind $tree "<Insert>" {alited::tree::AddItem}
  169. #bind $tree "<Delete>" {alited::tree::DelItem {} {}}
  170. createFileTree $tree
  171. unset dan(SAVED_FILE_TREE)
  172. $menu(FILE) entryconfigure $menu(ADD_FILE_ENTRY_IDX) -state disabled
  173. }
  174. # ________________________ createFileTree _________________________ #
  175. proc createFileTree {tree} {
  176. # Creates a file tree.
  177. # wtree - the tree's path
  178. namespace upvar ::radxide dan dan project project icons icons
  179. #set al(TREE,files) yes
  180. #[$obPav BtTswitch] configure -image alimg_gulls
  181. #baltip::tip [$obPav BtTswitch] $al(MC,swfiles)
  182. #baltip::tip [$obPav BtTAddT] $al(MC,filesadd)\nInsert
  183. #baltip::tip [$obPav BtTDelT] $al(MC,filesdel)\nDelete
  184. #baltip::tip [$obPav BtTUp] $al(MC,moveupF)
  185. #baltip::tip [$obPav BtTDown] $al(MC,movedownF)
  186. #$tree heading #0 -text ":: [file tail $al(prjroot)] ::"
  187. #$tree heading #1 -text $al(MC,files)
  188. bind $tree <Return> {::radxide::tree::openFile}
  189. set selID ""
  190. #if {[catch {set selfile [alited::bar::FileName]}]} {
  191. # set selfile {} ;# at closing by Ctrl+W with file tree open: no current file
  192. #}
  193. set parent {}
  194. set fc 0
  195. set fname $project(ROOT)
  196. set title [file tail $fname]
  197. set isfile no
  198. set itemID 0
  199. set isopen yes
  200. set imgopt $icons(PROJECT-ICONI)
  201. $tree insert $parent end -id $itemID -text "$title" \
  202. -values [list $fc $fname $isfile $itemID] -open $isopen -image $imgopt
  203. foreach item [getDirectoryContent $project(ROOT)] {
  204. set itemID [newItemID [incr iit]]
  205. lassign $item lev isfile fname fcount iroot
  206. #if {$selfile eq $fname} {set selID $itemID}
  207. set title [file tail $fname]
  208. if {$iroot<0} {
  209. set parent 0 ;#{}
  210. } else {
  211. set parent [newItemID [incr iroot]]
  212. }
  213. set isopen no
  214. if {$isfile} {
  215. if {$parent eq 0} {
  216. continue
  217. }
  218. if {[isPhp $fname]} {
  219. set imgopt $icons(PHP-ICONI)
  220. } else {
  221. set imgopt $icons(GENERIC-FILE-ICONI)
  222. }
  223. } else {
  224. if {$title eq "Private"} {
  225. set imgopt $icons(PRIVATEF-ICONI)
  226. } elseif {$title eq "Public"} {
  227. set imgopt $icons(PUBLICF-ICONI)
  228. } else {
  229. if {$parent eq 0} {
  230. continue
  231. }
  232. set imgopt $icons(FOLDER-ICONI)
  233. }
  234. # get the directory's flag of expanded branch (in the file tree)
  235. set idx [lsearch -index 0 -exact $dan(SAVED_FILE_TREE) $fname]
  236. if {$idx>-1} {
  237. set isopen [lindex $dan(SAVED_FILE_TREE) $idx 1]
  238. }
  239. }
  240. if {$fcount} {set fc $fcount} {set fc {}}
  241. $tree insert $parent end -id $itemID -text "$title" \
  242. -values [list $fc $fname $isfile $itemID] -open $isopen -image $imgopt
  243. $tree tag add tagNorm $itemID
  244. if {!$isfile} {
  245. $tree tag add tagBranch $itemID
  246. }
  247. }
  248. if {$selID ne {}} {
  249. $tree see $selID
  250. $tree selection set $selID
  251. }
  252. }
  253. # ________________________ delete _________________________ #
  254. proc deleteFile {ID} {
  255. # Removes a file.
  256. # ID - ID of the item to be deleted.
  257. namespace upvar ::radxide dan dan
  258. set tree $dan(TREEVIEW)
  259. if {$ID eq {}} {
  260. if {[set ID [$tree selection]] eq {}} return
  261. }
  262. lassign [$tree item $ID -values] -> fname isfile
  263. if {$isfile} {
  264. set answer [tk_messageBox -title $dan(TITLE) -message "Really delete the selected file?" \
  265. -icon question -type yesno -detail "Selected: \"$fname\""]
  266. if {$answer eq yes} {
  267. ::radxide::filelib::delFile $fname
  268. ::radxide::tree::create
  269. }
  270. }
  271. }
  272. # ________________________ delete _________________________ #
  273. proc delete {tree item} {
  274. # Removes recursively an item and its children from the tree.
  275. # tree - the tree widget's path
  276. # item - ID of the item to be deleted.
  277. foreach child [$tree children $item] {
  278. delete $tree $child
  279. }
  280. if {$item ne {}} {$tree delete $item}
  281. }
  282. # ________________________ dblClick _________________________ #
  283. proc dblClick {but x y X Y} {
  284. # Handles a mouse clicking the tree.
  285. # but - mouse button
  286. # x - x-coordinate to identify an item
  287. # y - y-coordinate to identify an item
  288. # X - x-coordinate of the click
  289. # Y - x-coordinate of the click
  290. namespace upvar ::radxide dan dan
  291. set tree $dan(TREEVIEW)
  292. set ID [$tree identify item $x $y]
  293. set region [$tree identify region $x $y]
  294. #set al(movID) [set al(movWin) {}]
  295. if {![$tree exists $ID] || $region ni {tree cell}} {
  296. return ;# only tree items are processed
  297. }
  298. #tk_messageBox -title $dan(TITLE) -icon error -message DoubleClick: ($but)
  299. switch $but {
  300. {3} {
  301. }
  302. {1} {
  303. #set al(movID) $ID
  304. #set al(movWin) .tritem_move
  305. #set msec [clock milliseconds]
  306. #if {[info exists al(_MSEC)] && [expr {($msec-$al(_MSEC))<400}]} {
  307. ::radxide::tree::openFile $ID
  308. #}
  309. #set al(_MSEC) $msec
  310. }
  311. }
  312. }
  313. # ________________________ dirContent _________________________ #
  314. proc dirContent {dirname {lev 0} {iroot -1} {globs "*"}} {
  315. # Reads a directory's contents.
  316. # dirname - a dirtectory's name
  317. # lev - level in the directory hierarchy
  318. # iroot - index of the directory's parent or -1
  319. # globs - list of globs to filter files.
  320. namespace upvar ::radxide dan dan _dirtree _dirtree
  321. incr lev
  322. if {[catch {set dcont [lsort -dictionary [glob [file join $dirname *]]]}]} {
  323. set dcont [list]
  324. }
  325. # firstly directories:
  326. # 1. skip the ignored ones
  327. for {set i [llength $dcont]} {$i} {} {
  328. incr i -1
  329. if {[ignoredDir [lindex $dcont $i]]} {
  330. set dcont [lreplace $dcont $i $i]
  331. }
  332. }
  333. # 2. put the directories to the beginning of the file list
  334. set i 0
  335. foreach fname $dcont {
  336. if {[file isdirectory $fname]} {
  337. set dcont [lreplace $dcont $i $i [list $fname "y"]]
  338. set nroot [addToDirContent $lev 0 $fname $iroot]
  339. if {[llength $_dirtree] < $dan(MAXFILES)} {
  340. dirContent $fname $lev $nroot $globs
  341. } else {
  342. break
  343. }
  344. } else {
  345. set dcont [lreplace $dcont $i $i [list $fname]]
  346. }
  347. incr i
  348. }
  349. # then files
  350. if {[llength $_dirtree] < $dan(MAXFILES)} {
  351. foreach fname $dcont {
  352. lassign $fname fname d
  353. if {$d ne "y"} {
  354. foreach gl [split $globs ","] {
  355. if {[string match $gl $fname]} {
  356. addToDirContent $lev 1 $fname $iroot
  357. break
  358. }
  359. }
  360. }
  361. }
  362. }
  363. }
  364. # ________________________ getDirectoryContent _________________________ #
  365. proc getDirectoryContent {dirname} {
  366. # Gets a directory's content.
  367. # dirname - the directory's name
  368. # Returns a list containing the directory's content.
  369. namespace upvar ::radxide dan dan _dirtree _dirtree
  370. set _dirtree [set dan(_dirignore) [list]]
  371. set _dirtree [list]
  372. catch { ;# there might be an incorrect list -> catch it
  373. foreach d $dan(prjdirignore) {
  374. lappend dan(_dirignore) [string toupper [string trim $d \"]]
  375. }
  376. }
  377. lappend dan(_dirignore) [string toupper [file tail [::radxide::Tclexe]]]
  378. dirContent $dirname
  379. return $_dirtree
  380. }
  381. # ________________________ ignoredDir _________________________ #
  382. proc getTree {{parent {}}} {
  383. # Gets a tree or its branch.
  384. # parent - ID of the branch
  385. # Tree - name of the tree widget
  386. namespace upvar ::radxide dan dan
  387. set tree $dan(TREEVIEW)
  388. set mytree [list]
  389. set levp -1
  390. procTreeItems $tree {
  391. set item "%item"
  392. set lev %level
  393. if {$levp>-1 || $item eq $parent} {
  394. if {$lev<=$levp} {return -code break} ;# all of branch fetched
  395. if {$item eq $parent} {set levp $lev}
  396. }
  397. catch {
  398. if {$parent eq {} || $levp>-1} {
  399. lappend mytree [list $lev %children $item {%text} {%values}]
  400. }
  401. }
  402. }
  403. return $mytree
  404. }
  405. # ________________________ ignoredDir _________________________ #
  406. proc ignoredDir {dir} {
  407. # Checks if a directory is in the list of the ignored ones.
  408. # dir - the directory's name
  409. namespace upvar ::radxide dan dan
  410. set dir [string toupper [file tail $dir]]
  411. return [expr {[lsearch -exact $dan(_dirignore) $dir]>-1}]
  412. }
  413. # ________________________ isPhp _________________________ #
  414. proc isPhp {fname} {
  415. # Checks if a file is of PHP.
  416. # fname - file name
  417. if {[string tolower [file extension $fname]] in $radxide::dan(PhpExts)} {
  418. return yes
  419. }
  420. return no
  421. }
  422. # ________________________ newItemID _________________________ #
  423. proc newItemID {iit} {
  424. # Gets a new ID for the tree item.
  425. # iit - index of the new item.
  426. return "al$iit"
  427. }
  428. # ________________________ openFile _________________________ #
  429. proc openFile {{ID ""}} {
  430. # Opens file at clicking a file tree's item.
  431. # ID - ID of file tree
  432. namespace upvar ::radxide dan dan menu menu project project
  433. set tree $dan(TREEVIEW)
  434. #tk_messageBox -title $dan(TITLE) -icon error -message $ID
  435. if {$ID eq {}} {
  436. if {[set ID [$tree selection]] eq {}} return
  437. }
  438. lassign [$tree item $ID -values] -> fname isfile
  439. if {$isfile} {
  440. $dan(TEXT) config -state normal
  441. $dan(TEXT) delete 1.0 end
  442. $dan(TEXT) insert 1.0 [::radxide::filelib::openFile $fname]
  443. ::radxide::win::fillGutter $dan(TEXT) $dan(GUTTEXT) 5 1 "#FFFFFF" "#222223"
  444. # Update menu
  445. $menu(FILE) entryconfigure $menu(SAVE_ENTRY_IDX) -state normal
  446. $menu(FILE) entryconfigure $menu(SAVE_AS_ENTRY_IDX) -state normal
  447. $menu(FILE) entryconfigure $menu(CLOSE_ENTRY_IDX) -state normal
  448. $menu(EDIT) entryconfigure $menu(COPY_ENTRY_IDX) -state normal
  449. $menu(EDIT) entryconfigure $menu(PASTE_ENTRY_IDX) -state normal
  450. $menu(EDIT) entryconfigure $menu(CUT_ENTRY_IDX) -state normal
  451. $menu(EDIT) entryconfigure $menu(FIND_ENTRY_IDX) -state normal
  452. set project(CUR_FILE_PATH) $fname
  453. ::radxide::main::updateAppTitle
  454. # after idle {alited::bar::BAR draw; alited::tree::UpdateFileTree}
  455. }
  456. }
  457. # ________________________ procTreeItems _________________________ #
  458. proc procTreeItems {tree aproc {lev 0} {branch {}}} {
  459. # Scans all items of the tree.
  460. # tree - the tree's path
  461. # aproc - a procedure to run at scanning
  462. # lev - level of the tree
  463. # branch - ID of the branch to be scanned
  464. # The 'aproc' argument can include wildcards to be replaced
  465. # appropriate data:
  466. # %level - current tree level
  467. # %children - children of a current item
  468. # %item - ID of a current item
  469. # %text - text of a current item
  470. # %values - values of a current item
  471. set children [$tree children $branch]
  472. if {$lev} {
  473. set proc [string map [list \
  474. %level $lev \
  475. %children [llength $children] \
  476. %item $branch \
  477. %text [$tree item $branch -text] \
  478. %values [$tree item $branch -values]] \
  479. $aproc]
  480. uplevel [expr {$lev+1}] "$proc"
  481. }
  482. incr lev
  483. foreach child $children {
  484. procTreeItems $tree $aproc $lev $child
  485. }
  486. }
  487. # ________________________ refreshTree _________________________ #
  488. proc refreshTree {{tree ""} {headers ""} {clearsel no}} {
  489. namespace upvar ::radxide dan dan
  490. if {$tree eq ""} {
  491. set tree $dan(TREEVIEW)
  492. }
  493. if {[set selID [$tree selection]] eq {}} return
  494. #tk_messageBox -title $dan(TITLE) -icon error -message $selID
  495. ::radxide::tree::create
  496. $tree selection set [list $selID]
  497. }
  498. # ________________________ renameFile _________________________ #
  499. proc renameFile {{ID ""}} {
  500. namespace upvar ::radxide dan dan
  501. set tree $dan(TREEVIEW)
  502. set args {}
  503. set name2 ""
  504. if {$ID eq {}} {
  505. if {[set ID [$tree selection]] eq {}} return
  506. }
  507. lassign [$tree item $ID -values] -> fname isfile
  508. # lassign [::radxide::win::input {} "Rename file" [list \
  509. # ent "{} {} {-w 32}" "{$fname}"] \
  510. # -head "File name:" res name2]
  511. set args "-buttons {butOK OK ::radxide::win::renameFileOK butCANCEL CANCEL ::radxide::win::renameFileCancel}"
  512. catch {lassign [::radxide::win::input "RenameFile" {} "Rename file" [list \
  513. ent "{} {} {-w 64}" "{$fname}"] \
  514. -head "File name:" {*}$args] res}
  515. #tk_messageBox -title $dan(TITLE) -icon error -message $res
  516. #tk_messageBox -title $dan(TITLE) -icon error -message $name2
  517. }
  518. # ________________________ showPopupMenu _________________________ #
  519. proc showPopupMenu {ID X Y} {
  520. # Creates and opens a popup menu at right clicking the tree.
  521. # ID - ID of clicked item
  522. # X - x-coordinate of the click
  523. # Y - y-coordinate of the click
  524. namespace upvar ::radxide dan dan project project
  525. #::baltip sleep 1000
  526. set tree $dan(TREEVIEW)
  527. set popm $tree.popup
  528. catch {destroy $popm}
  529. menu $popm -tearoff 0 -cursor ""
  530. set header [lindex [split "" \n] 0]
  531. lassign [$tree item $ID -values] -> fname isfile
  532. set m1 "Refresh project"
  533. set m2 "Add file"
  534. set m3 "Rename file"
  535. set m4 "Delete file"
  536. set m3b "Rename folder"
  537. set m4b "Delete folder"
  538. set m5 "Open file"
  539. set m6 "Open dir"
  540. $popm add command -label $m1 -command { ::radxide::tree::refreshTree }
  541. $popm add separator
  542. if {$isfile} {
  543. $popm add command -label $m2 -command "::radxide::tree::addFile $ID" -state disabled
  544. } else {
  545. $popm add command -label $m2 -command "::radxide::tree::addFile $ID" -state normal
  546. }
  547. if {$isfile} {
  548. $popm add command -label $m3 -command "::radxide::tree::renameFile $ID"
  549. $popm add command -label $m4 -command "::radxide::tree::deleteFile $ID"
  550. } else {
  551. if {($fname eq "$project(ROOT)/Public") || ($fname eq "$project(ROOT)/Private")} {
  552. $popm add command -label $m3b -command "::radxide::tree::renameFolder $ID" -state disabled
  553. $popm add command -label $m4b -command "::radxide::tree::delFolder $ID" -state disabled
  554. } else {
  555. $popm add command -label $m3b -command "::radxide::tree::renameFolder $ID" -state normal
  556. $popm add command -label $m4b -command "::radxide::tree::delFolder $ID" -state normal
  557. }
  558. }
  559. $popm add separator
  560. if {$isfile} {
  561. $popm add command -label $m5 -command "::radxide::tree::openFile $ID" -state normal
  562. } else {
  563. $popm add command -label $m5 -command { ::radxide::tree::openFile $ID } -state disabled
  564. }
  565. set addsel {}
  566. if {[llength [$tree selection]]>1} {
  567. if {[$tree tag has tagSel $ID]} {
  568. # the added tagSel tag should be overrided
  569. $tree tag remove tagSel $ID
  570. set addsel "; $tree tag add tagSel $ID"
  571. }
  572. }
  573. bind $popm <FocusIn> "$tree tag add tagBold $ID"
  574. bind $popm <FocusOut> "catch {$tree tag remove tagBold $ID; $addsel}"
  575. #$obPav themePopup $popm
  576. tk_popup $popm $X $Y
  577. }
  578. #_______________________
  579. }
  580. # _________________________________ EOF _________________________________ #