Adjusting settings to leverage base class (#5127)

* renaming / deleting file

* adding in base class

Co-authored-by: Clint Rutkas <crutkas@microsoft.com>
This commit is contained in:
Clint Rutkas
2020-07-21 14:06:39 -07:00
committed by GitHub
parent d01b93ae5f
commit 398991f3c1
30 changed files with 202 additions and 274 deletions

View File

@@ -3,16 +3,19 @@
// 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 abstract class BasePTModuleSettings
{
// Gets or sets name of the powertoy module.
public string name { get; set; }
[JsonPropertyName("name")]
public string Name { get; set; }
// Gets or sets the powertoys version.
public string version { get; set; }
[JsonPropertyName("version")]
public string Version { get; set; }
// converts the current to a json string.
public virtual string ToJsonString()

View File

@@ -3,6 +3,7 @@
// 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
{
@@ -10,18 +11,14 @@ namespace Microsoft.PowerToys.Settings.UI.Lib
{
public const string ModuleName = "ColorPicker";
public ColorPickerProperties properties { get; set; }
[JsonPropertyName("properties")]
public ColorPickerProperties Properties { get; set; }
public ColorPickerSettings()
{
properties = new ColorPickerProperties();
version = "1";
name = ModuleName;
}
public override string ToJsonString()
{
return JsonSerializer.Serialize(this);
Properties = new ColorPickerProperties();
Version = "1";
Name = ModuleName;
}
public virtual void Save()

View File

@@ -23,7 +23,7 @@ namespace Microsoft.PowerToys.Settings.UI.Lib
this.FancyzonesShowOnAllMonitors = new BoolProperty();
this.FancyzonesZoneHighlightColor = new StringProperty(ConfigDefaults.DefaultFancyZonesZoneHighlightColor);
this.FancyzonesHighlightOpacity = new IntProperty(50);
this.FancyzonesEditorHotkey = new KeyBoardKeysProperty(
this.FancyzonesEditorHotkey = new KeyboardKeysProperty(
new HotkeySettings()
{
Win = true,
@@ -82,7 +82,7 @@ namespace Microsoft.PowerToys.Settings.UI.Lib
public IntProperty FancyzonesHighlightOpacity { get; set; }
[JsonPropertyName("fancyzones_editor_hotkey")]
public KeyBoardKeysProperty FancyzonesEditorHotkey { get; set; }
public KeyboardKeysProperty FancyzonesEditorHotkey { get; set; }
[JsonPropertyName("fancyzones_excluded_apps")]
public StringProperty FancyzonesExcludedApps { get; set; }

View File

@@ -2,35 +2,20 @@
// 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;
using System.Collections.Generic;
using System.Text;
using System.Text.Json;
using System.Text.Json.Serialization;
namespace Microsoft.PowerToys.Settings.UI.Lib
{
public class FancyZonesSettings
public class FancyZonesSettings : BasePTModuleSettings
{
public FancyZonesSettings()
{
this.Version = string.Empty;
this.Name = string.Empty;
this.Properties = new FZConfigProperties();
Version = string.Empty;
Name = string.Empty;
Properties = new FZConfigProperties();
}
[JsonPropertyName("version")]
public string Version { get; set; }
[JsonPropertyName("name")]
public string Name { get; set; }
[JsonPropertyName("properties")]
public FZConfigProperties Properties { get; set; }
public string ToJsonString()
{
return JsonSerializer.Serialize(this);
}
}
}

View File

@@ -1,19 +0,0 @@
// 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;
using System.Collections.Generic;
using System.Text;
namespace Microsoft.PowerToys.Settings.UI.Lib
{
public interface IPowerToySettings
{
string name { get; set; }
string version { get; set; }
string ToJsonString();
}
}

View File

@@ -22,7 +22,7 @@ namespace Microsoft.PowerToys.Settings.UI.Lib
ImageresizerTiffCompressOption = new IntProperty();
ImageresizerFileName = new StringProperty("%1 (%2)");
ImageresizerSizes = new ImageresizerSizes(new ObservableCollection<ImageSize>()
ImageresizerSizes = new ImageResizerSizes(new ObservableCollection<ImageSize>()
{
new ImageSize(0, "Small", ResizeFit.Fit, 854, 480, ResizeUnit.Pixel),
new ImageSize(1, "Medium", ResizeFit.Fit, 1366, 768, ResizeUnit.Pixel),
@@ -32,7 +32,7 @@ namespace Microsoft.PowerToys.Settings.UI.Lib
ImageresizerKeepDateModified = new BoolProperty();
ImageresizerFallbackEncoder = new StringProperty(new System.Guid("19e4a5aa-5662-4fc5-a0c0-1758028e1057").ToString());
ImageresizerCustomSize = new ImageresizerCustomSizeProperty(new ImageSize(4, "custom", ResizeFit.Fit, 1024, 640, ResizeUnit.Pixel));
ImageresizerCustomSize = new ImageResizerCustomSizeProperty(new ImageSize(4, "custom", ResizeFit.Fit, 1024, 640, ResizeUnit.Pixel));
}
[JsonPropertyName("imageresizer_selectedSizeIndex")]
@@ -60,7 +60,7 @@ namespace Microsoft.PowerToys.Settings.UI.Lib
public StringProperty ImageresizerFileName { get; set; }
[JsonPropertyName("imageresizer_sizes")]
public ImageresizerSizes ImageresizerSizes { get; set; }
public ImageResizerSizes ImageresizerSizes { get; set; }
[JsonPropertyName("imageresizer_keepDateModified")]
public BoolProperty ImageresizerKeepDateModified { get; set; }
@@ -69,7 +69,7 @@ namespace Microsoft.PowerToys.Settings.UI.Lib
public StringProperty ImageresizerFallbackEncoder { get; set; }
[JsonPropertyName("imageresizer_customSize")]
public ImageresizerCustomSizeProperty ImageresizerCustomSize { get; set; }
public ImageResizerCustomSizeProperty ImageresizerCustomSize { get; set; }
public string ToJsonString()
{

View File

@@ -2,33 +2,26 @@
// 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;
using System.Collections.Generic;
using System.Text;
using System.Text.Json;
using System.Text.Json.Serialization;
namespace Microsoft.PowerToys.Settings.UI.Lib
{
public class ImageResizerSettings
public class ImageResizerSettings : BasePTModuleSettings
{
[JsonPropertyName("version")]
public string Version { get; set; }
[JsonPropertyName("name")]
public string Name { get; set; }
public const string ModuleName = "Image Resizer";
[JsonPropertyName("properties")]
public ImageResizerProperties Properties { get; set; }
public ImageResizerSettings()
{
this.Version = "1";
this.Name = "Image Resizer";
this.Properties = new ImageResizerProperties();
Version = "1";
Name = ModuleName;
Properties = new ImageResizerProperties();
}
public string ToJsonString()
public override string ToJsonString()
{
var options = new JsonSerializerOptions
{

View File

@@ -0,0 +1,19 @@
// 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.Serialization;
namespace Microsoft.PowerToys.Settings.UI.Lib
{
public class ImagerResizerKeepDateModified
{
[JsonPropertyName("value")]
public bool Value { get; set; }
public ImagerResizerKeepDateModified()
{
Value = false;
}
}
}

View File

@@ -1,22 +1,22 @@
using System;
using System.Collections.Generic;
using System.Text;
// 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.Serialization;
namespace Microsoft.PowerToys.Settings.UI.Lib
{
public class ImageresizerCustomSizeProperty
public class ImageResizerCustomSizeProperty
{
[JsonPropertyName("value")]
public ImageSize Value { get; set; }
public ImageresizerCustomSizeProperty()
public ImageResizerCustomSizeProperty()
{
this.Value = new ImageSize();
Value = new ImageSize();
}
public ImageresizerCustomSizeProperty(ImageSize value)
public ImageResizerCustomSizeProperty(ImageSize value)
{
Value = value;
}

View File

@@ -1,19 +1,19 @@
using System;
using System.Collections.Generic;
using System.Text;
// 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.Serialization;
namespace Microsoft.PowerToys.Settings.UI.Lib
{
public class ImageresizerFallbackEncoder
public class ImageResizerFallbackEncoder
{
[JsonPropertyName("value")]
public string Value { get; set; }
public ImageresizerFallbackEncoder()
public ImageResizerFallbackEncoder()
{
this.Value = string.Empty;
Value = string.Empty;
}
}
}

View File

@@ -1,19 +0,0 @@
using System;
using System.Collections.Generic;
using System.Text;
using System.Text.Json.Serialization;
namespace Microsoft.PowerToys.Settings.UI.Lib
{
public class ImageresizerKeepDateModified
{
[JsonPropertyName("value")]
public bool Value { get; set; }
public ImageresizerKeepDateModified()
{
this.Value = false;
}
}
}

View File

@@ -2,27 +2,23 @@
// 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;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.Text;
using System.Text.Json;
using System.Text.Json.Serialization;
namespace Microsoft.PowerToys.Settings.UI.Lib
{
public class ImageresizerSizes
public class ImageResizerSizes
{
[JsonPropertyName("value")]
public ObservableCollection<ImageSize> Value { get; set; }
public ImageresizerSizes()
public ImageResizerSizes()
{
this.Value = new ObservableCollection<ImageSize>();
Value = new ObservableCollection<ImageSize>();
}
public ImageresizerSizes(ObservableCollection<ImageSize> value)
public ImageResizerSizes(ObservableCollection<ImageSize> value)
{
Value = value;
}

View File

@@ -2,23 +2,20 @@
// 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;
using System.Collections.Generic;
using System.Text;
using System.Text.Json.Serialization;
namespace Microsoft.PowerToys.Settings.UI.Lib
{
public class KeyBoardKeysProperty
public class KeyboardKeysProperty
{
public KeyBoardKeysProperty()
public KeyboardKeysProperty()
{
this.Value = new HotkeySettings();
Value = new HotkeySettings();
}
public KeyBoardKeysProperty(HotkeySettings hkSettings)
public KeyboardKeysProperty(HotkeySettings hkSettings)
{
this.Value = hkSettings;
Value = hkSettings;
}
[JsonPropertyName("value")]

View File

@@ -2,10 +2,6 @@
// 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;
using System.Collections.Generic;
using System.Text;
using System.Text.Json;
using System.Text.Json.Serialization;
namespace Microsoft.PowerToys.Settings.UI.Lib
@@ -18,21 +14,15 @@ namespace Microsoft.PowerToys.Settings.UI.Lib
public KeyboardManagerSettings()
{
Properties = new KeyboardManagerProperties();
version = "1";
name = "_unset_";
Version = "1";
Name = "_unset_";
}
public KeyboardManagerSettings(string ptName)
{
Properties = new KeyboardManagerProperties();
version = "1";
name = ptName;
}
// converts the current to a json string.
public override string ToJsonString()
{
return JsonSerializer.Serialize(this);
Version = "1";
Name = ptName;
}
}
}

View File

@@ -3,20 +3,22 @@
// 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 PowerLauncherSettings : BasePTModuleSettings
{
public const string POWERTOYNAME = "PowerToys Run";
public const string ModuleName = "PowerToys Run";
public PowerLauncherProperties properties { get; set; }
[JsonPropertyName("properties")]
public PowerLauncherProperties Properties { get; set; }
public PowerLauncherSettings()
{
properties = new PowerLauncherProperties();
version = "1";
name = POWERTOYNAME;
Properties = new PowerLauncherProperties();
Version = "1";
Name = ModuleName;
}
public virtual void Save()
@@ -27,7 +29,7 @@ namespace Microsoft.PowerToys.Settings.UI.Lib
WriteIndented = true,
};
SettingsUtils.SaveSettings(JsonSerializer.Serialize(this, options), POWERTOYNAME);
SettingsUtils.SaveSettings(JsonSerializer.Serialize(this, options), ModuleName);
}
}
}

View File

@@ -17,15 +17,15 @@ namespace Microsoft.PowerToys.Settings.UI.Lib
public PowerPreviewSettings()
{
properties = new PowerPreviewProperties();
version = "1";
name = "File Explorer";
Version = "1";
Name = "File Explorer";
}
public PowerPreviewSettings(string ptName)
{
properties = new PowerPreviewProperties();
version = "1";
name = ptName;
Version = "1";
Name = ptName;
}
public override string ToJsonString()

View File

@@ -2,45 +2,42 @@
// 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 PowerRenameSettings : BasePTModuleSettings
{
public PowerRenameProperties properties { get; set; }
public const string ModuleName = "PowerRename";
[JsonPropertyName("properties")]
public PowerRenameProperties Properties { get; set; }
public PowerRenameSettings()
{
properties = new PowerRenameProperties();
version = "1";
name = "PowerRename";
Properties = new PowerRenameProperties();
Version = "1";
Name = ModuleName;
}
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;
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";
Version = "1";
Name = ModuleName;
}
public PowerRenameSettings(string ptName)
{
properties = new PowerRenameProperties();
version = "1";
name = ptName;
}
public override string ToJsonString()
{
return JsonSerializer.Serialize(this);
Properties = new PowerRenameProperties();
Version = "1";
Name = ptName;
}
}
}

View File

@@ -2,35 +2,22 @@
// 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;
using System.Collections.Generic;
using System.Text;
using System.Text.Json;
using System.Text.Json.Serialization;
namespace Microsoft.PowerToys.Settings.UI.Lib
{
public class ShortcutGuideSettings
public class ShortcutGuideSettings : BasePTModuleSettings
{
public ShortcutGuideSettings()
{
Name = "Shortcut Guide";
Properties = new ShortcutGuideProperties();
Version = "1.0";
}
[JsonPropertyName("name")]
public string Name { get; set; }
public const string ModuleName = "Shortcut Guide";
[JsonPropertyName("properties")]
public ShortcutGuideProperties Properties { get; set; }
[JsonPropertyName("version")]
public string Version { get; set; }
public string ToJsonString()
public ShortcutGuideSettings()
{
return JsonSerializer.Serialize(this);
Name = ModuleName;
Properties = new ShortcutGuideProperties();
Version = "1.0";
}
}
}