Extract history UI operation planning

This commit is contained in:
2026-06-03 11:13:57 +02:00
parent 8dc476d205
commit 58afa672c7
9 changed files with 392 additions and 7 deletions

View File

@@ -2,6 +2,7 @@
#include <cstdint>
#include "app_core/history_ui.h"
#include "app.h"
#include "log.h"
#include "node_canvas.h"
@@ -21,6 +22,20 @@ void unbind_texture_2d()
glBindTexture(pp::renderer::gl::texture_2d_target(), 0);
}
void run_history_undo_if_available()
{
const auto plan = pp::app::plan_history_undo(static_cast<int>(ActionManager::I.m_actions.size()));
if (plan && plan.value().invokes_undo)
ActionManager::undo();
}
void run_history_redo_if_available()
{
const auto plan = pp::app::plan_history_redo(static_cast<int>(ActionManager::I.m_redos.size()));
if (plan && plan.value().invokes_redo)
ActionManager::redo();
}
}
Node* NodeCanvas::clone_instantiate() const
@@ -600,8 +615,7 @@ kEventResult NodeCanvas::handle_event(Event* e)
if (ke->m_key == kKey::KeyE)
Canvas::set_mode(kCanvasMode::Erase);
if (ke->m_key == kKey::AndroidBack)
if (!ActionManager::empty())
ActionManager::undo();
run_history_undo_if_available();
if (ke->m_key == kKey::KeyAlt && m_mouse_focus)
App::I->show_cursor();
for (auto& mode : *m_canvas->m_mode)
@@ -614,7 +628,7 @@ kEventResult NodeCanvas::handle_event(Event* e)
if (ke->m_key == kKey::KeyTab)
App::I->toggle_ui();
if (ke->m_key == kKey::KeyZ && App::I->keys[(int)kKey::KeyCtrl])
App::I->keys[(int)kKey::KeyShift] ? ActionManager::redo() : ActionManager::undo();
App::I->keys[(int)kKey::KeyShift] ? run_history_redo_if_available() : run_history_undo_if_available();
if (ke->m_key == kKey::KeyS && App::I->keys[(int)kKey::KeyCtrl] && !App::I->keys[(int)kKey::KeyShift])
{
App::I->save_document(pp::app::DocumentSaveIntent::save);
@@ -654,7 +668,7 @@ kEventResult NodeCanvas::handle_event(Event* e)
break;
case kEventType::TouchTap:
if (te->m_finger_count == 2)
ActionManager::undo();
run_history_undo_if_available();
break;
default:
return kEventResult::Available;