Class: VR::FileTreeView
- Defined in:
- lib/treeview/FileTreeView.rb
Defined Under Namespace
Classes: IconHash
Instance Attribute Summary collapse
-
#glob ⇒ Object
Returns the value of attribute glob.
-
#root ⇒ Object
Returns the value of attribute root.
-
#validate_block ⇒ Object
A Code block that further excludes files and folders included in the tree.
Attributes included from ViewCommon
#column_keys, #vr_cols, #vr_column, #vr_id, #vr_renderer
Instance Method Summary collapse
-
#add_file(filename, parent = @root_iter) ⇒ Object
Adds a file to the tree under a given parent iter.
-
#expand_or_collapse_folder ⇒ Object
Expands or collapses the currently selected row.
-
#get_open_folders ⇒ Array
returns an array of open folders.
-
#get_selected_path ⇒ String?
Returns the full filename with path of the selected file.
-
#initialize(root = Dir.pwd, icon_path = nil, glob = "*", validate_block = nil) ⇒ FileTreeView
constructor
FileTreeView creates a TreeView of files with folders and icons.
-
#open_folders(folder_paths) ⇒ Object
Opens a list of folders.
-
#refresh(flags = {}) ⇒ Object
Refresh the file tree, optionally with a new root folder, and optionally opening an array of folders.
-
#set_show_expanders(expand = true) ⇒ Object
Sets whether or not the little arrow expanders appear net to the folders.
Methods inherited from TreeView
Methods included from ViewCommon
#add_column, #add_renderer_to_col, #col_attr, #column, #delete_selected, #each_cell_method, #each_renderer, #each_row, #flatten_hash, #get_iter, #id, #method_missing, #ren_attr, #renderer, #selected_rows, #turn_on_comboboxes, #vr_row
Constructor Details
#initialize(root = Dir.pwd, icon_path = nil, glob = "*", validate_block = nil) ⇒ FileTreeView
FileTreeView creates a TreeView of files with folders and icons.
Often you should subclass this class for a particular use.
18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 |
# File 'lib/treeview/FileTreeView.rb', line 18 def initialize(root = Dir.pwd, icon_path = nil, glob = "*", validate_block = nil) @root = File.(root) @glob = glob @validate_block = validate_block super(file: { pix: GdkPixbuf::Pixbuf, file_name: String}, empty: TrueClass, path: String, sort_on: String) self.col_visible(path: false, sort_on: false, empty: false, file: false) self.headers_visible = false @icons = File.directory?(icon_path) ? IconHash.new(icon_path) : nil # parse_signals() #fix this! Subclasses may call twice! self.model.set_sort_column_id(id(:sort_on), :ascending ) self.set_enable_search(false) refresh self.signal_connect("row_expanded") { |view, iter, path| iter = model.get_iter(path) # bug fix fill_folder(iter) if iter[id(:empty)] } end |
Dynamic Method Handling
This class handles dynamic methods through the method_missing method in the class VR::ViewCommon
Instance Attribute Details
#glob ⇒ Object
Returns the value of attribute glob.
6 7 8 |
# File 'lib/treeview/FileTreeView.rb', line 6 def glob @glob end |
#root ⇒ Object
Returns the value of attribute root.
6 7 8 |
# File 'lib/treeview/FileTreeView.rb', line 6 def root @root end |
#validate_block ⇒ Object
A Code block that further excludes files and folders included in the tree. If this block returns false for the entry, it will be excluded. If it returns true, it will be included…
10 11 12 |
# File 'lib/treeview/FileTreeView.rb', line 10 def validate_block @validate_block end |
Instance Method Details
#add_file(filename, parent = @root_iter) ⇒ Object
Adds a file to the tree under a given parent iter.
102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 |
# File 'lib/treeview/FileTreeView.rb', line 102 def add_file(filename, parent = @root_iter) my_path = File.dirname(filename) model.each do |model, path, iter| return if iter[id(:path)] == filename # duplicate parent = iter if iter[id(:path)] == my_path end fn = filename.gsub("\\", "/") parent[id(:empty)] = false unless parent.nil? child = add_row(parent) child[:pix] = @icons.get_icon(File.directory?(fn) ? "x.folder" : fn) if @icons child[:file_name] = File.basename(fn) child[:path] = fn if File.directory?(fn) child[:sort_on] = "0" + child[:file_name] child[:empty] = true add_row(child) # dummy record so expander appears else child[id(:sort_on)] = "1" + child[id(:file_name)] end return child end |
#expand_or_collapse_folder ⇒ Object
Expands or collapses the currently selected row
70 71 72 73 74 75 76 77 |
# File 'lib/treeview/FileTreeView.rb', line 70 def () return unless row = selected_rows.first if (row.path) collapse_row(row.path) else (row.path, false) end end |
#get_open_folders ⇒ Array
returns an array of open folders. The array of folders can be saved, and then you can pass the array to #open_folders to restore the state of the file tree.
82 83 84 85 86 |
# File 'lib/treeview/FileTreeView.rb', line 82 def get_open_folders() = [] {|view, path| << model.get_iter(path)[id(:path)] } return end |
#get_selected_path ⇒ String?
Returns the full filename with path of the selected file.
133 134 135 |
# File 'lib/treeview/FileTreeView.rb', line 133 def get_selected_path() selection.selected ? selection.selected[id(:path)] : nil end |
#open_folders(folder_paths) ⇒ Object
Opens a list of folders.
90 91 92 93 94 95 96 97 98 |
# File 'lib/treeview/FileTreeView.rb', line 90 def open_folders(folder_paths) model.each do |model, path, iter| if folder_paths.include?(iter[id(:path)]) fill_folder(iter) # expand_row(path, false) # self__row_expanded(self, iter, path) end end end |
#refresh(flags = {}) ⇒ Object
Refresh the file tree, optionally with a new root folder, and optionally opening an array of folders.
41 42 43 44 45 46 47 48 |
# File 'lib/treeview/FileTreeView.rb', line 41 def refresh(flags={}) @root = flags[:root] if flags[:root] open_folders = flags[:open_folders] ? flags[:open_folders] : get_open_folders() model.clear @root_iter = add_file(@root, nil) open_folders([@root_iter[:path]]) open_folders(open_folders) end |
#set_show_expanders(expand = true) ⇒ Object
Sets whether or not the little arrow expanders appear net to the folders.
126 127 128 129 |
# File 'lib/treeview/FileTreeView.rb', line 126 def ( = true) self. = self.level_indentation = ? 0 : 12 end |