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.
C# audio-converteravaloniabatch-conversionconvertercsharpdocument-converterdocx-to-pdfdotnetdrag-and-dropfile-conversionfile-converterheic-converterhwphwpximage-converterlinuxmacospdf-convertervideo-converterwindows
Watch folders: rename rules in their own window
KnifeLemone2cbe7659fff
diff --git a/CHANGELOG.md b/CHANGELOG.mdindex df256f0e..198590da 100644--- a/CHANGELOG.md+++ b/CHANGELOG.md@@ -24,10 +24,12 @@ find it, what it does and doesn't do.many files in the folder match. Other files in the folder are left alone.- *File name rule*: a name pattern for this folder in place of the preset's, with `{name}`, `{date}`, `{time}`,`{index}` and `{preset}`.- - *Replace part of the name*: regular expressions and what to put in their place, applied in order, e.g.- `IMG_(\d+)` → `Photo_$1`. **Common replacements** lists ready-made ones (camera numbers, spaces, copy numbers- like "(2)", text in brackets, dates, symbols, text at the start or end), each with an example of what it does;- double-click one or press + to add it as a step and change it from there.+ - *Rename converted files*: **Edit rules** opens a window of rules that find part of the name with a regular+ expression and replace it, applied from top to bottom (e.g. `IMG_(\d+)` → `Photo_$1`). **Common replacements**+ on the left lists ready-made ones (camera numbers, spaces, copy numbers like "(2)", text in brackets, dates,+ symbols, text at the start or end), each with an example of what it does; double-click one or press + to add it+ and change it from there. The preview shows files from the folder before and after, and any name you type.+ Nothing changes until you save.- A **preview** on every watch folder shows a converted file as it will be saved (`IMG_0412.jpg →converted\Photo_0412.pdf`, using a file already in the folder when there is one), what happens when the name istaken and what happens to the original.diff --git a/src/Filee.App/Assets/i18n/en.json b/src/Filee.App/Assets/i18n/en.jsonindex c49722bc..90079e7d 100644--- a/src/Filee.App/Assets/i18n/en.json+++ b/src/Filee.App/Assets/i18n/en.json@@ -481,15 +481,25 @@"watch.name": "File name rule","watch.name_placeholder": "Same as the preset: {0}","watch.name_hint": "{name} original name · {date} date · {time} time · {index} number in the batch · {preset} preset name",- "watch.rename": "Replace part of the name (regular expressions, applied in order)",+ "watch.rename": "Rename converted files","watch.rename_find": "Find, e.g. IMG_(\\d+)","watch.rename_replace": "Replace with, e.g. Photo_$1",+ "watch.rename_none": "Names stay as the file name rule makes them.",+ "watch.rename_edit": "Edit rules",+ "watch.rename_add": "Add rules",+ "watch.rename_title": "Rename converted files",+ "watch.rename_intro": "Each rule finds part of the name with a regular expression and replaces it; the rules run from top to bottom. The preview shows what happens to files in the folder.",+ "watch.rename_steps": "Rules (applied in order)",+ "watch.rename_no_steps": "No rules yet. Pick one on the left or add an empty one.",+ "watch.step_up": "Move up (run earlier)",+ "watch.rename_try": "Try a name",+ "watch.rename_try_placeholder": "Type a file name, e.g. IMG_0412.jpg","watch.include_matches": "{0} file(s) in the folder match now",- "watch.add_step": "Add a step",- "watch.remove_step": "Remove this step",+ "watch.add_step": "Add a rule",+ "watch.remove_step": "Remove this rule","watch.recipes": "Common replacements",- "watch.recipes_hint": "Double-click one (or press +) to add it as a step, then change it if you like.",- "watch.recipe_add": "Add as a step",+ "watch.recipes_hint": "Double-click one (or press +) to add it as a rule, then change it if you like.",+ "watch.recipe_add": "Add as a rule","watch.recipe_removes": "(removed)","watch.recipe.photo_number": "Camera file names to Photo_number","watch.recipe.drop_camera_prefix": "Remove IMG_, DSC_ or PXL_",diff --git a/src/Filee.App/Assets/i18n/ko.json b/src/Filee.App/Assets/i18n/ko.jsonindex 7dd06f96..92021cb0 100644--- a/src/Filee.App/Assets/i18n/ko.json+++ b/src/Filee.App/Assets/i18n/ko.json@@ -481,15 +481,25 @@"watch.name": "파일명 규칙","watch.name_placeholder": "프리셋과 같게: {0}","watch.name_hint": "{name} 원래 이름 · {date} 날짜 · {time} 시간 · {index} 순번 · {preset} 프리셋 이름",- "watch.rename": "이름 일부 바꾸기 (정규식, 위에서부터 차례로)",+ "watch.rename": "변환된 파일 이름 바꾸기","watch.rename_find": "찾을 패턴 (예: IMG_(\\d+))","watch.rename_replace": "바꿀 내용 (예: 사진_$1)",+ "watch.rename_none": "파일명 규칙으로 만든 이름을 그대로 써요.",+ "watch.rename_edit": "규칙 편집",+ "watch.rename_add": "규칙 추가",+ "watch.rename_title": "변환된 파일 이름 바꾸기",+ "watch.rename_intro": "규칙마다 이름의 일부를 정규식으로 찾아서 바꿔요. 위에서부터 차례로 적용되고, 미리보기에서 폴더의 파일이 어떻게 바뀌는지 바로 확인할 수 있어요.",+ "watch.rename_steps": "규칙 (위에서부터 차례로 적용)",+ "watch.rename_no_steps": "아직 규칙이 없어요. 왼쪽에서 고르거나 빈 규칙을 추가하세요.",+ "watch.step_up": "위로 (먼저 적용)",+ "watch.rename_try": "이름 넣어 보기",+ "watch.rename_try_placeholder": "파일 이름 입력 (예: IMG_0412.jpg)","watch.include_matches": "지금 폴더에서 {0}개 파일이 해당돼요",- "watch.add_step": "단계 추가",- "watch.remove_step": "이 단계 지우기",+ "watch.add_step": "규칙 추가",+ "watch.remove_step": "이 규칙 지우기","watch.recipes": "자주 쓰는 규칙",- "watch.recipes_hint": "더블클릭하거나 + 를 누르면 단계로 추가돼요. 추가한 뒤 자유롭게 고칠 수 있어요.",- "watch.recipe_add": "단계로 추가",+ "watch.recipes_hint": "더블클릭하거나 + 를 누르면 규칙으로 추가돼요. 추가한 뒤 자유롭게 고칠 수 있어요.",+ "watch.recipe_add": "규칙으로 추가","watch.recipe_removes": "(지우기)","watch.recipe.photo_number": "카메라 파일 이름을 Photo_번호로","watch.recipe.drop_camera_prefix": "IMG_, DSC_, PXL_ 지우기",diff --git a/src/Filee.App/Assets/i18n/zh-CN.json b/src/Filee.App/Assets/i18n/zh-CN.jsonindex bafaa6ed..e620c576 100644--- a/src/Filee.App/Assets/i18n/zh-CN.json+++ b/src/Filee.App/Assets/i18n/zh-CN.json@@ -481,15 +481,25 @@"watch.name": "文件名规则","watch.name_placeholder": "与预设相同:{0}","watch.name_hint": "{name} 原文件名 · {date} 日期 · {time} 时间 · {index} 序号 · {preset} 预设名称",- "watch.rename": "替换名称中的文字(正则表达式,按顺序执行)",+ "watch.rename": "重命名转换后的文件","watch.rename_find": "查找,例如 IMG_(\\d+)","watch.rename_replace": "替换为,例如 照片_$1",+ "watch.rename_none": "名称保持文件名规则生成的样子。",+ "watch.rename_edit": "编辑规则",+ "watch.rename_add": "添加规则",+ "watch.rename_title": "重命名转换后的文件",+ "watch.rename_intro": "每条规则用正则表达式找到名称的一部分并替换,规则从上到下依次执行。预览会显示文件夹中的文件如何变化。",+ "watch.rename_steps": "规则(按顺序执行)",+ "watch.rename_no_steps": "还没有规则。从左侧选择,或添加一条空规则。",+ "watch.step_up": "上移(先执行)",+ "watch.rename_try": "试一个名称",+ "watch.rename_try_placeholder": "输入文件名,例如 IMG_0412.jpg","watch.include_matches": "文件夹中目前有 {0} 个文件符合",- "watch.add_step": "添加一步",- "watch.remove_step": "删除此步",+ "watch.add_step": "添加规则",+ "watch.remove_step": "删除此规则","watch.recipes": "常用规则",- "watch.recipes_hint": "双击(或点 +)即可添加为一步,添加后可以再修改。",- "watch.recipe_add": "添加为一步",+ "watch.recipes_hint": "双击(或点 +)即可添加为规则,添加后可以再修改。",+ "watch.recipe_add": "添加为规则","watch.recipe_removes": "(删除)","watch.recipe.photo_number": "相机文件名改为 Photo_编号","watch.recipe.drop_camera_prefix": "去掉 IMG_、DSC_、PXL_",diff --git a/src/Filee.App/ViewModels/Pages/WatchFoldersPageViewModel.cs b/src/Filee.App/ViewModels/Pages/WatchFoldersPageViewModel.csindex 99096937..05284889 100644--- a/src/Filee.App/ViewModels/Pages/WatchFoldersPageViewModel.cs+++ b/src/Filee.App/ViewModels/Pages/WatchFoldersPageViewModel.cs@@ -79,12 +79,7 @@ public sealed partial class WatchFoldersPageViewModel : ObservableObject, IDisporeturn null;var folder = rule.Folder.Trim();var source = SampleFile(rule) ?? Path.Combine(folder, _loc["watch.sample_file"]);- var extension = preset.TargetFormat switch- {- BuiltInData.SameAsSource => FormatRegistry.ExtensionOf(source),- FormatRegistry.Folder => "",- var id => FormatRegistry.FindById(id)?.PrimaryExtension ?? id,- };+ var extension = TargetExtension(preset, source);var applied = rule.Apply(preset);var output = OutputPathResolver.Resolve(applied.Output,new OutputPathResolver.Tokens(source, _loc.DisplayName(preset), 1, DateTime.Now), extension, _ => false) ?? "";@@ -106,6 +101,44 @@ public sealed partial class WatchFoldersPageViewModel : ObservableObject, IDispointernal string Text(string key) => _loc[key];+ internal ILocalizer Localizer => _loc;++ /// <summary>The file name a source gets in this folder with <paramref name="steps"/> in place of the rule's.</summary>+ internal string OutputNameOf(WatchRule rule, string source, IReadOnlyList<RenameStep> steps)+ {+ if (_store.FindPreset(rule.PresetId) is not { } preset)+ return source;+ var trial = rule.Clone();+ trial.Renames = [.. steps];+ var applied = trial.Apply(preset);+ var output = OutputPathResolver.Resolve(applied.Output,+ new OutputPathResolver.Tokens(source, _loc.DisplayName(preset), 1, DateTime.Now), TargetExtension(preset, source), _ => false);+ return output is null ? source : Path.GetFileName(output);+ }++ /// <summary>Names of a few files in the folder the rule would convert, for the rename preview.</summary>+ internal static IReadOnlyList<string> SampleNames(WatchRule rule)+ {+ if (string.IsNullOrWhiteSpace(rule.Folder) || !Directory.Exists(rule.Folder))+ return [];+ try+ {+ return Directory.EnumerateFiles(rule.Folder).Take(500).Where(path => !FolderWatcher.ShouldIgnore(path, rule))+ .Select(Path.GetFileName).OfType<string>().Take(8).ToList();+ }+ catch (Exception ex) when (ex is IOException or UnauthorizedAccessException)+ {+ return [];+ }+ }++ private static string TargetExtension(Preset preset, string source) => preset.TargetFormat switch+ {+ BuiltInData.SameAsSource => FormatRegistry.ExtensionOf(source),+ FormatRegistry.Folder => "",+ var id => FormatRegistry.FindById(id)?.PrimaryExtension ?? id,+ };+/// <summary>Extensions starting with what is typed ("he" → *.heic, *.heif), minus the patterns already there.</summary>internal static IReadOnlyList<TagSuggestion> ExtensionSuggestions(string typed, IReadOnlyCollection<string> existing){@@ -179,9 +212,6 @@ public sealed partial class WatchRuleViewModel : ObservableObject_originals = page.OriginalsChoices.First(c => c.Value == rule.Originals);_status = page.StatusOf(rule);_fileNamePattern = rule.FileNamePattern;- foreach (var step in rule.Renames)- RenameSteps.Add(new RenameStepViewModel(step, this));- Recipes = RenameRecipes.All.Select(r => new RenameRecipeViewModel(r, page.Text(r.TitleKey), page.Text("watch.recipe_removes"), this)).ToList();// Options in use stay in view; a new rule starts with them folded away._showOptions = rule.Include.Count > 0 || rule.FileNamePattern.Length > 0 || rule.Renames.Count > 0;RefreshIncludeTags();@@ -220,13 +250,10 @@ public sealed partial class WatchRuleViewModel : ObservableObject/// <summary>"Same as the preset: {name}" in the empty file name box.</summary>[ObservableProperty] private string _fileNamePlaceholder = "";- /// <summary>Replacements applied in order to the name.</summary>- public ObservableCollection<RenameStepViewModel> RenameSteps { get; } = [];+ /// <summary>The rename steps, one "find → replace" line each, for the card.</summary>+ [ObservableProperty] private IReadOnlyList<string> _renameSummary = [];- /// <summary>Ready-made replacements, each with what it does to an example name.</summary>- public IReadOnlyList<RenameRecipeViewModel> Recipes { get; }-- [ObservableProperty] private bool _showRecipes;+ public bool HasRenames => RenameSummary.Count > 0;/// <summary>"scan.jpg → converted\scan.pdf": a converted file as it would be saved.</summary>[ObservableProperty] private string? _previewExample;@@ -253,9 +280,6 @@ public sealed partial class WatchRuleViewModel : ObservableObject[RelayCommand]private void ToggleOptions() => ShowOptions = !ShowOptions;- [RelayCommand]- private void ToggleRecipes() => ShowRecipes = !ShowRecipes;-/// <summary>Adds a typed pattern: "heic" becomes *.heic, plain text matches names containing it.</summary>[RelayCommand]private void AddInclude(string? typed)@@ -281,26 +305,12 @@ public sealed partial class WatchRuleViewModel : ObservableObjectChange(r => r.Include.RemoveAll(p => p == chip.Value));}- [RelayCommand]- private void AddStep() => AddStep(new RenameStep());-- internal void AddStep(RenameStep step)- {- Rule.Renames.Add(step);- RenameSteps.Add(new RenameStepViewModel(step, this));- StepsChanged();- }-- internal void RemoveStep(RenameStepViewModel step)- {- Rule.Renames.Remove(step.Step);- RenameSteps.Remove(step);- StepsChanged();- }-- internal void StepsChanged() => Change(_ => { });+ /// <summary>The dialog that edits the rename steps, on copies of them.</summary>+ public RenameToolViewModel CreateRenameTool() =>+ new(Rule.Renames, WatchFoldersPageViewModel.SampleNames(Rule), (steps, source) => _page.OutputNameOf(Rule, source, steps), _page.Localizer);- internal string InvalidRegex(string error) => _page.Format("watch.invalid_regex", error);+ /// <summary>Takes the steps the dialog applied.</summary>+ public void SetRenames(List<RenameStep> steps) => Change(r => r.Renames = steps);[RelayCommand]private void Remove() => _page.Remove(this);@@ -324,6 +334,8 @@ public sealed partial class WatchRuleViewModel : ObservableObjectprivate void RefreshPreview(){+ RenameSummary = Rule.Renames.Select(r => $"{r.Find} → {(r.Replace.Length == 0 ? _page.Text("watch.recipe_removes") : r.Replace)}").ToList();+ OnPropertyChanged(nameof(HasRenames));FileNamePlaceholder = _page.Format("watch.name_placeholder", _page.PresetNamePattern(Rule));var preview = _page.PreviewOf(Rule);PreviewExample = preview?.Example;@@ -332,59 +344,3 @@ public sealed partial class WatchRuleViewModel : ObservableObject}}-/// <summary>One replacement in a watch folder's names: a regular expression and what goes in its place.</summary>-public sealed partial class RenameStepViewModel : ObservableObject-{- private readonly WatchRuleViewModel _rule;-- public RenameStepViewModel(RenameStep step, WatchRuleViewModel rule)- {- Step = step;- _rule = rule;- _find = step.Find;- _replace = step.Replace;- Validate();- }-- public RenameStep Step { get; }-- [ObservableProperty] private string _find;- [ObservableProperty] private string _replace;-- /// <summary>Why <see cref="Find"/> is not a valid regular expression, or null.</summary>- [ObservableProperty] private string? _error;-- partial void OnFindChanged(string value)- {- Step.Find = value;- Validate();- _rule.StepsChanged();- }-- partial void OnReplaceChanged(string value)- {- Step.Replace = value;- _rule.StepsChanged();- }-- [RelayCommand]- private void Remove() => _rule.RemoveStep(this);-- private void Validate() => Error = OutputPathResolver.RenameError(Find) is { } error ? _rule.InvalidRegex(error) : null;-}--/// <summary>A ready-made replacement in the list: what it does, its expression and an example.</summary>-public sealed partial class RenameRecipeViewModel(RenameRecipe recipe, string title, string removes, WatchRuleViewModel rule) : ObservableObject-{- public string Title { get; } = title;-- /// <summary>"IMG_(\d+) → Photo_$1"; an empty replacement shows as "(removed)".</summary>- public string Expression { get; } = $"{recipe.Find} → {(recipe.Replace.Length == 0 ? removes : recipe.Replace)}";-- /// <summary>"IMG_0412 → Photo_0412".</summary>- public string Example { get; } = $"{recipe.Example} → {OutputPathResolver.Rename(recipe.Example, recipe.Find, recipe.Replace)}";-- /// <summary>Adds the replacement as the last step (double-click, or the + button).</summary>- [RelayCommand]- private void Add() => rule.AddStep(new RenameStep { Find = recipe.Find, Replace = recipe.Replace });-}diff --git a/src/Filee.App/ViewModels/RenameToolViewModel.cs b/src/Filee.App/ViewModels/RenameToolViewModel.csnew file mode 100644index 00000000..a1bf2271--- /dev/null+++ b/src/Filee.App/ViewModels/RenameToolViewModel.cs@@ -0,0 +1,166 @@+// The name tool of a watch folder (Watch folders → More options → Replace part of the name → Name tool…): regular+// expression steps applied in order, ready-made replacements to add with a double-click, and a preview of files from+// the folder before and after. Works on copies; the folder takes the steps only when the dialog is applied.++using System.Collections.ObjectModel;+using CommunityToolkit.Mvvm.ComponentModel;+using CommunityToolkit.Mvvm.Input;+using Filee.App.ViewModels.Pages;+using Filee.Core.Localization;+using Filee.Core.Presets;++namespace Filee.App.ViewModels;++/// <summary>A file name before and after the steps.</summary>+public sealed record RenamePreview(string Before, string After);++public sealed partial class RenameToolViewModel : ObservableObject+{+ private readonly ILocalizer _loc;+ private readonly Func<IReadOnlyList<RenameStep>, string, string> _rename;+ private readonly IReadOnlyList<string> _samples;++ /// <param name="steps">The folder's steps (copied; changes stay here until <see cref="Result"/> is taken).</param>+ /// <param name="samples">Names of files in the folder (with extension), for the preview.</param>+ /// <param name="rename">The name a file gets with some steps: source name → converted file name.</param>+ public RenameToolViewModel(IEnumerable<RenameStep> steps, IReadOnlyList<string> samples,+ Func<IReadOnlyList<RenameStep>, string, string> rename, ILocalizer loc)+ {+ _loc = loc;+ _rename = rename;+ _samples = samples;+ foreach (var step in steps)+ Steps.Add(new RenameStepViewModel(step.Clone(), this));+ Recipes = RenameRecipes.All.Select(r => new RenameRecipeViewModel(r, loc[r.TitleKey], loc["watch.recipe_removes"], this)).ToList();+ _customName = samples.Count == 0 ? loc["watch.sample_file"] : "";+ Refresh();+ }++ /// <summary>Replacements applied in order.</summary>+ public ObservableCollection<RenameStepViewModel> Steps { get; } = [];++ /// <summary>Ready-made replacements, each with what it does to an example name.</summary>+ public IReadOnlyList<RenameRecipeViewModel> Recipes { get; }++ /// <summary>Files from the folder, before and after.</summary>+ public ObservableCollection<RenamePreview> Previews { get; } = [];++ public bool HasSamples => _samples.Count > 0;++ /// <summary>A name to try the steps on.</summary>+ [ObservableProperty] private string _customName;++ /// <summary>What <see cref="CustomName"/> becomes.</summary>+ [ObservableProperty] private string _customResult = "";++ public bool HasNoSteps => Steps.Count == 0;++ /// <summary>True when every step's expression is valid.</summary>+ public bool IsValid => Steps.All(s => s.Error is null);++ /// <summary>The steps to keep: the ones with an expression.</summary>+ public List<RenameStep> Result => Steps.Where(s => s.Find.Length > 0).Select(s => s.Step.Clone()).ToList();++ partial void OnCustomNameChanged(string value) => Refresh();++ [RelayCommand]+ private void AddStep() => AddStep(new RenameStep());++ internal void AddStep(RenameStep step)+ {+ Steps.Add(new RenameStepViewModel(step, this));+ StepsChanged();+ }++ internal void RemoveStep(RenameStepViewModel step)+ {+ Steps.Remove(step);+ StepsChanged();+ }++ /// <summary>Moves a step one place up (it runs earlier).</summary>+ internal void MoveUp(RenameStepViewModel step)+ {+ var index = Steps.IndexOf(step);+ if (index > 0)+ {+ Steps.Move(index, index - 1);+ StepsChanged();+ }+ }++ internal void StepsChanged() => Refresh();++ internal string InvalidRegex(string error) => _loc.Format("watch.invalid_regex", error);++ private void Refresh()+ {+ var steps = Steps.Select(s => s.Step).Where(s => s.Find.Length > 0).ToList();+ Previews.Clear();+ foreach (var sample in _samples)+ Previews.Add(new RenamePreview(sample, _rename(steps, sample)));+ CustomResult = CustomName.Trim().Length == 0 ? "" : _rename(steps, CustomName.Trim());+ OnPropertyChanged(nameof(HasNoSteps));+ OnPropertyChanged(nameof(IsValid));+ }+}++/// <summary>One replacement: a regular expression and what goes in its place.</summary>+public sealed partial class RenameStepViewModel : ObservableObject+{+ private readonly RenameToolViewModel _tool;++ public RenameStepViewModel(RenameStep step, RenameToolViewModel tool)+ {+ Step = step;+ _tool = tool;+ _find = step.Find;+ _replace = step.Replace;+ Validate();+ }++ public RenameStep Step { get; }++ [ObservableProperty] private string _find;+ [ObservableProperty] private string _replace;++ /// <summary>Why <see cref="Find"/> is not a valid regular expression, or null.</summary>+ [ObservableProperty] private string? _error;++ partial void OnFindChanged(string value)+ {+ Step.Find = value;+ Validate();+ _tool.StepsChanged();+ }++ partial void OnReplaceChanged(string value)+ {+ Step.Replace = value;+ _tool.StepsChanged();+ }++ [RelayCommand]+ private void Remove() => _tool.RemoveStep(this);++ [RelayCommand]+ private void MoveUp() => _tool.MoveUp(this);++ private void Validate() => Error = OutputPathResolver.RenameError(Find) is { } error ? _tool.InvalidRegex(error) : null;+}++/// <summary>A ready-made replacement in the list: what it does, its expression and an example.</summary>+public sealed partial class RenameRecipeViewModel(RenameRecipe recipe, string title, string removes, RenameToolViewModel tool) : ObservableObject+{+ public string Title { get; } = title;++ /// <summary>"IMG_(\d+) → Photo_$1"; an empty replacement shows as "(removed)".</summary>+ public string Expression { get; } = $"{recipe.Find} → {(recipe.Replace.Length == 0 ? removes : recipe.Replace)}";++ /// <summary>"IMG_0412 → Photo_0412".</summary>+ public string Example { get; } = $"{recipe.Example} → {OutputPathResolver.Rename(recipe.Example, recipe.Find, recipe.Replace)}";++ /// <summary>Adds the replacement as the last step (double-click, or the + button).</summary>+ [RelayCommand]+ private void Add() => tool.AddStep(new RenameStep { Find = recipe.Find, Replace = recipe.Replace });+}diff --git a/src/Filee.App/Views/Pages/WatchFoldersPage.axaml b/src/Filee.App/Views/Pages/WatchFoldersPage.axamlindex f1c24bd6..be86af8a 100644--- a/src/Filee.App/Views/Pages/WatchFoldersPage.axaml+++ b/src/Filee.App/Views/Pages/WatchFoldersPage.axaml@@ -5,9 +5,6 @@x:Class="Filee.App.Views.Pages.WatchFoldersPage"x:DataType="vm:WatchFoldersPageViewModel"><UserControl.Styles>- <Style Selector="Border.recipe:pointerover">- <Setter Property="Background" Value="{DynamicResource AccentFaintBrush}" />- </Style><Style Selector="PathIcon.chevron"><Setter Property="RenderTransform" Value="rotate(0deg)" /></Style>@@ -101,68 +98,24 @@</StackPanel><StackPanel Spacing="4"><TextBlock Classes="label" Text="{DynamicResource watch.rename}" />- <!-- The steps, applied in order -->- <ItemsControl ItemsSource="{Binding RenameSteps}">- <ItemsControl.ItemsPanel>- <ItemsPanelTemplate>- <StackPanel Spacing="6" />- </ItemsPanelTemplate>- </ItemsControl.ItemsPanel>+ <!-- The steps in short; they are edited in their own window -->+ <ItemsControl ItemsSource="{Binding RenameSummary}" IsVisible="{Binding HasRenames}"><ItemsControl.ItemTemplate>- <DataTemplate x:DataType="vm:RenameStepViewModel">- <StackPanel Spacing="2">- <Grid ColumnDefinitions="*,Auto,*,Auto">- <TextBox Text="{Binding Find}" PlaceholderText="{DynamicResource watch.rename_find}" />- <TextBlock Grid.Column="1" Classes="muted" Text="→" Margin="8,0" VerticalAlignment="Center" />- <TextBox Grid.Column="2" Text="{Binding Replace}" PlaceholderText="{DynamicResource watch.rename_replace}" />- <Button Grid.Column="3" Classes="icon" Margin="6,0,0,0" Command="{Binding RemoveCommand}" ToolTip.Tip="{DynamicResource watch.remove_step}">- <PathIcon Width="12" Height="12" Data="{StaticResource Icon.Close}" />- </Button>- </Grid>- <TextBlock Classes="caption danger" Text="{Binding Error}" TextWrapping="Wrap" IsVisible="{Binding Error, Converter={x:Static ObjectConverters.IsNotNull}}" />- </StackPanel>+ <DataTemplate x:DataType="x:String">+ <TextBlock Classes="caption" FontFamily="Consolas, Menlo, monospace" Text="{Binding}" TextTrimming="CharacterEllipsis" /></DataTemplate></ItemsControl.ItemTemplate></ItemsControl>- <StackPanel Orientation="Horizontal" Spacing="8">- <Button Command="{Binding AddStepCommand}" Padding="10,5">- <StackPanel Orientation="Horizontal" Spacing="6">- <PathIcon Width="12" Height="12" Data="{StaticResource Icon.Plus}" />- <TextBlock Text="{DynamicResource watch.add_step}" />- </StackPanel>- </Button>- <Button Classes="ghost" Command="{Binding ToggleRecipesCommand}" Padding="6,4">- <StackPanel Orientation="Horizontal" Spacing="6">- <PathIcon Classes="chevron" Classes.open="{Binding ShowRecipes}" Width="12" Height="12" Data="{StaticResource Icon.ChevronRight}" />- <TextBlock Text="{DynamicResource watch.recipes}" />- </StackPanel>- </Button>- </StackPanel>-- <!-- Ready-made replacements: what each does to an example; double-click or + adds it as a step -->- <StackPanel Spacing="4" IsVisible="{Binding ShowRecipes}">- <TextBlock Classes="caption" Text="{DynamicResource watch.recipes_hint}" TextWrapping="Wrap" />- <Border BorderBrush="{DynamicResource SubtleBorderBrush}" BorderThickness="1" CornerRadius="8" ClipToBounds="True">- <ItemsControl ItemsSource="{Binding Recipes}">- <ItemsControl.ItemTemplate>- <DataTemplate x:DataType="vm:RenameRecipeViewModel">- <Border Classes="recipe" Padding="10,6" Background="Transparent" DoubleTapped="OnRecipeDoubleTapped">- <Grid ColumnDefinitions="*,*,Auto">- <StackPanel VerticalAlignment="Center">- <TextBlock FontWeight="SemiBold" Text="{Binding Title}" TextWrapping="Wrap" />- <TextBlock Classes="caption" FontFamily="Consolas, Menlo, monospace" Text="{Binding Expression}" TextWrapping="Wrap" />- </StackPanel>- <TextBlock Grid.Column="1" Classes="caption" Text="{Binding Example}" TextWrapping="Wrap" VerticalAlignment="Center" Margin="12,0" />- <Button Grid.Column="2" Classes="icon" Command="{Binding AddCommand}" ToolTip.Tip="{DynamicResource watch.recipe_add}" VerticalAlignment="Center">- <PathIcon Width="12" Height="12" Data="{StaticResource Icon.Plus}" />- </Button>- </Grid>- </Border>- </DataTemplate>- </ItemsControl.ItemTemplate>- </ItemsControl>- </Border>- </StackPanel>+ <TextBlock Classes="caption" Text="{DynamicResource watch.rename_none}" IsVisible="{Binding !HasRenames}" TextWrapping="Wrap" />+ <Button HorizontalAlignment="Left" Padding="10,5" Click="OnEditRenames">+ <StackPanel Orientation="Horizontal" Spacing="6">+ <PathIcon Width="12" Height="12" Data="{StaticResource Icon.Pencil}" />+ <Panel>+ <TextBlock Text="{DynamicResource watch.rename_edit}" IsVisible="{Binding HasRenames}" />+ <TextBlock Text="{DynamicResource watch.rename_add}" IsVisible="{Binding !HasRenames}" />+ </Panel>+ </StackPanel>+ </Button></StackPanel></StackPanel>diff --git a/src/Filee.App/Views/Pages/WatchFoldersPage.axaml.cs b/src/Filee.App/Views/Pages/WatchFoldersPage.axaml.csindex a67a06f5..4f65ee06 100644--- a/src/Filee.App/Views/Pages/WatchFoldersPage.axaml.cs+++ b/src/Filee.App/Views/Pages/WatchFoldersPage.axaml.cs@@ -1,5 +1,4 @@using Avalonia.Controls;-using Avalonia.Input;using Avalonia.Interactivity;using Avalonia.Platform.Storage;using Filee.App.ViewModels.Pages;@@ -22,11 +21,15 @@ public partial class WatchFoldersPage : UserControlrule.OutputFolder = path;}- /// <summary>Double-clicking a ready-made replacement adds it as a step, like its + button.</summary>- private void OnRecipeDoubleTapped(object? sender, TappedEventArgs e)+ /// <summary>Opens the rename steps in their own window; they change only when it is saved.</summary>+ private async void OnEditRenames(object? sender, RoutedEventArgs e){- if ((sender as Control)?.DataContext is RenameRecipeViewModel recipe)- recipe.AddCommand.Execute(null);+ if ((sender as Control)?.DataContext is not WatchRuleViewModel rule || TopLevel.GetTopLevel(this) is not Window owner)+ return;+ var tool = rule.CreateRenameTool();+ var dialog = new RenameToolWindow { DataContext = tool };+ if (await dialog.ShowDialog<bool>(owner))+ rule.SetRenames(tool.Result);}private async Task<string?> PickFolderAsync()diff --git a/src/Filee.App/Views/RenameToolWindow.axaml b/src/Filee.App/Views/RenameToolWindow.axamlnew file mode 100644index 00000000..9fb22991--- /dev/null+++ b/src/Filee.App/Views/RenameToolWindow.axaml@@ -0,0 +1,137 @@+<!-- Renaming converted files of a watch folder: steps on the right with the preview, ready-made replacements on+ the left (double-click or + adds one). Opened from Watch folders → More options. -->+<Window xmlns="https://github.com/avaloniaui"+ xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"+ xmlns:vm="using:Filee.App.ViewModels"+ x:Class="Filee.App.Views.RenameToolWindow"+ x:DataType="vm:RenameToolViewModel"+ Title="{DynamicResource watch.rename_title}"+ Icon="avares://Filee/Assets/Icons/filee.ico"+ Width="880" Height="640" MinWidth="640" MinHeight="420"+ WindowStartupLocation="CenterOwner"+ ShowInTaskbar="False">+ <Window.Styles>+ <Style Selector="Border.recipe">+ <Setter Property="Background" Value="Transparent" />+ <Setter Property="Cursor" Value="Hand" />+ </Style>+ <Style Selector="Border.recipe:pointerover">+ <Setter Property="Background" Value="{DynamicResource AccentFaintBrush}" />+ </Style>+ <Style Selector="TextBlock.code">+ <Setter Property="FontFamily" Value="Consolas, Menlo, monospace" />+ </Style>+ </Window.Styles>+ <DockPanel>+ <Border DockPanel.Dock="Bottom" Padding="20,12" BorderThickness="0,1,0,0" BorderBrush="{DynamicResource SubtleBorderBrush}"+ Background="{DynamicResource SurfaceBrush}">+ <StackPanel Orientation="Horizontal" HorizontalAlignment="Right" Spacing="8">+ <Button Content="{DynamicResource common.cancel}" Click="OnCancel" IsCancel="True" />+ <Button Classes="accent" Content="{DynamicResource common.save}" Click="OnSave" IsDefault="True" IsEnabled="{Binding IsValid}" />+ </StackPanel>+ </Border>++ <StackPanel DockPanel.Dock="Top" Margin="20,16,20,4" Spacing="4">+ <TextBlock Classes="h2" Text="{DynamicResource watch.rename_title}" />+ <TextBlock Classes="caption" Text="{DynamicResource watch.rename_intro}" TextWrapping="Wrap" />+ </StackPanel>++ <Grid ColumnDefinitions="340,*" Margin="20,8,20,16">+ <!-- Ready-made replacements -->+ <DockPanel Margin="0,0,16,0">+ <StackPanel DockPanel.Dock="Top" Spacing="2" Margin="0,0,0,6">+ <TextBlock Classes="label" Text="{DynamicResource watch.recipes}" />+ <TextBlock Classes="caption" Text="{DynamicResource watch.recipes_hint}" TextWrapping="Wrap" />+ </StackPanel>+ <Border BorderBrush="{DynamicResource SubtleBorderBrush}" BorderThickness="1" CornerRadius="8" ClipToBounds="True">+ <ScrollViewer>+ <ItemsControl ItemsSource="{Binding Recipes}">+ <ItemsControl.ItemTemplate>+ <DataTemplate x:DataType="vm:RenameRecipeViewModel">+ <Border Classes="recipe" Padding="10,7" DoubleTapped="OnRecipeDoubleTapped">+ <DockPanel>+ <Button DockPanel.Dock="Right" Classes="icon" Command="{Binding AddCommand}" ToolTip.Tip="{DynamicResource watch.recipe_add}"+ VerticalAlignment="Center" Margin="6,0,0,0">+ <PathIcon Width="12" Height="12" Data="{StaticResource Icon.Plus}" />+ </Button>+ <StackPanel Spacing="1">+ <TextBlock FontWeight="SemiBold" Text="{Binding Title}" TextWrapping="Wrap" />+ <TextBlock Classes="caption" Text="{Binding Example}" TextWrapping="Wrap" />+ <TextBlock Classes="caption code" Text="{Binding Expression}" TextWrapping="Wrap" Opacity="0.75" />+ </StackPanel>+ </DockPanel>+ </Border>+ </DataTemplate>+ </ItemsControl.ItemTemplate>+ </ItemsControl>+ </ScrollViewer>+ </Border>+ </DockPanel>++ <!-- The steps and what they do -->+ <ScrollViewer Grid.Column="1">+ <StackPanel Spacing="16" Margin="0,0,4,0">+ <StackPanel Spacing="6">+ <TextBlock Classes="label" Text="{DynamicResource watch.rename_steps}" />+ <TextBlock Classes="caption" Text="{DynamicResource watch.rename_no_steps}" TextWrapping="Wrap" IsVisible="{Binding HasNoSteps}" />+ <ItemsControl ItemsSource="{Binding Steps}">+ <ItemsControl.ItemsPanel>+ <ItemsPanelTemplate>+ <StackPanel Spacing="6" />+ </ItemsPanelTemplate>+ </ItemsControl.ItemsPanel>+ <ItemsControl.ItemTemplate>+ <DataTemplate x:DataType="vm:RenameStepViewModel">+ <StackPanel Spacing="2">+ <Grid ColumnDefinitions="*,Auto,*,Auto,Auto">+ <TextBox Text="{Binding Find}" PlaceholderText="{DynamicResource watch.rename_find}" FontFamily="Consolas, Menlo, monospace" />+ <TextBlock Grid.Column="1" Classes="muted" Text="→" Margin="8,0" VerticalAlignment="Center" />+ <TextBox Grid.Column="2" Text="{Binding Replace}" PlaceholderText="{DynamicResource watch.rename_replace}" FontFamily="Consolas, Menlo, monospace" />+ <Button Grid.Column="3" Classes="icon" Margin="6,0,0,0" Command="{Binding MoveUpCommand}" ToolTip.Tip="{DynamicResource watch.step_up}">+ <PathIcon Width="12" Height="12" Data="{StaticResource Icon.ChevronRight}" RenderTransform="rotate(-90deg)" />+ </Button>+ <Button Grid.Column="4" Classes="icon" Margin="2,0,0,0" Command="{Binding RemoveCommand}" ToolTip.Tip="{DynamicResource watch.remove_step}">+ <PathIcon Width="12" Height="12" Data="{StaticResource Icon.Close}" />+ </Button>+ </Grid>+ <TextBlock Classes="caption danger" Text="{Binding Error}" TextWrapping="Wrap" IsVisible="{Binding Error, Converter={x:Static ObjectConverters.IsNotNull}}" />+ </StackPanel>+ </DataTemplate>+ </ItemsControl.ItemTemplate>+ </ItemsControl>+ <Button HorizontalAlignment="Left" Command="{Binding AddStepCommand}" Padding="10,5">+ <StackPanel Orientation="Horizontal" Spacing="6">+ <PathIcon Width="12" Height="12" Data="{StaticResource Icon.Plus}" />+ <TextBlock Text="{DynamicResource watch.add_step}" />+ </StackPanel>+ </Button>+ </StackPanel>++ <!-- Before → after, for files in the folder and for a name typed here -->+ <Border Background="{DynamicResource SurfaceAltBrush}" CornerRadius="8" Padding="12,10">+ <StackPanel Spacing="6">+ <TextBlock Classes="label" Text="{DynamicResource watch.preview}" />+ <ItemsControl ItemsSource="{Binding Previews}" IsVisible="{Binding HasSamples}">+ <ItemsControl.ItemTemplate>+ <DataTemplate x:DataType="vm:RenamePreview">+ <Grid ColumnDefinitions="*,Auto,*" Margin="0,2">+ <TextBlock Classes="caption" Text="{Binding Before}" TextTrimming="CharacterEllipsis" VerticalAlignment="Center" />+ <TextBlock Grid.Column="1" Classes="muted" Text="→" Margin="8,0" />+ <TextBlock Grid.Column="2" FontWeight="SemiBold" Text="{Binding After}" TextTrimming="CharacterEllipsis" VerticalAlignment="Center" />+ </Grid>+ </DataTemplate>+ </ItemsControl.ItemTemplate>+ </ItemsControl>+ <TextBlock Classes="caption" Text="{DynamicResource watch.rename_try}" Margin="0,4,0,0" />+ <Grid ColumnDefinitions="*,Auto,*">+ <TextBox Text="{Binding CustomName}" PlaceholderText="{DynamicResource watch.rename_try_placeholder}" />+ <TextBlock Grid.Column="1" Classes="muted" Text="→" Margin="8,0" VerticalAlignment="Center" />+ <SelectableTextBlock Grid.Column="2" FontWeight="SemiBold" Text="{Binding CustomResult}" VerticalAlignment="Center" TextWrapping="Wrap" />+ </Grid>+ </StackPanel>+ </Border>+ </StackPanel>+ </ScrollViewer>+ </Grid>+ </DockPanel>+</Window>diff --git a/src/Filee.App/Views/RenameToolWindow.axaml.cs b/src/Filee.App/Views/RenameToolWindow.axaml.csnew file mode 100644index 00000000..75fa5a9d--- /dev/null+++ b/src/Filee.App/Views/RenameToolWindow.axaml.cs@@ -0,0 +1,32 @@+using Avalonia.Controls;+using Avalonia.Input;+using Avalonia.Interactivity;+using Filee.App.Services;+using Filee.App.ViewModels;++namespace Filee.App.Views;++/// <summary>Modal editor of a watch folder's rename steps. Returns true from ShowDialog when the user saved.</summary>+public partial class RenameToolWindow : Window+{+ public RenameToolWindow()+ {+ InitializeComponent();+ Motion.Track(this);+ }++ /// <summary>Double-clicking a ready-made replacement adds it as a step, like its + button.</summary>+ private void OnRecipeDoubleTapped(object? sender, TappedEventArgs e)+ {+ if ((sender as Control)?.DataContext is RenameRecipeViewModel recipe)+ recipe.AddCommand.Execute(null);+ }++ private void OnSave(object? sender, RoutedEventArgs e)+ {+ if (DataContext is RenameToolViewModel { IsValid: true })+ Close(true);+ }++ private void OnCancel(object? sender, RoutedEventArgs e) => Close(false);+}diff --git a/tests/Filee.App.Tests/RenderTests.cs b/tests/Filee.App.Tests/RenderTests.csindex 68392eea..b69be987 100644--- a/tests/Filee.App.Tests/RenderTests.cs+++ b/tests/Filee.App.Tests/RenderTests.cs@@ -116,18 +116,29 @@ public class RenderTestsitem.IncludeText = "";Assert.NotNull(item.IncludeMatches); // IMG_0412.jpg matches, notes.txt doesn't- // A ready-made replacement becomes a step; steps run in order.- item.Recipes[0].AddCommand.Execute(null); // camera number → Photo_number- Assert.Equal(@"^(?:IMG|DSC|PXL)_(\d+)", Assert.Single(rule.Renames).Find);- // A file already in the folder that the patterns let through, renamed by the name rule and the step.- Assert.Equal($"IMG_0412.jpg → {Path.Combine("converted", "Photo_0412_scan.pdf")}", item.PreviewExample);-- var step = item.RenameSteps[0];+ // The rename window works on copies: a ready-made replacement becomes a rule, the preview follows.+ var tool = item.CreateRenameTool();+ tool.Recipes[0].AddCommand.Execute(null); // camera number → Photo_number+ Assert.Empty(rule.Renames); // nothing changes before saving+ Assert.Equal(new Filee.App.ViewModels.RenamePreview("IMG_0412.jpg", "Photo_0412_scan.pdf"), Assert.Single(tool.Previews));+ tool.CustomName = "DSC_0815.heic";+ Assert.Equal("Photo_0815_scan.pdf", tool.CustomResult);+ var step = tool.Steps[0];step.Find = "IMG_(";Assert.NotNull(step.Error);+ Assert.False(tool.IsValid);step.Find = @"^(?:IMG|DSC|PXL)_(\d+)";- Assert.Null(step.Error);- item.ShowRecipes = true;+ Assert.True(tool.IsValid);+ var dialog = new Filee.App.Views.RenameToolWindow { DataContext = tool };+ dialog.Show();+ Pump();+ Save(dialog, $"window-rename-{language}.png");+ dialog.Close();++ item.SetRenames(tool.Result); // saved+ Assert.Equal(@"^(?:IMG|DSC|PXL)_(\d+)", Assert.Single(rule.Renames).Find);+ // A file already in the folder that the patterns let through, renamed by the name rule and the rule.+ Assert.Equal($"IMG_0412.jpg → {Path.Combine("converted", "Photo_0412_scan.pdf")}", item.PreviewExample);Pump();Save(window, $"page-watch-options-{language}.png");window.Close();