Class: RubyCurses::DirectoryTree
- Inherits:
-
Tree
- Object
- Tree
- RubyCurses::DirectoryTree
- Defined in:
- lib/rbcurse/experimental/widgets/directorytree.rb
Overview
this class shows a tree of directories. Pressing ENTER expands or collapses the node. Pressing ENTER selects a node. Should we give options for displaying filenames also ? TODO
Instance Attribute Summary collapse
-
#selected_path ⇒ Object
readonly
Returns the value of attribute selected_path.
Instance Method Summary collapse
- #_directories(wd) ⇒ Object
- #init_vars ⇒ Object
-
#path_expanded(path) ⇒ Object
notify applications of path expanded so they may do any related action # NOTE: this is not the cleanest way, since you will need objects from your app scope here.
-
#selected_path_changed(path) ⇒ Object
inform applications that path has changed gives the user application a place to effect changes elsewhere in app.
- #selection_event(ev) ⇒ Object
-
#will_expand_action(node) ⇒ Object
populate this node with child directories this gives user application a chance to override or extend this action.
Instance Attribute Details
#selected_path ⇒ Object (readonly)
Returns the value of attribute selected_path.
9 10 11 |
# File 'lib/rbcurse/experimental/widgets/directorytree.rb', line 9 def selected_path @selected_path end |
Instance Method Details
#_directories(wd) ⇒ Object
11 12 13 14 15 16 |
# File 'lib/rbcurse/experimental/widgets/directorytree.rb', line 11 def _directories wd d = Dir.new(wd) ent = d.entries.reject{|e| !File.directory? File.join(wd,e)} ent.delete(".");ent.delete("..") return ent end |
#init_vars ⇒ Object
18 19 20 21 22 23 24 25 26 27 28 29 |
# File 'lib/rbcurse/experimental/widgets/directorytree.rb', line 18 def init_vars super one_key_selection = false bind :TREE_WILL_EXPAND_EVENT do |node| node end bind :TREE_SELECTION_EVENT do |ev| selection_event ev end end |
#path_expanded(path) ⇒ Object
notify applications of path expanded so they may do any related action # NOTE: this is not the cleanest way, since you will need objects from your app scope here. User will have to add objects into the config hash after object creation and access them here. (See appdirtree.rb in examples)
54 55 |
# File 'lib/rbcurse/experimental/widgets/directorytree.rb', line 54 def path end |
#selected_path_changed(path) ⇒ Object
inform applications that path has changed gives the user application a place to effect changes elsewhere in app
66 67 |
# File 'lib/rbcurse/experimental/widgets/directorytree.rb', line 66 def selected_path_changed path end |
#selection_event(ev) ⇒ Object
56 57 58 59 60 61 62 63 |
# File 'lib/rbcurse/experimental/widgets/directorytree.rb', line 56 def selection_event ev if ev.state == :SELECTED node = ev.node path = File.join(*node.user_object_path) @selected_path = path selected_path_changed path end end |
#will_expand_action(node) ⇒ Object
populate this node with child directories this gives user application a chance to override or extend this action
33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 |
# File 'lib/rbcurse/experimental/widgets/directorytree.rb', line 33 def node path = File.join(*node.user_object_path) dirs = _directories path ch = node.children # add only children that may not be there ch.each do |e| o = e.user_object if dirs.include? o dirs.delete o else # delete this child since its no longer present TODO end end node.add dirs path end |