2020-04-10 18:52:50 +01:00
|
|
|
|
using System.Linq;
|
|
|
|
|
|
using System.Reactive;
|
|
|
|
|
|
using Aaru.Database;
|
2020-04-10 01:10:55 +01:00
|
|
|
|
using Aaru.Gui.Views;
|
2020-04-09 18:18:56 +01:00
|
|
|
|
using Avalonia;
|
|
|
|
|
|
using Avalonia.Controls;
|
|
|
|
|
|
using Avalonia.Controls.ApplicationLifetimes;
|
2020-04-10 18:52:50 +01:00
|
|
|
|
using MessageBox.Avalonia;
|
2020-04-10 01:10:55 +01:00
|
|
|
|
using ReactiveUI;
|
2020-04-09 18:18:56 +01:00
|
|
|
|
|
|
|
|
|
|
namespace Aaru.Gui.ViewModels
|
2020-04-09 02:26:04 +01:00
|
|
|
|
{
|
|
|
|
|
|
public class MainWindowViewModel : ViewModelBase
|
|
|
|
|
|
{
|
2020-04-10 01:10:55 +01:00
|
|
|
|
readonly MainWindow _view;
|
|
|
|
|
|
|
|
|
|
|
|
public MainWindowViewModel(MainWindow view)
|
|
|
|
|
|
{
|
2020-04-10 18:52:50 +01:00
|
|
|
|
AboutCommand = ReactiveCommand.Create(ExecuteAboutCommand);
|
|
|
|
|
|
EncodingsCommand = ReactiveCommand.Create(ExecuteEncodingsCommand);
|
|
|
|
|
|
PluginsCommand = ReactiveCommand.Create(ExecutePluginsCommand);
|
|
|
|
|
|
StatisticsCommand = ReactiveCommand.Create(ExecuteStatisticsCommand);
|
2020-04-10 22:33:27 +01:00
|
|
|
|
ExitCommand = ReactiveCommand.Create(ExecuteExitCommand);
|
|
|
|
|
|
SettingsCommand = ReactiveCommand.Create(ExecuteSettingsCommand);
|
2020-04-10 18:52:50 +01:00
|
|
|
|
_view = view;
|
2020-04-10 01:10:55 +01:00
|
|
|
|
}
|
|
|
|
|
|
|
2020-04-09 04:18:29 +01:00
|
|
|
|
public string Greeting => "Welcome to Aaru!";
|
2020-04-09 18:18:56 +01:00
|
|
|
|
|
2020-04-11 01:31:12 +01:00
|
|
|
|
public bool NativeMenuSupported =>
|
|
|
|
|
|
NativeMenu.GetIsNativeMenuExported((Application.Current.ApplicationLifetime as
|
2020-04-10 01:10:55 +01:00
|
|
|
|
IClassicDesktopStyleApplicationLifetime)?.MainWindow);
|
|
|
|
|
|
|
2020-04-10 18:52:50 +01:00
|
|
|
|
public ReactiveCommand<Unit, Unit> AboutCommand { get; }
|
|
|
|
|
|
public ReactiveCommand<Unit, Unit> EncodingsCommand { get; }
|
|
|
|
|
|
public ReactiveCommand<Unit, Unit> PluginsCommand { get; }
|
|
|
|
|
|
public ReactiveCommand<Unit, Unit> StatisticsCommand { get; }
|
2020-04-10 22:33:27 +01:00
|
|
|
|
public ReactiveCommand<Unit, Unit> ExitCommand { get; }
|
|
|
|
|
|
public ReactiveCommand<Unit, Unit> SettingsCommand { get; }
|
2020-04-10 01:10:55 +01:00
|
|
|
|
|
|
|
|
|
|
internal void ExecuteAboutCommand()
|
|
|
|
|
|
{
|
|
|
|
|
|
var dialog = new AboutDialog();
|
|
|
|
|
|
dialog.DataContext = new AboutDialogViewModel(dialog);
|
|
|
|
|
|
dialog.ShowDialog(_view);
|
|
|
|
|
|
}
|
2020-04-10 02:50:38 +01:00
|
|
|
|
|
|
|
|
|
|
internal void ExecuteEncodingsCommand()
|
|
|
|
|
|
{
|
|
|
|
|
|
var dialog = new EncodingsDialog();
|
|
|
|
|
|
dialog.DataContext = new EncodingsDialogViewModel(dialog);
|
|
|
|
|
|
dialog.ShowDialog(_view);
|
|
|
|
|
|
}
|
2020-04-10 04:16:48 +01:00
|
|
|
|
|
|
|
|
|
|
internal void ExecutePluginsCommand()
|
|
|
|
|
|
{
|
|
|
|
|
|
var dialog = new PluginsDialog();
|
|
|
|
|
|
dialog.DataContext = new PluginsDialogViewModel(dialog);
|
|
|
|
|
|
dialog.ShowDialog(_view);
|
|
|
|
|
|
}
|
2020-04-10 18:52:50 +01:00
|
|
|
|
|
|
|
|
|
|
internal void ExecuteStatisticsCommand()
|
|
|
|
|
|
{
|
|
|
|
|
|
using var ctx = AaruContext.Create(Settings.Settings.LocalDbPath);
|
|
|
|
|
|
|
|
|
|
|
|
if(!ctx.Commands.Any() &&
|
|
|
|
|
|
!ctx.Filesystems.Any() &&
|
|
|
|
|
|
!ctx.Filters.Any() &&
|
|
|
|
|
|
!ctx.MediaFormats.Any() &&
|
|
|
|
|
|
!ctx.Medias.Any() &&
|
|
|
|
|
|
!ctx.Partitions.Any() &&
|
|
|
|
|
|
!ctx.SeenDevices.Any())
|
|
|
|
|
|
{
|
|
|
|
|
|
MessageBoxManager.GetMessageBoxStandardWindow("Warning", "There are no statistics.").ShowDialog(_view);
|
|
|
|
|
|
|
|
|
|
|
|
return;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
var dialog = new StatisticsDialog();
|
|
|
|
|
|
dialog.DataContext = new StatisticsDialogViewModel(dialog);
|
|
|
|
|
|
dialog.ShowDialog(_view);
|
|
|
|
|
|
}
|
2020-04-10 19:11:19 +01:00
|
|
|
|
|
2020-04-10 22:33:27 +01:00
|
|
|
|
internal async void ExecuteSettingsCommand()
|
|
|
|
|
|
{
|
|
|
|
|
|
var dialog = new SettingsDialog();
|
|
|
|
|
|
dialog.DataContext = new SettingsDialogViewModel(dialog, false);
|
|
|
|
|
|
await dialog.ShowDialog(_view);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
internal void ExecuteExitCommand() =>
|
|
|
|
|
|
(Application.Current.ApplicationLifetime as ClassicDesktopStyleApplicationLifetime)?.Shutdown();
|
2020-04-09 02:26:04 +01:00
|
|
|
|
}
|
2020-04-09 04:18:29 +01:00
|
|
|
|
}
|