mirror of
https://mirror.ghproxy.com/https://github.com/dexyfex/CodeWalker
synced 2024-11-22 15:02:54 +08:00
Select multiple items in project explorer with ctrl and shift
This commit is contained in:
parent
95e2a8ec0f
commit
5cd2ebdd85
@ -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)
|
||||
|
@ -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)
|
||||
|
@ -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;
|
||||
|
12
WorldForm.cs
12
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);
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user