| 1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465 |
- //********************************** Banshee Engine (www.banshee3d.com) **************************************************//
- //**************** Copyright (c) 2016 Marko Pintera ([email protected]). All rights reserved. **********************//
- #pragma once
- #include "BsEditorPrerequisites.h"
- #include "BsEditorCommand.h"
- #include "BsUndoRedo.h"
- namespace BansheeEngine
- {
- /** @addtogroup UndoRedo
- * @{
- */
- /**
- * A command used for undo/redo purposes. It records a value of a GUI input field (specified by template type) and
- * allows you to apply or revert a change to that field as needed.
- */
- template <class InputFieldType, class ValueType>
- class BS_ED_EXPORT CmdInputFieldValueChange : public EditorCommand
- {
- public:
- /**
- * Creates and executes the command on the provided object and field. Automatically registers the command with
- * undo/redo system.
- *
- * @param[in] inputField Input field to modify the value on.
- * @param[in] value New value for the field.
- * @param[in] description Optional description of what exactly the command does.
- */
- static void execute(InputFieldType* inputField, const ValueType& value,
- const WString& description = StringUtil::WBLANK)
- {
- CmdInputFieldValueChange* command =
- new (bs_alloc<CmdInputFieldValueChange>()) CmdInputFieldValueChange(description, inputField, value);
- UndoRedo::instance().registerCommand(command);
- command->commit();
- }
- /** @copydoc EditorCommand::commit */
- void commit() override
- {
- mInputField->_setValue(mNewValue, true);
- }
- /** @copydoc EditorCommand::revert */
- void revert() override
- {
- mInputField->_setValue(mOldValue, true);
- }
- private:
- friend class UndoRedo;
- CmdInputFieldValueChange(const WString& description, InputFieldType* inputField, const ValueType& value)
- :EditorCommand(description), mOldValue(inputField->getValue()), mNewValue(value), mInputField(inputField)
- { }
- ValueType mOldValue;
- ValueType mNewValue;
- InputFieldType* mInputField;
- };
- /** @} */
- }
|