Skip to content

Commit

Permalink
app: enable save/save as from project-window
Browse files Browse the repository at this point in the history
  • Loading branch information
quesnel committed Jan 3, 2025
1 parent 187b5f5 commit 4342a91
Show file tree
Hide file tree
Showing 4 changed files with 64 additions and 62 deletions.
56 changes: 0 additions & 56 deletions app/gui/application.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -238,12 +238,6 @@ static void application_show_menu(application& app) noexcept
if (ImGui::MenuItem("Open project"))
app.menu_load_project_file = true;

if (ImGui::MenuItem("Save project"))
app.menu_save_project_file = true;

if (ImGui::MenuItem("Save project as..."))
app.menu_save_as_project_file = true;

if (ImGui::MenuItem("Quit"))
app.menu_quit = true;

Expand Down Expand Up @@ -356,56 +350,6 @@ static void application_manage_menu_action(application& app) noexcept
app.menu_load_project_file = false;
}
}

if (app.menu_save_project_file) {
const bool have_file = !app.project_file.empty();

if (have_file) {
auto u8str = app.project_file.u8string();
auto* str = reinterpret_cast<const char*>(u8str.c_str());

if (app.mod.registred_paths.can_alloc(1)) {
auto& path = app.mod.registred_paths.alloc();
auto id = app.mod.registred_paths.get_id(path);
path.path = str;

debug::breakpoint();
project_id pj_id;
app.start_save_project(id, pj_id);
}
} else {
app.menu_save_project_file = false;
app.menu_save_as_project_file = true;
}
}

if (app.menu_save_as_project_file) {
const char* title = "Select project file path to save";
const std::u8string_view default_filename = u8"filename.irt";
const char8_t* filters[] = { u8".irt", nullptr };

ImGui::OpenPopup(title);
if (app.f_dialog.show_save_file(title, default_filename, filters)) {
if (app.f_dialog.state == file_dialog::status::ok) {
app.project_file = app.f_dialog.result;
auto u8str = app.project_file.u8string();
auto* str = reinterpret_cast<const char*>(u8str.c_str());

if (app.mod.registred_paths.can_alloc(1)) {
auto& path = app.mod.registred_paths.alloc();
auto id = app.mod.registred_paths.get_id(path);
path.path = str;

debug::breakpoint();
project_id pj_id;
app.start_save_project(id, pj_id);
}
}

app.f_dialog.clear();
app.menu_save_as_project_file = false;
}
}
}

static void application_show_windows(application& app) noexcept
Expand Down
11 changes: 6 additions & 5 deletions app/gui/application.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -611,6 +611,9 @@ struct project_window {
bool have_use_back_advance = false;
bool display_graph = true;

bool save_project_file = false;
bool save_as_project_file = false;

bool show_internal_values = false;
bool show_internal_inputs = false;
bool show_identifiers = false;
Expand Down Expand Up @@ -1063,11 +1066,9 @@ struct application {
bool show_imgui_demo = false;
bool show_implot_demo = false;

bool menu_new_project_file = false;
bool menu_load_project_file = false;
bool menu_save_project_file = false;
bool menu_save_as_project_file = false;
bool menu_quit = false;
bool menu_new_project_file = false;
bool menu_load_project_file = false;
bool menu_quit = false;

bool init() noexcept;
void show() noexcept;
Expand Down
8 changes: 8 additions & 0 deletions app/gui/project-window.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -217,6 +217,14 @@ static bool show_project_simulation_settings(application& app,
ImGui::SameLine();
HelpMarker("Display the simulation phase. Only for debug.");

const auto sz = ImGui::ComputeButtonSize(2);
if (ImGui::Button("Save", sz))
ed.save_as_project_file = true;
ImGui::SameLine();

if (ImGui::Button("Save as...", sz))
ed.save_as_project_file = true;

return up > 0;
}

Expand Down
51 changes: 50 additions & 1 deletion app/gui/simulation-editor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1169,7 +1169,7 @@ void project_window::show(application& app) noexcept
is_dock_init = true;
}

if (not ImGui::Begin(name.c_str(), &is_open)) {
if (not ImGui::Begin(name.c_str(), &is_open, ImGuiWindowFlags_MenuBar)) {
ImGui::End();
return;
}
Expand Down Expand Up @@ -1275,6 +1275,55 @@ void project_window::show(application& app) noexcept

ImGui::EndChild();
ImGui::End();

if (save_project_file) {
const bool have_file = !app.project_file.empty();

if (have_file) {
auto u8str = app.project_file.u8string();
auto* str = reinterpret_cast<const char*>(u8str.c_str());

if (app.mod.registred_paths.can_alloc(1)) {
auto& path = app.mod.registred_paths.alloc();
auto id = app.mod.registred_paths.get_id(path);
path.path = str;
save_project_file = false;
save_as_project_file = false;

app.start_save_project(id, app.pjs.get_id(*this));
}
} else {
save_project_file = false;
save_as_project_file = true;
}
}

if (save_as_project_file) {
const char* title = "Select project file path to save";
const std::u8string_view default_filename = u8"filename.irt";
const char8_t* filters[] = { u8".irt", nullptr };

ImGui::OpenPopup(title);
if (app.f_dialog.show_save_file(title, default_filename, filters)) {
if (app.f_dialog.state == file_dialog::status::ok) {
app.project_file = app.f_dialog.result;
auto u8str = app.project_file.u8string();
auto* str = reinterpret_cast<const char*>(u8str.c_str());

if (app.mod.registred_paths.can_alloc(1)) {
auto& path = app.mod.registred_paths.alloc();
auto id = app.mod.registred_paths.get_id(path);
path.path = str;

app.start_save_project(id, app.pjs.get_id(*this));
}
}
save_project_file = false;
save_as_project_file = false;

app.f_dialog.clear();
}
}
}

} // namesapce irt

0 comments on commit 4342a91

Please sign in to comment.