MenuItem.cs 4.5 KB

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