18
18
19
19
namespace Files . App . UserControls . Widgets
20
20
{
21
- public sealed partial class RecentFilesWidget : UserControl , IWidgetItemModel
21
+ public sealed partial class RecentFilesWidget : UserControl , IWidgetItemModel , INotifyPropertyChanged
22
22
{
23
23
private IUserSettingsService UserSettingsService { get ; } = Ioc . Default . GetRequiredService < IUserSettingsService > ( ) ;
24
24
@@ -30,14 +30,14 @@ public sealed partial class RecentFilesWidget : UserControl, IWidgetItemModel
30
30
31
31
public event RecentFileInvokedEventHandler RecentFileInvoked ;
32
32
33
+ public event PropertyChangedEventHandler PropertyChanged ;
34
+
33
35
private ObservableCollection < RecentItem > recentItemsCollection = new ObservableCollection < RecentItem > ( ) ;
34
36
35
37
private SemaphoreSlim refreshRecentsSemaphore ;
36
38
37
39
private CancellationTokenSource refreshRecentsCTS ;
38
40
39
- private EmptyRecentsText Empty { get ; set ; } = new EmptyRecentsText ( ) ;
40
-
41
41
public string WidgetName => nameof ( RecentFilesWidget ) ;
42
42
43
43
public string AutomationProperties => "RecentFilesWidgetAutomationProperties/Name" . GetLocalizedResource ( ) ;
@@ -46,6 +46,34 @@ public sealed partial class RecentFilesWidget : UserControl, IWidgetItemModel
46
46
47
47
public bool IsWidgetSettingEnabled => UserSettingsService . AppearanceSettingsService . ShowRecentFilesWidget ;
48
48
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
+
49
77
public RecentFilesWidget ( )
50
78
{
51
79
InitializeComponent ( ) ;
@@ -54,11 +82,17 @@ public RecentFilesWidget()
54
82
refreshRecentsCTS = new CancellationTokenSource ( ) ;
55
83
56
84
// recent files could have changed while widget wasn't loaded
57
- _ = App . RecentItemsManager . UpdateRecentFilesAsync ( ) ;
85
+ _ = RefreshWidget ( ) ;
58
86
59
87
App . RecentItemsManager . RecentFilesChanged += Manager_RecentFilesChanged ;
60
88
}
61
89
90
+ public async Task RefreshWidget ( )
91
+ {
92
+ IsRecentFilesDisabledInWindows = App . RecentItemsManager . CheckIsRecentFilesEnabled ( ) is false ;
93
+ await App . RecentItemsManager . UpdateRecentFilesAsync ( ) ;
94
+ }
95
+
62
96
private async void Manager_RecentFilesChanged ( object sender , NotifyCollectionChangedEventArgs e )
63
97
{
64
98
await DispatcherQueue . EnqueueAsync ( async ( ) =>
@@ -100,7 +134,7 @@ private async Task UpdateRecentsList(NotifyCollectionChangedEventArgs e)
100
134
refreshRecentsCTS . Cancel ( ) ;
101
135
refreshRecentsCTS = new CancellationTokenSource ( ) ;
102
136
103
- Empty . Visibility = Visibility . Collapsed ;
137
+ EmptyRecentsTextVisibility = Visibility . Collapsed ;
104
138
105
139
switch ( e . Action )
106
140
{
@@ -131,9 +165,9 @@ private async Task UpdateRecentsList(NotifyCollectionChangedEventArgs e)
131
165
}
132
166
133
167
// update chevron if there aren't any items
134
- if ( recentItemsCollection . Count == 0 )
168
+ if ( recentItemsCollection . Count == 0 && ! IsRecentFilesDisabledInWindows )
135
169
{
136
- Empty . Visibility = Visibility . Visible ;
170
+ EmptyRecentsTextVisibility = Visibility . Visible ;
137
171
}
138
172
}
139
173
catch ( Exception ex )
@@ -202,7 +236,7 @@ private async void ClearRecentItems_Click(object sender, RoutedEventArgs e)
202
236
203
237
if ( success )
204
238
{
205
- Empty . Visibility = Visibility . Visible ;
239
+ EmptyRecentsTextVisibility = Visibility . Visible ;
206
240
}
207
241
}
208
242
finally
@@ -211,43 +245,14 @@ private async void ClearRecentItems_Click(object sender, RoutedEventArgs e)
211
245
}
212
246
}
213
247
214
- public Task RefreshWidget ( )
248
+ private void NotifyPropertyChanged ( [ CallerMemberName ] string propertyName = "" )
215
249
{
216
- // if files changed, event is fired to update widget
217
- return App . RecentItemsManager . UpdateRecentFilesAsync ( ) ;
250
+ PropertyChanged ? . Invoke ( this , new PropertyChangedEventArgs ( propertyName ) ) ;
218
251
}
219
252
220
253
public void Dispose ( )
221
254
{
222
255
App . RecentItemsManager . RecentFilesChanged -= Manager_RecentFilesChanged ;
223
256
}
224
257
}
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
- }
253
258
}
0 commit comments