Skip to content

Commit 1c6e41b

Browse files
authored
Feature: Display banner when recent items are turned off from File Explorer (#10777)
1 parent ee6f2c5 commit 1c6e41b

File tree

4 files changed

+100
-42
lines changed

4 files changed

+100
-42
lines changed

src/Files.App/Filesystem/RecentItems.cs

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
using Files.App.Helpers;
22
using Files.App.Shell;
33
using Files.Shared.Extensions;
4+
using Microsoft.Win32;
45
using System;
56
using System.Collections.Generic;
67
using System.Collections.Specialized;
@@ -204,6 +205,47 @@ public Task<bool> UnpinFromRecentFiles(RecentItem item)
204205
}));
205206
}
206207

208+
public bool CheckIsRecentFilesEnabled()
209+
{
210+
using var subkey = Registry.CurrentUser.OpenSubKey(@"SOFTWARE\Microsoft\Windows\CurrentVersion\Explorer");
211+
using var advSubkey = Registry.CurrentUser.OpenSubKey(@"SOFTWARE\Microsoft\Windows\CurrentVersion\Explorer\Advanced");
212+
using var userPolicySubkey = Registry.CurrentUser.OpenSubKey(@"SOFTWARE\Microsoft\Windows\CurrentVersion\Policies\Explorer");
213+
using var sysPolicySubkey = Registry.LocalMachine.OpenSubKey(@"SOFTWARE\Microsoft\Windows\CurrentVersion\Policies\Explorer");
214+
215+
if (subkey is not null)
216+
{
217+
// quick access: show recent files option
218+
bool showRecentValue = Convert.ToBoolean(subkey.GetValue("ShowRecent", true)); // 1 by default
219+
if (!showRecentValue)
220+
{
221+
return false;
222+
}
223+
}
224+
225+
if (advSubkey is not null)
226+
{
227+
// settings: personalization > start > show recently opened items
228+
bool startTrackDocsValue = Convert.ToBoolean(advSubkey.GetValue("Start_TrackDocs", true)); // 1 by default
229+
if (!startTrackDocsValue)
230+
{
231+
return false;
232+
}
233+
}
234+
235+
// for users in group policies
236+
var policySubkey = userPolicySubkey ?? sysPolicySubkey;
237+
if (policySubkey is not null)
238+
{
239+
bool noRecentDocsHistoryValue = Convert.ToBoolean(policySubkey.GetValue("NoRecentDocsHistory", false)); // 0 by default
240+
if (noRecentDocsHistoryValue)
241+
{
242+
return false;
243+
}
244+
}
245+
246+
return true;
247+
}
248+
207249
/// <summary>
208250
/// Returns whether two RecentItem enumerables have the same order.
209251
/// This function depends on `RecentItem` implementing IEquatable.
@@ -212,6 +254,7 @@ private bool RecentItemsOrderEquals(IEnumerable<RecentItem> oldOrder, IEnumerabl
212254
{
213255
return oldOrder != null && newOrder != null && oldOrder.SequenceEqual(newOrder);
214256
}
257+
215258
public void Dispose()
216259
{
217260
RecentItemsManager.Default.RecentItemsChanged -= OnRecentItemsChanged;

src/Files.App/Strings/en-US/Resources.resw

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2923,4 +2923,7 @@
29232923
<data name="SortBy" xml:space="preserve">
29242924
<value>Sort by</value>
29252925
</data>
2926+
<data name="RecentFilesDisabledOnWindowsWarning" xml:space="preserve">
2927+
<value>Recently used files is currently disabled in Windows File Explorer.</value>
2928+
</data>
29262929
</root>

src/Files.App/UserControls/Widgets/RecentFilesWidget.xaml

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
66
xmlns:fs="using:Files.App.Filesystem"
77
xmlns:helpers="using:Files.App.Helpers"
8-
xmlns:local="using:Files.App.UserControls.Widgets"
8+
xmlns:muxc="using:Microsoft.UI.Xaml.Controls"
99
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
1010
Background="{ThemeResource SolidBackgroundFillColorBaseBrush}"
1111
mc:Ignorable="d">
@@ -15,14 +15,21 @@
1515
MinHeight="200"
1616
Orientation="Vertical"
1717
Spacing="4">
18+
<muxc:InfoBar
19+
IsClosable="False"
20+
IsIconVisible="True"
21+
IsOpen="True"
22+
Message="{helpers:ResourceString Name=RecentFilesDisabledOnWindowsWarning}"
23+
Severity="Warning"
24+
Visibility="{x:Bind IsRecentFilesDisabledInWindows, Mode=OneWay}" />
1825
<TextBlock
1926
x:Name="RecentItemDescription"
2027
HorizontalAlignment="Stretch"
2128
FontSize="14"
2229
Text="{helpers:ResourceString Name=RecentItemDescription/Text}"
2330
TextAlignment="Center"
2431
TextWrapping="WrapWholeWords"
25-
Visibility="{x:Bind Empty.Visibility, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}" />
32+
Visibility="{x:Bind EmptyRecentsTextVisibility, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}" />
2633
<ListView
2734
x:Name="RecentsView"
2835
HorizontalAlignment="Stretch"
@@ -129,4 +136,4 @@
129136
</ListView.ItemTemplate>
130137
</ListView>
131138
</StackPanel>
132-
</UserControl>
139+
</UserControl>

src/Files.App/UserControls/Widgets/RecentFilesWidget.xaml.cs

Lines changed: 44 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818

1919
namespace Files.App.UserControls.Widgets
2020
{
21-
public sealed partial class RecentFilesWidget : UserControl, IWidgetItemModel
21+
public sealed partial class RecentFilesWidget : UserControl, IWidgetItemModel, INotifyPropertyChanged
2222
{
2323
private IUserSettingsService UserSettingsService { get; } = Ioc.Default.GetRequiredService<IUserSettingsService>();
2424

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

3131
public event RecentFileInvokedEventHandler RecentFileInvoked;
3232

33+
public event PropertyChangedEventHandler PropertyChanged;
34+
3335
private ObservableCollection<RecentItem> recentItemsCollection = new ObservableCollection<RecentItem>();
3436

3537
private SemaphoreSlim refreshRecentsSemaphore;
3638

3739
private CancellationTokenSource refreshRecentsCTS;
3840

39-
private EmptyRecentsText Empty { get; set; } = new EmptyRecentsText();
40-
4141
public string WidgetName => nameof(RecentFilesWidget);
4242

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

4747
public bool IsWidgetSettingEnabled => UserSettingsService.AppearanceSettingsService.ShowRecentFilesWidget;
4848

49+
private Visibility emptyRecentsTextVisibility = Visibility.Collapsed;
50+
public Visibility EmptyRecentsTextVisibility
51+
{
52+
get => emptyRecentsTextVisibility;
53+
internal set
54+
{
55+
if (emptyRecentsTextVisibility != value)
56+
{
57+
emptyRecentsTextVisibility = value;
58+
NotifyPropertyChanged(nameof(EmptyRecentsTextVisibility));
59+
}
60+
}
61+
}
62+
63+
private bool isRecentFilesDisabledInWindows = false;
64+
public bool IsRecentFilesDisabledInWindows
65+
{
66+
get => isRecentFilesDisabledInWindows;
67+
internal set
68+
{
69+
if (isRecentFilesDisabledInWindows != value)
70+
{
71+
isRecentFilesDisabledInWindows = value;
72+
NotifyPropertyChanged(nameof(IsRecentFilesDisabledInWindows));
73+
}
74+
}
75+
}
76+
4977
public RecentFilesWidget()
5078
{
5179
InitializeComponent();
@@ -54,11 +82,17 @@ public RecentFilesWidget()
5482
refreshRecentsCTS = new CancellationTokenSource();
5583

5684
// recent files could have changed while widget wasn't loaded
57-
_ = App.RecentItemsManager.UpdateRecentFilesAsync();
85+
_ = RefreshWidget();
5886

5987
App.RecentItemsManager.RecentFilesChanged += Manager_RecentFilesChanged;
6088
}
6189

90+
public async Task RefreshWidget()
91+
{
92+
IsRecentFilesDisabledInWindows = App.RecentItemsManager.CheckIsRecentFilesEnabled() is false;
93+
await App.RecentItemsManager.UpdateRecentFilesAsync();
94+
}
95+
6296
private async void Manager_RecentFilesChanged(object sender, NotifyCollectionChangedEventArgs e)
6397
{
6498
await DispatcherQueue.EnqueueAsync(async () =>
@@ -100,7 +134,7 @@ private async Task UpdateRecentsList(NotifyCollectionChangedEventArgs e)
100134
refreshRecentsCTS.Cancel();
101135
refreshRecentsCTS = new CancellationTokenSource();
102136

103-
Empty.Visibility = Visibility.Collapsed;
137+
EmptyRecentsTextVisibility = Visibility.Collapsed;
104138

105139
switch (e.Action)
106140
{
@@ -131,9 +165,9 @@ private async Task UpdateRecentsList(NotifyCollectionChangedEventArgs e)
131165
}
132166

133167
// update chevron if there aren't any items
134-
if (recentItemsCollection.Count == 0)
168+
if (recentItemsCollection.Count == 0 && !IsRecentFilesDisabledInWindows)
135169
{
136-
Empty.Visibility = Visibility.Visible;
170+
EmptyRecentsTextVisibility = Visibility.Visible;
137171
}
138172
}
139173
catch (Exception ex)
@@ -202,7 +236,7 @@ private async void ClearRecentItems_Click(object sender, RoutedEventArgs e)
202236

203237
if (success)
204238
{
205-
Empty.Visibility = Visibility.Visible;
239+
EmptyRecentsTextVisibility = Visibility.Visible;
206240
}
207241
}
208242
finally
@@ -211,43 +245,14 @@ private async void ClearRecentItems_Click(object sender, RoutedEventArgs e)
211245
}
212246
}
213247

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

220253
public void Dispose()
221254
{
222255
App.RecentItemsManager.RecentFilesChanged -= Manager_RecentFilesChanged;
223256
}
224257
}
225-
226-
public class EmptyRecentsText : INotifyPropertyChanged
227-
{
228-
private Visibility visibility;
229-
230-
public Visibility Visibility
231-
{
232-
get
233-
{
234-
return visibility;
235-
}
236-
set
237-
{
238-
if (value != visibility)
239-
{
240-
visibility = value;
241-
NotifyPropertyChanged(nameof(Visibility));
242-
}
243-
}
244-
}
245-
246-
public event PropertyChangedEventHandler PropertyChanged;
247-
248-
private void NotifyPropertyChanged([CallerMemberName] string propertyName = "")
249-
{
250-
PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(propertyName));
251-
}
252-
}
253258
}

0 commit comments

Comments
 (0)