Rename Plugin & API namespaces and implement saving/loading of setting

This commit is contained in:
Stone_Red
2023-11-21 19:54:29 +01:00
parent 1f9e123893
commit e8de6fe9a5
35 changed files with 247 additions and 138 deletions
@@ -11,6 +11,7 @@
<AssemblyVersion>0.0.0.5</AssemblyVersion>
<PackageProjectUrl></PackageProjectUrl>
<FileVersion>0.0.0.5</FileVersion>
<Nullable>enable</Nullable>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|AnyCPU'">
@@ -2,7 +2,7 @@
using System.Diagnostics.CodeAnalysis;
using System.Drawing;
namespace DesktopMagicPluginAPI.Drawing;
namespace DesktopMagic.Api.Drawing;
internal class FontComparer : IEqualityComparer<Font>
{
@@ -2,7 +2,7 @@
using System.Collections.Generic;
using System.Drawing;
namespace DesktopMagicPluginAPI.Drawing;
namespace DesktopMagic.Api.Drawing;
/// <summary>
/// Extensions for the <see cref="Graphics"/> class.
@@ -1,4 +1,4 @@
namespace DesktopMagicPluginAPI.Drawing;
namespace DesktopMagic.Api.Drawing;
/// <summary>
/// Specifies which render quality is used to display the bitmap images.
+1 -1
View File
@@ -1,6 +1,6 @@
using System.Drawing;
namespace DesktopMagicPluginAPI;
namespace DesktopMagic.Api;
/// <summary>
/// Defines properties and methods that provide information about the main application.
+1 -1
View File
@@ -1,6 +1,6 @@
using System.Drawing;
namespace DesktopMagicPluginAPI;
namespace DesktopMagic.Api;
/// <summary>
/// The theme settings of the main application.
+4 -4
View File
@@ -1,10 +1,10 @@
using DesktopMagicPluginAPI.Drawing;
using DesktopMagicPluginAPI.Inputs;
using DesktopMagic.Api.Drawing;
using DesktopMagic.Api.Settings;
using System;
using System.Drawing;
namespace DesktopMagicPluginAPI;
namespace DesktopMagic.Api;
/// <summary>
/// The plugin class.
@@ -50,7 +50,7 @@ public abstract class Plugin
/// Occurs when the <see cref="UpdateInterval"/> elapses.
/// </summary>
/// <returns></returns>
public abstract Bitmap Main();
public abstract Bitmap? Main();
/// <summary>
/// Occurs when the window is clicked by the mouse.
+1 -1
View File
@@ -1,6 +1,6 @@
using System;
namespace DesktopMagicPluginAPI.Settings;
namespace DesktopMagic.Api.Settings;
/// <summary>
/// Represents a button control.
+12 -1
View File
@@ -1,4 +1,4 @@
namespace DesktopMagicPluginAPI.Settings;
namespace DesktopMagic.Api.Settings;
/// <summary>
/// Represents a check box control.
@@ -31,4 +31,15 @@ public class CheckBox : Setting
{
Value = value;
}
internal override string GetJsonValue()
{
return Value.ToString();
}
internal override void SetJsonValue(string value)
{
_ = bool.TryParse(value, out bool result);
Value = result;
}
}
+24 -4
View File
@@ -1,8 +1,7 @@
using DesktopMagicPluginAPI.Inputs;
using System.Collections.ObjectModel;
using System.Text.Json;
using System.Collections.ObjectModel;
namespace DesktopMagicPluginAPI.Settings;
namespace DesktopMagic.Api.Settings;
/// <summary>
/// Represents a selection control with a drop-down list.
@@ -44,4 +43,25 @@ public class ComboBox : Setting
Items.Add(item);
}
}
internal override string GetJsonValue()
{
return JsonSerializer.Serialize(new { Value, Items });
}
internal override void SetJsonValue(string value)
{
if (string.IsNullOrEmpty(value))
{
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;
}
}
@@ -1,6 +1,6 @@
using System;
namespace DesktopMagicPluginAPI.Settings;
namespace DesktopMagic.Api.Settings;
/// <summary>
/// Represents a up-down control.
@@ -61,4 +61,15 @@ public class IntegerUpDown : Setting
Maximum = max;
Value = value;
}
internal override string GetJsonValue()
{
return Value.ToString();
}
internal override void SetJsonValue(string value)
{
_ = int.TryParse(value, out int result);
Value = result;
}
}
+1 -3
View File
@@ -1,6 +1,4 @@
using DesktopMagicPluginAPI.Settings;
namespace DesktopMagicPluginAPI.Inputs;
namespace DesktopMagic.Api.Settings;
/// <summary>
/// Represents a label control.
@@ -1,4 +1,4 @@
namespace DesktopMagicPluginAPI.Inputs;
namespace DesktopMagic.Api.Settings;
/// <summary>
/// Mouse Buttons
+13 -2
View File
@@ -1,6 +1,9 @@
using System;
using System.Runtime.CompilerServices;
namespace DesktopMagicPluginAPI.Settings;
[assembly: InternalsVisibleTo("DesktopMagic")]
namespace DesktopMagic.Api.Settings;
/// <summary>
/// The element base class.
@@ -10,7 +13,15 @@ public abstract class Setting
/// <summary>
/// Occurs when the value has been changed.
/// </summary>
public event Action OnValueChanged;
public event Action? OnValueChanged;
internal virtual string GetJsonValue()
{
return string.Empty;
}
internal virtual void SetJsonValue(string value)
{ }
/// <summary>
/// Triggers the <see cref="OnValueChanged"/> event.
@@ -1,6 +1,6 @@
using System;
namespace DesktopMagicPluginAPI.Inputs;
namespace DesktopMagic.Api.Settings;
/// <summary>
/// Marks a Property as element.
@@ -11,20 +11,27 @@ public class SettingAttribute : Attribute
/// <summary>
/// The name of the element.
/// </summary>
public string Name { get; }
public string Name { get; set; }
/// <summary>
/// The order index of the element.
/// </summary>
public int OrderIndex { get; }
public int OrderIndex { get; set; }
/// <summary>
/// The id of the element.
/// </summary>
public string Id { get; }
/// <summary>
/// Marks a Property as element with the provided <paramref name="name"/> and <paramref name="orderIndex"/>.
/// </summary>
/// <param name="id">The id of the element.</param>
/// <param name="name">The name of the element.</param>
/// <param name="orderIndex">The order index of the element.</param>
public SettingAttribute(string name, int orderIndex = 0)
public SettingAttribute(string id, string name, int orderIndex = 0)
{
Id = id;
Name = name;
OrderIndex = orderIndex;
}
@@ -32,14 +39,17 @@ public class SettingAttribute : Attribute
/// <summary>
/// Marks a Property as element with the provided <paramref name="orderIndex"/>.
/// </summary>
/// <param name="id">The id of the element.</param>
/// <param name="orderIndex">The order index of the element.</param>
public SettingAttribute(int orderIndex)
public SettingAttribute(string id, int orderIndex)
{
Id = id;
OrderIndex = orderIndex;
}
/// <inheritdoc cref="SettingAttribute"/>
public SettingAttribute()
public SettingAttribute(string id)
{
Id = id;
}
}
+12 -1
View File
@@ -1,6 +1,6 @@
using System;
namespace DesktopMagicPluginAPI.Settings;
namespace DesktopMagic.Api.Settings;
/// <summary>
/// Represents a slider control.
@@ -60,4 +60,15 @@ public sealed class Slider : Setting
Maximum = max;
Value = value;
}
internal override string GetJsonValue()
{
return Value.ToString();
}
internal override void SetJsonValue(string value)
{
_ = double.TryParse(value, out double result);
Value = result;
}
}
+11 -1
View File
@@ -1,4 +1,4 @@
namespace DesktopMagicPluginAPI.Settings;
namespace DesktopMagic.Api.Settings;
/// <summary>
/// Represents a text box control.
@@ -31,4 +31,14 @@ public class TextBox : Setting
{
Value = value;
}
internal override string GetJsonValue()
{
return Value;
}
internal override void SetJsonValue(string value)
{
Value = value;
}
}