Files
Aaru/Aaru.Gui/App.xaml.cs

118 lines
4.2 KiB
C#
Raw Normal View History

2020-04-17 21:45:50 +01:00
// /***************************************************************************
// Aaru Data Preservation Suite
// ----------------------------------------------------------------------------
//
// Filename : App.xaml.cs
// Author(s) : Natalia Portillo <claunia@claunia.com>
//
// Component : GUI.
//
// --[ Description ] ----------------------------------------------------------
//
// GUI initialization and globals.
//
// --[ License ] --------------------------------------------------------------
//
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU General public License as
// published by the Free Software Foundation, either version 3 of the
// License, or (at your option) any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General public License for more details.
//
// You should have received a copy of the GNU General public License
// along with this program. If not, see <http://www.gnu.org/licenses/>.
//
// ----------------------------------------------------------------------------
2022-02-18 10:02:53 +00:00
// Copyright © 2011-2022 Natalia Portillo
2020-04-17 21:45:50 +01:00
// ****************************************************************************/
2022-03-07 07:36:44 +00:00
// ReSharper disable UnusedMember.Local
// ReSharper disable UnusedParameter.Local
namespace Aaru.Gui;
2020-04-17 21:45:50 +01:00
using System;
2020-04-16 20:40:25 +01:00
using Aaru.Gui.ViewModels.Windows;
using Aaru.Gui.Views.Windows;
2020-04-09 02:26:04 +01:00
using Avalonia;
2020-04-09 04:18:29 +01:00
using Avalonia.Controls;
2020-04-09 02:26:04 +01:00
using Avalonia.Controls.ApplicationLifetimes;
using Avalonia.Markup.Xaml;
2022-03-06 13:29:38 +00:00
public sealed class App : Application
2020-04-09 02:26:04 +01:00
{
2022-03-06 13:29:38 +00:00
public override void Initialize() => AvaloniaXamlLoader.Load(this);
2020-04-09 02:26:04 +01:00
2022-03-06 13:29:38 +00:00
public override void OnFrameworkInitializationCompleted()
{
if(ApplicationLifetime is IClassicDesktopStyleApplicationLifetime desktop)
2020-04-09 02:26:04 +01:00
{
2022-03-06 13:29:38 +00:00
var splashWindow = new SplashWindow();
var swvm = new SplashWindowViewModel(splashWindow);
swvm.WorkFinished += OnSplashFinished;
splashWindow.DataContext = swvm;
desktop.MainWindow = splashWindow;
2020-04-09 02:26:04 +01:00
}
2020-04-09 04:18:29 +01:00
2022-03-06 13:29:38 +00:00
base.OnFrameworkInitializationCompleted();
}
2020-04-09 04:18:29 +01:00
2022-03-06 13:29:38 +00:00
void OnSplashFinished(object sender, EventArgs e)
{
if(!(ApplicationLifetime is IClassicDesktopStyleApplicationLifetime desktop))
return;
2020-04-09 04:18:29 +01:00
2022-03-06 13:29:38 +00:00
// Ensure not exit
desktop.ShutdownMode = ShutdownMode.OnExplicitShutdown;
2020-04-09 04:18:29 +01:00
2022-03-06 13:29:38 +00:00
// Close splash window
desktop.MainWindow.Close();
2020-04-09 04:18:29 +01:00
2022-03-06 13:29:38 +00:00
// Create and show main window
desktop.MainWindow = new MainWindow();
desktop.MainWindow.DataContext = new MainWindowViewModel(desktop.MainWindow as MainWindow);
desktop.MainWindow.Show();
2020-04-10 01:10:55 +01:00
2022-03-06 13:29:38 +00:00
// Now can close when all windows are closed
desktop.ShutdownMode = ShutdownMode.OnLastWindowClose;
}
2020-04-10 01:10:55 +01:00
2022-03-06 13:29:38 +00:00
void OnAboutClicked(object sender, EventArgs args)
{
if(!(ApplicationLifetime is IClassicDesktopStyleApplicationLifetime
2022-03-07 07:36:44 +00:00
{
MainWindow: MainWindow { DataContext: MainWindowViewModel mainWindowViewModel }
}))
2022-03-06 13:29:38 +00:00
return;
2020-04-10 19:11:19 +01:00
2022-03-06 13:29:38 +00:00
mainWindowViewModel.ExecuteAboutCommand();
}
2020-04-10 19:11:19 +01:00
2022-03-06 13:29:38 +00:00
void OnQuitClicked(object sender, EventArgs args)
{
if(!(ApplicationLifetime is IClassicDesktopStyleApplicationLifetime
2022-03-07 07:36:44 +00:00
{
MainWindow: MainWindow { DataContext: MainWindowViewModel mainWindowViewModel }
}))
2022-03-06 13:29:38 +00:00
return;
2022-03-06 13:29:38 +00:00
mainWindowViewModel.ExecuteExitCommand();
}
2022-03-06 13:29:38 +00:00
void OnPreferencesClicked(object sender, EventArgs args)
{
if(!(ApplicationLifetime is IClassicDesktopStyleApplicationLifetime
2022-03-07 07:36:44 +00:00
{
MainWindow: MainWindow { DataContext: MainWindowViewModel mainWindowViewModel }
}))
2022-03-06 13:29:38 +00:00
return;
mainWindowViewModel.ExecuteSettingsCommand();
2020-04-09 02:26:04 +01:00
}
2020-04-09 03:28:08 +01:00
}