From d6764b45515465ab6a29fb6dbd0905a70a536091 Mon Sep 17 00:00:00 2001 From: Kah Wei Date: Sat, 12 Nov 2022 03:25:46 +0800 Subject: [PATCH] Added support for adding and removing elements from a list --- SHADE_Managed/src/Editor/Editor.cxx | 22 ++++++++++++++++++++-- 1 file changed, 20 insertions(+), 2 deletions(-) diff --git a/SHADE_Managed/src/Editor/Editor.cxx b/SHADE_Managed/src/Editor/Editor.cxx index d1672929..c481e0b8 100644 --- a/SHADE_Managed/src/Editor/Editor.cxx +++ b/SHADE_Managed/src/Editor/Editor.cxx @@ -181,7 +181,12 @@ namespace SHADE SHEditorUI::Text(Convert::ToNative(field->Name)); SHEditorUI::SameLine(); - SHEditorUI::Button("+"); + if (SHEditorUI::Button("+")) + { + System::Object^ obj = System::Activator::CreateInstance(listType); + iList->Add(obj); + registerUndoListAddAction(listType, iList, iList->Count - 1, obj); + } SHEditorUI::Indent(); for (int i = 0; i < iList->Count; ++i) @@ -195,7 +200,14 @@ namespace SHADE registerUndoListChangeAction(listType, iList, i, obj, oldObj); } SHEditorUI::SameLine(); - SHEditorUI::Button("-"); + if (SHEditorUI::Button("-")) + { + System::Object^ obj = iList[i]; + iList->RemoveAt(i); + registerUndoListRemoveAction(listType, iList, i, obj); + SHEditorUI::PopID(); + break; + } SHEditorUI::PopID(); } SHEditorUI::Unindent(); @@ -367,6 +379,9 @@ namespace SHADE return; actionStack.Add(gcnew ListElementAddCommand(list, index, data)); + + // Inform the C++ Undo-Redo stack + SHCommandManager::RegisterCommand(std::reinterpret_pointer_cast(std::make_shared())); } void Editor::registerUndoListRemoveAction(System::Type^ type, System::Collections::IList^ list, int index, System::Object^ data) @@ -375,6 +390,9 @@ namespace SHADE return; actionStack.Add(gcnew ListElementRemoveCommand(list, index, data)); + + // Inform the C++ Undo-Redo stack + SHCommandManager::RegisterCommand(std::reinterpret_pointer_cast(std::make_shared())); } generic