2
0

LibraryMenu.cs 9.0 KB

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