[GUI] Add image processing commands to MainWindowViewModel and update UI bindings

This commit is contained in:
2025-10-27 16:04:01 +00:00
parent f9aef60c66
commit 07bae0328f
2 changed files with 151 additions and 23 deletions

View File

@@ -16,6 +16,7 @@ using Aaru.Gui.ViewModels.Dialogs;
using Aaru.Gui.ViewModels.Panels;
using Aaru.Gui.Views.Dialogs;
using Aaru.Gui.Views.Panels;
using Aaru.Gui.Views.Windows;
using Aaru.Localization;
using Aaru.Logging;
using Avalonia;
@@ -54,13 +55,15 @@ public partial class MainWindowViewModel : ViewModelBase
object _contentPanel;
[ObservableProperty]
bool _devicesSupported;
ImageModel _image;
[ObservableProperty]
bool _imageLoaded;
[ObservableProperty]
string _title;
[ObservableProperty]
ObservableCollection<RootModel> _treeRoot;
object _treeViewSelectedItem;
public MainWindowViewModel(Window view)
{
AboutCommand = new AsyncRelayCommand(AboutAsync);
@@ -71,6 +74,13 @@ public partial class MainWindowViewModel : ViewModelBase
SettingsCommand = new AsyncRelayCommand(SettingsAsync);
ConsoleCommand = new RelayCommand(Console);
OpenCommand = new AsyncRelayCommand(OpenAsync);
CalculateEntropyCommand = new RelayCommand(CalculateEntropy);
VerifyImageCommand = new RelayCommand(VerifyImage);
ChecksumImageCommand = new RelayCommand(ChecksumImage);
ConvertImageCommand = new RelayCommand(ConvertImage);
CreateSidecarCommand = new RelayCommand(CreateSidecar);
ViewImageSectorsCommand = new RelayCommand(ViewImageSectors);
DecodeImageMediaTagsCommand = new RelayCommand(DecodeImageMediaTags);
_genericHddIcon =
new Bitmap(AssetLoader.Open(new Uri("avares://Aaru.Gui/Assets/Icons/oxygen/32x32/drive-harddisk.png")));
@@ -115,6 +125,13 @@ public partial class MainWindowViewModel : ViewModelBase
public ICommand PluginsCommand { get; }
public ICommand StatisticsCommand { get; }
public ICommand AboutCommand { get; }
public ICommand CalculateEntropyCommand { get; }
public ICommand VerifyImageCommand { get; }
public ICommand ChecksumImageCommand { get; }
public ICommand ConvertImageCommand { get; }
public ICommand CreateSidecarCommand { get; }
public ICommand ViewImageSectorsCommand { get; }
public ICommand DecodeImageMediaTagsCommand { get; }
public bool NativeMenuSupported
{
@@ -447,6 +464,8 @@ public partial class MainWindowViewModel : ViewModelBase
TreeRoot.Clear();
TreeRoot.Add(imageModel);
Title = $"Aaru - {imageModel.FileName}";
ImageLoaded = true;
_image = imageModel;
}
catch(Exception ex)
{
@@ -545,4 +564,91 @@ public partial class MainWindowViewModel : ViewModelBase
_console.Show();
}
void CalculateEntropy()
{
if(_image is not {} imageModel) return;
var imageEntropyWindow = new ImageEntropy();
imageEntropyWindow.DataContext = new ImageEntropyViewModel(imageModel.Image, imageEntropyWindow);
imageEntropyWindow.Closed += (_, _) => imageEntropyWindow = null;
imageEntropyWindow.Show();
}
void VerifyImage()
{
if(_image is not {} imageModel) return;
var imageVerifyWindow = new ImageVerify();
imageVerifyWindow.DataContext = new ImageVerifyViewModel(imageModel.Image, imageVerifyWindow);
imageVerifyWindow.Closed += (_, _) => imageVerifyWindow = null;
imageVerifyWindow.Show();
}
void ChecksumImage()
{
if(_image is not {} imageModel) return;
var imageChecksumWindow = new ImageChecksum();
imageChecksumWindow.DataContext = new ImageChecksumViewModel(imageModel.Image, imageChecksumWindow);
imageChecksumWindow.Closed += (_, _) => imageChecksumWindow = null;
imageChecksumWindow.Show();
}
void ConvertImage()
{
if(_image is not {} imageModel) return;
var imageConvertWindow = new ImageConvert();
imageConvertWindow.DataContext =
new ImageConvertViewModel(imageModel.Image, imageModel.Path, imageConvertWindow);
imageConvertWindow.Closed += (_, _) => imageConvertWindow = null;
imageConvertWindow.Show();
}
void CreateSidecar()
{
if(_image is not {} imageModel) return;
var imageSidecarWindow = new ImageSidecar();
// TODO: Pass thru chosen default encoding
imageSidecarWindow.DataContext =
new ImageSidecarViewModel(imageModel.Image,
imageModel.Path,
imageModel.Filter.Id,
null,
imageSidecarWindow);
imageSidecarWindow.Show();
}
void ViewImageSectors()
{
if(_image is not {} imageModel) return;
new ViewSector
{
DataContext = new ViewSectorViewModel(imageModel.Image)
}.Show();
}
void DecodeImageMediaTags()
{
if(_image is not {} imageModel) return;
new DecodeMediaTags
{
DataContext = new DecodeMediaTagsViewModel(imageModel.Image)
}.Show();
}
}

