MenuItem.cs 4.5 KB

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