Centralize legacy history bridge

This commit is contained in:
2026-06-03 20:45:33 +02:00
parent 6945ce7e23
commit d1bd4e9b46
9 changed files with 104 additions and 53 deletions

View File

@@ -16,9 +16,9 @@
#include "app_core/document_import.h"
#include "app_core/file_menu.h"
#include "app_core/app_status.h"
#include "app_core/history_ui.h"
#include "app_core/main_toolbar.h"
#include "app_core/tools_menu.h"
#include "legacy_history_services.h"
#include "settings.h"
#include "serializer.h"
#include "font.h"
@@ -440,28 +440,9 @@ public:
}
private:
class LegacyHistoryUiServices final : public pp::app::HistoryUiServices {
public:
void invoke_undo() override
{
ActionManager::undo();
}
void invoke_redo() override
{
ActionManager::redo();
}
void clear_history() override
{
ActionManager::clear();
}
};
void execute_history_plan(const pp::app::HistoryUiPlan& plan)
{
LegacyHistoryUiServices services;
const auto status = pp::app::execute_history_ui_plan(plan, services);
const auto status = pp::panopainter::execute_legacy_history_plan(plan);
if (!status.ok())
LOG("History action failed: %s", status.message);
}
@@ -888,9 +869,10 @@ void App::init_toolbar_main()
if (auto* button = layout[main_id]->find<NodeButtonCustom>("btn-undo"))
{
button->on_click = [this, button](Node*) {
const auto history = pp::panopainter::legacy_history_snapshot();
const auto plan = pp::app::plan_main_toolbar_command(
pp::app::MainToolbarCommand::undo,
static_cast<int>(ActionManager::I.m_actions.size()));
history.undo_count);
if (plan)
execute_main_toolbar_plan(*this, plan.value());
};
@@ -898,10 +880,11 @@ void App::init_toolbar_main()
if (auto* button = layout[main_id]->find<NodeButtonCustom>("btn-redo"))
{
button->on_click = [this, button](Node*) {
const auto history = pp::panopainter::legacy_history_snapshot();
const auto plan = pp::app::plan_main_toolbar_command(
pp::app::MainToolbarCommand::redo,
0,
static_cast<int>(ActionManager::I.m_redos.size()));
history.redo_count);
if (plan)
execute_main_toolbar_plan(*this, plan.value());
};
@@ -909,11 +892,12 @@ void App::init_toolbar_main()
if (auto* button = layout[main_id]->find<NodeButtonCustom>("btn-clean-memory"))
{
button->on_click = [this](Node*) {
const auto history = pp::panopainter::legacy_history_snapshot();
const auto plan = pp::app::plan_main_toolbar_command(
pp::app::MainToolbarCommand::clear_history,
static_cast<int>(ActionManager::I.m_actions.size()),
static_cast<int>(ActionManager::I.m_redos.size()),
static_cast<int>(ActionManager::I.m_memory));
history.undo_count,
history.redo_count,
history.memory_bytes);
if (plan)
execute_main_toolbar_plan(*this, plan.value());
};