diff --git a/Project/Panels/ProjectExplorerPanel.cs b/Project/Panels/ProjectExplorerPanel.cs index 67786a8..bf5ccd4 100644 --- a/Project/Panels/ProjectExplorerPanel.cs +++ b/Project/Panels/ProjectExplorerPanel.cs @@ -20,6 +20,7 @@ namespace CodeWalker.Project.Panels public ProjectFile CurrentProjectFile { get; set; } private bool inDoubleClick = false; //used in disabling double-click to expand tree nodes + private List SelectedNodes = new List(); public ProjectExplorerPanel(ProjectForm projectForm) { @@ -2266,7 +2267,71 @@ namespace CodeWalker.Project.Panels private void ProjectTreeView_AfterSelect(object sender, TreeViewEventArgs e) { - OnItemSelected?.Invoke(ProjectTreeView.SelectedNode?.Tag); + bool addSelection = (ModifierKeys & Keys.Control) > 0; + bool fillSelection = (ModifierKeys & Keys.Shift) > 0; + if (addSelection) + { + if (SelectedNodes.Contains(e.Node)) + { + SelectedNodes.Remove(e.Node); + } + else + { + SelectedNodes.Add(e.Node); + } + } + else if (fillSelection) + { + var snode = (SelectedNodes.Count == 0) ? null : SelectedNodes[SelectedNodes.Count - 1]; + var pnode = snode?.Parent; + + if ((pnode == null) || (pnode != e.Node?.Parent)) + { + SelectedNodes.Add(e.Node); + } + else + { + bool start = false; + SelectedNodes.Clear(); + foreach (TreeNode cnode in pnode.Nodes) + { + if (start) + { + SelectedNodes.Add(cnode); + } + if (cnode == snode) + { + if (start) break; + else start = true; + SelectedNodes.Add(cnode); + } + if (cnode == e.Node) + { + if (start) break; + else start = true; + SelectedNodes.Add(cnode); + } + } + } + } + else + { + SelectedNodes.Clear(); + SelectedNodes.Add(e.Node); + } + if (SelectedNodes.Count > 1) + { + var objs = new List(); + foreach (var node in SelectedNodes) + { + objs.Add(node.Tag); + } + OnItemSelected?.Invoke(objs.ToArray()); + } + else + { + OnItemSelected?.Invoke(ProjectTreeView.SelectedNode?.Tag); + } } private void ProjectTreeView_DoubleClick(object sender, EventArgs e) { diff --git a/Project/ProjectForm.cs b/Project/ProjectForm.cs index b0bfafe..76f1234 100644 --- a/Project/ProjectForm.cs +++ b/Project/ProjectForm.cs @@ -711,6 +711,12 @@ namespace CodeWalker.Project } public void ShowProjectItem(object item, bool promote) { + if (item is object[] arr) + { + var multisel = MapSelection.FromProjectObject(arr); //convert to MapSelection array + item = multisel.MultipleSelectionItems; + } + ShowProjectItemInProcess = true; SetProjectItem(item); @@ -724,6 +730,11 @@ namespace CodeWalker.Project ShowCurrentProjectItem(promote); } + if (item is MapSelection[] multi) + { + WorldForm?.SelectMulti(multi, false, false); + } + ShowProjectItemInProcess = false; } public void SetProjectItem(object item, bool refreshUI = true) diff --git a/World/MapSelection.cs b/World/MapSelection.cs index 2ee32ea..46dc2ba 100644 --- a/World/MapSelection.cs +++ b/World/MapSelection.cs @@ -1291,7 +1291,16 @@ namespace CodeWalker { const float nrad = 0.5f; var ms = new MapSelection(); - if (o is YmapEntityDef entity) + if (o is object[] arr) + { + var multi = new MapSelection[arr.Length]; + for (int i = 0; i < arr.Length; i++) + { + multi[i] = FromProjectObject(arr[i]); + } + ms.SetMultipleSelectionItems(multi); + } + else if (o is YmapEntityDef entity) { ms.EntityDef = entity; ms.Archetype = entity?.Archetype; diff --git a/WorldForm.cs b/WorldForm.cs index ffff04d..054a0b4 100644 --- a/WorldForm.cs +++ b/WorldForm.cs @@ -3301,7 +3301,7 @@ namespace CodeWalker } } } - public void SelectItem(MapSelection? mhit = null, bool addSelection = false, bool manualSelection = false) + public void SelectItem(MapSelection? mhit = null, bool addSelection = false, bool manualSelection = false, bool notifyProject = true) { var mhitv = mhit.HasValue ? mhit.Value : new MapSelection(); if (mhit != null) @@ -3464,25 +3464,25 @@ namespace CodeWalker } } } - if (change && (ProjectForm != null) && (!addSelection || manualSelection)) + if (notifyProject && change && (ProjectForm != null) && (!addSelection || manualSelection)) { ProjectForm.OnWorldSelectionChanged(SelectedItem); } } - public void SelectMulti(MapSelection[] items, bool addSelection = false) + public void SelectMulti(MapSelection[] items, bool addSelection = false, bool notifyProject = true) { - SelectItem(null, addSelection); + SelectItem(null, addSelection, false, notifyProject); if (items != null) { foreach (var item in items) { - SelectItem(item, true); + SelectItem(item, true, false, notifyProject); } if (!addSelection) { UpdateSelectionUI(true); } - if ((ProjectForm != null) && !addSelection) + if (notifyProject && (ProjectForm != null) && !addSelection) { ProjectForm.OnWorldSelectionChanged(SelectedItem); }