Centralize legacy history bridge
This commit is contained in:
@@ -10,6 +10,7 @@
|
||||
#include "app_core/document_recording.h"
|
||||
#include "app_core/document_route.h"
|
||||
#include "app_core/document_session.h"
|
||||
#include "legacy_history_services.h"
|
||||
#include "platform_api/platform_services.h"
|
||||
#include "renderer_gl/opengl_capabilities.h"
|
||||
|
||||
@@ -239,7 +240,7 @@ void App::open_document(std::string path)
|
||||
"It may be inaccessible or corrupted.");
|
||||
}
|
||||
});
|
||||
ActionManager::clear();
|
||||
pp::panopainter::clear_legacy_history();
|
||||
};
|
||||
if (open_plan == pp::app::DocumentOpenPlanAction::open_project_now)
|
||||
{
|
||||
|
||||
@@ -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());
|
||||
};
|
||||
|
||||
58
src/legacy_history_services.cpp
Normal file
58
src/legacy_history_services.cpp
Normal file
@@ -0,0 +1,58 @@
|
||||
#include "pch.h"
|
||||
|
||||
#include "legacy_history_services.h"
|
||||
|
||||
#include "action.h"
|
||||
|
||||
#include <limits>
|
||||
|
||||
namespace pp::panopainter {
|
||||
namespace {
|
||||
|
||||
[[nodiscard]] int saturated_history_metric(size_t value) noexcept
|
||||
{
|
||||
constexpr auto max_int = static_cast<size_t>(std::numeric_limits<int>::max());
|
||||
return value > max_int ? std::numeric_limits<int>::max() : static_cast<int>(value);
|
||||
}
|
||||
|
||||
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();
|
||||
}
|
||||
};
|
||||
|
||||
} // namespace
|
||||
|
||||
LegacyHistorySnapshot legacy_history_snapshot() noexcept
|
||||
{
|
||||
return LegacyHistorySnapshot {
|
||||
.undo_count = saturated_history_metric(ActionManager::I.m_actions.size()),
|
||||
.redo_count = saturated_history_metric(ActionManager::I.m_redos.size()),
|
||||
.memory_bytes = saturated_history_metric(ActionManager::I.m_memory),
|
||||
};
|
||||
}
|
||||
|
||||
pp::foundation::Status execute_legacy_history_plan(const pp::app::HistoryUiPlan& plan)
|
||||
{
|
||||
LegacyHistoryUiServices services;
|
||||
return pp::app::execute_history_ui_plan(plan, services);
|
||||
}
|
||||
|
||||
void clear_legacy_history() noexcept
|
||||
{
|
||||
ActionManager::clear();
|
||||
}
|
||||
|
||||
} // namespace pp::panopainter
|
||||
18
src/legacy_history_services.h
Normal file
18
src/legacy_history_services.h
Normal file
@@ -0,0 +1,18 @@
|
||||
#pragma once
|
||||
|
||||
#include "app_core/history_ui.h"
|
||||
#include "foundation/result.h"
|
||||
|
||||
namespace pp::panopainter {
|
||||
|
||||
struct LegacyHistorySnapshot {
|
||||
int undo_count = 0;
|
||||
int redo_count = 0;
|
||||
int memory_bytes = 0;
|
||||
};
|
||||
|
||||
[[nodiscard]] LegacyHistorySnapshot legacy_history_snapshot() noexcept;
|
||||
[[nodiscard]] pp::foundation::Status execute_legacy_history_plan(const pp::app::HistoryUiPlan& plan);
|
||||
void clear_legacy_history() noexcept;
|
||||
|
||||
} // namespace pp::panopainter
|
||||
@@ -7,8 +7,8 @@
|
||||
|
||||
#include "app_core/canvas_hotkey.h"
|
||||
#include "app_core/canvas_tool_ui.h"
|
||||
#include "app_core/history_ui.h"
|
||||
#include "app.h"
|
||||
#include "legacy_history_services.h"
|
||||
#include "log.h"
|
||||
#include "node_canvas.h"
|
||||
#include "node_image_texture.h"
|
||||
@@ -103,24 +103,6 @@ public:
|
||||
}
|
||||
};
|
||||
|
||||
class LegacyNodeCanvasHistoryServices final : public pp::app::HistoryUiServices {
|
||||
public:
|
||||
void invoke_undo() override
|
||||
{
|
||||
ActionManager::undo();
|
||||
}
|
||||
|
||||
void invoke_redo() override
|
||||
{
|
||||
ActionManager::redo();
|
||||
}
|
||||
|
||||
void clear_history() override
|
||||
{
|
||||
ActionManager::clear();
|
||||
}
|
||||
};
|
||||
|
||||
class LegacyNodeCanvasHotkeyServices final : public pp::app::CanvasHotkeyServices {
|
||||
public:
|
||||
pp::foundation::Status execute_tool(const pp::app::CanvasToolPlan& plan) override
|
||||
@@ -131,8 +113,7 @@ public:
|
||||
|
||||
pp::foundation::Status execute_history(const pp::app::HistoryUiPlan& plan) override
|
||||
{
|
||||
LegacyNodeCanvasHistoryServices services;
|
||||
return pp::app::execute_history_ui_plan(plan, services);
|
||||
return pp::panopainter::execute_legacy_history_plan(plan);
|
||||
}
|
||||
|
||||
void save_document(pp::app::DocumentSaveIntent intent) override
|
||||
@@ -191,8 +172,9 @@ pp::app::CanvasHotkeyState canvas_hotkey_state(bool mouse_focused, int touch_fin
|
||||
state.ctrl_down = App::I && App::I->keys[(int)kKey::KeyCtrl];
|
||||
state.shift_down = App::I && App::I->keys[(int)kKey::KeyShift];
|
||||
state.mouse_focused = mouse_focused;
|
||||
state.undo_count = static_cast<int>(ActionManager::I.m_actions.size());
|
||||
state.redo_count = static_cast<int>(ActionManager::I.m_redos.size());
|
||||
const auto history = pp::panopainter::legacy_history_snapshot();
|
||||
state.undo_count = history.undo_count;
|
||||
state.redo_count = history.redo_count;
|
||||
state.touch_finger_count = touch_finger_count;
|
||||
return state;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user