BsMenuItemManager.h 1.7 KB

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