BsMenuItemManager.h 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  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 "Utility/BsModule.h"
  6. namespace bs
  7. {
  8. /** @addtogroup EditorScript
  9. * @{
  10. */
  11. /** Tracks main menu items that are registered in managed code using the MenuItem attribute. */
  12. class BS_SCR_BED_EXPORT MenuItemManager : public Module<MenuItemManager>
  13. {
  14. public:
  15. MenuItemManager(ScriptAssemblyManager& scriptObjectManager);
  16. ~MenuItemManager();
  17. private:
  18. /** Removes all managed menu items from the main menu. */
  19. void clearMenuItems();
  20. /**
  21. * Reloads all assembly types and attempts to find uses of MenuItem. Old menu items are cleared and new are added.
  22. */
  23. void reloadAssemblyData();
  24. /**
  25. * Parse the provided method and detect whether it has a MenuItem attribute. If it has extract needed data from it.
  26. *
  27. * @param[in] method Managed method to parse.
  28. * @param[in] path Output path defined in the MenuItem attribute.
  29. * @param[in] shortcut Shortcut key defined in the MenuItem attribute.
  30. * @param[in] priority Menu item priority defined in the MenuItem attribute.
  31. * @param[in] separator Should the separator be inserted before the menu item.
  32. * @return True if the method has a MenuItem attribute. If false is returned output parameters
  33. * from this method are undefined.
  34. */
  35. bool parseMenuItemMethod(MonoMethod* method, String& path, ShortcutKey& shortcut, INT32& priority, bool& separator) const;
  36. /**
  37. * Triggered when one of the managed menu items is clicked.
  38. *
  39. * @param[in] method Managed method that the MenuItem is referencing.
  40. */
  41. static void menuItemCallback(MonoMethod* method);
  42. ScriptAssemblyManager& mScriptObjectManager;
  43. HEvent mDomainLoadedConn;
  44. MonoClass* mMenuItemAttribute;
  45. MonoField* mPathField;
  46. MonoField* mShortcutField;
  47. MonoField* mPriorityField;
  48. MonoField* mSeparatorField;
  49. Vector<GUIMenuItem*> mMenuItems;
  50. };
  51. /** @} */
  52. }