Extract document-session workflow prompt helper

This commit is contained in:
2026-06-15 22:06:21 +02:00
parent eaa8a2fced
commit c37451e959
4 changed files with 72 additions and 18 deletions

View File

@@ -348,6 +348,30 @@ private:
App& app_;
};
void wire_prompt_save_before_continue_buttons(
App& app,
const std::shared_ptr<NodeMessageBox>& dialog,
std::function<void()> action)
{
auto* app_ptr = &app;
dialog->btn_ok->on_click = [app_ptr, dialog, action](Node*) {
project_save_after_snapshot(*app_ptr, [app_ptr, dialog, action](bool success) {
if (success)
action();
else {
const auto plan = pp::app::plan_document_session_prompt(
pp::app::DocumentSessionPromptKind::document_save_error);
app_ptr->message_box(plan.title, plan.message, plan.show_cancel);
}
});
pp::panopainter::close_legacy_dialog_node(*dialog);
};
dialog->btn_cancel->on_click = [dialog, action](Node*) {
action();
pp::panopainter::close_legacy_dialog_node(*dialog);
};
}
class LegacyDocumentWorkflowServices final : public pp::app::DocumentWorkflowServices {
public:
LegacyDocumentWorkflowServices(App& app, std::function<void()> action) noexcept
@@ -379,24 +403,7 @@ public:
app_,
pp::app::plan_document_session_prompt(
pp::app::DocumentSessionPromptKind::save_before_workflow_continue));
auto* app = &app_;
auto action = action_;
m->btn_ok->on_click = [app, m, action](Node*) {
project_save_after_snapshot(*app, [app, m, action](bool success) {
if (success)
action();
else {
const auto plan = pp::app::plan_document_session_prompt(
pp::app::DocumentSessionPromptKind::document_save_error);
app->message_box(plan.title, plan.message, plan.show_cancel);
}
});
pp::panopainter::close_legacy_dialog_node(*m);
};
m->btn_cancel->on_click = [m, action](Node*) {
action();
pp::panopainter::close_legacy_dialog_node(*m);
};
wire_prompt_save_before_continue_buttons(app_, m, action_);
}
private: