BsCmdInputFieldValueChange.h 937 B

1234567891011121314151617181920212223242526272829303132333435363738394041
  1. #pragma once
  2. #include "BsEditorPrerequisites.h"
  3. #include "BsEditorCommand.h"
  4. #include "BsUndoRedo.h"
  5. namespace BansheeEngine
  6. {
  7. template <class InputFieldType, class ValueType>
  8. class CmdInputFieldValueChange : public EditorCommand
  9. {
  10. public:
  11. static void execute(InputFieldType* inputField, const ValueType& value)
  12. {
  13. CmdInputFieldValueChange* command = new (bs_alloc<CmdInputFieldValueChange>()) CmdInputFieldValueChange(inputField, value);
  14. UndoRedo::instance().registerCommand(command);
  15. command->commit();
  16. }
  17. void commit()
  18. {
  19. mInputField->setValue(mNewValue);
  20. }
  21. void revert()
  22. {
  23. mInputField->setValue(mOldValue);
  24. }
  25. private:
  26. friend class UndoRedo;
  27. CmdInputFieldValueChange(InputFieldType* inputField, const ValueType& value)
  28. :mInputField(inputField), mOldValue(inputField->getValue()), mNewValue(value)
  29. { }
  30. ValueType mOldValue;
  31. ValueType mNewValue;
  32. InputFieldType* mInputField;
  33. };
  34. }