diff --git a/src/SopHelper.Avalonia/Presentation/DesktopPlatform.cs b/src/SopHelper.Avalonia/Presentation/DesktopPlatform.cs index 36f88f4..2143b69 100644 --- a/src/SopHelper.Avalonia/Presentation/DesktopPlatform.cs +++ b/src/SopHelper.Avalonia/Presentation/DesktopPlatform.cs @@ -76,9 +76,32 @@ public sealed class OpenFileDialog if(files.Count==0)return false; FileName=files[0].TryGetLocalPath()??throw new IOException("请选择本地文件");return true; } } -public sealed class OpenFolderDialog +/// 保存文件对话框:封装 Avalonia 存储选择器,供导出配方包等写盘入口复用。 +public sealed class SaveFileDialog { - public string Title { get; set; } = "选择文件夹"; + public string Title { get; set; } = "保存文件"; + public string Filter { get; set; } = "所有文件|*.*"; + public string DefaultExt { get; set; } = ""; + public string SuggestedFileName { get; set; } = ""; + public string InitialDirectory { get; set; } = ""; + + /// 用户确认后的本地保存路径;取消时保持为空。 + public string FileName { get; private set; } = ""; + + /// 弹出保存对话框,返回 true 表示已选择本地路径,false 表示用户取消;覆盖确认交给系统对话框处理。 + public async Task ShowDialogAsync() + { + var storage=DesktopPlatform.Owner.StorageProvider; + var filters=Filter.Split('|');var types=new List(); + for(var i=0;i+1 ShowDialogAsync() diff --git a/src/SopHelper.Avalonia/VVMs/RuntimeSettings/ImportRecipeConflictDialog.cs b/src/SopHelper.Avalonia/VVMs/RuntimeSettings/ImportRecipeConflictDialog.cs new file mode 100644 index 0000000..5da7af0 --- /dev/null +++ b/src/SopHelper.Avalonia/VVMs/RuntimeSettings/ImportRecipeConflictDialog.cs @@ -0,0 +1,53 @@ +// 同名配方导入确认窗口:说明覆盖会把旧配方整目录归档,同时提供改名导入,返回用户选择。 + +using Avalonia; +using Avalonia.Controls; +using Avalonia.Layout; +using Avalonia.Media; +using SopHelper.VVMs.SopPage; + +namespace SopHelper.VVMs.RuntimeSettings; + +/// 导入包内配方与工作区已有配方同名时的选择窗口。 +public sealed class ImportRecipeConflictDialog : Window +{ + public ImportRecipeConflictDialog(SopPageViewModel.ImportConflict conflict) + { + static string Size(long bytes) => bytes switch + { + >= 1024L * 1024 => $"{bytes / 1024.0 / 1024:0.0} MB", + >= 1024 => $"{bytes / 1024.0:0.0} KB", + _ => $"{bytes} B" + }; + + var name = conflict.Info.RecipeName; + Title = "导入配方"; Width = 540; SizeToContent = SizeToContent.Height; + CanResize = false; WindowStartupLocation = WindowStartupLocation.CenterOwner; + var cancel = new Button { Content = "取消", IsCancel = true, IsDefault = true }; + var saveAsNew = new Button { Content = $"另存为“{conflict.SuggestedName}”" }; + var overwrite = new Button { Content = "覆盖现有配方", Foreground = new SolidColorBrush(Color.FromRgb(240, 83, 60)) }; + cancel.Click += (_, _) => Close(SopPageViewModel.ImportConflictChoice.Cancel); + saveAsNew.Click += (_, _) => Close(SopPageViewModel.ImportConflictChoice.SaveAsNew); + overwrite.Click += (_, _) => Close(SopPageViewModel.ImportConflictChoice.Overwrite); + + var exportedAt = conflict.Info.ExportedAt is { } time ? time.ToLocalTime().ToString("yyyy-MM-dd HH:mm") : "未知时间"; + var details = new List + { + new TextBlock { Text = $"配方“{name}”已存在于本机。", FontSize = 16, FontWeight = FontWeight.Bold, TextWrapping = TextWrapping.Wrap }, + new TextBlock { Text = $"包内配方导出于 {exportedAt},含 {conflict.Info.FileCount} 个文件,约 {Size(conflict.Info.TotalBytes)}。", TextWrapping = TextWrapping.Wrap }, + new TextBlock { Text = "覆盖前会把现有配方整目录(含录像、标注和运行图片)移入本地“已删除配方”目录,必要时可以找回。", Foreground = new SolidColorBrush(Color.FromRgb(240, 83, 60)), TextWrapping = TextWrapping.Wrap }, + new TextBlock { Text = "导入的配方不会自动应用,请在列表中核对区域坐标后手动应用。", Foreground = new SolidColorBrush(Color.FromRgb(150, 150, 150)), TextWrapping = TextWrapping.Wrap } + }; + // 包内提醒(配方缺步骤、缺标准视频、完成图目录被改写等)在确认前公开,避免用户覆盖后才发现条件不足。 + foreach (var warning in conflict.Info.Warnings.Take(6)) + details.Add(new TextBlock { Text = "提醒:" + warning, Foreground = new SolidColorBrush(Color.FromRgb(150, 150, 150)), TextWrapping = TextWrapping.Wrap }); + details.Add(new StackPanel + { + Orientation = Orientation.Horizontal, HorizontalAlignment = HorizontalAlignment.Right, Spacing = 8, + Children = { cancel, saveAsNew, overwrite } + }); + var panel = new StackPanel { Margin = new Thickness(20), Spacing = 12 }; + foreach (var control in details) panel.Children.Add(control); + Content = panel; + } +} diff --git a/src/SopHelper.Avalonia/VVMs/RuntimeSettings/RuntimeSettings.axaml b/src/SopHelper.Avalonia/VVMs/RuntimeSettings/RuntimeSettings.axaml index 94f19ff..084224c 100644 --- a/src/SopHelper.Avalonia/VVMs/RuntimeSettings/RuntimeSettings.axaml +++ b/src/SopHelper.Avalonia/VVMs/RuntimeSettings/RuntimeSettings.axaml @@ -32,14 +32,20 @@ + +