Add about dialog.

This commit is contained in:
2020-08-22 03:13:49 +01:00
parent c96ed5596a
commit 09b8fb0fad
9 changed files with 446 additions and 2 deletions

View File

@@ -7,4 +7,11 @@
<StyleInclude Source="avares://Avalonia.Themes.Default/DefaultTheme.xaml" />
<StyleInclude Source="avares://Avalonia.Themes.Default/Accents/BaseLight.xaml" />
</Application.Styles>
<NativeMenu.Menu>
<NativeMenu>
<NativeMenuItem Header="_About" Clicked="OnAboutClicked" />
<NativeMenuItem Header="_Preferences" Clicked="OnPreferencesClicked" />
<NativeMenuItem Header="_Quit" Clicked="OnQuitClicked" />
</NativeMenu>
</NativeMenu.Menu>
</Application>

View File

@@ -64,11 +64,41 @@ namespace RomRepoMgr
// Create and show main window
desktop.MainWindow = new MainWindow();
desktop.MainWindow.DataContext = new MainWindowViewModel();
desktop.MainWindow.DataContext = new MainWindowViewModel(desktop.MainWindow as MainWindow);
desktop.MainWindow.Show();
// Now can close when all windows are closed
desktop.ShutdownMode = ShutdownMode.OnLastWindowClose;
}
void OnAboutClicked(object sender, EventArgs args)
{
if(!(ApplicationLifetime is IClassicDesktopStyleApplicationLifetime desktop) ||
!(desktop.MainWindow is MainWindow mainWindow) ||
!(mainWindow.DataContext is MainWindowViewModel mainWindowViewModel))
return;
mainWindowViewModel.ExecuteAboutCommand();
}
void OnQuitClicked(object sender, EventArgs args)
{
if(!(ApplicationLifetime is IClassicDesktopStyleApplicationLifetime desktop) ||
!(desktop.MainWindow is MainWindow mainWindow) ||
!(mainWindow.DataContext is MainWindowViewModel mainWindowViewModel))
return;
mainWindowViewModel.ExecuteExitCommand();
}
void OnPreferencesClicked(object sender, EventArgs args)
{
if(!(ApplicationLifetime is IClassicDesktopStyleApplicationLifetime desktop) ||
!(desktop.MainWindow is MainWindow mainWindow) ||
!(mainWindow.DataContext is MainWindowViewModel mainWindowViewModel))
return;
mainWindowViewModel.ExecuteSettingsCommand();
}
}
}

View File

@@ -0,0 +1,33 @@
/******************************************************************************
// RomRepoMgr - ROM repository manager
// ----------------------------------------------------------------------------
//
// Author(s) : Natalia Portillo <claunia@claunia.com>
//
// --[ 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/>.
//
// ----------------------------------------------------------------------------
// Copyright © 2020 Natalia Portillo
*******************************************************************************/
namespace RomRepoMgr.Models
{
public sealed class AssemblyModel
{
public string Name { get; set; }
public string Version { get; set; }
}
}

View File

@@ -15,6 +15,7 @@
</ItemGroup>
<ItemGroup>
<PackageReference Include="Avalonia" Version="0.10.0-preview3" />
<PackageReference Include="Avalonia.Controls.DataGrid" Version="0.10.0-preview3" />
<PackageReference Include="Avalonia.Desktop" Version="0.10.0-preview3" />
<PackageReference Include="Avalonia.ReactiveUI" Version="0.10.0-preview3" />
<PackageReference Include="Svg.Skia.Avalonia" Version="0.10.0-preview3" />

View File

