Class: Iup::FileDialog

Inherits:
Dialog show all
Defined in:
lib/wrapped/filedialog.rb

Overview

A predefined modal dialog for selecting files or a directory.

Example

The following opens a "save file" dialog, filtered on Ruby files.

filedlg = Iup::FileDialog.new do |d|
 d.dialogtype = 'save'
 d.title = 'File Save'
 d.filter = '*.rb'
 d.filterinfo = 'Ruby Files'
end
filedlg.popup(300, 300)

Note that popup must be used to show the dialog.

Also see: Iup.get_file

Instance Attribute Summary

Attributes inherited from Widget

#handle

Instance Method Summary collapse

Methods inherited from Dialog

#background, #border, #clientoffset, #clientsize, #close_cb=, #cursor, #cursor=, #defaultenter, #defaultenter=, #defaultesc, #defaultesc=, #expand, #fullscreen, #hide, #icon, #icon=, #map, #maxbox, #menu, #menu=, #menubox, #minbox, #modal, #parentdialog, #parentdialog=, #placement, #popup, #rastersize, #resize, #resize_cb=, #screenposition, #show, #show_cb=, #shrink, #startfocus, #startfocus=, #tip, #title

Methods included from AttributeReference

#attribute_reference

Methods included from DragDropAttributes

#dragbegin_cb=, #dragdata_cb=, #dragdatasize_cb=, #dragend_cb=, #dragsource, #dragsourcemove, #dragtypes, #dropdata_cb=, #dropmotion_cb=, #droptarget, #droptypes

Methods included from AttributeBuilders

#define_attribute, #define_id_attribute, #define_id_reader, #define_id_writer, #define_property_attribute, #define_property_reader, #define_property_writer, #define_reader, #define_writer

Methods inherited from Widget

#active, #assign_handle, #bgcolor, #destroy, #enterwindow_cb=, #fgcolor, #font, #getfocus_cb=, #help_cb=, #k_any=, #killfocus_cb=, #leavewindow_cb=, #map_cb=, #maxsize, #minsize, #open_controls, #size, #unmap_cb=, #visible, #wid, #zorder

Methods included from CallbackSetter

#define_callback

Constructor Details

#initialize {|_self| ... } ⇒ FileDialog

Creates a new dialog. If a block is given, the new instance is yielded to it.

Yields:

  • (_self)

Yield Parameters:



51
52
53
54
55
56
# File 'lib/wrapped/filedialog.rb', line 51

def initialize 
  @handle = IupLib.IupFileDlg

  # run any provided block on instance, to set up further attributes
  yield self if block_given?
end

Instance Method Details

#allownewObject

:attr: allownew If set, indicates if non-existent filenames are accepted. Values as 'yes' / 'no' - defaults to 'no'.



64
# File 'lib/wrapped/filedialog.rb', line 64

define_attribute :allownew

#dialogtypeObject

:attr: dialogtype 'open' / 'save' / 'dir'



69
# File 'lib/wrapped/filedialog.rb', line 69

define_attribute :dialogtype

#directoryObject

:attr: directory Initial directory



74
# File 'lib/wrapped/filedialog.rb', line 74

define_attribute :directory

#extfilterObject

:attr: extfilter Defines filters, e.g. "Text files|*.txt;*.doc|Image files|*.gif;*.jpg;*.bmp|", has priority over filterinfo and filter.



80
# File 'lib/wrapped/filedialog.rb', line 80

define_attribute :extfilter

#fileObject

:attr: file Name of file. Will be used instead of dictionary if it contains a complete path.



85
# File 'lib/wrapped/filedialog.rb', line 85

define_attribute :file

#file_cb=(callback) ⇒ Object

--



155
156
157
158
159
160
161
162
163
164
165
# File 'lib/wrapped/filedialog.rb', line 155

def file_cb= callback
  unless callback.arity == 2
    raise ArgumentError, 'file_cb callback must take 2 arguments, a filename, and status'
  end
  cb = Proc.new do |ih, fn_ptr, st_ptr|
    fn = FFI::Pointer.new(fn_ptr).read_string
    st = FFI::Pointer.new(st_ptr).read_string
    callback.call fn, st
  end
  define_callback cb, 'FILE_CB', :ss_i
end

#filterObject

:attr: filter Filter to use, e.g. "*.C;*.LED;test.*".



90
# File 'lib/wrapped/filedialog.rb', line 90

define_attribute :filter

#filterinfoObject

:attr: filterinfo Information about the filter, e.g. "C files".



95
# File 'lib/wrapped/filedialog.rb', line 95

define_attribute :filterinfo

#filterusedObject

:attr: filterused n, index of filter from extfilter that was used. Index counts from 1.



101
# File 'lib/wrapped/filedialog.rb', line 101

define_attribute :filterused

#multiplefilesObject

:attr: multiplefiles 'no' / 'yes', set to allow selection of multiple files.



106
# File 'lib/wrapped/filedialog.rb', line 106

define_attribute :multiplefiles

#nochangedirObject

:attr: nochangedir 'yes' / 'no', if set, restores current directory after dialog is closed.



111
# File 'lib/wrapped/filedialog.rb', line 111

define_attribute :nochangedir

#nooverwritepromptObject

:attr: nooverwriteprompt 'no' / 'yes', if set, prompts before overwriting existing files.



116
# File 'lib/wrapped/filedialog.rb', line 116

define_attribute :nooverwriteprompt

#showhiddenObject

:attr: showhidden 'no' / 'yes', if set, shows hidden files.



121
# File 'lib/wrapped/filedialog.rb', line 121

define_attribute :showhidden

#showpreviewObject

:attr: showpreview 'no' / 'yes', if set, shows a preview area for file.



126
# File 'lib/wrapped/filedialog.rb', line 126

define_attribute :showpreview

#statusObject

--



134
135
136
137
# File 'lib/wrapped/filedialog.rb', line 134

def status 
  status = IupLib.IupGetAttribute(@handle, 'STATUS').first
  status.to_i
end

#valueObject

:attr_reader: value Name of file(s) selected.



142
# File 'lib/wrapped/filedialog.rb', line 142

define_reader :value