51 lines
1.4 KiB
C++
51 lines
1.4 KiB
C++
#pragma once
|
|
|
|
#include <filesystem>
|
|
#include <string>
|
|
#include <vector>
|
|
|
|
namespace izo {
|
|
|
|
enum class DialogStatus {
|
|
Selected,
|
|
Cancelled,
|
|
Error,
|
|
};
|
|
|
|
struct FileFilter {
|
|
std::string name;
|
|
// Glob patterns, for example {"*.png", "*.jpg"}.
|
|
std::vector<std::string> patterns;
|
|
};
|
|
|
|
struct DialogOptions {
|
|
std::string title;
|
|
std::filesystem::path initialPath;
|
|
std::vector<FileFilter> filters;
|
|
bool allowMultiple = false;
|
|
bool showHidden = false;
|
|
};
|
|
|
|
struct DialogResult {
|
|
DialogStatus status = DialogStatus::Cancelled;
|
|
std::vector<std::filesystem::path> paths;
|
|
std::string errorMessage;
|
|
|
|
explicit operator bool() const noexcept { return status == DialogStatus::Selected; }
|
|
};
|
|
|
|
// These calls block until the user closes the native desktop dialog.
|
|
DialogResult OpenFile(const DialogOptions& options = {});
|
|
DialogResult SaveFile(const DialogOptions& options = {});
|
|
DialogResult PickFolder(const DialogOptions& options = {});
|
|
|
|
// Opens a file/folder using the operating system's registered default handler.
|
|
// Returns false and optionally fills errorMessage if launching it failed.
|
|
bool OpenPath(const std::filesystem::path& path, std::string* errorMessage = nullptr);
|
|
|
|
// Opens the containing file manager and selects path when the platform supports it.
|
|
bool RevealInFileManager(const std::filesystem::path& path,
|
|
std::string* errorMessage = nullptr);
|
|
|
|
} // namespace izo
|