Skip to content

Commit

Permalink
Added Tests and Refactored code (#2129)
Browse files Browse the repository at this point in the history
* Added Tests and Refactored code

* removed un-used file

* delete test files when test completes

* removed extra build configs

* added clean-up method

* removed unused variable

* re-added removed attributtion

* added error handling and move strings to string resource

* added error handling to file explorer view model

* moved varible assignment to if statement block

* removed savin of settings file from the UI

* re-added open source notice

* added missing controls for powerrename and fancy zones

* removed dead coded

* remove un-used configuration

* added error handling for file saving and updated powerreanme constructor

* removed added configurations

* added settings state
  • Loading branch information
Lavius Motileng committed Apr 17, 2020
1 parent 7e1f554 commit 3fc738b
Show file tree
Hide file tree
Showing 37 changed files with 1,537 additions and 503 deletions.
20 changes: 11 additions & 9 deletions PowerToys.sln
Original file line number Diff line number Diff line change
Expand Up @@ -188,8 +188,6 @@ Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "powerpreviewTest", "src\mod
EndProject
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "core", "core", "{C3081D9A-1586-441A-B5F4-ED815B3719C1}"
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Microsoft.PowerToys.Settings.Test", "src\core\Microsoft.PowerToys.Settings.Test\Microsoft.PowerToys.Settings.Test.csproj", "{6F2B5799-36AE-4D10-9DCF-B19CD26A5DBC}"
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Microsoft.PowerToys.Settings.UI.Runner", "src\core\Microsoft.PowerToys.Settings.UI.Runner\Microsoft.PowerToys.Settings.UI.Runner.csproj", "{E4E0D2AE-B17D-4BD4-8BEE-AFC8CC464C5F}"
ProjectSection(ProjectDependencies) = postProject
{F88B6FD1-14BD-48DB-85C2-6C51B8045121} = {F88B6FD1-14BD-48DB-85C2-6C51B8045121}
Expand All @@ -209,6 +207,8 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Solution Items", "Solution
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Microsoft.PowerToys.Settings.UI.Lib", "src\core\Microsoft.PowerToys.Settings.UI.Lib\Microsoft.PowerToys.Settings.UI.Lib.csproj", "{B1BCC8C6-46B5-4BFA-8F22-20F32D99EC6A}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Microsoft.PowerToys.Settings.UnitTest", "src\core\Microsoft.PowerToys.Settings.UnitTest\Microsoft.PowerToys.Settings.UnitTest.csproj", "{A80355C2-780D-4245-BD80-25B8DE698EE3}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|x64 = Debug|x64
Expand Down Expand Up @@ -367,10 +367,6 @@ Global
{47310AB4-9034-4BD1-8D8B-E88AD21A171B}.Debug|x64.Build.0 = Debug|x64
{47310AB4-9034-4BD1-8D8B-E88AD21A171B}.Release|x64.ActiveCfg = Release|x64
{47310AB4-9034-4BD1-8D8B-E88AD21A171B}.Release|x64.Build.0 = Release|x64
{6F2B5799-36AE-4D10-9DCF-B19CD26A5DBC}.Debug|x64.ActiveCfg = Debug|x64
{6F2B5799-36AE-4D10-9DCF-B19CD26A5DBC}.Debug|x64.Build.0 = Debug|x64
{6F2B5799-36AE-4D10-9DCF-B19CD26A5DBC}.Release|x64.ActiveCfg = Release|x64
{6F2B5799-36AE-4D10-9DCF-B19CD26A5DBC}.Release|x64.Build.0 = Release|x64
{E4E0D2AE-B17D-4BD4-8BEE-AFC8CC464C5F}.Debug|x64.ActiveCfg = Debug|x64
{E4E0D2AE-B17D-4BD4-8BEE-AFC8CC464C5F}.Debug|x64.Build.0 = Debug|x64
{E4E0D2AE-B17D-4BD4-8BEE-AFC8CC464C5F}.Release|x64.ActiveCfg = Release|x64
Expand All @@ -389,8 +385,14 @@ Global
{C073B057-B157-40F0-8678-1DCD119D841C}.Release|x64.ActiveCfg = Release|x64
{B1BCC8C6-46B5-4BFA-8F22-20F32D99EC6A}.Debug|x64.ActiveCfg = Debug|x64
{B1BCC8C6-46B5-4BFA-8F22-20F32D99EC6A}.Debug|x64.Build.0 = Debug|x64
{B1BCC8C6-46B5-4BFA-8F22-20F32D99EC6A}.Release|x64.ActiveCfg = Release|Any CPU
{B1BCC8C6-46B5-4BFA-8F22-20F32D99EC6A}.Release|x64.Build.0 = Release|Any CPU
{B1BCC8C6-46B5-4BFA-8F22-20F32D99EC6A}.Release|x64.ActiveCfg = Release|x64
{B1BCC8C6-46B5-4BFA-8F22-20F32D99EC6A}.Release|x64.Build.0 = Release|x64
{A80355C2-780D-4245-BD80-25B8DE698EE3}.Debug|x64.ActiveCfg = Debug|x64
{A80355C2-780D-4245-BD80-25B8DE698EE3}.Debug|x64.Build.0 = Debug|x64
{A80355C2-780D-4245-BD80-25B8DE698EE3}.Debug|x64.Deploy.0 = Debug|x64
{A80355C2-780D-4245-BD80-25B8DE698EE3}.Release|x64.ActiveCfg = Release|x64
{A80355C2-780D-4245-BD80-25B8DE698EE3}.Release|x64.Build.0 = Release|x64
{A80355C2-780D-4245-BD80-25B8DE698EE3}.Release|x64.Deploy.0 = Release|x64
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
Expand Down Expand Up @@ -438,12 +440,12 @@ Global
{748417CA-F17E-487F-9411-CAFB6D3F4877} = {2F305555-C296-497E-AC20-5FA1B237996A}
{217DF501-135C-4E38-BFC8-99D4821032EA} = {2F305555-C296-497E-AC20-5FA1B237996A}
{47310AB4-9034-4BD1-8D8B-E88AD21A171B} = {2F305555-C296-497E-AC20-5FA1B237996A}
{6F2B5799-36AE-4D10-9DCF-B19CD26A5DBC} = {C3081D9A-1586-441A-B5F4-ED815B3719C1}
{E4E0D2AE-B17D-4BD4-8BEE-AFC8CC464C5F} = {C3081D9A-1586-441A-B5F4-ED815B3719C1}
{F88B6FD1-14BD-48DB-85C2-6C51B8045121} = {C3081D9A-1586-441A-B5F4-ED815B3719C1}
{A7D5099E-F0FD-4BF3-8522-5A682759F915} = {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}
{A80355C2-780D-4245-BD80-25B8DE698EE3} = {C3081D9A-1586-441A-B5F4-ED815B3719C1}
EndGlobalSection
GlobalSection(ExtensibilityGlobals) = postSolution
SolutionGuid = {C3A2F9D1-7930-4EF4-A6FC-7EE0A99821D0}
Expand Down

This file was deleted.

13 changes: 0 additions & 13 deletions src/core/Microsoft.PowerToys.Settings.Test/UnitTest1.cs

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@ public FZConfigProperties()
this.FancyzonesHighlightOpacity = new IntProperty();
this.FancyzonesEditorHotkey = new KeyBoardKeysProperty();
this.FancyzonesExcludedApps = new StringProperty();
this.FancyzonesInActiveColor = new StringProperty();
this.FancyzonesBorderColor = new StringProperty();
}

