diff --git a/Aaru.Tui/App.axaml.cs b/Aaru.Tui/App.axaml.cs index bc884775e..82e36c742 100644 --- a/Aaru.Tui/App.axaml.cs +++ b/Aaru.Tui/App.axaml.cs @@ -16,10 +16,12 @@ public class App : Application public override void OnFrameworkInitializationCompleted() { if(ApplicationLifetime is IClassicDesktopStyleApplicationLifetime desktopLifetime) - desktopLifetime.MainWindow = new MainWindow - { - DataContext = new MainWindowViewModel() - }; + { + var mainWindow = new MainWindow(); + var vm = new MainWindowViewModel(mainWindow); + mainWindow.DataContext = vm; + desktopLifetime.MainWindow = mainWindow; + } base.OnFrameworkInitializationCompleted(); } diff --git a/Aaru.Tui/Models/FileSystemModelNode.cs b/Aaru.Tui/Models/FileSystemModelNode.cs index 4317b7578..8d5707469 100644 --- a/Aaru.Tui/Models/FileSystemModelNode.cs +++ b/Aaru.Tui/Models/FileSystemModelNode.cs @@ -1,5 +1,6 @@ using System.Collections.ObjectModel; using Aaru.CommonTypes; +using Aaru.CommonTypes.Interfaces; namespace Aaru.Tui.Models; @@ -13,7 +14,8 @@ public class FileSystemModelNode SubNodes = subNodes; } - public ObservableCollection? SubNodes { get; } - public string Title { get; } - public Partition? Partition { get; set; } + public ObservableCollection? SubNodes { get; set; } + public string Title { get; } + public Partition? Partition { get; set; } + public IFilesystem? Filesystem { get; set; } } \ No newline at end of file diff --git a/Aaru.Tui/ViewModels/Windows/ImageWindowViewModel.cs b/Aaru.Tui/ViewModels/Windows/ImageWindowViewModel.cs index 67d637145..f29f30ea9 100644 --- a/Aaru.Tui/ViewModels/Windows/ImageWindowViewModel.cs +++ b/Aaru.Tui/ViewModels/Windows/ImageWindowViewModel.cs @@ -15,6 +15,7 @@ public sealed partial class ImageWindowViewModel : ViewModelBase { readonly string _filename; readonly IMediaImage _imageFormat; + readonly Window _parent; readonly Window _view; [ObservableProperty] bool _isStatusVisible; @@ -23,11 +24,12 @@ public sealed partial class ImageWindowViewModel : ViewModelBase [ObservableProperty] string? _status; - public ImageWindowViewModel(Window view, IMediaImage imageFormat, string filename) + public ImageWindowViewModel(Window parent, Window view, IMediaImage imageFormat, string filename) { _imageFormat = imageFormat; _filename = filename; _view = view; + _parent = parent; ExitCommand = new RelayCommand(Exit); BackCommand = new RelayCommand(Back); @@ -38,6 +40,7 @@ public sealed partial class ImageWindowViewModel : ViewModelBase void Back() { + _parent.Show(); _view.Close(); } @@ -73,6 +76,10 @@ public sealed partial class ImageWindowViewModel : ViewModelBase var sequence = 0; + Status = "Loading filesystems..."; + + PluginRegister plugins = PluginRegister.Singleton; + foreach(Partition partition in partitionsList) { var node = new FileSystemModelNode(partition.Name ?? $"Partition {sequence}") @@ -80,6 +87,25 @@ public sealed partial class ImageWindowViewModel : ViewModelBase Partition = partition }; + Core.Filesystems.Identify(_imageFormat, out List? idPlugins, partition); + + if(idPlugins.Count > 0) + { + var subNodes = new ObservableCollection(); + + foreach(string pluginName in idPlugins) + { + if(!plugins.Filesystems.TryGetValue(pluginName, out IFilesystem? fs)) continue; + if(fs is null) continue; + + var fsNode = new FileSystemModelNode(fs.Name); + fsNode.Filesystem = fs; + subNodes.Add(fsNode); + } + + node.SubNodes = subNodes; + } + Nodes.Add(node); sequence++; } diff --git a/Aaru.Tui/ViewModels/Windows/MainWindowViewModel.cs b/Aaru.Tui/ViewModels/Windows/MainWindowViewModel.cs index 0db1852b6..002685547 100644 --- a/Aaru.Tui/ViewModels/Windows/MainWindowViewModel.cs +++ b/Aaru.Tui/ViewModels/Windows/MainWindowViewModel.cs @@ -10,6 +10,7 @@ using Aaru.Helpers; using Aaru.Tui.Models; using Aaru.Tui.Views.Windows; using Avalonia; +using Avalonia.Controls; using Avalonia.Controls.ApplicationLifetimes; using Avalonia.Media; using CommunityToolkit.Mvvm.ComponentModel; @@ -22,6 +23,7 @@ namespace Aaru.Tui.ViewModels.Windows; public sealed partial class MainWindowViewModel : ViewModelBase { + readonly Window _view; [ObservableProperty] string _copyright; [ObservableProperty] @@ -36,8 +38,9 @@ public sealed partial class MainWindowViewModel : ViewModelBase [ObservableProperty] string _status; - public MainWindowViewModel() + public MainWindowViewModel(Window view) { + _view = view; ExitCommand = new RelayCommand(Exit); OpenSelectedFileCommand = new RelayCommand(OpenSelectedFile, CanOpenSelectedFile); @@ -300,10 +303,14 @@ public sealed partial class MainWindowViewModel : ViewModelBase if(SelectedFile.ImageFormat is null) return; - var imageWindow = new ImageWindow(); - var imageViewModel = new ImageWindowViewModel(imageWindow, SelectedFile.ImageFormat, SelectedFile.Filename); + var imageWindow = new ImageWindow(); + + var imageViewModel = + new ImageWindowViewModel(_view, imageWindow, SelectedFile.ImageFormat, SelectedFile.Filename); + imageWindow.DataContext = imageViewModel; imageWindow.Show(); + _view.Hide(); } bool CanOpenSelectedFile() => SelectedFile != null; diff --git a/Aaru.Tui/Views/Windows/MainWindow.axaml.cs b/Aaru.Tui/Views/Windows/MainWindow.axaml.cs index 4382e3b7b..5f2158709 100644 --- a/Aaru.Tui/Views/Windows/MainWindow.axaml.cs +++ b/Aaru.Tui/Views/Windows/MainWindow.axaml.cs @@ -5,13 +5,15 @@ using Avalonia.Interactivity; namespace Aaru.Tui.Views.Windows; -public partial class MainWindow : Window +public class MainWindow : Window { public MainWindow() { InitializeComponent(); } + public MainWindow(object? dataContext) : this() => DataContext = dataContext; + private void ListBox_OnKeyDown(object sender, KeyEventArgs e) { if(e.Key == Key.Enter)