| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232 |
- //********************************** Banshee Engine (www.banshee3d.com) **************************************************//
- //**************** Copyright (c) 2016 Marko Pintera ([email protected]). All rights reserved. **********************//
- using System.IO;
- using bs;
- namespace bs.Editor
- {
- /** @addtogroup Library
- * @{
- */
- /// <summary>
- /// Handles main menu and context menu items and callbacks for project library window.
- /// </summary>
- internal static class LibraryMenu
- {
- /// <summary>
- /// Creates the context menu used by project library window. New context menu must be created when a new instance
- /// of the project library window is created.
- /// </summary>
- /// <param name="win">Instance of the project library window.</param>
- /// <returns>Context menu bound to the specified instance of the project library window.</returns>
- internal static ContextMenu CreateContextMenu(LibraryWindow win)
- {
- ContextMenu entryContextMenu = new ContextMenu();
- entryContextMenu.AddItem("Create", null);
- entryContextMenu.AddItem("Create/Folder", CreateFolder);
- entryContextMenu.AddItem("Create/Material", CreateEmptyMaterial);
- entryContextMenu.AddItem("Create/Physics material", CreateEmptyPhysicsMaterial);
- entryContextMenu.AddItem("Create/Shader", CreateEmptyShader);
- entryContextMenu.AddItem("Create/C# script", CreateEmptyCSScript);
- entryContextMenu.AddItem("Create/Sprite texture", CreateEmptySpriteTexture);
- entryContextMenu.AddItem("Create/GUI skin", CreateEmptyGUISkin);
- entryContextMenu.AddItem("Create/String table", CreateEmptyStringTable);
- entryContextMenu.AddSeparator("");
- entryContextMenu.AddItem("Rename", win.RenameSelection, new ShortcutKey(ButtonModifier.None, ButtonCode.F2));
- entryContextMenu.AddSeparator("");
- entryContextMenu.AddItem("Cut", win.CutSelection, new ShortcutKey(ButtonModifier.Ctrl, ButtonCode.X));
- entryContextMenu.AddItem("Copy", win.CopySelection, new ShortcutKey(ButtonModifier.Ctrl, ButtonCode.C));
- entryContextMenu.AddItem("Duplicate", win.DuplicateSelection, new ShortcutKey(ButtonModifier.Ctrl, ButtonCode.D));
- entryContextMenu.AddItem("Paste", win.PasteToSelection, new ShortcutKey(ButtonModifier.Ctrl, ButtonCode.V));
- entryContextMenu.AddSeparator("");
- entryContextMenu.AddItem("Delete", win.DeleteSelection, new ShortcutKey(ButtonModifier.None, ButtonCode.Delete));
- entryContextMenu.AddSeparator("");
- entryContextMenu.AddItem("Open externally", OpenExternally);
- entryContextMenu.AddItem("Explore location", ExploreLocation);
- entryContextMenu.SetLocalizedName("Rename", new LocEdString("Rename"));
- entryContextMenu.SetLocalizedName("Cut", new LocEdString("Cut"));
- entryContextMenu.SetLocalizedName("Copy", new LocEdString("Copy"));
- entryContextMenu.SetLocalizedName("Duplicate", new LocEdString("Duplicate"));
- entryContextMenu.SetLocalizedName("Paste", new LocEdString("Paste"));
- entryContextMenu.SetLocalizedName("Delete", new LocEdString("Delete"));
- return entryContextMenu;
- }
- /// <summary>
- /// Queries if a library window is displayed.
- /// </summary>
- /// <returns>True if a library window is active, false if not.</returns>
- internal static bool IsLibraryWindowActive()
- {
- return EditorWindow.GetWindow<LibraryWindow>() != null;
- }
- /// <summary>
- /// Scrolls to and selects the specified resource path then start a rename operation.
- /// </summary>
- /// <param name="path">Path to the resource to rename</param>
- /// <param name="window">Reference to the library window</param>
- private static void StartRename(string path, LibraryWindow window)
- {
- if (window == null)
- return;
- window.Refresh();
- window.HasFocus = true;
- window.GoToEntry(path);
- window.Select(path);
- window.RenameSelection();
- }
- /// <summary>
- /// Creates a new material with the default shader in the currently selected project library folder.
- /// </summary>
- [MenuItem("Resources/Create/Folder", 9051, false, "IsLibraryWindowActive")]
- internal static void CreateFolder()
- {
- LibraryWindow win = EditorWindow.GetWindow<LibraryWindow>();
- if (win == null)
- return;
- string path = LibraryUtility.CreateFolder(win.SelectedFolder);
- StartRename(path, win);
- }
- /// <summary>
- /// Creates a new material with the default shader in the currently selected project library folder.
- /// </summary>
- [MenuItem("Resources/Create/Material", 9050, false, "IsLibraryWindowActive")]
- [ToolbarItem("Material", ToolbarIcon.NewMat, "New material", 1498)]
- internal static void CreateEmptyMaterial()
- {
- LibraryWindow win = EditorWindow.GetWindow<LibraryWindow>();
- if(win == null)
- return;
- string path = LibraryUtility.CreateEmptyMaterial(win.SelectedFolder);
- StartRename(path, win);
- }
- /// <summary>
- /// Creates a new shader containing a rough code outline in the currently selected project library folder.
- /// </summary>
- [MenuItem("Resources/Create/Shader", 9049, false, "IsLibraryWindowActive")]
- [ToolbarItem("Shader", ToolbarIcon.NewShader, "New shader", 1499)]
- internal static void CreateEmptyShader()
- {
- LibraryWindow win = EditorWindow.GetWindow<LibraryWindow>();
- if (win == null)
- return;
- LibraryUtility.CreateEmptyShader(win.SelectedFolder);
- }
- /// <summary>
- /// Creates a new C# script containing a rough code outline in the currently selected project library folder.
- /// </summary>
- [MenuItem("Resources/Create/C# script", 9048, false, "IsLibraryWindowActive")]
- [ToolbarItem("C# script", ToolbarIcon.NewCSScript, "New C# script", 1500, true)]
- internal static void CreateEmptyCSScript()
- {
- LibraryWindow win = EditorWindow.GetWindow<LibraryWindow>();
- if (win == null)
- return;
- LibraryUtility.CreateEmptyCSScript(win.SelectedFolder);
- }
- /// <summary>
- /// Creates a new empty sprite texture in the currently selected project library folder.
- /// </summary>
- [MenuItem("Resources/Create/Sprite texture", 9047, false, "IsLibraryWindowActive")]
- [ToolbarItem("Sprite texture", ToolbarIcon.NewSpriteTex, "New sprite texture", 1497)]
- internal static void CreateEmptySpriteTexture()
- {
- LibraryWindow win = EditorWindow.GetWindow<LibraryWindow>();
- if (win == null)
- return;
- string path = LibraryUtility.CreateEmptySpriteTexture(win.SelectedFolder);
- StartRename(path, win);
- }
- /// <summary>
- /// Creates a new empty GUI skin in the currently selected project library folder.
- /// </summary>
- [MenuItem("Resources/Create/GUI skin", 9046, false, "IsLibraryWindowActive")]
- internal static void CreateEmptyGUISkin()
- {
- LibraryWindow win = EditorWindow.GetWindow<LibraryWindow>();
- if (win == null)
- return;
- string path = LibraryUtility.CreateEmptyGUISkin(win.SelectedFolder);
- StartRename(path, win);
- }
- /// <summary>
- /// Creates a new empty string table in the currently selected project library folder.
- /// </summary>
- [MenuItem("Resources/Create/String table", 9045, false, "IsLibraryWindowActive")]
- internal static void CreateEmptyStringTable()
- {
- LibraryWindow win = EditorWindow.GetWindow<LibraryWindow>();
- if (win == null)
- return;
- string path = LibraryUtility.CreateEmptyStringTable(win.SelectedFolder);
- StartRename(path, win);
- }
- /// <summary>
- /// Creates a new physics material with the default properties in the currently selected project library folder.
- /// </summary>
- [MenuItem("Resources/Create/Physics material", 9044, false, "IsLibraryWindowActive")]
- internal static void CreateEmptyPhysicsMaterial()
- {
- LibraryWindow win = EditorWindow.GetWindow<LibraryWindow>();
- if (win == null)
- return;
- string path = LibraryUtility.CreateEmptyPhysicsMaterial(win.SelectedFolder);
- StartRename(path, win);
- }
- /// <summary>
- /// Opens the currently selected project library file or folder in the default external application.
- /// </summary>
- [MenuItem("Resources/Open externally", 9040, true, "IsLibraryWindowActive")]
- internal static void OpenExternally()
- {
- LibraryWindow win = EditorWindow.GetWindow<LibraryWindow>();
- if (win == null)
- return;
- EditorApplication.OpenFolder(Path.Combine(ProjectLibrary.ResourceFolder, win.SelectedEntry));
- }
- /// <summary>
- /// Explores the current project library folder in the external file system explorer.
- /// </summary>
- [MenuItem("Resources/Explore location", 9039, false, "IsLibraryWindowActive")]
- internal static void ExploreLocation()
- {
- LibraryWindow win = EditorWindow.GetWindow<LibraryWindow>();
- if (win == null)
- return;
- EditorApplication.OpenFolder(Path.Combine(ProjectLibrary.ResourceFolder, win.CurrentFolder));
- }
- }
- /** @} */
- }
|