Files
Aaru/Aaru.Gui/ViewModels/Windows/MainWindowViewModel.cs

165 lines
4.5 KiB
C#
Raw Normal View History

using System.Collections.ObjectModel;
2020-04-11 04:35:38 +01:00
using System.Linq;
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;
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;
using Aaru.Localization;
2020-04-09 18:18:56 +01:00
using Avalonia;
using Avalonia.Controls;
using Avalonia.Controls.ApplicationLifetimes;
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;
using Console = Aaru.Gui.Views.Dialogs.Console;
using PlatformID = Aaru.CommonTypes.Interop.PlatformID;
2020-04-09 18:18:56 +01:00
namespace Aaru.Gui.ViewModels.Windows;
public partial class MainWindowViewModel : ViewModelBase
2020-04-09 02:26: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);
2022-03-06 13:29:38 +00:00
switch(DetectOS.GetRealPlatformID())
{
case PlatformID.Win32NT:
case PlatformID.Linux:
case PlatformID.FreeBSD:
DevicesSupported = true;
2022-03-06 13:29:38 +00:00
break;
}
TreeRoot =
[
new RootModel
{
Name = "Nothing opened."
}
];
_view = view;
2022-03-06 13:29:38 +00: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; }
public bool NativeMenuSupported
{
get
{
2024-05-01 04:05:22 +01:00
Window mainWindow = (Application.Current?.ApplicationLifetime as IClassicDesktopStyleApplicationLifetime)
?.MainWindow;
return mainWindow is not null && NativeMenu.GetIsNativeMenuExported(mainWindow);
}
}
2022-03-06 13:29:38 +00:00
public object TreeViewSelectedItem
{
get => _treeViewSelectedItem;
set => SetProperty(ref _treeViewSelectedItem, value);
2022-03-06 13:29:38 +00:00
}
2020-04-14 19:27:07 +01:00
Task OpenAsync() =>
2020-04-14 19:27:07 +01:00
// TODO
null;
2020-04-14 19:27:07 +01:00
Task AboutAsync()
2022-03-06 13:29:38 +00:00
{
var dialog = new About();
dialog.DataContext = new AboutViewModel(dialog);
return dialog.ShowDialog(_view);
2022-03-06 13:29:38 +00:00
}
2020-04-10 01:10:55 +01:00
Task EncodingsAsync()
2022-03-06 13:29:38 +00:00
{
var dialog = new Encodings();
dialog.DataContext = new EncodingsViewModel(dialog);
return dialog.ShowDialog(_view);
2022-03-06 13:29:38 +00:00
}
Task PluginsAsync()
2022-03-06 13:29:38 +00:00
{
var dialog = new PluginsDialog();
dialog.DataContext = new PluginsViewModel(dialog);
return dialog.ShowDialog(_view);
2022-03-06 13:29:38 +00:00
}
async Task StatisticsAsync()
2022-03-06 13:29:38 +00: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())
{
await MessageBoxManager.GetMessageBoxStandard(UI.Title_Warning, UI.There_are_no_statistics)
.ShowWindowDialogAsync(_view);
2022-03-06 13:29:38 +00:00
return;
}
2022-03-06 13:29:38 +00:00
var dialog = new StatisticsDialog();
dialog.DataContext = new StatisticsViewModel(dialog);
await dialog.ShowDialog(_view);
2022-03-06 13:29:38 +00:00
}
Task SettingsAsync()
2022-03-06 13:29:38 +00:00
{
var dialog = new SettingsDialog();
dialog.DataContext = new SettingsViewModel(dialog, false);
return dialog.ShowDialog(_view);
2022-03-06 13:29:38 +00: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)
{
_console = new Console();
2022-03-06 13:29:38 +00:00
_console.DataContext = new ConsoleViewModel(_console);
}
2022-03-06 13:29:38 +00:00
_console.Show();
}
2020-04-09 04:18:29 +01:00
}