LibraryMenu.cs 8.0 KB

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