Fix built in plugins and some UI issues

This commit is contained in:
Stone_Red
2023-11-23 17:28:57 +01:00
parent 247c374e99
commit 5c9613276a
12 changed files with 125 additions and 230 deletions
+7 -1
View File
@@ -11,7 +11,13 @@ namespace DesktopMagic.Api;
/// </summary>
public abstract class Plugin
{
private IPluginData application = null;
[Setting("horizontalAlignment", "Horizontal Alignment", -999)]
internal ComboBox horizontalAlignment = new ComboBox("Center", "Left", "Right");
[Setting("verticalAlignment", "Vertical Alignment", -998)]
internal ComboBox verticalAlignment = new ComboBox("Center", "Top", "Bottom");
private IPluginData application = null!;
/// <summary>
/// Informations about the main application.
+5 -10
View File
@@ -1,5 +1,4 @@
using System.Collections.ObjectModel;
using System.Text.Json;
namespace DesktopMagic.Api.Settings;
@@ -8,7 +7,7 @@ namespace DesktopMagic.Api.Settings;
/// </summary>
public class ComboBox : Setting
{
private string _value;
private string _value = string.Empty;
/// <summary>
/// Gets the collection used to generate the content of the <see cref="ComboBox"/>.
@@ -38,6 +37,8 @@ public class ComboBox : Setting
/// <param name="items"></param>
public ComboBox(params string[] items)
{
Value = items[0];
foreach (string item in items)
{
Items.Add(item);
@@ -46,7 +47,7 @@ public class ComboBox : Setting
internal override string GetJsonValue()
{
return JsonSerializer.Serialize(new { Value, Items });
return Value;
}
internal override void SetJsonValue(string value)
@@ -56,12 +57,6 @@ public class ComboBox : Setting
return;
}
JsonElement json = JsonSerializer.Deserialize<JsonElement>(value);
Items.Clear();
foreach (JsonElement item in json.GetProperty(nameof(Items)).EnumerateArray())
{
Items.Add(item.GetString() ?? string.Empty);
}
Value = json.GetProperty(nameof(Value)).GetString() ?? string.Empty;
Value = value;
}
}
@@ -5,13 +5,13 @@ namespace DesktopMagic.Api.Settings;
/// <summary>
/// Marks a Property as element.
/// </summary>
[AttributeUsage(AttributeTargets.Field)]
[AttributeUsage(AttributeTargets.Field | AttributeTargets.Property)]
public class SettingAttribute : Attribute
{
/// <summary>
/// The name of the element.
/// </summary>
public string Name { get; set; }
public string Name { get; set; } = string.Empty;
/// <summary>
/// The order index of the element.