User/lamotile/add powerrename settings (#1813)

* added powerrename settings

* removed pop-up message

* removed unused files

* revrted changes to old settings

* updated solution file

* added ToJsonString() method

* added JSON property for the powertoy name
This commit is contained in:
Lavius Motileng
2020-04-02 06:08:56 -07:00
parent 3015ffd950
commit 89b44f5126
16 changed files with 346 additions and 125 deletions

View File

@@ -0,0 +1,18 @@
using System;
using System.Collections.Generic;
using System.Text;
using System.Text.Json;
namespace Microsoft.PowerToys.Settings.UI.Lib
{
public abstract class BasePTModuleSettings
{
public string name { get; set; }
public string version { get; set; }
public virtual string ToJsonString()
{
return JsonSerializer.Serialize(this);
}
}
}

View File

@@ -6,7 +6,7 @@ using System.Threading.Tasks;
using System.Text.Json;
using System.Text.Json.Serialization;
namespace Microsoft.PowerToys.Settings.UI.ViewModels
namespace Microsoft.PowerToys.Settings.UI.Lib
{
public class GeneralSettings
{
@@ -30,7 +30,7 @@ namespace Microsoft.PowerToys.Settings.UI.ViewModels
this.powertoys_version = "v0.15.3";
}
public override string ToString()
public string ToJsonString()
{
return JsonSerializer.Serialize(this);
}

View File

@@ -0,0 +1,13 @@
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

@@ -2,70 +2,62 @@
using System.Collections.Generic;
using System.Text;
using System.Text.Json;
using System.Text.Json.Serialization;
namespace Microsoft.PowerToys.Settings.UI.Lib
{
/// <summary>
/// This class models the settings for the PowerPreview class.
/// Eaxmple JSON:
/// {
/// "name": "File Explorer Preview",
/// "properties": {
/// "IDS_PREVPANE_SVG_BOOL_TOGGLE_CONTROLL": { "value": true },
/// "PREVPANE_MD_BOOL_TOGGLE_CONTROLL_ID": { "value": true }
/// },
/// "version": "1.0"
/// }
/// </summary>
public class PowerPreviewSettings
public class PowerPreviewSettings : BasePTModuleSettings
{
public string name { get; set; }
public Properties properties { get; set; }
public string version { get; set; }
public PowerPreviewProperties properties { get; set; }
public PowerPreviewSettings()
{
this.properties = new Properties();
this.properties = new PowerPreviewProperties();
this.version = "1";
this.name = "_unset_";
}
public PowerPreviewSettings(string ptName)
{
this.properties = new Properties();
this.properties = new PowerPreviewProperties();
this.version = "1";
this.name = ptName;
}
public override string ToString()
public override string ToJsonString()
{
return "{\"" + this.name + "\":" + JsonSerializer.Serialize(this) + "}";
return JsonSerializer.Serialize(this);
}
}
public class Property
public class PowerPreviewProperties
{
public bool value { get; set; }
public BoolProperty IDS_PREVPANE_SVG_BOOL_TOGGLE_CONTROLL { get; set; }
public BoolProperty PREVPANE_MD_BOOL_TOGGLE_CONTROLL_ID { get; set; }
public PowerPreviewProperties()
{
this.IDS_PREVPANE_SVG_BOOL_TOGGLE_CONTROLL = new BoolProperty();
this.PREVPANE_MD_BOOL_TOGGLE_CONTROLL_ID = new BoolProperty();
}
public override string ToString()
{
return JsonSerializer.Serialize(this);
}
}
public class Properties
public class SndPowerPreviewSettings
{
public Property IDS_PREVPANE_SVG_BOOL_TOGGLE_CONTROLL { get; set; }
public Property PREVPANE_MD_BOOL_TOGGLE_CONTROLL_ID { get; set; }
[JsonPropertyName("File Explorer Preview")]
public PowerPreviewSettings File_Explorer_Preview { get; set; }
public Properties()
public SndPowerPreviewSettings(PowerPreviewSettings settings)
{
this.IDS_PREVPANE_SVG_BOOL_TOGGLE_CONTROLL = new Property();
this.PREVPANE_MD_BOOL_TOGGLE_CONTROLL_ID = new Property();
this.File_Explorer_Preview = settings;
}
public override string ToString()
public string ToJsonString()
{
return JsonSerializer.Serialize(this);
}

View File

@@ -0,0 +1,67 @@
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 PowerRenameSettings : BasePTModuleSettings
{
public PowerRenameProperties properties { get; set; }
public PowerRenameSettings()
{
this.properties = new PowerRenameProperties();
this.version = "1";
this.name = "_unset_";
}
public PowerRenameSettings(string ptName)
{
this.properties = new PowerRenameProperties();
this.version = "1";
this.name = ptName;
}
public override string ToJsonString()
{
return JsonSerializer.Serialize(this);
}
}
public class PowerRenameProperties
{
public PowerRenameProperties()
{
this.bool_persist_input = new BoolProperty();
this.bool_mru_enabled = new BoolProperty();
this.int_max_mru_size = new IntProperty();
this.bool_show_icon_on_menu = new BoolProperty();
this.bool_show_extended_menu = new BoolProperty();
}
public BoolProperty bool_persist_input { get; set; }
public BoolProperty bool_mru_enabled { get; set; }
public IntProperty int_max_mru_size { get; set; }
public BoolProperty bool_show_icon_on_menu { get; set; }
public BoolProperty bool_show_extended_menu { get; set; }
}
public class SndPowerRenameSettings
{
[JsonPropertyName("PowerRename")]
public PowerRenameSettings PowerRename { get; set; }
public SndPowerRenameSettings(PowerRenameSettings settings)
{
this.PowerRename = settings;
}
public string ToJsonString()
{
return JsonSerializer.Serialize(this);
}
}
}

View File

@@ -0,0 +1,27 @@
using System;
using System.Collections.Generic;
using System.Text;
using System.Text.Json;
namespace Microsoft.PowerToys.Settings.UI.Lib
{
public class BoolProperty
{
public bool value { get; set; }
public override string ToString()
{
return JsonSerializer.Serialize(this);
}
}
public class IntProperty
{
public int value { get; set; }
public override string ToString()
{
return JsonSerializer.Serialize(this);
}
}
}

View File

@@ -39,13 +39,13 @@ namespace Microsoft.PowerToys.Settings.UI.Lib
/// Save settings to a json file.
/// </summary>
/// <param name="settings">dynamic json settings object.</param>
public static void SaveSettings<T>(T settings, string powertoy)
public static void SaveSettings(string jsonSettings, string powertoy)
{
if(settings != null)
if(jsonSettings != null)
{
System.IO.File.WriteAllText(
SettingsUtils.GetSettingsPath(powertoy),
settings.ToString());
jsonSettings.ToString());
}
}
}

View File

@@ -5,24 +5,18 @@ using System.Text.Json;
namespace Microsoft.PowerToys.Settings.UI.Lib
{
/// <summary>
/// PowerToys runner expects a json text that contains one of the following attributes: refresh, general and powertoys.
/// The one for general settings is placed in the General settings model. This class represents the json text that starts with the "powertoys" attribute.
/// this will tell the runner that we are sending settings for a powertoy module and not for general settings.
/// </summary>
/// <typeparam name="M">M stands for the Model of PT Module Settings to be sent.</typeparam>
public class SndModuleSettings<M>
public class SndModuleSettings<S>
{
public M powertoys { get; set; }
public S powertoys { get; set; }
public SndModuleSettings(M ptModuleSettings)
public SndModuleSettings(S settings)
{
this.powertoys = ptModuleSettings;
this.powertoys = settings;
}
public override string ToString()
public string ToJsonString()
{
return "{\"powertoys\":" + this.powertoys.ToString() + "}";
return JsonSerializer.Serialize(this);
}
}
}