Migrate encodings from Eto.Forms to Avalonia.

This commit is contained in:
2020-04-10 02:50:38 +01:00
parent 6dd6e84e67
commit f66960f077
10 changed files with 517 additions and 529 deletions

View File

@@ -330,6 +330,12 @@
<Compile Update="Views\LicenseDialog.xaml.cs"> <Compile Update="Views\LicenseDialog.xaml.cs">
<DependentUpon>LicenseDialog.xaml</DependentUpon> <DependentUpon>LicenseDialog.xaml</DependentUpon>
</Compile> </Compile>
<AvaloniaResource Update="Views\EncodingsDialog.xaml">
<SubType>Designer</SubType>
</AvaloniaResource>
<Compile Update="Views\EncodingsDialog.xaml.cs">
<DependentUpon>EncodingsDialog.xaml</DependentUpon>
</Compile>
</ItemGroup> </ItemGroup>
<ItemGroup> <ItemGroup>
<UpToDateCheckInput Remove="Views\MainWindow.xaml"/> <UpToDateCheckInput Remove="Views\MainWindow.xaml"/>

View File

@@ -1,48 +0,0 @@
<?xml version="1.0" encoding="UTF-8"?><!--
// /***************************************************************************
// The Disc Image Chef
// ============================================================================
//
// Filename : dlgEncodings.xeto
// Author(s) : Natalia Portillo <claunia@claunia.com>
//
// Component : Encodings dialog.
//
// ==[ Description ] ==========================================================
//
// Defines the structure for the encodings list dialog.
//
// ==[ 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 © 2011-2020 Natalia Portillo
// ****************************************************************************/
-->
<Dialog xmlns="http://schema.picoe.ca/eto.forms" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" Title="Encodings"
ClientSize="600, 450" Padding="10">
<StackLayout Orientation="Vertical">
<StackLayoutItem HorizontalAlignment="Stretch" Expand="True" VerticalAlignment="Stretch">
<GridView ID="grdEncodings"/>
</StackLayoutItem>
<StackLayoutItem HorizontalAlignment="Right" VerticalAlignment="Bottom">
<StackLayout Orientation="Horizontal">
<StackLayoutItem HorizontalAlignment="Stretch" Expand="True">
<Button ID="btnClose" Click="OnBtnClose">Close</Button>
</StackLayoutItem>
</StackLayout>
</StackLayoutItem>
</StackLayout>
</Dialog>

View File

@@ -1,113 +0,0 @@
// /***************************************************************************
// Aaru Data Preservation Suite
// ----------------------------------------------------------------------------
//
// Filename : dlgEncodings.xeto.cs
// Author(s) : Natalia Portillo <claunia@claunia.com>
//
// Component : Plugins dialog.
//
// --[ Description ] ----------------------------------------------------------
//
// Implements the encodings list dialog.
//
// --[ 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 © 2011-2020 Natalia Portillo
// ****************************************************************************/
using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.Linq;
using System.Text;
using Eto.Forms;
using Eto.Serialization.Xaml;
namespace Aaru.Gui.Dialogs
{
public class dlgEncodings : Dialog
{
readonly ObservableCollection<CommonEncodingInfo> encodings;
public dlgEncodings()
{
XamlReader.Load(this);
DefaultButton = btnClose;
DisplayMode = DialogDisplayMode.Attached;
encodings = new ObservableCollection<CommonEncodingInfo>();
grdEncodings.DataStore = encodings;
grdEncodings.Columns.Add(new GridColumn
{
DataCell = new TextBoxCell
{
Binding = Binding.Property<CommonEncodingInfo, string>(r => r.Name)
},
HeaderText = "Code", Sortable = true
});
grdEncodings.Columns.Add(new GridColumn
{
DataCell = new TextBoxCell
{
Binding = Binding.Property<CommonEncodingInfo, string>(r => r.DisplayName)
},
HeaderText = "Name", Sortable = true
});
grdEncodings.AllowMultipleSelection = false;
grdEncodings.AllowColumnReordering = true;
}
protected override void OnLoadComplete(EventArgs e)
{
base.OnLoadComplete(e);
encodings.Clear();
List<CommonEncodingInfo> _encodings = Encoding.GetEncodings().Select(info => new CommonEncodingInfo
{
Name = info.Name, DisplayName = info.GetEncoding().EncodingName
}).ToList();
_encodings.AddRange(Claunia.Encoding.Encoding.GetEncodings().Select(info => new CommonEncodingInfo
{
Name = info.Name, DisplayName = info.DisplayName
}));
foreach(CommonEncodingInfo encoding in _encodings.OrderBy(t => t.DisplayName))
encodings.Add(encoding);
}
protected void OnBtnClose(object sender, EventArgs e) => Close();
class CommonEncodingInfo
{
public string Name { get; set; }
public string DisplayName { get; set; }
}
#region XAML controls
GridView grdEncodings;
Button btnClose;
#endregion
}
}

