1818
1919namespace 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