Class: Fzeet::FolderDialog

Inherits:
CommonDialog show all
Defined in:
lib/fzeet/windows/comdlg/FileDialog.rb

Constant Summary collapse

DialogStruct =
Windows::BROWSEINFO
HookProc =
-> *args { CommonDialog::HookProc.(*args.unshift(DialogStruct)) }

Constants included from WindowMethods

WindowMethods::EnumChildProc

Instance Attribute Summary

Attributes inherited from CommonDialog

#struct

Instance Method Summary collapse

Methods inherited from CommonDialog

crackMessage, #hookProc, #on

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

#toggle

Constructor Details

#initialize(opts = {}) ⇒ FolderDialog

Returns a new instance of FolderDialog.



198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
# File 'lib/fzeet/windows/comdlg/FileDialog.rb', line 198

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

#pathObject



220
# File 'lib/fzeet/windows/comdlg/FileDialog.rb', line 220

def path; @path && @path.dup end

#show(window = Application.window) ⇒ Object



222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
# File 'lib/fzeet/windows/comdlg/FileDialog.rb', line 222

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