Skip to content

Commit

Permalink
Fixed #606 menu to add more nodes of same type
Browse files Browse the repository at this point in the history
  • Loading branch information
rappen committed Dec 29, 2021
1 parent 6cd27b4 commit 80ce6bb
Show file tree
Hide file tree
Showing 7 changed files with 156 additions and 126 deletions.
1 change: 0 additions & 1 deletion FXBEditorUtils/FXBEditorUtils.projitems
Expand Up @@ -16,6 +16,5 @@
<Compile Include="$(MSBuildThisFileDirectory)ListViewItemComparer.cs" />
<Compile Include="$(MSBuildThisFileDirectory)Prompt.cs" />
<Compile Include="$(MSBuildThisFileDirectory)SaveEventArgs.cs" />
<Compile Include="$(MSBuildThisFileDirectory)TreeNodeCapabilities.cs" />
</ItemGroup>
</Project>
60 changes: 0 additions & 60 deletions FXBEditorUtils/TreeNodeCapabilities.cs

This file was deleted.

121 changes: 90 additions & 31 deletions FetchXmlBuilder/AppCode/FetchNodeCapabilities.cs
@@ -1,63 +1,122 @@
using Cinteros.Xrm.XmlEditorUtils;
using System.Collections.Generic;
using System.Windows.Forms;

namespace Cinteros.Xrm.FetchXmlBuilder.AppCode
{
public class FetchNodeCapabilities : TreeNodeCapabilities
public class FetchNodeCapabilities
{
public FetchNodeCapabilities(TreeNode node)
: base(node)
public string Name;
public bool Multiple = true;
public bool Delete = true;
public bool Attributes = false;
public bool Comment = true;
public bool Uncomment = false;
public List<FetchNodeCapabilities> ChildTypes;

public FetchNodeCapabilities(string name, bool addchildren) : this(name)
{
if (addchildren)
{
AddChildren();
}
}

private FetchNodeCapabilities(string name)
{
Name = name;
switch (Name)
{
case "fetch":
Multiple = false;
Delete = false;
Comment = false;
ChildTypes.Add(new ChildNodeCapabilities("entity", false));
ChildTypes.Add(new ChildNodeCapabilities("-", true));
ChildTypes.Add(new ChildNodeCapabilities("#comment", true));
break;
case "entity":
Multiple = false;
Attributes = true;
break;
case "link-entity":
Delete = true;
Attributes = true;
ChildTypes.Add(new ChildNodeCapabilities("-", true));
ChildTypes.Add(new ChildNodeCapabilities("all-attributes", false));
ChildTypes.Add(new ChildNodeCapabilities("attribute", true));
ChildTypes.Add(new ChildNodeCapabilities("filter", true));
ChildTypes.Add(new ChildNodeCapabilities("order", true));
ChildTypes.Add(new ChildNodeCapabilities("link-entity", true));
ChildTypes.Add(new ChildNodeCapabilities("-", true));
ChildTypes.Add(new ChildNodeCapabilities("#comment", true));
break;
case "all-attributes":
Multiple = false;
break;
case "attribute":
case "order":
Delete = true;
ChildTypes.Add(new ChildNodeCapabilities("#comment", true));
case "filter":
case "condition":
case "value":
break;
case "#comment":
Comment = false;
Uncomment = true;
break;
}
}

private void AddChildren()
{
ChildTypes = new List<FetchNodeCapabilities>();
switch (Name)
{
case "fetch":
ChildTypes.Add(new FetchNodeCapabilities("entity"));
ChildTypes.Add(new FetchNodeCapabilities("-"));
ChildTypes.Add(new FetchNodeCapabilities("#comment"));
break;
case "entity":
case "link-entity":
ChildTypes.Add(new FetchNodeCapabilities("-"));
ChildTypes.Add(new FetchNodeCapabilities("all-attributes"));
ChildTypes.Add(new FetchNodeCapabilities("attribute"));
ChildTypes.Add(new FetchNodeCapabilities("filter"));
ChildTypes.Add(new FetchNodeCapabilities("order"));
ChildTypes.Add(new FetchNodeCapabilities("link-entity"));
ChildTypes.Add(new FetchNodeCapabilities("-"));
ChildTypes.Add(new FetchNodeCapabilities("#comment"));
break;
case "all-attributes":
case "attribute":
case "order":
ChildTypes.Add(new FetchNodeCapabilities("#comment"));
break;
case "filter":
Delete = true;
ChildTypes.Add(new ChildNodeCapabilities("condition", true));
ChildTypes.Add(new ChildNodeCapabilities("filter", true));
ChildTypes.Add(new ChildNodeCapabilities("-", true));
ChildTypes.Add(new ChildNodeCapabilities("#comment", true));
ChildTypes.Add(new FetchNodeCapabilities("condition"));
ChildTypes.Add(new FetchNodeCapabilities("filter"));
ChildTypes.Add(new FetchNodeCapabilities("-"));
ChildTypes.Add(new FetchNodeCapabilities("#comment"));
break;
case "condition":
Delete = true;
ChildTypes.Add(new ChildNodeCapabilities("value", true));
ChildTypes.Add(new ChildNodeCapabilities("-", true));
ChildTypes.Add(new ChildNodeCapabilities("#comment", true));
ChildTypes.Add(new FetchNodeCapabilities("value"));
ChildTypes.Add(new FetchNodeCapabilities("-"));
ChildTypes.Add(new FetchNodeCapabilities("#comment"));
break;
case "value":
Delete = true;
ChildTypes.Add(new ChildNodeCapabilities("#comment", true));
ChildTypes.Add(new FetchNodeCapabilities("#comment"));
break;
case "#comment":
Delete = true;
Comment = false;
Uncomment = true;
break;
}
}

public int IndexOfChild(string name)
{
var index = 0;
while (index < ChildTypes.Count && ChildTypes[index].Name != name)
{
index++;
}
if (index >= ChildTypes.Count)
{
index = -1;
}
return index;
}

public override string ToString()
{
return Name + " (" + (ChildTypes != null ? ChildTypes.Count.ToString() : "?") + ")";
}
}
}
39 changes: 26 additions & 13 deletions FetchXmlBuilder/AppCode/TreeNodeHelper.cs
Expand Up @@ -57,7 +57,6 @@ public static TreeNode AddTreeViewNode(object parentObject, XmlNode xmlNode, Tre
throw new Exception("AddTreeViewNode: Unsupported control type");
}
node.Tag = attributes;
AddContextMenu(node, tree);
foreach (XmlNode childNode in xmlNode.ChildNodes)
{
AddTreeViewNode(node, childNode, tree, fxb);
Expand Down Expand Up @@ -292,8 +291,14 @@ public static void AddContextMenu(TreeNode node, TreeBuilderControl tree)
}
if (node != null)
{
var nodecapabilities = new FetchNodeCapabilities(node);
var nodecapabilities = new FetchNodeCapabilities(node.Name, true);

if (nodecapabilities.Multiple)
{
tree.addOneMoreToolStripMenuItem.Text = "More " + nodecapabilities.Name;
tree.addOneMoreToolStripMenuItem.Tag = "MORE-" + nodecapabilities.Name;
AddLinkFromCapability(tree, "+" + nodecapabilities.Name, "MORE-" + nodecapabilities.Name);
}
if (nodecapabilities.Attributes && tree.selectAttributesToolStripMenuItem.Enabled)
{
AddLinkFromCapability(tree, "Select Attributes", "SelectAttributes");
Expand All @@ -316,6 +321,7 @@ public static void AddContextMenu(TreeNode node, TreeBuilderControl tree)
dummy.Enabled = false;
}

tree.addOneMoreToolStripMenuItem.Visible = nodecapabilities.Multiple;
tree.selectAttributesToolStripMenuItem.Visible = nodecapabilities.Attributes;
tree.deleteToolStripMenuItem.Enabled = nodecapabilities.Delete;
tree.commentToolStripMenuItem.Enabled = nodecapabilities.Comment;
Expand Down Expand Up @@ -421,7 +427,7 @@ internal static void AddXmlNode(TreeNode currentNode, XmlNode parentXmlNode)
parentXmlNode.AppendChild(newNode);
}

