2
0

LibraryMenu.cs 8.9 KB

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