mirror of
https://github.com/ckaczor/sqltoolsservice.git
synced 2026-01-14 01:25:40 -05:00
update filebrowser expand contract and methods (#500)
This commit is contained in:
@@ -17,9 +17,14 @@ namespace Microsoft.SqlTools.ServiceLayer.FileBrowser.Contracts
|
||||
public string OwnerUri;
|
||||
|
||||
/// <summary>
|
||||
/// Expanded node
|
||||
/// Expand path
|
||||
/// </summary>
|
||||
public FileTreeNode ExpandedNode;
|
||||
public string ExpandPath;
|
||||
|
||||
/// <summary>
|
||||
/// Children nodes
|
||||
/// </summary>
|
||||
public FileTreeNode[] Children;
|
||||
|
||||
/// <summary>
|
||||
/// Result of the operation
|
||||
|
||||
@@ -23,7 +23,7 @@ namespace Microsoft.SqlTools.ServiceLayer.FileBrowser.Contracts
|
||||
/// <summary>
|
||||
/// List of children nodes
|
||||
/// </summary>
|
||||
public List<FileTreeNode> Children { get; private set; }
|
||||
public List<FileTreeNode> Children { get; set; }
|
||||
|
||||
// Indicates if the node is expanded, applicable to a folder.
|
||||
public bool IsExpanded { get; set; }
|
||||
|
||||
@@ -52,7 +52,7 @@ namespace Microsoft.SqlTools.ServiceLayer.FileBrowser
|
||||
|
||||
#endregion
|
||||
|
||||
#region public properties and methods
|
||||
#region public properties
|
||||
|
||||
public FileTree FileTree
|
||||
{
|
||||
@@ -70,6 +70,8 @@ namespace Microsoft.SqlTools.ServiceLayer.FileBrowser
|
||||
}
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
public void PopulateFileTree()
|
||||
{
|
||||
this.PathSeparator = GetPathSeparator(this.Enumerator, this.sqlConnection);
|
||||
@@ -107,7 +109,7 @@ namespace Microsoft.SqlTools.ServiceLayer.FileBrowser
|
||||
currentNode.IsExpanded = true;
|
||||
if (!currentNode.IsFile)
|
||||
{
|
||||
PopulateFileNode(currentNode);
|
||||
currentNode.Children = this.GetChildren(currentNode.FullPath);
|
||||
}
|
||||
currentChildren = currentNode.Children;
|
||||
lastNode = currentNode;
|
||||
@@ -129,38 +131,10 @@ namespace Microsoft.SqlTools.ServiceLayer.FileBrowser
|
||||
}
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
private void PopulateDrives()
|
||||
public List<FileTreeNode> GetChildren(string filepath)
|
||||
{
|
||||
bool first = true;
|
||||
foreach (var fileInfo in EnumerateDrives(Enumerator, sqlConnection))
|
||||
{
|
||||
// Windows drive letter paths have a '\' at the end. Linux drive paths won't have a '\'.
|
||||
var node = new FileTreeNode
|
||||
{
|
||||
Name = Convert.ToString(fileInfo.path, CultureInfo.InvariantCulture).TrimEnd('\\'),
|
||||
FullPath = fileInfo.path
|
||||
};
|
||||
|
||||
this.fileTree.RootNode.AddChildNode(node);
|
||||
|
||||
if (first)
|
||||
{
|
||||
this.fileTree.SelectedNode = node;
|
||||
first = false;
|
||||
}
|
||||
|
||||
PopulateFileNode(node);
|
||||
}
|
||||
}
|
||||
|
||||
private void PopulateFileNode(FileTreeNode parentNode)
|
||||
{
|
||||
string parentPath = parentNode.FullPath;
|
||||
parentNode.Children.Clear();
|
||||
|
||||
foreach (var file in EnumerateFilesInFolder(Enumerator, sqlConnection, parentPath))
|
||||
List<FileTreeNode> children = new List<FileTreeNode>();
|
||||
foreach (var file in EnumerateFilesInFolder(Enumerator, sqlConnection, filepath))
|
||||
{
|
||||
bool isFile = !string.IsNullOrEmpty(file.fileName);
|
||||
FileTreeNode treeNode = new FileTreeNode();
|
||||
@@ -180,9 +154,35 @@ namespace Microsoft.SqlTools.ServiceLayer.FileBrowser
|
||||
// add the node to the tree
|
||||
if (!isFile || (this.FilterFile(treeNode.Name, this.fileFilters)))
|
||||
{
|
||||
parentNode.AddChildNode(treeNode);
|
||||
children.Add(treeNode);
|
||||
}
|
||||
}
|
||||
|
||||
return children;
|
||||
}
|
||||
|
||||
public void PopulateDrives()
|
||||
{
|
||||
bool first = true;
|
||||
foreach (var fileInfo in EnumerateDrives(Enumerator, sqlConnection))
|
||||
{
|
||||
// Windows drive letter paths have a '\' at the end. Linux drive paths won't have a '\'.
|
||||
var node = new FileTreeNode
|
||||
{
|
||||
Name = Convert.ToString(fileInfo.path, CultureInfo.InvariantCulture).TrimEnd('\\'),
|
||||
FullPath = fileInfo.path
|
||||
};
|
||||
|
||||
this.fileTree.RootNode.AddChildNode(node);
|
||||
|
||||
if (first)
|
||||
{
|
||||
this.fileTree.SelectedNode = node;
|
||||
first = false;
|
||||
}
|
||||
|
||||
node.Children = this.GetChildren(node.FullPath);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
|
||||
@@ -230,9 +230,9 @@ namespace Microsoft.SqlTools.ServiceLayer.FileBrowser
|
||||
if (this.ownerToFileBrowserMap.ContainsKey(fileBrowserParams.OwnerUri))
|
||||
{
|
||||
FileBrowserOperation browser = this.ownerToFileBrowserMap[fileBrowserParams.OwnerUri];
|
||||
browser.ExpandSelectedNode(fileBrowserParams.ExpandPath);
|
||||
result.Children = browser.GetChildren(fileBrowserParams.ExpandPath).ToArray();
|
||||
result.ExpandPath = fileBrowserParams.ExpandPath;
|
||||
result.OwnerUri = fileBrowserParams.OwnerUri;
|
||||
result.ExpandedNode = browser.FileTree.SelectedNode;
|
||||
result.Succeeded = true;
|
||||
}
|
||||
else
|
||||
|
||||
@@ -288,9 +288,8 @@ CREATE CERTIFICATE {1} WITH SUBJECT = 'Backup Encryption Certificate'; ";
|
||||
// Verify result
|
||||
serviceHostMock.Verify(x => x.SendEvent(FileBrowserExpandedNotification.Type,
|
||||
It.Is<FileBrowserExpandedParams>(p => p.Succeeded == true
|
||||
&& p.ExpandedNode != null
|
||||
&& p.ExpandedNode.Children != null
|
||||
&& p.ExpandedNode.Children.Count > 0)),
|
||||
&& p.Children != null
|
||||
&& p.Children.Length > 0)),
|
||||
Times.Once());
|
||||
|
||||
var validateParams = new FileBrowserValidateParams
|
||||
|
||||
Reference in New Issue
Block a user