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

4
.editorconfig Normal file
View File

@ -0,0 +1,4 @@
[*.cs]
# SA1201: Elements should appear in the correct order
dotnet_diagnostic.SA1201.severity = none

View File

@ -186,6 +186,12 @@ EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Microsoft.PowerToys.Settings.UI", "src\core\Microsoft.PowerToys.Settings.UI\Microsoft.PowerToys.Settings.UI.csproj", "{4EB9C181-96E2-4587-AB98-2DB84C1A2310}"
EndProject
Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "Microsoft.PowerToys.Settings.IPCWrapperPS", "src\core\Microsoft.PowerToys.Settings.IPCWrapperPS\Microsoft.PowerToys.Settings.IPCWrapperPS.vcxproj", "{C073B057-B157-40F0-8678-1DCD119D841C}"
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Solution Items", "Solution Items", "{4981CCD1-4CD9-4A49-B240-00AA46493FF8}"
ProjectSection(SolutionItems) = preProject
.editorconfig = .editorconfig
EndProjectSection
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Microsoft.PowerToys.Settings.UI.Lib", "src\core\Microsoft.PowerToys.Settings.UI.Lib\Microsoft.PowerToys.Settings.UI.Lib.csproj", "{B1BCC8C6-46B5-4BFA-8F22-20F32D99EC6A}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
@ -635,6 +641,14 @@ Global
{C073B057-B157-40F0-8678-1DCD119D841C}.Release|ARM64.ActiveCfg = Release|Win32
{C073B057-B157-40F0-8678-1DCD119D841C}.Release|x64.ActiveCfg = Release|x64
{C073B057-B157-40F0-8678-1DCD119D841C}.Release|x86.ActiveCfg = Release|Win32
{B1BCC8C6-46B5-4BFA-8F22-20F32D99EC6A}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{B1BCC8C6-46B5-4BFA-8F22-20F32D99EC6A}.Debug|Any CPU.Build.0 = Debug|Any CPU
{B1BCC8C6-46B5-4BFA-8F22-20F32D99EC6A}.Debug|x64.ActiveCfg = Debug|Any CPU
{B1BCC8C6-46B5-4BFA-8F22-20F32D99EC6A}.Debug|x64.Build.0 = Debug|Any CPU
{B1BCC8C6-46B5-4BFA-8F22-20F32D99EC6A}.Release|Any CPU.ActiveCfg = Release|Any CPU
{B1BCC8C6-46B5-4BFA-8F22-20F32D99EC6A}.Release|Any CPU.Build.0 = Release|Any CPU
{B1BCC8C6-46B5-4BFA-8F22-20F32D99EC6A}.Release|x64.ActiveCfg = Release|Any CPU
{B1BCC8C6-46B5-4BFA-8F22-20F32D99EC6A}.Release|x64.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
@ -683,6 +697,7 @@ Global
{F88B6FD1-14BD-48DB-85C2-6C51B8045121} = {C3081D9A-1586-441A-B5F4-ED815B3719C1}
{4EB9C181-96E2-4587-AB98-2DB84C1A2310} = {C3081D9A-1586-441A-B5F4-ED815B3719C1}
{C073B057-B157-40F0-8678-1DCD119D841C} = {C3081D9A-1586-441A-B5F4-ED815B3719C1}
{B1BCC8C6-46B5-4BFA-8F22-20F32D99EC6A} = {C3081D9A-1586-441A-B5F4-ED815B3719C1}
EndGlobalSection
GlobalSection(ExtensibilityGlobals) = postSolution
SolutionGuid = {C3A2F9D1-7930-4EF4-A6FC-7EE0A99821D0}

View File

@ -0,0 +1,47 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Text.Json;
using System.Text.Json.Serialization;
namespace Microsoft.PowerToys.Settings.UI.ViewModels
{
public class GeneralSettings
{
public bool packaged { get; set; }
public bool startup { get; set; }
public bool is_elevated { get; set; }
public bool run_elevated { get; set; }
public bool is_admin { get; set; }
public string theme { get; set; }
public string system_theme { get; set; }
public string powertoys_version { get; set; }
public override string ToString()
{
return JsonSerializer.Serialize(this);
}
}
public class OutGoingGeneralSettings
{
public GeneralSettings general { get; set; }
public OutGoingGeneralSettings()
{
this.general = null;
}
public OutGoingGeneralSettings(GeneralSettings generalSettings)
{
this.general = generalSettings;
}
public override string ToString()
{
return JsonSerializer.Serialize(this);
}
}
}

