BsManagedEditorCommand.h 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687
  1. //********************************** Banshee Engine (www.banshee3d.com) **************************************************//
  2. //**************** Copyright (c) 2016 Marko Pintera ([email protected]). All rights reserved. **********************//
  3. #pragma once
  4. #include "BsScriptEditorPrerequisites.h"
  5. #include "BsScriptObject.h"
  6. #include "BsEditorCommand.h"
  7. namespace BansheeEngine
  8. {
  9. class CmdManaged;
  10. /** @addtogroup ScriptInteropEditor
  11. * @{
  12. */
  13. /** Interop class between C++ & CLR for CmdManaged. */
  14. class BS_SCR_BED_EXPORT ScriptCmdManaged : public ScriptObject <ScriptCmdManaged>
  15. {
  16. public:
  17. SCRIPT_OBJ(EDITOR_ASSEMBLY, "BansheeEditor", "UndoableCommand")
  18. ~ScriptCmdManaged();
  19. private:
  20. friend class CmdManaged;
  21. ScriptCmdManaged(MonoObject* instance);
  22. /** Triggers the Commit() method on the managed object instance. */
  23. void triggerCommit();
  24. /** Triggers the Revert() method on the managed object instance. */
  25. void triggerRevert();
  26. /** Notifies the script instance that the underlying managed command was destroyed. */
  27. void notifyCommandDestroyed();
  28. CmdManaged* mManagedCommand;
  29. /************************************************************************/
  30. /* CLR HOOKS */
  31. /************************************************************************/
  32. static void internal_CreateInstance(MonoObject* instance);
  33. static MonoMethod* sCommitMethod;
  34. static MonoMethod* sRevertMethod;
  35. };
  36. /** @} */
  37. /** @addtogroup SBansheeEditor
  38. * @{
  39. */
  40. /**
  41. * A command used for undo/redo purposes. This particular implementation provides a generic overridable base to be
  42. * implemented by script classes.
  43. */
  44. class BS_SCR_BED_EXPORT CmdManaged : public EditorCommand
  45. {
  46. public:
  47. ~CmdManaged();
  48. /** @copydoc EditorCommand::commit */
  49. void commit() override;
  50. /** @copydoc EditorCommand::revert */
  51. void revert() override;
  52. private:
  53. friend class UndoRedo;
  54. friend class ScriptCmdManaged;
  55. CmdManaged(ScriptCmdManaged* scriptObj);
  56. /**
  57. * Notifies the command the managed script object instance it is referencing has been destroyed. Normally when this
  58. * happens the command should already be outside of the undo/redo stack, but we clear the instance just in case.
  59. */
  60. void notifyScriptInstanceDestroyed();
  61. ScriptCmdManaged* mScriptObj;
  62. };
  63. /** @} */
  64. }