LibraryMenu.cs 8.5 KB

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