From d956bd8b2a680cb6201505c68154f6d0e12565b8 Mon Sep 17 00:00:00 2001 From: XanatosX <10531466+XanatosX@users.noreply.github.com> Date: Sun, 11 Dec 2022 14:15:09 +0100 Subject: [PATCH 01/12] Add code to load plugin settings in add function model --- .../ViewModels/AddFunctionViewModel.cs | 34 ++++++++++++++++++- .../Services/FunctionSettingService.cs | 14 ++++---- .../Services/IFunctionSettingsService.cs | 10 +++++- 3 files changed, 48 insertions(+), 10 deletions(-) diff --git a/src/ModularToolManager/ViewModels/AddFunctionViewModel.cs b/src/ModularToolManager/ViewModels/AddFunctionViewModel.cs index 8e006dc2..8557d7c2 100644 --- a/src/ModularToolManager/ViewModels/AddFunctionViewModel.cs +++ b/src/ModularToolManager/ViewModels/AddFunctionViewModel.cs @@ -7,6 +7,7 @@ using ModularToolManager.Services.Ui; using ModularToolManagerModel.Services.Functions; using ModularToolManagerModel.Services.Plugin; +using ModularToolManagerPlugin.Services; using System; using System.Collections.Generic; using System.ComponentModel.DataAnnotations; @@ -30,7 +31,13 @@ internal partial class AddFunctionViewModel : ObservableValidator /// Private list for all the function plugins /// private readonly List functionPlugins; + private readonly IPluginService? pluginService; + + /// + /// The function service to use + /// private readonly IFunctionService? functionService; + private readonly IFunctionSettingsService functionSettingsService; /// /// Service to use for opening windows or modals @@ -62,6 +69,12 @@ internal partial class AddFunctionViewModel : ObservableValidator [NotifyCanExecuteChangedFor(nameof(OpenFunctionPathCommand))] private FunctionPluginViewModel? selectedFunctionPlugin; + /// + /// Are there any settings available for the plugin + /// + [ObservableProperty] + private bool settingsAvailable; + /// /// The parameters for the function /// @@ -86,10 +99,12 @@ internal partial class AddFunctionViewModel : ObservableValidator /// /// The plugin service to use /// The function service to use - public AddFunctionViewModel(IPluginService? pluginService, IFunctionService? functionService, IWindowManagementService windowManagmentService) + public AddFunctionViewModel(IPluginService? pluginService, IFunctionService? functionService, IFunctionSettingsService functionSettingsService, IWindowManagementService windowManagmentService) { functionPlugins = new(); + this.pluginService = pluginService; this.functionService = functionService; + this.functionSettingsService = functionSettingsService; this.windowManagmentService = windowManagmentService; if (pluginService is not null) { @@ -97,9 +112,26 @@ public AddFunctionViewModel(IPluginService? pluginService, IFunctionService? fun .Select(plugin => new FunctionPluginViewModel(plugin))); } + PropertyChanged += (_, e) => + { + if (e.PropertyName == nameof(SelectedFunctionPlugin)) + { + LoadPluginSettings(); + } + }; + InitialValueSet(); } + private void LoadPluginSettings() + { + if (SelectedFunctionPlugin is null || SelectedFunctionPlugin.Plugin is null) + { + return; + } + var settings = functionSettingsService.GetPluginSettingsValues(SelectedFunctionPlugin.Plugin, false).ToList(); + } + /// /// Load on a function by the identifer to allow editing of the function /// diff --git a/src/ModularToolManagerPlugin/Services/FunctionSettingService.cs b/src/ModularToolManagerPlugin/Services/FunctionSettingService.cs index f61260bb..2be692a6 100644 --- a/src/ModularToolManagerPlugin/Services/FunctionSettingService.cs +++ b/src/ModularToolManagerPlugin/Services/FunctionSettingService.cs @@ -38,13 +38,6 @@ public IEnumerable GetPluginSettings(Type type) .OfType(); } - /// - public IEnumerable GetPluginSettingsValues(IFunctionPlugin plugin) - { - IFunctionSettingsService local = this as IFunctionSettingsService; - return local.GetPluginSettings(plugin).Select(settings => GetSettingModel(settings, plugin)); - } - /// /// Get the setting model for a given attribute for a specific plugin /// @@ -124,5 +117,10 @@ private bool IsSearchedSettingValue(PropertyInfo propertyInfo, SettingAttribute return attribute is not null && attribute.Key == searchedAttribute.Key; } - + /// + public IEnumerable GetPluginSettingsValues(IFunctionPlugin plugin, bool globalOnly) + { + IFunctionSettingsService local = this as IFunctionSettingsService; + return local.GetPluginSettings(plugin).Where(plugin => globalOnly ? true : plugin.GlobalOnly == false).Select(settings => GetSettingModel(settings, plugin)); + } } diff --git a/src/ModularToolManagerPlugin/Services/IFunctionSettingsService.cs b/src/ModularToolManagerPlugin/Services/IFunctionSettingsService.cs index 6994c6df..c669441a 100644 --- a/src/ModularToolManagerPlugin/Services/IFunctionSettingsService.cs +++ b/src/ModularToolManagerPlugin/Services/IFunctionSettingsService.cs @@ -28,7 +28,15 @@ public interface IFunctionSettingsService /// /// The plugin to get all the settings values from /// A list with setting models for the plugin - IEnumerable GetPluginSettingsValues(IFunctionPlugin plugin); + IEnumerable GetPluginSettingsValues(IFunctionPlugin plugin) => GetPluginSettingsValues(plugin, true); + + /// + /// Get all the setting values from the given plugin + /// + /// The plugin to get all the settings values from + /// Show only global settings + /// A list with setting models for the plugin + IEnumerable GetPluginSettingsValues(IFunctionPlugin plugin, bool globalOnly); /// /// Does the plugin contain settings From 084f8abe0f12c8404f45787a10060c049d09e007 Mon Sep 17 00:00:00 2001 From: XanatosX <10531466+XanatosX@users.noreply.github.com> Date: Sun, 29 Jan 2023 19:44:01 +0100 Subject: [PATCH 02/12] Add converter for setting model Rework code --- .../DependencyInjectionExtension.cs | 12 +++---- .../Data/FunctionModel.cs | 8 ++++- .../SettingModelJsonConverter.cs | 35 +++++++++++++++++++ .../ModelDependencyInjection.cs | 31 ++++++++++++++++ .../Functions/SerializedFunctionService.cs | 1 + .../Serialization/JsonSerializationService.cs | 4 ++- 6 files changed, 82 insertions(+), 9 deletions(-) create mode 100644 src/ModularToolManagerModel/Data/Serialization/SettingModelJsonConverter.cs create mode 100644 src/ModularToolManagerModel/DependencyInjection/ModelDependencyInjection.cs diff --git a/src/ModularToolManager/DependencyInjection/DependencyInjectionExtension.cs b/src/ModularToolManager/DependencyInjection/DependencyInjectionExtension.cs index 29c55f80..a11bcffd 100644 --- a/src/ModularToolManager/DependencyInjection/DependencyInjectionExtension.cs +++ b/src/ModularToolManager/DependencyInjection/DependencyInjectionExtension.cs @@ -8,6 +8,7 @@ using ModularToolManager.Services.Ui; using ModularToolManager.ViewModels; using ModularToolManager.Views; +using ModularToolManagerModel.DependencyInjection; using ModularToolManagerModel.Services.Dependency; using ModularToolManagerModel.Services.Functions; using ModularToolManagerModel.Services.IO; @@ -80,23 +81,20 @@ public static IServiceCollection AddViews(this IServiceCollection collection) /// The extended collection public static IServiceCollection AddServices(this IServiceCollection collection) { - return collection.AddSingleton() + return collection.AddAllModelDepdencies() + .AddSingleton() .AddSingleton() .AddSingleton() .AddSingleton() .AddSingleton() .AddSingleton() - .AddSingleton() .AddSingleton, JsonSerializationOptionFactory>() .AddSingleton() .AddSingleton() .AddSingleton() .AddSingleton() .AddTransient() - .AddTransient() - .AddTransient() - .AddTransient() - .AddTransient() - .AddTransient(typeof(IPluginLoggerService<>), typeof(LoggingPluginAdapter<>)); + + .AddTransient(); } } diff --git a/src/ModularToolManagerModel/Data/FunctionModel.cs b/src/ModularToolManagerModel/Data/FunctionModel.cs index 572fdbd8..f3afee65 100644 --- a/src/ModularToolManagerModel/Data/FunctionModel.cs +++ b/src/ModularToolManagerModel/Data/FunctionModel.cs @@ -1,4 +1,5 @@ -using ModularToolManagerPlugin.Plugin; +using ModularToolManagerPlugin.Models; +using ModularToolManagerPlugin.Plugin; namespace ModularToolManager.Models { @@ -42,6 +43,11 @@ public class FunctionModel /// public int SortOrder { get; set; } + /// + /// The settings for this specific function + /// + public IEnumerable Settings { get; set; } + /// /// Create a new instance of ths class /// diff --git a/src/ModularToolManagerModel/Data/Serialization/SettingModelJsonConverter.cs b/src/ModularToolManagerModel/Data/Serialization/SettingModelJsonConverter.cs new file mode 100644 index 00000000..9dac3e3f --- /dev/null +++ b/src/ModularToolManagerModel/Data/Serialization/SettingModelJsonConverter.cs @@ -0,0 +1,35 @@ +using ModularToolManagerPlugin.Models; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Text.Json; +using System.Text.Json.Serialization; +using System.Threading.Tasks; + +namespace ModularToolManagerModel.Data.Serialization; +public class SettingModelJsonConverter : JsonConverter +{ + private const string VALUE_KEY = "value"; + + private const string KEY_NAME_KEY = "key"; + + private const string TYPE_KEY = "type"; + + public override SettingModel? Read(ref Utf8JsonReader reader, Type typeToConvert, JsonSerializerOptions options) + { + throw new NotImplementedException(); + } + + public override void Write(Utf8JsonWriter writer, SettingModel value, JsonSerializerOptions options) + { + writer.WriteStartObject(nameof(SettingModel)); + writer.WriteString(KEY_NAME_KEY, value.Key); + writer.WriteNumber(TYPE_KEY, (int)value.Type); + writer.WriteString(VALUE_KEY, value.Value?.ToString() ?? string.Empty); + writer.WriteEndObject(); + throw new NotImplementedException(); + } +} + + diff --git a/src/ModularToolManagerModel/DependencyInjection/ModelDependencyInjection.cs b/src/ModularToolManagerModel/DependencyInjection/ModelDependencyInjection.cs new file mode 100644 index 00000000..cafe65ca --- /dev/null +++ b/src/ModularToolManagerModel/DependencyInjection/ModelDependencyInjection.cs @@ -0,0 +1,31 @@ +using Microsoft.Extensions.DependencyInjection; +using ModularToolManager.Services.Serialization; +using ModularToolManagerModel.Services.IO; +using ModularToolManagerModel.Services.Logging; +using ModularToolManagerModel.Services.Plugin; +using ModularToolManagerModel.Services.Serialization; +using ModularToolManagerPlugin.Services; + +namespace ModularToolManagerModel.DependencyInjection; +public static class ModelDependencyInjection +{ + public static IServiceCollection AddModelDependencies(this IServiceCollection collection) + { + return collection.AddSingleton() + .AddSingleton() + .AddTransient(typeof(IPluginLoggerService<>), typeof(LoggingPluginAdapter<>)) + .AddSingleton() + .AddTransient(); + } + + public static IServiceCollection AddAdditionalDependencies(this IServiceCollection collection) + { + return collection.AddSingleton(); + } + + public static IServiceCollection AddAllModelDepdencies(this IServiceCollection collection) + { + return collection.AddModelDependencies() + .AddAdditionalDependencies(); + } +} diff --git a/src/ModularToolManagerModel/Services/Functions/SerializedFunctionService.cs b/src/ModularToolManagerModel/Services/Functions/SerializedFunctionService.cs index 6856ba50..d40c4e16 100644 --- a/src/ModularToolManagerModel/Services/Functions/SerializedFunctionService.cs +++ b/src/ModularToolManagerModel/Services/Functions/SerializedFunctionService.cs @@ -39,6 +39,7 @@ public class SerializedFunctionService : IFunctionService + /// /// Create a new instance of this class /// diff --git a/src/ModularToolManagerModel/Services/Serialization/JsonSerializationService.cs b/src/ModularToolManagerModel/Services/Serialization/JsonSerializationService.cs index f68a4a43..1fcedc1d 100644 --- a/src/ModularToolManagerModel/Services/Serialization/JsonSerializationService.cs +++ b/src/ModularToolManagerModel/Services/Serialization/JsonSerializationService.cs @@ -27,7 +27,9 @@ public class JsonSerializationService : ISerializeService /// The factory to use for creating the serialization options /// /// The logging service to use /// A empty factory was recievend, the class cannot be used - public JsonSerializationService(ISerializationOptionFactory? serializationOptionFactory, ILogger? loggingService) + public JsonSerializationService( + ISerializationOptionFactory? serializationOptionFactory, + ILogger? loggingService) { jsonSerializerOptions = serializationOptionFactory?.CreateOptions() ?? throw new NullReferenceException(); this.loggingService = loggingService; From a9119e31a7e55f8049390dc1540537d91ce26655 Mon Sep 17 00:00:00 2001 From: XanatosX <10531466+XanatosX@users.noreply.github.com> Date: Sun, 29 Jan 2023 20:21:43 +0100 Subject: [PATCH 03/12] Add converter to DI --- .../Models/PersistantPluginSetting.cs | 2 ++ .../DependencyInjection/ModelDependencyInjection.cs | 11 ++++++++++- .../Services/Functions/SerializedFunctionService.cs | 5 ----- .../Serialization/JsonSerializationService.cs | 6 +++++- 4 files changed, 17 insertions(+), 7 deletions(-) diff --git a/src/ModularToolManager/Models/PersistantPluginSetting.cs b/src/ModularToolManager/Models/PersistantPluginSetting.cs index cc5362b3..6fb3b264 100644 --- a/src/ModularToolManager/Models/PersistantPluginSetting.cs +++ b/src/ModularToolManager/Models/PersistantPluginSetting.cs @@ -1,5 +1,6 @@ using Microsoft.Extensions.Options; using ModularToolManagerPlugin.Enums; +using System; using System.Text.Json; using System.Text.Json.Serialization; @@ -8,6 +9,7 @@ namespace ModularToolManagerPlugin.Models; /// /// Plugin settings ready to save on the disc /// +[Obsolete] public class PersistantPluginSetting { /// diff --git a/src/ModularToolManagerModel/DependencyInjection/ModelDependencyInjection.cs b/src/ModularToolManagerModel/DependencyInjection/ModelDependencyInjection.cs index cafe65ca..4e8e8d1a 100644 --- a/src/ModularToolManagerModel/DependencyInjection/ModelDependencyInjection.cs +++ b/src/ModularToolManagerModel/DependencyInjection/ModelDependencyInjection.cs @@ -1,10 +1,13 @@ using Microsoft.Extensions.DependencyInjection; using ModularToolManager.Services.Serialization; +using ModularToolManagerModel.Data.Serialization; using ModularToolManagerModel.Services.IO; using ModularToolManagerModel.Services.Logging; using ModularToolManagerModel.Services.Plugin; using ModularToolManagerModel.Services.Serialization; +using ModularToolManagerPlugin.Models; using ModularToolManagerPlugin.Services; +using System.Text.Json.Serialization; namespace ModularToolManagerModel.DependencyInjection; public static class ModelDependencyInjection @@ -15,7 +18,8 @@ public static IServiceCollection AddModelDependencies(this IServiceCollection co .AddSingleton() .AddTransient(typeof(IPluginLoggerService<>), typeof(LoggingPluginAdapter<>)) .AddSingleton() - .AddTransient(); + .AddTransient() + .AddJsonConverters(); } public static IServiceCollection AddAdditionalDependencies(this IServiceCollection collection) @@ -23,6 +27,11 @@ public static IServiceCollection AddAdditionalDependencies(this IServiceCollecti return collection.AddSingleton(); } + public static IServiceCollection AddJsonConverters(this IServiceCollection collection) + { + return collection.AddSingleton, SettingModelJsonConverter>(); + } + public static IServiceCollection AddAllModelDepdencies(this IServiceCollection collection) { return collection.AddModelDependencies() diff --git a/src/ModularToolManagerModel/Services/Functions/SerializedFunctionService.cs b/src/ModularToolManagerModel/Services/Functions/SerializedFunctionService.cs index d40c4e16..1a7befef 100644 --- a/src/ModularToolManagerModel/Services/Functions/SerializedFunctionService.cs +++ b/src/ModularToolManagerModel/Services/Functions/SerializedFunctionService.cs @@ -2,8 +2,6 @@ using ModularToolManager.Models; using ModularToolManager.Services.Serialization; using ModularToolManagerModel.Services.IO; -using ModularToolManagerModel.Services.Logging; -using ModularToolManagerPlugin.Plugin; namespace ModularToolManagerModel.Services.Functions; @@ -37,9 +35,6 @@ public class SerializedFunctionService : IFunctionService /// private readonly List cachedFunctions; - - - /// /// Create a new instance of this class /// diff --git a/src/ModularToolManagerModel/Services/Serialization/JsonSerializationService.cs b/src/ModularToolManagerModel/Services/Serialization/JsonSerializationService.cs index 1fcedc1d..6a69c489 100644 --- a/src/ModularToolManagerModel/Services/Serialization/JsonSerializationService.cs +++ b/src/ModularToolManagerModel/Services/Serialization/JsonSerializationService.cs @@ -1,8 +1,10 @@ using Microsoft.Extensions.Logging; using ModularToolManager.Services.Serialization; using ModularToolManagerModel.Services.Logging; +using ModularToolManagerPlugin.Models; using System.Text; using System.Text.Json; +using System.Text.Json.Serialization; namespace ModularToolManagerModel.Services.Serialization; @@ -29,9 +31,11 @@ public class JsonSerializationService : ISerializeService /// A empty factory was recievend, the class cannot be used public JsonSerializationService( ISerializationOptionFactory? serializationOptionFactory, - ILogger? loggingService) + ILogger? loggingService, + JsonConverter settingConverter) { jsonSerializerOptions = serializationOptionFactory?.CreateOptions() ?? throw new NullReferenceException(); + jsonSerializerOptions.Converters.Add(settingConverter); this.loggingService = loggingService; } From dbd4469c55d8d3437ceb769ef4e2b077c70e0529 Mon Sep 17 00:00:00 2001 From: XanatosX <10531466+XanatosX@users.noreply.github.com> Date: Sun, 29 Jan 2023 21:09:25 +0100 Subject: [PATCH 04/12] Use new converter to save setting model --- .../DependencyInjectionExtension.cs | 2 +- .../Models/PluginSettings.cs | 2 +- .../ModularToolManager.csproj | 3 - .../Ui/PluginSettingViewModelService.cs | 20 ++++ .../ViewModels/FunctionButtonViewModel.cs | 2 +- .../ViewModels/PluginSettingsViewModel.cs | 30 ++--- .../SettingModelJsonConverter.cs | 113 ++++++++++++++++-- 7 files changed, 142 insertions(+), 30 deletions(-) create mode 100644 src/ModularToolManager/Services/Ui/PluginSettingViewModelService.cs diff --git a/src/ModularToolManager/DependencyInjection/DependencyInjectionExtension.cs b/src/ModularToolManager/DependencyInjection/DependencyInjectionExtension.cs index a11bcffd..ffe40741 100644 --- a/src/ModularToolManager/DependencyInjection/DependencyInjectionExtension.cs +++ b/src/ModularToolManager/DependencyInjection/DependencyInjectionExtension.cs @@ -94,7 +94,7 @@ public static IServiceCollection AddServices(this IServiceCollection collection) .AddSingleton() .AddSingleton() .AddTransient() - + .AddSingleton() .AddTransient(); } } diff --git a/src/ModularToolManager/Models/PluginSettings.cs b/src/ModularToolManager/Models/PluginSettings.cs index a9b1649f..9e56937b 100644 --- a/src/ModularToolManager/Models/PluginSettings.cs +++ b/src/ModularToolManager/Models/PluginSettings.cs @@ -20,5 +20,5 @@ public class PluginSettings /// The settings to persist for the plugin /// [JsonPropertyName("settings")] - public List? Settings { get; set; } + public List? Settings { get; set; } } diff --git a/src/ModularToolManager/ModularToolManager.csproj b/src/ModularToolManager/ModularToolManager.csproj index 3d60fd4f..7c82dc93 100644 --- a/src/ModularToolManager/ModularToolManager.csproj +++ b/src/ModularToolManager/ModularToolManager.csproj @@ -46,7 +46,4 @@ Resources.Designer.cs - - - diff --git a/src/ModularToolManager/Services/Ui/PluginSettingViewModelService.cs b/src/ModularToolManager/Services/Ui/PluginSettingViewModelService.cs new file mode 100644 index 00000000..1390082d --- /dev/null +++ b/src/ModularToolManager/Services/Ui/PluginSettingViewModelService.cs @@ -0,0 +1,20 @@ +using ModularToolManager.ViewModels; +using ModularToolManager.ViewModels.Settings; +using ModularToolManagerPlugin.Enums; +using ModularToolManagerPlugin.Models; + +namespace ModularToolManager.Services.Ui; +internal class PluginSettingViewModelService +{ + public IPluginSettingModel? GetViewModel(SettingModel settingModel) + { + return settingModel.Type switch + { + SettingType.Boolean => new BoolPluginSettingViewModel(settingModel), + SettingType.String => new StringPluginSettingViewModel(settingModel), + SettingType.Float => new FloatPluginSettingViewModel(settingModel), + SettingType.Int => new IntPluginSettingViewModel(settingModel), + _ => null + }; + } +} diff --git a/src/ModularToolManager/ViewModels/FunctionButtonViewModel.cs b/src/ModularToolManager/ViewModels/FunctionButtonViewModel.cs index e0a30c1b..186c8848 100644 --- a/src/ModularToolManager/ViewModels/FunctionButtonViewModel.cs +++ b/src/ModularToolManager/ViewModels/FunctionButtonViewModel.cs @@ -138,7 +138,7 @@ private void ApplyPluginSettings(IFunctionPlugin? plugin) List pluginSettings = functionSettingsService.GetPluginSettings(plugin).ToList() ?? new(); var settings = settingsService.GetApplicationSettings().PluginSettings.FirstOrDefault(setting => setting?.Plugin?.GetType() == functionModel?.Plugin?.GetType()); - foreach (var loadedPluginSetting in settings?.Settings?.Select(setting => setting.GetSettingModel()) ?? Enumerable.Empty()) + foreach (var loadedPluginSetting in settings?.Settings ?? Enumerable.Empty()) { var matchingAttribute = pluginSettings.FirstOrDefault(setting => setting.Key == loadedPluginSetting.Key); if (matchingAttribute is null) diff --git a/src/ModularToolManager/ViewModels/PluginSettingsViewModel.cs b/src/ModularToolManager/ViewModels/PluginSettingsViewModel.cs index 3daf4c37..e30fe1b5 100644 --- a/src/ModularToolManager/ViewModels/PluginSettingsViewModel.cs +++ b/src/ModularToolManager/ViewModels/PluginSettingsViewModel.cs @@ -2,6 +2,7 @@ using CommunityToolkit.Mvvm.Input; using ModularToolManager.Models; using ModularToolManager.Services.Settings; +using ModularToolManager.Services.Ui; using ModularToolManager.ViewModels.Settings; using ModularToolManagerPlugin.Enums; using ModularToolManagerPlugin.Models; @@ -28,6 +29,11 @@ internal partial class PluginSettingsViewModel : ObservableObject /// private readonly ISettingsService applicationSettingService; + /// + /// Service to use to get correct view for settings model + /// + private readonly PluginSettingViewModelService pluginSettingView; + /// /// The settings of the plugin /// @@ -44,10 +50,13 @@ internal partial class PluginSettingsViewModel : ObservableObject /// /// The plugin service to use for loading plugin settings /// The service used to load application settings and sync plugin settings with - public PluginSettingsViewModel(IFunctionSettingsService pluginSettingService, ISettingsService applicationSettingService) + public PluginSettingsViewModel(IFunctionSettingsService pluginSettingService, + ISettingsService applicationSettingService, + PluginSettingViewModelService pluginSettingView) { this.pluginSettingService = pluginSettingService; this.applicationSettingService = applicationSettingService; + this.pluginSettingView = pluginSettingView; pluginSettings = new ObservableCollection(); } @@ -59,7 +68,7 @@ public void SetPlugin(IFunctionPlugin plugin) { currentPlugin = plugin; PluginSettings applicationPluginSettings = applicationSettingService.GetApplicationSettings()?.PluginSettings.FirstOrDefault(setting => setting?.Plugin?.GetType() == plugin.GetType()) ?? new(); - List persistantSettings = applicationPluginSettings.Settings ?? new(); + List persistantSettings = applicationPluginSettings.Settings ?? new(); List settings = pluginSettingService.GetPluginSettingsValues(plugin) .Select(setting => GetViewModel(setting, persistantSettings)) .Where(view => view is not null) @@ -82,18 +91,11 @@ public void SetPlugin(IFunctionPlugin plugin) /// The setting model to get the view from /// The loaded plugin settings stored for the application /// A setting model for the setting model - private IPluginSettingModel? GetViewModel(SettingModel settingModel, List pluginSettings) + private IPluginSettingModel? GetViewModel(SettingModel settingModel, List pluginSettings) { - var matchingSetting = pluginSettings.FirstOrDefault(setting => setting.Key == settingModel.Key)?.GetSettingModel(); + var matchingSetting = pluginSettings.FirstOrDefault(setting => setting.Key == settingModel.Key); settingModel.SetValue(matchingSetting is not null ? matchingSetting.Value : settingModel.Value); - return settingModel.Type switch - { - SettingType.Boolean => new BoolPluginSettingViewModel(settingModel), - SettingType.String => new StringPluginSettingViewModel(settingModel), - SettingType.Float => new FloatPluginSettingViewModel(settingModel), - SettingType.Int => new IntPluginSettingViewModel(settingModel), - _ => null - }; + return pluginSettingView.GetViewModel(settingModel); } /// @@ -102,8 +104,8 @@ public void SetPlugin(IFunctionPlugin plugin) [RelayCommand] private void SaveSettings() { - List settingsToSave = PluginSettings.Select(setting => setting.GetSettingsModel()) - .Select(model => new PersistantPluginSetting(model)) + List settingsToSave = PluginSettings.Select(setting => setting.GetSettingsModel()) + .Select(model => new SettingModel(model.Value) { Key = model.Key, Type = model.Type }) .Where(model => model.Key is not null) .ToList(); PluginSettings newPluginSettings = new() diff --git a/src/ModularToolManagerModel/Data/Serialization/SettingModelJsonConverter.cs b/src/ModularToolManagerModel/Data/Serialization/SettingModelJsonConverter.cs index 9dac3e3f..8ce15090 100644 --- a/src/ModularToolManagerModel/Data/Serialization/SettingModelJsonConverter.cs +++ b/src/ModularToolManagerModel/Data/Serialization/SettingModelJsonConverter.cs @@ -1,34 +1,127 @@ -using ModularToolManagerPlugin.Models; -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; +using ModularToolManagerPlugin.Enums; +using ModularToolManagerPlugin.Models; using System.Text.Json; using System.Text.Json.Serialization; -using System.Threading.Tasks; namespace ModularToolManagerModel.Data.Serialization; + +/// +/// Converter for the setting model +/// public class SettingModelJsonConverter : JsonConverter { + /// + /// The key to use for the value + /// private const string VALUE_KEY = "value"; + /// + /// The key to use for the settings key + /// private const string KEY_NAME_KEY = "key"; + /// + /// The key to use for the type + /// private const string TYPE_KEY = "type"; + /// public override SettingModel? Read(ref Utf8JsonReader reader, Type typeToConvert, JsonSerializerOptions options) { - throw new NotImplementedException(); + string? readKey = null; + string keyValue = string.Empty; + SettingType type = SettingType.String; + object? value = null; + while (reader.Read()) + { + if (reader.TokenType == JsonTokenType.EndObject) + { + break; + } + if (readKey is not null) + { + if (readKey == KEY_NAME_KEY) + { + keyValue = reader.GetString() ?? string.Empty; + } + if (readKey == TYPE_KEY) + { + var intType = reader.GetInt32(); + try + { + type = (SettingType)intType; + } + catch (Exception) + { + } + } + if (readKey == VALUE_KEY) + { + try + { + switch (type) + { + case SettingType.Boolean: + value = reader.GetBoolean(); + break; + case SettingType.String: + value = reader.GetString(); + break; + case SettingType.Float: + value = (float)reader.GetDouble(); + break; + case SettingType.Int: + value = (float)reader.GetInt32(); + break; + default: + break; + } + } + catch (Exception) + { + + } + + } + + readKey = null; + continue; + } + readKey = reader.GetString(); + + } + return new SettingModel(value) + { + Key = keyValue, + Type = type + }; } + /// public override void Write(Utf8JsonWriter writer, SettingModel value, JsonSerializerOptions options) { - writer.WriteStartObject(nameof(SettingModel)); + writer.WriteStartObject(); writer.WriteString(KEY_NAME_KEY, value.Key); writer.WriteNumber(TYPE_KEY, (int)value.Type); - writer.WriteString(VALUE_KEY, value.Value?.ToString() ?? string.Empty); + switch (value.Type) + { + case SettingType.Boolean: + writer.WriteBoolean(VALUE_KEY, value.Value as bool? ?? false); + break; + case SettingType.String: + writer.WriteString(VALUE_KEY, value.Value?.ToString() ?? string.Empty); + break; + case SettingType.Float: + writer.WriteNumber(VALUE_KEY, value.Value as float? ?? 0f); + break; + case SettingType.Int: + writer.WriteNumber(VALUE_KEY, value.Value as int? ?? 0); + break; + default: + break; + } + writer.WriteEndObject(); - throw new NotImplementedException(); } } From 27e56612b10c1a66c4ec7f7cb5db261e22df0fed Mon Sep 17 00:00:00 2001 From: XanatosX <10531466+XanatosX@users.noreply.github.com> Date: Sun, 29 Jan 2023 21:09:52 +0100 Subject: [PATCH 05/12] Remove unused class --- .../Models/PersistantPluginSetting.cs | 97 ------------------- 1 file changed, 97 deletions(-) delete mode 100644 src/ModularToolManager/Models/PersistantPluginSetting.cs diff --git a/src/ModularToolManager/Models/PersistantPluginSetting.cs b/src/ModularToolManager/Models/PersistantPluginSetting.cs deleted file mode 100644 index 6fb3b264..00000000 --- a/src/ModularToolManager/Models/PersistantPluginSetting.cs +++ /dev/null @@ -1,97 +0,0 @@ -using Microsoft.Extensions.Options; -using ModularToolManagerPlugin.Enums; -using System; -using System.Text.Json; -using System.Text.Json.Serialization; - -namespace ModularToolManagerPlugin.Models; - -/// -/// Plugin settings ready to save on the disc -/// -[Obsolete] -public class PersistantPluginSetting -{ - /// - /// The key of the plugin settings - /// - [JsonPropertyName("key")] - public string? Key { get; set; } - - /// - /// The type of the plugin settings - /// - [JsonPropertyName("type")] - public SettingType Type { get; set; } - - /// - /// The value of the plugin setting - /// - [JsonPropertyName("value")] - public object? Value { get; set; } - - /// - /// Create a new instance of this class - /// - public PersistantPluginSetting() - { - //Required empty constructor for json serializer - Type = SettingType.String; - Key = null; - Value = null; - } - - /// - /// Create a new instance of this class - /// - /// The settings model to use as a base - public PersistantPluginSetting(SettingModel settingModel) - { - Key = settingModel.Key; - Type = settingModel.Type; - Value = settingModel.Value; - } - - /// - /// Get the value from the plugin setting - /// - /// The type to convert the value to - /// The converted value or the default of T - private T? GetValue() - { - object? dataObject = Value; - if (dataObject is JsonElement element) - { - dataObject = Type switch - { - SettingType.Boolean => element.GetBoolean(), - SettingType.Int => element.GetInt32(), - SettingType.Float => (float)element.GetDecimal(), - SettingType.String => element.GetString(), - _ => element.GetRawText() - }; - } - return dataObject is null || dataObject.GetType() != typeof(T) ? default : (T?)dataObject; - } - - /// - /// Convert to a valid setting model - /// - /// A useable setting model - public SettingModel GetSettingModel() - { - object? data = Type switch - { - SettingType.Boolean => GetValue(), - SettingType.Int => GetValue(), - SettingType.Float => GetValue(), - _ => GetValue() - }; - return new SettingModel(data) - { - DisplayName = Key, - Key = Key, - Type = Type - }; - } -} From 2a71b117935678efe41f4318bdce5c8ab68f06e8 Mon Sep 17 00:00:00 2001 From: XanatosX <10531466+XanatosX@users.noreply.github.com> Date: Sun, 29 Jan 2023 21:44:58 +0100 Subject: [PATCH 06/12] Add code to save and load function specific settings --- .../ViewModels/AddFunctionViewModel.cs | 55 ++++++++++++++++++- .../ViewModels/BoolPluginSettingViewModel.cs | 8 +++ .../ViewModels/FloatPluginSettingViewModel.cs | 8 +++ .../ViewModels/IntPluginSettingViewModel.cs | 8 +++ .../ViewModels/PluginSettingBaseViewModel.cs | 3 +- .../Settings/IPluginSettingModel.cs | 2 + .../StringPluginSettingViewModel.cs | 8 +++ .../Views/AddFunctionView.axaml | 3 + .../Functions/SerializedFunctionService.cs | 1 + 9 files changed, 92 insertions(+), 4 deletions(-) diff --git a/src/ModularToolManager/ViewModels/AddFunctionViewModel.cs b/src/ModularToolManager/ViewModels/AddFunctionViewModel.cs index 8557d7c2..9a18c503 100644 --- a/src/ModularToolManager/ViewModels/AddFunctionViewModel.cs +++ b/src/ModularToolManager/ViewModels/AddFunctionViewModel.cs @@ -5,8 +5,10 @@ using ModularToolManager.Models; using ModularToolManager.Models.Messages; using ModularToolManager.Services.Ui; +using ModularToolManager.ViewModels.Settings; using ModularToolManagerModel.Services.Functions; using ModularToolManagerModel.Services.Plugin; +using ModularToolManagerPlugin.Models; using ModularToolManagerPlugin.Services; using System; using System.Collections.Generic; @@ -31,18 +33,27 @@ internal partial class AddFunctionViewModel : ObservableValidator /// Private list for all the function plugins /// private readonly List functionPlugins; + + /// + /// The service used to get plugins + /// private readonly IPluginService? pluginService; + /// + /// The service used to get the function settings + /// + private readonly IFunctionSettingsService functionSettingsService; + /// /// The function service to use /// private readonly IFunctionService? functionService; - private readonly IFunctionSettingsService functionSettingsService; /// /// Service to use for opening windows or modals /// private readonly IWindowManagementService windowManagmentService; + private readonly PluginSettingViewModelService pluginSettingView; /// /// The display name of the function @@ -89,6 +100,15 @@ internal partial class AddFunctionViewModel : ObservableValidator [NotifyCanExecuteChangedFor(nameof(OkCommand))] private string? selectedPath; + [ObservableProperty] + [NotifyPropertyChangedFor(nameof(PluginSettingsFound))] + private List? pluginSettings; + + /// + /// Should the settings part be visible + /// + public bool PluginSettingsFound => PluginSettings?.Any() ?? false; + /// /// The identifier to use for the function /// @@ -99,13 +119,18 @@ internal partial class AddFunctionViewModel : ObservableValidator /// /// The plugin service to use /// The function service to use - public AddFunctionViewModel(IPluginService? pluginService, IFunctionService? functionService, IFunctionSettingsService functionSettingsService, IWindowManagementService windowManagmentService) + public AddFunctionViewModel(IPluginService? pluginService, + IFunctionService? functionService, + IFunctionSettingsService functionSettingsService, + IWindowManagementService windowManagmentService, + PluginSettingViewModelService pluginSettingView) { functionPlugins = new(); this.pluginService = pluginService; this.functionService = functionService; this.functionSettingsService = functionSettingsService; this.windowManagmentService = windowManagmentService; + this.pluginSettingView = pluginSettingView; if (pluginService is not null) { functionPlugins.AddRange(pluginService!.GetAvailablePlugins() @@ -123,13 +148,21 @@ public AddFunctionViewModel(IPluginService? pluginService, IFunctionService? fun InitialValueSet(); } + /// + /// Load all the possible settings for the plugin + /// private void LoadPluginSettings() { if (SelectedFunctionPlugin is null || SelectedFunctionPlugin.Plugin is null) { return; } - var settings = functionSettingsService.GetPluginSettingsValues(SelectedFunctionPlugin.Plugin, false).ToList(); + SelectedFunctionPlugin.Plugin.ResetSettings(); + PluginSettings = functionSettingsService.GetPluginSettingsValues(SelectedFunctionPlugin.Plugin, false) + .OfType() + .Select(pluginSetting => pluginSettingView.GetViewModel(pluginSetting)) + .OfType() + .ToList(); } /// @@ -148,6 +181,15 @@ public bool LoadInFunction(string identifier) DisplayName = function.DisplayName; Description = function.Description; SelectedFunctionPlugin = FunctionPlugins.FirstOrDefault(plugin => plugin.Plugin == function.Plugin); + foreach (var setting in PluginSettings ?? Enumerable.Empty()) + { + var settingToUpdate = function.Settings.FirstOrDefault(pSetting => pSetting.Key == setting.GetSettingsModel().Key); + if (settingToUpdate is not null) + { + setting.UpdateValue(settingToUpdate.Value); + } + + } FunctionParameters = function.Parameters; SelectedPath = function.Path; @@ -200,11 +242,17 @@ private FunctionModel CreateNewFunctionModel() Description = Description, Plugin = SelectedFunctionPlugin!.Plugin, Parameters = FunctionParameters!, + Settings = GetPluginSettings(), Path = SelectedPath!, SortOrder = 0 }; } + private IEnumerable GetPluginSettings() + { + return PluginSettings?.Select(model => model.GetSettingsModel()) ?? Enumerable.Empty(); + } + /// /// Create a edited function model with given identifier /// @@ -218,6 +266,7 @@ private FunctionModel CreateEditedFunctionModel() Description = Description, Plugin = SelectedFunctionPlugin!.Plugin, Parameters = FunctionParameters!, + Settings = GetPluginSettings(), Path = SelectedPath!, SortOrder = 0 }; diff --git a/src/ModularToolManager/ViewModels/BoolPluginSettingViewModel.cs b/src/ModularToolManager/ViewModels/BoolPluginSettingViewModel.cs index 19a9064f..9322440d 100644 --- a/src/ModularToolManager/ViewModels/BoolPluginSettingViewModel.cs +++ b/src/ModularToolManager/ViewModels/BoolPluginSettingViewModel.cs @@ -26,4 +26,12 @@ public override SettingModel GetSettingsModel() storedModel.SetValue(IsChecked); return storedModel; } + + public override void UpdateValue(object? newData) + { + if (newData is bool) + { + IsChecked = (bool)newData; + } + } } diff --git a/src/ModularToolManager/ViewModels/FloatPluginSettingViewModel.cs b/src/ModularToolManager/ViewModels/FloatPluginSettingViewModel.cs index 8317e978..3866b26f 100644 --- a/src/ModularToolManager/ViewModels/FloatPluginSettingViewModel.cs +++ b/src/ModularToolManager/ViewModels/FloatPluginSettingViewModel.cs @@ -32,4 +32,12 @@ public override SettingModel GetSettingsModel() storedModel.SetValue(FloatNumber); return storedModel; } + + public override void UpdateValue(object? newData) + { + if (newData is float) + { + FloatNumber = (float)newData; + } + } } diff --git a/src/ModularToolManager/ViewModels/IntPluginSettingViewModel.cs b/src/ModularToolManager/ViewModels/IntPluginSettingViewModel.cs index 6fcab2ee..cf7bab46 100644 --- a/src/ModularToolManager/ViewModels/IntPluginSettingViewModel.cs +++ b/src/ModularToolManager/ViewModels/IntPluginSettingViewModel.cs @@ -31,4 +31,12 @@ public override SettingModel GetSettingsModel() storedModel.SetValue(IntergerNumber); return storedModel; } + + public override void UpdateValue(object? newData) + { + if (newData is int) + { + intergerNumber = (int)newData; + } + } } diff --git a/src/ModularToolManager/ViewModels/PluginSettingBaseViewModel.cs b/src/ModularToolManager/ViewModels/PluginSettingBaseViewModel.cs index e4a37e50..c780dc0e 100644 --- a/src/ModularToolManager/ViewModels/PluginSettingBaseViewModel.cs +++ b/src/ModularToolManager/ViewModels/PluginSettingBaseViewModel.cs @@ -39,5 +39,6 @@ public PluginSettingBaseViewModel(SettingModel settingModel) /// public abstract SettingModel GetSettingsModel(); - + /// + public abstract void UpdateValue(object? newData); } \ No newline at end of file diff --git a/src/ModularToolManager/ViewModels/Settings/IPluginSettingModel.cs b/src/ModularToolManager/ViewModels/Settings/IPluginSettingModel.cs index 80a68336..d3a4e19d 100644 --- a/src/ModularToolManager/ViewModels/Settings/IPluginSettingModel.cs +++ b/src/ModularToolManager/ViewModels/Settings/IPluginSettingModel.cs @@ -7,6 +7,8 @@ namespace ModularToolManager.ViewModels.Settings; /// internal interface IPluginSettingModel { + void UpdateValue(object? newData); + /// /// Get the setting model from the view /// diff --git a/src/ModularToolManager/ViewModels/StringPluginSettingViewModel.cs b/src/ModularToolManager/ViewModels/StringPluginSettingViewModel.cs index 777396c7..99fe7d70 100644 --- a/src/ModularToolManager/ViewModels/StringPluginSettingViewModel.cs +++ b/src/ModularToolManager/ViewModels/StringPluginSettingViewModel.cs @@ -26,4 +26,12 @@ public override SettingModel GetSettingsModel() storedModel.SetValue(SettingText); return storedModel; } + + public override void UpdateValue(object? newData) + { + if (newData is string) + { + settingText = (string)newData; + } + } } diff --git a/src/ModularToolManager/Views/AddFunctionView.axaml b/src/ModularToolManager/Views/AddFunctionView.axaml index 6a164b45..0dd6e460 100644 --- a/src/ModularToolManager/Views/AddFunctionView.axaml +++ b/src/ModularToolManager/Views/AddFunctionView.axaml @@ -14,6 +14,9 @@ Items="{Binding FunctionPlugins}" SelectedItem="{Binding SelectedFunctionPlugin}"/> + + + Date: Sun, 29 Jan 2023 21:56:17 +0100 Subject: [PATCH 07/12] Add code to use specific settings Add code to correctly load global settings --- .../ViewModels/AddFunctionViewModel.cs | 17 ++++++++++++++++- .../ViewModels/FunctionButtonViewModel.cs | 5 +++++ 2 files changed, 21 insertions(+), 1 deletion(-) diff --git a/src/ModularToolManager/ViewModels/AddFunctionViewModel.cs b/src/ModularToolManager/ViewModels/AddFunctionViewModel.cs index 9a18c503..78f7f52d 100644 --- a/src/ModularToolManager/ViewModels/AddFunctionViewModel.cs +++ b/src/ModularToolManager/ViewModels/AddFunctionViewModel.cs @@ -4,6 +4,7 @@ using CommunityToolkit.Mvvm.Messaging; using ModularToolManager.Models; using ModularToolManager.Models.Messages; +using ModularToolManager.Services.Settings; using ModularToolManager.Services.Ui; using ModularToolManager.ViewModels.Settings; using ModularToolManagerModel.Services.Functions; @@ -53,6 +54,7 @@ internal partial class AddFunctionViewModel : ObservableValidator /// Service to use for opening windows or modals /// private readonly IWindowManagementService windowManagmentService; + private readonly ISettingsService settingsService; private readonly PluginSettingViewModelService pluginSettingView; /// @@ -123,6 +125,7 @@ public AddFunctionViewModel(IPluginService? pluginService, IFunctionService? functionService, IFunctionSettingsService functionSettingsService, IWindowManagementService windowManagmentService, + ISettingsService settingsService, PluginSettingViewModelService pluginSettingView) { functionPlugins = new(); @@ -130,6 +133,7 @@ public AddFunctionViewModel(IPluginService? pluginService, this.functionService = functionService; this.functionSettingsService = functionSettingsService; this.windowManagmentService = windowManagmentService; + this.settingsService = settingsService; this.pluginSettingView = pluginSettingView; if (pluginService is not null) { @@ -158,11 +162,22 @@ private void LoadPluginSettings() return; } SelectedFunctionPlugin.Plugin.ResetSettings(); - PluginSettings = functionSettingsService.GetPluginSettingsValues(SelectedFunctionPlugin.Plugin, false) + List settings = functionSettingsService.GetPluginSettingsValues(SelectedFunctionPlugin.Plugin, false) .OfType() .Select(pluginSetting => pluginSettingView.GetViewModel(pluginSetting)) .OfType() .ToList(); + var appPluginSettings = settingsService.GetApplicationSettings().PluginSettings + .FirstOrDefault(pSettings => pSettings.Plugin == SelectedFunctionPlugin.Plugin); + if (appPluginSettings is not null) + { + foreach (var setting in appPluginSettings.Settings ?? Enumerable.Empty()) + { + var matchingSettingView = settings.First(settingView => settingView.GetSettingsModel().Key == setting.Key); + matchingSettingView?.UpdateValue(setting.Value); + } + } + PluginSettings = settings; } /// diff --git a/src/ModularToolManager/ViewModels/FunctionButtonViewModel.cs b/src/ModularToolManager/ViewModels/FunctionButtonViewModel.cs index 186c8848..9869594f 100644 --- a/src/ModularToolManager/ViewModels/FunctionButtonViewModel.cs +++ b/src/ModularToolManager/ViewModels/FunctionButtonViewModel.cs @@ -140,6 +140,11 @@ private void ApplyPluginSettings(IFunctionPlugin? plugin) var settings = settingsService.GetApplicationSettings().PluginSettings.FirstOrDefault(setting => setting?.Plugin?.GetType() == functionModel?.Plugin?.GetType()); foreach (var loadedPluginSetting in settings?.Settings ?? Enumerable.Empty()) { + var specificSettings = functionModel?.Settings.FirstOrDefault(setting => setting.Key == loadedPluginSetting.Key); + if (specificSettings is not null) + { + loadedPluginSetting.SetValue(specificSettings.Value); + } var matchingAttribute = pluginSettings.FirstOrDefault(setting => setting.Key == loadedPluginSetting.Key); if (matchingAttribute is null) { From 13edaa607ae615e32a9a693188a317c16fc0f738 Mon Sep 17 00:00:00 2001 From: XanatosX <10531466+XanatosX@users.noreply.github.com> Date: Sun, 29 Jan 2023 21:57:26 +0100 Subject: [PATCH 08/12] Fix crash --- src/ModularToolManager/ViewModels/AddFunctionViewModel.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/ModularToolManager/ViewModels/AddFunctionViewModel.cs b/src/ModularToolManager/ViewModels/AddFunctionViewModel.cs index 78f7f52d..c01a87e4 100644 --- a/src/ModularToolManager/ViewModels/AddFunctionViewModel.cs +++ b/src/ModularToolManager/ViewModels/AddFunctionViewModel.cs @@ -173,7 +173,7 @@ private void LoadPluginSettings() { foreach (var setting in appPluginSettings.Settings ?? Enumerable.Empty()) { - var matchingSettingView = settings.First(settingView => settingView.GetSettingsModel().Key == setting.Key); + var matchingSettingView = settings.FirstOrDefault(settingView => settingView.GetSettingsModel().Key == setting.Key); matchingSettingView?.UpdateValue(setting.Value); } } From b8b21f14770566660399538ca840d78b807b831d Mon Sep 17 00:00:00 2001 From: XanatosX <10531466+XanatosX@users.noreply.github.com> Date: Sun, 29 Jan 2023 22:03:06 +0100 Subject: [PATCH 09/12] Add missing summary blocks --- .../Services/Ui/PluginSettingViewModelService.cs | 9 +++++++++ .../ViewModels/BoolPluginSettingViewModel.cs | 1 + .../ViewModels/FloatPluginSettingViewModel.cs | 2 ++ .../ViewModels/IntPluginSettingViewModel.cs | 1 + .../ViewModels/Settings/IPluginSettingModel.cs | 4 ++++ 5 files changed, 17 insertions(+) diff --git a/src/ModularToolManager/Services/Ui/PluginSettingViewModelService.cs b/src/ModularToolManager/Services/Ui/PluginSettingViewModelService.cs index 1390082d..f2d55f20 100644 --- a/src/ModularToolManager/Services/Ui/PluginSettingViewModelService.cs +++ b/src/ModularToolManager/Services/Ui/PluginSettingViewModelService.cs @@ -4,8 +4,17 @@ using ModularToolManagerPlugin.Models; namespace ModularToolManager.Services.Ui; + +/// +/// Service to get the matching view model for a given setting model +/// internal class PluginSettingViewModelService { + /// + /// Get the view model based on the provided setting model + /// + /// The setting model to get the view model for + /// A matching view model or null if nothing was found public IPluginSettingModel? GetViewModel(SettingModel settingModel) { return settingModel.Type switch diff --git a/src/ModularToolManager/ViewModels/BoolPluginSettingViewModel.cs b/src/ModularToolManager/ViewModels/BoolPluginSettingViewModel.cs index 9322440d..7e10c41d 100644 --- a/src/ModularToolManager/ViewModels/BoolPluginSettingViewModel.cs +++ b/src/ModularToolManager/ViewModels/BoolPluginSettingViewModel.cs @@ -27,6 +27,7 @@ public override SettingModel GetSettingsModel() return storedModel; } + /// public override void UpdateValue(object? newData) { if (newData is bool) diff --git a/src/ModularToolManager/ViewModels/FloatPluginSettingViewModel.cs b/src/ModularToolManager/ViewModels/FloatPluginSettingViewModel.cs index 3866b26f..f072901f 100644 --- a/src/ModularToolManager/ViewModels/FloatPluginSettingViewModel.cs +++ b/src/ModularToolManager/ViewModels/FloatPluginSettingViewModel.cs @@ -33,6 +33,8 @@ public override SettingModel GetSettingsModel() return storedModel; } + /// + public override void UpdateValue(object? newData) { if (newData is float) diff --git a/src/ModularToolManager/ViewModels/IntPluginSettingViewModel.cs b/src/ModularToolManager/ViewModels/IntPluginSettingViewModel.cs index cf7bab46..16cf878f 100644 --- a/src/ModularToolManager/ViewModels/IntPluginSettingViewModel.cs +++ b/src/ModularToolManager/ViewModels/IntPluginSettingViewModel.cs @@ -32,6 +32,7 @@ public override SettingModel GetSettingsModel() return storedModel; } + /// public override void UpdateValue(object? newData) { if (newData is int) diff --git a/src/ModularToolManager/ViewModels/Settings/IPluginSettingModel.cs b/src/ModularToolManager/ViewModels/Settings/IPluginSettingModel.cs index d3a4e19d..ef4752ce 100644 --- a/src/ModularToolManager/ViewModels/Settings/IPluginSettingModel.cs +++ b/src/ModularToolManager/ViewModels/Settings/IPluginSettingModel.cs @@ -7,6 +7,10 @@ namespace ModularToolManager.ViewModels.Settings; /// internal interface IPluginSettingModel { + /// + /// Update the internal value from the outside + /// + /// The new data to set void UpdateValue(object? newData); /// From 7eeaaefc8b377470625556a21accc858c3302f0e Mon Sep 17 00:00:00 2001 From: XanatosX <10531466+XanatosX@users.noreply.github.com> Date: Sun, 29 Jan 2023 22:03:24 +0100 Subject: [PATCH 10/12] Add missing summary block --- .../ViewModels/StringPluginSettingViewModel.cs | 1 + 1 file changed, 1 insertion(+) diff --git a/src/ModularToolManager/ViewModels/StringPluginSettingViewModel.cs b/src/ModularToolManager/ViewModels/StringPluginSettingViewModel.cs index 99fe7d70..9afa3081 100644 --- a/src/ModularToolManager/ViewModels/StringPluginSettingViewModel.cs +++ b/src/ModularToolManager/ViewModels/StringPluginSettingViewModel.cs @@ -27,6 +27,7 @@ public override SettingModel GetSettingsModel() return storedModel; } + /// public override void UpdateValue(object? newData) { if (newData is string) From 1ca3e33ec2425a858862644b0228c67abd7a0bbb Mon Sep 17 00:00:00 2001 From: XanatosX <10531466+XanatosX@users.noreply.github.com> Date: Sun, 29 Jan 2023 22:05:07 +0100 Subject: [PATCH 11/12] Add missing summary blocks --- .../ModelDependencyInjection.cs | 26 ++++++++++++++++++- 1 file changed, 25 insertions(+), 1 deletion(-) diff --git a/src/ModularToolManagerModel/DependencyInjection/ModelDependencyInjection.cs b/src/ModularToolManagerModel/DependencyInjection/ModelDependencyInjection.cs index 4e8e8d1a..3e01588c 100644 --- a/src/ModularToolManagerModel/DependencyInjection/ModelDependencyInjection.cs +++ b/src/ModularToolManagerModel/DependencyInjection/ModelDependencyInjection.cs @@ -10,8 +10,17 @@ using System.Text.Json.Serialization; namespace ModularToolManagerModel.DependencyInjection; + +/// +/// Static extension method class to add dependencies from the model +/// public static class ModelDependencyInjection { + /// + /// Add all the dependencies for the model itself + /// + /// The collection to add the dependencies to + /// The collection with the additional dependencies public static IServiceCollection AddModelDependencies(this IServiceCollection collection) { return collection.AddSingleton() @@ -22,16 +31,31 @@ public static IServiceCollection AddModelDependencies(this IServiceCollection co .AddJsonConverters(); } + /// + /// Add all additional dependencies for the model + /// + /// The collection to add the dependencies to + /// The collection with the additional dependencies public static IServiceCollection AddAdditionalDependencies(this IServiceCollection collection) { return collection.AddSingleton(); } - public static IServiceCollection AddJsonConverters(this IServiceCollection collection) + /// + /// Add all the json serializer converters to the dependencies + /// + /// The collection to add the dependencies to + /// The collection with the additional dependencies + private static IServiceCollection AddJsonConverters(this IServiceCollection collection) { return collection.AddSingleton, SettingModelJsonConverter>(); } + /// + /// Add all possible dependencies + /// + /// The collection to add the dependencies to + /// The collection with the additional dependencies public static IServiceCollection AddAllModelDepdencies(this IServiceCollection collection) { return collection.AddModelDependencies() From 574613fd202a9818cac70bece457afa91f3db3d7 Mon Sep 17 00:00:00 2001 From: XanatosX <10531466+XanatosX@users.noreply.github.com> Date: Sun, 29 Jan 2023 22:05:36 +0100 Subject: [PATCH 12/12] Fix spelling mistake --- .../DependencyInjection/DependencyInjectionExtension.cs | 2 +- .../DependencyInjection/ModelDependencyInjection.cs | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/ModularToolManager/DependencyInjection/DependencyInjectionExtension.cs b/src/ModularToolManager/DependencyInjection/DependencyInjectionExtension.cs index ffe40741..67e487bd 100644 --- a/src/ModularToolManager/DependencyInjection/DependencyInjectionExtension.cs +++ b/src/ModularToolManager/DependencyInjection/DependencyInjectionExtension.cs @@ -81,7 +81,7 @@ public static IServiceCollection AddViews(this IServiceCollection collection) /// The extended collection public static IServiceCollection AddServices(this IServiceCollection collection) { - return collection.AddAllModelDepdencies() + return collection.AddAllModelDependencies() .AddSingleton() .AddSingleton() .AddSingleton() diff --git a/src/ModularToolManagerModel/DependencyInjection/ModelDependencyInjection.cs b/src/ModularToolManagerModel/DependencyInjection/ModelDependencyInjection.cs index 3e01588c..2b08d6bf 100644 --- a/src/ModularToolManagerModel/DependencyInjection/ModelDependencyInjection.cs +++ b/src/ModularToolManagerModel/DependencyInjection/ModelDependencyInjection.cs @@ -56,7 +56,7 @@ private static IServiceCollection AddJsonConverters(this IServiceCollection coll /// /// The collection to add the dependencies to /// The collection with the additional dependencies - public static IServiceCollection AddAllModelDepdencies(this IServiceCollection collection) + public static IServiceCollection AddAllModelDependencies(this IServiceCollection collection) { return collection.AddModelDependencies() .AddAdditionalDependencies();