mirror of
https://github.com/Artemis-RGB/Artemis
synced 2026-11-12 11:56:30 +00:00
Added dialog system
Added surface delete
This commit is contained in:
1 parent
c7790c1d82
commit
89bd76387b
24 files changed
+470
-96
No files matched your search
@@ -0,0 +1,28 @@
|
||||
namespace Artemis.UI.ViewModels.Dialogs
|
||||
{
|
||||
public class ConfirmDialogViewModel : DialogViewModelBase
|
||||
{
|
||||
public ConfirmDialogViewModel(string header, string text, string confirmText, string cancelText)
|
||||
{
|
||||
Header = header;
|
||||
Text = text;
|
||||
ConfirmText = confirmText;
|
||||
CancelText = cancelText;
|
||||
}
|
||||
|
||||
public string Header { get; }
|
||||
public string Text { get; }
|
||||
public string ConfirmText { get; }
|
||||
public string CancelText { get; }
|
||||
|
||||
public void Confirm()
|
||||
{
|
||||
Session.Close(true);
|
||||
}
|
||||
|
||||
public void Cancel()
|
||||
{
|
||||
Session.Close(false);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,29 @@
|
||||
using Artemis.UI.ViewModels.Utilities;
|
||||
using MaterialDesignThemes.Wpf;
|
||||
using Stylet;
|
||||
|
||||
namespace Artemis.UI.ViewModels.Dialogs
|
||||
{
|
||||
public abstract class DialogViewModelBase : ValidatingModelBase
|
||||
{
|
||||
protected DialogViewModelBase(IModelValidator validator) : base(validator)
|
||||
{
|
||||
}
|
||||
|
||||
protected DialogViewModelBase()
|
||||
{
|
||||
}
|
||||
|
||||
public DialogViewModelHost DialogViewModelHost { get; set; }
|
||||
public DialogSession Session { get; private set; }
|
||||
|
||||
public void OnDialogOpened(object sender, DialogOpenedEventArgs e)
|
||||
{
|
||||
Session = e.Session;
|
||||
}
|
||||
|
||||
public virtual void OnDialogClosed(object sender, DialogClosingEventArgs e)
|
||||
{
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,29 @@
|
||||
using System.Threading.Tasks;
|
||||
using Stylet;
|
||||
|
||||
namespace Artemis.UI.ViewModels.Dialogs
|
||||
{
|
||||
public class SurfaceCreateViewModel : DialogViewModelBase
|
||||
{
|
||||
public SurfaceCreateViewModel(IModelValidator<SurfaceCreateViewModel> validator) : base(validator)
|
||||
{
|
||||
}
|
||||
|
||||
public string SurfaceName { get; set; }
|
||||
|
||||
public async Task Accept()
|
||||
{
|
||||
await ValidateAsync();
|
||||
|
||||
if (HasErrors)
|
||||
return;
|
||||
|
||||
Session.Close(SurfaceName);
|
||||
}
|
||||
|
||||
public void Cancel()
|
||||
{
|
||||
Session.Close();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,12 @@
|
||||
using FluentValidation;
|
||||
|
||||
namespace Artemis.UI.ViewModels.Dialogs
|
||||
{
|
||||
public class SurfaceCreateViewModelValidator : AbstractValidator<SurfaceCreateViewModel>
|
||||
{
|
||||
public SurfaceCreateViewModelValidator()
|
||||
{
|
||||
RuleFor(m => m.SurfaceName).NotEmpty().WithMessage("Layout name may not be empty");
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,40 +1,40 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Collections.ObjectModel;
|
||||
using System.Linq;
|
||||
using System.Threading.Tasks;
|
||||
using System.Windows;
|
||||
using System.Windows.Controls;
|
||||
using System.Windows.Input;
|
||||
using System.Windows.Media;
|
||||
using Artemis.Core.Events;
|
||||
using Artemis.Core.Models.Surface;
|
||||
using Artemis.Core.Services.Interfaces;
|
||||
using Artemis.Core.Services.Storage;
|
||||
using Artemis.UI.Services.Interfaces;
|
||||
using Artemis.UI.ViewModels.Controls.SurfaceEditor;
|
||||
using Artemis.UI.ViewModels.Dialogs;
|
||||
using Artemis.UI.ViewModels.Interfaces;
|
||||
using Artemis.UI.ViewModels.Utilities;
|
||||
using Stylet;
|
||||
|
||||
namespace Artemis.UI.ViewModels.Screens
|
||||
{
|
||||
public class SurfaceEditorViewModel : Screen, ISurfaceEditorViewModel
|
||||
{
|
||||
private readonly IRgbService _rgbService;
|
||||
private readonly IDialogService _dialogService;
|
||||
private readonly ISurfaceService _surfaceService;
|
||||
|
||||
public SurfaceEditorViewModel(IRgbService rgbService, ISurfaceService surfaceService)
|
||||
public SurfaceEditorViewModel(ISurfaceService surfaceService, IDialogService dialogService)
|
||||
{
|
||||
Devices = new ObservableCollection<SurfaceDeviceViewModel>();
|
||||
SurfaceConfigurations = new ObservableCollection<SurfaceConfiguration>();
|
||||
SelectionRectangle = new RectangleGeometry();
|
||||
PanZoomViewModel = new PanZoomViewModel();
|
||||
|
||||
_rgbService = rgbService;
|
||||
_surfaceService = surfaceService;
|
||||
_dialogService = dialogService;
|
||||
}
|
||||
|
||||
public RectangleGeometry SelectionRectangle { get; set; }
|
||||
public ObservableCollection<SurfaceDeviceViewModel> Devices { get; set; }
|
||||
public ObservableCollection<SurfaceConfiguration> SurfaceConfigurations { get; set; }
|
||||
|
||||
public SurfaceConfiguration SelectedSurfaceConfiguration
|
||||
{
|
||||
@@ -46,14 +46,10 @@ namespace Artemis.UI.ViewModels.Screens
|
||||
}
|
||||
}
|
||||
|
||||
public ObservableCollection<SurfaceConfiguration> SurfaceConfigurations { get; set; }
|
||||
public string NewConfigurationName { get; set; }
|
||||
|
||||
public PanZoomViewModel PanZoomViewModel { get; set; }
|
||||
|
||||
public string Title => "Surface Editor";
|
||||
|
||||
public SurfaceConfiguration AddSurfaceConfiguration(string name)
|
||||
public SurfaceConfiguration CreateSurfaceConfiguration(string name)
|
||||
{
|
||||
var config = _surfaceService.CreateSurfaceConfiguration(name);
|
||||
Execute.OnUIThread(() => SurfaceConfigurations.Add(config));
|
||||
@@ -69,7 +65,7 @@ namespace Artemis.UI.ViewModels.Screens
|
||||
var activeConfig = _surfaceService.ActiveSurfaceConfiguration;
|
||||
if (activeConfig == null)
|
||||
{
|
||||
activeConfig = AddSurfaceConfiguration("Default");
|
||||
activeConfig = CreateSurfaceConfiguration("Default");
|
||||
_surfaceService.SetActiveSurfaceConfiguration(activeConfig);
|
||||
}
|
||||
|
||||
@@ -121,15 +117,25 @@ namespace Artemis.UI.ViewModels.Screens
|
||||
|
||||
#region Configuration management
|
||||
|
||||
public void ConfirmationDialogClosing()
|
||||
public async Task DeleteSurfaceConfiguration(SurfaceConfiguration surfaceConfiguration)
|
||||
{
|
||||
if (!string.IsNullOrWhiteSpace(NewConfigurationName))
|
||||
var result = await _dialogService.ShowConfirmDialogAt(
|
||||
"SurfaceListDialogHost",
|
||||
"Delete surface configuration",
|
||||
"Are you sure you want to delete this surface configuration?"
|
||||
);
|
||||
if (result)
|
||||
{
|
||||
var newConfig = AddSurfaceConfiguration(NewConfigurationName);
|
||||
SelectedSurfaceConfiguration = newConfig;
|
||||
SurfaceConfigurations.Remove(surfaceConfiguration);
|
||||
_surfaceService.DeleteSurfaceConfiguration(surfaceConfiguration);
|
||||
}
|
||||
}
|
||||
|
||||
NewConfigurationName = null;
|
||||
public async Task AddSurfaceConfiguration()
|
||||
{
|
||||
var result = await _dialogService.ShowDialogAt<SurfaceCreateViewModel>("SurfaceListDialogHost");
|
||||
if (result is string name)
|
||||
CreateSurfaceConfiguration(name);
|
||||
}
|
||||
|
||||
#endregion
|
||||
@@ -274,9 +280,7 @@ namespace Artemis.UI.ViewModels.Screens
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
_surfaceService.UpdateSurfaceConfiguration(SelectedSurfaceConfiguration, true);
|
||||
}
|
||||
|
||||
Mouse.OverrideCursor = null;
|
||||
_mouseDragStatus = MouseDragStatus.None;
|
||||
|
||||
@@ -0,0 +1,28 @@
|
||||
using Artemis.UI.ViewModels.Dialogs;
|
||||
using MaterialDesignThemes.Wpf;
|
||||
using Stylet;
|
||||
|
||||
namespace Artemis.UI.ViewModels.Utilities
|
||||
{
|
||||
public class DialogViewModelHost : PropertyChangedBase
|
||||
{
|
||||
private readonly IViewManager _viewManager;
|
||||
|
||||
public DialogViewModelHost(IViewManager viewManager)
|
||||
{
|
||||
_viewManager = viewManager;
|
||||
}
|
||||
public DialogViewModelBase ActiveDialogViewModel { get; set; }
|
||||
public bool IsOpen { get; set; }
|
||||
|
||||
public void OpenDialog(DialogViewModelBase viewModel, string dialogIdentifier)
|
||||
{
|
||||
var view = _viewManager.CreateViewForModel(viewModel);
|
||||
DialogHost.Show(view, dialogIdentifier, viewModel.OnDialogClosed);
|
||||
viewModel.DialogViewModelHost = this;
|
||||
|
||||
ActiveDialogViewModel = viewModel;
|
||||
IsOpen = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
+1
-5
@@ -1,15 +1,11 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using System.Windows;
|
||||
using System.Windows.Controls;
|
||||
using System.Windows.Input;
|
||||
using System.Windows.Media;
|
||||
using Stylet;
|
||||
|
||||
namespace Artemis.UI.ViewModels
|
||||
namespace Artemis.UI.ViewModels.Utilities
|
||||
{
|
||||
public class PanZoomViewModel : PropertyChangedBase
|
||||
{
|
||||
Reference in new issue
Block a user