mirror of
https://github.com/ckaczor/sqltoolsservice.git
synced 2026-01-13 17:23:02 -05:00
Add ability to only show folders in File Browser dialogs (#2238)
This commit is contained in:
@@ -25,7 +25,7 @@ namespace Microsoft.SqlTools.ServiceLayer.FileBrowser.Contracts
|
||||
public string ExpandPath;
|
||||
|
||||
/// <summary>
|
||||
/// File extension filter (e.g. *.bak)
|
||||
/// File extension filter (e.g. *.bak). Ignored if <see cref="ShowFoldersOnly"/> is set to <c>true</c>.
|
||||
/// </summary>
|
||||
public string[] FileFilters;
|
||||
|
||||
@@ -33,6 +33,11 @@ namespace Microsoft.SqlTools.ServiceLayer.FileBrowser.Contracts
|
||||
/// True if this is a request to change file filter
|
||||
/// </summary>
|
||||
public bool ChangeFilter;
|
||||
|
||||
/// <summary>
|
||||
/// Whether to only show folders in the file browser.
|
||||
/// </summary>
|
||||
public bool? ShowFoldersOnly;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
|
||||
@@ -26,19 +26,23 @@ namespace Microsoft.SqlTools.ServiceLayer.FileBrowser
|
||||
private bool fileTreeCreated;
|
||||
private CancellationTokenSource cancelSource;
|
||||
private CancellationToken cancelToken;
|
||||
private bool showFoldersOnly;
|
||||
|
||||
#region Constructors
|
||||
|
||||
/// <summary>
|
||||
/// Initializes a new instance of the <see cref="FileBrowser"/> class.
|
||||
/// </summary>
|
||||
/// <param name="connection">The connection object</param>
|
||||
/// <param name="fileFilters">The file extension filters</param>
|
||||
public FileBrowserOperation(ServerConnection connection, string expandPath, string[] fileFilters = null)
|
||||
/// <param name="connection">The connection object.</param>
|
||||
/// <param name="expandPath">The initial folder to open in the file dialog.</param>
|
||||
/// <param name="fileFilters">The file extension filters. Ignored if <see cref="showFoldersOnly"/> is set to <c>true</c>.</param>
|
||||
/// <param name="showFoldersOnly">Whether to only show folders in the file browser.</param>
|
||||
public FileBrowserOperation(ServerConnection connection, string expandPath, string[] fileFilters = null, bool? showFoldersOnly = null)
|
||||
{
|
||||
this.cancelSource = new CancellationTokenSource();
|
||||
this.cancelToken = cancelSource.Token;
|
||||
this.connection = connection;
|
||||
this.showFoldersOnly = showFoldersOnly ?? false;
|
||||
this.Initialize(expandPath, fileFilters);
|
||||
}
|
||||
|
||||
@@ -236,9 +240,10 @@ namespace Microsoft.SqlTools.ServiceLayer.FileBrowser
|
||||
}
|
||||
treeNode.IsFile = isFile;
|
||||
|
||||
// if the node is a directory, or if we are browsing for files and the file name is allowed,
|
||||
// add the node to the tree
|
||||
if (!isFile || (this.FilterFile(treeNode.Name, this.fileFilters)))
|
||||
// If the node is a directory, or if we are browsing for files and the file name is allowed,
|
||||
// add the node to the tree. Files will be skipped instead if the dialog is only showing folders,
|
||||
// regardless of any provided file filters.
|
||||
if (!isFile || (this.FilterFile(treeNode.Name, this.fileFilters) && !this.showFoldersOnly))
|
||||
{
|
||||
children.Add(treeNode);
|
||||
}
|
||||
|
||||
@@ -232,7 +232,7 @@ namespace Microsoft.SqlTools.ServiceLayer.FileBrowser
|
||||
{
|
||||
if (!fileBrowserParams.ChangeFilter)
|
||||
{
|
||||
browser = new FileBrowserOperation(bindingContext.ServerConnection, fileBrowserParams.ExpandPath, fileBrowserParams.FileFilters);
|
||||
browser = new FileBrowserOperation(bindingContext.ServerConnection, fileBrowserParams.ExpandPath, fileBrowserParams.FileFilters, fileBrowserParams.ShowFoldersOnly);
|
||||
}
|
||||
else
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user