Class: VR::FileTreeView::IconHash

Inherits:
Hash
  • Object
show all
Defined in:
lib/treeview/FileTreeView.rb

Overview

Creates a Hash of icons for VR::FileTreeView. The folder should contain .png files that correspond to file extensions. For example, rb.png would be an icon that displays next to files with an .rb extension. A file named “unknown.png” should be in the folder for file types that aren't found.

Instance Method Summary collapse

Constructor Details

#initialize(path) ⇒ IconHash

Sets the path to find the icons

Parameters:

  • path (String)

    Path to folder where icons are.



150
151
152
153
154
155
# File 'lib/treeview/FileTreeView.rb', line 150

def initialize(path)
  Dir.glob(path + "/*.png").each do |f|
    ext = File.basename(f, ".png")
    self[ext] = Gdk::Pixbuf.new(f)
  end
end

Instance Method Details

#get_icon(file_name) ⇒ Object



157
158
159
160
# File 'lib/treeview/FileTreeView.rb', line 157

def get_icon(file_name)
  ext = File.extname(file_name).gsub(".", "")
  self.has_key?(ext) ? self[ext] : self["unknown"] 
end