Skip to content

Feature: Display banner when recent items are turned off from File Explorer #10777

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

Merged
Merged
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
43 changes: 43 additions & 0 deletions src/Files.App/Filesystem/RecentItems.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
using Files.App.Helpers;
using Files.App.Shell;
using Files.Shared.Extensions;
using Microsoft.Win32;
using System;
using System.Collections.Generic;
using System.Collections.Specialized;
Expand Down Expand Up @@ -204,6 +205,47 @@ public Task<bool> UnpinFromRecentFiles(RecentItem item)
}));
}

public bool CheckIsRecentFilesEnabled()
{
using var subkey = Registry.CurrentUser.OpenSubKey(@"SOFTWARE\Microsoft\Windows\CurrentVersion\Explorer");
using var advSubkey = Registry.CurrentUser.OpenSubKey(@"SOFTWARE\Microsoft\Windows\CurrentVersion\Explorer\Advanced");
using var userPolicySubkey = Registry.CurrentUser.OpenSubKey(@"SOFTWARE\Microsoft\Windows\CurrentVersion\Policies\Explorer");
using var sysPolicySubkey = Registry.LocalMachine.OpenSubKey(@"SOFTWARE\Microsoft\Windows\CurrentVersion\Policies\Explorer");

if (subkey is not null)
{
// quick access: show recent files option
bool showRecentValue = Convert.ToBoolean(subkey.GetValue("ShowRecent", true)); // 1 by default
if (!showRecentValue)
{
return false;
}
}

if (advSubkey is not null)
{
// settings: personalization > start > show recently opened items
bool startTrackDocsValue = Convert.ToBoolean(advSubkey.GetValue("Start_TrackDocs", true)); // 1 by default
if (!startTrackDocsValue)
{
return false;
}
}

// for users in group policies
var policySubkey = userPolicySubkey ?? sysPolicySubkey;
if (policySubkey is not null)
{
bool noRecentDocsHistoryValue = Convert.ToBoolean(policySubkey.GetValue("NoRecentDocsHistory", false)); // 0 by default
if (noRecentDocsHistoryValue)
{
return false;
}
}

return true;
}

