Files
Aaru/Aaru.Gui/ViewModels/Dialogs/EncodingsViewModel.cs

83 lines
3.1 KiB
C#
Raw Permalink Normal View History

2020-04-17 21:45:50 +01:00
// /***************************************************************************
// Aaru Data Preservation Suite
// ----------------------------------------------------------------------------
//
// Filename : EncodingsViewModel.cs
// Author(s) : Natalia Portillo <claunia@claunia.com>
//
// Component : GUI view models.
//
// --[ Description ] ----------------------------------------------------------
//
// View model and code 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/>.
//
// ----------------------------------------------------------------------------
2024-12-19 10:45:18 +00:00
// Copyright © 2011-2025 Natalia Portillo
2020-04-17 21:45:50 +01:00
// ****************************************************************************/
using System.Collections.ObjectModel;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
2025-08-20 21:19:43 +01:00
using System.Windows.Input;
using Aaru.Gui.Models;
2020-04-16 20:40:25 +01:00
using Aaru.Gui.Views.Dialogs;
using Avalonia.Threading;
2025-08-20 21:19:43 +01:00
using CommunityToolkit.Mvvm.Input;
namespace Aaru.Gui.ViewModels.Dialogs;
2022-03-06 13:29:38 +00:00
public sealed class EncodingsViewModel : ViewModelBase
{
2022-03-06 13:29:38 +00:00
readonly Encodings _view;
public EncodingsViewModel(Encodings view)
{
2022-03-06 13:29:38 +00:00
_view = view;
2024-05-01 04:39:38 +01:00
Encodings = [];
2025-08-20 21:19:43 +01:00
CloseCommand = new RelayCommand(Close);
2025-08-20 21:19:43 +01:00
_ = Task.Run(() =>
{
2024-05-01 04:05:22 +01:00
var encodings = Encoding.GetEncodings()
.Select(static info => new EncodingModel
{
Name = info.Name,
DisplayName = info.GetEncoding().EncodingName
2024-05-01 04:05:22 +01:00
})
.ToList();
2024-05-01 04:05:22 +01:00
encodings.AddRange(Claunia.Encoding.Encoding.GetEncodings()
.Select(static info => new EncodingModel
{
Name = info.Name,
DisplayName = info.DisplayName
}));
Dispatcher.UIThread.Invoke(() =>
{
foreach(EncodingModel encoding in encodings.OrderBy(static t => t.DisplayName)) Encodings.Add(encoding);
});
2022-03-06 13:29:38 +00:00
});
}
2025-08-20 21:19:43 +01:00
public ICommand CloseCommand { get; }
2022-03-06 13:29:38 +00:00
public ObservableCollection<EncodingModel> Encodings { get; }
2025-08-20 21:19:43 +01:00
void Close() => _view.Close();
}