Class: VR::FileTreeView
- Includes:
- GladeGUI
- 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 GladeGUI
Attributes included from ViewCommon
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 included from GladeGUI
#buttonCancel__clicked, #extract_key, #fill_control, #get_control_value, #get_glade_active_record, #get_glade_all, #get_glade_variables, included, #load_glade, #parse_signals, #set_drag_drop, #set_glade_active_record, #set_glade_all, #set_glade_hash, #set_glade_variables, #show_glade, #try_to_select_text_in_combobox, #window1__destroy, #window1__key_press_event
Methods inherited from TreeView
Methods included from ViewCommon
#col_attr, #column, #delete_selected, #each_renderer, #each_row, #flatten_hash, #get_iter, #id, #load_columns, #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.
20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 |
# File 'lib/treeview/FileTreeView.rb', line 20 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) col_visible( :path => false, :sort_on => false, :empty => false) self.headers_visible = false @icons = File.directory?(icon_path) ? IconHash.new(icon_path) : nil # parse_signals() #fix this! Subclasses may call twice! 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)] } self.visible = true # necessary! 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.
8 9 10 |
# File 'lib/treeview/FileTreeView.rb', line 8 def glob @glob end |
#root ⇒ Object
Returns the value of attribute root.
8 9 10 |
# File 'lib/treeview/FileTreeView.rb', line 8 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…
12 13 14 |
# File 'lib/treeview/FileTreeView.rb', line 12 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.
106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 |
# File 'lib/treeview/FileTreeView.rb', line 106 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
74 75 76 77 78 79 80 81 |
# File 'lib/treeview/FileTreeView.rb', line 74 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.
86 87 88 89 90 |
# File 'lib/treeview/FileTreeView.rb', line 86 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.
137 138 139 |
# File 'lib/treeview/FileTreeView.rb', line 137 def get_selected_path() selection.selected ? selection.selected[id(:path)] : nil end |
#open_folders(folder_paths) ⇒ Object
Opens a list of folders.
94 95 96 97 98 99 100 101 102 |
# File 'lib/treeview/FileTreeView.rb', line 94 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.
45 46 47 48 49 50 51 52 |
# File 'lib/treeview/FileTreeView.rb', line 45 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.
130 131 132 133 |
# File 'lib/treeview/FileTreeView.rb', line 130 def ( = true) self. = self.level_indentation = ? 0 : 12 end |