MenuItem.cs 4.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667
  1. using System;
  2. using BansheeEngine;
  3. namespace BansheeEditor
  4. {
  5. /// <summary>
  6. /// Adds an entry to the main menu bar. Clicking on that entry will trigger the method the attribute is attached to.
  7. /// The method must be static, have no parameters or return values otherwise the attribute will be ignored.
  8. /// </summary>
  9. [AttributeUsage(AttributeTargets.Method)]
  10. public sealed class MenuItem : Attribute
  11. {
  12. /// <summary>
  13. /// Creates a new menu item attribute with a shortcut. Pressing the shortcut key or selecting the item in the menu
  14. /// will trigger the menu item callback.
  15. /// </summary>
  16. /// <param name="path">Path that determines where in the menu to add the element. All path elements must be
  17. /// separated by /, e.g. "View/Toolbars/Find"</param>
  18. /// <param name="shortcutModifier">Optional shortcut modifier that needs to be pressed along with the shortcut
  19. /// button in order to trigger the shortcut.</param>
  20. /// <param name="shortcutKey">Shortcut key that will trigger the shortcut.</param>
  21. /// <param name="priority">Priority determines the position of the menu item relative to its siblings.
  22. /// Higher priority means it will be placed earlier in the menu.</param>
  23. /// <param name="separator">Determines should a separator be inserted just before this element.</param>
  24. /// <param name="contextCallback">Name of a method that returns a boolean determining whether the menu item callback
  25. /// is allowed to trigger. This is useful if menu items are only valid in specific
  26. /// situations (e.g. a scene object must be selected). The method must be static,
  27. /// return a boolean value, accept no parameters and be in the same class as
  28. /// the method this attribute is attached to.</param>
  29. public MenuItem(string path, ButtonModifier shortcutModifier, ButtonCode shortcutKey, int priority = 0,
  30. bool separator = false, string contextCallback = null)
  31. {
  32. this.path = path;
  33. this.shortcut = new ShortcutKey(shortcutModifier, shortcutKey);
  34. this.priority = priority;
  35. this.separator = separator;
  36. this.contextCallback = contextCallback;
  37. }
  38. /// <summary>
  39. /// Creates a new menu item attribute. Selecting the item in the menu will trigger the menu item callback.
  40. /// </summary>
  41. /// <param name="path">Path that determines where in the menu to add the element. All path elements must be
  42. /// separated by /, e.g. "View/Toolbars/Find"</param>
  43. /// <param name="priority">Priority determines the position of the menu item relative to its siblings.
  44. /// Higher priority means it will be placed earlier in the menu.</param>
  45. /// <param name="separator">Determines should a separator be inserted just before this element.</param>
  46. /// <param name="contextCallback">Name of a method that returns a boolean determining whether the menu item callback
  47. /// is allowed to trigger. This is useful if menu items are only valid in specific
  48. /// situations (e.g. a scene object must be selected). The method must be static,
  49. /// return a boolean value, accept no parameters and be in the same class as
  50. /// the method this attribute is attached to.</param>
  51. public MenuItem(string path, int priority = 0, bool separator = false, string contextCallback = null)
  52. {
  53. this.path = path;
  54. this.priority = priority;
  55. this.separator = separator;
  56. this.contextCallback = contextCallback;
  57. }
  58. private string path;
  59. private ShortcutKey shortcut;
  60. private int priority;
  61. private bool separator;
  62. private string contextCallback;
  63. }
  64. }