View File

@ -0,0 +1,11 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>netstandard2.0</TargetFramework>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="System.Text.Json" Version="4.7.1" />
</ItemGroup>
</Project>

View File

@ -0,0 +1,52 @@
using System;
using System.Collections.Generic;
using System.IO;
using System.Text;
using System.Text.Json;
namespace Microsoft.PowerToys.Settings.UI.Lib
{
public static class SettingsUtils
{
/// <summary>
/// Get path to the json settings file.
/// </summary>
/// <returns>string path.</returns>
public static string GetSettingsPath(string powertoy)
{
if(string.IsNullOrWhiteSpace(powertoy))
{
return Path.Combine(
Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData),
$"Microsoft\\PowerToys\\settings.json");
}
return Path.Combine(
Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData),
$"Microsoft\\PowerToys\\{powertoy}\\settings.json");
}
/// <summary>
/// Get a Deserialized object of the json settings string.
/// </summary>
/// <returns>Deserialized json settings object.</returns>
public static T GetSettings<T>(string powertoy)
{
var jsonSettingsString = System.IO.File.ReadAllText(SettingsUtils.GetSettingsPath(powertoy));
return JsonSerializer.Deserialize<T>(jsonSettingsString);
}
/// <summary>
/// Save settings to a json file.
/// </summary>
/// <param name="settings">dynamic json settings object.</param>
public static void SaveSettings<T>(T settings, string powertoy)
{
if(settings != null)
{
System.IO.File.WriteAllText(
SettingsUtils.GetSettingsPath(powertoy),
settings.ToString());
}
}
}
}

View File

@ -7,8 +7,10 @@
xmlns:Controls="clr-namespace:Microsoft.Toolkit.Wpf.UI.Controls;assembly=Microsoft.Toolkit.Wpf.UI.Controls"
xmlns:xaml="clr-namespace:Microsoft.Toolkit.Wpf.UI.XamlHost;assembly=Microsoft.Toolkit.Wpf.UI.XamlHost"
mc:Ignorable="d"
Title="PowerToys Settings" Height="800" Width="1000">
<Grid>
Title="PowerToys Settings" Height="800" Width="800">
<Grid >
<!--<xaml:WindowsXamlHost InitialTypeName="Microsoft.PowerToys.Settings.UI.Controls.DummyUserControl" ChildChanged="WindowsXamlHost_ChildChanged" />-->
<xaml:WindowsXamlHost InitialTypeName="Microsoft.PowerToys.Settings.UI.Views.ShellPage" ChildChanged="WindowsXamlHost_ChildChanged" />
</Grid>
</Window>

View File

@ -5,7 +5,7 @@
using System;
using System.Windows;
using Microsoft.PowerToys.Settings.UI.Views;
using Microsoft.Toolkit.Wpf.UI.XamlHost;
using System.Threading;
namespace Microsoft.PowerToys.Settings.UI.Runner
{
@ -23,6 +23,35 @@ namespace Microsoft.PowerToys.Settings.UI.Runner
WindowsXamlHost windowsXamlHost = sender as WindowsXamlHost;
ShellPage shellPage = windowsXamlHost.GetUwpInternalObject() as ShellPage;
if (shellPage != null)
{
shellPage.SetRestartElevatedCallback(delegate(string msg)
{
MessageBox.Show(
msg,
"Restart Elevated",
MessageBoxButton.OK);
Program.ipcmanager.SendMessage(msg);
int milliseconds = 2000;
Thread.Sleep(milliseconds);
System.Windows.Application.Current.Shutdown();
});
shellPage.SetRunOnStartUpCallback(delegate (string msg)
{
MessageBox.Show(
msg,
"Run On Start Up",
MessageBoxButton.OK);
Program.ipcmanager.SendMessage(msg);
});
}
}
if (shellPage != null)
{
}

