LibraryMenu.cs 7.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167
  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. [ToolbarItem("Material", ToolbarIcon.NewMat, "", 1498)]
  59. internal static void CreateEmptyMaterial()
  60. {
  61. LibraryWindow win = EditorWindow.GetWindow<LibraryWindow>();
  62. if(win == null)
  63. return;
  64. LibraryUtility.CreateEmptyMaterial(win.SelectedFolder);
  65. }
  66. /// <summary>
  67. /// Creates a new shader containing a rough code outline in the currently selected project library folder.
  68. /// </summary>
  69. [MenuItem("Resources/Create/Shader", 9049, false, "IsLibraryWindowActive")]
  70. [ToolbarItem("Shader", ToolbarIcon.NewShader, "", 1499)]
  71. internal static void CreateEmptyShader()
  72. {
  73. LibraryWindow win = EditorWindow.GetWindow<LibraryWindow>();
  74. if (win == null)
  75. return;
  76. LibraryUtility.CreateEmptyShader(win.SelectedFolder);
  77. }
  78. /// <summary>
  79. /// Creates a new C# script containing a rough code outline in the currently selected project library folder.
  80. /// </summary>
  81. [MenuItem("Resources/Create/C# script", 9048, false, "IsLibraryWindowActive")]
  82. [ToolbarItem("C# script", ToolbarIcon.NewCSScript, "", 1500, true)]
  83. internal static void CreateEmptyCSScript()
  84. {
  85. LibraryWindow win = EditorWindow.GetWindow<LibraryWindow>();
  86. if (win == null)
  87. return;
  88. LibraryUtility.CreateEmptyCSScript(win.SelectedFolder);
  89. }
  90. /// <summary>
  91. /// Creates a new empty sprite texture in the currently selected project library folder.
  92. /// </summary>
  93. [MenuItem("Resources/Create/Sprite texture", 9047, false, "IsLibraryWindowActive")]
  94. [ToolbarItem("Sprite texture", ToolbarIcon.NewSpriteTex, "", 1497)]
  95. internal static void CreateEmptySpriteTexture()
  96. {
  97. LibraryWindow win = EditorWindow.GetWindow<LibraryWindow>();
  98. if (win == null)
  99. return;
  100. LibraryUtility.CreateEmptySpriteTexture(win.SelectedFolder);
  101. }
  102. /// <summary>
  103. /// Creates a new empty GUI skin in the currently selected project library folder.
  104. /// </summary>
  105. [MenuItem("Resources/Create/GUI skin", 9046, false, "IsLibraryWindowActive")]
  106. internal static void CreateEmptyGUISkin()
  107. {
  108. LibraryWindow win = EditorWindow.GetWindow<LibraryWindow>();
  109. if (win == null)
  110. return;
  111. LibraryUtility.CreateEmptyGUISkin(win.SelectedFolder);
  112. }
  113. /// <summary>
  114. /// Creates a new empty string table in the currently selected project library folder.
  115. /// </summary>
  116. [MenuItem("Resources/Create/String table", 9045, false, "IsLibraryWindowActive")]
  117. internal static void CreateEmptyStringTable()
  118. {
  119. LibraryWindow win = EditorWindow.GetWindow<LibraryWindow>();
  120. if (win == null)
  121. return;
  122. LibraryUtility.CreateEmptyStringTable(win.SelectedFolder);
  123. }
  124. /// <summary>
  125. /// Opens the currently selected project library file or folder in the default external application.
  126. /// </summary>
  127. [MenuItem("Resources/Open externally", 9040, true, "IsLibraryWindowActive")]
  128. internal static void OpenExternally()
  129. {
  130. LibraryWindow win = EditorWindow.GetWindow<LibraryWindow>();
  131. if (win == null)
  132. return;
  133. EditorApplication.OpenExternally(Path.Combine(ProjectLibrary.ResourceFolder, win.SelectedEntry));
  134. }
  135. /// <summary>
  136. /// Explores the current project library folder in the external file system explorer.
  137. /// </summary>
  138. [MenuItem("Resources/Explore location", 9039, false, "IsLibraryWindowActive")]
  139. internal static void ExploreLocation()
  140. {
  141. LibraryWindow win = EditorWindow.GetWindow<LibraryWindow>();
  142. if (win == null)
  143. return;
  144. EditorApplication.OpenExternally(Path.Combine(ProjectLibrary.ResourceFolder, win.CurrentFolder));
  145. }
  146. }
  147. }