Skip to content

Commit

Permalink
Added functionality for General Settings Page (#1664)
Browse files Browse the repository at this point in the history
* 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
  • Loading branch information
Lavius Motileng committed Apr 7, 2020
1 parent 2a0e92e commit 4243fea
Show file tree
Hide file tree
Showing 32 changed files with 442 additions and 307 deletions.
4 changes: 4 additions & 0 deletions .editorconfig
@@ -0,0 +1,4 @@
[*.cs]

# SA1201: Elements should appear in the correct order
dotnet_diagnostic.SA1201.severity = none
15 changes: 15 additions & 0 deletions PowerToys.sln
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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}
Expand Down
47 changes: 47 additions & 0 deletions src/core/Microsoft.PowerToys.Settings.UI.Lib/GeneralSettings.cs
@@ -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);
}
}
}
@@ -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>
52 changes: 52 additions & 0 deletions src/core/Microsoft.PowerToys.Settings.UI.Lib/SettingsUtils.cs
@@ -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());
}
}
}
}
Expand Up @@ -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>
Expand Down
Expand Up @@ -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
{
Expand All @@ -23,6 +23,35 @@ private void WindowsXamlHost_ChildChanged(object sender, EventArgs e)
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)
{
}
Expand Down
Expand Up @@ -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">
Expand Down Expand Up @@ -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" />
Expand Down Expand Up @@ -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>
Expand Down
@@ -1,5 +1,5 @@
using System;

using System.IO;
using Microsoft.PowerToys.Settings.UI.Helpers;

namespace Microsoft.PowerToys.Settings.UI.ViewModels
Expand Down

This file was deleted.

@@ -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;
Expand Down

This file was deleted.

This file was deleted.

This file was deleted.

0 comments on commit 4243fea

Please sign in to comment.