View File

@@ -686,8 +686,6 @@ namespace Aaru.Gui.Forms
protected void OnMenuPlugins(object sender, EventArgs e) => new dlgPlugins().ShowModal(this); protected void OnMenuPlugins(object sender, EventArgs e) => new dlgPlugins().ShowModal(this);
protected void OnMenuEncodings(object sender, EventArgs e) => new dlgEncodings().ShowModal(this);
protected void OnMenuStatistics(object sender, EventArgs e) protected void OnMenuStatistics(object sender, EventArgs e)
{ {
var ctx = AaruContext.Create(Settings.Settings.LocalDbPath); var ctx = AaruContext.Create(Settings.Settings.LocalDbPath);

View File

@@ -0,0 +1,8 @@
namespace Aaru.Gui.Models
{
public class EncodingModel
{
public string Name { get; set; }
public string DisplayName { get; set; }
}
}

View File

@@ -0,0 +1,48 @@
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.Linq;
using System.Reactive;
using System.Text;
using System.Threading.Tasks;
using Aaru.Gui.Models;
using Aaru.Gui.Views;
using ReactiveUI;
namespace Aaru.Gui.ViewModels
{
public class EncodingsDialogViewModel : ViewModelBase
{
readonly EncodingsDialog _view;
string _versionText;
public EncodingsDialogViewModel(EncodingsDialog view)
{
_view = view;
Encodings = new ObservableCollection<EncodingModel>();
CloseCommand = ReactiveCommand.Create(ExecuteCloseCommand);
Task.Run(() =>
{
List<EncodingModel> encodings = Encoding.GetEncodings().Select(info => new EncodingModel
{
Name = info.Name, DisplayName = info.GetEncoding().EncodingName
}).ToList();
encodings.AddRange(Claunia.Encoding.Encoding.GetEncodings().Select(info => new EncodingModel
{
Name = info.Name, DisplayName = info.DisplayName
}));
foreach(EncodingModel encoding in encodings.OrderBy(t => t.DisplayName))
Encodings.Add(encoding);
});
}
public string Title => "Encodings";
public string CloseLabel => "Close";
public ReactiveCommand<Unit, Unit> CloseCommand { get; }
public ObservableCollection<EncodingModel> Encodings { get; }
void ExecuteCloseCommand() => _view.Close();
}
}

View File

@@ -14,6 +14,7 @@ namespace Aaru.Gui.ViewModels
public MainWindowViewModel(MainWindow view) public MainWindowViewModel(MainWindow view)
{ {
AboutCommand = ReactiveCommand.Create(ExecuteAboutCommand); AboutCommand = ReactiveCommand.Create(ExecuteAboutCommand);
EncodingsCommand = ReactiveCommand.Create(ExecuteEncodingsCommand);
_view = view; _view = view;
} }
@@ -24,6 +25,7 @@ namespace Aaru.Gui.ViewModels
IClassicDesktopStyleApplicationLifetime)?.MainWindow); IClassicDesktopStyleApplicationLifetime)?.MainWindow);
public ReactiveCommand<Unit, Unit> AboutCommand { get; } public ReactiveCommand<Unit, Unit> AboutCommand { get; }
public ReactiveCommand<Unit, Unit> EncodingsCommand { get; }
internal void ExecuteAboutCommand() internal void ExecuteAboutCommand()
{ {
@@ -31,5 +33,12 @@ namespace Aaru.Gui.ViewModels
dialog.DataContext = new AboutDialogViewModel(dialog); dialog.DataContext = new AboutDialogViewModel(dialog);
dialog.ShowDialog(_view); dialog.ShowDialog(_view);
} }
internal void ExecuteEncodingsCommand()
{
var dialog = new EncodingsDialog();
dialog.DataContext = new EncodingsDialogViewModel(dialog);
dialog.ShowDialog(_view);
}
} }
} }