View File

@ -134,29 +134,13 @@
<Compile Include="Services\ActivationService.cs" />
<Compile Include="Services\NavigationService.cs" />
<Compile Include="ViewModels\GeneralViewModel.cs" />
<Compile Include="ViewModels\MainViewModel.cs" />
<Compile Include="ViewModels\ShellViewModel.cs" />
<Compile Include="ViewModels\Test1ViewModel.cs" />
<Compile Include="ViewModels\Test2ViewModel.cs" />
<Compile Include="ViewModels\Test3ViewModel.cs" />
<Compile Include="Views\GeneralPage.xaml.cs">
<DependentUpon>GeneralPage.xaml</DependentUpon>
</Compile>
<Compile Include="Views\MainPage.xaml.cs">
<DependentUpon>MainPage.xaml</DependentUpon>
</Compile>
<Compile Include="Views\ShellPage.xaml.cs">
<DependentUpon>ShellPage.xaml</DependentUpon>
</Compile>
<Compile Include="Views\Test1Page.xaml.cs">
<DependentUpon>Test1Page.xaml</DependentUpon>
</Compile>
<Compile Include="Views\Test2Page.xaml.cs">
<DependentUpon>Test2Page.xaml</DependentUpon>
</Compile>
<Compile Include="Views\Test3Page.xaml.cs">
<DependentUpon>Test3Page.xaml</DependentUpon>
</Compile>
</ItemGroup>
<ItemGroup>
<AppxManifest Include="Package.appxmanifest">
@ -187,6 +171,9 @@
<PackageReference Include="Microsoft.Xaml.Behaviors.Uwp.Managed">
<Version>2.0.1</Version>
</PackageReference>
<PackageReference Include="Newtonsoft.Json">
<Version>12.0.3</Version>
</PackageReference>
</ItemGroup>
<ItemGroup>
<PRIResource Include="Strings\en-us\Resources.resw" />
@ -220,26 +207,16 @@
<SubType>Designer</SubType>
<Generator>MSBuild:Compile</Generator>
</Page>
<Page Include="Views\MainPage.xaml">
<Generator>MSBuild:Compile</Generator>
<SubType>Designer</SubType>
</Page>
<Page Include="Views\ShellPage.xaml">
<Generator>MSBuild:Compile</Generator>
<SubType>Designer</SubType>
</Page>
<Page Include="Views\Test1Page.xaml">
<Generator>MSBuild:Compile</Generator>
<SubType>Designer</SubType>
</Page>
<Page Include="Views\Test2Page.xaml">
<Generator>MSBuild:Compile</Generator>
<SubType>Designer</SubType>
</Page>
<Page Include="Views\Test3Page.xaml">
<Generator>MSBuild:Compile</Generator>
<SubType>Designer</SubType>
</Page>
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\Microsoft.PowerToys.Settings.UI.Lib\Microsoft.PowerToys.Settings.UI.Lib.csproj">
<Project>{b1bcc8c6-46b5-4bfa-8f22-20f32d99ec6a}</Project>
<Name>Microsoft.PowerToys.Settings.UI.Lib</Name>
</ProjectReference>
</ItemGroup>
<PropertyGroup Condition=" '$(VisualStudioVersion)' == '' or '$(VisualStudioVersion)' &lt; '14.0' ">
<VisualStudioVersion>14.0</VisualStudioVersion>

View File

@ -1,5 +1,5 @@
using System;
using System.IO;
using Microsoft.PowerToys.Settings.UI.Helpers;
namespace Microsoft.PowerToys.Settings.UI.ViewModels

View File

@ -1,13 +0,0 @@
using System;
using Microsoft.PowerToys.Settings.UI.Helpers;
namespace Microsoft.PowerToys.Settings.UI.ViewModels
{
public class MainViewModel : Observable
{
public MainViewModel()
{
}
}
}

View File

