Restore undo/redo
Signed-off-by: carlitosan <82187351+carlitosan@users.noreply.github.com>
This commit is contained in:
@@ -252,11 +252,16 @@ namespace ScriptCanvasEditor
|
||||
AZ::u64 entityId =
|
||||
aznumeric_caster(ScriptCanvas::MathNodeUtilities::GetRandomIntegral<AZ::s64>(1, std::numeric_limits<AZ::s64>::max()));
|
||||
entity->SetId(AZ::EntityId(entityId));
|
||||
entity->Init();
|
||||
entity->Activate();
|
||||
|
||||
auto graph = entity->FindComponent<ScriptCanvasEditor::Graph>();
|
||||
graph->MarkOwnership(*scriptCanvasData);
|
||||
|
||||
entity->Init();
|
||||
entity->Activate();
|
||||
}
|
||||
else
|
||||
{
|
||||
return AZ::Failure(AZStd::string("Loaded script canvas file was missing a necessary Entity."));
|
||||
}
|
||||
|
||||
return AZ::Success(ScriptCanvasEditor::SourceHandle(scriptCanvasData, path));
|
||||
|
||||
@@ -278,8 +278,6 @@ namespace ScriptCanvasEditor
|
||||
|
||||
EditorGraphNotificationBus::Handler::BusDisconnect();
|
||||
EditorGraphNotificationBus::Handler::BusConnect(m_scriptCanvasId);
|
||||
|
||||
m_undoHelper = AZStd::make_unique<UndoHelper>(*this);
|
||||
}
|
||||
|
||||
ScriptCanvasEditor::Widget::CanvasWidget* ScriptCanvasMemoryAsset::CreateView(QWidget* /*parent*/)
|
||||
|
||||
@@ -9,13 +9,19 @@
|
||||
#include "ScriptCanvasUndoHelper.h"
|
||||
#include "ScriptCanvasMemoryAsset.h"
|
||||
#include <Undo/ScriptCanvasGraphCommand.h>
|
||||
#include <ScriptCanvas/Components/EditorGraph.h>
|
||||
|
||||
namespace ScriptCanvasEditor
|
||||
{
|
||||
UndoHelper::UndoHelper(ScriptCanvasMemoryAsset& memoryAsset)
|
||||
: m_memoryAsset(memoryAsset)
|
||||
UndoHelper::UndoHelper()
|
||||
: m_undoState(this)
|
||||
{
|
||||
UndoRequestBus::Handler::BusConnect(memoryAsset.GetScriptCanvasId());
|
||||
}
|
||||
|
||||
UndoHelper::UndoHelper(SourceHandle memoryAsset)
|
||||
: m_undoState(this)
|
||||
{
|
||||
SetSource(memoryAsset);
|
||||
}
|
||||
|
||||
UndoHelper::~UndoHelper()
|
||||
@@ -23,15 +29,21 @@ namespace ScriptCanvasEditor
|
||||
UndoRequestBus::Handler::BusDisconnect();
|
||||
}
|
||||
|
||||
void UndoHelper::SetSource(SourceHandle source)
|
||||
{
|
||||
m_memoryAsset = source;
|
||||
UndoRequestBus::Handler::BusConnect(source.Get()->GetScriptCanvasId());
|
||||
}
|
||||
|
||||
ScriptCanvasEditor::UndoCache* UndoHelper::GetSceneUndoCache()
|
||||
{
|
||||
return m_memoryAsset.GetUndoState()->m_undoCache.get();
|
||||
return m_undoState.m_undoCache.get();
|
||||
}
|
||||
|
||||
ScriptCanvasEditor::UndoData UndoHelper::CreateUndoData()
|
||||
{
|
||||
AZ::EntityId graphCanvasGraphId = m_memoryAsset.GetGraphId();
|
||||
ScriptCanvas::ScriptCanvasId scriptCanvasId = m_memoryAsset.GetScriptCanvasId();
|
||||
AZ::EntityId graphCanvasGraphId = m_memoryAsset.Get()->GetGraphCanvasGraphId();
|
||||
ScriptCanvas::ScriptCanvasId scriptCanvasId = m_memoryAsset.Get()->GetScriptCanvasId();
|
||||
|
||||
GraphCanvas::GraphModelRequestBus::Event(graphCanvasGraphId, &GraphCanvas::GraphModelRequests::OnSaveDataDirtied, graphCanvasGraphId);
|
||||
|
||||
@@ -56,17 +68,17 @@ namespace ScriptCanvasEditor
|
||||
|
||||
void UndoHelper::BeginUndoBatch(AZStd::string_view label)
|
||||
{
|
||||
m_memoryAsset.GetUndoState()->BeginUndoBatch(label);
|
||||
m_undoState.BeginUndoBatch(label);
|
||||
}
|
||||
|
||||
void UndoHelper::EndUndoBatch()
|
||||
{
|
||||
m_memoryAsset.GetUndoState()->EndUndoBatch();
|
||||
m_undoState.EndUndoBatch();
|
||||
}
|
||||
|
||||
void UndoHelper::AddUndo(AzToolsFramework::UndoSystem::URSequencePoint* sequencePoint)
|
||||
{
|
||||
if (SceneUndoState* sceneUndoState = m_memoryAsset.GetUndoState())
|
||||
if (SceneUndoState* sceneUndoState = &m_undoState)
|
||||
{
|
||||
if (!sceneUndoState->m_currentUndoBatch)
|
||||
{
|
||||
@@ -105,7 +117,7 @@ namespace ScriptCanvasEditor
|
||||
{
|
||||
AZ_PROFILE_FUNCTION(ScriptCanvas);
|
||||
|
||||
SceneUndoState* sceneUndoState = m_memoryAsset.GetUndoState();
|
||||
SceneUndoState* sceneUndoState = &m_undoState;
|
||||
if (sceneUndoState)
|
||||
{
|
||||
AZ_Warning("Script Canvas", !sceneUndoState->m_currentUndoBatch, "Script Canvas Editor has an open undo batch when performing a redo operation");
|
||||
@@ -125,7 +137,7 @@ namespace ScriptCanvasEditor
|
||||
{
|
||||
AZ_PROFILE_FUNCTION(ScriptCanvas);
|
||||
|
||||
SceneUndoState* sceneUndoState = m_memoryAsset.GetUndoState();
|
||||
SceneUndoState* sceneUndoState = &m_undoState;
|
||||
if (sceneUndoState)
|
||||
{
|
||||
AZ_Warning("Script Canvas", !sceneUndoState->m_currentUndoBatch, "Script Canvas Editor has an open undo batch when performing a redo operation");
|
||||
@@ -143,7 +155,7 @@ namespace ScriptCanvasEditor
|
||||
|
||||
void UndoHelper::Reset()
|
||||
{
|
||||
if (SceneUndoState* sceneUndoState = m_memoryAsset.GetUndoState())
|
||||
if (SceneUndoState* sceneUndoState = &m_undoState)
|
||||
{
|
||||
AZ_Warning("Script Canvas", !sceneUndoState->m_currentUndoBatch, "Script Canvas Editor has an open undo batch when resetting the undo stack");
|
||||
sceneUndoState->m_undoStack->Reset();
|
||||
@@ -162,17 +174,23 @@ namespace ScriptCanvasEditor
|
||||
|
||||
bool UndoHelper::CanUndo() const
|
||||
{
|
||||
return m_memoryAsset.GetUndoState()->m_undoStack->CanUndo();
|
||||
return m_undoState.m_undoStack->CanUndo();
|
||||
}
|
||||
|
||||
bool UndoHelper::CanRedo() const
|
||||
{
|
||||
return m_memoryAsset.GetUndoState()->m_undoStack->CanRedo();
|
||||
return m_undoState.m_undoStack->CanRedo();
|
||||
}
|
||||
|
||||
void UndoHelper::OnUndoStackChanged()
|
||||
{
|
||||
UndoNotificationBus::Broadcast(&UndoNotifications::OnCanUndoChanged, m_undoState.m_undoStack->CanUndo());
|
||||
UndoNotificationBus::Broadcast(&UndoNotifications::OnCanRedoChanged, m_undoState.m_undoStack->CanRedo());
|
||||
}
|
||||
|
||||
void UndoHelper::UpdateCache()
|
||||
{
|
||||
ScriptCanvas::ScriptCanvasId scriptCanvasId = m_memoryAsset.GetScriptCanvasId();
|
||||
ScriptCanvas::ScriptCanvasId scriptCanvasId = m_memoryAsset.Get()->GetScriptCanvasId();
|
||||
|
||||
UndoCache* undoCache = nullptr;
|
||||
UndoRequestBus::EventResult(undoCache, scriptCanvasId, &UndoRequests::GetSceneUndoCache);
|
||||
|
||||
@@ -8,22 +8,27 @@
|
||||
|
||||
#pragma once
|
||||
#include <ScriptCanvas/Bus/UndoBus.h>
|
||||
#include <Editor/Undo/ScriptCanvasUndoManager.h>
|
||||
|
||||
namespace ScriptCanvasEditor
|
||||
{
|
||||
class ScriptCanvasMemoryAsset;
|
||||
|
||||
// Helper class that provides the implementation for UndoRequestBus
|
||||
class UndoHelper : UndoRequestBus::Handler
|
||||
class UndoHelper
|
||||
: public UndoRequestBus::Handler
|
||||
, public AzToolsFramework::UndoSystem::IUndoNotify
|
||||
{
|
||||
public:
|
||||
|
||||
UndoHelper(ScriptCanvasMemoryAsset& memoryAsset);
|
||||
UndoHelper();
|
||||
UndoHelper(SourceHandle source);
|
||||
~UndoHelper();
|
||||
|
||||
UndoCache* GetSceneUndoCache() override;
|
||||
UndoData CreateUndoData() override;
|
||||
|
||||
void SetSource(SourceHandle source);
|
||||
|
||||
void BeginUndoBatch(AZStd::string_view label) override;
|
||||
void EndUndoBatch() override;
|
||||
void AddUndo(AzToolsFramework::UndoSystem::URSequencePoint* seqPoint) override;
|
||||
@@ -41,6 +46,7 @@ namespace ScriptCanvasEditor
|
||||
bool CanRedo() const override;
|
||||
|
||||
private:
|
||||
void OnUndoStackChanged() override;
|
||||
|
||||
void UpdateCache();
|
||||
|
||||
@@ -51,7 +57,7 @@ namespace ScriptCanvasEditor
|
||||
};
|
||||
|
||||
Status m_status = Status::Idle;
|
||||
|
||||
ScriptCanvasMemoryAsset& m_memoryAsset;
|
||||
SceneUndoState m_undoState;
|
||||
SourceHandle m_memoryAsset;
|
||||
};
|
||||
}
|
||||
|
||||
@@ -1067,6 +1067,7 @@ namespace ScriptCanvasEditor
|
||||
void Graph::MarkOwnership(ScriptCanvas::ScriptCanvasData& owner)
|
||||
{
|
||||
m_owner = &owner;
|
||||
m_undoHelper.SetSource(SourceHandle(GetOwnership(), {}, ""));
|
||||
}
|
||||
|
||||
ScriptCanvas::DataPtr Graph::GetOwnership() const
|
||||
|
||||
@@ -34,6 +34,7 @@
|
||||
#include <GraphCanvas/Widgets/NodePropertyBus.h>
|
||||
|
||||
#include <Editor/Include/ScriptCanvas/Components/GraphUpgrade.h>
|
||||
#include <Editor/Assets/ScriptCanvasUndoHelper.h>
|
||||
|
||||
namespace ScriptCanvas
|
||||
{
|
||||
@@ -380,6 +381,7 @@ namespace ScriptCanvasEditor
|
||||
|
||||
GraphCanvas::NodeFocusCyclingHelper m_focusHelper;
|
||||
GraphStatisticsHelper m_statisticsHelper;
|
||||
UndoHelper m_undoHelper;
|
||||
|
||||
bool m_ignoreSaveRequests;
|
||||
|
||||
|
||||
@@ -11,6 +11,7 @@
|
||||
#include <AzCore/Serialization/Utils.h>
|
||||
|
||||
#include <ScriptCanvas/Core/Graph.h>
|
||||
#include <ScriptCanvas/Components/EditorGraph.h>
|
||||
#include <ScriptCanvas/Variable/VariableBus.h>
|
||||
|
||||
#include <GraphCanvas/Components/SceneBus.h>
|
||||
@@ -19,7 +20,6 @@
|
||||
|
||||
#include <Editor/Include/ScriptCanvas/Bus/EditorScriptCanvasBus.h>
|
||||
#include <Editor/Assets/ScriptCanvasAssetTrackerBus.h>
|
||||
#include <Editor/Assets/ScriptCanvasMemoryAsset.h>
|
||||
|
||||
namespace ScriptCanvasEditor
|
||||
{
|
||||
@@ -36,7 +36,7 @@ namespace ScriptCanvasEditor
|
||||
{
|
||||
}
|
||||
|
||||
void GraphItemCommand::Capture(ScriptCanvasMemoryAsset&, bool)
|
||||
void GraphItemCommand::Capture(SourceHandle&, bool)
|
||||
{
|
||||
}
|
||||
|
||||
@@ -105,10 +105,10 @@ namespace ScriptCanvasEditor
|
||||
RestoreItem(m_redoState);
|
||||
}
|
||||
|
||||
void GraphItemChangeCommand::Capture(ScriptCanvasMemoryAsset& memoryAsset, bool captureUndo)
|
||||
void GraphItemChangeCommand::Capture(SourceHandle& memoryAsset, bool captureUndo)
|
||||
{
|
||||
m_scriptCanvasId = memoryAsset.GetScriptCanvasId();
|
||||
m_graphCanvasGraphId = memoryAsset.GetGraphId();
|
||||
m_scriptCanvasId = memoryAsset.Get()->GetScriptCanvasId();
|
||||
m_graphCanvasGraphId = memoryAsset.Get()->GetGraphCanvasGraphId();
|
||||
|
||||
UndoCache* undoCache = nullptr;
|
||||
UndoRequestBus::EventResult(undoCache, m_scriptCanvasId, &UndoRequests::GetSceneUndoCache);
|
||||
@@ -204,7 +204,7 @@ namespace ScriptCanvasEditor
|
||||
RestoreItem(m_redoState);
|
||||
}
|
||||
|
||||
void GraphItemAddCommand::Capture(ScriptCanvasMemoryAsset& memoryAsset, bool)
|
||||
void GraphItemAddCommand::Capture(SourceHandle& memoryAsset, bool)
|
||||
{
|
||||
GraphItemChangeCommand::Capture(memoryAsset, false);
|
||||
}
|
||||
@@ -225,7 +225,7 @@ namespace ScriptCanvasEditor
|
||||
RestoreItem(m_redoState);
|
||||
}
|
||||
|
||||
void GraphItemRemovalCommand::Capture(ScriptCanvasMemoryAsset& memoryAsset, bool)
|
||||
void GraphItemRemovalCommand::Capture(SourceHandle& memoryAsset, bool)
|
||||
{
|
||||
GraphItemChangeCommand::Capture(memoryAsset, true);
|
||||
}
|
||||
|
||||
@@ -46,7 +46,7 @@ namespace ScriptCanvasEditor
|
||||
void Undo() override;
|
||||
void Redo() override;
|
||||
|
||||
virtual void Capture(ScriptCanvasMemoryAsset& memoryAsset, bool captureUndo);
|
||||
virtual void Capture(SourceHandle& memoryAsset, bool captureUndo);
|
||||
|
||||
bool Changed() const override;
|
||||
|
||||
@@ -76,7 +76,7 @@ namespace ScriptCanvasEditor
|
||||
|
||||
void Undo() override;
|
||||
void Redo() override;
|
||||
void Capture(ScriptCanvasMemoryAsset& memoryAsset, bool captureUndo) override;
|
||||
void Capture(SourceHandle& memoryAsset, bool captureUndo) override;
|
||||
|
||||
void RestoreItem(const AZStd::vector<AZ::u8>& restoreBuffer) override;
|
||||
|
||||
@@ -103,7 +103,7 @@ namespace ScriptCanvasEditor
|
||||
void Undo() override;
|
||||
void Redo() override;
|
||||
|
||||
void Capture(ScriptCanvasMemoryAsset& memoryAsset, bool captureUndo) override;
|
||||
void Capture(SourceHandle& memoryAsset, bool captureUndo) override;
|
||||
|
||||
protected:
|
||||
GraphItemAddCommand(const GraphItemAddCommand&) = delete;
|
||||
@@ -124,7 +124,7 @@ namespace ScriptCanvasEditor
|
||||
void Undo() override;
|
||||
void Redo() override;
|
||||
|
||||
void Capture(ScriptCanvasMemoryAsset& memoryAsset, bool captureUndo) override;
|
||||
void Capture(SourceHandle& memoryAsset, bool captureUndo) override;
|
||||
|
||||
protected:
|
||||
GraphItemRemovalCommand(const GraphItemRemovalCommand&) = delete;
|
||||
|
||||
@@ -28,9 +28,9 @@ namespace ScriptCanvasEditor
|
||||
// SceneUndoState
|
||||
|
||||
SceneUndoState::SceneUndoState(AzToolsFramework::UndoSystem::IUndoNotify* undoNotify)
|
||||
: m_undoStack(AZStd::make_unique<AzToolsFramework::UndoSystem::UndoStack>(c_undoLimit, undoNotify))
|
||||
, m_undoCache(AZStd::make_unique<UndoCache>())
|
||||
{
|
||||
m_undoStack = AZStd::make_unique<AzToolsFramework::UndoSystem::UndoStack>(c_undoLimit, undoNotify);
|
||||
m_undoCache = AZStd::make_unique<UndoCache>();
|
||||
}
|
||||
|
||||
void SceneUndoState::BeginUndoBatch(AZStd::string_view label)
|
||||
|
||||
@@ -61,6 +61,7 @@ namespace ScriptCanvasEditor
|
||||
public:
|
||||
AZ_CLASS_ALLOCATOR(SceneUndoState, AZ::SystemAllocator, 0);
|
||||
|
||||
SceneUndoState() = default;
|
||||
SceneUndoState(AzToolsFramework::UndoSystem::IUndoNotify* undoNotify);
|
||||
~SceneUndoState();
|
||||
|
||||
|
||||
Reference in New Issue
Block a user