View File

@@ -0,0 +1,61 @@
<!--
// /***************************************************************************
// The Disc Image Chef
// ============================================================================
//
// Filename : dlgEncodings.xeto
// Author(s) : Natalia Portillo <claunia@claunia.com>
//
// Component : Encodings dialog.
//
// ==[ Description ] ==========================================================
//
// Defines the structure for the encodings list dialog.
//
// ==[ 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 © 2011-2020 Natalia Portillo
// ****************************************************************************/
-->
<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.EncodingsDialog"
Icon="/Assets/avalonia-logo.ico" CanResize="False" Title="{Binding Title}">
<Design.DataContext>
<vm:EncodingsDialogViewModel />
</Design.DataContext>
<Border Padding="15">
<Grid HorizontalAlignment="Stretch" VerticalAlignment="Stretch">
<Grid.RowDefinitions>
<RowDefinition Height="260" /> <RowDefinition Height="Auto" />
</Grid.RowDefinitions>
<DataGrid Items="{Binding Encodings}" HorizontalScrollBarVisibility="Visible">
<DataGrid.Columns>
<DataGridTextColumn Header="Code" Binding="{Binding Name}" Width="Auto" IsReadOnly="True" />
<DataGridTextColumn Header="Name" Binding="{Binding DisplayName}" Width="Auto" IsReadOnly="True" />
</DataGrid.Columns>
</DataGrid>
<Border Grid.Row="1" Padding="10">
<Button HorizontalAlignment="Right" VerticalAlignment="Bottom" Command="{Binding CloseCommand}">
<TextBlock Text="{Binding CloseLabel}" />
</Button>
</Border>
</Grid>
</Border>
</Window>

View File

@@ -0,0 +1,19 @@
using Avalonia;
using Avalonia.Controls;
using Avalonia.Markup.Xaml;
namespace Aaru.Gui.Views
{
public class EncodingsDialog : Window
{
public EncodingsDialog()
{
InitializeComponent();
#if DEBUG
this.AttachDevTools();
#endif
}
void InitializeComponent() => AvaloniaXamlLoader.Load(this);
}
}

View File

@@ -20,8 +20,8 @@
<MenuItem Header="_Console" /> <MenuItem Header="_Console" />
</MenuItem> </MenuItem>
<MenuItem Header="_Help"> <MenuItem Header="_Help">
<MenuItem Header="_Encodings" /> <MenuItem Header="_Plugins" /> <MenuItem Header="_Statistics" /> <MenuItem Header="_Encodings" Command="{Binding EncodingsCommand}" /> <MenuItem Header="_Plugins" />
<Separator IsVisible="{Binding NativeMenuNotSupported}" /> <MenuItem Header="_Statistics" /> <Separator IsVisible="{Binding NativeMenuNotSupported}" />
<MenuItem Header="_About" Name="AboutMenuItem" IsVisible="{Binding NativeMenuNotSupported}" <MenuItem Header="_About" Name="AboutMenuItem" IsVisible="{Binding NativeMenuNotSupported}"
Command="{Binding AboutCommand}" /> Command="{Binding AboutCommand}" />
</MenuItem> </MenuItem>