using Avalonia; using Avalonia.Controls; using Avalonia.Controls.ApplicationLifetimes; using Avalonia.Platform.Storage; using CommunityToolkit.Mvvm.Input; using Shaker.Models; using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; using System.Windows.Input; namespace ShakerApp.ViewModels { internal class SaveConfigViewModel:DisplayViewModelBase { public override string OKContent => "Confirm"; public override bool CanResize => false; public override double Height => 320; public override double Width => 620; private string selectedFile = string.Empty; private SaveConfigViewModel() { Content = typeof(Views.SaveConfigView); } static SaveConfigViewModel() { } public string SelectedFile { get => selectedFile; set =>SetProperty(ref selectedFile , value); } public override void InitData() { base.InitData(); SelectedFile = string.Empty; } protected override void Save() { base.Save(); } public ICommand SelectFileCommand => new RelayCommand(SelectFile); private async void SelectFile(string? p) { if (Application.Current?.ApplicationLifetime is IClassicDesktopStyleApplicationLifetime desktop) { var folder = await TopLevel.GetTopLevel(desktop.MainWindow)!.StorageProvider.SaveFilePickerAsync(new Avalonia.Platform.Storage.FilePickerSaveOptions() { Title = p == null ? "" : App.Current?.FindResource(p) + "", FileTypeChoices = new FilePickerFileType[] { new FilePickerFileType($"{(p ==null ?"": App.Current?.FindResource(p) + "")}"){ Patterns = new []{"*.cfg" } } } }); if (folder != null) { SelectedFile = folder.Path.LocalPath; } } } public static SaveConfigViewModel Instance { get; } = new SaveConfigViewModel(); } }