Class: VR::FileTreeView
Overview
Constant Summary
collapse
- FILETREEVIEW_GTYPE =
self.name.split(":").collect {|x| x.empty? ? nil : x}.compact.join("_")
Constants inherited
from TreeView
TreeView::TREEVIEW_GTYPE
Instance Method Summary
collapse
Methods inherited from TreeView
#add_row
Methods included from ViewCommon
#col_attr, #column, #each_renderer, #each_row, #flatten_hash, #id, #load_columns, #method_missing, #ren_attr, #renderer, #selected_rows, #turn_on_comboboxes, #vr_row
Constructor Details
#initialize(icon_path = nil, width = nil, height = nil) ⇒ FileTreeView
11
12
13
14
15
16
17
|
# File 'lib/treeview/FileTreeView.rb', line 11
def initialize(icon_path = nil, width = nil, height = nil) super(:file => {:pix => Gdk::Pixbuf, :file_name => String}, :path => String, :modified_date => VR::DateCol, :sort_on => String)
col_visible( :path => false, :modified_date => false, :sort_on => false)
self. = false
model.set_sort_column_id(id(:sort_on))
@icons = File.directory?(icon_path.to_s) ? VR::IconHash.new(icon_path,width,height) : nil
end
|
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
in the class VR::ViewCommon
Instance Method Details
#add_file(fn, parent) ⇒ Object
64
65
66
67
68
69
70
71
72
73
74
75
76
|
# File 'lib/treeview/FileTreeView.rb', line 64
def add_file(fn, parent)
fn.gsub!("\\", "/")
child = model.append(parent)
if @root_dir == fn && @icons.get_icon("x.project")
child[id(:pix)] = @icons.get_icon("x.project")
else
child[id(:pix)] = @icons.get_icon(File.directory?(fn) ? "x.folder" : fn)
end
child[id(:file_name)] = File.basename(fn)
child[id(:path)] = fn
child[id(:sort_on)] = (File.directory?(fn) ? "0" : "1") + child[id(:file_name)]
return child
end
|
#delete_selected ⇒ Object
85
|
# File 'lib/treeview/FileTreeView.rb', line 85
def delete_selected() self.model.remove(selection.selected) if selection.selected end
|
#file_name(iter) ⇒ Object
80
|
# File 'lib/treeview/FileTreeView.rb', line 80
def file_name(iter) iter ? iter[id(:path)] : nil end
|
#folder?(iter) ⇒ Boolean
79
|
# File 'lib/treeview/FileTreeView.rb', line 79
def folder?(iter) iter[id(:sort_on)][0,1] == "0" end
|
#get_iter_from_path(fn) ⇒ Object
55
56
57
58
59
60
61
62
|
# File 'lib/treeview/FileTreeView.rb', line 55
def get_iter_from_path(fn)
model.each do | model, path, iter|
if iter[id(:path)] == fn
return iter
end
end
return false
end
|
#get_open_folders ⇒ Object
19
20
21
22
23
|
# File 'lib/treeview/FileTreeView.rb', line 19
def get_open_folders()
expanded = []
map_expanded_rows {|view, path| expanded << model.get_iter(path)[id(:path)] }
return expanded
end
|
#get_selected_file_name ⇒ Object
81
82
83
|
# File 'lib/treeview/FileTreeView.rb', line 81
def get_selected_file_name()
selection.selected ? selection.selected[id(:file_name)] : nil
end
|
#get_selected_path ⇒ Object
84
|
# File 'lib/treeview/FileTreeView.rb', line 84
def get_selected_path() (selection.selected ? selection.selected[id(:path)] : nil) end
|
#insert(fn) ⇒ Object
46
47
48
49
50
51
52
53
|
# File 'lib/treeview/FileTreeView.rb', line 46
def insert(fn) fn.gsub!("\\", "/")
return if not File.exists?(fn) or get_iter_from_path(fn) or not fn.match(/^#{model.iter_first[id(:path)]}/)
if not parent_iter = get_iter_from_path(File.dirname(fn))
parent_iter = insert(File.dirname(fn))
end
return add_file(fn, parent_iter)
end
|
#open_folders(folder_paths) ⇒ Object
25
26
27
28
29
30
31
32
|
# File 'lib/treeview/FileTreeView.rb', line 25
def open_folders(folder_paths)
collapse_all
model.each do |model, path, iter|
if folder_paths.include?(iter[id(:path)])
expand_row(path, false)
end
end
end
|
#refresh(root = Dir.pwd, glob = File.join(root, "**","*")) ⇒ Object
34
35
36
37
38
39
40
41
42
43
44
|
# File 'lib/treeview/FileTreeView.rb', line 34
def refresh(root = Dir.pwd, glob = File.join(root, "**","*"))
@root_dir = root
expanded_folders = get_open_folders()
self.model.clear
add_file(root, nil)
Dir.glob(glob).each do |fn|
insert(fn)
end
open_folders(expanded_folders)
self.expand_row(self.model.iter_first.path, false)
end
|