Migrate partition panel from Eto.Forms to Avalonia.

This commit is contained in:
2020-04-14 19:58:23 +01:00
parent 28e0f3dca3
commit 754f8d5adb
8 changed files with 206 additions and 253 deletions

View File

@@ -1254,14 +1254,14 @@
<e p="Panels" t="Include"> <e p="Panels" t="Include">
<e p="ImageInfoPanel.xaml" t="Include" /> <e p="ImageInfoPanel.xaml" t="Include" />
<e p="ImageInfoPanel.xaml.cs" t="Include" /> <e p="ImageInfoPanel.xaml.cs" t="Include" />
<e p="PartitionPanel.xaml" t="Include" />
<e p="PartitionPanel.xaml.cs" t="Include" />
<e p="pnlDeviceInfo.xeto" t="Include" /> <e p="pnlDeviceInfo.xeto" t="Include" />
<e p="pnlDeviceInfo.xeto.cs" t="Include" /> <e p="pnlDeviceInfo.xeto.cs" t="Include" />
<e p="pnlFilesystem.xeto" t="Include" /> <e p="pnlFilesystem.xeto" t="Include" />
<e p="pnlFilesystem.xeto.cs" t="Include" /> <e p="pnlFilesystem.xeto.cs" t="Include" />
<e p="pnlListFiles.xeto" t="Include" /> <e p="pnlListFiles.xeto" t="Include" />
<e p="pnlListFiles.xeto.cs" t="Include" /> <e p="pnlListFiles.xeto.cs" t="Include" />
<e p="pnlPartition.xeto" t="Include" />
<e p="pnlPartition.xeto.cs" t="Include" />
<e p="pnlScsiInfo.xeto" t="Include" /> <e p="pnlScsiInfo.xeto" t="Include" />
<e p="pnlScsiInfo.xeto.cs" t="Include" /> <e p="pnlScsiInfo.xeto.cs" t="Include" />
</e> </e>
@@ -1305,6 +1305,7 @@
<e p="ImageVerifyViewModel.cs" t="Include" /> <e p="ImageVerifyViewModel.cs" t="Include" />
<e p="LicenseDialogViewModel.cs" t="Include" /> <e p="LicenseDialogViewModel.cs" t="Include" />
<e p="MainWindowViewModel.cs" t="Include" /> <e p="MainWindowViewModel.cs" t="Include" />
<e p="PartitionViewModel.cs" t="Include" />
<e p="PcmciaInfoViewModel.cs" t="Include" /> <e p="PcmciaInfoViewModel.cs" t="Include" />
<e p="PluginsDialogViewModel.cs" t="Include" /> <e p="PluginsDialogViewModel.cs" t="Include" />
<e p="ScsiInfoViewModel.cs" t="Include" /> <e p="ScsiInfoViewModel.cs" t="Include" />

View File

@@ -1,5 +1,6 @@
using System.Collections.ObjectModel; using System.Collections.ObjectModel;
using Aaru.CommonTypes; using Aaru.CommonTypes;
using Aaru.Gui.ViewModels;
using Avalonia.Media.Imaging; using Avalonia.Media.Imaging;
namespace Aaru.Gui.Models namespace Aaru.Gui.Models
@@ -12,5 +13,6 @@ namespace Aaru.Gui.Models
public Bitmap Icon { get; set; } public Bitmap Icon { get; set; }
public ObservableCollection<FileSystemModel> FileSystems { get; } public ObservableCollection<FileSystemModel> FileSystems { get; }
public Partition Partition { get; set; } public Partition Partition { get; set; }
public PartitionViewModel ViewModel { get; set; }
} }
} }

View File

@@ -0,0 +1,15 @@
<UserControl xmlns="https://github.com/avaloniaui" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:vm="clr-namespace:Aaru.Gui.ViewModels" mc:Ignorable="d" d:DesignWidth="800" d:DesignHeight="450"
x:Class="Aaru.Gui.Panels.PartitionPanel">
<Design.DataContext>
<vm:PartitionViewModel />
</Design.DataContext>
<StackPanel>
<TextBlock Text="{Binding NameText}" /> <TextBlock Text="{Binding TypeText}" />
<TextBlock Text="{Binding StartText}" /> <TextBlock Text="{Binding LengthText}" />
<TextBlock Text="{Binding DescriptionLabelText}" IsVisible="{Binding !!DescriptionText}" />
<TextBox Text="{Binding DescriptionText}" IsVisible="{Binding !!DescriptionText}" IsReadOnly="True" />
</StackPanel>
</UserControl>

View File