internal static TreeNode AddChildNode(TreeNode parentNode, string name)
internal static TreeNode AddChildNode(TreeNode parentNode, string name, TreeNode sisterNode = null)
{
var childNode = new TreeNode(name);
childNode.Tag = new Dictionary<string, string>();
Expand All @@ -432,20 +438,27 @@ internal static TreeNode AddChildNode(TreeNode parentNode, string name)
}
if (parentNode != null)
{
var parentCap = new FetchNodeCapabilities(parentNode);
var nodeIndex = parentCap.IndexOfChild(name);
var pos = 0;
while (pos < parentNode.Nodes.Count && nodeIndex >= parentCap.IndexOfChild(parentNode.Nodes[pos].Name))
{
pos++;
}
if (pos == parentNode.Nodes.Count)
if (sisterNode != null)
{
parentNode.Nodes.Add(childNode);
parentNode.Nodes.Insert(sisterNode.Index + 1, childNode);
}
else
{
parentNode.Nodes.Insert(pos, childNode);
var parentCap = new FetchNodeCapabilities(parentNode.Name, true);
var nodeIndex = parentCap.IndexOfChild(name);
var pos = 0;
while (pos < parentNode.Nodes.Count && nodeIndex >= parentCap.IndexOfChild(parentNode.Nodes[pos].Name))
{
pos++;
}
if (pos == parentNode.Nodes.Count)
{
parentNode.Nodes.Add(childNode);
}
else
{
parentNode.Nodes.Insert(pos, childNode);
}
}
}
return childNode;
Expand Down
11 changes: 11 additions & 0 deletions FetchXmlBuilder/DockControls/TreeBuilderControl.cs
Expand Up @@ -469,6 +469,10 @@ private void DisplayDefinition(XmlDocument fetchDoc)
tvFetch.Nodes.Clear();
TreeNodeHelper.AddTreeViewNode(tvFetch, definitionXmlNode, this, fxb);
tvFetch.ExpandAll();
if (tvFetch.Nodes.Count > 0)
{
tvFetch.SelectedNode = tvFetch.Nodes[0];
}
ManageMenuDisplay();
}

Expand Down Expand Up @@ -564,6 +568,13 @@ private void HandleNodeMenuClick(string ClickedTag)
{
SelectAttributes();
}
else if (ClickedTag.StartsWith("MORE-"))
{
var nodename = ClickedTag.Substring(5);
updateNode = TreeNodeHelper.AddChildNode(tvFetch.SelectedNode.Parent, nodename, tvFetch.SelectedNode);
RecordHistory("add " + updateNode.Name);
HandleNodeSelection(updateNode);
}
else
{
updateNode = TreeNodeHelper.AddChildNode(tvFetch.SelectedNode, ClickedTag);
Expand Down
11 changes: 10 additions & 1 deletion FetchXmlBuilder/DockControls/TreeBuilderControl.designer.cs

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 80ce6bb

Please sign in to comment.