[JsonPropertyName("fancyzones_shiftDrag")]
Expand Down Expand Up @@ -62,5 +64,11 @@ public FZConfigProperties()

[JsonPropertyName("fancyzones_excluded_apps")]
public StringProperty FancyzonesExcludedApps { get; set; }

[JsonPropertyName("fancyzones_zoneBorderColor")]
public StringProperty FancyzonesBorderColor { get; set; }

[JsonPropertyName("fancyzones_zoneColor")]
public StringProperty FancyzonesInActiveColor { get; set; }
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
// Copyright (c) Microsoft Corporation
// The Microsoft Corporation licenses this file to you under the MIT license.
// See the LICENSE file in the project root for more information.

using System.Text.Json;
using System.Text.Json.Serialization;

namespace Microsoft.PowerToys.Settings.UI.Lib
{

public class PowerRenameLocalProperties
{
public PowerRenameLocalProperties()
{
PersistState = false;
MRUEnabled = false;
MaxMRUSize = 0;
ShowIcon = false;
ExtendedContextMenuOnly = false;
}

private int _maxSize;

public bool PersistState { get; set; }

public bool MRUEnabled { get; set; }

public int MaxMRUSize
{
get
{
return _maxSize;
}

set
{
if (value < 0)
{
_maxSize = 0;
}
}
}

public bool ShowIcon { get; set; }

public bool ExtendedContextMenuOnly { get; set; }

public string ToJsonString()
{
return JsonSerializer.Serialize(this);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -10,26 +10,26 @@ public class PowerRenameProperties
{
public PowerRenameProperties()
{
PersistInput = new BoolProperty();
MruEnabled = new BoolProperty();
MaxMruSize = new IntProperty();
ShowIconInMenu = new BoolProperty();
ShowExtendedMenu = new BoolProperty();
PersistState = new BoolProperty();
MRUEnabled = new BoolProperty();
MaxMRUSize = new IntProperty();
ShowIcon = new BoolProperty();
ExtendedContextMenuOnly = new BoolProperty();
}

[JsonPropertyName("bool_persist_input")]
public BoolProperty PersistInput { get; set; }
public BoolProperty PersistState { get; set; }

[JsonPropertyName("bool_mru_enabled")]
public BoolProperty MruEnabled { get; set; }
public BoolProperty MRUEnabled { get; set; }

[JsonPropertyName("int_max_mru_size")]
public IntProperty MaxMruSize { get; set; }
public IntProperty MaxMRUSize { get; set; }

[JsonPropertyName("bool_show_icon_on_menu")]
public BoolProperty ShowIconInMenu { get; set; }
public BoolProperty ShowIcon { get; set; }

[JsonPropertyName("bool_show_extended_menu")]
public BoolProperty ShowExtendedMenu { get; set; }
public BoolProperty ExtendedContextMenuOnly { get; set; }
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,20 @@ public PowerRenameSettings()
{
properties = new PowerRenameProperties();
version = "1";
name = "_unset_";
name = "PowerRename";
}

public PowerRenameSettings(PowerRenameLocalProperties localProperties)
{
properties = new PowerRenameProperties();
properties.PersistState.Value = localProperties.PersistState;
properties.MRUEnabled.Value = localProperties.MRUEnabled;
properties.MaxMRUSize.Value = localProperties.MaxMRUSize;
properties.ShowIcon.Value = localProperties.ShowIcon;
properties.ExtendedContextMenuOnly.Value = localProperties.ExtendedContextMenuOnly;

version = "1";
name = "PowerRename";
}

public PowerRenameSettings(string ptName)
Expand Down
36 changes: 22 additions & 14 deletions src/core/Microsoft.PowerToys.Settings.UI.Lib/SettingsUtils.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@ namespace Microsoft.PowerToys.Settings.UI.Lib
{
public static class SettingsUtils
{
private const string DefaultFileName = "settings.json";

public static bool SettingsFolderExists(string powertoy)
{
return Directory.Exists(Path.Combine(LocalApplicationDataFolder(), $"Microsoft\\PowerToys\\{powertoy}"));
Expand All @@ -24,50 +26,56 @@ public static void CreateSettingsFolder(string powertoy)
/// Get path to the json settings file.
/// </summary>
/// <returns>string path.</returns>
public static string GetSettingsPath(string powertoy)
public static string GetSettingsPath(string powertoy, string fileName = DefaultFileName)
{
if (string.IsNullOrWhiteSpace(powertoy))
{
return Path.Combine(
LocalApplicationDataFolder(),
$"Microsoft\\PowerToys\\settings.json");
$"Microsoft\\PowerToys\\{fileName}");
}

return Path.Combine(
LocalApplicationDataFolder(),
$"Microsoft\\PowerToys\\{powertoy}\\settings.json");
$"Microsoft\\PowerToys\\{powertoy}\\{fileName}");
}

public static bool SettingsExists(string powertoy)
public static bool SettingsExists(string powertoy, string fileName = DefaultFileName)
{
return File.Exists(GetSettingsPath(powertoy));
return File.Exists(GetSettingsPath(powertoy, fileName));
}

/// <summary>
/// Get a Deserialized object of the json settings string.
/// </summary>
/// <returns>Deserialized json settings object.</returns>
public static T GetSettings<T>(string powertoy)
public static T GetSettings<T>(string powertoy, string fileName = DefaultFileName)
{
var jsonSettingsString = File.ReadAllText(GetSettingsPath(powertoy));
var jsonSettingsString = File.ReadAllText(GetSettingsPath(powertoy, fileName));
return JsonSerializer.Deserialize<T>(jsonSettingsString);
}

// Save settings to a json file.
public static void SaveSettings(string jsonSettings, string powertoy)
public static void SaveSettings(string jsonSettings, string powertoy, string fileName = DefaultFileName)
{
if (jsonSettings != null)
try
{
if (!SettingsFolderExists(powertoy))
if (jsonSettings != null)
{
CreateSettingsFolder(powertoy);
}
if (!SettingsFolderExists(powertoy))
{
CreateSettingsFolder(powertoy);
}

File.WriteAllText(GetSettingsPath(powertoy), jsonSettings);
File.WriteAllText(GetSettingsPath(powertoy, fileName), jsonSettings);
}
}
catch
{
}
}

private static string LocalApplicationDataFolder()
public static string LocalApplicationDataFolder()
{
return Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,7 @@
<Compile Include="ViewModels\ImageResizerViewModel.cs" />
<Compile Include="ViewModels\KeyboardManagerViewModel.cs" />
<Compile Include="ViewModels\Keys.cs" />
<Compile Include="ViewModels\PowerPreviewViewModel.cs" />
<Compile Include="ViewModels\PowerRenameViewModel.cs" />
<Compile Include="ViewModels\PowerLauncherViewModel.cs" />
<Compile Include="ViewModels\RemapKeysModel.cs" />
Expand Down

0 comments on commit 3fc738b

Please sign in to comment.