Skip to content

Added a setting to enable or disable saving recent items opened #6577

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 14 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 5 additions & 3 deletions Files/Helpers/NavigationHelpers.cs
Original file line number Diff line number Diff line change
Expand Up @@ -302,7 +302,7 @@ private static async Task<FilesystemResult> OpenDirectory(string path, IShellPag
.OnSuccess(async (childFolder) =>
{
// Add location to MRU List
if (childFolder.Folder is SystemStorageFolder)
if (userSettingsService.PreferencesSettingsService.IsSavingRecentItemsEnabled && childFolder.Folder is SystemStorageFolder)
{
var mostRecentlyUsed = Windows.Storage.AccessCache.StorageApplicationPermissions.MostRecentlyUsedList;
mostRecentlyUsed.Add(await childFolder.Folder.ToStorageFolderAsync(), childFolder.Path);
Expand Down Expand Up @@ -335,6 +335,8 @@ private static async Task<FilesystemResult> OpenDirectory(string path, IShellPag

private static async Task<FilesystemResult> OpenFile(string path, IShellPage associatedInstance, IEnumerable<string> selectItems, ShortcutItem shortcutInfo, bool openViaApplicationPicker = false, string args = default)
{
IUserSettingsService userSettingsService = Ioc.Default.GetService<IUserSettingsService>();

var opened = (FilesystemResult)false;
bool isHiddenItem = NativeFileOperationsHelper.HasFileAttribute(path, System.IO.FileAttributes.Hidden);
bool isShortcutItem = path.EndsWith(".lnk") || path.EndsWith(".url"); // Determine
Expand All @@ -352,7 +354,7 @@ private static async Task<FilesystemResult> OpenFile(string path, IShellPage ass
if (childFile != null)
{
// Add location to MRU List
if (childFile.File is SystemStorageFile)
if (userSettingsService.PreferencesSettingsService.IsSavingRecentItemsEnabled && childFile.File is SystemStorageFile)
{
var mostRecentlyUsed = Windows.Storage.AccessCache.StorageApplicationPermissions.MostRecentlyUsedList;
mostRecentlyUsed.Add(await childFile.File.ToStorageFileAsync(), childFile.Path);
Expand All @@ -373,7 +375,7 @@ private static async Task<FilesystemResult> OpenFile(string path, IShellPage ass
.OnSuccess(async childFile =>
{
// Add location to MRU List
if (childFile.File is SystemStorageFile)
if (userSettingsService.PreferencesSettingsService.IsSavingRecentItemsEnabled && childFile.File is SystemStorageFile)
{
var mostRecentlyUsed = Windows.Storage.AccessCache.StorageApplicationPermissions.MostRecentlyUsedList;
mostRecentlyUsed.Add(await childFile.File.ToStorageFileAsync(), childFile.Path);
Expand Down
5 changes: 5 additions & 0 deletions Files/Services/IPreferencesSettingsService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,5 +11,10 @@ public interface IPreferencesSettingsService
/// Gets or sets a value indicating whether or not to open folders in new tab.
/// </summary>
bool OpenFoldersInNewTab { get; set; }

/// <summary>
/// Enables saving recent items for quick access and the recent items widget
/// </summary>
bool IsSavingRecentItemsEnabled { get; set; }
}
}
7 changes: 7 additions & 0 deletions Files/Services/Implementation/PreferencesSettingsService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ public override void RaiseOnSettingChangedEvent(object sender, EventArguments.Se
{
case nameof(ShowConfirmDeleteDialog):
case nameof(OpenFoldersInNewTab):
case nameof(IsSavingRecentItemsEnabled):
Microsoft.AppCenter.Analytics.Analytics.TrackEvent($"{nameof(e.settingName)} {e.newValue}");
break;
}
Expand All @@ -34,5 +35,11 @@ public bool OpenFoldersInNewTab
get => Get(false);
set => Set(value);
}

public bool IsSavingRecentItemsEnabled
{
get => Get(true);
set => Set(value);
}
}
}
3 changes: 3 additions & 0 deletions Files/Strings/en-US/Resources.resw
Original file line number Diff line number Diff line change
Expand Up @@ -2776,4 +2776,7 @@ We use App Center to keep track of app usage, find bugs, and fix crashes. All in
<data name="NavToolbarArrangementOptionFolderPath.Text" xml:space="preserve">
<value>Folder path</value>
</data>
<data name="SettingsEnableSavingRecentItems" xml:space="preserve">
<value>Enable saving recently opened directories and files</value>
</data>
</root>
1 change: 1 addition & 0 deletions Files/UserControls/InnerNavigationToolbar.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -232,6 +232,7 @@
<ToggleSwitch
x:Uid="NavToolbarShowRecentFilesWidget"
Header="Show Recent Files widget"
IsEnabled="{x:Bind UserSettingsService.PreferencesSettingsService.IsSavingRecentItemsEnabled, Mode=OneWay}"
IsOn="{x:Bind ViewModel.ShowRecentFilesWidget, Mode=TwoWay}" />
</StackPanel>
</StackPanel>
Expand Down
22 changes: 22 additions & 0 deletions Files/ViewModels/SettingsViewModels/PreferencesViewModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
using System.Windows.Input;
using Windows.Foundation.Collections;
using Windows.Storage;
using Windows.Storage.AccessCache;
using Windows.System;

namespace Files.ViewModels.SettingsViewModels
Expand Down Expand Up @@ -142,6 +143,27 @@ public bool OpenFoldersNewTab
}
}

public bool IsSavingRecentItemsEnabled
{
get => UserSettingsService.PreferencesSettingsService.IsSavingRecentItemsEnabled;
set
{
if (value != UserSettingsService.PreferencesSettingsService.IsSavingRecentItemsEnabled)
{
UserSettingsService.PreferencesSettingsService.IsSavingRecentItemsEnabled = value;

if (!UserSettingsService.PreferencesSettingsService.IsSavingRecentItemsEnabled)
{
var mru = StorageApplicationPermissions.MostRecentlyUsedList;
mru.Clear();
UserSettingsService.WidgetsSettingsService.ShowRecentFilesWidget = false;
}

OnPropertyChanged();
}
}
}

private async Task LaunchTerminalsConfigFile()
{
var configFile = await StorageFile.GetFileFromApplicationUriAsync(new Uri("ms-appdata:///local/settings/terminal.json"));
Expand Down
15 changes: 14 additions & 1 deletion Files/Views/SettingsPages/Preferences.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
xmlns:datamodels="using:Files.DataModels"
xmlns:local="using:Files.UserControls.Settings"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:settingsviewmodels="using:Files.ViewModels.SettingsViewModels"
xmlns:settingsviewmodels="using:Files.ViewModels.SettingsViewModels" xmlns:helpers="using:Files.Helpers"
mc:Ignorable="d">
<Page.Resources>
<ResourceDictionary Source="/ResourceDictionaries/RightAlignedToggleSwitchStyle.xaml" />
Expand Down Expand Up @@ -146,6 +146,19 @@
IsOn="{Binding OpenFoldersNewTab, Mode=TwoWay}"
Style="{StaticResource RightAlignedToggleSwitchStyle}" />
</local:SettingsBlockControl>

<local:SettingsBlockControl
Title="{helpers:ResourceString Name=SettingsEnableSavingRecentItems}"
HorizontalAlignment="Stretch">
<local:SettingsBlockControl.Icon>
<FontIcon Glyph="&#xE823;" />
</local:SettingsBlockControl.Icon>
<ToggleSwitch
x:Name="IsSavingRecentItemsEnabled"
AutomationProperties.Name="{helpers:ResourceString Name=SettingsEnableSavingRecentItems}"
IsOn="{Binding IsSavingRecentItemsEnabled, Mode=TwoWay}"
Style="{StaticResource RightAlignedToggleSwitchStyle}" />
</local:SettingsBlockControl>
</StackPanel>

<UserControls:RestartControl
Expand Down