Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
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
- Loading branch information
Lavius Motileng
committed
Apr 7, 2020
1 parent
2a0e92e
commit 4243fea
Showing
32 changed files
with
442 additions
and
307 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
[*.cs] | ||
|
||
# SA1201: Elements should appear in the correct order | ||
dotnet_diagnostic.SA1201.severity = none |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
47 changes: 47 additions & 0 deletions
47
src/core/Microsoft.PowerToys.Settings.UI.Lib/GeneralSettings.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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); | ||
} | ||
} | ||
} |
11 changes: 11 additions & 0 deletions
11
src/core/Microsoft.PowerToys.Settings.UI.Lib/Microsoft.PowerToys.Settings.UI.Lib.csproj
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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
52
src/core/Microsoft.PowerToys.Settings.UI.Lib/SettingsUtils.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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()); | ||
} | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2 changes: 1 addition & 1 deletion
2
src/core/Microsoft.PowerToys.Settings.UI/ViewModels/GeneralViewModel.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
13 changes: 0 additions & 13 deletions
13
src/core/Microsoft.PowerToys.Settings.UI/ViewModels/MainViewModel.cs
This file was deleted.
Oops, something went wrong.
32 changes: 17 additions & 15 deletions
32
src/core/Microsoft.PowerToys.Settings.UI/ViewModels/ShellViewModel.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
13 changes: 0 additions & 13 deletions
13
src/core/Microsoft.PowerToys.Settings.UI/ViewModels/Test1ViewModel.cs
This file was deleted.
Oops, something went wrong.
13 changes: 0 additions & 13 deletions
13
src/core/Microsoft.PowerToys.Settings.UI/ViewModels/Test2ViewModel.cs
This file was deleted.
Oops, something went wrong.
13 changes: 0 additions & 13 deletions
13
src/core/Microsoft.PowerToys.Settings.UI/ViewModels/Test3ViewModel.cs
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.