mirror of
https://github.com/ckaczor/sqltoolsservice.git
synced 2026-02-16 18:47:57 -05:00
Use object names instead of labels in node paths (#600)
This commit is contained in:
committed by
Karl Burtram
parent
92456d50aa
commit
167948256c
@@ -56,6 +56,11 @@ namespace Microsoft.SqlTools.ServiceLayer.ObjectExplorer.Nodes
|
|||||||
/// Returns the custom name of the object assigned to the node. If the object doesn't have custom name, returns empty string
|
/// Returns the custom name of the object assigned to the node. If the object doesn't have custom name, returns empty string
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public abstract string GetNodeCustomName(object smoObject, SmoQueryContext smoContext);
|
public abstract string GetNodeCustomName(object smoObject, SmoQueryContext smoContext);
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Returns the name of the object as shown in its Object Explorer node path
|
||||||
|
/// </summary>
|
||||||
|
public abstract string GetNodePathName(object smoObject);
|
||||||
|
|
||||||
public abstract bool CanCreateChild(TreeNode parent, object context);
|
public abstract bool CanCreateChild(TreeNode parent, object context);
|
||||||
public abstract TreeNode CreateChild(TreeNode parent, object context);
|
public abstract TreeNode CreateChild(TreeNode parent, object context);
|
||||||
|
|||||||
@@ -26,6 +26,7 @@ namespace Microsoft.SqlTools.ServiceLayer.ObjectExplorer.Nodes
|
|||||||
private TreeNode parent;
|
private TreeNode parent;
|
||||||
private string nodePath;
|
private string nodePath;
|
||||||
private string label;
|
private string label;
|
||||||
|
private string nodePathName;
|
||||||
public const char PathPartSeperator = '/';
|
public const char PathPartSeperator = '/';
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
@@ -62,6 +63,23 @@ namespace Microsoft.SqlTools.ServiceLayer.ObjectExplorer.Nodes
|
|||||||
/// </summary>
|
/// </summary>
|
||||||
public string NodeValue { get; set; }
|
public string NodeValue { get; set; }
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// The name of this object as included in its node path
|
||||||
|
/// </summary>
|
||||||
|
public string NodePathName {
|
||||||
|
get
|
||||||
|
{
|
||||||
|
if (string.IsNullOrEmpty(nodePathName))
|
||||||
|
{
|
||||||
|
return NodeValue;
|
||||||
|
}
|
||||||
|
return nodePathName;
|
||||||
|
}
|
||||||
|
set
|
||||||
|
{
|
||||||
|
nodePathName = value;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Object metadata for smo objects
|
/// Object metadata for smo objects
|
||||||
@@ -175,7 +193,7 @@ namespace Microsoft.SqlTools.ServiceLayer.ObjectExplorer.Nodes
|
|||||||
}
|
}
|
||||||
// Otherwise add this value to the beginning of the path and keep iterating up
|
// Otherwise add this value to the beginning of the path and keep iterating up
|
||||||
path = string.Format(CultureInfo.InvariantCulture,
|
path = string.Format(CultureInfo.InvariantCulture,
|
||||||
"{0}{1}{2}", node.NodeValue, string.IsNullOrEmpty(path) ? "" : PathPartSeperator.ToString(), path);
|
"{0}{1}{2}", node.NodePathName, string.IsNullOrEmpty(path) ? "" : PathPartSeperator.ToString(), path);
|
||||||
return true;
|
return true;
|
||||||
});
|
});
|
||||||
nodePath = path;
|
nodePath = path;
|
||||||
|
|||||||
@@ -241,6 +241,7 @@ namespace Microsoft.SqlTools.ServiceLayer.ObjectExplorer.SmoModel
|
|||||||
if (!string.IsNullOrEmpty(customizedName))
|
if (!string.IsNullOrEmpty(customizedName))
|
||||||
{
|
{
|
||||||
childAsMeItem.NodeValue = customizedName;
|
childAsMeItem.NodeValue = customizedName;
|
||||||
|
childAsMeItem.NodePathName = GetNodePathName(context);
|
||||||
}
|
}
|
||||||
|
|
||||||
childAsMeItem.NodeSubType = GetNodeSubType(context, smoContext);
|
childAsMeItem.NodeSubType = GetNodeSubType(context, smoContext);
|
||||||
@@ -321,5 +322,10 @@ namespace Microsoft.SqlTools.ServiceLayer.ObjectExplorer.SmoModel
|
|||||||
{
|
{
|
||||||
return string.Empty;
|
return string.Empty;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public override string GetNodePathName(object smoObject)
|
||||||
|
{
|
||||||
|
return (smoObject as NamedSmoObject).Name;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -184,21 +184,23 @@ namespace Microsoft.SqlTools.ServiceLayer.UnitTests.ObjectExplorer
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
[Fact]
|
||||||
public void MultiLevelTreeShouldFormatPath()
|
public void MultiLevelTreeShouldFormatPath()
|
||||||
{
|
{
|
||||||
TreeNode root = new TreeNode("root");
|
TreeNode root = new TreeNode("root");
|
||||||
Assert.Equal("/root" , root.GetNodePath());
|
Assert.Equal("root" , root.GetNodePath());
|
||||||
|
|
||||||
TreeNode level1Child1 = new TreeNode("L1C1");
|
TreeNode level1Child1 = new TreeNode("L1C1 (with extra info)");
|
||||||
|
level1Child1.NodePathName = "L1C1";
|
||||||
TreeNode level1Child2 = new TreeNode("L1C2");
|
TreeNode level1Child2 = new TreeNode("L1C2");
|
||||||
root.AddChild(level1Child1);
|
root.AddChild(level1Child1);
|
||||||
root.AddChild(level1Child2);
|
root.AddChild(level1Child2);
|
||||||
Assert.Equal("/root/L1C1" , level1Child1.GetNodePath());
|
Assert.Equal("root/L1C1" , level1Child1.GetNodePath());
|
||||||
Assert.Equal("/root/L1C2", level1Child2.GetNodePath());
|
Assert.Equal("root/L1C2", level1Child2.GetNodePath());
|
||||||
|
|
||||||
TreeNode level2Child1 = new TreeNode("L2C2");
|
TreeNode level2Child1 = new TreeNode("L2C2");
|
||||||
level1Child1.AddChild(level2Child1);
|
level1Child1.AddChild(level2Child1);
|
||||||
Assert.Equal("/root/L1C1/L2C2", level2Child1.GetNodePath());
|
Assert.Equal("root/L1C1/L2C2", level2Child1.GetNodePath());
|
||||||
}
|
}
|
||||||
|
|
||||||
[Fact]
|
[Fact]
|
||||||
|
|||||||
Reference in New Issue
Block a user