Added implementation for ListElementAddCommand and ListElementRemoveCommand
This commit is contained in:
parent
80db641b6f
commit
85cc97ca27
|
@ -24,6 +24,9 @@ of DigiPen Institute of Technology is prohibited.
|
|||
|
||||
namespace SHADE
|
||||
{
|
||||
/*---------------------------------------------------------------------------------*/
|
||||
/* UndoRedoStack - Properties */
|
||||
/*---------------------------------------------------------------------------------*/
|
||||
bool UndoRedoStack::UndoActionPresent::get()
|
||||
{
|
||||
return commandStack->Count > 0 && latestActionIndex >= 0;
|
||||
|
@ -34,6 +37,9 @@ namespace SHADE
|
|||
return latestActionIndex >= 0 && latestActionIndex < commandStack->Count - 1;
|
||||
}
|
||||
|
||||
/*---------------------------------------------------------------------------------*/
|
||||
/* UndoRedoStack - Usage Functions */
|
||||
/*---------------------------------------------------------------------------------*/
|
||||
void UndoRedoStack::Add(ICommand^ command)
|
||||
{
|
||||
// Erase any other actions ahead of the current action
|
||||
|
@ -69,6 +75,9 @@ namespace SHADE
|
|||
++latestActionIndex;
|
||||
}
|
||||
|
||||
/*---------------------------------------------------------------------------------*/
|
||||
/* FieldChangeCommand - Constructor */
|
||||
/*---------------------------------------------------------------------------------*/
|
||||
FieldChangeCommand::FieldChangeCommand(System::Object^ obj, System::Reflection::FieldInfo^ field, System::Object^ newData, System::Object^ oldData)
|
||||
: objectToChange { obj }
|
||||
, field { field }
|
||||
|
@ -76,6 +85,9 @@ namespace SHADE
|
|||
, oldData { oldData }
|
||||
{}
|
||||
|
||||
/*---------------------------------------------------------------------------------*/
|
||||
/* FieldChangeCommand - ICommand Functions */
|
||||
/*---------------------------------------------------------------------------------*/
|
||||
bool FieldChangeCommand::Execute()
|
||||
{
|
||||
if (field && objectToChange)
|
||||
|
@ -117,14 +129,20 @@ namespace SHADE
|
|||
return false;
|
||||
}
|
||||
|
||||
/*---------------------------------------------------------------------------------*/
|
||||
/* ListElementChangeCommand - Constructor */
|
||||
/*---------------------------------------------------------------------------------*/
|
||||
generic<typename T>
|
||||
ListElementChangeCommand<T>::ListElementChangeCommand(System::Collections::Generic::List<T>^ list, int index, T newData, T oldData)
|
||||
: list { list }
|
||||
, index { index }
|
||||
, index{ index }
|
||||
, newData { newData }
|
||||
, oldData { oldData }
|
||||
{}
|
||||
|
||||
/*---------------------------------------------------------------------------------*/
|
||||
/* ListElementChangeCommand - ICommand Functions */
|
||||
/*---------------------------------------------------------------------------------*/
|
||||
generic<typename T>
|
||||
bool ListElementChangeCommand<T>::Execute()
|
||||
{
|
||||
|
@ -166,4 +184,91 @@ namespace SHADE
|
|||
}
|
||||
}
|
||||
|
||||
/*---------------------------------------------------------------------------------*/
|
||||
/* ListElementAddCommand - ICommand Functions */
|
||||
/*---------------------------------------------------------------------------------*/
|
||||
generic<typename T>
|
||||
ListElementAddCommand<T>::ListElementAddCommand(System::Collections::Generic::List<T>^ list, int addIndex, T data)
|
||||
: list { list }
|
||||
, addIndex { addIndex }
|
||||
, data { data }
|
||||
{}
|
||||
|
||||
/*---------------------------------------------------------------------------------*/
|
||||
/* ListElementAddCommand - ICommand Functions */
|
||||
/*---------------------------------------------------------------------------------*/
|
||||
generic<typename T>
|
||||
bool ListElementAddCommand<T>::Execute()
|
||||
{
|
||||
if (list)
|
||||
{
|
||||
list->Insert(addIndex, data);
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
generic<typename T>
|
||||
bool ListElementAddCommand<T>::Unexceute()
|
||||
{
|
||||
if (list && addIndex < System::Linq::Enumerable::Count(list))
|
||||
{
|
||||
list->RemoveAt(addIndex);
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
generic<typename T>
|
||||
bool ListElementAddCommand<T>::Merge(ICommand^)
|
||||
{
|
||||
// Not allowed
|
||||
return false;
|
||||
}
|
||||
|
||||
/*---------------------------------------------------------------------------------*/
|
||||
/* ListElementRemoveCommand - ICommand Functions */
|
||||
/*---------------------------------------------------------------------------------*/
|
||||
generic<typename T>
|
||||
ListElementRemoveCommand<T>::ListElementRemoveCommand(System::Collections::Generic::List<T>^ list, int removeIndex, T data)
|
||||
: list { list }
|
||||
, removeIndex { removeIndex }
|
||||
, data { data }
|
||||
{}
|
||||
|
||||
/*---------------------------------------------------------------------------------*/
|
||||
/* ListElementRemoveCommand - ICommand Functions */
|
||||
/*---------------------------------------------------------------------------------*/
|
||||
generic<typename T>
|
||||
bool ListElementRemoveCommand<T>::Execute()
|
||||
{
|
||||
if (list && removeIndex < System::Linq::Enumerable::Count(list))
|
||||
{
|
||||
list->RemoveAt(removeIndex);
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
generic<typename T>
|
||||
bool ListElementRemoveCommand<T>::Unexceute()
|
||||
{
|
||||
if (list)
|
||||
{
|
||||
list->Insert(removeIndex, data);
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
generic<typename T>
|
||||
bool ListElementRemoveCommand<T>::Merge(ICommand^)
|
||||
{
|
||||
// Not allowed
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -72,6 +72,38 @@ namespace SHADE
|
|||
T oldData;
|
||||
};
|
||||
|
||||
generic<typename T>
|
||||
private ref class ListElementAddCommand sealed : public ICommand
|
||||
{
|
||||
public:
|
||||
ListElementAddCommand(System::Collections::Generic::List<T>^ list, int addIndex, T data);
|
||||
|
||||
bool Execute() override;
|
||||
bool Unexceute() override;
|
||||
bool Merge(ICommand^ command) override;
|
||||
|
||||
private:
|
||||
System::Collections::Generic::List<T>^ list;
|
||||
int addIndex; // New index of the added element
|
||||
T data;
|
||||
};
|
||||
|
||||
generic<typename T>
|
||||
private ref class ListElementRemoveCommand sealed : public ICommand
|
||||
{
|
||||
public:
|
||||
ListElementRemoveCommand(System::Collections::Generic::List<T>^ list, int removeIndex, T data);
|
||||
|
||||
bool Execute() override;
|
||||
bool Unexceute() override;
|
||||
bool Merge(ICommand^ command) override;
|
||||
|
||||
private:
|
||||
System::Collections::Generic::List<T>^ list;
|
||||
int removeIndex; // Index of the element to remove at
|
||||
T data;
|
||||
};
|
||||
|
||||
/// <summary>
|
||||
/// Class that is able to store a stack of actions that can be done and redone.
|
||||
/// </summary>
|
||||
|
|
Loading…
Reference in New Issue