BsMenuItemManager.h 2.2 KB

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