@@ -0,0 +1,12 @@
using Avalonia.Controls;
using Avalonia.Markup.Xaml;
namespace Aaru.Gui.Panels
{
public class PartitionPanel : UserControl
{
public PartitionPanel() => InitializeComponent();
void InitializeComponent() => AvaloniaXamlLoader.Load(this);
}
}

View File

@@ -1,44 +0,0 @@
<?xml version="1.0" encoding="UTF-8"?><!--
// /***************************************************************************
// The Disc Image Chef
// ============================================================================
//
// Filename : pnlPartition.xeto
// Author(s) : Natalia Portillo <claunia@claunia.com>
//
// Component : Partitions information panel.
//
// ==[ Description ] ==========================================================
//
// Defines the structure for the partitions information panel.
//
// ==[ License ] ==============================================================
//
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU General public License as
// published by the Free Software Foundation, either version 3 of the
// License, or (at your option) any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General public License for more details.
//
// You should have received a copy of the GNU General public License
// along with this program. If not, see <http://www.gnu.org/licenses/>.
//
// ============================================================================
// Copyright © 2011-2020 Natalia Portillo
// ****************************************************************************/
-->
<Panel xmlns="http://schema.picoe.ca/eto.forms" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml">
<StackLayout Orientation="Vertical">
<Label ID="lblName"/>
<Label ID="lblType"/>
<Label ID="lblStart"/>
<Label ID="lblLength"/>
<GroupBox ID="grpDescription">
<TextArea ID="txtDescription" ReadOnly="True"/>
</GroupBox>
</StackLayout>
</Panel>

View File

@@ -1,67 +0,0 @@
// /***************************************************************************
// Aaru Data Preservation Suite
// ----------------------------------------------------------------------------
//
// Filename : pnlPartition.xeto.cs
// Author(s) : Natalia Portillo <claunia@claunia.com>
//
// Component : Partitions information panel.
//
// --[ Description ] ----------------------------------------------------------
//
// Implements the partitions information panel.
//
// --[ License ] --------------------------------------------------------------
//
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU General public License as
// published by the Free Software Foundation, either version 3 of the
// License, or (at your option) any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General public License for more details.
//
// You should have received a copy of the GNU General public License
// along with this program. If not, see <http://www.gnu.org/licenses/>.
//
// ----------------------------------------------------------------------------
// Copyright © 2011-2020 Natalia Portillo
// ****************************************************************************/
using Aaru.CommonTypes;
using Eto.Forms;
using Eto.Serialization.Xaml;
namespace Aaru.Gui.Panels
{
public class pnlPartition : Panel
{
public pnlPartition(Partition partition)
{
XamlReader.Load(this);
lblName.Text = $"Partition name: {partition.Name}";
lblType.Text = $"Partition type: {partition.Type}";
lblStart.Text = $"Partition start: sector {partition.Start}, byte {partition.Offset}";
lblLength.Text = $"Partition length: {partition.Length} sectors, {partition.Size} bytes";
grpDescription.Text = "Partition description:";
txtDescription.Text = partition.Description;
grpDescription.Visible = !string.IsNullOrEmpty(partition.Description);
}
#region XAML controls
#pragma warning disable 169
#pragma warning disable 649
Label lblName;
Label lblType;
Label lblStart;
Label lblLength;
GroupBox grpDescription;
TextArea txtDescription;
#pragma warning restore 169
#pragma warning restore 649
#endregion
}
}

View File

