Make document session history effects explicit

This commit is contained in:
2026-06-12 19:16:24 +02:00
parent a4cc251c68
commit 34a9e91099
5 changed files with 247 additions and 4 deletions

View File

@@ -2,11 +2,11 @@
#include "legacy_document_session_services.h"
#include "action.h"
#include "app.h"
#include "legacy_app_dialog_services.h"
#include "legacy_document_canvas_services.h"
#include "legacy_canvas_view_services.h"
#include "legacy_history_services.h"
#include "legacy_ui_overlay_services.h"
#include "node_dialog_open.h"
@@ -15,6 +15,30 @@
namespace pp::panopainter {
namespace {
class LegacyDocumentHistoryServices final : public pp::app::HistoryUiServices {
public:
void invoke_undo() override
{
ActionManager::undo();
}
void invoke_redo() override
{
ActionManager::redo();
}
void clear_history() override
{
ActionManager::clear();
}
};
pp::foundation::Status apply_document_history(const pp::app::HistoryUiPlan& plan)
{
LegacyDocumentHistoryServices services;
return pp::app::execute_history_ui_plan(plan, services);
}
void log_legacy_document_save_snapshot(
const char* context,
const pp::app::DocumentCanvasSaveSnapshotReport& report)
@@ -110,7 +134,10 @@ void create_legacy_new_document(
const auto reset_status = execute_legacy_canvas_camera_reset(app);
if (!reset_status.ok())
LOG("New document camera reset failed: %s", reset_status.message);
pp::panopainter::clear_legacy_history();
const auto history_status = apply_document_history(pp::app::plan_new_document_history(plan));
if (!history_status.ok()) {
LOG("New document history effect failed: %s", history_status.message);
}
app.layers->add_layer("Default", false, true);
@@ -158,6 +185,10 @@ void save_legacy_document_file(
const pp::app::DocumentFileSavePlan& plan,
const std::shared_ptr<NodeDialogSave>& dialog)
{
const auto history_status = apply_document_history(pp::app::plan_document_file_save_history(plan));
if (!history_status.ok()) {
LOG("Document file save history effect failed: %s", history_status.message);
}
project_save_after_snapshot(app, plan.target.path);
app.doc_name = plan.target.name;
app.doc_path = plan.target.path;
@@ -208,6 +239,10 @@ public:
void save_document_version(const pp::app::DocumentVersionTarget& target) override
{
const auto history_status = apply_document_history(pp::app::plan_document_version_save_history(target));
if (!history_status.ok()) {
LOG("Document version history effect failed: %s", history_status.message);
}
app_.doc_name = target.name;
app_.doc_path = target.path;
app_.canvas->m_canvas->m_unsaved = true;
@@ -229,10 +264,20 @@ public:
void request_close_now() override
{
const auto history_status = apply_document_history(
pp::app::plan_close_request_history(pp::app::CloseRequestDecision::close_now));
if (!history_status.ok()) {
LOG("Close request history effect failed: %s", history_status.message);
}
}
void show_unsaved_close_prompt() override
{
const auto history_status = apply_document_history(
pp::app::plan_close_request_history(pp::app::CloseRequestDecision::show_unsaved_prompt));
if (!history_status.ok()) {
LOG("Close prompt history effect failed: %s", history_status.message);
}
auto* app = &app_;
auto* dialog_already_opened = &dialog_already_opened_;
auto m = pp::panopainter::create_legacy_app_message_dialog(
@@ -264,16 +309,31 @@ public:
void show_save_dialog() override
{
const auto history_status = apply_document_history(
pp::app::plan_document_save_history(pp::app::DocumentSaveDecision::show_save_dialog));
if (!history_status.ok()) {
LOG("Save dialog history effect failed: %s", history_status.message);
}
app_.dialog_save();
}
void save_existing_document() override
{
const auto history_status = apply_document_history(
pp::app::plan_document_save_history(pp::app::DocumentSaveDecision::save_existing));
if (!history_status.ok()) {
LOG("Save existing history effect failed: %s", history_status.message);
}
project_save_after_snapshot(app_);
}
void save_document_version() override
{
const auto history_status = apply_document_history(
pp::app::plan_document_save_history(pp::app::DocumentSaveDecision::save_version));
if (!history_status.ok()) {
LOG("Save version history effect failed: %s", history_status.message);
}
app_.dialog_save_ver();
}
@@ -291,11 +351,23 @@ public:
void continue_workflow_now() override
{
const auto history_status = apply_document_history(
pp::app::plan_document_workflow_history(
pp::app::DocumentWorkflowDecision::continue_now));
if (!history_status.ok()) {
LOG("Workflow continue history effect failed: %s", history_status.message);
}
action_();
}
void prompt_save_before_continue() override
{
const auto history_status = apply_document_history(
pp::app::plan_document_workflow_history(
pp::app::DocumentWorkflowDecision::prompt_save_before_continue));
if (!history_status.ok()) {
LOG("Workflow prompt history effect failed: %s", history_status.message);
}
auto m = pp::panopainter::create_legacy_app_message_dialog(
app_,
pp::app::plan_document_session_prompt(