mirror of
https://github.com/geode-sdk/geode.git
synced 2024-11-23 16:07:52 -05:00
fix file open dialog default path not having a way to specify filename
This commit is contained in:
parent
deadb58b18
commit
5c9ee08922
2 changed files with 48 additions and 3 deletions
|
@ -187,6 +187,10 @@ namespace geode::utils::file {
|
||||||
);
|
);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Open a folder / file in the system's file explorer
|
||||||
|
* @param path Folder / file to open
|
||||||
|
*/
|
||||||
GEODE_DLL bool openFolder(ghc::filesystem::path const& path);
|
GEODE_DLL bool openFolder(ghc::filesystem::path const& path);
|
||||||
|
|
||||||
enum class PickMode {
|
enum class PickMode {
|
||||||
|
@ -203,10 +207,27 @@ namespace geode::utils::file {
|
||||||
std::unordered_set<std::string> files;
|
std::unordered_set<std::string> files;
|
||||||
};
|
};
|
||||||
|
|
||||||
ghc::filesystem::path defaultPath;
|
/**
|
||||||
|
* On PickMode::SaveFile and PickMode::OpenFile, last item is assumed
|
||||||
|
* to be a filename, unless it points to an extant directory.
|
||||||
|
* On PickMode::OpenFolder, path is treated as leading up to a directory
|
||||||
|
*/
|
||||||
|
std::optional<ghc::filesystem::path> defaultPath;
|
||||||
|
/**
|
||||||
|
* File extension filters to show on the file picker
|
||||||
|
*/
|
||||||
std::vector<Filter> filters;
|
std::vector<Filter> filters;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Prompt the user to pick a file using the system's file system picker
|
||||||
|
* @param mode Type of file selection prompt to show
|
||||||
|
* @param options Picker options
|
||||||
|
*/
|
||||||
GEODE_DLL Result<ghc::filesystem::path> pickFile(PickMode mode, FilePickOptions const& options);
|
GEODE_DLL Result<ghc::filesystem::path> pickFile(PickMode mode, FilePickOptions const& options);
|
||||||
|
/**
|
||||||
|
* Prompt the user to pick a bunch of files for opening using the system's file system picker
|
||||||
|
* @param options Picker options
|
||||||
|
*/
|
||||||
GEODE_DLL Result<std::vector<ghc::filesystem::path>> pickFiles(FilePickOptions const& options);
|
GEODE_DLL Result<std::vector<ghc::filesystem::path>> pickFiles(FilePickOptions const& options);
|
||||||
}
|
}
|
||||||
|
|
|
@ -125,6 +125,14 @@ static bool setDefaultPath(
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static bool setDefaultFile(
|
||||||
|
IFileDialog* dialog,
|
||||||
|
ghc::filesystem::path const& fileName
|
||||||
|
) {
|
||||||
|
dialog->SetFileName(fileName.wstring().c_str());
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
template<class T>
|
template<class T>
|
||||||
struct Holder {
|
struct Holder {
|
||||||
T m_deallocator;
|
T m_deallocator;
|
||||||
|
@ -173,9 +181,25 @@ Result<> nfdPick(
|
||||||
if (!addFiltersToDialog(dialog, options.filters)) {
|
if (!addFiltersToDialog(dialog, options.filters)) {
|
||||||
return Err("Unable to add filters to dialog");
|
return Err("Unable to add filters to dialog");
|
||||||
}
|
}
|
||||||
if (!setDefaultPath(dialog, options.defaultPath)) {
|
if (options.defaultPath && options.defaultPath.value().wstring().size()) {
|
||||||
|
ghc::filesystem::path path = options.defaultPath.value();
|
||||||
|
if (mode == NFDMode::OpenFile || mode == NFDMode::SaveFile) {
|
||||||
|
if (!ghc::filesystem::exists(path) || !ghc::filesystem::is_directory(path)) {
|
||||||
|
if (path.has_filename()) {
|
||||||
|
setDefaultFile(dialog, path.filename());
|
||||||
|
}
|
||||||
|
if (path.has_parent_path()) {
|
||||||
|
path = path.parent_path();
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
path = "";
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (path.wstring().size() && !setDefaultPath(dialog, path)) {
|
||||||
return Err("Unable to set default path to dialog");
|
return Err("Unable to set default path to dialog");
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
if (mode == NFDMode::OpenFiles) {
|
if (mode == NFDMode::OpenFiles) {
|
||||||
DWORD flags;
|
DWORD flags;
|
||||||
|
|
Loading…
Reference in a new issue