-
Notifications
You must be signed in to change notification settings - Fork 722
Expand file tree
/
Copy pathSettingsPage.xaml.cs
More file actions
204 lines (180 loc) · 6.87 KB
/
SettingsPage.xaml.cs
File metadata and controls
204 lines (180 loc) · 6.87 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT License.
using Microsoft.UI;
using Microsoft.UI.Xaml;
using Microsoft.UI.Xaml.Controls;
using Microsoft.UI.Xaml.Navigation;
using System;
using Windows.ApplicationModel.DataTransfer;
using Windows.System;
using WinUIGallery.Helpers;
namespace WinUIGallery.Pages;
/// <summary>
/// A page that displays the app's settings.
/// </summary>
public sealed partial class SettingsPage : Page
{
public string Version
{
get
{
return ProcessInfoHelper.GetVersion() is Version version
? string.Format("{0}.{1}.{2}.{3}", version.Major, version.Minor, version.Build, version.Revision)
: string.Empty;
}
}
public string WinAppSdkRuntimeDetails => VersionHelper.WinAppSdkRuntimeDetails;
private int lastNavigationSelectionMode = 0;
private SettingsHelper Settings => SettingsHelper.Current;
public SettingsPage()
{
this.InitializeComponent();
Loaded += OnSettingsPageLoaded;
}
protected override void OnNavigatedTo(NavigationEventArgs e)
{
base.OnNavigatedTo(e);
}
private void CheckRecentAndFavoriteButtonStates()
{
ClearRecentBtn.IsEnabled = SettingsHelper.Current.RecentlyVisited.Count > 0;
UnfavoriteBtn.IsEnabled = SettingsHelper.Current.Favorites.Count > 0;
}
private void OnSettingsPageLoaded(object sender, RoutedEventArgs e)
{
CheckRecentAndFavoriteButtonStates();
var currentTheme = ThemeHelper.RootTheme;
switch (currentTheme)
{
case ElementTheme.Light:
themeMode.SelectedIndex = 0;
break;
case ElementTheme.Dark:
themeMode.SelectedIndex = 1;
break;
case ElementTheme.Default:
themeMode.SelectedIndex = 2;
break;
}
if (App.MainWindow.NavigationView.PaneDisplayMode == NavigationViewPaneDisplayMode.Auto)
{
navigationLocation.SelectedIndex = 0;
}
else
{
navigationLocation.SelectedIndex = 1;
}
lastNavigationSelectionMode = navigationLocation.SelectedIndex;
if (ElementSoundPlayer.State == ElementSoundPlayerState.On)
soundToggle.IsOn = true;
if (ElementSoundPlayer.SpatialAudioMode == ElementSpatialAudioMode.On)
spatialSoundBox.IsOn = true;
}
private void themeMode_SelectionChanged(object sender, RoutedEventArgs e)
{
if (sender is not UIElement senderUiLement ||
(themeMode.SelectedItem as ComboBoxItem)?.Tag.ToString() is not string selectedTheme ||
WindowHelper.GetWindowForElement(this) is not Window window)
{
return;
}
ThemeHelper.RootTheme = EnumHelper.GetEnum<ElementTheme>(selectedTheme);
var elementThemeResolved = ThemeHelper.RootTheme == ElementTheme.Default ? ThemeHelper.ActualTheme : ThemeHelper.RootTheme;
TitleBarHelper.ApplySystemThemeToCaptionButtons(window, elementThemeResolved);
// announce visual change to automation
UIHelper.AnnounceActionForAccessibility(
senderUiLement,
$"Theme changed to {elementThemeResolved}",
"ThemeChangedNotificationActivityId");
}
private void soundToggle_Toggled(object sender, RoutedEventArgs e)
{
if (soundToggle.IsOn == true)
{
SpatialAudioCard.IsEnabled = true;
ElementSoundPlayer.State = ElementSoundPlayerState.On;
}
else
{
SpatialAudioCard.IsEnabled = false;
spatialSoundBox.IsOn = false;
ElementSoundPlayer.State = ElementSoundPlayerState.Off;
ElementSoundPlayer.SpatialAudioMode = ElementSpatialAudioMode.Off;
}
}
private void navigationLocation_SelectionChanged(object sender, SelectionChangedEventArgs e)
{
// Since setting the left mode does not look at the old setting we
// need to check if this is an actual update
if (navigationLocation.SelectedIndex != lastNavigationSelectionMode)
{
NavigationOrientationHelper.IsLeftModeForElement(navigationLocation.SelectedIndex == 0);
lastNavigationSelectionMode = navigationLocation.SelectedIndex;
}
}
private void spatialSoundBox_Toggled(object sender, RoutedEventArgs e)
{
if (soundToggle.IsOn == true)
{
ElementSoundPlayer.SpatialAudioMode = ElementSpatialAudioMode.Off;
}
else
{
ElementSoundPlayer.SpatialAudioMode = ElementSpatialAudioMode.On;
}
}
private void soundPageHyperlink_Click(object sender, RoutedEventArgs e)
{
App.MainWindow.Navigate(typeof(ItemPage), "Sound");
}
private void toCloneRepoCard_Click(object sender, RoutedEventArgs e)
{
DataPackage package = new DataPackage();
package.SetText(gitCloneTextBlock.Text);
Clipboard.SetContent(package);
}
private async void bugRequestCard_Click(object sender, RoutedEventArgs e)
{
await Launcher.LaunchUriAsync(new Uri("https://github.com/microsoft/WinUI-Gallery/issues/new/choose"));
}
private async void UnfavoriteBtn_Click(object sender, RoutedEventArgs e)
{
ContentDialog dialog = new()
{
XamlRoot = this.XamlRoot,
Style = Application.Current.Resources["DefaultContentDialogStyle"] as Style,
Title = "Remove all favorites?",
PrimaryButtonText = "Remove",
CloseButtonText = "Cancel",
DefaultButton = ContentDialogButton.Primary,
Content = "This will unfavorite all your samples.",
RequestedTheme = this.ActualTheme
};
dialog.PrimaryButtonClick += (s, args) =>
{
SettingsHelper.Current.UpdateFavorites(items => items.Clear());
CheckRecentAndFavoriteButtonStates();
};
var result = await dialog.ShowAsync();
}
private async void ClearRecentBtn_Click(object sender, RoutedEventArgs e)
{
ContentDialog dialog = new()
{
XamlRoot = this.XamlRoot,
Style = Application.Current.Resources["DefaultContentDialogStyle"] as Style,
Title = "Clear recently visited samples?",
PrimaryButtonText = "Clear",
CloseButtonText = "Cancel",
DefaultButton = ContentDialogButton.Primary,
Content = "This will remove all samples from your recent history.",
RequestedTheme = this.ActualTheme
};
dialog.PrimaryButtonClick += (s, args) =>
{
SettingsHelper.Current.UpdateRecentlyVisited(items => items.Clear());
CheckRecentAndFavoriteButtonStates();
};
var result = await dialog.ShowAsync();
}
}