View File

@@ -32,6 +32,23 @@
IsVisible="{Binding DevicesSupported, Mode=OneWay}">
<MenuItem Header="TODO" />
</MenuItem>
<MenuItem Header="Image"
IsEnabled="{Binding ImageLoaded, Mode=OneWay}">
<MenuItem Command="{Binding CalculateEntropyCommand, Mode=OneWay}"
Header="{x:Static localization:UI.ButtonLabel_Calculate_entropy}" />
<MenuItem Command="{Binding VerifyImageCommand, Mode=OneWay}"
Header="{x:Static localization:UI.ButtonLabel_Verify}" />
<MenuItem Command="{Binding ChecksumImageCommand, Mode=OneWay}"
Header="{x:Static localization:UI.ButtonLabel_Checksum}" />
<MenuItem Command="{Binding ConvertImageCommand, Mode=OneWay}"
Header="{x:Static localization:UI.ButtonLabel_Convert_to}" />
<MenuItem Command="{Binding CreateSidecarCommand, Mode=OneWay}"
Header="{x:Static localization:UI.ButtonLabel_Create_Aaru_Metadata_sidecar}" />
<MenuItem Command="{Binding ViewImageSectorsCommand, Mode=OneWay}"
Header="{x:Static localization:UI.ButtonLabel_View_sectors}" />
<MenuItem Command="{Binding DecodeImageMediaTagsCommand, Mode=OneWay}"
Header="{x:Static localization:UI.ButtonLabel_Decode_media_tags}" />
</MenuItem>
<MenuItem Header="{x:Static localization:UI.Menu_Window}">
<MenuItem Header="{x:Static localization:UI.Menu_Console}"
Command="{Binding ConsoleCommand, Mode=OneWay}" />
@@ -83,7 +100,8 @@
<Image Width="24"
Height="24"
Source="{Binding Icon, Mode=OneWay}" />
<TextBlock Text="{Binding FileName, Mode=OneWay}" VerticalAlignment="Center"/>
<TextBlock Text="{Binding FileName, Mode=OneWay}"
VerticalAlignment="Center" />
</StackPanel>
</TreeDataTemplate>
<TreeDataTemplate DataType="models:PartitionSchemeModel"
@@ -92,7 +110,8 @@
<Image Width="24"
Height="24"
Source="{Binding Icon, Mode=OneWay}" />
<TextBlock Text="{Binding Name, Mode=OneWay}" VerticalAlignment="Center"/>
<TextBlock Text="{Binding Name, Mode=OneWay}"
VerticalAlignment="Center" />
</StackPanel>
</TreeDataTemplate>
<TreeDataTemplate DataType="models:PartitionModel"
@@ -101,7 +120,8 @@
<Image Width="24"
Height="24"
Source="{Binding Icon, Mode=OneWay}" />
<TextBlock Text="{Binding Name, Mode=OneWay}" VerticalAlignment="Center"/>
<TextBlock Text="{Binding Name, Mode=OneWay}"
VerticalAlignment="Center" />
</StackPanel>
</TreeDataTemplate>
<TreeDataTemplate DataType="models:FileSystemModel"
@@ -110,7 +130,8 @@
<Image Width="24"
Height="24"
Source="{Binding Icon, Mode=OneWay}" />
<TextBlock Text="{Binding VolumeName, Mode=OneWay}" VerticalAlignment="Center"/>
<TextBlock Text="{Binding VolumeName, Mode=OneWay}"
VerticalAlignment="Center" />
</StackPanel>
</TreeDataTemplate>
<TreeDataTemplate DataType="models:SubdirectoryModel"
@@ -119,7 +140,8 @@
<Image Width="24"
Height="24"
Source="{Binding Icon, Mode=OneWay}" />
<TextBlock Text="{Binding Name, Mode=OneWay}" VerticalAlignment="Center"/>
<TextBlock Text="{Binding Name, Mode=OneWay}"
VerticalAlignment="Center" />
</StackPanel>
</TreeDataTemplate>
<DataTemplate DataType="models:RootModel">