Files
WCS/Plugins/Driver/Cowain.Driver/ViewModels/DeviceEditDialogViewModel.cs

79 lines
2.1 KiB
C#
Raw Normal View History

using Avalonia.Controls.Notifications;
using CommunityToolkit.Mvvm.ComponentModel;
using CommunityToolkit.Mvvm.Input;
using Cowain.Base.Helpers;
using Irihi.Avalonia.Shared.Contracts;
using Ke.Bee.Localization.Localizer.Abstractions;
using Plugin.Cowain.Driver.IServices;
namespace Plugin.Cowain.Driver.ViewModels;
public partial class DeviceEditDialogViewModel : ObservableObject, IDialogContext
{
public event EventHandler<object?>? RequestClose;
[ObservableProperty]
private DeviceViewModel? _device;
private readonly ILocalizer _l;
private IDriverPluginService _driverService;
public DeviceEditDialogViewModel(ILocalizer l, DeviceViewModel deviceModel, IDriverPluginService driverService)
{
_l = l;
_device = deviceModel;
_driverService = driverService;
}
public void Close()
{
RequestClose?.Invoke(this, false);
}
[RelayCommand]
private void EditParam()
{
if (Device == null)
{
return;
}
_driverService.ParamEditDialogAsync(Device);
}
[RelayCommand]
private void Ok()
{
if (Device == null)
{
return;
}
if (string.IsNullOrEmpty(Device.DeviceName))
{
NotificationHelper.ShowNormal(NotificationType.Information, _l["DeviceEditDilog.Error.DeviceNameNull"]);
return;
}
if (string.IsNullOrEmpty(Device.DriverName))
{
NotificationHelper.ShowNormal(NotificationType.Information, _l["DeviceEditDilog.Error.DriverNameNull"]);
return;
}
if (string.IsNullOrEmpty(Device.DeviceType))
{
NotificationHelper.ShowNormal(NotificationType.Information, _l["DeviceEditDilog.Error.DeviceTypeNull"]);
return;
}
if (string.IsNullOrEmpty(Device.Param))
{
NotificationHelper.ShowNormal(NotificationType.Information, _l["DeviceEditDilog.Error.ParamNull"]);
return;
}
RequestClose?.Invoke(this, true);
}
[RelayCommand]
private void Cancel()
{
RequestClose?.Invoke(this, false);
}
}