RAPPEL : Opération de maintenance > ForgeMIA indisponible le 20 Janvier entre 7h et 12h

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
file_dialog fd;
// static const char8_t* filters[] = { u8".irt", nullptr };
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()) {
fd.fill_drives();
......@@ -381,7 +384,7 @@ load_file_dialog(std::filesystem::path& out)
std::filesystem::path next;
bool res = false;
if (ImGui::BeginPopupModal("Select file path to load")) {
if (ImGui::BeginPopupModal(title)) {
bool path_click = false;
fd.show_drives(&path_click, &next);
......@@ -442,7 +445,6 @@ load_file_dialog(std::filesystem::path& out)
if (path_click) {
fd.paths.clear();
static const char8_t* filters[] = { u8".irt", nullptr };
fd.extension_filters = filters;
fd.file_filters = nullptr;
......@@ -484,8 +486,11 @@ load_file_dialog(std::filesystem::path& out)
return res;
}
// static const char8_t* filters[] = { u8".irt", nullptr };
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()) {
fd.fill_drives();
......@@ -504,7 +509,7 @@ save_file_dialog(std::filesystem::path& out)
std::filesystem::path next;
bool res = false;
if (ImGui::BeginPopupModal("Select file path to save")) {
if (ImGui::BeginPopupModal(title)) {
bool path_click = false;
fd.show_drives(&path_click, &next);
......@@ -573,7 +578,6 @@ save_file_dialog(std::filesystem::path& out)
if (path_click) {
fd.paths.clear();
static const char8_t* filters[] = { u8".irt", nullptr };
fd.extension_filters = filters;
fd.file_filters = nullptr;
......
......@@ -30,10 +30,14 @@ get_executable_directory();
/* Filesytem dialog box */
bool
load_file_dialog(std::filesystem::path& out);
load_file_dialog(std::filesystem::path& out,
const char* title,
const char8_t** filters);
bool
save_file_dialog(std::filesystem::path& out);
save_file_dialog(std::filesystem::path& out,
const char* title,
const char8_t** filters);
bool
select_directory_dialog(std::filesystem::path& out);
......
......@@ -2468,8 +2468,11 @@ editor::show_editor() noexcept
}
if (show_load_file_dialog) {
ImGui::OpenPopup("Select file path to load");
if (load_file_dialog(path)) {
const char* title = "Select file path to load";
const char8_t* filters[] = { u8".irt", nullptr };
ImGui::OpenPopup(title);
if (load_file_dialog(path, title, filters)) {
show_load_file_dialog = false;
log_w.log(
5, "Load file from %s: ", (const char*)path.u8string().c_str());
......@@ -2492,8 +2495,11 @@ editor::show_editor() noexcept
if (show_save_file_dialog) {
if (sim.models.size()) {
ImGui::OpenPopup("Select file path to save");
if (save_file_dialog(path)) {
const char* title = "Select file path to save";
const char8_t* filters[] = { u8".irt", nullptr };
ImGui::OpenPopup(title);
if (save_file_dialog(path, title, filters)) {
show_save_file_dialog = false;
log_w.log(
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