Select multiple items in project explorer with ctrl and shift

This commit is contained in:
dexy 2020-01-15 19:00:19 +11:00
parent 95e2a8ec0f
commit 5cd2ebdd85
4 changed files with 93 additions and 8 deletions

View File

@ -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<TreeNode> SelectedNodes = new List<TreeNode>();
public ProjectExplorerPanel(ProjectForm projectForm)
{
@ -2265,9 +2266,73 @@ namespace CodeWalker.Project.Panels
private void ProjectTreeView_AfterSelect(object sender, TreeViewEventArgs e)
{
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<object>();
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)
{
if (ProjectTreeView.SelectedNode != null)

View File

@ -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)

View File

@ -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;

View File

@ -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);
}