tree.tcl 23 KB

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