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

@@ -38,131 +38,31 @@ namespace Aaru.Gui.ViewModels
readonly ImagesRootModel _imagesRoot;
readonly MainWindow _view;
ConsoleWindow _consoleWindow;
public object _contentPanel;
bool _devicesSupported;
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 object _contentPanel;
bool _devicesSupported;
public object _treeViewSelectedItem;
public MainWindowViewModel(MainWindow view)
{
AboutCommand = ReactiveCommand.Create(ExecuteAboutCommand);
EncodingsCommand = ReactiveCommand.Create(ExecuteEncodingsCommand);
PluginsCommand = ReactiveCommand.Create(ExecutePluginsCommand);
StatisticsCommand = ReactiveCommand.Create(ExecuteStatisticsCommand);
ExitCommand = ReactiveCommand.Create(ExecuteExitCommand);
SettingsCommand = ReactiveCommand.Create(ExecuteSettingsCommand);
ConsoleCommand = ReactiveCommand.Create(ExecuteConsoleCommand);
OpenCommand = ReactiveCommand.Create(ExecuteOpenCommand);
CalculateEntropyCommand = ReactiveCommand.Create(ExecuteCalculateEntropyCommand);
VerifyImageCommand = ReactiveCommand.Create(ExecuteVerifyImageCommand);
ChecksumImageCommand = ReactiveCommand.Create(ExecuteChecksumImageCommand);
ConvertImageCommand = ReactiveCommand.Create(ExecuteConvertImageCommand);
CreateSidecarCommand = ReactiveCommand.Create(ExecuteCreateSidecarCommand);
ViewImageSectorsCommand = ReactiveCommand.Create(ExecuteViewImageSectorsCommand);
AboutCommand = ReactiveCommand.Create(ExecuteAboutCommand);
EncodingsCommand = ReactiveCommand.Create(ExecuteEncodingsCommand);
PluginsCommand = ReactiveCommand.Create(ExecutePluginsCommand);
StatisticsCommand = ReactiveCommand.Create(ExecuteStatisticsCommand);
ExitCommand = ReactiveCommand.Create(ExecuteExitCommand);
SettingsCommand = ReactiveCommand.Create(ExecuteSettingsCommand);
ConsoleCommand = ReactiveCommand.Create(ExecuteConsoleCommand);
OpenCommand = ReactiveCommand.Create(ExecuteOpenCommand);
CalculateEntropyCommand = ReactiveCommand.Create(ExecuteCalculateEntropyCommand);
VerifyImageCommand = ReactiveCommand.Create(ExecuteVerifyImageCommand);
ChecksumImageCommand = ReactiveCommand.Create(ExecuteChecksumImageCommand);
ConvertImageCommand = ReactiveCommand.Create(ExecuteConvertImageCommand);
CreateSidecarCommand = ReactiveCommand.Create(ExecuteCreateSidecarCommand);
ViewImageSectorsCommand = ReactiveCommand.Create(ExecuteViewImageSectorsCommand);
DecodeImageMediaTagsCommand = ReactiveCommand.Create(ExecuteDecodeImageMediaTagsCommand);
_view = view;
TreeRoot = new ObservableCollection<RootModel>();
_assets = AvaloniaLocator.Current.GetService<IAssetLoader>();
ContentPanel = Greeting;
_view = view;
TreeRoot = new ObservableCollection<RootModel>();
_assets = AvaloniaLocator.Current.GetService<IAssetLoader>();
ContentPanel = Greeting;
_imagesRoot = new ImagesRootModel
{
@@ -210,23 +110,23 @@ namespace Aaru.Gui.ViewModels
NativeMenu.GetIsNativeMenuExported((Application.Current.ApplicationLifetime as
IClassicDesktopStyleApplicationLifetime)?.MainWindow);
public string Greeting => "Welcome to Aaru!";
public ObservableCollection<RootModel> TreeRoot { get; }
public ReactiveCommand<Unit, Unit> AboutCommand { get; }
public ReactiveCommand<Unit, Unit> ConsoleCommand { get; }
public ReactiveCommand<Unit, Unit> EncodingsCommand { get; }
public ReactiveCommand<Unit, Unit> PluginsCommand { get; }
public ReactiveCommand<Unit, Unit> StatisticsCommand { get; }
public ReactiveCommand<Unit, Unit> ExitCommand { get; }
public ReactiveCommand<Unit, Unit> SettingsCommand { get; }
public ReactiveCommand<Unit, Unit> OpenCommand { get; }
public ReactiveCommand<Unit, Unit> CalculateEntropyCommand { get; }
public ReactiveCommand<Unit, Unit> VerifyImageCommand { get; }
public ReactiveCommand<Unit, Unit> ChecksumImageCommand { get; }
public ReactiveCommand<Unit, Unit> ConvertImageCommand { get; }
public ReactiveCommand<Unit, Unit> CreateSidecarCommand { get; }
public ReactiveCommand<Unit, Unit> ViewImageSectorsCommand { get; }
public ReactiveCommand<Unit, Unit> DecodeImageMediaTagsCommand { get; }
public string Greeting => "Welcome to Aaru!";
public ObservableCollection<RootModel> TreeRoot { get; }
public ReactiveCommand<Unit, Unit> AboutCommand { get; }
public ReactiveCommand<Unit, Unit> ConsoleCommand { get; }
public ReactiveCommand<Unit, Unit> EncodingsCommand { get; }
public ReactiveCommand<Unit, Unit> PluginsCommand { get; }
public ReactiveCommand<Unit, Unit> StatisticsCommand { get; }
public ReactiveCommand<Unit, Unit> ExitCommand { get; }
public ReactiveCommand<Unit, Unit> SettingsCommand { get; }
public ReactiveCommand<Unit, Unit> OpenCommand { get; }
public ReactiveCommand<Unit, Unit> CalculateEntropyCommand { get; }
public ReactiveCommand<Unit, Unit> VerifyImageCommand { get; }
public ReactiveCommand<Unit, Unit> ChecksumImageCommand { get; }
public ReactiveCommand<Unit, Unit> ConvertImageCommand { get; }
public ReactiveCommand<Unit, Unit> CreateSidecarCommand { get; }
public ReactiveCommand<Unit, Unit> ViewImageSectorsCommand { get; }
public ReactiveCommand<Unit, Unit> DecodeImageMediaTagsCommand { get; }
public object ContentPanel
{
@@ -248,10 +148,119 @@ namespace Aaru.Gui.ViewModels
DataContext = imageModel.ViewModel
};
if(value is PartitionModel partitionModel)
ContentPanel = new PartitionPanel
{
DataContext = partitionModel.ViewModel
};
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()
{
var dialog = new AboutDialog();
@@ -381,7 +390,7 @@ namespace Aaru.Gui.ViewModels
: _genericFolderIcon,
FileName = Path.GetFileName(result[0]), Image = imageFormat,
ViewModel = new ImageInfoViewModel(result[0], inputFilter, imageFormat, _view),
Filter = inputFilter
Filter = inputFilter
};
// TODO: pnlImageInfo
@@ -419,7 +428,8 @@ namespace Aaru.Gui.ViewModels
var partitionModel = new PartitionModel
{
// 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");