BsMenuItemManager.h 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  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. * @param separator Should the separator be inserted before the menu item.
  34. *
  35. * @return True if the method has a MenuItem attribute. If false is returned output parameters
  36. * from this method are undefined.
  37. */
  38. bool parseMenuItemMethod(MonoMethod* method, WString& path, ShortcutKey& shortcut, INT32& priority, bool& separator) const;
  39. /**
  40. * @brief Triggered when one of the managed menu items is clicked.
  41. *
  42. * @param method Managed method that the MenuItem is referencing.
  43. */
  44. static void menuItemCallback(MonoMethod* method);
  45. ScriptAssemblyManager& mScriptObjectManager;
  46. HEvent mDomainLoadedConn;
  47. MonoClass* mMenuItemAttribute;
  48. MonoField* mPathField;
  49. MonoField* mShortcutField;
  50. MonoField* mPriorityField;
  51. MonoField* mSeparatorField;
  52. Vector<GUIMenuItem*> mMenuItems;
  53. };
  54. }