@ -1,24 +1,26 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using System.Windows.Input;
using Microsoft.PowerToys.Settings.UI.Helpers;
using Microsoft.PowerToys.Settings.UI.Services;
using Windows.System;
using Windows.UI.Xaml.Controls;
using Windows.UI.Xaml.Input;
using Windows.UI.Xaml.Navigation;
using WinUI = Microsoft.UI.Xaml.Controls;
// <copyright file="ShellViewModel.cs" company="Microsoft Corp">
// Copyright (c) Microsoft Corp. All rights reserved.
// </copyright>
namespace Microsoft.PowerToys.Settings.UI.ViewModels
{
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using System.Windows.Input;
using Microsoft.PowerToys.Settings.UI.Helpers;
using Microsoft.PowerToys.Settings.UI.Services;
using Windows.System;
using Windows.UI.Xaml.Controls;
using Windows.UI.Xaml.Input;
using Windows.UI.Xaml.Navigation;
using WinUI = Microsoft.UI.Xaml.Controls;
public class ShellViewModel : Observable
{
private readonly KeyboardAccelerator _altLeftKeyboardAccelerator = BuildKeyboardAccelerator(VirtualKey.Left, VirtualKeyModifiers.Menu);
private readonly KeyboardAccelerator _backKeyboardAccelerator = BuildKeyboardAccelerator(VirtualKey.GoBack);
private bool _isBackEnabled;

View File

@ -1,13 +0,0 @@
using System;
using Microsoft.PowerToys.Settings.UI.Helpers;
namespace Microsoft.PowerToys.Settings.UI.ViewModels
{
public class Test1ViewModel : Observable
{
public Test1ViewModel()
{
}
}
}

View File

@ -1,13 +0,0 @@
using System;
using Microsoft.PowerToys.Settings.UI.Helpers;
namespace Microsoft.PowerToys.Settings.UI.ViewModels
{
public class Test2ViewModel : Observable
{
public Test2ViewModel()
{
}
}
}

View File

@ -1,13 +0,0 @@
using System;
using Microsoft.PowerToys.Settings.UI.Helpers;
namespace Microsoft.PowerToys.Settings.UI.ViewModels
{
public class Test3ViewModel : Observable
{
public Test3ViewModel()
{
}
}
}

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();
}
}
}

18
src/core/Test/Program.cs Normal file
View File

@ -0,0 +1,18 @@
using Microsoft.PowerToys.Settings.UI.Lib;
using Microsoft.PowerToys.Settings.UI.ViewModels;
using System;
using System.IO;
using System.Text.Json;
namespace Test
{
class Program
{
static void Main(string[] args)
{
GeneralSettings settings = SettingsUtils.GetSettings<GeneralSettings>(string.Empty);
OutGoingGeneralSettings outSettings = new OutGoingGeneralSettings(settings);
Console.WriteLine(outSettings.ToString());
}
}
}

12
src/core/Test/Test.csproj Normal file
View File

@ -0,0 +1,12 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>netcoreapp3.1</TargetFramework>
</PropertyGroup>
<ItemGroup>
<ProjectReference Include="..\Microsoft.PowerToys.Settings.UI.Lib\Microsoft.PowerToys.Settings.UI.Lib.csproj" />
</ItemGroup>
</Project>

View File

@ -9,14 +9,13 @@
<AssemblyCopyright>Copyright (C) 2019 Microsoft Corp.</AssemblyCopyright>
</PropertyGroup>
<ItemGroup>
<AssemblyVersionFiles Include="Generated Files\AssemblyInfo.cs"/>
<AssemblyVersionFiles Include="Generated Files\AssemblyInfo.cs" />
</ItemGroup>
<Target Name="GenerateAssemblyInfo" BeforeTargets="PrepareForBuild">
<ItemGroup>
<HeaderLines Include="// Copyright (c) Microsoft Corporation" />
<HeaderLines Include="// The Microsoft Corporation licenses this file to you under the MIT license." />
<HeaderLines Include="// See the LICENSE file in the project root for more information." />
<HeaderLines Include="#pragma warning disable SA1516" />
<HeaderLines Include="using System.Reflection%3b" />
<HeaderLines Include="using System.Runtime.InteropServices%3b" />
@ -34,15 +33,8 @@
<HeaderLines Include="[assembly: AssemblyVersion(&quot;$(Version).0&quot;)]" />
<HeaderLines Include="[assembly: AssemblyFileVersion(&quot;$(Version).0&quot;)]" />
</ItemGroup>
<WriteLinesToFile
File="Generated Files\AssemblyInfo.cs"
Lines="@(HeaderLines)"
Overwrite="true"
Encoding="Unicode"
WriteOnlyWhenDifferent="true" />
<WriteLinesToFile File="Generated Files\AssemblyInfo.cs" Lines="@(HeaderLines)" Overwrite="true" Encoding="Unicode" WriteOnlyWhenDifferent="true" />
</Target>
<PropertyGroup>
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>

