Commit d0a1bdca authored by Gauthier Quesnel's avatar Gauthier Quesnel
Browse files

gui: improve file dialog API

parent a0e0de77
...@@ -368,8 +368,11 @@ struct file_dialog ...@@ -368,8 +368,11 @@ struct file_dialog
file_dialog fd; file_dialog fd;
// static const char8_t* filters[] = { u8".irt", nullptr };
bool bool
load_file_dialog(std::filesystem::path& out) load_file_dialog(std::filesystem::path& out,
const char* title,
const char8_t** filters)
{ {
if (fd.current.empty()) { if (fd.current.empty()) {
fd.fill_drives(); fd.fill_drives();
...@@ -381,7 +384,7 @@ load_file_dialog(std::filesystem::path& out) ...@@ -381,7 +384,7 @@ load_file_dialog(std::filesystem::path& out)
std::filesystem::path next; std::filesystem::path next;
bool res = false; bool res = false;
if (ImGui::BeginPopupModal("Select file path to load")) { if (ImGui::BeginPopupModal(title)) {
bool path_click = false; bool path_click = false;
fd.show_drives(&path_click, &next); fd.show_drives(&path_click, &next);
...@@ -442,7 +445,6 @@ load_file_dialog(std::filesystem::path& out) ...@@ -442,7 +445,6 @@ load_file_dialog(std::filesystem::path& out)
if (path_click) { if (path_click) {
fd.paths.clear(); fd.paths.clear();
static const char8_t* filters[] = { u8".irt", nullptr };
fd.extension_filters = filters; fd.extension_filters = filters;
fd.file_filters = nullptr; fd.file_filters = nullptr;
...@@ -484,8 +486,11 @@ load_file_dialog(std::filesystem::path& out) ...@@ -484,8 +486,11 @@ load_file_dialog(std::filesystem::path& out)
return res; return res;
} }
// static const char8_t* filters[] = { u8".irt", nullptr };
bool bool
save_file_dialog(std::filesystem::path& out) save_file_dialog(std::filesystem::path& out,
const char* title,
const char8_t** filters)
{ {
if (fd.current.empty()) { if (fd.current.empty()) {
fd.fill_drives(); fd.fill_drives();
...@@ -504,7 +509,7 @@ save_file_dialog(std::filesystem::path& out) ...@@ -504,7 +509,7 @@ save_file_dialog(std::filesystem::path& out)
std::filesystem::path next; std::filesystem::path next;
bool res = false; bool res = false;
if (ImGui::BeginPopupModal("Select file path to save")) { if (ImGui::BeginPopupModal(title)) {
bool path_click = false; bool path_click = false;
fd.show_drives(&path_click, &next); fd.show_drives(&path_click, &next);
...@@ -573,7 +578,6 @@ save_file_dialog(std::filesystem::path& out) ...@@ -573,7 +578,6 @@ save_file_dialog(std::filesystem::path& out)
if (path_click) { if (path_click) {
fd.paths.clear(); fd.paths.clear();
static const char8_t* filters[] = { u8".irt", nullptr };
fd.extension_filters = filters; fd.extension_filters = filters;
fd.file_filters = nullptr; fd.file_filters = nullptr;
......
...@@ -30,10 +30,14 @@ get_executable_directory(); ...@@ -30,10 +30,14 @@ get_executable_directory();
/* Filesytem dialog box */ /* Filesytem dialog box */
bool bool
load_file_dialog(std::filesystem::path& out); load_file_dialog(std::filesystem::path& out,
const char* title,
const char8_t** filters);
bool bool
save_file_dialog(std::filesystem::path& out); save_file_dialog(std::filesystem::path& out,
const char* title,
const char8_t** filters);
bool bool
select_directory_dialog(std::filesystem::path& out); select_directory_dialog(std::filesystem::path& out);
......
...@@ -2468,8 +2468,11 @@ editor::show_editor() noexcept ...@@ -2468,8 +2468,11 @@ editor::show_editor() noexcept
} }
if (show_load_file_dialog) { if (show_load_file_dialog) {
ImGui::OpenPopup("Select file path to load"); const char* title = "Select file path to load";
if (load_file_dialog(path)) { const char8_t* filters[] = { u8".irt", nullptr };
ImGui::OpenPopup(title);
if (load_file_dialog(path, title, filters)) {
show_load_file_dialog = false; show_load_file_dialog = false;
log_w.log( log_w.log(
5, "Load file from %s: ", (const char*)path.u8string().c_str()); 5, "Load file from %s: ", (const char*)path.u8string().c_str());
...@@ -2492,8 +2495,11 @@ editor::show_editor() noexcept ...@@ -2492,8 +2495,11 @@ editor::show_editor() noexcept
if (show_save_file_dialog) { if (show_save_file_dialog) {
if (sim.models.size()) { if (sim.models.size()) {
ImGui::OpenPopup("Select file path to save"); const char* title = "Select file path to save";
if (save_file_dialog(path)) { const char8_t* filters[] = { u8".irt", nullptr };
ImGui::OpenPopup(title);
if (save_file_dialog(path, title, filters)) {
show_save_file_dialog = false; show_save_file_dialog = false;
log_w.log( log_w.log(
5, "Save file to %s\n", (const char*)path.u8string().c_str()); 5, "Save file to %s\n", (const char*)path.u8string().c_str());
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment