mirror of
https://github.com/Artemis-RGB/Artemis
synced 2025-12-13 05:48:35 +00:00
Added back layer renaming/deleting
Cleaned up VM factories Surface editor use theme colors
This commit is contained in:
parent
8795be2cde
commit
f91ea0f992
@ -192,10 +192,7 @@
|
||||
<Compile Include="Exceptions\ArtemisCoreException.cs" />
|
||||
<Compile Include="Extensions\RgbColorExtensions.cs" />
|
||||
<Compile Include="Extensions\RgbRectangleExtensions.cs" />
|
||||
<Compile Include="Ninject\Factories\IArtemisUIFactory.cs" />
|
||||
<Compile Include="Ninject\Factories\IDeviceSettingsViewModelFactory.cs" />
|
||||
<Compile Include="Ninject\Factories\IModuleViewModelFactory.cs" />
|
||||
<Compile Include="Ninject\Factories\IProfileEditorViewModelFactory.cs" />
|
||||
<Compile Include="Ninject\Factories\IViewModelFactory.cs" />
|
||||
<Compile Include="Ninject\UIModule.cs" />
|
||||
<Compile Include="Utilities\SizeObserver.cs" />
|
||||
<Compile Include="Properties\Resources.Designer.cs">
|
||||
|
||||
@ -1,6 +0,0 @@
|
||||
namespace Artemis.UI.Ninject.Factories
|
||||
{
|
||||
public interface IArtemisUIFactory
|
||||
{
|
||||
}
|
||||
}
|
||||
@ -1,10 +0,0 @@
|
||||
using Artemis.Core.Models.Surface;
|
||||
using Artemis.UI.Screens.Settings.Tabs.Devices;
|
||||
|
||||
namespace Artemis.UI.Ninject.Factories
|
||||
{
|
||||
public interface IDeviceSettingsViewModelFactory : IArtemisUIFactory
|
||||
{
|
||||
DeviceSettingsViewModel Create(ArtemisDevice device);
|
||||
}
|
||||
}
|
||||
@ -1,10 +0,0 @@
|
||||
using Artemis.Core.Plugins.Abstract;
|
||||
using Artemis.UI.Screens.Module;
|
||||
|
||||
namespace Artemis.UI.Ninject.Factories
|
||||
{
|
||||
public interface IModuleViewModelFactory : IArtemisUIFactory
|
||||
{
|
||||
ModuleRootViewModel Create(Module module);
|
||||
}
|
||||
}
|
||||
@ -1,10 +0,0 @@
|
||||
using Artemis.Core.Plugins.Abstract;
|
||||
using Artemis.UI.Screens.Module.ProfileEditor;
|
||||
|
||||
namespace Artemis.UI.Ninject.Factories
|
||||
{
|
||||
public interface IProfileEditorViewModelFactory : IArtemisUIFactory
|
||||
{
|
||||
ProfileEditorViewModel Create(ProfileModule module);
|
||||
}
|
||||
}
|
||||
40
src/Artemis.UI/Ninject/Factories/IViewModelFactory.cs
Normal file
40
src/Artemis.UI/Ninject/Factories/IViewModelFactory.cs
Normal file
@ -0,0 +1,40 @@
|
||||
using Artemis.Core.Models.Profile.Abstract;
|
||||
using Artemis.Core.Models.Surface;
|
||||
using Artemis.Core.Plugins.Abstract;
|
||||
using Artemis.UI.Screens.Module;
|
||||
using Artemis.UI.Screens.Module.ProfileEditor;
|
||||
using Artemis.UI.Screens.Module.ProfileEditor.ProfileTree.TreeItem;
|
||||
using Artemis.UI.Screens.Settings.Tabs.Devices;
|
||||
|
||||
namespace Artemis.UI.Ninject.Factories
|
||||
{
|
||||
public interface IViewModelFactory
|
||||
{
|
||||
}
|
||||
|
||||
public interface IModuleViewModelFactory : IViewModelFactory
|
||||
{
|
||||
ModuleRootViewModel Create(Module module);
|
||||
}
|
||||
|
||||
public interface IDeviceSettingsViewModelFactory : IViewModelFactory
|
||||
{
|
||||
DeviceSettingsViewModel Create(ArtemisDevice device);
|
||||
}
|
||||
|
||||
public interface IProfileEditorViewModelFactory : IViewModelFactory
|
||||
{
|
||||
ProfileEditorViewModel Create(ProfileModule module);
|
||||
}
|
||||
|
||||
public interface IFolderViewModelFactory : IViewModelFactory
|
||||
{
|
||||
FolderViewModel Create(ProfileElement folder);
|
||||
FolderViewModel Create(TreeItemViewModel parent, ProfileElement folder);
|
||||
}
|
||||
|
||||
public interface ILayerViewModelFactory : IViewModelFactory
|
||||
{
|
||||
LayerViewModel Create(TreeItemViewModel parent, ProfileElement folder);
|
||||
}
|
||||
}
|
||||
@ -43,15 +43,11 @@ namespace Artemis.UI.Ninject
|
||||
Kernel.Bind(x =>
|
||||
{
|
||||
x.FromThisAssembly()
|
||||
.SelectAllClasses()
|
||||
.InheritedFrom<IArtemisUIFactory>()
|
||||
.SelectAllInterfaces()
|
||||
.InheritedFrom<IViewModelFactory>()
|
||||
.BindToFactory();
|
||||
});
|
||||
|
||||
Kernel.Bind<IDeviceSettingsViewModelFactory>().ToFactory();
|
||||
Kernel.Bind<IModuleViewModelFactory>().ToFactory();
|
||||
Kernel.Bind<IProfileEditorViewModelFactory>().ToFactory();
|
||||
|
||||
// Bind profile editor VMs
|
||||
Kernel.Bind(x =>
|
||||
{
|
||||
|
||||
@ -2,6 +2,7 @@
|
||||
using System.Linq;
|
||||
using System.Windows;
|
||||
using Artemis.Core.Models.Profile;
|
||||
using Artemis.UI.Ninject.Factories;
|
||||
using Artemis.UI.Screens.Module.ProfileEditor.ProfileTree.TreeItem;
|
||||
using Artemis.UI.Services.Interfaces;
|
||||
using GongSolutions.Wpf.DragDrop;
|
||||
@ -11,11 +12,13 @@ namespace Artemis.UI.Screens.Module.ProfileEditor.ProfileTree
|
||||
public class ProfileTreeViewModel : ProfileEditorPanelViewModel, IDropTarget
|
||||
{
|
||||
private readonly IProfileEditorService _profileEditorService;
|
||||
private readonly IFolderViewModelFactory _folderViewModelFactory;
|
||||
private TreeItemViewModel _selectedTreeItem;
|
||||
|
||||
public ProfileTreeViewModel(IProfileEditorService profileEditorService)
|
||||
public ProfileTreeViewModel(IProfileEditorService profileEditorService, IFolderViewModelFactory folderViewModelFactory)
|
||||
{
|
||||
_profileEditorService = profileEditorService;
|
||||
_folderViewModelFactory = folderViewModelFactory;
|
||||
|
||||
CreateRootFolderViewModel();
|
||||
_profileEditorService.SelectedProfileChanged += OnSelectedProfileChanged;
|
||||
@ -96,7 +99,7 @@ namespace Artemis.UI.Screens.Module.ProfileEditor.ProfileTree
|
||||
return;
|
||||
}
|
||||
|
||||
RootFolder = new FolderViewModel(null, folder, _profileEditorService);
|
||||
RootFolder = _folderViewModelFactory.Create(folder);
|
||||
}
|
||||
|
||||
private static DragDropType GetDragDropType(IDropInfo dropInfo)
|
||||
|
||||
@ -1,11 +1,28 @@
|
||||
using Artemis.Core.Models.Profile.Abstract;
|
||||
using Artemis.UI.Ninject.Factories;
|
||||
using Artemis.UI.Services.Interfaces;
|
||||
|
||||
namespace Artemis.UI.Screens.Module.ProfileEditor.ProfileTree.TreeItem
|
||||
{
|
||||
public class FolderViewModel : TreeItemViewModel
|
||||
{
|
||||
public FolderViewModel(TreeItemViewModel parent, ProfileElement folder, IProfileEditorService profileEditorService) : base(parent, folder, profileEditorService)
|
||||
// I hate this about DI, oh well
|
||||
public FolderViewModel(ProfileElement folder,
|
||||
IProfileEditorService profileEditorService,
|
||||
IDialogService dialogService,
|
||||
IFolderViewModelFactory folderViewModelFactory,
|
||||
ILayerViewModelFactory layerViewModelFactory) :
|
||||
base(null, folder, profileEditorService, dialogService, folderViewModelFactory, layerViewModelFactory)
|
||||
{
|
||||
}
|
||||
|
||||
public FolderViewModel(TreeItemViewModel parent,
|
||||
ProfileElement folder,
|
||||
IProfileEditorService profileEditorService,
|
||||
IDialogService dialogService,
|
||||
IFolderViewModelFactory folderViewModelFactory,
|
||||
ILayerViewModelFactory layerViewModelFactory) :
|
||||
base(parent, folder, profileEditorService, dialogService, folderViewModelFactory, layerViewModelFactory)
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
@ -1,11 +1,18 @@
|
||||
using Artemis.Core.Models.Profile.Abstract;
|
||||
using Artemis.UI.Ninject.Factories;
|
||||
using Artemis.UI.Services.Interfaces;
|
||||
|
||||
namespace Artemis.UI.Screens.Module.ProfileEditor.ProfileTree.TreeItem
|
||||
{
|
||||
public class LayerViewModel : TreeItemViewModel
|
||||
{
|
||||
public LayerViewModel(TreeItemViewModel parent, ProfileElement layer, IProfileEditorService profileEditorService) : base(parent, layer, profileEditorService)
|
||||
public LayerViewModel(TreeItemViewModel parent,
|
||||
ProfileElement folder,
|
||||
IProfileEditorService profileEditorService,
|
||||
IDialogService dialogService,
|
||||
IFolderViewModelFactory folderViewModelFactory,
|
||||
ILayerViewModelFactory layerViewModelFactory) :
|
||||
base(parent, folder, profileEditorService, dialogService, folderViewModelFactory, layerViewModelFactory)
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
@ -4,6 +4,8 @@ using System.Threading.Tasks;
|
||||
using Artemis.Core.Models.Profile;
|
||||
using Artemis.Core.Models.Profile.Abstract;
|
||||
using Artemis.UI.Exceptions;
|
||||
using Artemis.UI.Ninject.Factories;
|
||||
using Artemis.UI.Screens.Module.ProfileEditor.Dialogs;
|
||||
using Artemis.UI.Services.Interfaces;
|
||||
using Stylet;
|
||||
|
||||
@ -11,11 +13,25 @@ namespace Artemis.UI.Screens.Module.ProfileEditor.ProfileTree.TreeItem
|
||||
{
|
||||
public abstract class TreeItemViewModel : PropertyChangedBase
|
||||
{
|
||||
protected TreeItemViewModel(TreeItemViewModel parent, ProfileElement profileElement, IProfileEditorService profileEditorService)
|
||||
private readonly IProfileEditorService _profileEditorService;
|
||||
private readonly IDialogService _dialogService;
|
||||
private readonly IFolderViewModelFactory _folderViewModelFactory;
|
||||
private readonly ILayerViewModelFactory _layerViewModelFactory;
|
||||
|
||||
protected TreeItemViewModel(TreeItemViewModel parent,
|
||||
ProfileElement profileElement,
|
||||
IProfileEditorService profileEditorService,
|
||||
IDialogService dialogService,
|
||||
IFolderViewModelFactory folderViewModelFactory,
|
||||
ILayerViewModelFactory layerViewModelFactory)
|
||||
{
|
||||
_profileEditorService = profileEditorService;
|
||||
_dialogService = dialogService;
|
||||
_folderViewModelFactory = folderViewModelFactory;
|
||||
_layerViewModelFactory = layerViewModelFactory;
|
||||
|
||||
Parent = parent;
|
||||
ProfileElement = profileElement;
|
||||
ProfileEditorService = profileEditorService;
|
||||
|
||||
Children = new BindableCollection<TreeItemViewModel>();
|
||||
UpdateProfileElements();
|
||||
@ -23,7 +39,6 @@ namespace Artemis.UI.Screens.Module.ProfileEditor.ProfileTree.TreeItem
|
||||
|
||||
public TreeItemViewModel Parent { get; set; }
|
||||
public ProfileElement ProfileElement { get; set; }
|
||||
public IProfileEditorService ProfileEditorService { get; set; }
|
||||
|
||||
public abstract bool SupportsChildren { get; }
|
||||
public BindableCollection<TreeItemViewModel> Children { get; set; }
|
||||
@ -95,7 +110,7 @@ namespace Artemis.UI.Screens.Module.ProfileEditor.ProfileTree.TreeItem
|
||||
|
||||
ProfileElement.AddChild(new Folder(ProfileElement.Profile, ProfileElement, "New folder"));
|
||||
UpdateProfileElements();
|
||||
ProfileEditorService.UpdateSelectedProfile();
|
||||
_profileEditorService.UpdateSelectedProfile();
|
||||
}
|
||||
|
||||
public void AddLayer()
|
||||
@ -105,40 +120,40 @@ namespace Artemis.UI.Screens.Module.ProfileEditor.ProfileTree.TreeItem
|
||||
|
||||
ProfileElement.AddChild(new Layer(ProfileElement.Profile, ProfileElement, "New layer"));
|
||||
UpdateProfileElements();
|
||||
ProfileEditorService.UpdateSelectedProfile();
|
||||
_profileEditorService.UpdateSelectedProfile();
|
||||
}
|
||||
|
||||
// ReSharper disable once UnusedMember.Global - Called from view
|
||||
public async Task RenameElement()
|
||||
{
|
||||
// var result = await ProfileEditorService.DialogService.ShowDialog<ProfileElementRenameViewModel>(
|
||||
// new Dictionary<string, object> {{"profileElement", ProfileElement}}
|
||||
// );
|
||||
// if (result is string newName)
|
||||
// {
|
||||
// ProfileElement.Name = newName;
|
||||
// ProfileEditorService.UpdateSelectedProfile();
|
||||
// }
|
||||
var result = await _dialogService.ShowDialog<ProfileElementRenameViewModel>(
|
||||
new Dictionary<string, object> {{"profileElement", ProfileElement}}
|
||||
);
|
||||
if (result is string newName)
|
||||
{
|
||||
ProfileElement.Name = newName;
|
||||
_profileEditorService.UpdateSelectedProfile();
|
||||
}
|
||||
}
|
||||
|
||||
// ReSharper disable once UnusedMember.Global - Called from view
|
||||
public async Task DeleteElement()
|
||||
{
|
||||
// var result = await ProfileEditorService.DialogService.ShowConfirmDialog(
|
||||
// "Delete profile element",
|
||||
// "Are you sure you want to delete this element? This cannot be undone."
|
||||
// );
|
||||
//
|
||||
// if (!result)
|
||||
// return;
|
||||
//
|
||||
// // Farewell, cruel world
|
||||
// var parent = Parent;
|
||||
// ProfileElement.Parent.RemoveChild(ProfileElement);
|
||||
// parent.RemoveExistingElement(this);
|
||||
// parent.UpdateProfileElements();
|
||||
//
|
||||
// ProfileEditorService.UpdateSelectedProfile();
|
||||
var result = await _dialogService.ShowConfirmDialog(
|
||||
"Delete profile element",
|
||||
"Are you sure you want to delete this element? This cannot be undone."
|
||||
);
|
||||
|
||||
if (!result)
|
||||
return;
|
||||
|
||||
// Farewell, cruel world
|
||||
var parent = Parent;
|
||||
ProfileElement.Parent.RemoveChild(ProfileElement);
|
||||
parent.RemoveExistingElement(this);
|
||||
parent.UpdateProfileElements();
|
||||
|
||||
_profileEditorService.UpdateSelectedProfile();
|
||||
}
|
||||
|
||||
private void UpdateProfileElements()
|
||||
@ -161,13 +176,13 @@ namespace Artemis.UI.Screens.Module.ProfileEditor.ProfileTree.TreeItem
|
||||
{
|
||||
existing = Children.FirstOrDefault(p => p is FolderViewModel vm && vm.ProfileElement == folder);
|
||||
if (existing == null)
|
||||
Children.Add(new FolderViewModel(this, folder, ProfileEditorService));
|
||||
Children.Add(_folderViewModelFactory.Create((FolderViewModel) this, folder));
|
||||
}
|
||||
else if (profileElement is Layer layer)
|
||||
{
|
||||
existing = Children.FirstOrDefault(p => p is LayerViewModel vm && vm.ProfileElement == layer);
|
||||
if (existing == null)
|
||||
Children.Add(new LayerViewModel(this, layer, ProfileEditorService));
|
||||
Children.Add(_layerViewModelFactory.Create((FolderViewModel) this, layer));
|
||||
}
|
||||
|
||||
existing?.UpdateProfileElements();
|
||||
|
||||
@ -21,9 +21,9 @@
|
||||
</Grid.LayoutTransform>
|
||||
|
||||
<!-- Device image with fallback -->
|
||||
<Border Effect="{StaticResource MaterialDesignShadowDepth3}" VerticalAlignment="Top" HorizontalAlignment="Left" >
|
||||
<Image Source="{Binding Device.RgbDevice.DeviceInfo.Image, Converter={StaticResource NullToImageConverter}}"/>
|
||||
</Border>
|
||||
<Image VerticalAlignment="Top"
|
||||
HorizontalAlignment="Left"
|
||||
Source="{Binding Device.RgbDevice.DeviceInfo.Image, Converter={StaticResource NullToImageConverter}}" />
|
||||
|
||||
<Rectangle Fill="{DynamicResource ControlBackgroundBrush}"
|
||||
Stroke="{DynamicResource ControlBorderBrush}"
|
||||
|
||||
@ -57,7 +57,7 @@
|
||||
<Grid.Background>
|
||||
<VisualBrush TileMode="Tile" Stretch="Uniform" Viewport="{Binding PanZoomViewModel.BackgroundViewport}" ViewportUnits="Absolute">
|
||||
<VisualBrush.Visual>
|
||||
<Grid Width="20" Height="20">
|
||||
<Grid Width="25" Height="25">
|
||||
<Grid.RowDefinitions>
|
||||
<RowDefinition />
|
||||
<RowDefinition />
|
||||
@ -66,10 +66,10 @@
|
||||
<ColumnDefinition />
|
||||
<ColumnDefinition />
|
||||
</Grid.ColumnDefinitions>
|
||||
<Rectangle Grid.Row="0" Grid.Column="0" Fill="LightGray" />
|
||||
<Rectangle Grid.Row="0" Grid.Column="0" Fill="{DynamicResource MaterialDesignPaper}" />
|
||||
<Rectangle Grid.Row="0" Grid.Column="1" />
|
||||
<Rectangle Grid.Row="1" Grid.Column="0" />
|
||||
<Rectangle Grid.Row="1" Grid.Column="1" Fill="LightGray" />
|
||||
<Rectangle Grid.Row="1" Grid.Column="0" />
|
||||
<Rectangle Grid.Row="1" Grid.Column="1" Fill="{DynamicResource MaterialDesignPaper}" />
|
||||
</Grid>
|
||||
</VisualBrush.Visual>
|
||||
</VisualBrush>
|
||||
|
||||
@ -26,7 +26,9 @@
|
||||
</Grid.LayoutTransform>
|
||||
|
||||
<!-- Device image with fallback -->
|
||||
<Image Source="{Binding Device.RgbDevice.DeviceInfo.Image, Converter={StaticResource NullToImageConverter}}" VerticalAlignment="Top" HorizontalAlignment="Left" />
|
||||
<Image VerticalAlignment="Top"
|
||||
HorizontalAlignment="Left"
|
||||
Source="{Binding Device.RgbDevice.DeviceInfo.Image, Converter={StaticResource NullToImageConverter}}" />
|
||||
|
||||
<Rectangle Fill="{DynamicResource ControlBackgroundBrush}"
|
||||
Stroke="{DynamicResource ControlBorderBrush}"
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user