Extract app dialog and binding service seams

This commit is contained in:
2026-06-17 19:37:58 +02:00
parent 52ed7ddeb0
commit b505d9f727
19 changed files with 432 additions and 248 deletions

View File

@@ -9,27 +9,6 @@
#include "node_dialog_open.h"
#include "node_dialog_resize.h"
namespace {
void wire_document_save_dialog_buttons(
App& app,
const std::shared_ptr<NodeDialogSave>& dialog,
std::function<void()> close_dialog)
{
dialog->btn_ok->on_click = [&app, dialog](Node*)
{
const auto status = pp::panopainter::execute_legacy_document_file_save_dialog(app, dialog);
if (!status.ok())
LOG("Document file save action failed: %s", status.message);
};
dialog->btn_cancel->on_click = [close_dialog](Node*)
{
close_dialog();
};
}
} // namespace
void App::continue_document_workflow_after_optional_save(std::function<void()> action)
{
const bool has_canvas = canvas != nullptr;
@@ -46,62 +25,7 @@ void App::continue_document_workflow_after_optional_save(std::function<void()> a
void App::dialog_newdoc()
{
auto show_dialog = [this] {
auto* overlay_anchor = layout[main_id];
if (!overlay_anchor) {
LOG("New document dialog open failed: main layout anchor is missing");
return;
}
auto dialog = pp::panopainter::make_legacy_overlay_node<NodeDialogNewDoc>(*this);
dialog->input->set_text("name");
App::I->showKeyboard();
const auto overlay = pp::panopainter::open_legacy_overlay_node_with_handle(*overlay_anchor, dialog);
if (!overlay) {
App::I->hideKeyboard();
LOG("New document dialog open failed: %s", overlay.status().message);
return;
}
const auto overlay_handle = overlay.value();
const auto close_dialog = [this, overlay_anchor, overlay_handle]() {
const auto close_status =
pp::panopainter::close_legacy_overlay_node(*overlay_anchor, overlay_handle);
(void)close_status;
App::I->hideKeyboard();
};
dialog->btn_ok->on_click = [this, dialog](Node*)
{
std::string name = dialog->input->m_text;
const auto plan = pp::app::plan_new_document(
work_path,
name,
dialog->m_resolution->m_current_index,
[](const std::string& path) {
return Asset::exist(path);
});
if (!plan)
{
const bool missing_name =
plan.status().code == pp::foundation::StatusCode::invalid_argument;
message_box(
"Warning",
missing_name ? "You need to specify a name to file." : plan.status().message);
return;
}
const auto status =
pp::panopainter::execute_legacy_new_document_plan(*this, plan.value(), dialog);
if (!status.ok())
LOG("New document action failed: %s", status.message);
};
dialog->btn_cancel->on_click = [close_dialog](Node*)
{
close_dialog();
};
pp::panopainter::open_legacy_new_document_dialog(*this);
};
continue_document_workflow_after_optional_save(show_dialog);
@@ -219,35 +143,7 @@ void App::dialog_save()
}
if (canvas)
{
auto* overlay_anchor = layout[main_id];
if (!overlay_anchor) {
LOG("Save document dialog open failed: main layout anchor is missing");
return;
}
auto dialog = pp::panopainter::make_legacy_overlay_node<NodeDialogSave>(*this);
dialog->input->set_text(doc_name);
App::I->showKeyboard();
const auto overlay = pp::panopainter::open_legacy_overlay_node_with_handle(*overlay_anchor, dialog);
if (!overlay) {
App::I->hideKeyboard();
LOG("Save document dialog open failed: %s", overlay.status().message);
return;
}
const auto overlay_handle = overlay.value();
const auto close_dialog = [this, overlay_anchor, overlay_handle]() {
const auto close_status =
pp::panopainter::close_legacy_overlay_node(*overlay_anchor, overlay_handle);
(void)close_status;
App::I->hideKeyboard();
};
wire_document_save_dialog_buttons(*this, dialog, close_dialog);
}
pp::panopainter::open_legacy_document_file_save_dialog(*this);
}
void App::dialog_resize()