8
8
using System ;
9
9
using Windows . ApplicationModel . DataTransfer ;
10
10
using Windows . System ;
11
+ using WinUIGallery . ControlPages ;
11
12
using WinUIGallery . Helpers ;
12
13
13
14
namespace WinUIGallery . Pages ;
@@ -33,18 +34,22 @@ public SettingsPage()
33
34
{
34
35
this . InitializeComponent ( ) ;
35
36
Loaded += OnSettingsPageLoaded ;
36
- ClearVisitedSamplesCard . IsEnabled = SettingsHelper . Exists ( SettingsKeys . RecentlyVisited ) ;
37
- UnfavoriteSamplesCard . IsEnabled = SettingsHelper . Exists ( SettingsKeys . Favorites ) ;
38
- SamplesSettingsExpander . IsExpanded = ClearVisitedSamplesCard . IsEnabled || UnfavoriteSamplesCard . IsEnabled ;
39
37
}
40
38
41
39
protected override void OnNavigatedTo ( NavigationEventArgs e )
42
40
{
43
41
base . OnNavigatedTo ( e ) ;
44
42
}
45
43
44
+ private void CheckRecentAndFavoriteButtonStates ( )
45
+ {
46
+ ClearRecentBtn . IsEnabled = SettingsHelper . Exists ( SettingsKeys . RecentlyVisited ) ;
47
+ UnfavoriteBtn . IsEnabled = SettingsHelper . Exists ( SettingsKeys . Favorites ) ;
48
+ }
49
+
46
50
private void OnSettingsPageLoaded ( object sender , RoutedEventArgs e )
47
51
{
52
+ CheckRecentAndFavoriteButtonStates ( ) ;
48
53
var currentTheme = ThemeHelper . RootTheme ;
49
54
switch ( currentTheme )
50
55
{
@@ -161,20 +166,43 @@ private async void bugRequestCard_Click(object sender, RoutedEventArgs e)
161
166
await Launcher . LaunchUriAsync ( new Uri ( "https://github.com/microsoft/WinUI-Gallery/issues/new/choose" ) ) ;
162
167
163
168
}
164
-
165
- private void ClearRecentlyVisitedSamples_Click ( object sender , RoutedEventArgs e )
169
+ private async void UnfavoriteBtn_Click ( object sender , RoutedEventArgs e )
166
170
{
167
- ClearRecentlyVisitedSamplesFlyout . Hide ( ) ;
168
- SettingsHelper . Delete ( SettingsKeys . RecentlyVisited ) ;
169
- ClearVisitedSamplesCard . IsEnabled = false ;
170
- SamplesSettingsExpander . IsExpanded = ClearVisitedSamplesCard . IsEnabled || UnfavoriteSamplesCard . IsEnabled ;
171
+ ContentDialog dialog = new ( )
172
+ {
173
+ XamlRoot = this . XamlRoot ,
174
+ Style = Application . Current . Resources [ "DefaultContentDialogStyle" ] as Style ,
175
+ Title = "Remove all favorites?" ,
176
+ PrimaryButtonText = "Remove" ,
177
+ CloseButtonText = "Cancel" ,
178
+ DefaultButton = ContentDialogButton . Primary ,
179
+ Content = "This will unfavorite all your samples."
180
+ } ;
181
+ dialog . PrimaryButtonClick += ( s , args ) =>
182
+ {
183
+ SettingsHelper . Delete ( SettingsKeys . Favorites ) ;
184
+ CheckRecentAndFavoriteButtonStates ( ) ;
185
+ } ;
186
+ var result = await dialog . ShowAsync ( ) ;
171
187
}
172
188
173
- private void UnfavoriteAllSamples_Click ( object sender , RoutedEventArgs e )
189
+ private async void ClearRecentBtn_Click ( object sender , RoutedEventArgs e )
174
190
{
175
- UnfavoriteAllSamplesFlyout . Hide ( ) ;
176
- SettingsHelper . Delete ( SettingsKeys . Favorites ) ;
177
- UnfavoriteSamplesCard . IsEnabled = false ;
178
- SamplesSettingsExpander . IsExpanded = ClearVisitedSamplesCard . IsEnabled || UnfavoriteSamplesCard . IsEnabled ;
191
+ ContentDialog dialog = new ( )
192
+ {
193
+ XamlRoot = this . XamlRoot ,
194
+ Style = Application . Current . Resources [ "DefaultContentDialogStyle" ] as Style ,
195
+ Title = "Clear recently visited samples?" ,
196
+ PrimaryButtonText = "Clear" ,
197
+ CloseButtonText = "Cancel" ,
198
+ DefaultButton = ContentDialogButton . Primary ,
199
+ Content = "This will remove all samples from your recent history."
200
+ } ;
201
+ dialog . PrimaryButtonClick += ( s , args ) =>
202
+ {
203
+ SettingsHelper . Delete ( SettingsKeys . RecentlyVisited ) ;
204
+ CheckRecentAndFavoriteButtonStates ( ) ;
205
+ } ;
206
+ var result = await dialog . ShowAsync ( ) ;
179
207
}
180
208
}
0 commit comments