[UI] Implement Type::kDirectory in Win32FilePicker
This commit is contained in:
parent
e3425b242e
commit
d36c3975d8
|
@ -113,8 +113,6 @@ Win32FilePicker::~Win32FilePicker() = default;
|
||||||
bool Win32FilePicker::Show(Window* parent_window) {
|
bool Win32FilePicker::Show(Window* parent_window) {
|
||||||
// TODO(benvanik): FileSaveDialog.
|
// TODO(benvanik): FileSaveDialog.
|
||||||
assert_true(mode() == Mode::kOpen);
|
assert_true(mode() == Mode::kOpen);
|
||||||
// TODO(benvanik): folder dialogs.
|
|
||||||
assert_true(type() == Type::kFile);
|
|
||||||
|
|
||||||
Microsoft::WRL::ComPtr<IFileDialog> file_dialog;
|
Microsoft::WRL::ComPtr<IFileDialog> file_dialog;
|
||||||
HRESULT hr =
|
HRESULT hr =
|
||||||
|
@ -134,37 +132,41 @@ bool Win32FilePicker::Show(Window* parent_window) {
|
||||||
if (!SUCCEEDED(hr)) {
|
if (!SUCCEEDED(hr)) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
// FOS_PICKFOLDERS
|
|
||||||
// FOS_FILEMUSTEXIST
|
// FOS_FILEMUSTEXIST
|
||||||
// FOS_PATHMUSTEXIST
|
// FOS_PATHMUSTEXIST
|
||||||
flags |= FOS_FORCEFILESYSTEM;
|
flags |= FOS_FORCEFILESYSTEM;
|
||||||
if (multi_selection()) {
|
if (multi_selection()) {
|
||||||
flags |= FOS_ALLOWMULTISELECT;
|
flags |= FOS_ALLOWMULTISELECT;
|
||||||
}
|
}
|
||||||
|
if (type() == Type::kDirectory) {
|
||||||
|
flags |= FOS_PICKFOLDERS;
|
||||||
|
}
|
||||||
hr = file_dialog->SetOptions(flags);
|
hr = file_dialog->SetOptions(flags);
|
||||||
if (!SUCCEEDED(hr)) {
|
if (!SUCCEEDED(hr)) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Set the file types to display only. Notice that this is a 1-based array.
|
if (type() == Type::kFile) {
|
||||||
std::vector<std::pair<std::u16string, std::u16string>> file_pairs;
|
// Set the file types to display only. Notice that this is a 1-based array.
|
||||||
std::vector<COMDLG_FILTERSPEC> file_types;
|
std::vector<std::pair<std::u16string, std::u16string>> file_pairs;
|
||||||
for (const auto& extension : this->extensions()) {
|
std::vector<COMDLG_FILTERSPEC> file_types;
|
||||||
const auto& file_pair =
|
for (const auto& extension : this->extensions()) {
|
||||||
file_pairs.emplace_back(std::move(xe::to_utf16(extension.first)),
|
const auto& file_pair =
|
||||||
std::move(xe::to_utf16(extension.second)));
|
file_pairs.emplace_back(std::move(xe::to_utf16(extension.first)),
|
||||||
file_types.push_back(
|
std::move(xe::to_utf16(extension.second)));
|
||||||
{(LPCWSTR)file_pair.first.c_str(), (LPCWSTR)file_pair.second.c_str()});
|
file_types.push_back({(LPCWSTR)file_pair.first.c_str(),
|
||||||
}
|
(LPCWSTR)file_pair.second.c_str()});
|
||||||
hr = file_dialog->SetFileTypes(static_cast<UINT>(file_types.size()),
|
}
|
||||||
file_types.data());
|
hr = file_dialog->SetFileTypes(static_cast<UINT>(file_types.size()),
|
||||||
if (!SUCCEEDED(hr)) {
|
file_types.data());
|
||||||
return false;
|
if (!SUCCEEDED(hr)) {
|
||||||
}
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
hr = file_dialog->SetFileTypeIndex(1);
|
hr = file_dialog->SetFileTypeIndex(1);
|
||||||
if (!SUCCEEDED(hr)) {
|
if (!SUCCEEDED(hr)) {
|
||||||
return false;
|
return false;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Create an event handling object, and hook it up to the dialog.
|
// Create an event handling object, and hook it up to the dialog.
|
||||||
|
|
Loading…
Reference in New Issue