private ContextMenu OnViewDropdownPopupCreate(ComboBox comboBox) { var menu = new ContextMenu(); var showFileExtensionsButton = menu.AddButton("Show file extensions", () => View.ShowFileExtensions = !View.ShowFileExtensions); showFileExtensionsButton.Checked = View.ShowFileExtensions; showFileExtensionsButton.AutoCheck = true; var viewScale = menu.AddButton("View Scale"); var scaleValue = new FloatValueBox(1, 75, 2, 50.0f, 0.3f, 3.0f, 0.01f); scaleValue.Parent = viewScale; scaleValue.ValueChanged += () => View.ViewScale = scaleValue.Value; menu.VisibleChanged += control => { scaleValue.Value = View.ViewScale; }; var viewType = menu.AddChildMenu("View Type"); viewType.ContextMenu.AddButton("Tiles", OnViewTypeButtonClicked).Tag = ContentViewType.Tiles; viewType.ContextMenu.AddButton("List", OnViewTypeButtonClicked).Tag = ContentViewType.List; viewType.ContextMenu.VisibleChanged += control => { if (!control.Visible) { return; } foreach (var item in ((ContextMenu)control).Items) { if (item is ContextMenuButton button) { button.Checked = View.ViewType == (ContentViewType)button.Tag; } } }; var filters = menu.AddChildMenu("Filters"); for (int i = 0; i < _viewDropdown.Items.Count; i++) { var filterButton = filters.ContextMenu.AddButton(_viewDropdown.Items[i], OnFilterClicked); filterButton.Tag = i; } filters.ContextMenu.VisibleChanged += control => { if (!control.Visible) { return; } foreach (var item in ((ContextMenu)control).Items) { if (item is ContextMenuButton filterButton) { filterButton.Checked = _viewDropdown.IsSelected(filterButton.Text); } } }; return(menu); }
private ContextMenuChildMenu GetOrAddChildMenu(string name, ContextMenu parent) { ContextMenuChildMenu item = parent.GetChildMenu(name); if (item == null) { item = parent.AddChildMenu(name); _menus.Add(item); } return(item); }
/// <summary> /// Creates the context menu for the current objects selection. /// </summary> /// <returns>The context menu.</returns> private ContextMenu CreateContextMenu() { // Prepare bool hasSthSelected = Selection.Count > 0; bool isSingleActorSelected = Selection.Count == 1 && Selection[0] is ActorNode; bool isRootSelected = isSingleActorSelected && Selection[0] == Graph.Main; bool hasPrefabLink = isSingleActorSelected && (Selection[0] as ActorNode).HasPrefabLink; // Create popup var contextMenu = new ContextMenu { MinimumWidth = 120 }; // Basic editing options var b = contextMenu.AddButton("Rename", Rename); b.Enabled = isSingleActorSelected; b = contextMenu.AddButton("Duplicate", Duplicate); b.Enabled = hasSthSelected && !isRootSelected; b = contextMenu.AddButton("Delete", Delete); b.Enabled = hasSthSelected && !isRootSelected; contextMenu.AddSeparator(); b = contextMenu.AddButton("Copy", Copy); b.Enabled = hasSthSelected; b.Enabled = hasSthSelected; contextMenu.AddButton("Paste", Paste); b = contextMenu.AddButton("Cut", Cut); b.Enabled = hasSthSelected && !isRootSelected; b = contextMenu.AddButton("Set Root", SetRoot); b.Enabled = isSingleActorSelected && !isRootSelected && hasPrefabLink && Editor.Internal_CanSetToRoot(FlaxEngine.Object.GetUnmanagedPtr(Asset), FlaxEngine.Object.GetUnmanagedPtr(((ActorNode)Selection[0]).Actor)); // Prefab options contextMenu.AddSeparator(); b = contextMenu.AddButton("Create Prefab", () => Editor.Prefabs.CreatePrefab(Selection)); b.Enabled = isSingleActorSelected && (Selection[0] as ActorNode).CanCreatePrefab && Editor.Windows.ContentWin.CurrentViewFolder.CanHaveAssets; b = contextMenu.AddButton("Select Prefab", Editor.Prefabs.SelectPrefab); b.Enabled = hasPrefabLink; // Spawning actors options contextMenu.AddSeparator(); var spawnMenu = contextMenu.AddChildMenu("New"); var newActorCm = spawnMenu.ContextMenu; for (int i = 0; i < SceneTreeWindow.SpawnActorsGroups.Length; i++) { var group = SceneTreeWindow.SpawnActorsGroups[i]; if (group.Types.Length == 1) { var type = group.Types[0].Value; newActorCm.AddButton(group.Types[0].Key, () => Spawn(type)); } else { var groupCm = newActorCm.AddChildMenu(group.Name).ContextMenu; for (int j = 0; j < group.Types.Length; j++) { var type = group.Types[j].Value; groupCm.AddButton(group.Types[j].Key, () => Spawn(type)); } } } // Custom options bool showCustomNodeOptions = Editor.SceneEditing.Selection.Count == 1; if (!showCustomNodeOptions && Editor.SceneEditing.Selection.Count != 0) { showCustomNodeOptions = true; for (int i = 1; i < Editor.SceneEditing.Selection.Count; i++) { if (Editor.SceneEditing.Selection[0].GetType() != Editor.SceneEditing.Selection[i].GetType()) { showCustomNodeOptions = false; break; } } } if (showCustomNodeOptions) { Editor.SceneEditing.Selection[0].OnContextMenu(contextMenu); } ContextMenuShow?.Invoke(contextMenu); return(contextMenu); }
/// <summary> /// Creates the context menu for the current objects selection and the current Editor state. /// </summary> /// <returns>The context menu.</returns> private ContextMenu CreateContextMenu() { // Prepare bool hasSthSelected = Editor.SceneEditing.HasSthSelected; bool isSingleActorSelected = Editor.SceneEditing.SelectionCount == 1 && Editor.SceneEditing.Selection[0] is ActorNode; bool canEditScene = Editor.StateMachine.CurrentState.CanEditScene && Level.IsAnySceneLoaded; // Create popup var contextMenu = new ContextMenu { MinimumWidth = 120 }; // Expand/collapse var b = contextMenu.AddButton("Expand All", OnExpandAllClicked); b.Enabled = hasSthSelected; b = contextMenu.AddButton("Collapse All", OnCollapseAllClicked); b.Enabled = hasSthSelected; if (hasSthSelected) { contextMenu.AddButton(Editor.Windows.EditWin.IsPilotActorActive ? "Stop piloting actor" : "Pilot actor", Editor.UI.PilotActor); } contextMenu.AddSeparator(); // Basic editing options b = contextMenu.AddButton("Rename", Rename); b.Enabled = isSingleActorSelected; b = contextMenu.AddButton("Duplicate", Editor.SceneEditing.Duplicate); b.Enabled = hasSthSelected; if (isSingleActorSelected) { var convertMenu = contextMenu.AddChildMenu("Convert"); var convertActorCm = convertMenu.ContextMenu; for (int i = 0; i < SpawnActorsGroups.Length; i++) { var group = SpawnActorsGroups[i]; if (group.Types.Length == 1) { var type = group.Types[0].Value; convertActorCm.AddButton(group.Types[0].Key, () => Editor.SceneEditing.Convert(type)); } else { var groupCm = convertActorCm.AddChildMenu(group.Name).ContextMenu; for (int j = 0; j < group.Types.Length; j++) { var type = group.Types[j].Value; groupCm.AddButton(group.Types[j].Key, () => Editor.SceneEditing.Convert(type)); } } } } b = contextMenu.AddButton("Delete", Editor.SceneEditing.Delete); b.Enabled = hasSthSelected; contextMenu.AddSeparator(); b = contextMenu.AddButton("Copy", Editor.SceneEditing.Copy); b.Enabled = hasSthSelected; contextMenu.AddButton("Paste", Editor.SceneEditing.Paste); b = contextMenu.AddButton("Cut", Editor.SceneEditing.Cut); b.Enabled = canEditScene; // Prefab options contextMenu.AddSeparator(); b = contextMenu.AddButton("Create Prefab", Editor.Prefabs.CreatePrefab); b.Enabled = isSingleActorSelected && ((ActorNode)Editor.SceneEditing.Selection[0]).CanCreatePrefab && Editor.Windows.ContentWin.CurrentViewFolder.CanHaveAssets; bool hasPrefabLink = canEditScene && isSingleActorSelected && (Editor.SceneEditing.Selection[0] as ActorNode).HasPrefabLink; if (hasPrefabLink) { contextMenu.AddButton("Select Prefab", Editor.Prefabs.SelectPrefab); contextMenu.AddButton("Break Prefab Link", Editor.Prefabs.BreakLinks); } // Spawning actors options contextMenu.AddSeparator(); var spawnMenu = contextMenu.AddChildMenu("New"); var newActorCm = spawnMenu.ContextMenu; for (int i = 0; i < SpawnActorsGroups.Length; i++) { var group = SpawnActorsGroups[i]; if (group.Types.Length == 1) { var type = group.Types[0].Value; newActorCm.AddButton(group.Types[0].Key, () => Spawn(type)); } else { var groupCm = newActorCm.AddChildMenu(group.Name).ContextMenu; for (int j = 0; j < group.Types.Length; j++) { var type = group.Types[j].Value; groupCm.AddButton(group.Types[j].Key, () => Spawn(type)); } } } // Custom options bool showCustomNodeOptions = Editor.SceneEditing.Selection.Count == 1; if (!showCustomNodeOptions && Editor.SceneEditing.Selection.Count != 0) { showCustomNodeOptions = true; for (int i = 1; i < Editor.SceneEditing.Selection.Count; i++) { if (Editor.SceneEditing.Selection[0].GetType() != Editor.SceneEditing.Selection[i].GetType()) { showCustomNodeOptions = false; break; } } } if (showCustomNodeOptions) { Editor.SceneEditing.Selection[0].OnContextMenu(contextMenu); } ContextMenuShow?.Invoke(contextMenu); return(contextMenu); }
/// <summary> /// Initializes a new instance of the <see cref="SceneTreeWindow"/> class. /// </summary> /// <param name="editor">The editor.</param> public SceneTreeWindow(Editor editor) : base(editor, true, ScrollBars.Both) { Title = "Scene"; // Create scene structure tree var root = editor.Scene.Root; root.TreeNode.Expand(); _tree = new Tree(true); _tree.AddChild(root.TreeNode); _tree.SelectedChanged += Tree_OnSelectedChanged; _tree.RightClick += Tree_OnRightClick; _tree.Parent = this; // Spawnable actors (groups with single entry are inlined without a child menu) var groups = new[] { new ActorsGroup { Types = new[] { new KeyValuePair <string, Type>("Actor", typeof(EmptyActor)) } }, new ActorsGroup { Types = new[] { new KeyValuePair <string, Type>("Model", typeof(ModelActor)) } }, new ActorsGroup { Types = new[] { new KeyValuePair <string, Type>("Camera", typeof(Camera)) } }, new ActorsGroup { Name = "Lights", Types = new[] { new KeyValuePair <string, Type>("Point Light", typeof(PointLight)), new KeyValuePair <string, Type>("Spot Light", typeof(SpotLight)), new KeyValuePair <string, Type>("Directional Light", typeof(DirectionalLight)), } }, new ActorsGroup { Name = "Visuals", Types = new[] { new KeyValuePair <string, Type>("Environment Probe", typeof(EnvironmentProbe)), new KeyValuePair <string, Type>("Sky", typeof(Sky)), new KeyValuePair <string, Type>("Skybox", typeof(Skybox)), } }, new ActorsGroup { Name = "Physics", Types = new[] { new KeyValuePair <string, Type>("Rigid Body", typeof(RigidBody)), new KeyValuePair <string, Type>("Character Controller", typeof(CharacterController)), new KeyValuePair <string, Type>("Box Collider", typeof(BoxCollider)), new KeyValuePair <string, Type>("Sphere Collider", typeof(SphereCollider)), new KeyValuePair <string, Type>("Capsule Collider", typeof(CapsuleCollider)), new KeyValuePair <string, Type>("Mesh Collider", typeof(MeshCollider)), new KeyValuePair <string, Type>("Fixed Joint", typeof(FixedJoint)), new KeyValuePair <string, Type>("Distance Joint", typeof(DistanceJoint)), new KeyValuePair <string, Type>("Slider Joint", typeof(SliderJoint)), new KeyValuePair <string, Type>("Spherical Joint", typeof(SphericalJoint)), new KeyValuePair <string, Type>("Hinge Joint", typeof(HingeJoint)), new KeyValuePair <string, Type>("D6 Joint", typeof(D6Joint)), } }, new ActorsGroup { Name = "CSG", Types = new[] { new KeyValuePair <string, Type>("Box Brush", typeof(BoxBrush)), } }, new ActorsGroup { Name = "Volumes", Types = new[] { new KeyValuePair <string, Type>("PostFx Volume", typeof(PostFxVolume)), } }, }; // Create context menu _contextMenu = new ContextMenu(); _contextMenu.MinimumWidth = 120; _contextMenu.AddButton(1, "Duplicate"); _contextMenu.AddButton(2, "Delete"); _contextMenu.AddSeparator(); _contextMenu.AddButton(3, "Copy"); _contextMenu.AddButton(4, "Paste"); _contextMenu.AddButton(5, "Cut"); _contextMenu.AddSeparator(); _spawnMenu = _contextMenu.AddChildMenu("New"); var newActorCm = _spawnMenu.ContextMenu; for (int i = 0; i < groups.Length; i++) { var group = groups[i]; if (group.Types.Length == 1) { var button = newActorCm.AddButton(6 + i, group.Types[0].Key); button.Tag = group.Types[0].Value; } else { var groupCm = newActorCm.AddChildMenu(group.Name).ContextMenu; for (int j = 0; j < group.Types.Length; j++) { var button = groupCm.AddButton(j, group.Types[j].Key); button.Tag = group.Types[j].Value; } groupCm.OnButtonClicked += GroupCmOnButtonClicked; } } newActorCm.OnButtonClicked += ContextMenuOnButtonClicked; _contextMenu.VisibleChanged += ContextMenuOnVisibleChanged; _contextMenu.OnButtonClicked += ContextMenuOnButtonClicked; }
/// <summary> /// Creates the context menu for the current objects selection. /// </summary> /// <returns>The context menu.</returns> private ContextMenu CreateContextMenu() { // Prepare bool hasSthSelected = Selection.Count > 0; bool isSingleActorSelected = Selection.Count == 1 && Selection[0] is ActorNode; bool isRootSelected = isSingleActorSelected && Selection[0] == Graph.Main; // Create popup var contextMenu = new ContextMenu(); contextMenu.MinimumWidth = 120; // Basic editing options var b = contextMenu.AddButton("Rename", Rename); b.Enabled = isSingleActorSelected; b = contextMenu.AddButton("Duplicate", Duplicate); b.Enabled = hasSthSelected && !isRootSelected; b = contextMenu.AddButton("Delete", Delete); b.Enabled = hasSthSelected && !isRootSelected; contextMenu.AddSeparator(); b = contextMenu.AddButton("Copy", Copy); b.Enabled = hasSthSelected; b.Enabled = hasSthSelected; contextMenu.AddButton("Paste", Paste); b = contextMenu.AddButton("Cut", Cut); b.Enabled = hasSthSelected && !isRootSelected; // Prefab options contextMenu.AddSeparator(); b = contextMenu.AddButton("Create Prefab", Editor.Prefabs.CreatePrefab); b.Enabled = isSingleActorSelected && (Selection[0] as ActorNode).CanCreatePrefab && Editor.Windows.ContentWin.CurrentViewFolder.CanHaveAssets; bool hasPrefabLink = isSingleActorSelected && (Selection[0] as ActorNode).HasPrefabLink; b = contextMenu.AddButton("Select Prefab", Editor.Prefabs.SelectPrefab); b.Enabled = hasPrefabLink; // Spawning actors options contextMenu.AddSeparator(); var spawnMenu = contextMenu.AddChildMenu("New"); var newActorCm = spawnMenu.ContextMenu; for (int i = 0; i < SceneTreeWindow.SpawnActorsGroups.Length; i++) { var group = SceneTreeWindow.SpawnActorsGroups[i]; if (group.Types.Length == 1) { var type = group.Types[0].Value; newActorCm.AddButton(group.Types[0].Key, () => Spawn(type)); } else { var groupCm = newActorCm.AddChildMenu(group.Name).ContextMenu; for (int j = 0; j < group.Types.Length; j++) { var type = group.Types[j].Value; groupCm.AddButton(group.Types[j].Key, () => Spawn(type)); } } } // Custom options ContextMenuShow?.Invoke(contextMenu); return(contextMenu); }
/// <summary> /// Initializes a new instance of the <see cref="SceneTreeWindow"/> class. /// </summary> /// <param name="editor">The editor.</param> public SceneTreeWindow(Editor editor) : base(editor, true, ScrollBars.Both) { Title = "Scene"; // Create scene structure tree var root = editor.Scene.Root; root.TreeNode.ChildrenIndent = 0; root.TreeNode.Expand(); _tree = new Tree(true); _tree.Margin = new Margin(0.0f, 0.0f, -14.0f, 0.0f); // Hide root node _tree.AddChild(root.TreeNode); _tree.SelectedChanged += Tree_OnSelectedChanged; _tree.RightClick += Tree_OnRightClick; _tree.Parent = this; // Spawnable actors (groups with single entry are inlined without a child menu) var groups = new[] { new ActorsGroup { Types = new[] { new KeyValuePair <string, Type>("Actor", typeof(EmptyActor)) } }, new ActorsGroup { Types = new[] { new KeyValuePair <string, Type>("Model", typeof(ModelActor)) } }, new ActorsGroup { Types = new[] { new KeyValuePair <string, Type>("Camera", typeof(Camera)) } }, new ActorsGroup { Name = "Lights", Types = new[] { new KeyValuePair <string, Type>("Directional Light", typeof(DirectionalLight)), new KeyValuePair <string, Type>("Point Light", typeof(PointLight)), new KeyValuePair <string, Type>("Spot Light", typeof(SpotLight)), new KeyValuePair <string, Type>("Sky Light", typeof(SkyLight)), } }, new ActorsGroup { Name = "Visuals", Types = new[] { new KeyValuePair <string, Type>("Environment Probe", typeof(EnvironmentProbe)), new KeyValuePair <string, Type>("Sky", typeof(Sky)), new KeyValuePair <string, Type>("Skybox", typeof(Skybox)), new KeyValuePair <string, Type>("Exponential Height Fog", typeof(ExponentialHeightFog)), new KeyValuePair <string, Type>("PostFx Volume", typeof(PostFxVolume)), new KeyValuePair <string, Type>("Decal", typeof(Decal)), } }, new ActorsGroup { Name = "Physics", Types = new[] { new KeyValuePair <string, Type>("Rigid Body", typeof(RigidBody)), new KeyValuePair <string, Type>("Character Controller", typeof(CharacterController)), new KeyValuePair <string, Type>("Box Collider", typeof(BoxCollider)), new KeyValuePair <string, Type>("Sphere Collider", typeof(SphereCollider)), new KeyValuePair <string, Type>("Capsule Collider", typeof(CapsuleCollider)), new KeyValuePair <string, Type>("Mesh Collider", typeof(MeshCollider)), new KeyValuePair <string, Type>("Fixed Joint", typeof(FixedJoint)), new KeyValuePair <string, Type>("Distance Joint", typeof(DistanceJoint)), new KeyValuePair <string, Type>("Slider Joint", typeof(SliderJoint)), new KeyValuePair <string, Type>("Spherical Joint", typeof(SphericalJoint)), new KeyValuePair <string, Type>("Hinge Joint", typeof(HingeJoint)), new KeyValuePair <string, Type>("D6 Joint", typeof(D6Joint)), } }, new ActorsGroup { Name = "Other", Types = new[] { new KeyValuePair <string, Type>("Animated Model", typeof(AnimatedModel)), new KeyValuePair <string, Type>("Bone Socket", typeof(BoneSocket)), new KeyValuePair <string, Type>("CSG Box Brush", typeof(BoxBrush)), new KeyValuePair <string, Type>("Audio Source", typeof(AudioSource)), new KeyValuePair <string, Type>("Audio Listener", typeof(AudioListener)), } }, new ActorsGroup { Name = "GUI", Types = new[] { new KeyValuePair <string, Type>("UI Control", typeof(UIControl)), new KeyValuePair <string, Type>("UI Canvas", typeof(UICanvas)), new KeyValuePair <string, Type>("Text Render", typeof(TextRender)), } }, }; // Create context menu _contextMenu = new ContextMenu(); _contextMenu.MinimumWidth = 120; _cmRename = _contextMenu.AddButton("Rename", Rename); _cmDuplicate = _contextMenu.AddButton("Duplicate", Editor.SceneEditing.Duplicate); _cmDelete = _contextMenu.AddButton("Delete", Editor.SceneEditing.Delete); _contextMenu.AddSeparator(); _cmCopy = _contextMenu.AddButton("Copy", Editor.SceneEditing.Copy); _contextMenu.AddButton("Paste", Editor.SceneEditing.Paste); _cmCut = _contextMenu.AddButton("Cut", Editor.SceneEditing.Cut); _contextMenu.AddSeparator(); _spawnMenu = _contextMenu.AddChildMenu("New"); var newActorCm = _spawnMenu.ContextMenu; for (int i = 0; i < groups.Length; i++) { var group = groups[i]; if (group.Types.Length == 1) { var type = group.Types[0].Value; newActorCm.AddButton(group.Types[0].Key, () => Spawn(type)); } else { var groupCm = newActorCm.AddChildMenu(group.Name).ContextMenu; for (int j = 0; j < group.Types.Length; j++) { var type = group.Types[j].Value; groupCm.AddButton(group.Types[j].Key, () => Spawn(type)); } } } _contextMenu.VisibleChanged += ContextMenuOnVisibleChanged; }
private void ShowContextMenuForItem(ContentItem item, ref Vector2 location, bool isTreeNode) { Assert.IsNull(_newElement); // Cache data bool isValidElement = item != null; var proxy = Editor.ContentDatabase.GetProxy(item); ContentFolder folder = null; bool isFolder = false; if (isValidElement) { isFolder = item.IsFolder; folder = isFolder ? (ContentFolder)item : item.ParentFolder; } else { folder = CurrentViewFolder; } Assert.IsNotNull(folder); bool isRootFolder = CurrentViewFolder == _root.Folder; // Create context menu ContextMenuButton b; ContextMenuChildMenu c; ContextMenu cm = new ContextMenu(); cm.Tag = item; if (isTreeNode) { b = cm.AddButton("Expand All", OnExpandAllClicked); b.Enabled = CurrentViewFolder.Node.ChildrenCount != 0; b = cm.AddButton("Collapse All", OnCollapseAllClicked); b.Enabled = CurrentViewFolder.Node.ChildrenCount != 0; cm.AddSeparator(); } if (isValidElement) { b = cm.AddButton("Open", () => Open(item)); b.Enabled = proxy != null || isFolder; cm.AddButton("Show in explorer", () => Application.StartProcess(System.IO.Path.GetDirectoryName(item.Path))); if (item.HasDefaultThumbnail == false) { cm.AddButton("Refresh thumbnail", item.RefreshThumbnail); } if (!isFolder) { b = cm.AddButton("Reimport", ReimportSelection); b.Enabled = proxy != null && proxy.CanReimport(item); if (item is BinaryAssetItem binaryAsset) { string importPath; if (!binaryAsset.GetImportPath(out importPath)) { string importLocation = System.IO.Path.GetDirectoryName(importPath); if (!string.IsNullOrEmpty(importLocation) && System.IO.Directory.Exists(importLocation)) { cm.AddButton("Show import location", () => Application.StartProcess(importLocation)); } } } if (Editor.CanExport(item.Path)) { b = cm.AddButton("Export", ExportSelection); } } cm.AddButton("Delete", () => Delete(item)); cm.AddSeparator(); b = cm.AddButton("Clone", _view.Duplicate); b.Enabled = !isFolder; cm.AddButton("Copy", _view.Copy); cm.AddButton("Paste", _view.Paste); b.Enabled = _view.CanPaste(); cm.AddButton("Rename", () => Rename(item)); // Custom options ContextMenuShow?.Invoke(cm, item); proxy?.OnContentWindowContextMenu(cm, item); cm.AddButton("Copy name to Clipboard", () => Application.ClipboardText = item.NamePath); cm.AddButton("Copy path to Clipboard", () => Application.ClipboardText = item.Path); } else { cm.AddButton("Show in explorer", () => Application.StartProcess(CurrentViewFolder.Path)); b = cm.AddButton("Paste", _view.Paste); b.Enabled = _view.CanPaste(); cm.AddButton("Refresh", () => Editor.ContentDatabase.RefreshFolder(CurrentViewFolder, true)); cm.AddButton("Refresh all thumbnails", RefreshViewItemsThumbnails); } cm.AddSeparator(); if (!isRootFolder) { cm.AddButton("New folder", NewFolder); } c = cm.AddChildMenu("New"); c.ContextMenu.Tag = item; int newItems = 0; for (int i = 0; i < Editor.ContentDatabase.Proxy.Count; i++) { var p = Editor.ContentDatabase.Proxy[i]; if (p.CanCreate(folder)) { c.ContextMenu.AddButton(p.Name, () => NewItem(p)); newItems++; } } c.Enabled = newItems > 0; if (folder.CanHaveAssets) { cm.AddButton("Import file", () => { _view.ClearSelection(); Editor.ContentImporting.ShowImportFileDialog(CurrentViewFolder); }); } // Show it cm.Show(this, location); }
private void ShowContextMenuForItem(ContentItem item, ref Vector2 location) { // TODO: verify this logic during elements searching Assert.IsNull(_newElement); // Cache data bool isValidElement = item != null; var proxy = Editor.ContentDatabase.GetProxy(item); ContentFolder folder = null; bool isFolder = false; if (isValidElement) { isFolder = item.IsFolder; folder = isFolder ? (ContentFolder)item : item.ParentFolder; } else { folder = CurrentViewFolder; } Assert.IsNotNull(folder); // Create context menu ContextMenuButton b; ContextMenuChildMenu c; ContextMenu cm = new ContextMenu(); cm.Tag = item; cm.OnButtonClicked += OnItemCMButtonClicked; if (isValidElement) { b = cm.AddButton(0, "Open"); b.Enabled = proxy != null || isFolder; cm.AddButton(14, "Show in explorer"); if (item.HasDefaultThumbnail == false) { cm.AddButton(1, "Refresh thumbnail"); } if (!isFolder) { b = cm.AddButton(2, "Reimport"); b.Enabled = proxy != null && proxy.CanReimport(item); if (item is BinaryAssetItem binaryAsset) { string importPath; if (!binaryAsset.GetImportPath(out importPath)) { string importLocation = System.IO.Path.GetDirectoryName(importPath); if (!string.IsNullOrEmpty(importLocation) && System.IO.Directory.Exists(importLocation)) { b = cm.AddButton(8, "Show import location"); } } } } cm.AddButton(3, "Delete"); cm.AddSeparator(); // TODO: exportig assets //b = cm.AddButton(4, "Export"); //b.Enabled = proxy != null && proxy.CanExport; b = cm.AddButton(5, "Clone"); b.Enabled = !isFolder; b = cm.AddButton(6, "Rename"); cm.AddButton(7, "Copy name to Clipboard"); cm.AddButton(17, "Copy path to Clipboard"); } else { cm.AddButton(14, "Show in explorer"); b = cm.AddButton(13, "Refresh"); b = cm.AddButton(16, "Refresh all thumbnails"); } cm.AddSeparator(); cm.AddButton(10, "New folder"); c = cm.AddChildMenu("New"); c.ContextMenu.Tag = item; c.ContextMenu.OnButtonClicked += OnItemCMButtonClicked; for (int i = 0; i < Editor.ContentDatabase.Proxy.Count; i++) { var p = Editor.ContentDatabase.Proxy[i]; if (p.CanCreate(folder)) { c.ContextMenu.AddButton(CM_SPAWN_BUTTON_ID_START + i, p.Name); } } c.Enabled = c.ContextMenu.HasChildren; if (folder.CanHaveAssets) { cm.AddButton(12, "Import file"); } // Show it cm.Show(this, location); }
/// <summary> /// Creates the context menu for the current objects selection and the current Editor state. /// </summary> /// <returns>The context menu.</returns> private ContextMenu CreateContextMenu() { // Prepare bool hasSthSelected = Editor.SceneEditing.HasSthSelected; bool isSingleActorSelected = Editor.SceneEditing.SelectionCount == 1 && Editor.SceneEditing.Selection[0] is ActorNode; bool canEditScene = Editor.StateMachine.CurrentState.CanEditScene && SceneManager.IsAnySceneLoaded; // Create popup var contextMenu = new ContextMenu(); contextMenu.MinimumWidth = 120; // Expand/collapse var b = contextMenu.AddButton("Expand All", OnExpandAllClicked); b.Enabled = hasSthSelected; b = contextMenu.AddButton("Collapse All", OnCollapseAllClicked); b.Enabled = hasSthSelected; contextMenu.AddSeparator(); // Basic editing options b = contextMenu.AddButton("Rename", Rename); b.Enabled = isSingleActorSelected; b = contextMenu.AddButton("Duplicate", Editor.SceneEditing.Duplicate); b.Enabled = hasSthSelected; b = contextMenu.AddButton("Delete", Editor.SceneEditing.Delete); b.Enabled = hasSthSelected; contextMenu.AddSeparator(); b = contextMenu.AddButton("Copy", Editor.SceneEditing.Copy); b.Enabled = hasSthSelected; contextMenu.AddButton("Paste", Editor.SceneEditing.Paste); b = contextMenu.AddButton("Cut", Editor.SceneEditing.Cut); b.Enabled = canEditScene; // Prefab options contextMenu.AddSeparator(); b = contextMenu.AddButton("Create Prefab", Editor.Prefabs.CreatePrefab); b.Enabled = isSingleActorSelected && (Editor.SceneEditing.Selection[0] as ActorNode).CanCreatePrefab && Editor.Windows.ContentWin.CurrentViewFolder.CanHaveAssets; bool hasPrefabLink = canEditScene && isSingleActorSelected && (Editor.SceneEditing.Selection[0] as ActorNode).HasPrefabLink; b = contextMenu.AddButton("Select Prefab", Editor.Prefabs.SelectPrefab); b.Enabled = hasPrefabLink; b = contextMenu.AddButton("Break Prefab Link", Editor.Prefabs.BreakLinks); b.Enabled = hasPrefabLink; // Spawning actors options contextMenu.AddSeparator(); var spawnMenu = contextMenu.AddChildMenu("New"); var newActorCm = spawnMenu.ContextMenu; for (int i = 0; i < SpawnActorsGroups.Length; i++) { var group = SpawnActorsGroups[i]; if (group.Types.Length == 1) { var type = group.Types[0].Value; newActorCm.AddButton(group.Types[0].Key, () => Spawn(type)); } else { var groupCm = newActorCm.AddChildMenu(group.Name).ContextMenu; for (int j = 0; j < group.Types.Length; j++) { var type = group.Types[j].Value; groupCm.AddButton(group.Types[j].Key, () => Spawn(type)); } } } // Custom options ContextMenuShow?.Invoke(contextMenu); return(contextMenu); }
private void ShowContextMenuForItem(ContentItem item, ref Vector2 location) { // TODO: verify this logic during elements searching Assert.IsNull(_newElement); // Cache data bool isValidElement = item != null; var proxy = Editor.ContentDatabase.GetProxy(item); ContentFolder folder = null; bool isFolder = false; if (isValidElement) { isFolder = item.IsFolder; folder = isFolder ? (ContentFolder)item : item.ParentFolder; } else { folder = CurrentViewFolder; } Assert.IsNotNull(folder); // Create context menu ContextMenuButton b; ContextMenuChildMenu c; ContextMenu cm = new ContextMenu(); cm.Tag = item; if (isValidElement) { b = cm.AddButton("Open", () => Open(item)); b.Enabled = proxy != null || isFolder; cm.AddButton("Show in explorer", () => Application.StartProcess(System.IO.Path.GetDirectoryName(item.Path))); if (item.HasDefaultThumbnail == false) { cm.AddButton("Refresh thumbnail", item.RefreshThumbnail); } if (!isFolder) { b = cm.AddButton("Reimport", ReimportSelection); b.Enabled = proxy != null && proxy.CanReimport(item); if (item is BinaryAssetItem binaryAsset) { string importPath; if (!binaryAsset.GetImportPath(out importPath)) { string importLocation = System.IO.Path.GetDirectoryName(importPath); if (!string.IsNullOrEmpty(importLocation) && System.IO.Directory.Exists(importLocation)) { cm.AddButton("Show import location", () => Application.StartProcess(importLocation)); } } } } cm.AddButton("Delete", () => Delete(item)); cm.AddSeparator(); // TODO: exportig assets //b = cm.AddButton(4, "Export"); //b.Enabled = proxy != null && proxy.CanExport; b = cm.AddButton("Clone", _view.DuplicateSelection); b.Enabled = !isFolder; cm.AddButton("Rename", () => Rename(item)); cm.AddButton("Copy name to Clipboard", () => Application.ClipboardText = item.NamePath); cm.AddButton("Copy path to Clipboard", () => Application.ClipboardText = item.Path); } else { cm.AddButton("Show in explorer", () => Application.StartProcess(CurrentViewFolder.Path)); cm.AddButton("Refresh", () => Editor.ContentDatabase.RefreshFolder(CurrentViewFolder, true)); cm.AddButton("Refresh all thumbnails", RefreshViewItemsThumbnails); } cm.AddSeparator(); cm.AddButton("New folder", NewFolder); c = cm.AddChildMenu("New"); c.ContextMenu.Tag = item; for (int i = 0; i < Editor.ContentDatabase.Proxy.Count; i++) { var p = Editor.ContentDatabase.Proxy[i]; if (p.CanCreate(folder)) { c.ContextMenu.AddButton(p.Name, () => NewItem(p)); } } c.Enabled = c.ContextMenu.HasChildren; if (folder.CanHaveAssets) { cm.AddButton("Import file", () => { _view.ClearSelection(); Editor.ContentImporting.ShowImportFileDialog(CurrentViewFolder); }); } // Show it cm.Show(this, location); }