@@ -38,131 +38,31 @@ namespace Aaru.Gui.ViewModels
readonly ImagesRootModel _imagesRoot; readonly ImagesRootModel _imagesRoot;
readonly MainWindow _view; readonly MainWindow _view;
ConsoleWindow _consoleWindow; ConsoleWindow _consoleWindow;
public object _contentPanel; public object _contentPanel;
bool _devicesSupported; bool _devicesSupported;
public object _treeViewSelectedItem; public object _treeViewSelectedItem;
void ExecuteCalculateEntropyCommand()
{
if(!(TreeViewSelectedItem is ImageModel imageModel))
return;
var imageEntropyWindow = new ImageEntropyWindow();
imageEntropyWindow.DataContext = new ImageEntropyViewModel(imageModel.Image, imageEntropyWindow);
imageEntropyWindow.Closed += (sender, args) =>
{
imageEntropyWindow = null;
};
imageEntropyWindow.Show();
}
void ExecuteVerifyImageCommand()
{
if(!(TreeViewSelectedItem is ImageModel imageModel))
return;
var imageVerifyWindow = new ImageVerifyWindow();
imageVerifyWindow.DataContext = new ImageVerifyViewModel(imageModel.Image, imageVerifyWindow);
imageVerifyWindow.Closed += (sender, args) =>
{
imageVerifyWindow = null;
};
imageVerifyWindow.Show();
}
void ExecuteChecksumImageCommand()
{
if(!(TreeViewSelectedItem is ImageModel imageModel))
return;
var imageChecksumWindow = new ImageChecksumWindow();
imageChecksumWindow.DataContext = new ImageChecksumViewModel(imageModel.Image, imageChecksumWindow);
imageChecksumWindow.Closed += (sender, args) =>
{
imageChecksumWindow = null;
};
imageChecksumWindow.Show();
}
void ExecuteConvertImageCommand()
{
if(!(TreeViewSelectedItem is ImageModel imageModel))
return;
var imageConvertWindow = new ImageConvertWindow();
imageConvertWindow.DataContext = new ImageConvertViewModel(imageModel.Image, imageModel.Path, imageConvertWindow);
imageConvertWindow.Closed += (sender, args) =>
{
imageConvertWindow = null;
};
imageConvertWindow.Show();
}
void ExecuteCreateSidecarCommand()
{
if(!(TreeViewSelectedItem is ImageModel imageModel))
return;
var imageSidecarWindow = new ImageSidecarWindow();
// TODO: Pass thru chosen default encoding
imageSidecarWindow.DataContext =
new ImageSidecarViewModel(imageModel.Image, imageModel.Path, imageModel.Filter.Id, null, imageSidecarWindow);
imageSidecarWindow.Show();
}
void ExecuteViewImageSectorsCommand()
{
if(!(TreeViewSelectedItem is ImageModel imageModel))
return;
new ViewSectorWindow
{
DataContext = new ViewSectorViewModel(imageModel.Image)
}.Show();
}
void ExecuteDecodeImageMediaTagsCommand()
{
if(!(TreeViewSelectedItem is ImageModel imageModel))
return;
new DecodeMediaTagsWindow
{
DataContext = new DecodeMediaTagsViewModel(imageModel.Image)
}.Show();
}
public MainWindowViewModel(MainWindow view) public MainWindowViewModel(MainWindow view)
{ {
AboutCommand = ReactiveCommand.Create(ExecuteAboutCommand); AboutCommand = ReactiveCommand.Create(ExecuteAboutCommand);
EncodingsCommand = ReactiveCommand.Create(ExecuteEncodingsCommand); EncodingsCommand = ReactiveCommand.Create(ExecuteEncodingsCommand);
PluginsCommand = ReactiveCommand.Create(ExecutePluginsCommand); PluginsCommand = ReactiveCommand.Create(ExecutePluginsCommand);
StatisticsCommand = ReactiveCommand.Create(ExecuteStatisticsCommand); StatisticsCommand = ReactiveCommand.Create(ExecuteStatisticsCommand);
ExitCommand = ReactiveCommand.Create(ExecuteExitCommand); ExitCommand = ReactiveCommand.Create(ExecuteExitCommand);
SettingsCommand = ReactiveCommand.Create(ExecuteSettingsCommand); SettingsCommand = ReactiveCommand.Create(ExecuteSettingsCommand);
ConsoleCommand = ReactiveCommand.Create(ExecuteConsoleCommand); ConsoleCommand = ReactiveCommand.Create(ExecuteConsoleCommand);
OpenCommand = ReactiveCommand.Create(ExecuteOpenCommand); OpenCommand = ReactiveCommand.Create(ExecuteOpenCommand);
CalculateEntropyCommand = ReactiveCommand.Create(ExecuteCalculateEntropyCommand); CalculateEntropyCommand = ReactiveCommand.Create(ExecuteCalculateEntropyCommand);
VerifyImageCommand = ReactiveCommand.Create(ExecuteVerifyImageCommand); VerifyImageCommand = ReactiveCommand.Create(ExecuteVerifyImageCommand);
ChecksumImageCommand = ReactiveCommand.Create(ExecuteChecksumImageCommand); ChecksumImageCommand = ReactiveCommand.Create(ExecuteChecksumImageCommand);
ConvertImageCommand = ReactiveCommand.Create(ExecuteConvertImageCommand); ConvertImageCommand = ReactiveCommand.Create(ExecuteConvertImageCommand);
CreateSidecarCommand = ReactiveCommand.Create(ExecuteCreateSidecarCommand); CreateSidecarCommand = ReactiveCommand.Create(ExecuteCreateSidecarCommand);
ViewImageSectorsCommand = ReactiveCommand.Create(ExecuteViewImageSectorsCommand); ViewImageSectorsCommand = ReactiveCommand.Create(ExecuteViewImageSectorsCommand);
DecodeImageMediaTagsCommand = ReactiveCommand.Create(ExecuteDecodeImageMediaTagsCommand); DecodeImageMediaTagsCommand = ReactiveCommand.Create(ExecuteDecodeImageMediaTagsCommand);
_view = view; _view = view;
TreeRoot = new ObservableCollection<RootModel>(); TreeRoot = new ObservableCollection<RootModel>();
_assets = AvaloniaLocator.Current.GetService<IAssetLoader>(); _assets = AvaloniaLocator.Current.GetService<IAssetLoader>();
ContentPanel = Greeting; ContentPanel = Greeting;
_imagesRoot = new ImagesRootModel _imagesRoot = new ImagesRootModel
{ {
@@ -210,23 +110,23 @@ namespace Aaru.Gui.ViewModels
NativeMenu.GetIsNativeMenuExported((Application.Current.ApplicationLifetime as NativeMenu.GetIsNativeMenuExported((Application.Current.ApplicationLifetime as
IClassicDesktopStyleApplicationLifetime)?.MainWindow); IClassicDesktopStyleApplicationLifetime)?.MainWindow);
public string Greeting => "Welcome to Aaru!"; public string Greeting => "Welcome to Aaru!";
public ObservableCollection<RootModel> TreeRoot { get; } public ObservableCollection<RootModel> TreeRoot { get; }
public ReactiveCommand<Unit, Unit> AboutCommand { get; } public ReactiveCommand<Unit, Unit> AboutCommand { get; }
public ReactiveCommand<Unit, Unit> ConsoleCommand { get; } public ReactiveCommand<Unit, Unit> ConsoleCommand { get; }
public ReactiveCommand<Unit, Unit> EncodingsCommand { get; } public ReactiveCommand<Unit, Unit> EncodingsCommand { get; }
public ReactiveCommand<Unit, Unit> PluginsCommand { get; } public ReactiveCommand<Unit, Unit> PluginsCommand { get; }
public ReactiveCommand<Unit, Unit> StatisticsCommand { get; } public ReactiveCommand<Unit, Unit> StatisticsCommand { get; }
public ReactiveCommand<Unit, Unit> ExitCommand { get; } public ReactiveCommand<Unit, Unit> ExitCommand { get; }
public ReactiveCommand<Unit, Unit> SettingsCommand { get; } public ReactiveCommand<Unit, Unit> SettingsCommand { get; }
public ReactiveCommand<Unit, Unit> OpenCommand { get; } public ReactiveCommand<Unit, Unit> OpenCommand { get; }
public ReactiveCommand<Unit, Unit> CalculateEntropyCommand { get; } public ReactiveCommand<Unit, Unit> CalculateEntropyCommand { get; }
public ReactiveCommand<Unit, Unit> VerifyImageCommand { get; } public ReactiveCommand<Unit, Unit> VerifyImageCommand { get; }
public ReactiveCommand<Unit, Unit> ChecksumImageCommand { get; } public ReactiveCommand<Unit, Unit> ChecksumImageCommand { get; }
public ReactiveCommand<Unit, Unit> ConvertImageCommand { get; } public ReactiveCommand<Unit, Unit> ConvertImageCommand { get; }
public ReactiveCommand<Unit, Unit> CreateSidecarCommand { get; } public ReactiveCommand<Unit, Unit> CreateSidecarCommand { get; }
public ReactiveCommand<Unit, Unit> ViewImageSectorsCommand { get; } public ReactiveCommand<Unit, Unit> ViewImageSectorsCommand { get; }
public ReactiveCommand<Unit, Unit> DecodeImageMediaTagsCommand { get; } public ReactiveCommand<Unit, Unit> DecodeImageMediaTagsCommand { get; }
public object ContentPanel public object ContentPanel
{ {
@@ -248,10 +148,119 @@ namespace Aaru.Gui.ViewModels
DataContext = imageModel.ViewModel DataContext = imageModel.ViewModel
}; };
if(value is PartitionModel partitionModel)
ContentPanel = new PartitionPanel
{
DataContext = partitionModel.ViewModel
};
this.RaiseAndSetIfChanged(ref _treeViewSelectedItem, value); this.RaiseAndSetIfChanged(ref _treeViewSelectedItem, value);
} }
} }
void ExecuteCalculateEntropyCommand()
{
if(!(TreeViewSelectedItem is ImageModel imageModel))
return;
var imageEntropyWindow = new ImageEntropyWindow();
imageEntropyWindow.DataContext = new ImageEntropyViewModel(imageModel.Image, imageEntropyWindow);
imageEntropyWindow.Closed += (sender, args) =>
{
imageEntropyWindow = null;
};
imageEntropyWindow.Show();
}
void ExecuteVerifyImageCommand()
{
if(!(TreeViewSelectedItem is ImageModel imageModel))
return;
var imageVerifyWindow = new ImageVerifyWindow();
imageVerifyWindow.DataContext = new ImageVerifyViewModel(imageModel.Image, imageVerifyWindow);
imageVerifyWindow.Closed += (sender, args) =>
{
imageVerifyWindow = null;
};
imageVerifyWindow.Show();
}
void ExecuteChecksumImageCommand()
{
if(!(TreeViewSelectedItem is ImageModel imageModel))
return;
var imageChecksumWindow = new ImageChecksumWindow();
imageChecksumWindow.DataContext = new ImageChecksumViewModel(imageModel.Image, imageChecksumWindow);
imageChecksumWindow.Closed += (sender, args) =>
{
imageChecksumWindow = null;
};
imageChecksumWindow.Show();
}
void ExecuteConvertImageCommand()
{
if(!(TreeViewSelectedItem is ImageModel imageModel))
return;
var imageConvertWindow = new ImageConvertWindow();
imageConvertWindow.DataContext =
new ImageConvertViewModel(imageModel.Image, imageModel.Path, imageConvertWindow);
imageConvertWindow.Closed += (sender, args) =>
{
imageConvertWindow = null;
};
imageConvertWindow.Show();
}
void ExecuteCreateSidecarCommand()
{
if(!(TreeViewSelectedItem is ImageModel imageModel))
return;
var imageSidecarWindow = new ImageSidecarWindow();
// TODO: Pass thru chosen default encoding
imageSidecarWindow.DataContext =
new ImageSidecarViewModel(imageModel.Image, imageModel.Path, imageModel.Filter.Id, null,
imageSidecarWindow);
imageSidecarWindow.Show();
}
void ExecuteViewImageSectorsCommand()
{
if(!(TreeViewSelectedItem is ImageModel imageModel))
return;
new ViewSectorWindow
{
DataContext = new ViewSectorViewModel(imageModel.Image)
}.Show();
}
void ExecuteDecodeImageMediaTagsCommand()
{
if(!(TreeViewSelectedItem is ImageModel imageModel))
return;
new DecodeMediaTagsWindow
{
DataContext = new DecodeMediaTagsViewModel(imageModel.Image)
}.Show();
}
internal void ExecuteAboutCommand() internal void ExecuteAboutCommand()
{ {
var dialog = new AboutDialog(); var dialog = new AboutDialog();
@@ -381,7 +390,7 @@ namespace Aaru.Gui.ViewModels
: _genericFolderIcon, : _genericFolderIcon,
FileName = Path.GetFileName(result[0]), Image = imageFormat, FileName = Path.GetFileName(result[0]), Image = imageFormat,
ViewModel = new ImageInfoViewModel(result[0], inputFilter, imageFormat, _view), ViewModel = new ImageInfoViewModel(result[0], inputFilter, imageFormat, _view),
Filter = inputFilter Filter = inputFilter
}; };
// TODO: pnlImageInfo // TODO: pnlImageInfo
@@ -419,7 +428,8 @@ namespace Aaru.Gui.ViewModels
var partitionModel = new PartitionModel var partitionModel = new PartitionModel
{ {
// TODO: Add icons to partition types // TODO: Add icons to partition types
Name = $"{partition.Name} ({partition.Type})", Partition = partition Name = $"{partition.Name} ({partition.Type})", Partition = partition,
ViewModel = new PartitionViewModel(partition)
}; };
AaruConsole.WriteLine("Identifying filesystem on partition"); AaruConsole.WriteLine("Identifying filesystem on partition");

View File

@@ -0,0 +1,24 @@
using Aaru.CommonTypes;
namespace Aaru.Gui.ViewModels
{
public class PartitionViewModel
{
public PartitionViewModel(Partition partition)
{
NameText = $"Partition name: {partition.Name}";
TypeText = $"Partition type: {partition.Type}";
StartText = $"Partition start: sector {partition.Start}, byte {partition.Offset}";
LengthText = $"Partition length: {partition.Length} sectors, {partition.Size} bytes";
DescriptionLabelText = "Partition description:";
DescriptionText = partition.Description;
}
public string NameText { get; }
public string TypeText { get; }
public string StartText { get; }
public string LengthText { get; }
public string DescriptionLabelText { get; }
public string DescriptionText { get; }
}
}