mirror of
https://github.com/ckaczor/sqltoolsservice.git
synced 2026-02-17 02:51:45 -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;
|
public string OwnerUri;
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Expanded node
|
/// Expand path
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public FileTreeNode ExpandedNode;
|
public string ExpandPath;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Children nodes
|
||||||
|
/// </summary>
|
||||||
|
public FileTreeNode[] Children;
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Result of the operation
|
/// Result of the operation
|
||||||
|
|||||||
@@ -23,7 +23,7 @@ namespace Microsoft.SqlTools.ServiceLayer.FileBrowser.Contracts
|
|||||||
/// <summary>
|
/// <summary>
|
||||||
/// List of children nodes
|
/// List of children nodes
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public List<FileTreeNode> Children { get; private set; }
|
public List<FileTreeNode> Children { get; set; }
|
||||||
|
|
||||||
// Indicates if the node is expanded, applicable to a folder.
|
// Indicates if the node is expanded, applicable to a folder.
|
||||||
public bool IsExpanded { get; set; }
|
public bool IsExpanded { get; set; }
|
||||||
|
|||||||
@@ -52,7 +52,7 @@ namespace Microsoft.SqlTools.ServiceLayer.FileBrowser
|
|||||||
|
|
||||||
#endregion
|
#endregion
|
||||||
|
|
||||||
#region public properties and methods
|
#region public properties
|
||||||
|
|
||||||
public FileTree FileTree
|
public FileTree FileTree
|
||||||
{
|
{
|
||||||
@@ -70,6 +70,8 @@ namespace Microsoft.SqlTools.ServiceLayer.FileBrowser
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#endregion
|
||||||
|
|
||||||
public void PopulateFileTree()
|
public void PopulateFileTree()
|
||||||
{
|
{
|
||||||
this.PathSeparator = GetPathSeparator(this.Enumerator, this.sqlConnection);
|
this.PathSeparator = GetPathSeparator(this.Enumerator, this.sqlConnection);
|
||||||
@@ -107,7 +109,7 @@ namespace Microsoft.SqlTools.ServiceLayer.FileBrowser
|
|||||||
currentNode.IsExpanded = true;
|
currentNode.IsExpanded = true;
|
||||||
if (!currentNode.IsFile)
|
if (!currentNode.IsFile)
|
||||||
{
|
{
|
||||||
PopulateFileNode(currentNode);
|
currentNode.Children = this.GetChildren(currentNode.FullPath);
|
||||||
}
|
}
|
||||||
currentChildren = currentNode.Children;
|
currentChildren = currentNode.Children;
|
||||||
lastNode = currentNode;
|
lastNode = currentNode;
|
||||||
@@ -129,38 +131,10 @@ namespace Microsoft.SqlTools.ServiceLayer.FileBrowser
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#endregion
|
public List<FileTreeNode> GetChildren(string filepath)
|
||||||
|
|
||||||
private void PopulateDrives()
|
|
||||||
{
|
{
|
||||||
bool first = true;
|
List<FileTreeNode> children = new List<FileTreeNode>();
|
||||||
foreach (var fileInfo in EnumerateDrives(Enumerator, sqlConnection))
|
foreach (var file in EnumerateFilesInFolder(Enumerator, sqlConnection, filepath))
|
||||||
{
|
|
||||||
// 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))
|
|
||||||
{
|
{
|
||||||
bool isFile = !string.IsNullOrEmpty(file.fileName);
|
bool isFile = !string.IsNullOrEmpty(file.fileName);
|
||||||
FileTreeNode treeNode = new FileTreeNode();
|
FileTreeNode treeNode = new FileTreeNode();
|
||||||
@@ -180,9 +154,35 @@ namespace Microsoft.SqlTools.ServiceLayer.FileBrowser
|
|||||||
// add the node to the tree
|
// add the node to the tree
|
||||||
if (!isFile || (this.FilterFile(treeNode.Name, this.fileFilters)))
|
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>
|
/// <summary>
|
||||||
|
|||||||
@@ -230,9 +230,9 @@ namespace Microsoft.SqlTools.ServiceLayer.FileBrowser
|
|||||||
if (this.ownerToFileBrowserMap.ContainsKey(fileBrowserParams.OwnerUri))
|
if (this.ownerToFileBrowserMap.ContainsKey(fileBrowserParams.OwnerUri))
|
||||||
{
|
{
|
||||||
FileBrowserOperation browser = this.ownerToFileBrowserMap[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.OwnerUri = fileBrowserParams.OwnerUri;
|
||||||
result.ExpandedNode = browser.FileTree.SelectedNode;
|
|
||||||
result.Succeeded = true;
|
result.Succeeded = true;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
|
|||||||
@@ -288,9 +288,8 @@ CREATE CERTIFICATE {1} WITH SUBJECT = 'Backup Encryption Certificate'; ";
|
|||||||
// Verify result
|
// Verify result
|
||||||
serviceHostMock.Verify(x => x.SendEvent(FileBrowserExpandedNotification.Type,
|
serviceHostMock.Verify(x => x.SendEvent(FileBrowserExpandedNotification.Type,
|
||||||
It.Is<FileBrowserExpandedParams>(p => p.Succeeded == true
|
It.Is<FileBrowserExpandedParams>(p => p.Succeeded == true
|
||||||
&& p.ExpandedNode != null
|
&& p.Children != null
|
||||||
&& p.ExpandedNode.Children != null
|
&& p.Children.Length > 0)),
|
||||||
&& p.ExpandedNode.Children.Count > 0)),
|
|
||||||
Times.Once());
|
Times.Once());
|
||||||
|
|
||||||
var validateParams = new FileBrowserValidateParams
|
var validateParams = new FileBrowserValidateParams
|
||||||
|
|||||||
Reference in New Issue
Block a user