Rework much of options UI

This commit is contained in:
2023-04-13 20:05:55 -04:00
parent ace251fd4f
commit 5c0c84a068
18 changed files with 322 additions and 331 deletions

View File

@@ -1,8 +1,6 @@
using ChrisKaczor.InstalledBrowsers;
using ChrisKaczor.Wpf.Application;
using ChrisKaczor.Wpf.Application;
using FeedCenter.Properties;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Controls.Primitives;
namespace FeedCenter.Options;
@@ -19,87 +17,20 @@ public partial class GeneralOptionsPanel
{
base.LoadPanel();
var settings = Properties.Settings.Default;
StartWithWindowsCheckBox.IsChecked = settings.StartWithWindows;
LoadBrowserComboBox(BrowserComboBox, settings.Browser);
LoadUserAgentComboBox(UserAgentComboBox, settings.DefaultUserAgent);
MarkLoaded();
}
private static void LoadBrowserComboBox(Selector selector, string selected)
private void OnSaveSettings(object sender, RoutedEventArgs e)
{
selector.SelectedIndex = 0;
ComboBoxItem selectedItem = null;
var browsers = InstalledBrowser.GetInstalledBrowsers(true);
foreach (var browser in browsers)
{
var item = new ComboBoxItem { Content = browser.Value.Name, Tag = browser.Key };
selector.Items.Add(item);
if (browser.Key == selected)
selectedItem = item;
}
if (selectedItem != null)
selector.SelectedItem = selectedItem;
SaveSettings();
}
private static void LoadUserAgentComboBox(Selector selector, string selected)
{
selector.SelectedIndex = 0;
ComboBoxItem selectedItem = null;
var userAgents = UserAgentItem.GetUserAgents();
foreach (var userAgent in userAgents)
{
var item = new ComboBoxItem { Content = userAgent.Caption, Tag = userAgent.UserAgent };
selector.Items.Add(item);
if (userAgent.UserAgent == selected)
selectedItem = item;
}
if (selectedItem != null)
selector.SelectedItem = selectedItem;
}
private void StartWithWindowsCheckBox_Click(object sender, System.Windows.RoutedEventArgs e)
private void SaveSettings()
{
if (!HasLoaded) return;
var settings = Properties.Settings.Default;
Settings.Default.Save();
if (StartWithWindowsCheckBox.IsChecked.HasValue &&
settings.StartWithWindows != StartWithWindowsCheckBox.IsChecked.Value)
settings.StartWithWindows = StartWithWindowsCheckBox.IsChecked.Value;
System.Windows.Application.Current.SetStartWithWindows(settings.StartWithWindows);
}
private void BrowserComboBox_SelectionChanged(object sender, SelectionChangedEventArgs e)
{
if (!HasLoaded) return;
var settings = Properties.Settings.Default;
settings.Browser = (string) ((ComboBoxItem) BrowserComboBox.SelectedItem).Tag;
}
private void UserAgentComboBox_SelectionChanged(object sender, SelectionChangedEventArgs e)
{
if (!HasLoaded) return;
var settings = Properties.Settings.Default;
settings.DefaultUserAgent = (string) ((ComboBoxItem) UserAgentComboBox.SelectedItem).Tag;
Application.Current.SetStartWithWindows(Settings.Default.StartWithWindows);
}
}