LibraryMenu.cs 7.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163
  1. using System.IO;
  2. using BansheeEngine;
  3. namespace BansheeEditor
  4. {
  5. /// <summary>
  6. /// Handles main menu and context menu items and callbacks for project library window.
  7. /// </summary>
  8. internal static class LibraryMenu
  9. {
  10. /// <summary>
  11. /// Creates the context menu used by project library window. New context menu must be created when a new instance
  12. /// of the project library window is created.
  13. /// </summary>
  14. /// <param name="win">Instance of the project library window.</param>
  15. /// <returns>Context menu bound to the specified instance of the project library window.</returns>
  16. internal static ContextMenu CreateContextMenu(LibraryWindow win)
  17. {
  18. ContextMenu entryContextMenu = new ContextMenu();
  19. entryContextMenu.AddItem("Create", null);
  20. entryContextMenu.AddItem("Create/Material", CreateEmptyMaterial);
  21. entryContextMenu.AddItem("Create/Shader", CreateEmptyShader);
  22. entryContextMenu.AddItem("Create/C# script", CreateEmptyCSScript);
  23. entryContextMenu.AddItem("Create/Sprite texture", CreateEmptySpriteTexture);
  24. entryContextMenu.AddItem("Create/GUI skin", CreateEmptyGUISkin);
  25. entryContextMenu.AddItem("Create/String table", CreateEmptyStringTable);
  26. entryContextMenu.AddSeparator("");
  27. entryContextMenu.AddItem("Rename", win.RenameSelection, new ShortcutKey(ButtonModifier.None, ButtonCode.F2));
  28. entryContextMenu.AddSeparator("");
  29. entryContextMenu.AddItem("Cut", win.CutSelection, new ShortcutKey(ButtonModifier.Ctrl, ButtonCode.X));
  30. entryContextMenu.AddItem("Copy", win.CopySelection, new ShortcutKey(ButtonModifier.Ctrl, ButtonCode.C));
  31. entryContextMenu.AddItem("Duplicate", win.DuplicateSelection, new ShortcutKey(ButtonModifier.Ctrl, ButtonCode.D));
  32. entryContextMenu.AddItem("Paste", win.PasteToSelection, new ShortcutKey(ButtonModifier.Ctrl, ButtonCode.V));
  33. entryContextMenu.AddSeparator("");
  34. entryContextMenu.AddItem("Delete", win.DeleteSelection, new ShortcutKey(ButtonModifier.None, ButtonCode.Delete));
  35. entryContextMenu.AddSeparator("");
  36. entryContextMenu.AddItem("Open externally", OpenExternally);
  37. entryContextMenu.AddItem("Explore location", ExploreLocation);
  38. entryContextMenu.SetLocalizedName("Rename", new LocEdString("Rename"));
  39. entryContextMenu.SetLocalizedName("Cut", new LocEdString("Cut"));
  40. entryContextMenu.SetLocalizedName("Copy", new LocEdString("Copy"));
  41. entryContextMenu.SetLocalizedName("Duplicate", new LocEdString("Duplicate"));
  42. entryContextMenu.SetLocalizedName("Paste", new LocEdString("Paste"));
  43. entryContextMenu.SetLocalizedName("Delete", new LocEdString("Delete"));
  44. return entryContextMenu;
  45. }
  46. /// <summary>
  47. /// Queries if a library window is displayed.
  48. /// </summary>
  49. /// <returns>True if a library window is active, false if not.</returns>
  50. internal static bool IsLibraryWindowActive()
  51. {
  52. return EditorWindow.GetWindow<LibraryWindow>() != null;
  53. }
  54. /// <summary>
  55. /// Creates a new material with the default shader in the currently selected project library folder.
  56. /// </summary>
  57. [MenuItem("Resources/Create/Material", 9050, false, "IsLibraryWindowActive")]
  58. internal static void CreateEmptyMaterial()
  59. {
  60. LibraryWindow win = EditorWindow.GetWindow<LibraryWindow>();
  61. if(win == null)
  62. return;
  63. LibraryUtility.CreateEmptyMaterial(win.SelectedFolder);
  64. }
  65. /// <summary>
  66. /// Creates a new shader containing a rough code outline in the currently selected project library folder.
  67. /// </summary>
  68. [MenuItem("Resources/Create/Shader", 9049, false, "IsLibraryWindowActive")]
  69. internal static void CreateEmptyShader()
  70. {
  71. LibraryWindow win = EditorWindow.GetWindow<LibraryWindow>();
  72. if (win == null)
  73. return;
  74. LibraryUtility.CreateEmptyShader(win.SelectedFolder);
  75. }
  76. /// <summary>
  77. /// Creates a new C# script containing a rough code outline in the currently selected project library folder.
  78. /// </summary>
  79. [MenuItem("Resources/Create/C# script", 9048, false, "IsLibraryWindowActive")]
  80. internal static void CreateEmptyCSScript()
  81. {
  82. LibraryWindow win = EditorWindow.GetWindow<LibraryWindow>();
  83. if (win == null)
  84. return;
  85. LibraryUtility.CreateEmptyCSScript(win.SelectedFolder);
  86. }
  87. /// <summary>
  88. /// Creates a new empty sprite texture in the currently selected project library folder.
  89. /// </summary>
  90. [MenuItem("Resources/Create/Sprite texture", 9047, false, "IsLibraryWindowActive")]
  91. internal static void CreateEmptySpriteTexture()
  92. {
  93. LibraryWindow win = EditorWindow.GetWindow<LibraryWindow>();
  94. if (win == null)
  95. return;
  96. LibraryUtility.CreateEmptySpriteTexture(win.SelectedFolder);
  97. }
  98. /// <summary>
  99. /// Creates a new empty GUI skin in the currently selected project library folder.
  100. /// </summary>
  101. [MenuItem("Resources/Create/GUI skin", 9046, false, "IsLibraryWindowActive")]
  102. internal static void CreateEmptyGUISkin()
  103. {
  104. LibraryWindow win = EditorWindow.GetWindow<LibraryWindow>();
  105. if (win == null)
  106. return;
  107. LibraryUtility.CreateEmptyGUISkin(win.SelectedFolder);
  108. }
  109. /// <summary>
  110. /// Creates a new empty string table in the currently selected project library folder.
  111. /// </summary>
  112. [MenuItem("Resources/Create/String table", 9045, false, "IsLibraryWindowActive")]
  113. internal static void CreateEmptyStringTable()
  114. {
  115. LibraryWindow win = EditorWindow.GetWindow<LibraryWindow>();
  116. if (win == null)
  117. return;
  118. LibraryUtility.CreateEmptyStringTable(win.SelectedFolder);
  119. }
  120. /// <summary>
  121. /// Opens the currently selected project library file or folder in the default external application.
  122. /// </summary>
  123. [MenuItem("Resources/Open externally", 9040, true, "IsLibraryWindowActive")]
  124. internal static void OpenExternally()
  125. {
  126. LibraryWindow win = EditorWindow.GetWindow<LibraryWindow>();
  127. if (win == null)
  128. return;
  129. EditorApplication.OpenExternally(Path.Combine(ProjectLibrary.ResourceFolder, win.SelectedEntry));
  130. }
  131. /// <summary>
  132. /// Explores the current project library folder in the external file system explorer.
  133. /// </summary>
  134. [MenuItem("Resources/Explore location", 9039, false, "IsLibraryWindowActive")]
  135. internal static void ExploreLocation()
  136. {
  137. LibraryWindow win = EditorWindow.GetWindow<LibraryWindow>();
  138. if (win == null)
  139. return;
  140. EditorApplication.OpenExternally(Path.Combine(ProjectLibrary.ResourceFolder, win.CurrentFolder));
  141. }
  142. }
  143. }