|
|
@@ -1,5 +1,6 @@
|
|
|
using CommunityToolkit.Mvvm.ComponentModel;
|
|
|
using CommunityToolkit.Mvvm.Input;
|
|
|
+using DynamicData.Binding;
|
|
|
using InABox.Avalonia;
|
|
|
using InABox.Avalonia.Components;
|
|
|
using PRS.Avalonia.Modules;
|
|
|
@@ -20,16 +21,57 @@ internal partial class ImageViewerViewModel : ModuleViewModel
|
|
|
[ObservableProperty]
|
|
|
private byte[] _data = null!;
|
|
|
|
|
|
+ [ObservableProperty]
|
|
|
+ private bool _canEdit = false;
|
|
|
+
|
|
|
+ [ObservableProperty]
|
|
|
+ private bool _isEditing;
|
|
|
+
|
|
|
+ [ObservableProperty]
|
|
|
+ private Func<byte[]>? _getImage;
|
|
|
+
|
|
|
+ [ObservableProperty]
|
|
|
+ private bool _imageChanged;
|
|
|
+
|
|
|
[ObservableProperty]
|
|
|
private IRelayCommand? _deleteCommand;
|
|
|
|
|
|
+ [ObservableProperty]
|
|
|
+ private IRelayCommand? _saveCommand;
|
|
|
+
|
|
|
public ImageViewerViewModel()
|
|
|
{
|
|
|
_deleteButton = new AvaloniaMenuItem(Images.cross, Delete);
|
|
|
_deleteButton.IsVisible = false;
|
|
|
+
|
|
|
+ var editButton = new AvaloniaMenuItem(Images.edit, Edit);
|
|
|
+ this.WhenValueChanged(x => x.CanEdit).Subscribe(x => editButton.IsVisible = ShowCanEdit());
|
|
|
+ this.WhenValueChanged(x => x.IsEditing).Subscribe(x => editButton.IsVisible = ShowCanEdit());
|
|
|
+
|
|
|
+ var saveButton = new AvaloniaMenuItem(Images.save, Save);
|
|
|
+ this.WhenValueChanged(x => x.IsEditing).Subscribe(x => saveButton.IsVisible = IsEditing && ImageChanged);
|
|
|
+ this.WhenValueChanged(x => x.ImageChanged).Subscribe(x => saveButton.IsVisible = IsEditing && ImageChanged);
|
|
|
+
|
|
|
+ PrimaryMenu.Items.Add(editButton);
|
|
|
+ PrimaryMenu.Items.Add(saveButton);
|
|
|
PrimaryMenu.Items.Add(_deleteButton);
|
|
|
}
|
|
|
|
|
|
+ private void Save()
|
|
|
+ {
|
|
|
+ Data = GetImage?.Invoke() ?? Data;
|
|
|
+ SaveCommand?.Execute(Data);
|
|
|
+ ImageChanged = false;
|
|
|
+ Navigation.Back();
|
|
|
+ }
|
|
|
+
|
|
|
+ private bool ShowCanEdit() => CanEdit && !IsEditing;
|
|
|
+
|
|
|
+ private void Edit()
|
|
|
+ {
|
|
|
+ IsEditing = true;
|
|
|
+ }
|
|
|
+
|
|
|
partial void OnDeleteCommandChanged(IRelayCommand? value)
|
|
|
{
|
|
|
_deleteButton.IsVisible = value is not null;
|