|
4 | 4 | using CommunityToolkit.WinUI.Helpers; |
5 | 5 | using GithubPackageUpdater.Services; |
6 | 6 | using System; |
| 7 | +using System.Collections.Generic; |
| 8 | +using System.Linq; |
7 | 9 | using System.Threading.Tasks; |
8 | 10 | using System.Windows.Input; |
9 | 11 | using Windows.ApplicationModel; |
10 | 12 | using WingetGUIInstaller.Constants; |
| 13 | +using WingetGUIInstaller.Enums; |
11 | 14 | using WingetGUIInstaller.Messages; |
12 | 15 |
|
13 | 16 | namespace WingetGUIInstaller.ViewModels |
14 | 17 | { |
15 | 18 | public class SettingsPageViewModel : ObservableObject |
16 | 19 | { |
| 20 | + private readonly NavigationItemKey[] _disallowedKeys = new NavigationItemKey[] { |
| 21 | + NavigationItemKey.Settings, NavigationItemKey.About, NavigationItemKey.Console, NavigationItemKey.Home }; |
17 | 22 | private readonly ApplicationDataStorageHelper _configurationStore; |
18 | 23 | private readonly GithubPackageUpdaterSerivce _updaterSerivce; |
19 | 24 | private bool? _consoleTabEnabled; |
20 | 25 | private bool? _notificationsEnabled; |
21 | 26 | private bool? _packageSourceFilteringEnabled; |
22 | 27 | private bool? _ignoreEmptyPackageSourceEnabled; |
23 | 28 | private bool? _automaticUpdatesEnabled; |
| 29 | + private NavigationItemKey? _selectedPage; |
| 30 | + |
24 | 31 |
|
25 | 32 | public SettingsPageViewModel(ApplicationDataStorageHelper configurationStore, |
26 | 33 | GithubPackageUpdaterSerivce updaterSerivce) |
@@ -129,7 +136,30 @@ public bool AutomaticUpdatesEnabled |
129 | 136 | _configurationStore.Save(ConfigurationPropertyKeys.AutomaticUpdates, value); |
130 | 137 | } |
131 | 138 | } |
132 | | - } |
| 139 | + } |
| 140 | + |
| 141 | + public NavigationItemKey SelectedPage |
| 142 | + { |
| 143 | + get |
| 144 | + { |
| 145 | + if (_selectedPage == null) |
| 146 | + { |
| 147 | + _selectedPage = (NavigationItemKey)_configurationStore |
| 148 | + .Read(ConfigurationPropertyKeys.SelectedPage, ConfigurationPropertyKeys.SelectedPageDefaultValue); |
| 149 | + } |
| 150 | + return _selectedPage.Value; |
| 151 | + } |
| 152 | + set |
| 153 | + { |
| 154 | + if (SetProperty(ref _selectedPage, value)) |
| 155 | + { |
| 156 | + _configurationStore.Save(ConfigurationPropertyKeys.SelectedPage, (int)value); |
| 157 | + } |
| 158 | + } |
| 159 | + } |
| 160 | + |
| 161 | + public IReadOnlyList<NavigationItemKey> AvailablePages => Enum.GetValues<NavigationItemKey>().Cast<NavigationItemKey>() |
| 162 | + .Where(key => !_disallowedKeys.Contains(key)).ToList(); |
133 | 163 |
|
134 | 164 | public ICommand CheckForUpdatesCommand => new AsyncRelayCommand(CheckForUpdatesAsync); |
135 | 165 |
|
|
0 commit comments