Class: FileTreeStore
- Inherits:
-
ActiveWindow::ActiveTreeStore
- Object
- Gtk::TreeStore
- ActiveWindow::ActiveTreeStore
- FileTreeStore
- Defined in:
- lib/file_tree_store.rb
Instance Attribute Summary collapse
-
#excludes ⇒ Object
readonly
Returns the value of attribute excludes.
Instance Method Summary collapse
- #add_path(path, parent = nil) ⇒ Object
- #exclude!(new_exclude) ⇒ Object
-
#excludes?(path) ⇒ Boolean
Path ends with a node name contained in the exclude list.
-
#initialize ⇒ FileTreeStore
constructor
A new instance of FileTreeStore.
- #refresh_path(path) ⇒ Object
- #remove_path(file_path) ⇒ Object
Methods inherited from ActiveWindow::ActiveTreeStore
#initial_add_in_progress?, #initial_adding
Methods included from ActiveWindow::TreeStoreExtentions
#add, #apply_to_tree, #get_object, included, #populate, #refresh
Constructor Details
#initialize ⇒ FileTreeStore
Returns a new instance of FileTreeStore.
14 15 16 17 18 19 20 21 |
# File 'lib/file_tree_store.rb', line 14 def initialize super @excludes ||= [] set_sort_column_id self.class.column_id[:sort] ActiveWindow::Signal.on_file_modified { |path| refresh_path(path) } ActiveWindow::Signal.on_file_created { |path| add_path(path) } ActiveWindow::Signal.on_file_deleted { |path| remove_path(path) } end |
Instance Attribute Details
#excludes ⇒ Object (readonly)
Returns the value of attribute excludes.
13 14 15 |
# File 'lib/file_tree_store.rb', line 13 def excludes @excludes end |
Instance Method Details
#add_path(path, parent = nil) ⇒ Object
23 24 25 26 27 28 29 30 31 32 33 34 35 |
# File 'lib/file_tree_store.rb', line 23 def add_path(path, parent=nil) unless excludes?(File.(path)) file = ListedFile.create(:full_path => path) iter = add file, parent || find_by_full_path( File.dirname(path) ) if file.directory? file.children_paths.each do |child| add_path(child, iter) end end end rescue ArgumentError => e STDERR.puts e. end |
#exclude!(new_exclude) ⇒ Object
70 71 72 |
# File 'lib/file_tree_store.rb', line 70 def exclude!(new_exclude) excludes << new_exclude.chomp.strip end |
#excludes?(path) ⇒ Boolean
Path ends with a node name contained in the exclude list
66 67 68 |
# File 'lib/file_tree_store.rb', line 66 def excludes?(path) excludes.any? {|f| path[-(f.size+1)..-1] == "/#{f}" } end |
#refresh_path(path) ⇒ Object
37 38 39 40 41 42 43 44 45 46 47 48 |
# File 'lib/file_tree_store.rb', line 37 def refresh_path(path) if iter = find_by_full_path(path) update_iter_from_object(iter, iter[OBJECT]) if iter[OBJECT].directory? each do |iter| if iter[FULL_PATH].start_with?(path) refresh_path iter[FULL_PATH] end end end end end |
#remove_path(file_path) ⇒ Object
50 51 52 53 54 55 56 57 58 59 60 61 62 63 |
# File 'lib/file_tree_store.rb', line 50 def remove_path(file_path) if has_full_path?(file_path) to_remove = [] each do |model,path,iter| if iter[FULL_PATH].starts_with?(file_path) to_remove << reference_for(iter) end end to_remove.each do |element| i = get_iter(element.path) remove(i) if i end end end |