Class: Fzeet::FolderDialog
- Inherits:
-
CommonDialog
- Object
- Handle
- CommonDialog
- Fzeet::FolderDialog
- Defined in:
- lib/fzeet/Dialog/FileDialog.rb
Constant Summary collapse
- DialogStruct =
Windows::BROWSEINFO
- HookProc =
-> *args { CommonDialog::HookProc.(*args.unshift(DialogStruct)) }
Constants included from WindowMethods
Instance Attribute Summary
Attributes inherited from CommonDialog
Attributes inherited from Handle
Instance Method Summary collapse
-
#initialize(opts = {}) ⇒ FolderDialog
constructor
A new instance of FolderDialog.
- #path ⇒ Object
- #show(window = Application.window) ⇒ Object
Methods inherited from CommonDialog
Methods included from WindowMethods
#[], #capture=, #capture?, #dialog=, #dialog?, #dlgmsg?, #drawMenuBar, #eachChild, #enabled=, #enabled?, #focus=, #focus?, #invalidate, #location, #location=, #long, #menu, #menu=, #message, #paint, #position, #position=, #postmsg, #question, #rect, #reframe, #sendmsg, #size, #size=, #style, #style?, #text, #text=, #textlen, #topmost=, #topmost?, #update, #visible=, #visible?, #xstyle, #xstyle?
Methods included from Toggle
Methods inherited from Handle
#attach, #detach, #dup, instance, instance?, wrap
Constructor Details
#initialize(opts = {}) ⇒ FolderDialog
Returns a new instance of FolderDialog.
88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 |
# File 'lib/fzeet/Dialog/FileDialog.rb', line 88 def initialize(opts = {}) _opts = { root: nil, displayName: nil, title: nil, flags: 0, hook: nil, param: 0, image: 0 } badopts = opts.keys - _opts.keys; raise "Bad option(s): #{badopts.join(', ')}." unless badopts.empty? _opts.merge!(opts) @struct = DialogStruct.new @struct[:ulFlags] = Fzeet.flags([:returnonlyfsdirs, :usenewui], :bif_) @struct[:lpfn] = HookProc @struct[:lParam] = object_id super() end |
Instance Method Details
#path ⇒ Object
110 |
# File 'lib/fzeet/Dialog/FileDialog.rb', line 110 def path; @path && @path.dup end |
#show(window = Application.window) ⇒ Object
112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 |
# File 'lib/fzeet/Dialog/FileDialog.rb', line 112 def show(window = Application.window) @struct[:hwndOwner] = window.handle @path = nil DialogResult.new(((pidl = Windows.SHBrowseForFolder(@struct)).null?) ? Windows::IDCANCEL : Windows::IDOK).tap { |result| next unless result.ok? FFI::MemoryPointer.new(:char, 4096) { |p| Windows.SHGetPathFromIDList(pidl, p) @path = p.read_string } } ensure Windows.CoTaskMemFree(pidl) end |