@@ -0,0 +1,171 @@
/******************************************************************************
// RomRepoMgr - ROM repository manager
// ----------------------------------------------------------------------------
//
// Author(s) : Natalia Portillo <claunia@claunia.com>
//
// --[ 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/>.
//
// ----------------------------------------------------------------------------
// Copyright © 2020 Natalia Portillo
*******************************************************************************/
using System;
using System.Collections.ObjectModel;
using System.Diagnostics;
using System.Linq;
using System.Reactive;
using System.Reflection;
using System.Threading.Tasks;
using JetBrains.Annotations;
using Microsoft.DotNet.PlatformAbstractions;
using ReactiveUI;
using RomRepoMgr.Models;
using RomRepoMgr.Views;
namespace RomRepoMgr.ViewModels
{
public sealed class AboutViewModel : ViewModelBase
{
readonly About _view;
string _versionText;
public AboutViewModel(About view)
{
_view = view;
VersionText =
(Attribute.GetCustomAttribute(typeof(App).Assembly, typeof(AssemblyInformationalVersionAttribute)) as
AssemblyInformationalVersionAttribute)?.InformationalVersion;
WebsiteCommand = ReactiveCommand.Create(ExecuteWebsiteCommand);
LicenseCommand = ReactiveCommand.Create(ExecuteLicenseCommand);
CloseCommand = ReactiveCommand.Create(ExecuteCloseCommand);
Assemblies = new ObservableCollection<AssemblyModel>();
// TODO: They do not load in time
Task.Run(() =>
{
foreach(Assembly assembly in AppDomain.CurrentDomain.GetAssemblies().OrderBy(a => a.FullName))
{
string name = assembly.GetName().Name;
string version =
(Attribute.GetCustomAttribute(assembly, typeof(AssemblyInformationalVersionAttribute)) as
AssemblyInformationalVersionAttribute)?.InformationalVersion;
if(name is null ||
version is null)
continue;
Assemblies.Add(new AssemblyModel
{
Name = name,
Version = version
});
}
});
}
[NotNull]
public string AboutLabel => "About";
[NotNull]
public string LibrariesLabel => "Libraries";
[NotNull]
public string AuthorsLabel => "Authors";
[NotNull]
public string Title => "About ROM Repository Manager";
[NotNull]
public string SoftwareName => "RomRepoMgr";
[NotNull]
public string SuiteName => "ROM Repository Manager";
[NotNull]
public string Copyright => "© 2020 Natalia Portillo";
[NotNull]
public string Website => "https://www.claunia.com";
[NotNull]
public string License => "License: GNU General Public License Version 3";
[NotNull]
public string CloseLabel => "Close";
[NotNull]
public string AssembliesLibraryText => "Library";
[NotNull]
public string AssembliesVersionText => "Version";
[NotNull]
public string Authors => @"Developers:
Natalia Portillo
";
public ReactiveCommand<Unit, Unit> WebsiteCommand { get; }
public ReactiveCommand<Unit, Unit> LicenseCommand { get; }
public ReactiveCommand<Unit, Unit> CloseCommand { get; }
public ObservableCollection<AssemblyModel> Assemblies { get; }
public string VersionText
{
get => _versionText;
set => this.RaiseAndSetIfChanged(ref _versionText, value);
}
void ExecuteWebsiteCommand()
{
var process = new Process
{
StartInfo =
{
UseShellExecute = false,
CreateNoWindow = true,
Arguments = "https://www.claunia.com"
}
};
switch(RuntimeEnvironment.OperatingSystemPlatform)
{
case Platform.Unknown: return;
case Platform.Windows:
process.StartInfo.FileName = "cmd";
process.StartInfo.Arguments = $"/c start {process.StartInfo.Arguments.Replace("&", "^&")}";
break;
case Platform.FreeBSD:
case Platform.Linux:
process.StartInfo.FileName = "xdg-open";
break;
case Platform.Darwin:
process.StartInfo.FileName = "open";
break;
default:
if(Debugger.IsAttached)
throw new ArgumentOutOfRangeException();
return;
}
process.Start();
}
void ExecuteLicenseCommand()
{
/* var dialog = new LicenseDialog();
dialog.DataContext = new LicenseViewModel(dialog);
dialog.ShowDialog(_view);*/
}
void ExecuteCloseCommand() => _view.Close();
}
}

View File

