2020-04-11 21:04:20 +01:00
|
|
|
using System.Collections.ObjectModel;
|
2020-04-11 04:35:38 +01:00
|
|
|
using System.Linq;
|
2022-03-26 16:52:00 +00:00
|
|
|
using System.Threading.Tasks;
|
2025-08-20 21:19:43 +01:00
|
|
|
using System.Windows.Input;
|
2020-04-11 04:35:38 +01:00
|
|
|
using Aaru.CommonTypes.Interop;
|
2020-04-10 18:52:50 +01:00
|
|
|
using Aaru.Database;
|
2020-04-11 04:35:38 +01:00
|
|
|
using Aaru.Gui.Models;
|
2020-04-16 20:40:25 +01:00
|
|
|
using Aaru.Gui.ViewModels.Dialogs;
|
|
|
|
|
using Aaru.Gui.Views.Dialogs;
|
2022-11-19 21:10:41 +00:00
|
|
|
using Aaru.Localization;
|
2020-04-09 18:18:56 +01:00
|
|
|
using Avalonia;
|
|
|
|
|
using Avalonia.Controls;
|
|
|
|
|
using Avalonia.Controls.ApplicationLifetimes;
|
2025-10-25 14:38:04 +01:00
|
|
|
using CommunityToolkit.Mvvm.ComponentModel;
|
2025-08-20 21:19:43 +01:00
|
|
|
using CommunityToolkit.Mvvm.Input;
|
2023-09-26 01:29:07 +01:00
|
|
|
using MsBox.Avalonia;
|
2025-08-17 05:50:25 +01:00
|
|
|
using Console = Aaru.Gui.Views.Dialogs.Console;
|
2020-04-11 21:04:20 +01:00
|
|
|
using PlatformID = Aaru.CommonTypes.Interop.PlatformID;
|
2020-04-09 18:18:56 +01:00
|
|
|
|
2022-11-15 15:58:43 +00:00
|
|
|
namespace Aaru.Gui.ViewModels.Windows;
|
|
|
|
|
|
2025-10-25 14:38:04 +01:00
|
|
|
public partial class MainWindowViewModel : ViewModelBase
|
2020-04-09 02:26:04 +01:00
|
|
|
{
|
2025-10-25 14:38:04 +01:00
|
|
|
readonly Window _view;
|
|
|
|
|
Console _console;
|
|
|
|
|
[ObservableProperty]
|
|
|
|
|
object _contentPanel;
|
|
|
|
|
[ObservableProperty]
|
|
|
|
|
bool _devicesSupported;
|
|
|
|
|
[ObservableProperty]
|
|
|
|
|
ObservableCollection<RootModel> _treeRoot;
|
|
|
|
|
object _treeViewSelectedItem;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public MainWindowViewModel(Window view)
|
|
|
|
|
{
|
|
|
|
|
AboutCommand = new AsyncRelayCommand(AboutAsync);
|
|
|
|
|
EncodingsCommand = new AsyncRelayCommand(EncodingsAsync);
|
|
|
|
|
PluginsCommand = new AsyncRelayCommand(PluginsAsync);
|
|
|
|
|
StatisticsCommand = new AsyncRelayCommand(StatisticsAsync);
|
|
|
|
|
ExitCommand = new RelayCommand(Exit);
|
|
|
|
|
SettingsCommand = new AsyncRelayCommand(SettingsAsync);
|
|
|
|
|
ConsoleCommand = new RelayCommand(Console);
|
|
|
|
|
OpenCommand = new AsyncRelayCommand(OpenAsync);
|
2020-04-14 19:58:23 +01:00
|
|
|
|
2022-03-06 13:29:38 +00:00
|
|
|
switch(DetectOS.GetRealPlatformID())
|
|
|
|
|
{
|
|
|
|
|
case PlatformID.Win32NT:
|
|
|
|
|
case PlatformID.Linux:
|
|
|
|
|
case PlatformID.FreeBSD:
|
|
|
|
|
DevicesSupported = true;
|
2020-04-14 19:58:23 +01:00
|
|
|
|
2022-03-06 13:29:38 +00:00
|
|
|
break;
|
|
|
|
|
}
|
2020-04-14 19:58:23 +01:00
|
|
|
|
2025-10-25 14:38:04 +01:00
|
|
|
TreeRoot =
|
|
|
|
|
[
|
|
|
|
|
new RootModel
|
|
|
|
|
{
|
|
|
|
|
Name = "Nothing opened."
|
|
|
|
|
}
|
|
|
|
|
];
|
2020-04-14 22:32:47 +01:00
|
|
|
|
2025-10-25 14:38:04 +01:00
|
|
|
_view = view;
|
2022-03-06 13:29:38 +00:00
|
|
|
}
|
2020-04-14 19:58:23 +01:00
|
|
|
|
2025-10-25 14:38:04 +01:00
|
|
|
public ICommand OpenCommand { get; }
|
|
|
|
|
public ICommand SettingsCommand { get; }
|
|
|
|
|
public ICommand ExitCommand { get; }
|
|
|
|
|
public ICommand ConsoleCommand { get; }
|
|
|
|
|
public ICommand EncodingsCommand { get; }
|
|
|
|
|
public ICommand PluginsCommand { get; }
|
|
|
|
|
public ICommand StatisticsCommand { get; }
|
|
|
|
|
public ICommand AboutCommand { get; }
|
2020-04-14 19:58:23 +01:00
|
|
|
|
2023-10-04 09:55:17 +01:00
|
|
|
public bool NativeMenuSupported
|
|
|
|
|
{
|
|
|
|
|
get
|
|
|
|
|
{
|
2024-05-01 04:05:22 +01:00
|
|
|
Window mainWindow = (Application.Current?.ApplicationLifetime as IClassicDesktopStyleApplicationLifetime)
|
|
|
|
|
?.MainWindow;
|
|
|
|
|
|
2023-10-04 09:55:17 +01:00
|
|
|
return mainWindow is not null && NativeMenu.GetIsNativeMenuExported(mainWindow);
|
|
|
|
|
}
|
|
|
|
|
}
|
2022-03-06 13:29:38 +00:00
|
|
|
|
|
|
|
|
public object TreeViewSelectedItem
|
|
|
|
|
{
|
|
|
|
|
get => _treeViewSelectedItem;
|
2025-10-25 14:38:04 +01:00
|
|
|
set => SetProperty(ref _treeViewSelectedItem, value);
|
2022-03-06 13:29:38 +00:00
|
|
|
}
|
2020-04-14 19:27:07 +01:00
|
|
|
|
2025-10-25 14:38:04 +01:00
|
|
|
Task OpenAsync() =>
|
2020-04-14 19:27:07 +01:00
|
|
|
|
2025-10-25 14:38:04 +01:00
|
|
|
// TODO
|
|
|
|
|
null;
|
2020-04-14 19:27:07 +01:00
|
|
|
|
2025-10-25 14:38:04 +01:00
|
|
|
Task AboutAsync()
|
2022-03-06 13:29:38 +00:00
|
|
|
{
|
|
|
|
|
var dialog = new About();
|
|
|
|
|
dialog.DataContext = new AboutViewModel(dialog);
|
2025-10-25 14:38:04 +01:00
|
|
|
|
|
|
|
|
return dialog.ShowDialog(_view);
|
2022-03-06 13:29:38 +00:00
|
|
|
}
|
2020-04-10 01:10:55 +01:00
|
|
|
|
2025-10-25 14:38:04 +01:00
|
|
|
Task EncodingsAsync()
|
2022-03-06 13:29:38 +00:00
|
|
|
{
|
|
|
|
|
var dialog = new Encodings();
|
|
|
|
|
dialog.DataContext = new EncodingsViewModel(dialog);
|
2025-10-25 14:38:04 +01:00
|
|
|
|
|
|
|
|
return dialog.ShowDialog(_view);
|
2022-03-06 13:29:38 +00:00
|
|
|
}
|
2020-04-10 02:50:38 +01:00
|
|
|
|
2025-10-25 14:38:04 +01:00
|
|
|
Task PluginsAsync()
|
2022-03-06 13:29:38 +00:00
|
|
|
{
|
|
|
|
|
var dialog = new PluginsDialog();
|
|
|
|
|
dialog.DataContext = new PluginsViewModel(dialog);
|
2025-10-25 14:38:04 +01:00
|
|
|
|
|
|
|
|
return dialog.ShowDialog(_view);
|
2022-03-06 13:29:38 +00:00
|
|
|
}
|
2020-04-10 04:16:48 +01:00
|
|
|
|
2025-10-25 14:38:04 +01:00
|
|
|
async Task StatisticsAsync()
|
2022-03-06 13:29:38 +00:00
|
|
|
{
|
2025-10-25 14:38:04 +01:00
|
|
|
await using var ctx = AaruContext.Create(Settings.Settings.LocalDbPath);
|
2022-03-06 13:29:38 +00:00
|
|
|
|
|
|
|
|
if(!ctx.Commands.Any() &&
|
|
|
|
|
!ctx.Filesystems.Any() &&
|
|
|
|
|
!ctx.Filters.Any() &&
|
|
|
|
|
!ctx.MediaFormats.Any() &&
|
|
|
|
|
!ctx.Medias.Any() &&
|
|
|
|
|
!ctx.Partitions.Any() &&
|
|
|
|
|
!ctx.SeenDevices.Any())
|
2020-04-10 04:16:48 +01:00
|
|
|
{
|
2025-10-25 14:38:04 +01:00
|
|
|
await MessageBoxManager.GetMessageBoxStandard(UI.Title_Warning, UI.There_are_no_statistics)
|
|
|
|
|
.ShowWindowDialogAsync(_view);
|
2022-03-06 13:29:38 +00:00
|
|
|
|
|
|
|
|
return;
|
2020-04-10 04:16:48 +01:00
|
|
|
}
|
2020-04-10 18:52:50 +01:00
|
|
|
|
2022-03-06 13:29:38 +00:00
|
|
|
var dialog = new StatisticsDialog();
|
|
|
|
|
dialog.DataContext = new StatisticsViewModel(dialog);
|
2025-10-25 14:38:04 +01:00
|
|
|
await dialog.ShowDialog(_view);
|
2022-03-06 13:29:38 +00:00
|
|
|
}
|
2020-04-10 18:52:50 +01:00
|
|
|
|
2025-10-25 14:38:04 +01:00
|
|
|
Task SettingsAsync()
|
2022-03-06 13:29:38 +00:00
|
|
|
{
|
|
|
|
|
var dialog = new SettingsDialog();
|
|
|
|
|
dialog.DataContext = new SettingsViewModel(dialog, false);
|
2025-10-25 14:38:04 +01:00
|
|
|
|
|
|
|
|
return dialog.ShowDialog(_view);
|
2022-03-06 13:29:38 +00:00
|
|
|
}
|
2020-04-10 18:52:50 +01:00
|
|
|
|
2025-10-25 14:38:04 +01:00
|
|
|
void Exit() => (Application.Current?.ApplicationLifetime as ClassicDesktopStyleApplicationLifetime)?.Shutdown();
|
2020-04-10 19:11:19 +01:00
|
|
|
|
2025-08-20 21:19:43 +01:00
|
|
|
void Console()
|
2022-03-06 13:29:38 +00:00
|
|
|
{
|
|
|
|
|
if(_console is null)
|
2020-04-10 22:33:27 +01:00
|
|
|
{
|
2025-08-17 05:50:25 +01:00
|
|
|
_console = new Console();
|
2022-03-06 13:29:38 +00:00
|
|
|
_console.DataContext = new ConsoleViewModel(_console);
|
2020-04-10 22:33:27 +01:00
|
|
|
}
|
|
|
|
|
|
2022-03-06 13:29:38 +00:00
|
|
|
_console.Show();
|
|
|
|
|
}
|
2020-04-09 04:18:29 +01:00
|
|
|
}
|