@@ -17,6 +17,8 @@ namespace Files.App.ViewModels.UserControls
17
17
{
18
18
public class ToolbarViewModel : ObservableObject , IAddressToolbar , IDisposable
19
19
{
20
+ private const int MAX_SUGGESTIONS = 10 ;
21
+
20
22
private IUserSettingsService UserSettingsService { get ; } = Ioc . Default . GetRequiredService < IUserSettingsService > ( ) ;
21
23
22
24
private readonly IDialogService _dialogService = Ioc . Default . GetRequiredService < IDialogService > ( ) ;
@@ -707,6 +709,7 @@ await DialogDisplayHelper.ShowDialogAsync("CommandNotExecutable".GetLocalizedRes
707
709
{
708
710
if ( currentInput . Equals ( "Home" , StringComparison . OrdinalIgnoreCase ) || currentInput . Equals ( "Home" . GetLocalizedResource ( ) , StringComparison . OrdinalIgnoreCase ) )
709
711
{
712
+ SavePathToHistory ( "Home" ) ;
710
713
shellPage . NavigateHome ( ) ;
711
714
}
712
715
else
@@ -732,10 +735,12 @@ await DialogDisplayHelper.ShowDialogAsync("CommandNotExecutable".GetLocalizedRes
732
735
return ;
733
736
}
734
737
var pathToNavigate = resFolder . Result ? . Path ?? currentInput ;
738
+ SavePathToHistory ( pathToNavigate ) ;
735
739
shellPage . NavigateToPath ( pathToNavigate ) ;
736
740
}
737
741
else if ( isFtp )
738
742
{
743
+ SavePathToHistory ( currentInput ) ;
739
744
shellPage . NavigateToPath ( currentInput ) ;
740
745
}
741
746
else // Not a folder or inaccessible
@@ -776,6 +781,18 @@ await DialogDisplayHelper.ShowDialogAsync("InvalidItemDialogTitle".GetLocalizedR
776
781
}
777
782
}
778
783
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
+
779
796
private static async Task < bool > LaunchApplicationFromPath ( string currentInput , string workingDir )
780
797
{
781
798
var trimmedInput = currentInput . Trim ( ) ;
@@ -791,9 +808,9 @@ private static async Task<bool> LaunchApplicationFromPath(string currentInput, s
791
808
return await LaunchHelper . LaunchAppAsync ( fileName , arguments , workingDir ) ;
792
809
}
793
810
794
- public async Task SetAddressBarSuggestionsAsync ( AutoSuggestBox sender , IShellPage shellpage , int maxSuggestions = 7 )
811
+ public async Task SetAddressBarSuggestionsAsync ( AutoSuggestBox sender , IShellPage shellpage )
795
812
{
796
- if ( ! string . IsNullOrWhiteSpace ( sender . Text ) && shellpage . FilesystemViewModel is not null )
813
+ if ( sender . Text is not null && shellpage . FilesystemViewModel is not null )
797
814
{
798
815
if ( ! await SafetyExtensions . IgnoreExceptions ( async ( ) =>
799
816
{
@@ -818,37 +835,54 @@ public async Task SetAddressBarSuggestionsAsync(AutoSuggestBox sender, IShellPag
818
835
{
819
836
IsCommandPaletteOpen = false ;
820
837
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 ) ;
826
838
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" )
832
840
{
833
- suggestions = currPath . Select ( x => new NavigationBarSuggestionItem ( )
841
+ // Load previously entered path
842
+ var pathHistoryList = UserSettingsService . GeneralSettingsService . PathHistoryList ;
843
+ if ( pathHistoryList is not null )
834
844
{
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
+ }
838
851
}
839
- else if ( currPath . Any ( ) )
852
+ else
840
853
{
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 ( ) )
843
873
{
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 ( )
848
876
{
849
877
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
+ }
852
886
}
853
887
}
854
888
0 commit comments