@@ -23,10 +23,51 @@
// Copyright © 2020 Natalia Portillo
*******************************************************************************/
using System.Reactive;
using Avalonia;
using Avalonia.Controls;
using Avalonia.Controls.ApplicationLifetimes;
using ReactiveUI;
using RomRepoMgr.Views;
namespace RomRepoMgr.ViewModels
{
public class MainWindowViewModel : ViewModelBase
{
readonly MainWindow _view;
public MainWindowViewModel(MainWindow view)
{
_view = view;
ExitCommand = ReactiveCommand.Create(ExecuteExitCommand);
SettingsCommand = ReactiveCommand.Create(ExecuteSettingsCommand);
AboutCommand = ReactiveCommand.Create(ExecuteAboutCommand);
}
public string Greeting => "Hello World!";
public bool NativeMenuSupported =>
NativeMenu.GetIsNativeMenuExported((Application.Current.ApplicationLifetime as
IClassicDesktopStyleApplicationLifetime)?.MainWindow);
public ReactiveCommand<Unit, Unit> AboutCommand { get; }
public ReactiveCommand<Unit, Unit> ExitCommand { get; }
public ReactiveCommand<Unit, Unit> SettingsCommand { get; }
internal async void ExecuteSettingsCommand()
{
/*var dialog = new SettingsDialog();
dialog.DataContext = new SettingsViewModel(dialog, false);
await dialog.ShowDialog(_view);*/
}
internal void ExecuteExitCommand() =>
(Application.Current.ApplicationLifetime as ClassicDesktopStyleApplicationLifetime)?.Shutdown();
internal void ExecuteAboutCommand()
{
var dialog = new About();
dialog.DataContext = new AboutViewModel(dialog);
dialog.ShowDialog(_view);
}
}
}

110
RomRepoMgr/Views/About.xaml Normal file
View File

