Class: MittensUi::FilePicker

Inherits:
Object
  • Object
show all
Defined in:
lib/mittens_ui/file_picker.rb

Overview

A file picker dialog that allows the user to select a file. Wraps Gtk::FileDialog. Opens immediately on instantiation. The selected path is accessible via #path after the dialog closes.

Examples:

Basic usage

picker = MittensUi::FilePicker.new
puts picker.path  # => "/home/user/file.txt" or nil if cancelled

With block

MittensUi::FilePicker.new do |path|
  puts "Selected: #{path}" if path
end

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(options = {}) {|path| ... } ⇒ FilePicker

Creates a new FilePicker dialog and opens it immediately.

Parameters:

  • options (Hash) (defaults to: {})

    configuration options

Options Hash (options):

  • :title (String) — default: "Select File"

    the dialog title

Yields:

  • (path)

    optional block called with the selected path, or nil if cancelled

Yield Parameters:

  • path (String, nil)

    the selected file path



28
29
30
31
# File 'lib/mittens_ui/file_picker.rb', line 28

def initialize(options = {}, &block)
  @path = nil
  open_dialog(options, &block)
end

Instance Attribute Details

#pathObject (readonly)

Returns the value of attribute path.



20
21
22
# File 'lib/mittens_ui/file_picker.rb', line 20

def path
  @path
end