Added functionality for General Settings Page (#1664)

* archive

* formmated code

* reverted changes to test class file.

* reverted changes to test file: reverted name

* added class models and updated link

* removed test console project
This commit is contained in:
Lavius Motileng
2020-03-24 19:55:02 -07:00
parent 2a0e92e4e2
commit 4243feaf37
32 changed files with 442 additions and 307 deletions

View File

@@ -13,17 +13,22 @@
<ScrollViewer>
<StackPanel Orientation="Vertical" Margin="14,0,14,48">
<ToggleSwitch Header="Start at startup" IsOn="True" Margin="0,14,0,0" />
<ToggleSwitch Header="Run at startup" x:Name="ToggleSwitch_RunAtStartUp" Margin="0,14,0,0" Toggled="ToggleSwitch_RunAtStartUp_Toggled" />
<muxc:RadioButtons Header="Theme" Margin="0, 28,0,0">
<RadioButton Content="Dark"/>
<RadioButton Content="Light"/>
<RadioButton Content="System default" IsChecked="True"/>
<RadioButton x:Name="Rodio_Theme_Dark" Content="Dark" Tag="Dark" Checked="Theme_Changed"/>
<RadioButton x:Name="Rodio_Theme_Light" Content="Light" Tag="Light" Checked="Theme_Changed"/>
<RadioButton x:Name="Rodio_Theme_Default" Content="System default" Tag="System" Checked="Theme_Changed"/>
</muxc:RadioButtons>
<!--
<ToggleSwitch Header="Disable telemetry" IsOn="True" Margin="0,14,0,0" />
<TextBlock Text="PowerToys currently respects the Windows data &amp; feedback setting" Opacity="0.8" Margin="0,0,0,0" />
-->
<Button Background="{ThemeResource SystemAccentColor}" Content="Restart as admin" Margin="0,10,0,0" Foreground="White" Click="Restart_Elevated" />
<!--
<TextBlock Text="Default apps" Style="{StaticResource SubtitleTextBlockStyle}" Margin="0,34,0,8"/>
<ComboBox Header="Shell" SelectedIndex="0" MinWidth="240" Margin="0,14,0,0">
<ComboBoxItem>PowerShell</ComboBoxItem>
@@ -31,14 +36,16 @@
<ComboBox Header="Terminal" SelectedIndex="0" MinWidth="240" Margin="0,14,0,0">
<ComboBoxItem>Windows Console</ComboBoxItem>
</ComboBox>
-->
<TextBlock Text="About PowerToys" Style="{StaticResource SubtitleTextBlockStyle}" Margin="0,34,0,8"/>
<TextBlock FontWeight="Bold" Text="Version 0.15.1.0" Margin="0,14,0,0" />
<Button Background="{ThemeResource SystemAccentColor}" Content="Check for updates" Margin="0,10,0,0" Foreground="White"/>
<!-- TO DO: The styling of this button should be improved so the hover/pressed states are representing the SystemAccentColor -->
<!--<Button Background="{ThemeResource SystemAccentColor}" Content="Check for updates" Margin="0,10,0,0" Foreground="White" />
TO DO: The styling of this button should be improved so the hover/pressed states are representing the SystemAccentColor -->
<HyperlinkButton Content="Report a bug" Margin="0,14,0,0" />
<HyperlinkButton Content="Request a feature" />
<HyperlinkButton Content="Privacy statement" />
<HyperlinkButton Content="Report a bug" Margin="0,14,0,0" NavigateUri="https://github.com/microsoft/PowerToys/issues" />
<HyperlinkButton Content="Request a feature" NavigateUri="https://github.com/microsoft/PowerToys/issues"/>
<HyperlinkButton Content="Privacy statement" NavigateUri=" http://go.microsoft.com/fwlink/?LinkId=521839" />
</StackPanel>
</ScrollViewer>
</Grid>

View File

@@ -1,29 +1,128 @@
using Microsoft.PowerToys.Settings.UI.ViewModels;
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Runtime.InteropServices.WindowsRuntime;
using Windows.Foundation;
using Windows.Foundation.Collections;
using Windows.UI.Xaml;
using Windows.UI.Xaml.Controls;
using Windows.UI.Xaml.Controls.Primitives;
using Windows.UI.Xaml.Data;
using Windows.UI.Xaml.Input;
using Windows.UI.Xaml.Media;
using Windows.UI.Xaml.Navigation;
// <copyright file="GeneralPage.xaml.cs" company="Microsoft Corp">
// Copyright (c) Microsoft Corp. All rights reserved.
// </copyright>
namespace Microsoft.PowerToys.Settings.UI.Views
{
using System;
using System.IO;
using Microsoft.PowerToys.Settings.UI.Lib;
using Microsoft.PowerToys.Settings.UI.ViewModels;
using Windows.UI.Popups;
using Windows.UI.Xaml;
using Windows.UI.Xaml.Controls;
using Windows.UI.Xaml.Navigation;
/// <summary>
/// General Settings Page.
/// </summary>
public sealed partial class GeneralPage : Page
{
/// <summary>
/// Gets view model.
/// </summary>
public GeneralViewModel ViewModel { get; } = new GeneralViewModel();
/// <summary>
/// Initializes a new instance of the <see cref="GeneralPage"/> class.
/// General Settings page constructor.
/// </summary>
public GeneralPage()
{
this.InitializeComponent();
}
/// <inheritdoc/>
protected override void OnNavigatedTo(NavigationEventArgs e)
{
GeneralSettings settings = SettingsUtils.GetSettings<GeneralSettings>(string.Empty);
base.OnNavigatedTo(e);
// load and apply theme settings
this.ReLoadTheme(settings.theme);
// load run on start up ui settings value and update the ui state.
this.ToggleSwitch_RunAtStartUp.IsOn = settings.startup;
}
/// <summary>
/// Update and save theme settings to json file.
/// </summary>
/// <param name="themeName">theme name.</param>
private void ReLoadTheme(string themeName)
{
switch (themeName.ToLower())
{
case "light":
ShellPage.ShellHandler.RequestedTheme = ElementTheme.Light;
this.Rodio_Theme_Light.IsChecked = true;
break;
case "dark":
ShellPage.ShellHandler.RequestedTheme = ElementTheme.Dark;
this.Rodio_Theme_Dark.IsChecked = true;
break;
case "system":
ShellPage.ShellHandler.RequestedTheme = ElementTheme.Default;
this.Rodio_Theme_Default.IsChecked = true;
break;
}
}
private void ToggleSwitch_RunAtStartUp_Toggled(object sender, RoutedEventArgs e)
{
ToggleSwitch swt = sender as ToggleSwitch;
if (swt != null)
{
GeneralSettings settings = SettingsUtils.GetSettings<GeneralSettings>(string.Empty);
string startup = swt.IsOn.ToString().ToLower();
switch (startup)
{
case "true":
settings.startup = true;
break;
case "false":
settings.startup = false;
break;
}
SettingsUtils.SaveSettings<GeneralSettings>(settings, string.Empty);
OutGoingGeneralSettings outsettings = new OutGoingGeneralSettings(settings);
if (ShellPage.Run_OnStartUp_Callback != null)
{
ShellPage.Run_OnStartUp_Callback(outsettings.ToString());
}
}
}
private void Restart_Elevated(object sender, RoutedEventArgs e)
{
GeneralSettings settings = SettingsUtils.GetSettings<GeneralSettings>(string.Empty);
settings.run_elevated = true;
OutGoingGeneralSettings outsettings = new OutGoingGeneralSettings(settings);
if (ShellPage.Restart_Elevated_Callback != null)
{
ShellPage.Restart_Elevated_Callback(outsettings.ToString());
}
}
private void Theme_Changed(object sender, RoutedEventArgs e)
{
RadioButton rb = sender as RadioButton;
if (rb != null)
{
string themeName = rb.Tag.ToString();
this.ReLoadTheme(themeName);
// update and save settings to file.
GeneralSettings settings = SettingsUtils.GetSettings<GeneralSettings>(string.Empty);
settings.theme = themeName;
SettingsUtils.SaveSettings<GeneralSettings>(settings,string.Empty);
}
}
}
}

View File

@@ -1,18 +0,0 @@
<Page
x:Class="Microsoft.PowerToys.Settings.UI.Views.MainPage"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
Style="{StaticResource PageStyle}"
mc:Ignorable="d">
<Grid x:Name="ContentArea" Margin="{StaticResource MediumLeftRightMargin}">
<Grid
Background="{ThemeResource SystemControlPageBackgroundChromeLowBrush}">
<!--
The SystemControlPageBackgroundChromeLowBrush background represents where you should place your content.
Place your content here.
-->
</Grid>
</Grid>
</Page>

View File

@@ -1,18 +0,0 @@
using System;
using Microsoft.PowerToys.Settings.UI.ViewModels;
using Windows.UI.Xaml.Controls;
namespace Microsoft.PowerToys.Settings.UI.Views
{
public sealed partial class MainPage : Page
{
public MainViewModel ViewModel { get; } = new MainViewModel();
public MainPage()
{
InitializeComponent();
}
}
}

View File

@@ -52,10 +52,10 @@
<FontIcon Glyph="&#xE713;"/>
</winui:NavigationViewItem.Icon>
</winui:NavigationViewItem>
<winui:NavigationViewItem x:Uid="Shell_Main" Icon="Home" helpers:NavHelper.NavigateTo="views:MainPage" />
<!--<winui:NavigationViewItem x:Uid="Shell_Main" Icon="Home" helpers:NavHelper.NavigateTo="views:MainPage" />
<winui:NavigationViewItem x:Uid="Shell_Test1" Icon="Play" helpers:NavHelper.NavigateTo="views:Test1Page" />
<winui:NavigationViewItem x:Uid="Shell_Test2" Icon="Refresh" helpers:NavHelper.NavigateTo="views:Test2Page" />
<winui:NavigationViewItem x:Uid="Shell_Test3" Icon="Save" helpers:NavHelper.NavigateTo="views:Test3Page" />
<winui:NavigationViewItem x:Uid="Shell_Test3" Icon="Save" helpers:NavHelper.NavigateTo="views:Test3Page" />-->
</winui:NavigationView.MenuItems>
<i:Interaction.Behaviors>
<behaviors:NavigationViewHeaderBehavior

View File

@@ -1,25 +1,79 @@
using System;
using Microsoft.PowerToys.Settings.UI.Activation;
using Microsoft.PowerToys.Settings.UI.Helpers;
using Microsoft.PowerToys.Settings.UI.Services;
using Microsoft.PowerToys.Settings.UI.ViewModels;
using Windows.UI.Xaml.Controls;
// <copyright file="ShellPage.xaml.cs" company="Microsoft Corp">
// Copyright (c) Microsoft Corp. All rights reserved.
// </copyright>
namespace Microsoft.PowerToys.Settings.UI.Views
{
// TODO WTS: Change the icons and titles for all NavigationViewItems in ShellPage.xaml.
using System;
using Microsoft.PowerToys.Settings.UI.Activation;
using Microsoft.PowerToys.Settings.UI.Helpers;
using Microsoft.PowerToys.Settings.UI.Services;
using Microsoft.PowerToys.Settings.UI.ViewModels;
using Windows.UI.Xaml.Controls;
/// <summary>
/// Root page.
/// </summary>
public sealed partial class ShellPage : UserControl
{
/// <summary>
/// Delcaration for the ipc callback function.
/// </summary>
/// <param name="msg">message.</param>
public delegate void IPCMessageCallback(string msg);
/// <summary>
/// Gets view model.
/// </summary>
public ShellViewModel ViewModel { get; } = new ShellViewModel();
/// <summary>
/// A shell handler to be used to update contents of the shell dynamically from page within the frame.
/// </summary>
public static Microsoft.UI.Xaml.Controls.NavigationView ShellHandler = null;
/// <summary>
/// IPC callback function for restart elevated.
/// </summary>
public static IPCMessageCallback Restart_Elevated_Callback = null;
/// <summary>
/// IPC callback function for run on start up.
/// </summary>
public static IPCMessageCallback Run_OnStartUp_Callback = null;
/// <summary>
/// Initializes a new instance of the <see cref="ShellPage"/> class.
/// Shell page constructor.
/// </summary>
public ShellPage()
{
InitializeComponent();
DataContext = ViewModel;
ViewModel.Initialize(shellFrame, navigationView, KeyboardAccelerators);
NavigationService.Navigate(typeof(MainPage));
this.InitializeComponent();
this.DataContext = this.ViewModel;
ShellHandler = this.navigationView;
this.ViewModel.Initialize(this.shellFrame, this.navigationView, this.KeyboardAccelerators);
this.shellFrame.Navigate(typeof(GeneralPage));
}
/// <summary>
/// Restart elevated callback function initialization.
/// </summary>
/// <param name="implmentation">delegate function implementation.</param>
public void SetRestartElevatedCallback(IPCMessageCallback implmentation)
{
Restart_Elevated_Callback = implmentation;
}
/// <summary>
/// Run on start up callback function elevated initialization.
/// </summary>
/// <param name="implmentation">delegate function implementation.</param>
public void SetRunOnStartUpCallback(IPCMessageCallback implmentation)
{
Run_OnStartUp_Callback = implmentation;
}
}
}

View File

@@ -1,18 +0,0 @@
<Page
x:Class="Microsoft.PowerToys.Settings.UI.Views.Test1Page"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
Style="{StaticResource PageStyle}"
mc:Ignorable="d">
<Grid x:Name="ContentArea" Margin="{StaticResource MediumLeftRightMargin}">
<Grid
Background="{ThemeResource SystemControlPageBackgroundChromeLowBrush}">
<!--
The SystemControlPageBackgroundChromeLowBrush background represents where you should place your content.
Place your content here.
-->
</Grid>
</Grid>
</Page>

View File

@@ -1,18 +0,0 @@
using System;
using Microsoft.PowerToys.Settings.UI.ViewModels;
using Windows.UI.Xaml.Controls;
namespace Microsoft.PowerToys.Settings.UI.Views
{
public sealed partial class Test1Page : Page
{
public Test1ViewModel ViewModel { get; } = new Test1ViewModel();
public Test1Page()
{
InitializeComponent();
}
}
}

View File

@@ -1,18 +0,0 @@
<Page
x:Class="Microsoft.PowerToys.Settings.UI.Views.Test2Page"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
Style="{StaticResource PageStyle}"
mc:Ignorable="d">
<Grid x:Name="ContentArea" Margin="{StaticResource MediumLeftRightMargin}">
<Grid
Background="{ThemeResource SystemControlPageBackgroundChromeLowBrush}">
<!--
The SystemControlPageBackgroundChromeLowBrush background represents where you should place your content.
Place your content here.
-->
</Grid>
</Grid>
</Page>

View File

@@ -1,18 +0,0 @@
using System;
using Microsoft.PowerToys.Settings.UI.ViewModels;
using Windows.UI.Xaml.Controls;
namespace Microsoft.PowerToys.Settings.UI.Views
{
public sealed partial class Test2Page : Page
{
public Test2ViewModel ViewModel { get; } = new Test2ViewModel();
public Test2Page()
{
InitializeComponent();
}
}
}

View File

@@ -1,18 +0,0 @@
<Page
x:Class="Microsoft.PowerToys.Settings.UI.Views.Test3Page"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
Style="{StaticResource PageStyle}"
mc:Ignorable="d">
<Grid x:Name="ContentArea" Margin="{StaticResource MediumLeftRightMargin}">
<Grid
Background="{ThemeResource SystemControlPageBackgroundChromeLowBrush}">
<!--
The SystemControlPageBackgroundChromeLowBrush background represents where you should place your content.
Place your content here.
-->
</Grid>
</Grid>
</Page>

View File

@@ -1,18 +0,0 @@
using System;
using Microsoft.PowerToys.Settings.UI.ViewModels;
using Windows.UI.Xaml.Controls;
namespace Microsoft.PowerToys.Settings.UI.Views
{
public sealed partial class Test3Page : Page
{
public Test3ViewModel ViewModel { get; } = new Test3ViewModel();
public Test3Page()
{
InitializeComponent();
}
}
}