@@ -0,0 +1,110 @@
<!--
// /***************************************************************************
// RomRepoMgr - ROM repository manager
//
//
// Author(s) : Natalia Portillo <claunia@claunia.com>
//
// [ 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/>.
//
//
// Copyright © 2020 Natalia Portillo
// ****************************************************************************/
-->
<Window xmlns="https://github.com/avaloniaui" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:vm="clr-namespace:RomRepoMgr.ViewModels;assembly=RomRepoMgr" mc:Ignorable="d" d:DesignWidth="800"
d:DesignHeight="450" Width="480" Height="320" x:Class="RomRepoMgr.Views.About" Icon="/Assets/avalonia-logo.ico"
CanResize="False" Title="{Binding Title}">
<Design.DataContext>
<vm:AboutViewModel />
</Design.DataContext>
<Border Padding="15">
<Grid>
<Grid.RowDefinitions>
<RowDefinition Height="Auto" /> <RowDefinition Height="*" /> <RowDefinition Height="Auto" />
</Grid.RowDefinitions>
<Grid Grid.Row="0">
<Grid.ColumnDefinitions>
<ColumnDefinition Width="Auto" /> <ColumnDefinition Width="*" />
</Grid.ColumnDefinitions>
<Border Grid.Column="0" BorderThickness="5">
<Image Source="/Assets/avalonia-logo.ico" Width="48" Height="48" />
</Border>
<Grid Grid.Column="1" HorizontalAlignment="Left" VerticalAlignment="Center">
<Grid.RowDefinitions>
<RowDefinition Height="Auto" /> <RowDefinition Height="Auto" />
</Grid.RowDefinitions>
<TextBlock Grid.Row="0" Text="{Binding SoftwareName}" HorizontalAlignment="Left"
VerticalAlignment="Center" FontSize="16" FontWeight="Bold" />
<TextBlock Grid.Row="1" Text="{Binding VersionText}" HorizontalAlignment="Left"
VerticalAlignment="Center" />
</Grid>
</Grid>
<TabControl Grid.Row="1" HorizontalAlignment="Stretch" VerticalAlignment="Stretch">
<TabItem>
<TabItem.Header>
<TextBlock Text="{Binding AboutLabel}" />
</TabItem.Header>
<Grid>
<Grid.RowDefinitions>
<RowDefinition Height="Auto" /> <RowDefinition Height="12" />
<RowDefinition Height="Auto" /> <RowDefinition Height="12" />
<RowDefinition Height="Auto" /> <RowDefinition Height="Auto" />
<RowDefinition Height="*" />
</Grid.RowDefinitions>
<TextBlock Grid.Row="0" Text="{Binding SuiteName}" />
<TextBlock Grid.Row="2" Text="{Binding Copyright}" />
<Button Grid.Row="4" BorderThickness="0" Background="Transparent" HorizontalAlignment="Left"
VerticalAlignment="Center" Padding="0" Command="{Binding WebsiteCommand}">
<!-- TODO: TextDecorations="Underline" in next Avalonia UI version -->
<TextBlock Text="{Binding Website}" Foreground="Blue" />
</Button>
<Button Grid.Row="5" BorderThickness="0" Background="Transparent" HorizontalAlignment="Left"
VerticalAlignment="Center" Padding="0" Command="{Binding LicenseCommand}">
<!-- TODO: TextDecorations="Underline" in next Avalonia UI version -->
<TextBlock Text="{Binding License}" Foreground="Blue" />
</Button>
</Grid>
</TabItem>
<TabItem>
<TabItem.Header>
<TextBlock Text="{Binding LibrariesLabel}" />
</TabItem.Header>
<DataGrid Items="{Binding Assemblies}" HorizontalScrollBarVisibility="Visible">
<DataGrid.Columns>
<DataGridTextColumn Header="Library" Binding="{Binding Name}" Width="Auto"
IsReadOnly="True" />
<DataGridTextColumn Header="Version" Binding="{Binding Version}" Width="Auto"
IsReadOnly="True" />
</DataGrid.Columns>
</DataGrid>
</TabItem>
<TabItem>
<TabItem.Header>
<TextBlock Text="{Binding AuthorsLabel}" />
</TabItem.Header>
<TextBox IsReadOnly="True" Text="{Binding Authors}" />
</TabItem>
</TabControl>
<Button Grid.Row="2" HorizontalAlignment="Right" VerticalAlignment="Center"
Command="{Binding CloseCommand}">
<TextBlock Text="{Binding CloseLabel}" />
</Button>
</Grid>
</Border>
</Window>

View File

@@ -0,0 +1,37 @@
/******************************************************************************
// RomRepoMgr - ROM repository manager
// ----------------------------------------------------------------------------
//
// Author(s) : Natalia Portillo <claunia@claunia.com>
//
// --[ 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/>.
//
// ----------------------------------------------------------------------------
// Copyright © 2020 Natalia Portillo
*******************************************************************************/
using Avalonia.Controls;
using Avalonia.Markup.Xaml;
namespace RomRepoMgr.Views
{
public sealed class About : Window
{
public About() => InitializeComponent();
void InitializeComponent() => AvaloniaXamlLoader.Load(this);
}
}

View File

@@ -6,5 +6,19 @@
<Design.DataContext>
<vm:MainWindowViewModel />
</Design.DataContext>
<TextBlock Text="{Binding Greeting}" HorizontalAlignment="Center" VerticalAlignment="Center" />
<DockPanel>
<Menu DockPanel.Dock="Top">
<MenuItem Header="_File">
<MenuItem Header="_Settings" IsVisible="{Binding !NativeMenuSupported}"
Command="{Binding SettingsCommand}" />
<Separator />
<MenuItem Header="E_xit" IsVisible="{Binding !NativeMenuSupported}" Command="{Binding ExitCommand}" />
</MenuItem>
<MenuItem Header="_Help">
<MenuItem Header="_About" Name="AboutMenuItem" IsVisible="{Binding !NativeMenuSupported}"
Command="{Binding AboutCommand}" />
</MenuItem>
</Menu>
<TextBlock Text="{Binding Greeting}" HorizontalAlignment="Center" VerticalAlignment="Center" />
</DockPanel>
</Window>