@@ -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
0 commit comments