mirror of
https://github.com/aaru-dps/Aaru.git
synced 2025-12-16 19:24:25 +00:00
Implement about window.
This commit is contained in:
@@ -19,6 +19,7 @@
|
||||
<NrtShowRevision>true</NrtShowRevision>
|
||||
</PropertyGroup>
|
||||
<ItemGroup>
|
||||
<PackageReference Include="Avalonia.Controls.DataGrid" Version="0.9.7" />
|
||||
<PackageReference Include="Claunia.Encoding" Version="1.7.0" />
|
||||
<PackageReference Include="Eto.Forms" Version="2.5.0" />
|
||||
<PackageReference Include="Eto.Serialization.Xaml" Version="2.5.0" />
|
||||
|
||||
@@ -1,21 +1,17 @@
|
||||
<Application xmlns="https://github.com/avaloniaui"
|
||||
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
|
||||
xmlns:gui="clr-namespace:Aaru.Gui"
|
||||
x:Class="Aaru.Gui.App">
|
||||
<Application xmlns="https://github.com/avaloniaui" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
|
||||
xmlns:gui="clr-namespace:Aaru.Gui" x:Class="Aaru.Gui.App">
|
||||
<Application.DataTemplates>
|
||||
<gui:ViewLocator/>
|
||||
<gui:ViewLocator />
|
||||
</Application.DataTemplates>
|
||||
|
||||
<Application.Styles>
|
||||
<StyleInclude Source="avares://Avalonia.Themes.Default/DefaultTheme.xaml"/>
|
||||
<StyleInclude Source="avares://Avalonia.Themes.Default/Accents/BaseLight.xaml"/>
|
||||
<StyleInclude Source="avares://Avalonia.Themes.Default/DefaultTheme.xaml" />
|
||||
<StyleInclude Source="avares://Avalonia.Themes.Default/Accents/BaseLight.xaml" />
|
||||
<StyleInclude Source="avares://Avalonia.Controls.DataGrid/Themes/Default.xaml" />
|
||||
</Application.Styles>
|
||||
|
||||
<NativeMenu.Menu>
|
||||
<NativeMenu>
|
||||
<NativeMenuItem Header="_About"/>
|
||||
<NativeMenuItem Header="_Preferences"/>
|
||||
<NativeMenuItem Header="_Quit"/>
|
||||
<NativeMenuItem Header="_About" Clicked="OnAboutClicked" /> <NativeMenuItem Header="_Preferences" />
|
||||
<NativeMenuItem Header="_Quit" />
|
||||
</NativeMenu>
|
||||
</NativeMenu.Menu>
|
||||
</Application>
|
||||
</Application>
|
||||
@@ -40,15 +40,22 @@ namespace Aaru.Gui
|
||||
desktop.MainWindow.Close();
|
||||
|
||||
// Create and show main window
|
||||
desktop.MainWindow = new MainWindow
|
||||
{
|
||||
DataContext = new MainWindowViewModel()
|
||||
};
|
||||
|
||||
desktop.MainWindow = new MainWindow();
|
||||
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();
|
||||
}
|
||||
}
|
||||
}
|
||||
8
Aaru.Gui/Models/AssemblyModel.cs
Normal file
8
Aaru.Gui/Models/AssemblyModel.cs
Normal file
@@ -0,0 +1,8 @@
|
||||
namespace Aaru.Gui.Models
|
||||
{
|
||||
public class AssemblyModel
|
||||
{
|
||||
public string Name { get; set; }
|
||||
public string Version { get; set; }
|
||||
}
|
||||
}
|
||||
129
Aaru.Gui/ViewModels/AboutDialogViewModel.cs
Normal file
129
Aaru.Gui/ViewModels/AboutDialogViewModel.cs
Normal file
@@ -0,0 +1,129 @@
|
||||
using System;
|
||||
using System.Collections.ObjectModel;
|
||||
using System.Diagnostics;
|
||||
using System.Linq;
|
||||
using System.Reactive;
|
||||
using System.Reflection;
|
||||
using System.Threading.Tasks;
|
||||
using Aaru.Gui.Models;
|
||||
using Aaru.Gui.Views;
|
||||
using Microsoft.DotNet.PlatformAbstractions;
|
||||
using ReactiveUI;
|
||||
|
||||
namespace Aaru.Gui.ViewModels
|
||||
{
|
||||
public class AboutDialogViewModel : ViewModelBase
|
||||
{
|
||||
readonly AboutDialog _view;
|
||||
string _versionText;
|
||||
|
||||
public AboutDialogViewModel(AboutDialog 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>();
|
||||
|
||||
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
|
||||
});
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
public string AboutLabel => "About";
|
||||
public string LibrariesLabel => "Libraries";
|
||||
public string AuthorsLabel => "Authors";
|
||||
public string Title => "About Aaru";
|
||||
public string SoftwareName => "Aaru";
|
||||
public string SuiteName => "Aaru Data Preservation Suite";
|
||||
public string Copyright => "© 2011-2020 Natalia Portillo";
|
||||
public string Website => "https://aaru.app";
|
||||
public string License => "License: GNU General Public License Version 3";
|
||||
public string CloseLabel => "Close";
|
||||
public string AssembliesLibraryText => "Library";
|
||||
public string AssembliesVersionText => "Version";
|
||||
public string Authors => @"Developers:
|
||||
Natalia Portillo
|
||||
Michael Drüing
|
||||
|
||||
Testers:
|
||||
Silas Laspada
|
||||
|
||||
Public relations:
|
||||
Noah Bacon";
|
||||
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://aaru.app"
|
||||
}
|
||||
};
|
||||
|
||||
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() => throw new NotImplementedException();
|
||||
|
||||
void ExecuteCloseCommand() => _view.Close();
|
||||
}
|
||||
}
|
||||
@@ -1,15 +1,35 @@
|
||||
using System;
|
||||
using System.Reactive;
|
||||
using Aaru.Gui.Views;
|
||||
using Avalonia;
|
||||
using Avalonia.Controls;
|
||||
using Avalonia.Controls.ApplicationLifetimes;
|
||||
using ReactiveUI;
|
||||
|
||||
namespace Aaru.Gui.ViewModels
|
||||
{
|
||||
public class MainWindowViewModel : ViewModelBase
|
||||
{
|
||||
readonly MainWindow _view;
|
||||
|
||||
public MainWindowViewModel(MainWindow view)
|
||||
{
|
||||
AboutCommand = ReactiveCommand.Create(ExecuteAboutCommand);
|
||||
_view = view;
|
||||
}
|
||||
|
||||
public string Greeting => "Welcome to Aaru!";
|
||||
|
||||
public bool NativeMenuNotSupported => !NativeMenu.GetIsNativeMenuExported((Application.Current.ApplicationLifetime as
|
||||
IClassicDesktopStyleApplicationLifetime)?.MainWindow);
|
||||
public bool NativeMenuNotSupported =>
|
||||
!NativeMenu.GetIsNativeMenuExported((Application.Current.ApplicationLifetime as
|
||||
IClassicDesktopStyleApplicationLifetime)?.MainWindow);
|
||||
|
||||
public ReactiveCommand<Unit, Unit> AboutCommand { get; }
|
||||
|
||||
internal void ExecuteAboutCommand()
|
||||
{
|
||||
var dialog = new AboutDialog();
|
||||
dialog.DataContext = new AboutDialogViewModel(dialog);
|
||||
dialog.ShowDialog(_view);
|
||||
}
|
||||
}
|
||||
}
|
||||
84
Aaru.Gui/Views/AboutDialog.xaml
Normal file
84
Aaru.Gui/Views/AboutDialog.xaml
Normal file
@@ -0,0 +1,84 @@
|
||||
<Window xmlns="https://github.com/avaloniaui" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
|
||||
xmlns:vm="clr-namespace:Aaru.Gui.ViewModels;assembly=Aaru.Gui"
|
||||
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
|
||||
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" mc:Ignorable="d" d:DesignWidth="800"
|
||||
d:DesignHeight="450" Width="480" Height="320" x:Class="Aaru.Gui.Views.AboutDialog"
|
||||
Icon="/Assets/avalonia-logo.ico" CanResize="False" Title="{Binding Title}">
|
||||
<Design.DataContext>
|
||||
<vm:AboutDialogViewModel />
|
||||
</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>
|
||||
19
Aaru.Gui/Views/AboutDialog.xaml.cs
Normal file
19
Aaru.Gui/Views/AboutDialog.xaml.cs
Normal file
@@ -0,0 +1,19 @@
|
||||
using Avalonia;
|
||||
using Avalonia.Controls;
|
||||
using Avalonia.Markup.Xaml;
|
||||
|
||||
namespace Aaru.Gui.Views
|
||||
{
|
||||
public class AboutDialog : Window
|
||||
{
|
||||
public AboutDialog()
|
||||
{
|
||||
InitializeComponent();
|
||||
#if DEBUG
|
||||
this.AttachDevTools();
|
||||
#endif
|
||||
}
|
||||
|
||||
void InitializeComponent() => AvaloniaXamlLoader.Load(this);
|
||||
}
|
||||
}
|
||||
@@ -1,41 +1,31 @@
|
||||
<Window xmlns="https://github.com/avaloniaui"
|
||||
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
|
||||
<Window xmlns="https://github.com/avaloniaui" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
|
||||
xmlns:vm="clr-namespace:Aaru.Gui.ViewModels;assembly=Aaru.Gui"
|
||||
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
|
||||
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
|
||||
mc:Ignorable="d" d:DesignWidth="800" d:DesignHeight="450"
|
||||
x:Class="Aaru.Gui.Views.MainWindow"
|
||||
Icon="/Assets/avalonia-logo.ico"
|
||||
Title="Aaru.Gui">
|
||||
|
||||
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" mc:Ignorable="d" d:DesignWidth="800"
|
||||
d:DesignHeight="450" x:Class="Aaru.Gui.Views.MainWindow" Icon="/Assets/avalonia-logo.ico" Title="Aaru.Gui">
|
||||
<Design.DataContext>
|
||||
<vm:MainWindowViewModel/>
|
||||
<vm:MainWindowViewModel />
|
||||
</Design.DataContext>
|
||||
|
||||
<DockPanel>
|
||||
<Menu DockPanel.Dock="Top">
|
||||
<MenuItem Header="_File">
|
||||
<MenuItem Header="_Open"/>
|
||||
<Separator/>
|
||||
<MenuItem Header="_Settings" IsVisible="{Binding NativeMenuNotSupported}"/>
|
||||
<Separator/>
|
||||
<MenuItem Header="E_xit" IsVisible="{Binding NativeMenuNotSupported}"/>
|
||||
<MenuItem Header="_Open" /> <Separator />
|
||||
<MenuItem Header="_Settings" IsVisible="{Binding NativeMenuNotSupported}" /> <Separator />
|
||||
<MenuItem Header="E_xit" IsVisible="{Binding NativeMenuNotSupported}" />
|
||||
</MenuItem>
|
||||
<MenuItem Header="_Devices">
|
||||
<MenuItem Header="_Refresh"/>
|
||||
<MenuItem Header="_Refresh" />
|
||||
</MenuItem>
|
||||
<MenuItem Header="_Window">
|
||||
<MenuItem Header="_Console"/>
|
||||
<MenuItem Header="_Console" />
|
||||
</MenuItem>
|
||||
<MenuItem Header="_Help">
|
||||
<MenuItem Header="_Encodings"/>
|
||||
<MenuItem Header="_Plugins"/>
|
||||
<MenuItem Header="_Statistics"/>
|
||||
<Separator IsVisible="{Binding NativeMenuNotSupported}"/>
|
||||
<MenuItem Header="_About" Name="AboutMenuItem" IsVisible="{Binding NativeMenuNotSupported}"/>
|
||||
<MenuItem Header="_Encodings" /> <MenuItem Header="_Plugins" /> <MenuItem Header="_Statistics" />
|
||||
<Separator IsVisible="{Binding NativeMenuNotSupported}" />
|
||||
<MenuItem Header="_About" Name="AboutMenuItem" IsVisible="{Binding NativeMenuNotSupported}"
|
||||
Command="{Binding AboutCommand}" />
|
||||
</MenuItem>
|
||||
</Menu>
|
||||
<TextBlock Text="{Binding Greeting}" HorizontalAlignment="Center" VerticalAlignment="Center"/>
|
||||
<TextBlock Text="{Binding Greeting}" HorizontalAlignment="Center" VerticalAlignment="Center" />
|
||||
</DockPanel>
|
||||
|
||||
</Window>
|
||||
</Window>
|
||||
Reference in New Issue
Block a user