diff --git a/src/Artemis.UI.Shared/DataModelVisualization/Input/DataModelDynamicViewModel.cs b/src/Artemis.UI.Shared/DataModelVisualization/Input/DataModelDynamicViewModel.cs index 88f1a0933..dd5091d0c 100644 --- a/src/Artemis.UI.Shared/DataModelVisualization/Input/DataModelDynamicViewModel.cs +++ b/src/Artemis.UI.Shared/DataModelVisualization/Input/DataModelDynamicViewModel.cs @@ -29,7 +29,7 @@ namespace Artemis.UI.Shared.Input private bool _isEnabled = true; private string _placeholder = "Select a property"; - internal DataModelDynamicViewModel(Module module, ISettingsService settingsService, IDataModelUIService dataModelUIService) + public DataModelDynamicViewModel(Module module, ISettingsService settingsService, IDataModelUIService dataModelUIService) { _module = module; _dataModelUIService = dataModelUIService; diff --git a/src/Artemis.UI.Shared/DataModelVisualization/Input/DataModelStaticViewModel.cs b/src/Artemis.UI.Shared/DataModelVisualization/Input/DataModelStaticViewModel.cs index 11c993fc9..490b126c9 100644 --- a/src/Artemis.UI.Shared/DataModelVisualization/Input/DataModelStaticViewModel.cs +++ b/src/Artemis.UI.Shared/DataModelVisualization/Input/DataModelStaticViewModel.cs @@ -25,7 +25,7 @@ namespace Artemis.UI.Shared.Input private object _value; private bool _displaySwitchButton; - internal DataModelStaticViewModel(Type targetType, DataModelPropertyAttribute targetDescription, IDataModelUIService dataModelUIService) + public DataModelStaticViewModel(Type targetType, DataModelPropertyAttribute targetDescription, IDataModelUIService dataModelUIService) { _dataModelUIService = dataModelUIService; _rootView = Application.Current.Windows.OfType().SingleOrDefault(x => x.IsActive); diff --git a/src/Artemis.UI.Shared/Ninject/Factories/ISharedVMFactory.cs b/src/Artemis.UI.Shared/Ninject/Factories/ISharedVMFactory.cs new file mode 100644 index 000000000..d15414099 --- /dev/null +++ b/src/Artemis.UI.Shared/Ninject/Factories/ISharedVMFactory.cs @@ -0,0 +1,17 @@ +using System; +using Artemis.Core.DataModelExpansions; +using Artemis.Core.Modules; +using Artemis.UI.Shared.Input; + +namespace Artemis.UI.Shared.Ninject.Factories +{ + public interface ISharedVmFactory + { + } + + public interface IDataModelVmFactory : ISharedVmFactory + { + DataModelDynamicViewModel DataModelDynamicViewModel(Module module); + DataModelStaticViewModel DataModelStaticViewModel(Type targetType, DataModelPropertyAttribute targetDescription); + } +} \ No newline at end of file diff --git a/src/Artemis.UI.Shared/Ninject/SharedUIModule.cs b/src/Artemis.UI.Shared/Ninject/SharedUIModule.cs index 15949fe33..7482e6347 100644 --- a/src/Artemis.UI.Shared/Ninject/SharedUIModule.cs +++ b/src/Artemis.UI.Shared/Ninject/SharedUIModule.cs @@ -1,4 +1,5 @@ using System; +using Artemis.UI.Shared.Ninject.Factories; using Artemis.UI.Shared.Services; using MaterialDesignThemes.Wpf; using Ninject.Extensions.Conventions; @@ -29,6 +30,15 @@ namespace Artemis.UI.Shared.Ninject }); Kernel.Bind().ToConstant(new SnackbarMessageQueue(TimeSpan.FromSeconds(5))).InSingletonScope(); + + // Bind UI factories + Kernel.Bind(x => + { + x.FromThisAssembly() + .SelectAllInterfaces() + .InheritedFrom() + .BindToFactory(); + }); } } } \ No newline at end of file diff --git a/src/Artemis.UI.Shared/Services/DataModelUIService.cs b/src/Artemis.UI.Shared/Services/DataModelUIService.cs index 55eda84b2..bfcdb4da4 100644 --- a/src/Artemis.UI.Shared/Services/DataModelUIService.cs +++ b/src/Artemis.UI.Shared/Services/DataModelUIService.cs @@ -7,6 +7,7 @@ using Artemis.Core.Modules; using Artemis.Core.Services; using Artemis.UI.Shared.DefaultTypes.DataModel.Display; using Artemis.UI.Shared.Input; +using Artemis.UI.Shared.Ninject.Factories; using Ninject; using Ninject.Parameters; @@ -15,13 +16,15 @@ namespace Artemis.UI.Shared.Services internal class DataModelUIService : IDataModelUIService { private readonly IDataModelService _dataModelService; + private readonly IDataModelVmFactory _dataModelVmFactory; private readonly IKernel _kernel; private readonly List _registeredDataModelDisplays; private readonly List _registeredDataModelEditors; - public DataModelUIService(IDataModelService dataModelService, IKernel kernel) + public DataModelUIService(IDataModelService dataModelService, IDataModelVmFactory dataModelVmFactory, IKernel kernel) { _dataModelService = dataModelService; + _dataModelVmFactory = dataModelVmFactory; _kernel = kernel; _registeredDataModelEditors = new List(); _registeredDataModelDisplays = new List(); @@ -219,12 +222,12 @@ namespace Artemis.UI.Shared.Services public DataModelDynamicViewModel GetDynamicSelectionViewModel(Module module) { - return _kernel.Get(new ConstructorArgument("module", module)); + return _dataModelVmFactory.DataModelDynamicViewModel(module); } public DataModelStaticViewModel GetStaticInputViewModel(Type targetType, DataModelPropertyAttribute targetDescription) { - return _kernel.Get(new ConstructorArgument("targetType", targetType), new ConstructorArgument("targetDescription", targetDescription)); + return _dataModelVmFactory.DataModelStaticViewModel(targetType, targetDescription); } private DataModelInputViewModel InstantiateDataModelInputViewModel(DataModelVisualizationRegistration registration, DataModelPropertyAttribute description, object initialValue) diff --git a/src/Artemis.UI/Screens/Settings/Tabs/Plugins/PluginFeatureView.xaml b/src/Artemis.UI/Screens/Settings/Tabs/Plugins/PluginFeatureView.xaml index 8ef815d40..9e88a2346 100644 --- a/src/Artemis.UI/Screens/Settings/Tabs/Plugins/PluginFeatureView.xaml +++ b/src/Artemis.UI/Screens/Settings/Tabs/Plugins/PluginFeatureView.xaml @@ -6,9 +6,13 @@ xmlns:local="clr-namespace:Artemis.UI.Screens.Settings.Tabs.Plugins" xmlns:materialDesign="http://materialdesigninxaml.net/winfx/xaml/themes" xmlns:s="https://github.com/canton7/Stylet" + xmlns:converters="clr-namespace:Artemis.UI.Converters" mc:Ignorable="d" d:DesignHeight="450" d:DesignWidth="800" d:DataContext="{d:DesignInstance local:PluginFeatureViewModel}"> + + + @@ -17,9 +21,26 @@ - + + + + - + - diff --git a/src/Artemis.UI/Screens/Settings/Tabs/Plugins/PluginFeatureViewModel.cs b/src/Artemis.UI/Screens/Settings/Tabs/Plugins/PluginFeatureViewModel.cs index d0fbc81ad..11313831d 100644 --- a/src/Artemis.UI/Screens/Settings/Tabs/Plugins/PluginFeatureViewModel.cs +++ b/src/Artemis.UI/Screens/Settings/Tabs/Plugins/PluginFeatureViewModel.cs @@ -67,6 +67,14 @@ namespace Artemis.UI.Screens.Settings.Tabs.Plugins } } + public void ViewLoadException() + { + if (LoadException == null) + return; + + _dialogService.ShowExceptionDialog("Feature failed to enable", Feature.LoadException); + } + protected override void OnInitialActivate() { base.OnInitialActivate(); @@ -148,7 +156,7 @@ namespace Artemis.UI.Screens.Settings.Tabs.Plugins { if (e.PluginFeature != Feature) return; Enabling = false; - + NotifyOfPropertyChange(nameof(IsEnabled)); NotifyOfPropertyChange(nameof(LoadException)); } diff --git a/src/Artemis.UI/Screens/Settings/Tabs/Plugins/PluginSettingsView.xaml b/src/Artemis.UI/Screens/Settings/Tabs/Plugins/PluginSettingsView.xaml index 8a6d5954e..2ce5c47b2 100644 --- a/src/Artemis.UI/Screens/Settings/Tabs/Plugins/PluginSettingsView.xaml +++ b/src/Artemis.UI/Screens/Settings/Tabs/Plugins/PluginSettingsView.xaml @@ -102,7 +102,6 @@ diff --git a/src/Artemis.UI/Screens/Sidebar/SidebarView.xaml b/src/Artemis.UI/Screens/Sidebar/SidebarView.xaml index 9da80b24c..d2d3be984 100644 --- a/src/Artemis.UI/Screens/Sidebar/SidebarView.xaml +++ b/src/Artemis.UI/Screens/Sidebar/SidebarView.xaml @@ -25,6 +25,7 @@ VerticalAlignment="Top" Height="120" />