Module: Fzeet::ShellFileDialogMethods

Included in:
ShellFileOpenDialog, ShellFileSaveDialog, ShellFolderDialog
Defined in:
lib/fzeet/Dialog/ShellFileDialog.rb

Instance Method Summary collapse

Instance Method Details

#pathObject



13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
# File 'lib/fzeet/Dialog/ShellFileDialog.rb', line 13

def path
	result = nil

	FFI::MemoryPointer.new(:pointer) { |psi|
		next unless GetResult(psi) == Windows::S_OK

		si = Windows::ShellItem.new(psi.read_pointer)

		begin
			FFI::MemoryPointer.new(:pointer) { |pwcs|
				next unless si.GetDisplayName(Windows::SIGDN_FILESYSPATH, pwcs) == Windows::S_OK

				wcs = pwcs.read_pointer

				begin
					result = Windows.WCSTOMBS(wcs)
				ensure
					Windows.CoTaskMemFree(wcs)
				end
			}
		ensure
			si.Release
		end
	}

	result
end

#pathsObject



41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
# File 'lib/fzeet/Dialog/ShellFileDialog.rb', line 41

def paths
	result = []

	FFI::MemoryPointer.new(:pointer) { |psia|
		next unless GetResults(psia) == Windows::S_OK

		sia = Windows::ShellItemArray.new(psia.read_pointer)

		begin
			FFI::MemoryPointer.new(:ulong) { |pc|
				next unless sia.GetCount(pc) == Windows::S_OK

				pc.read_long.times { |i|
					FFI::MemoryPointer.new(:pointer) { |psi|
						next unless sia.GetItemAt(i, psi) == Windows::S_OK

						si = Windows::ShellItem.new(psi.read_pointer)

						begin
							FFI::MemoryPointer.new(:pointer) { |pwcs|
								next unless si.GetDisplayName(Windows::SIGDN_FILESYSPATH, pwcs) == Windows::S_OK

								wcs = pwcs.read_pointer

								begin
									result << Windows.WCSTOMBS(wcs)
								ensure
									Windows.CoTaskMemFree(wcs)
								end
							}
						ensure
							si.Release
						end
					}
				}
			}
		ensure
			sia.Release
		end
	}

	result
end

#Show(*args) ⇒ Object



5
6
7
8
9
10
11
# File 'lib/fzeet/Dialog/ShellFileDialog.rb', line 5

def Show(*args)
	raise "#{self}.#{__method__} failed." if
		Windows.FAILED(result = vtbl[:Show].call(self, *args)) &&
		result != Windows.HRESULT_FROM_WIN32(Windows::ERROR_CANCELLED) - 0x1_0000_0000

	result
end

#show(window = Application.window) ⇒ Object



85
86
87
# File 'lib/fzeet/Dialog/ShellFileDialog.rb', line 85

def show(window = Application.window)
	DialogResult.new((Show(window.handle) == Windows::S_OK) ? Windows::IDOK : Windows::IDCANCEL)
end