/// <summary>
/// Returns whether two RecentItem enumerables have the same order.
/// This function depends on `RecentItem` implementing IEquatable.
Expand All @@ -212,6 +254,7 @@ private bool RecentItemsOrderEquals(IEnumerable<RecentItem> oldOrder, IEnumerabl
{
return oldOrder != null && newOrder != null && oldOrder.SequenceEqual(newOrder);
}

public void Dispose()
{
RecentItemsManager.Default.RecentItemsChanged -= OnRecentItemsChanged;
Expand Down
3 changes: 3 additions & 0 deletions src/Files.App/Strings/en-US/Resources.resw
Original file line number Diff line number Diff line change
Expand Up @@ -2935,4 +2935,7 @@
<data name="SortBy" xml:space="preserve">
<value>Sort by</value>
</data>
<data name="RecentFilesDisabledOnWindowsWarning" xml:space="preserve">
<value>Recently used files is currently disabled in Windows File Explorer.</value>
</data>
</root>
13 changes: 10 additions & 3 deletions src/Files.App/UserControls/Widgets/RecentFilesWidget.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:fs="using:Files.App.Filesystem"
xmlns:helpers="using:Files.App.Helpers"
xmlns:local="using:Files.App.UserControls.Widgets"
xmlns:muxc="using:Microsoft.UI.Xaml.Controls"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
Background="{ThemeResource SolidBackgroundFillColorBaseBrush}"
mc:Ignorable="d">
Expand All @@ -15,14 +15,21 @@
MinHeight="200"
Orientation="Vertical"
Spacing="4">
<muxc:InfoBar
IsClosable="False"
IsIconVisible="True"
IsOpen="True"
Message="{helpers:ResourceString Name=RecentFilesDisabledOnWindowsWarning}"
Severity="Warning"
Visibility="{x:Bind IsRecentFilesDisabledInWindows, Mode=OneWay}" />
<TextBlock
x:Name="RecentItemDescription"
HorizontalAlignment="Stretch"
FontSize="14"
Text="{helpers:ResourceString Name=RecentItemDescription/Text}"
TextAlignment="Center"
TextWrapping="WrapWholeWords"
Visibility="{x:Bind Empty.Visibility, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}" />
Visibility="{x:Bind EmptyRecentsTextVisibility, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}" />
<ListView
x:Name="RecentsView"
HorizontalAlignment="Stretch"
Expand Down Expand Up @@ -129,4 +136,4 @@
</ListView.ItemTemplate>
</ListView>
</StackPanel>
</UserControl>
</UserControl>
83 changes: 44 additions & 39 deletions src/Files.App/UserControls/Widgets/RecentFilesWidget.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@

namespace Files.App.UserControls.Widgets
{
public sealed partial class RecentFilesWidget : UserControl, IWidgetItemModel
public sealed partial class RecentFilesWidget : UserControl, IWidgetItemModel, INotifyPropertyChanged
{
private IUserSettingsService UserSettingsService { get; } = Ioc.Default.GetRequiredService<IUserSettingsService>();

Expand All @@ -30,14 +30,14 @@ public sealed partial class RecentFilesWidget : UserControl, IWidgetItemModel

public event RecentFileInvokedEventHandler RecentFileInvoked;

public event PropertyChangedEventHandler PropertyChanged;

private ObservableCollection<RecentItem> recentItemsCollection = new ObservableCollection<RecentItem>();

private SemaphoreSlim refreshRecentsSemaphore;

private CancellationTokenSource refreshRecentsCTS;

private EmptyRecentsText Empty { get; set; } = new EmptyRecentsText();

public string WidgetName => nameof(RecentFilesWidget);

public string AutomationProperties => "RecentFilesWidgetAutomationProperties/Name".GetLocalizedResource();
Expand All @@ -46,6 +46,34 @@ public sealed partial class RecentFilesWidget : UserControl, IWidgetItemModel

public bool IsWidgetSettingEnabled => UserSettingsService.AppearanceSettingsService.ShowRecentFilesWidget;

private Visibility emptyRecentsTextVisibility = Visibility.Collapsed;
public Visibility EmptyRecentsTextVisibility
{
get => emptyRecentsTextVisibility;
internal set
{
if (emptyRecentsTextVisibility != value)
{
emptyRecentsTextVisibility = value;
NotifyPropertyChanged(nameof(EmptyRecentsTextVisibility));
}
}
}

private bool isRecentFilesDisabledInWindows = false;
public bool IsRecentFilesDisabledInWindows
{
get => isRecentFilesDisabledInWindows;
internal set
{
if (isRecentFilesDisabledInWindows != value)
{
isRecentFilesDisabledInWindows = value;
NotifyPropertyChanged(nameof(IsRecentFilesDisabledInWindows));
}
}
}

public RecentFilesWidget()
{
InitializeComponent();
Expand All @@ -54,11 +82,17 @@ public RecentFilesWidget()
refreshRecentsCTS = new CancellationTokenSource();

// recent files could have changed while widget wasn't loaded
_ = App.RecentItemsManager.UpdateRecentFilesAsync();
_ = RefreshWidget();

App.RecentItemsManager.RecentFilesChanged += Manager_RecentFilesChanged;
}

public async Task RefreshWidget()
{
IsRecentFilesDisabledInWindows = App.RecentItemsManager.CheckIsRecentFilesEnabled() is false;
await App.RecentItemsManager.UpdateRecentFilesAsync();
}

private async void Manager_RecentFilesChanged(object sender, NotifyCollectionChangedEventArgs e)
{
await DispatcherQueue.EnqueueAsync(async () =>
Expand Down Expand Up @@ -100,7 +134,7 @@ private async Task UpdateRecentsList(NotifyCollectionChangedEventArgs e)
refreshRecentsCTS.Cancel();
refreshRecentsCTS = new CancellationTokenSource();

Empty.Visibility = Visibility.Collapsed;
EmptyRecentsTextVisibility = Visibility.Collapsed;

switch (e.Action)
{
Expand Down Expand Up @@ -131,9 +165,9 @@ private async Task UpdateRecentsList(NotifyCollectionChangedEventArgs e)
}

// update chevron if there aren't any items
if (recentItemsCollection.Count == 0)
if (recentItemsCollection.Count == 0 && !IsRecentFilesDisabledInWindows)
{
Empty.Visibility = Visibility.Visible;
EmptyRecentsTextVisibility = Visibility.Visible;
}
}
catch (Exception ex)
Expand Down Expand Up @@ -202,7 +236,7 @@ private async void ClearRecentItems_Click(object sender, RoutedEventArgs e)

if (success)
{
Empty.Visibility = Visibility.Visible;
EmptyRecentsTextVisibility = Visibility.Visible;
}
}
finally
Expand All @@ -211,43 +245,14 @@ private async void ClearRecentItems_Click(object sender, RoutedEventArgs e)
}
}

public Task RefreshWidget()
private void NotifyPropertyChanged([CallerMemberName] string propertyName = "")
{
// if files changed, event is fired to update widget
return App.RecentItemsManager.UpdateRecentFilesAsync();
PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(propertyName));
}

public void Dispose()
{
App.RecentItemsManager.RecentFilesChanged -= Manager_RecentFilesChanged;
}
}

public class EmptyRecentsText : INotifyPropertyChanged
{
private Visibility visibility;

public Visibility Visibility
{
get
{
return visibility;
}
set
{
if (value != visibility)
{
visibility = value;
NotifyPropertyChanged(nameof(Visibility));
}
}
}

public event PropertyChangedEventHandler PropertyChanged;

private void NotifyPropertyChanged([CallerMemberName] string propertyName = "")
{
PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(propertyName));
}
}
}