Add ability to only show folders in File Browser dialogs (#2238)

This commit is contained in:
Cory Rivera
2023-09-12 15:52:13 -07:00
committed by GitHub
parent 1b886c4380
commit 8a72707c60
3 changed files with 18 additions and 8 deletions

View File

@@ -25,7 +25,7 @@ namespace Microsoft.SqlTools.ServiceLayer.FileBrowser.Contracts
public string ExpandPath; public string ExpandPath;
/// <summary> /// <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> /// </summary>
public string[] FileFilters; public string[] FileFilters;
@@ -33,6 +33,11 @@ namespace Microsoft.SqlTools.ServiceLayer.FileBrowser.Contracts
/// True if this is a request to change file filter /// True if this is a request to change file filter
/// </summary> /// </summary>
public bool ChangeFilter; public bool ChangeFilter;
/// <summary>
/// Whether to only show folders in the file browser.
/// </summary>
public bool? ShowFoldersOnly;
} }
/// <summary> /// <summary>

View File

@@ -26,19 +26,23 @@ namespace Microsoft.SqlTools.ServiceLayer.FileBrowser
private bool fileTreeCreated; private bool fileTreeCreated;
private CancellationTokenSource cancelSource; private CancellationTokenSource cancelSource;
private CancellationToken cancelToken; private CancellationToken cancelToken;
private bool showFoldersOnly;
#region Constructors #region Constructors
/// <summary> /// <summary>
/// Initializes a new instance of the <see cref="FileBrowser"/> class. /// Initializes a new instance of the <see cref="FileBrowser"/> class.
/// </summary> /// </summary>
/// <param name="connection">The connection object</param> /// <param name="connection">The connection object.</param>
/// <param name="fileFilters">The file extension filters</param> /// <param name="expandPath">The initial folder to open in the file dialog.</param>
public FileBrowserOperation(ServerConnection connection, string expandPath, string[] fileFilters = null) /// <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.cancelSource = new CancellationTokenSource();
this.cancelToken = cancelSource.Token; this.cancelToken = cancelSource.Token;
this.connection = connection; this.connection = connection;
this.showFoldersOnly = showFoldersOnly ?? false;
this.Initialize(expandPath, fileFilters); this.Initialize(expandPath, fileFilters);
} }
@@ -236,9 +240,10 @@ namespace Microsoft.SqlTools.ServiceLayer.FileBrowser
} }
treeNode.IsFile = isFile; treeNode.IsFile = isFile;
// if the node is a directory, or if we are browsing for files and the file name is allowed, // 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 // add the node to the tree. Files will be skipped instead if the dialog is only showing folders,
if (!isFile || (this.FilterFile(treeNode.Name, this.fileFilters))) // regardless of any provided file filters.
if (!isFile || (this.FilterFile(treeNode.Name, this.fileFilters) && !this.showFoldersOnly))
{ {
children.Add(treeNode); children.Add(treeNode);
} }

View File

@@ -232,7 +232,7 @@ namespace Microsoft.SqlTools.ServiceLayer.FileBrowser
{ {
if (!fileBrowserParams.ChangeFilter) if (!fileBrowserParams.ChangeFilter)
{ {
browser = new FileBrowserOperation(bindingContext.ServerConnection, fileBrowserParams.ExpandPath, fileBrowserParams.FileFilters); browser = new FileBrowserOperation(bindingContext.ServerConnection, fileBrowserParams.ExpandPath, fileBrowserParams.FileFilters, fileBrowserParams.ShowFoldersOnly);
} }
else else
{ {