Skip to content

armgit / Filee

Public Imported from GitHub
0

Free, open-source file converter. Convert 263 formats offline by drag & drop — images, PDF, Word, Excel, PowerPoint, HWP/HWPX, video, audio, e-books and archives. No upload, no Office needed.

Presets: save to "Ask every time" (#521)

cre8ive-marketinge5371396bbeb
diff --git a/src/Filee.App/Assets/i18n/ar.json b/src/Filee.App/Assets/i18n/ar.json
index 3de1151e..695d9936 100644
--- a/src/Filee.App/Assets/i18n/ar.json
+++ b/src/Filee.App/Assets/i18n/ar.json
@@ -745,6 +745,9 @@
"presets.location.SameFolder": "مجلد الملف الأصلي نفسه",
"presets.location.Subfolder": "مجلد فرعي",
"presets.location.CustomFolder": "مجلد ثابت",
+ "presets.location.Ask": "السؤال في كل مرة",
+ "ask.save_title": "حفظ النتيجة باسم",
+ "ask.folder_title": "اختر مكان حفظ النتائج",
"presets.subfolder": "اسم المجلد الفرعي",
"presets.subfolder_only_several": "فقط عندما ينتج أكثر من ملف",
"presets.subfolder_only_several_hint": "إذا نتج عن التحويل ملف واحد فإنه يُحفظ بجانب الأصل؛ ولا يُنشأ المجلد الفرعي إلا عندما ينتج عدة ملفات (مثل تقسيم PDF إلى صفحات).",
diff --git a/src/Filee.App/Assets/i18n/en.json b/src/Filee.App/Assets/i18n/en.json
index 75d0ee92..122500b2 100644
--- a/src/Filee.App/Assets/i18n/en.json
+++ b/src/Filee.App/Assets/i18n/en.json
@@ -760,6 +760,9 @@
"presets.location.SameFolder": "Same folder as the source",
"presets.location.Subfolder": "A subfolder",
"presets.location.CustomFolder": "A fixed folder",
+ "presets.location.Ask": "Ask every time",
+ "ask.save_title": "Save the result as",
+ "ask.folder_title": "Choose where to save the results",
"presets.subfolder": "Subfolder name",
"presets.subfolder_only_several": "Only when a file becomes several",
"presets.subfolder_only_several_hint": "A file converted to one file is saved next to the original; only one that becomes several files (a PDF split into pages) gets the subfolder.",
diff --git a/src/Filee.App/Assets/i18n/es.json b/src/Filee.App/Assets/i18n/es.json
index c074a17f..cc44ee17 100644
--- a/src/Filee.App/Assets/i18n/es.json
+++ b/src/Filee.App/Assets/i18n/es.json
@@ -745,6 +745,9 @@
"presets.location.SameFolder": "La misma carpeta que el original",
"presets.location.Subfolder": "Una subcarpeta",
"presets.location.CustomFolder": "Una carpeta fija",
+ "presets.location.Ask": "Preguntar cada vez",
+ "ask.save_title": "Guardar el resultado como",
+ "ask.folder_title": "Elige dónde guardar los resultados",
"presets.subfolder": "Nombre de la subcarpeta",
"presets.subfolder_only_several": "Solo si salen varios archivos",
"presets.subfolder_only_several_hint": "Si un archivo se convierte en uno solo, se guarda junto al original; la subcarpeta solo se crea cuando salen varios archivos (un PDF dividido en páginas).",
diff --git a/src/Filee.App/Assets/i18n/fr.json b/src/Filee.App/Assets/i18n/fr.json
index 68101164..75400e0c 100644
--- a/src/Filee.App/Assets/i18n/fr.json
+++ b/src/Filee.App/Assets/i18n/fr.json
@@ -760,6 +760,9 @@
"presets.location.SameFolder": "Même dossier que l'original",
"presets.location.Subfolder": "Un sous-dossier",
"presets.location.CustomFolder": "Un dossier fixe",
+ "presets.location.Ask": "Demander à chaque fois",
+ "ask.save_title": "Enregistrer le résultat sous",
+ "ask.folder_title": "Choisissez où enregistrer les résultats",
"presets.subfolder": "Nom du sous-dossier",
"presets.subfolder_only_several": "Seulement si un fichier en produit plusieurs",
"presets.subfolder_only_several_hint": "Un fichier converti en un seul fichier est enregistré à côté de l'original ; seul celui qui en produit plusieurs (un PDF découpé en pages) va dans le sous-dossier.",
diff --git a/src/Filee.App/Assets/i18n/hi.json b/src/Filee.App/Assets/i18n/hi.json
index 957153f4..fff88313 100644
--- a/src/Filee.App/Assets/i18n/hi.json
+++ b/src/Filee.App/Assets/i18n/hi.json
@@ -745,6 +745,9 @@
"presets.location.SameFolder": "स्रोत वाला ही फ़ोल्डर",
"presets.location.Subfolder": "एक सबफ़ोल्डर",
"presets.location.CustomFolder": "एक तय फ़ोल्डर",
+ "presets.location.Ask": "हर बार पूछें",
+ "ask.save_title": "परिणाम को इस रूप में सहेजें",
+ "ask.folder_title": "चुनें कि परिणाम कहाँ सहेजे जाएँ",
"presets.subfolder": "सबफ़ोल्डर का नाम",
"presets.subfolder_only_several": "सिर्फ़ तब, जब कई फ़ाइलें बनें",
"presets.subfolder_only_several_hint": "एक फ़ाइल बनने पर वह मूल फ़ाइल के पास सेव होती है; सबफ़ोल्डर सिर्फ़ तब बनता है जब कई फ़ाइलें बनें (जैसे PDF को पेजों में बाँटने पर)।",
diff --git a/src/Filee.App/Assets/i18n/ja.json b/src/Filee.App/Assets/i18n/ja.json
index 5dcc03f9..4e567d17 100644
--- a/src/Filee.App/Assets/i18n/ja.json
+++ b/src/Filee.App/Assets/i18n/ja.json
@@ -745,6 +745,9 @@
"presets.location.SameFolder": "元ファイルと同じフォルダー",
"presets.location.Subfolder": "サブフォルダー",
"presets.location.CustomFolder": "指定したフォルダー",
+ "presets.location.Ask": "毎回確認する",
+ "ask.save_title": "変換結果を保存",
+ "ask.folder_title": "変換結果の保存先を選択",
"presets.subfolder": "サブフォルダー名",
"presets.subfolder_only_several": "複数のファイルになるときだけ",
"presets.subfolder_only_several_hint": "1つのファイルに変換されたときは元のファイルの隣に保存し、複数のファイルになるとき(PDFをページごとに分けるときなど)だけサブフォルダーを作ります。",
diff --git a/src/Filee.App/Assets/i18n/ko.json b/src/Filee.App/Assets/i18n/ko.json
index 5e899b54..8ec8b087 100644
--- a/src/Filee.App/Assets/i18n/ko.json
+++ b/src/Filee.App/Assets/i18n/ko.json
@@ -760,6 +760,9 @@
"presets.location.SameFolder": "원본과 같은 폴더",
"presets.location.Subfolder": "하위 폴더",
"presets.location.CustomFolder": "지정한 폴더",
+ "presets.location.Ask": "매번 묻기",
+ "ask.save_title": "결과를 다른 이름으로 저장",
+ "ask.folder_title": "결과를 저장할 곳을 고르세요",
"presets.subfolder": "하위 폴더 이름",
"presets.subfolder_only_several": "여러 파일이 될 때만",
"presets.subfolder_only_several_hint": "한 파일로 변환되면 원본 옆에 저장하고, 여러 파일이 될 때(PDF를 페이지별로 나눌 때 등)만 하위 폴더를 만듭니다.",
diff --git a/src/Filee.App/Assets/i18n/ne.json b/src/Filee.App/Assets/i18n/ne.json
index a9a85890..9653b5bc 100644
--- a/src/Filee.App/Assets/i18n/ne.json
+++ b/src/Filee.App/Assets/i18n/ne.json
@@ -745,6 +745,9 @@
"presets.location.SameFolder": "स्रोत जस्तै उही फोल्डर",
"presets.location.Subfolder": "एउटा सबफोल्डर",
"presets.location.CustomFolder": "एउटा निश्चित फोल्डर",
+ "presets.location.Ask": "हरेक पटक सोध्नुहोस्",
+ "ask.save_title": "नतिजालाई यस रूपमा सेभ गर्नुहोस्",
+ "ask.folder_title": "नतिजाहरू कहाँ सेभ गर्ने छान्नुहोस्",
"presets.subfolder": "सबफोल्डर नाम",
"presets.subfolder_only_several": "धेरै फाइलहरू बन्दा मात्र",
"presets.subfolder_only_several_hint": "एउटा फाइल रूपान्तरण हुँदा मूल फाइलकै छेउमा सुरक्षित हुन्छ; धेरै फाइलहरू बन्दा मात्र सबफोल्डर बन्छ (जस्तै पृष्ठहरूमा विभाजित गरिएको PDF)।",
diff --git a/src/Filee.App/Assets/i18n/pl.json b/src/Filee.App/Assets/i18n/pl.json
index 72f4aa02..2cc735b7 100644
--- a/src/Filee.App/Assets/i18n/pl.json
+++ b/src/Filee.App/Assets/i18n/pl.json
@@ -760,6 +760,9 @@
"presets.location.SameFolder": "Ten sam folder co źródło",
"presets.location.Subfolder": "Podfolder",
"presets.location.CustomFolder": "Stały folder",
+ "presets.location.Ask": "Pytaj za każdym razem",
+ "ask.save_title": "Zapisz wynik jako",
+ "ask.folder_title": "Wybierz, gdzie zapisać wyniki",
"presets.subfolder": "Nazwa podfolderu",
"presets.subfolder_only_several": "Tylko gdy powstaje kilka plików",
"presets.subfolder_only_several_hint": "Plik przekonwertowany na jeden plik zostaje zapisany obok oryginału; podfolder powstaje tylko wtedy, gdy powstaje kilka plików (PDF podzielony na strony).",
diff --git a/src/Filee.App/Assets/i18n/pt-BR.json b/src/Filee.App/Assets/i18n/pt-BR.json
index 75099813..97c6a9fb 100644
--- a/src/Filee.App/Assets/i18n/pt-BR.json
+++ b/src/Filee.App/Assets/i18n/pt-BR.json
@@ -760,6 +760,9 @@
"presets.location.SameFolder": "A mesma pasta da origem",
"presets.location.Subfolder": "Uma subpasta",
"presets.location.CustomFolder": "Uma pasta fixa",
+ "presets.location.Ask": "Perguntar sempre",
+ "ask.save_title": "Salvar o resultado como",
+ "ask.folder_title": "Escolha onde salvar os resultados",
"presets.subfolder": "Nome da subpasta",
"presets.subfolder_only_several": "Só quando um arquivo vira vários",
"presets.subfolder_only_several_hint": "Um arquivo convertido em um único arquivo é salvo ao lado do original; só um que vira vários arquivos (um PDF dividido em páginas) vai para a subpasta.",
diff --git a/src/Filee.App/Assets/i18n/pt-PT.json b/src/Filee.App/Assets/i18n/pt-PT.json
index e6ca7c15..bf2db301 100644
--- a/src/Filee.App/Assets/i18n/pt-PT.json
+++ b/src/Filee.App/Assets/i18n/pt-PT.json
@@ -760,6 +760,9 @@
"presets.location.SameFolder": "Mesma pasta da origem",
"presets.location.Subfolder": "Uma subpasta",
"presets.location.CustomFolder": "Uma pasta fixa",
+ "presets.location.Ask": "Perguntar sempre",
+ "ask.save_title": "Guardar o resultado como",
+ "ask.folder_title": "Escolha onde guardar os resultados",
"presets.subfolder": "Nome da subpasta",
"presets.subfolder_only_several": "Só se resultar em vários ficheiros",
"presets.subfolder_only_several_hint": "Se a conversão gerar um só ficheiro, este é guardado junto ao original. A subpasta só é criada quando gerar vários ficheiros (por exemplo, ao dividir um PDF em páginas).",
diff --git a/src/Filee.App/Assets/i18n/ru.json b/src/Filee.App/Assets/i18n/ru.json
index 29acdd1e..69668b81 100644
--- a/src/Filee.App/Assets/i18n/ru.json
+++ b/src/Filee.App/Assets/i18n/ru.json
@@ -760,6 +760,9 @@
"presets.location.SameFolder": "В ту же папку, что исходник",
"presets.location.Subfolder": "Во вложенную папку",
"presets.location.CustomFolder": "В заданную папку",
+ "presets.location.Ask": "Спрашивать каждый раз",
+ "ask.save_title": "Сохранить результат как",
+ "ask.folder_title": "Выберите, куда сохранить результаты",
"presets.subfolder": "Имя вложенной папки",
"presets.subfolder_only_several": "Только если файлов получается несколько",
"presets.subfolder_only_several_hint": "Если из файла получается один файл, он сохраняется рядом с оригиналом; вложенная папка создаётся, только когда файлов несколько (например, PDF разбит на страницы).",
diff --git a/src/Filee.App/Assets/i18n/th.json b/src/Filee.App/Assets/i18n/th.json
index 8c419e6b..caf39ce4 100644
--- a/src/Filee.App/Assets/i18n/th.json
+++ b/src/Filee.App/Assets/i18n/th.json
@@ -745,6 +745,9 @@
"presets.location.SameFolder": "โฟลเดอร์เดียวกับต้นฉบับ",
"presets.location.Subfolder": "โฟลเดอร์ย่อย",
"presets.location.CustomFolder": "โฟลเดอร์ที่กำหนดเอง",
+ "presets.location.Ask": "ถามทุกครั้ง",
+ "ask.save_title": "บันทึกผลลัพธ์เป็น",
+ "ask.folder_title": "เลือกที่บันทึกผลลัพธ์",
"presets.subfolder": "ชื่อโฟลเดอร์ย่อย",
"presets.subfolder_only_several": "เฉพาะเมื่อหนึ่งไฟล์แยกเป็นหลายไฟล์",
"presets.subfolder_only_several_hint": "ไฟล์ที่แปลงแล้วได้ไฟล์เดียวจะบันทึกข้างไฟล์ต้นฉบับ มีเฉพาะไฟล์ที่แตกออกเป็นหลายไฟล์ (เช่น PDF ที่แยกหน้า) ที่จะบันทึกลงในโฟลเดอร์ย่อย",
diff --git a/src/Filee.App/Assets/i18n/tr.json b/src/Filee.App/Assets/i18n/tr.json
index 62a8e5e1..1bf29e89 100644
--- a/src/Filee.App/Assets/i18n/tr.json
+++ b/src/Filee.App/Assets/i18n/tr.json
@@ -745,6 +745,9 @@
"presets.location.SameFolder": "Kaynakla aynı klasör",
"presets.location.Subfolder": "Alt klasör",
"presets.location.CustomFolder": "Sabit klasör",
+ "presets.location.Ask": "Her seferinde sor",
+ "ask.save_title": "Sonucu farklı kaydet",
+ "ask.folder_title": "Sonuçların kaydedileceği yeri seçin",
"presets.subfolder": "Alt klasör adı",
"presets.subfolder_only_several": "Yalnızca tek dosya birden fazla dosyaya dönüşürse",
"presets.subfolder_only_several_hint": "Tek dosyaya dönüştürülen dosya özgünün yanına kaydedilir; yalnızca birkaç dosyaya dönüşenler (sayfalara bölünen PDF gibi) alt klasöre kaydedilir.",
diff --git a/src/Filee.App/Assets/i18n/zh-CN.json b/src/Filee.App/Assets/i18n/zh-CN.json
index 340de83b..0d252fa3 100644
--- a/src/Filee.App/Assets/i18n/zh-CN.json
+++ b/src/Filee.App/Assets/i18n/zh-CN.json
@@ -760,6 +760,9 @@
"presets.location.SameFolder": "与源文件相同的文件夹",
"presets.location.Subfolder": "子文件夹",
"presets.location.CustomFolder": "指定文件夹",
+ "presets.location.Ask": "每次询问",
+ "ask.save_title": "将结果另存为",
+ "ask.folder_title": "选择结果的保存位置",
"presets.subfolder": "子文件夹名称",
"presets.subfolder_only_several": "仅在生成多个文件时",
"presets.subfolder_only_several_hint": "只生成一个文件时保存在原文件旁边,生成多个文件时(例如 PDF 拆分成页面)才新建子文件夹。",
diff --git a/src/Filee.App/Assets/i18n/zh-TW.json b/src/Filee.App/Assets/i18n/zh-TW.json
index ee508a74..3c1f2c99 100644
--- a/src/Filee.App/Assets/i18n/zh-TW.json
+++ b/src/Filee.App/Assets/i18n/zh-TW.json
@@ -760,6 +760,9 @@
"presets.location.SameFolder": "與來源檔案相同的資料夾",
"presets.location.Subfolder": "子資料夾",
"presets.location.CustomFolder": "指定資料夾",
+ "presets.location.Ask": "每次詢問",
+ "ask.save_title": "將結果另存為",
+ "ask.folder_title": "選擇結果的儲存位置",
"presets.subfolder": "子資料夾名稱",
"presets.subfolder_only_several": "僅在產生多個檔案時",
"presets.subfolder_only_several_hint": "只產生一個檔案時儲存在原始檔案旁邊,產生多個檔案時(例如 PDF 拆分成頁面)才新增子資料夾。",
diff --git a/src/Filee.App/Services/RadialController.cs b/src/Filee.App/Services/RadialController.cs
index b8fb4174..b518bb0a 100644
--- a/src/Filee.App/Services/RadialController.cs
+++ b/src/Filee.App/Services/RadialController.cs
@@ -346,6 +346,15 @@ public sealed class RadialController(
return;
}
+ // "Ask every time" (#521): the save dialog first; the toast shows the job, the donut has closed for the dialog.
+ // shortcut: files from a browser aren't asked about, they save into the download folder as "next to the source".
+ if (preset.Output.Location == OutputLocation.Ask && web is null)
+ {
+ Close(animate: false);
+ _ = AskThenConvertAsync(sources, preset, oneResult: sources.Count == 1);
+ return;
+ }
+
log.LogInformation("Converting {Count} file(s) with preset {Preset}{Web}", sources.Count, preset.Id,
web is null ? "" : " (from a browser)");
var job = conversions.Start(sources, preset, showInToast: false, web);
@@ -363,7 +372,9 @@ public sealed class RadialController(
try
{
var ordered = await windows.ChooseMergeOrderAsync(files);
- if (ordered is not null)
+ if (ordered is not null && preset.Output.Location == OutputLocation.Ask && web is null)
+ await AskThenConvertAsync(ordered, preset, oneResult: true); // the merge is one file
+ else if (ordered is not null)
{
conversions.Start(ordered, preset, web: web);
web = null; // the conversion owns the browser drop now
@@ -379,6 +390,22 @@ public sealed class RadialController(
}
}
+ private async Task AskThenConvertAsync(IReadOnlyList<string> sources, Preset preset, bool oneResult)
+ {
+ try
+ {
+ if (await windows.AskSaveLocationAsync(sources, preset, oneResult) is { } asked)
+ {
+ log.LogInformation("Converting {Count} file(s) with preset {Preset} where the user chose", sources.Count, preset.Id);
+ conversions.Start(sources, asked);
+ }
+ }
+ catch (Exception ex) when (ex is not OutOfMemoryException)
+ {
+ log.LogError(ex, "Could not ask where to save");
+ }
+ }
+
/// <summary>A tool (crop, clip) on files from a browser: they are saved first, then it opens on them.</summary>
private async Task ShowToolForBrowserFilesAsync(WebDrop web, Filee.Core.Presets.Preset preset, PixelPoint? near)
{
diff --git a/src/Filee.App/Services/WindowService.cs b/src/Filee.App/Services/WindowService.cs
index 20ed7e98..90a21e0f 100644
--- a/src/Filee.App/Services/WindowService.cs
+++ b/src/Filee.App/Services/WindowService.cs
@@ -5,6 +5,7 @@ using Avalonia.Controls;
using Avalonia.Controls.ApplicationLifetimes;
using Avalonia.Layout;
using Avalonia.Media;
+using Avalonia.Platform.Storage;
using Filee.App.ViewModels;
using Filee.App.Views;
using Filee.Core.Conversion;
@@ -67,6 +68,56 @@ public sealed class WindowService(ILocalizer loc, IServiceProvider services, Mem
return dialog.Result;
}
+ /// <summary>
+ /// "Ask every time" (#521): one save dialog for the batch, starting in the first source's folder. One result is
+ /// saved under a name (<see cref="AskedLocation.ForFile"/>), several go into a folder. Null when cancelled.
+ /// </summary>
+ /// <param name="oneResult">The batch makes one file (a single source, or a merge of several).</param>
+ public async Task<Preset?> AskSaveLocationAsync(IReadOnlyList<string> sources, Preset preset, bool oneResult)
+ {
+ // The donut has closed and the main window may be in the tray: a small window of its own owns the dialog.
+ var host = new Window
+ {
+ Width = 1,
+ Height = 1,
+ Opacity = 0,
+ ShowInTaskbar = false,
+ WindowDecorations = WindowDecorations.None,
+ WindowStartupLocation = WindowStartupLocation.CenterScreen,
+ Title = "Filee",
+ };
+ host.Show();
+ try
+ {
+ var storage = host.StorageProvider;
+ var start = await storage.TryGetFolderFromPathAsync(Path.GetDirectoryName(Path.GetFullPath(sources[0]))!);
+ if (oneResult)
+ {
+ var extension = AskedLocation.Extension(preset, sources[0]);
+ var file = await storage.SaveFilePickerAsync(new Avalonia.Platform.Storage.FilePickerSaveOptions
+ {
+ Title = loc["ask.save_title"],
+ SuggestedStartLocation = start,
+ SuggestedFileName = AskedLocation.SuggestedName(preset, loc.DisplayName(preset), sources[0]),
+ DefaultExtension = extension.Length == 0 ? null : extension,
+ ShowOverwritePrompt = true,
+ });
+ return file?.TryGetLocalPath() is { } path ? AskedLocation.ForFile(preset, path) : null;
+ }
+ var folders = await storage.OpenFolderPickerAsync(new Avalonia.Platform.Storage.FolderPickerOpenOptions
+ {
+ Title = loc["ask.folder_title"],
+ SuggestedStartLocation = start,
+ AllowMultiple = false,
+ });
+ return folders.FirstOrDefault()?.TryGetLocalPath() is { } folder ? AskedLocation.ForFolder(preset, folder) : null;
+ }
+ finally
+ {
+ host.Close();
+ }
+ }
+
public MainWindow? Main => _main;
/// <summary>
diff --git a/src/Filee.Core/Presets/AskedLocation.cs b/src/Filee.Core/Presets/AskedLocation.cs
new file mode 100644
index 00000000..4bc58201
--- /dev/null
+++ b/src/Filee.Core/Presets/AskedLocation.cs
@@ -0,0 +1,55 @@
+// "Ask every time" (#521): what the save dialog suggests, and the preset as it runs once the user has answered it.
+
+using Filee.Core.Formats;
+
+namespace Filee.Core.Presets;
+
+public static class AskedLocation
+{
+ /// <summary>
+ /// The name the save dialog suggests for <paramref name="source"/>: the preset's name pattern and renames, and the
+ /// target's extension (the source's own for "same as source").
+ /// </summary>
+ public static string SuggestedName(Preset preset, string presetName, string source)
+ {
+ var tokens = new OutputPathResolver.Tokens(source, presetName, 1, DateTime.Now);
+ var name = OutputPathResolver.Sanitize(
+ OutputPathResolver.Rename(OutputPathResolver.ExpandPattern(preset.Output.FileNamePattern, tokens), preset.Output.Renames),
+ FormatRegistry.NameWithoutExtension(source));
+ var extension = Extension(preset, source);
+ return extension.Length == 0 ? name : $"{name}.{extension}";
+ }
+
+ /// <summary>The extension the result gets, without the dot; empty for a folder ("Extract").</summary>
+ public static string Extension(Preset preset, string source) =>
+ preset.TargetFormat == BuiltInData.SameAsSource
+ ? FormatRegistry.ExtensionOf(source)
+ : FormatRegistry.FindById(preset.TargetFormat)?.Extensions.FirstOrDefault() ?? "";
+
+ /// <summary>
+ /// One result, saved as <paramref name="chosenPath"/>: that folder and that name, without the pattern or renames
+ /// on top. The dialog has already asked about replacing a file there, so it is replaced.
+ /// </summary>
+ public static Preset ForFile(Preset preset, string chosenPath)
+ {
+ var copy = InFolder(preset, Path.GetDirectoryName(Path.GetFullPath(chosenPath))!);
+ // shortcut: a chosen name with a pattern token in it ("{date}") is expanded, there is no escape; rare enough.
+ copy.Output.FileNamePattern = Path.GetFileNameWithoutExtension(chosenPath);
+ copy.Output.Renames = [];
+ copy.Output.Conflict = ConflictPolicy.Overwrite;
+ return copy;
+ }
+
+ /// <summary>Several results, all saved in <paramref name="folder"/> under the preset's own names.</summary>
+ public static Preset ForFolder(Preset preset, string folder) => InFolder(preset, folder);
+
+ private static Preset InFolder(Preset preset, string folder)
+ {
+ var copy = preset.Clone();
+ copy.Output.Location = OutputLocation.CustomFolder;
+ copy.Output.CustomFolder = folder;
+ copy.Output.KeepFoldersFrom = "";
+ copy.Output.SubfolderOnlyForSeveralFiles = false;
+ return copy;
+ }
+}
diff --git a/src/Filee.Core/Presets/OutputRule.cs b/src/Filee.Core/Presets/OutputRule.cs
index c9dc828b..fe871494 100644
--- a/src/Filee.Core/Presets/OutputRule.cs
+++ b/src/Filee.Core/Presets/OutputRule.cs
@@ -16,6 +16,11 @@ public enum OutputLocation
Subfolder,
/// <summary>In a fixed folder (see <see cref="OutputRule.CustomFolder"/>).</summary>
CustomFolder,
+ /// <summary>
+ /// "Ask every time" (#521): a save dialog that starts in the source's folder, once per batch (see
+ /// <see cref="AskedLocation"/>). Where nothing can ask (watch folders, the command line), next to the source.
+ /// </summary>
+ Ask,
}
/// <summary>What to do when the output file already exists.</summary>
diff --git a/tests/Filee.Core.Tests/AskedLocationTests.cs b/tests/Filee.Core.Tests/AskedLocationTests.cs
new file mode 100644
index 00000000..c964fb0f
--- /dev/null
+++ b/tests/Filee.Core.Tests/AskedLocationTests.cs
@@ -0,0 +1,58 @@
+// "Ask every time" (#521): what the save dialog suggests, and where the files go once it is answered.
+
+using Filee.Core.Presets;
+
+namespace Filee.Core.Tests;
+
+public class AskedLocationTests
+{
+ private static readonly OutputPathResolver.Tokens At = new(Path.Combine(Path.GetTempPath(), "photos", "IMG_0412.heic"), "JPG", 1, DateTime.Now);
+
+ private static Preset Asking(string target = "jpg") => new()
+ {
+ TargetFormat = target,
+ Output = { Location = OutputLocation.Ask, FileNamePattern = "{name}_small", Renames = [new RenameStep { Kind = RenameKind.Replace, Find = "IMG_", Replace = "Photo_" }] },
+ };
+
+ [Fact]
+ public void The_dialog_suggests_the_name_the_preset_would_give()
+ {
+ Assert.Equal("Photo_0412_small.jpg", AskedLocation.SuggestedName(Asking(), "JPG", At.SourcePath));
+ Assert.Equal("Photo_0412_small.heic", AskedLocation.SuggestedName(Asking(BuiltInData.SameAsSource), "Same", At.SourcePath));
+ }
+
+ [Fact]
+ public void Where_nothing_asks_the_result_goes_next_to_the_source()
+ {
+ var path = OutputPathResolver.Resolve(Asking().Output, At, "jpg", _ => false);
+ Assert.Equal(Path.Combine(Path.GetDirectoryName(At.SourcePath)!, "Photo_0412_small.jpg"), path);
+ }
+
+ [Fact]
+ public void One_result_is_saved_exactly_as_chosen_replacing_what_the_dialog_asked_about()
+ {
+ var chosen = Path.Combine(Path.GetTempPath(), "out", "holiday.jpg");
+ var preset = Asking();
+
+ var asked = AskedLocation.ForFile(preset, chosen);
+
+ // The name typed in the dialog, without the pattern or renames on top, even though the file exists.
+ Assert.Equal(chosen, OutputPathResolver.Resolve(asked.Output, At, "jpg", _ => true));
+ Assert.Equal(OutputLocation.Ask, preset.Output.Location); // the preset itself keeps asking
+ Assert.Single(preset.Output.Renames);
+ }
+
+ [Fact]
+ public void Several_results_go_into_the_chosen_folder_under_their_own_names()
+ {
+ var folder = Path.Combine(Path.GetTempPath(), "chosen");
+ var preset = Asking();
+ preset.Output.Conflict = ConflictPolicy.Rename;
+
+ var asked = AskedLocation.ForFolder(preset, folder);
+
+ Assert.Equal(Path.Combine(folder, "Photo_0412_small.jpg"), OutputPathResolver.Resolve(asked.Output, At, "jpg", _ => false));
+ // An existing file there isn't replaced: only one picked by name in the dialog is.
+ Assert.Equal(Path.Combine(folder, "Photo_0412_small (2).jpg"), OutputPathResolver.Resolve(asked.Output, At, "jpg", p => !p.Contains("(2)")));
+ }
+}