Make document session history effects explicit
This commit is contained in:
@@ -1 +1,62 @@
|
||||
#include "app_core/document_session.h"
|
||||
|
||||
namespace pp::app {
|
||||
namespace {
|
||||
|
||||
[[nodiscard]] constexpr HistoryUiPlan make_history_clear_effect() noexcept
|
||||
{
|
||||
HistoryUiPlan plan;
|
||||
plan.operation = HistoryUiOperation::clear;
|
||||
plan.clears_history = true;
|
||||
plan.updates_memory_label = true;
|
||||
return plan;
|
||||
}
|
||||
|
||||
[[nodiscard]] constexpr HistoryUiPlan make_history_no_op_effect() noexcept
|
||||
{
|
||||
HistoryUiPlan plan;
|
||||
plan.operation = HistoryUiOperation::clear;
|
||||
plan.no_op = true;
|
||||
return plan;
|
||||
}
|
||||
|
||||
} // namespace
|
||||
|
||||
HistoryUiPlan plan_document_open_history(const DocumentOpenRoute& route) noexcept
|
||||
{
|
||||
return route.kind == DocumentOpenKind::open_project
|
||||
? make_history_clear_effect()
|
||||
: make_history_no_op_effect();
|
||||
}
|
||||
|
||||
HistoryUiPlan plan_close_request_history(CloseRequestDecision) noexcept
|
||||
{
|
||||
return make_history_no_op_effect();
|
||||
}
|
||||
|
||||
HistoryUiPlan plan_document_save_history(DocumentSaveDecision) noexcept
|
||||
{
|
||||
return make_history_no_op_effect();
|
||||
}
|
||||
|
||||
HistoryUiPlan plan_document_workflow_history(DocumentWorkflowDecision) noexcept
|
||||
{
|
||||
return make_history_no_op_effect();
|
||||
}
|
||||
|
||||
HistoryUiPlan plan_document_file_save_history(const DocumentFileSavePlan&) noexcept
|
||||
{
|
||||
return make_history_no_op_effect();
|
||||
}
|
||||
|
||||
HistoryUiPlan plan_document_version_save_history(const DocumentVersionTarget&) noexcept
|
||||
{
|
||||
return make_history_no_op_effect();
|
||||
}
|
||||
|
||||
HistoryUiPlan plan_new_document_history(const NewDocumentPlan&) noexcept
|
||||
{
|
||||
return make_history_clear_effect();
|
||||
}
|
||||
|
||||
} // namespace pp::app
|
||||
|
||||
@@ -2,6 +2,7 @@
|
||||
|
||||
#include "app_core/app_dialog.h"
|
||||
#include "app_core/document_route.h"
|
||||
#include "app_core/history_ui.h"
|
||||
#include "foundation/result.h"
|
||||
|
||||
#include <array>
|
||||
@@ -144,6 +145,14 @@ public:
|
||||
virtual void prompt_overwrite_new_document(const NewDocumentPlan& plan) = 0;
|
||||
};
|
||||
|
||||
[[nodiscard]] HistoryUiPlan plan_document_open_history(const DocumentOpenRoute& route) noexcept;
|
||||
[[nodiscard]] HistoryUiPlan plan_close_request_history(CloseRequestDecision decision) noexcept;
|
||||
[[nodiscard]] HistoryUiPlan plan_document_save_history(DocumentSaveDecision decision) noexcept;
|
||||
[[nodiscard]] HistoryUiPlan plan_document_workflow_history(DocumentWorkflowDecision decision) noexcept;
|
||||
[[nodiscard]] HistoryUiPlan plan_document_file_save_history(const DocumentFileSavePlan& plan) noexcept;
|
||||
[[nodiscard]] HistoryUiPlan plan_document_version_save_history(const DocumentVersionTarget& target) noexcept;
|
||||
[[nodiscard]] HistoryUiPlan plan_new_document_history(const NewDocumentPlan& plan) noexcept;
|
||||
|
||||
[[nodiscard]] inline AppMessageDialogPlan plan_document_session_prompt(
|
||||
DocumentSessionPromptKind kind,
|
||||
std::string_view document_name = {})
|
||||
|
||||
@@ -2,10 +2,10 @@
|
||||
|
||||
#include "legacy_document_open_services.h"
|
||||
|
||||
#include "action.h"
|
||||
#include "app.h"
|
||||
#include "legacy_brush_package_import_services.h"
|
||||
#include "legacy_canvas_view_services.h"
|
||||
#include "legacy_history_services.h"
|
||||
#include "legacy_ui_overlay_services.h"
|
||||
#include "log.h"
|
||||
#include "node_panel_brush.h"
|
||||
@@ -14,6 +14,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 open_legacy_project(App& app, const pp::app::DocumentOpenRoute& route)
|
||||
{
|
||||
app.doc_name = route.name;
|
||||
@@ -41,7 +65,10 @@ void open_legacy_project(App& app, const pp::app::DocumentOpenRoute& route)
|
||||
"It may be inaccessible or corrupted.");
|
||||
}
|
||||
});
|
||||
pp::panopainter::clear_legacy_history();
|
||||
const auto history_status = apply_document_history(pp::app::plan_document_open_history(route));
|
||||
if (!history_status.ok()) {
|
||||
LOG("Project open history effect failed: %s", history_status.message);
|
||||
}
|
||||
}
|
||||
|
||||
class LegacyDocumentOpenServices final : public pp::app::DocumentOpenServices {
|
||||
|
||||
@@ -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(
|
||||
|
||||
Reference in New Issue
Block a user