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.



146
147
148
149
150
151
# File 'lib/treeview/FileTreeView.rb', line 146

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

Instance Method Details

#get_icon(file_name) ⇒ Object



153
154
155
156
# File 'lib/treeview/FileTreeView.rb', line 153

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