Skip to content

Commit 496e03f

Browse files
authored
Feature: Added support for displaying recently entered paths (#14301)
1 parent 3752486 commit 496e03f

File tree

4 files changed

+71
-25
lines changed

4 files changed

+71
-25
lines changed

src/Files.App/Services/Settings/GeneralSettingsService.cs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,12 @@ public List<string> LastCrashedTabList
6767
set => Set(value);
6868
}
6969

70+
public List<string> PathHistoryList
71+
{
72+
get => Get<List<string>>(null);
73+
set => Set(value);
74+
}
75+
7076
public DateTimeFormats DateTimeFormat
7177
{
7278
get => Get(DateTimeFormats.Application);

src/Files.App/Services/Settings/UserSettingsService.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,7 @@ public override object ExportSettings()
7272
// Remove session settings
7373
export.Remove(nameof(GeneralSettingsService.LastSessionTabList));
7474
export.Remove(nameof(GeneralSettingsService.LastCrashedTabList));
75+
export.Remove(nameof(GeneralSettingsService.PathHistoryList));
7576

7677
return JsonSettingsSerializer.SerializeToJson(export);
7778
}

src/Files.App/ViewModels/UserControls/ToolbarViewModel.cs

Lines changed: 59 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,8 @@ namespace Files.App.ViewModels.UserControls
1717
{
1818
public class ToolbarViewModel : ObservableObject, IAddressToolbar, IDisposable
1919
{
20+
private const int MAX_SUGGESTIONS = 10;
21+
2022
private IUserSettingsService UserSettingsService { get; } = Ioc.Default.GetRequiredService<IUserSettingsService>();
2123

2224
private readonly IDialogService _dialogService = Ioc.Default.GetRequiredService<IDialogService>();
@@ -707,6 +709,7 @@ await DialogDisplayHelper.ShowDialogAsync("CommandNotExecutable".GetLocalizedRes
707709
{
708710
if (currentInput.Equals("Home", StringComparison.OrdinalIgnoreCase) || currentInput.Equals("Home".GetLocalizedResource(), StringComparison.OrdinalIgnoreCase))
709711
{
712+
SavePathToHistory("Home");
710713
shellPage.NavigateHome();
711714
}
712715
else
@@ -732,10 +735,12 @@ await DialogDisplayHelper.ShowDialogAsync("CommandNotExecutable".GetLocalizedRes
732735
return;
733736
}
734737
var pathToNavigate = resFolder.Result?.Path ?? currentInput;
738+
SavePathToHistory(pathToNavigate);
735739
shellPage.NavigateToPath(pathToNavigate);
736740
}
737741
else if (isFtp)
738742
{
743+
SavePathToHistory(currentInput);
739744
shellPage.NavigateToPath(currentInput);
740745
}
741746
else // Not a folder or inaccessible
@@ -776,6 +781,18 @@ await DialogDisplayHelper.ShowDialogAsync("InvalidItemDialogTitle".GetLocalizedR
776781
}
777782
}
778783

784+
private void SavePathToHistory(string path)
785+
{
786+
var pathHistoryList = UserSettingsService.GeneralSettingsService.PathHistoryList?.ToList() ?? new List<string>();
787+
pathHistoryList.Remove(path);
788+
pathHistoryList.Insert(0, path);
789+
790+
if (pathHistoryList.Count > MAX_SUGGESTIONS)
791+
UserSettingsService.GeneralSettingsService.PathHistoryList = pathHistoryList.RemoveFrom(MAX_SUGGESTIONS + 1);
792+
else
793+
UserSettingsService.GeneralSettingsService.PathHistoryList = pathHistoryList;
794+
}
795+
779796
private static async Task<bool> LaunchApplicationFromPath(string currentInput, string workingDir)
780797
{
781798
var trimmedInput = currentInput.Trim();
@@ -791,9 +808,9 @@ private static async Task<bool> LaunchApplicationFromPath(string currentInput, s
791808
return await LaunchHelper.LaunchAppAsync(fileName, arguments, workingDir);
792809
}
793810

794-
public async Task SetAddressBarSuggestionsAsync(AutoSuggestBox sender, IShellPage shellpage, int maxSuggestions = 7)
811+
public async Task SetAddressBarSuggestionsAsync(AutoSuggestBox sender, IShellPage shellpage)
795812
{
796-
if (!string.IsNullOrWhiteSpace(sender.Text) && shellpage.FilesystemViewModel is not null)
813+
if (sender.Text is not null && shellpage.FilesystemViewModel is not null)
797814
{
798815
if (!await SafetyExtensions.IgnoreExceptions(async () =>
799816
{
@@ -818,37 +835,54 @@ public async Task SetAddressBarSuggestionsAsync(AutoSuggestBox sender, IShellPag
818835
{
819836
IsCommandPaletteOpen = false;
820837
var currentInput = sender.Text;
821-
var isFtp = FtpHelpers.IsFtpPath(currentInput);
822-
currentInput = NormalizePathInput(currentInput, isFtp);
823-
var expandedPath = StorageFileExtensions.GetResolvedPath(currentInput, isFtp);
824-
var folderPath = PathNormalization.GetParentDir(expandedPath) ?? expandedPath;
825-
StorageFolderWithPath folder = await shellpage.FilesystemViewModel.GetFolderWithPathFromPathAsync(folderPath);
826838

827-
if (folder is null)
828-
return false;
829-
830-
var currPath = await folder.GetFoldersWithPathAsync(Path.GetFileName(expandedPath), (uint)maxSuggestions);
831-
if (currPath.Count >= maxSuggestions)
839+
if (string.IsNullOrWhiteSpace(currentInput) || currentInput == "Home")
832840
{
833-
suggestions = currPath.Select(x => new NavigationBarSuggestionItem()
841+
// Load previously entered path
842+
var pathHistoryList = UserSettingsService.GeneralSettingsService.PathHistoryList;
843+
if (pathHistoryList is not null)
834844
{
835-
Text = x.Path,
836-
PrimaryDisplay = x.Item.DisplayName
837-
}).ToList();
845+
suggestions = pathHistoryList.Select(x => new NavigationBarSuggestionItem()
846+
{
847+
Text = x,
848+
PrimaryDisplay = x
849+
}).ToList();
850+
}
838851
}
839-
else if (currPath.Any())
852+
else
840853
{
841-
var subPath = await currPath.First().GetFoldersWithPathAsync((uint)(maxSuggestions - currPath.Count));
842-
suggestions = currPath.Select(x => new NavigationBarSuggestionItem()
854+
var isFtp = FtpHelpers.IsFtpPath(currentInput);
855+
currentInput = NormalizePathInput(currentInput, isFtp);
856+
var expandedPath = StorageFileExtensions.GetResolvedPath(currentInput, isFtp);
857+
var folderPath = PathNormalization.GetParentDir(expandedPath) ?? expandedPath;
858+
StorageFolderWithPath folder = await shellpage.FilesystemViewModel.GetFolderWithPathFromPathAsync(folderPath);
859+
860+
if (folder is null)
861+
return false;
862+
863+
var currPath = await folder.GetFoldersWithPathAsync(Path.GetFileName(expandedPath), (uint)MAX_SUGGESTIONS);
864+
if (currPath.Count >= MAX_SUGGESTIONS)
865+
{
866+
suggestions = currPath.Select(x => new NavigationBarSuggestionItem()
867+
{
868+
Text = x.Path,
869+
PrimaryDisplay = x.Item.DisplayName
870+
}).ToList();
871+
}
872+
else if (currPath.Any())
843873
{
844-
Text = x.Path,
845-
PrimaryDisplay = x.Item.DisplayName
846-
}).Concat(
847-
subPath.Select(x => new NavigationBarSuggestionItem()
874+
var subPath = await currPath.First().GetFoldersWithPathAsync((uint)(MAX_SUGGESTIONS - currPath.Count));
875+
suggestions = currPath.Select(x => new NavigationBarSuggestionItem()
848876
{
849877
Text = x.Path,
850-
PrimaryDisplay = PathNormalization.Combine(currPath.First().Item.DisplayName, x.Item.DisplayName)
851-
})).ToList();
878+
PrimaryDisplay = x.Item.DisplayName
879+
}).Concat(
880+
subPath.Select(x => new NavigationBarSuggestionItem()
881+
{
882+
Text = x.Path,
883+
PrimaryDisplay = PathNormalization.Combine(currPath.First().Item.DisplayName, x.Item.DisplayName)
884+
})).ToList();
885+
}
852886
}
853887
}
854888

src/Files.Core/Services/Settings/IGeneralSettingsService.cs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,11 @@ public interface IGeneralSettingsService : IBaseSettingsService, INotifyProperty
5454
/// </summary>
5555
List<string> LastCrashedTabList { get; set; }
5656

57+
/// <summary>
58+
/// A list containing paths previously entered in the path bar.
59+
/// </summary>
60+
List<string> PathHistoryList { get; set; }
61+
5762
/// <summary>
5863
/// Gets or sets a value indicating which date and time format to use.
5964
/// </summary>

0 commit comments

Comments
 (0)