Plugins - Simplified and streamlined the way plugins provide VMs

Plugins - Added dependency injection to all plugin VMs
Plugin settings - Allow injecting plugin settings into any class defined in the plugin assembly
This commit is contained in:
Robert committed 2020-08-21 11:14:53 +02:00
1 parent aa3c3d6b95
commit c71faba2c9
29 files changed
+349 -165

No files matched your search

@@ -1,7 +1,9 @@
using System.Linq;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using Artemis.Core.Plugins.Abstract;
using Artemis.Core.Plugins.Abstract.ViewModels;
using Artemis.Core.Plugins.Modules;
using Artemis.UI.Ninject.Factories;
using Ninject;
using Ninject.Parameters;
@@ -39,9 +41,9 @@ namespace Artemis.UI.Screens.Module
Items.Add(profileEditor);
}
var moduleTabs = Module.GetModuleTabs();
if (moduleTabs != null)
if (Module.ModuleTabs != null)
{
var moduleTabs = new List<ModuleTab>(Module.ModuleTabs);
foreach (var moduleTab in moduleTabs.Where(m => m != null))
{
var module = new ConstructorArgument("module", Module);
@@ -106,7 +106,7 @@
VerticalAlignment="Center"
HorizontalAlignment="Right"
Command="{s:Action OpenBrushSettings}"
Visibility="{Binding LayerPropertyGroupViewModel.LayerPropertyGroup.LayerBrush.HasConfigurationViewModel, Converter={x:Static s:BoolToVisibilityConverter.Instance}, Mode=OneWay}">
Visibility="{Binding LayerPropertyGroupViewModel.LayerPropertyGroup.LayerBrush.ConfigurationDialog, Converter={StaticResource NullToVisibilityConverter}}">
<materialDesign:PackIcon Kind="Settings" Height="16" Width="16" />
</Button>
</Grid>
@@ -184,7 +184,7 @@
Height="24"
VerticalAlignment="Center"
Command="{s:Action OpenEffectSettings}"
Visibility="{Binding LayerPropertyGroupViewModel.LayerPropertyGroup.LayerEffect.HasConfigurationViewModel, Converter={x:Static s:BoolToVisibilityConverter.Instance}, Mode=OneWay}">
Visibility="{Binding LayerPropertyGroupViewModel.LayerPropertyGroup.LayerEffect.ConfigurationDialog, Converter={StaticResource NullToVisibilityConverter}}">
<materialDesign:PackIcon Kind="Settings" Height="16" Width="16" />
</Button>
<Button Style="{StaticResource MaterialDesignIconButton}"
@@ -1,9 +1,12 @@
using System;
using System.Collections.Generic;
using Artemis.Core.Plugins.Abstract.ViewModels;
using Artemis.Core.Services.Interfaces;
using Artemis.UI.Screens.ProfileEditor.Dialogs;
using Artemis.UI.Screens.ProfileEditor.LayerProperties.Abstract;
using Artemis.UI.Shared.Services.Interfaces;
using Ninject;
using Ninject.Parameters;
using Stylet;
namespace Artemis.UI.Screens.ProfileEditor.LayerProperties.Tree
@@ -12,16 +15,22 @@ namespace Artemis.UI.Screens.ProfileEditor.LayerProperties.Tree
{
private readonly IDialogService _dialogService;
private readonly IWindowManager _windowManager;
private readonly IKernel _kernel;
private readonly IRenderElementService _renderElementService;
private readonly IProfileEditorService _profileEditorService;
public TreePropertyGroupViewModel(LayerPropertyBaseViewModel layerPropertyBaseViewModel,
IProfileEditorService profileEditorService, IRenderElementService renderElementService, IDialogService dialogService, IWindowManager windowManager)
IProfileEditorService profileEditorService,
IRenderElementService renderElementService,
IDialogService dialogService,
IWindowManager windowManager,
IKernel kernel)
{
_profileEditorService = profileEditorService;
_renderElementService = renderElementService;
_dialogService = dialogService;
_windowManager = windowManager;
_kernel = kernel;
LayerPropertyGroupViewModel = (LayerPropertyGroupViewModel) layerPropertyBaseViewModel;
}
@@ -29,11 +38,15 @@ namespace Artemis.UI.Screens.ProfileEditor.LayerProperties.Tree
public void OpenBrushSettings()
{
var configurationViewModel = LayerPropertyGroupViewModel.LayerPropertyGroup.LayerBrush.ConfigurationDialog;
if (configurationViewModel == null)
return;
try
{
var configurationViewModel = LayerPropertyGroupViewModel.LayerPropertyGroup.LayerBrush.GetConfigurationViewModel();
if (configurationViewModel != null)
_windowManager.ShowDialog(new LayerBrushSettingsWindowViewModel(configurationViewModel));
var layerBrush = new ConstructorArgument("layerBrush", LayerPropertyGroupViewModel.LayerPropertyGroup.LayerBrush);
var viewModel = (BrushConfigurationViewModel) _kernel.Get(configurationViewModel.Type, layerBrush);
_windowManager.ShowDialog(new LayerBrushSettingsWindowViewModel(viewModel));
}
catch (Exception e)
{
@@ -44,11 +57,15 @@ namespace Artemis.UI.Screens.ProfileEditor.LayerProperties.Tree
public void OpenEffectSettings()
{
var configurationViewModel = LayerPropertyGroupViewModel.LayerPropertyGroup.LayerEffect.ConfigurationDialog;
if (configurationViewModel == null)
return;
try
{
var configurationViewModel = LayerPropertyGroupViewModel.LayerPropertyGroup.LayerEffect.GetConfigurationViewModel();
if (configurationViewModel != null)
_windowManager.ShowDialog(new LayerEffectSettingsWindowViewModel(configurationViewModel));
var layerEffect = new ConstructorArgument("layerEffect", LayerPropertyGroupViewModel.LayerPropertyGroup.LayerEffect);
var viewModel = (EffectConfigurationViewModel) _kernel.Get(configurationViewModel.Type, layerEffect);
_windowManager.ShowDialog(new LayerEffectSettingsWindowViewModel(viewModel));
}
catch (Exception e)
{
@@ -3,10 +3,13 @@ using System.Diagnostics;
using System.IO;
using System.Threading.Tasks;
using Artemis.Core.Plugins.Abstract;
using Artemis.Core.Plugins.Abstract.ViewModels;
using Artemis.Core.Plugins.Models;
using Artemis.Core.Services.Interfaces;
using Artemis.UI.Shared.Services.Interfaces;
using MaterialDesignThemes.Wpf;
using Ninject;
using Ninject.Parameters;
using Stylet;
namespace Artemis.UI.Screens.Settings.Tabs.Plugins
@@ -16,17 +19,23 @@ namespace Artemis.UI.Screens.Settings.Tabs.Plugins
private readonly IDialogService _dialogService;
private readonly IPluginService _pluginService;
private readonly ISnackbarMessageQueue _snackbarMessageQueue;
private readonly IKernel _kernel;
private readonly IWindowManager _windowManager;
private Plugin _plugin;
private PluginInfo _pluginInfo;
private bool _enabling;
public PluginSettingsViewModel(Plugin plugin, IWindowManager windowManager, IDialogService dialogService, IPluginService pluginService,
public PluginSettingsViewModel(Plugin plugin,
IKernel kernel,
IWindowManager windowManager,
IDialogService dialogService,
IPluginService pluginService,
ISnackbarMessageQueue snackbarMessageQueue)
{
Plugin = plugin;
PluginInfo = plugin.PluginInfo;
_kernel = kernel;
_windowManager = windowManager;
_dialogService = dialogService;
_pluginService = pluginService;
@@ -53,7 +62,7 @@ namespace Artemis.UI.Screens.Settings.Tabs.Plugins
public PackIconKind Icon => GetIconKind();
public string Type => Plugin.GetType().BaseType?.Name ?? Plugin.GetType().Name;
public bool CanOpenSettings => IsEnabled && Plugin.HasConfigurationViewModel;
public bool CanOpenSettings => IsEnabled && Plugin.ConfigurationDialog != null;
public bool DisplayLoadFailed => !Enabling && PluginInfo.LoadException != null;
public bool IsEnabled
@@ -64,11 +73,15 @@ namespace Artemis.UI.Screens.Settings.Tabs.Plugins
public void OpenSettings()
{
var configurationViewModel = Plugin.ConfigurationDialog;
if (configurationViewModel == null)
return;
try
{
var configurationViewModel = Plugin.GetConfigurationViewModel();
if (configurationViewModel != null)
_windowManager.ShowDialog(new PluginSettingsWindowViewModel(configurationViewModel, Icon));
var plugin = new ConstructorArgument("plugin", Plugin);
var viewModel = (PluginConfigurationViewModel) _kernel.Get(configurationViewModel.Type, plugin);
_windowManager.ShowDialog(new PluginSettingsWindowViewModel(viewModel, Icon));
}
catch (Exception e)
{