View File

@ -52,6 +52,9 @@
<AdditionalFiles Include="..\..\..\codeAnalysis\StyleCop.json">
<Link>StyleCop.json</Link>
</AdditionalFiles>
<None Include="..\..\..\..\.editorconfig">
<Link>.editorconfig</Link>
</None>
<None Include="App.config">
<SubType>Designer</SubType>
</None>

View File

@ -9,14 +9,13 @@
<AssemblyCopyright>Copyright (C) 2019 Microsoft Corp.</AssemblyCopyright>
</PropertyGroup>
<ItemGroup>
<AssemblyVersionFiles Include="Generated Files\AssemblyInfo.cs"/>
<AssemblyVersionFiles Include="Generated Files\AssemblyInfo.cs" />
</ItemGroup>
<Target Name="GenerateAssemblyInfo" BeforeTargets="PrepareForBuild">
<ItemGroup>
<HeaderLines Include="// Copyright (c) Microsoft Corporation" />
<HeaderLines Include="// The Microsoft Corporation licenses this file to you under the MIT license." />
<HeaderLines Include="// See the LICENSE file in the project root for more information." />
<HeaderLines Include="#pragma warning disable SA1516" />
<HeaderLines Include="using System.Reflection%3b" />
<HeaderLines Include="using System.Resources%3b" />
@ -36,13 +35,7 @@
<HeaderLines Include="[assembly: AssemblyVersion(&quot;$(Version).0&quot;)]" />
<HeaderLines Include="[assembly: AssemblyFileVersion(&quot;$(Version).0&quot;)]" />
</ItemGroup>
<WriteLinesToFile
File="Generated Files\AssemblyInfo.cs"
Lines="@(HeaderLines)"
Overwrite="true"
Encoding="Unicode"
WriteOnlyWhenDifferent="true" />
<WriteLinesToFile File="Generated Files\AssemblyInfo.cs" Lines="@(HeaderLines)" Overwrite="true" Encoding="Unicode" WriteOnlyWhenDifferent="true" />
</Target>
<PropertyGroup>
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>

View File

@ -16,7 +16,21 @@
<TargetFrameworkProfile />
<NuGetPackageImportStamp>
</NuGetPackageImportStamp>
<IntermediateOutputPath>$(SolutionDir)$(Platform)\$(Configuration)\obj\$(AssemblyName)\</IntermediateOutputPath>
<PublishUrl>publish\</PublishUrl>
<Install>true</Install>
<InstallFrom>Disk</InstallFrom>
<UpdateEnabled>false</UpdateEnabled>
<UpdateMode>Foreground</UpdateMode>
<UpdateInterval>7</UpdateInterval>
<UpdateIntervalUnits>Days</UpdateIntervalUnits>
<UpdatePeriodically>false</UpdatePeriodically>
<UpdateRequired>false</UpdateRequired>
<MapFileExtensions>true</MapFileExtensions>
<ApplicationRevision>0</ApplicationRevision>
<ApplicationVersion>1.0.0.%2a</ApplicationVersion>
<IsWebBootstrapper>false</IsWebBootstrapper>
<UseApplicationTrust>false</UseApplicationTrust>
<BootstrapperEnabled>true</BootstrapperEnabled>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|x64' ">
<PlatformTarget>x64</PlatformTarget>