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.

Watch folders: one place for the name of converted files, plainer filter help

KnifeLemon234b2719e532
diff --git a/CHANGELOG.md b/CHANGELOG.md
index 3a163612..7e03cbcf 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -19,18 +19,16 @@ find it, what it does and doesn't do.
- **Watch folders: choose files and name them** (Settings → Watch folders → *More options*, all optional; empty
fields change nothing):
- *Files to convert*: patterns entered as tags. Typing `heic` adds `*.heic`, other text picks names that contain
- it, `*` stands for any text and `?` for one character, and a regular expression goes between slashes
- (`/^IMG_\d+/`). Extensions are suggested while typing, a broken expression is not added, and the card says how
- 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}`.
- - *Rename converted files*: **Edit rules** opens a window of rules applied from top to bottom. Each rule says
- what it does — replace text, remove text, add at the start or end, spaces to `_`, remove a copy number like
- "(2)", remove text in brackets, remove a leading number, remove symbols, all lowercase or uppercase — and asks
- only for the text it needs. A regular expression is there as the last, advanced kind. **Common replacements** on
- the left lists ready-made rules with an example of what each 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.
+ it, and `*` stands for any text, `?` for one character. Extensions are suggested while typing, and the card says
+ how many files in the folder match. Other files in the folder are left alone.
+ - *Names of converted files*: **Edit name rules** opens a window with the base name (typed, or built with buttons
+ for the original name, date, time, number and preset name; empty keeps the preset's) and changes applied to it
+ from top to bottom. Each change says what it does — replace text, remove text, add at the start or end, spaces
+ to `_`, remove a copy number like "(2)", text in brackets, a leading number or symbols, all lowercase or
+ uppercase — and asks only for the text it needs; a regular expression is there as the last, advanced kind.
+ **Common replacements** on the left lists ready-made changes with an example of each; double-click one or press +
+ to add it. The preview shows the name each file in the folder will get, and any name you type. Nothing changes
+ until you save. The card shows the name in words ("[Original name]_scan") and the changes.
- 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 is
taken and what happens to the original.
diff --git a/src/Filee.App/Assets/i18n/en.json b/src/Filee.App/Assets/i18n/en.json
index 6190baff..ece2e5f8 100644
--- a/src/Filee.App/Assets/i18n/en.json
+++ b/src/Filee.App/Assets/i18n/en.json
@@ -477,13 +477,21 @@
"watch.options": "More options (optional)",
"watch.include": "Files to convert",
"watch.include_placeholder": "Type an extension or a name, then Enter (e.g. heic, scan_*)",
- "watch.include_hint": "Empty converts every file. An extension such as heic becomes *.heic; other text picks names that contain it. * stands for any text and ? for one character; put a regular expression between slashes, e.g. /^IMG_\\d+/.",
- "watch.name": "File name rule",
+ "watch.include_hint": "Leave empty to convert every file.\n· heic → files ending in .heic\n· scan → files with \"scan\" in the name\n· * stands for any text, ? for one character (e.g. scan_*.jpg)",
+ "watch.name": "Base name",
"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": "Rename converted files",
+ "watch.name_hint": "The buttons add parts of the name. Leave it empty to use the preset's name.",
+ "watch.rename": "Names of converted files",
"watch.rename_find": "Find, e.g. IMG_(\\d+)",
"watch.rename_replace": "Replace with, e.g. Photo_$1",
+ "watch.name_summary": "Name: {0}",
+ "watch.name_summary_preset": "Name: {0} (same as the preset)",
+ "watch.token.name": "Original name",
+ "watch.token.ext": "Original extension",
+ "watch.token.date": "Date",
+ "watch.token.time": "Time",
+ "watch.token.index": "Number",
+ "watch.token.preset": "Preset name",
"watch.kind.Replace": "Replace text",
"watch.kind.Remove": "Remove text",
"watch.kind.Prefix": "Add at the start",
@@ -504,13 +512,11 @@
"watch.advanced": "Advanced",
"watch.recipe.camera_to_photo": "Change IMG_ to Photo_",
"watch.recipe.lowercase": "All lowercase",
- "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": "Pick what each rule does and fill in the text. Rules run from top to bottom, and 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.rename_edit": "Edit name rules",
+ "watch.rename_title": "Name converted files",
+ "watch.rename_intro": "Set the base name, then change parts of it with rules if you need to. The preview shows the name each file in the folder will get.",
+ "watch.rename_steps": "Changes (applied from top to bottom)",
+ "watch.rename_no_steps": "No changes. Pick one on the left or add one if you need it.",
"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",
diff --git a/src/Filee.App/Assets/i18n/ko.json b/src/Filee.App/Assets/i18n/ko.json
index 05c62b1b..f49021d8 100644
--- a/src/Filee.App/Assets/i18n/ko.json
+++ b/src/Filee.App/Assets/i18n/ko.json
@@ -477,13 +477,21 @@
"watch.options": "추가 옵션 (선택)",
"watch.include": "변환할 파일",
"watch.include_placeholder": "확장자나 이름을 입력하고 Enter (예: heic, scan_*)",
- "watch.include_hint": "비워 두면 모든 파일을 변환해요. heic처럼 확장자만 쓰면 *.heic가 되고, 다른 글자는 이름에 그 글자가 들어간 파일을 골라요. * 는 아무 글자, ? 는 한 글자이고, 정규식은 /^IMG_\\d+/ 처럼 슬래시로 감싸요.",
- "watch.name": "파일명 규칙",
+ "watch.include_hint": "비워 두면 모든 파일을 변환해요.\n· heic → 확장자가 heic인 파일\n· scan → 이름에 scan이 들어간 파일\n· * 는 아무 글자, ? 는 한 글자 (예: scan_*.jpg)",
+ "watch.name": "기본 이름",
"watch.name_placeholder": "프리셋과 같게: {0}",
- "watch.name_hint": "{name} 원래 이름 · {date} 날짜 · {time} 시간 · {index} 순번 · {preset} 프리셋 이름",
- "watch.rename": "변환된 파일 이름 바꾸기",
+ "watch.name_hint": "버튼을 누르면 해당 부분이 들어가요. 비워 두면 프리셋과 같은 이름을 써요.",
+ "watch.rename": "변환된 파일 이름",
"watch.rename_find": "찾을 패턴 (예: IMG_(\\d+))",
"watch.rename_replace": "바꿀 내용 (예: 사진_$1)",
+ "watch.name_summary": "이름: {0}",
+ "watch.name_summary_preset": "이름: {0} (프리셋과 같게)",
+ "watch.token.name": "원래 이름",
+ "watch.token.ext": "원래 확장자",
+ "watch.token.date": "날짜",
+ "watch.token.time": "시간",
+ "watch.token.index": "순번",
+ "watch.token.preset": "프리셋 이름",
"watch.kind.Replace": "글자 바꾸기",
"watch.kind.Remove": "글자 지우기",
"watch.kind.Prefix": "앞에 붙이기",
@@ -504,13 +512,11 @@
"watch.advanced": "고급",
"watch.recipe.camera_to_photo": "IMG_를 Photo_로 바꾸기",
"watch.recipe.lowercase": "모두 소문자로",
- "watch.rename_none": "파일명 규칙으로 만든 이름을 그대로 써요.",
- "watch.rename_edit": "규칙 편집",
- "watch.rename_add": "규칙 추가",
- "watch.rename_title": "변환된 파일 이름 바꾸기",
- "watch.rename_intro": "규칙마다 할 일을 고르고 필요한 글자만 넣으세요. 위에서부터 차례로 적용되고, 미리보기에서 폴더의 파일이 어떻게 바뀌는지 바로 확인할 수 있어요.",
- "watch.rename_steps": "규칙 (위에서부터 차례로 적용)",
- "watch.rename_no_steps": "아직 규칙이 없어요. 왼쪽에서 고르거나 빈 규칙을 추가하세요.",
+ "watch.rename_edit": "이름 규칙 편집",
+ "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)",
diff --git a/src/Filee.App/Assets/i18n/zh-CN.json b/src/Filee.App/Assets/i18n/zh-CN.json
index 971be2e8..07628995 100644
--- a/src/Filee.App/Assets/i18n/zh-CN.json
+++ b/src/Filee.App/Assets/i18n/zh-CN.json
@@ -477,13 +477,21 @@
"watch.options": "更多选项(可选)",
"watch.include": "要转换的文件",
"watch.include_placeholder": "输入扩展名或名称后按 Enter(例如 heic、scan_*)",
- "watch.include_hint": "留空则转换所有文件。只写 heic 这样的扩展名会变成 *.heic,其他文字会选出名称中包含它的文件。* 代表任意文字,? 代表一个字符,正则表达式用斜杠包住,例如 /^IMG_\\d+/。",
- "watch.name": "文件名规则",
+ "watch.include_hint": "留空则转换所有文件。\n· heic → 扩展名为 heic 的文件\n· scan → 名称中含有 scan 的文件\n· * 代表任意文字,? 代表一个字符(例如 scan_*.jpg)",
+ "watch.name": "基本名称",
"watch.name_placeholder": "与预设相同:{0}",
- "watch.name_hint": "{name} 原文件名 · {date} 日期 · {time} 时间 · {index} 序号 · {preset} 预设名称",
- "watch.rename": "重命名转换后的文件",
+ "watch.name_hint": "点按钮即可加入对应部分。留空则使用预设的名称。",
+ "watch.rename": "转换后的文件名",
"watch.rename_find": "查找,例如 IMG_(\\d+)",
"watch.rename_replace": "替换为,例如 照片_$1",
+ "watch.name_summary": "名称:{0}",
+ "watch.name_summary_preset": "名称:{0}(与预设相同)",
+ "watch.token.name": "原文件名",
+ "watch.token.ext": "原扩展名",
+ "watch.token.date": "日期",
+ "watch.token.time": "时间",
+ "watch.token.index": "序号",
+ "watch.token.preset": "预设名称",
"watch.kind.Replace": "替换文字",
"watch.kind.Remove": "删除文字",
"watch.kind.Prefix": "在开头添加",
@@ -504,13 +512,11 @@
"watch.advanced": "高级",
"watch.recipe.camera_to_photo": "把 IMG_ 改为 Photo_",
"watch.recipe.lowercase": "全部小写",
- "watch.rename_none": "名称保持文件名规则生成的样子。",
- "watch.rename_edit": "编辑规则",
- "watch.rename_add": "添加规则",
- "watch.rename_title": "重命名转换后的文件",
- "watch.rename_intro": "为每条规则选择要做的事,只需填写所需的文字。规则从上到下依次执行,预览会显示文件夹中的文件如何变化。",
- "watch.rename_steps": "规则(按顺序执行)",
- "watch.rename_no_steps": "还没有规则。从左侧选择,或添加一条空规则。",
+ "watch.rename_edit": "编辑命名规则",
+ "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",
diff --git a/src/Filee.App/ViewModels/Pages/RenameRecipes.cs b/src/Filee.App/ViewModels/Pages/RenameRecipes.cs
index f8f8b434..4c38f658 100644
--- a/src/Filee.App/ViewModels/Pages/RenameRecipes.cs
+++ b/src/Filee.App/ViewModels/Pages/RenameRecipes.cs
@@ -28,6 +28,14 @@ public static class RenameRecipes
new("watch.recipe.date_dashes", new RenameStep { Kind = RenameKind.Regex, Find = @"(\d{4})(\d{2})(\d{2})", Replace = "$1-$2-$3" }, "scan_20261011"),
];
+ /// <summary>A name pattern with its parts in words: <c>{name}_{date}</c> → "[Original name]_[Date]".</summary>
+ public static string Friendly(ILocalizer loc, string pattern)
+ {
+ foreach (var token in new[] { "name", "ext", "date", "time", "index", "preset" })
+ pattern = pattern.Replace("{" + token + "}", $"[{loc[$"watch.token.{token}"]}]", StringComparison.Ordinal);
+ return pattern;
+ }
+
/// <summary>A rule in one line for the watch folder card: "Replace text: IMG_ → Photo_", "Spaces to _".</summary>
public static string Describe(ILocalizer loc, RenameStep step)
{
diff --git a/src/Filee.App/ViewModels/Pages/WatchFoldersPageViewModel.cs b/src/Filee.App/ViewModels/Pages/WatchFoldersPageViewModel.cs
index b3e70b9f..0cf71957 100644
--- a/src/Filee.App/ViewModels/Pages/WatchFoldersPageViewModel.cs
+++ b/src/Filee.App/ViewModels/Pages/WatchFoldersPageViewModel.cs
@@ -103,12 +103,13 @@ public sealed partial class WatchFoldersPageViewModel : ObservableObject, IDispo
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)
+ /// <summary>The file name a source gets in this folder with a base name pattern and rules in place of the rule's.</summary>
+ internal string OutputNameOf(WatchRule rule, string source, string pattern, IReadOnlyList<RenameStep> steps)
{
if (_store.FindPreset(rule.PresetId) is not { } preset)
return source;
var trial = rule.Clone();
+ trial.FileNamePattern = pattern;
trial.Renames = [.. steps];
var applied = trial.Apply(preset);
var output = OutputPathResolver.Resolve(applied.Output,
@@ -211,7 +212,6 @@ public sealed partial class WatchRuleViewModel : ObservableObject
_outputFolder = rule.OutputFolder;
_originals = page.OriginalsChoices.First(c => c.Value == rule.Originals);
_status = page.StatusOf(rule);
- _fileNamePattern = rule.FileNamePattern;
// 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();
@@ -245,12 +245,10 @@ public sealed partial class WatchRuleViewModel : ObservableObject
/// <summary>"3 files in the folder match now", or null.</summary>
[ObservableProperty] private string? _includeMatches;
- [ObservableProperty] private string _fileNamePattern;
+ /// <summary>"Name: [Original name]_scan", or the preset's name when the folder has none.</summary>
+ [ObservableProperty] private string _nameSummary = "";
- /// <summary>"Same as the preset: {name}" in the empty file name box.</summary>
- [ObservableProperty] private string _fileNamePlaceholder = "";
-
- /// <summary>The rename steps, one "find → replace" line each, for the card.</summary>
+ /// <summary>The rules, one line each, for the card.</summary>
[ObservableProperty] private IReadOnlyList<string> _renameSummary = [];
public bool HasRenames => RenameSummary.Count > 0;
@@ -269,7 +267,6 @@ public sealed partial class WatchRuleViewModel : ObservableObject
partial void OnIncludeSubfoldersChanged(bool value) => Change(r => r.IncludeSubfolders = value);
partial void OnOutputFolderChanged(string value) => Change(r => r.OutputFolder = value.Trim());
partial void OnOriginalsChanged(Choice<AfterConversion> value) => Change(r => r.Originals = value.Value);
- partial void OnFileNamePatternChanged(string value) => Change(r => r.FileNamePattern = value.Trim());
partial void OnIncludeTextChanged(string value)
{
@@ -307,10 +304,15 @@ public sealed partial class WatchRuleViewModel : ObservableObject
/// <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);
+ new(Rule.FileNamePattern, _page.PresetNamePattern(Rule), Rule.Renames, WatchFoldersPageViewModel.SampleNames(Rule),
+ (pattern, steps, source) => _page.OutputNameOf(Rule, source, pattern, steps), _page.Localizer);
- /// <summary>Takes the steps the dialog applied.</summary>
- public void SetRenames(List<RenameStep> steps) => Change(r => r.Renames = steps);
+ /// <summary>Takes the base name and the rules the dialog saved.</summary>
+ public void SetNaming(string pattern, List<RenameStep> steps) => Change(r =>
+ {
+ r.FileNamePattern = pattern.Trim();
+ r.Renames = steps;
+ });
[RelayCommand]
private void Remove() => _page.Remove(this);
@@ -334,9 +336,12 @@ public sealed partial class WatchRuleViewModel : ObservableObject
private void RefreshPreview()
{
- RenameSummary = Rule.Renames.Select(r => RenameRecipes.Describe(_page.Localizer, r)).ToList();
+ var loc = _page.Localizer;
+ NameSummary = Rule.FileNamePattern.Length > 0
+ ? loc.Format("watch.name_summary", RenameRecipes.Friendly(loc, Rule.FileNamePattern))
+ : loc.Format("watch.name_summary_preset", RenameRecipes.Friendly(loc, _page.PresetNamePattern(Rule)));
+ RenameSummary = Rule.Renames.Select(r => RenameRecipes.Describe(loc, r)).ToList();
OnPropertyChanged(nameof(HasRenames));
- FileNamePlaceholder = _page.Format("watch.name_placeholder", _page.PresetNamePattern(Rule));
var preview = _page.PreviewOf(Rule);
PreviewExample = preview?.Example;
PreviewDetails = preview?.Details;
diff --git a/src/Filee.App/ViewModels/RenameToolViewModel.cs b/src/Filee.App/ViewModels/RenameToolViewModel.cs
index 9952c61f..c26b5d32 100644
--- a/src/Filee.App/ViewModels/RenameToolViewModel.cs
+++ b/src/Filee.App/ViewModels/RenameToolViewModel.cs
@@ -1,6 +1,6 @@
-// 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.
+// Naming the converted files of a watch folder (Watch folders → More options → Edit name rules): the base name (a
+// pattern, built with token buttons), rules applied to it in order, ready-made rules to add with a double-click, and
+// a preview of files from the folder. Works on copies; the folder takes them only when the dialog is saved.
using System.Collections.ObjectModel;
using CommunityToolkit.Mvvm.ComponentModel;
@@ -11,24 +11,32 @@ using Filee.Core.Presets;
namespace Filee.App.ViewModels;
+/// <summary>A part of the base name a button inserts: <c>date</c> → <c>{date}</c>, labelled "Date".</summary>
+public sealed record NamePart(string Token, string Label);
+
/// <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 Func<string, 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="pattern">The folder's base name pattern; empty for the preset's.</param>
+ /// <param name="presetPattern">The preset's pattern, used while <paramref name="pattern"/> is empty.</param>
+ /// <param name="steps">The folder's rules (copied; changes stay here until the dialog is saved).</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)
+ /// <param name="rename">The name a file gets: (pattern, rules, source name) → converted file name.</param>
+ public RenameToolViewModel(string pattern, string presetPattern, IEnumerable<RenameStep> steps, IReadOnlyList<string> samples,
+ Func<string, IReadOnlyList<RenameStep>, string, string> rename, ILocalizer loc)
{
_loc = loc;
_rename = rename;
_samples = samples;
+ _namePattern = pattern;
+ NamePlaceholder = loc.Format("watch.name_placeholder", RenameRecipes.Friendly(loc, presetPattern));
+ Tokens = new[] { "name", "date", "time", "index", "preset" }.Select(t => new NamePart(t, loc[$"watch.token.{t}"])).ToList();
Kinds = Enum.GetValues<RenameKind>().Select(k => new Choice<RenameKind>(k, loc[$"watch.kind.{k}"])).ToList();
Recipes = RenameRecipes.All.Select(r => new RenameRecipeViewModel(r, loc[r.TitleKey], this)).ToList();
foreach (var step in steps)
@@ -37,7 +45,16 @@ public sealed partial class RenameToolViewModel : ObservableObject
Refresh();
}
- /// <summary>Replacements applied in order.</summary>
+ /// <summary>The base name: <c>{name}_scan</c>; empty for the preset's.</summary>
+ [ObservableProperty] private string _namePattern;
+
+ /// <summary>"Same as the preset: [Original name]" in the empty box.</summary>
+ public string NamePlaceholder { get; }
+
+ /// <summary>The parts the token buttons insert: name, date, time, index, preset.</summary>
+ public IReadOnlyList<NamePart> Tokens { get; }
+
+ /// <summary>Rules applied in order to the base name.</summary>
public ObservableCollection<RenameStepViewModel> Steps { get; } = [];
/// <summary>What a rule can do, for its drop-down.</summary>
@@ -67,6 +84,12 @@ public sealed partial class RenameToolViewModel : ObservableObject
partial void OnCustomNameChanged(string value) => Refresh();
+ partial void OnNamePatternChanged(string value) => Refresh();
+
+ /// <summary>Adds a part ({name}, {date}, …) at the end of the base name; an empty one starts from the original name.</summary>
+ public void InsertToken(string token) =>
+ NamePattern = (NamePattern.Trim().Length == 0 && token != "name" ? "{name}_" : NamePattern) + "{" + token + "}";
+
[RelayCommand]
private void AddStep() => AddStep(new RenameStep());
@@ -104,8 +127,8 @@ public sealed partial class RenameToolViewModel : ObservableObject
var steps = Steps.Select(s => s.Step).Where(s => !s.IsBlank).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());
+ Previews.Add(new RenamePreview(sample, _rename(NamePattern.Trim(), steps, sample)));
+ CustomResult = CustomName.Trim().Length == 0 ? "" : _rename(NamePattern.Trim(), steps, CustomName.Trim());
OnPropertyChanged(nameof(HasNoSteps));
OnPropertyChanged(nameof(IsValid));
}
diff --git a/src/Filee.App/Views/Pages/WatchFoldersPage.axaml b/src/Filee.App/Views/Pages/WatchFoldersPage.axaml
index be86af8a..aa0c31fd 100644
--- a/src/Filee.App/Views/Pages/WatchFoldersPage.axaml
+++ b/src/Filee.App/Views/Pages/WatchFoldersPage.axaml
@@ -91,29 +91,21 @@
<TextBlock Classes="caption" Text="{Binding IncludeMatches}" TextWrapping="Wrap" IsVisible="{Binding IncludeMatches, Converter={x:Static ObjectConverters.IsNotNull}}" />
<TextBlock Classes="caption" Text="{DynamicResource watch.include_hint}" TextWrapping="Wrap" />
</StackPanel>
- <StackPanel Spacing="4">
- <TextBlock Classes="label" Text="{DynamicResource watch.name}" />
- <TextBox Text="{Binding FileNamePattern}" PlaceholderText="{Binding FileNamePlaceholder}" />
- <TextBlock Classes="caption" Text="{DynamicResource watch.name_hint}" TextWrapping="Wrap" />
- </StackPanel>
+ <!-- The base name and the rules in short; both are edited in their own window -->
<StackPanel Spacing="4">
<TextBlock Classes="label" Text="{DynamicResource watch.rename}" />
- <!-- The steps in short; they are edited in their own window -->
+ <TextBlock Classes="caption" Text="{Binding NameSummary}" TextWrapping="Wrap" />
<ItemsControl ItemsSource="{Binding RenameSummary}" IsVisible="{Binding HasRenames}">
<ItemsControl.ItemTemplate>
<DataTemplate x:DataType="x:String">
- <TextBlock Classes="caption" FontFamily="Consolas, Menlo, monospace" Text="{Binding}" TextTrimming="CharacterEllipsis" />
+ <TextBlock Classes="caption" Text="{Binding StringFormat='· {0}'}" TextTrimming="CharacterEllipsis" />
</DataTemplate>
</ItemsControl.ItemTemplate>
</ItemsControl>
- <TextBlock Classes="caption" Text="{DynamicResource watch.rename_none}" IsVisible="{Binding !HasRenames}" TextWrapping="Wrap" />
- <Button HorizontalAlignment="Left" Padding="10,5" Click="OnEditRenames">
+ <Button HorizontalAlignment="Left" Padding="10,5" Margin="0,2,0,0" 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>
+ <TextBlock Text="{DynamicResource watch.rename_edit}" />
</StackPanel>
</Button>
</StackPanel>
diff --git a/src/Filee.App/Views/Pages/WatchFoldersPage.axaml.cs b/src/Filee.App/Views/Pages/WatchFoldersPage.axaml.cs
index 4f65ee06..895e7cfe 100644
--- a/src/Filee.App/Views/Pages/WatchFoldersPage.axaml.cs
+++ b/src/Filee.App/Views/Pages/WatchFoldersPage.axaml.cs
@@ -29,7 +29,7 @@ public partial class WatchFoldersPage : UserControl
var tool = rule.CreateRenameTool();
var dialog = new RenameToolWindow { DataContext = tool };
if (await dialog.ShowDialog<bool>(owner))
- rule.SetRenames(tool.Result);
+ rule.SetNaming(tool.NamePattern, tool.Result);
}
private async Task<string?> PickFolderAsync()
diff --git a/src/Filee.App/Views/RenameToolWindow.axaml b/src/Filee.App/Views/RenameToolWindow.axaml
index 6f43b334..eb40ed90 100644
--- a/src/Filee.App/Views/RenameToolWindow.axaml
+++ b/src/Filee.App/Views/RenameToolWindow.axaml
@@ -72,9 +72,34 @@
</Border>
</DockPanel>
- <!-- The steps and what they do -->
+ <!-- The base name, the rules and what they do -->
<ScrollViewer Grid.Column="1">
<StackPanel Spacing="16" Margin="0,0,4,0">
+ <!-- 1. Base name: typed, or built with the part buttons -->
+ <StackPanel Spacing="6">
+ <TextBlock Classes="label" Text="{DynamicResource watch.name}" />
+ <TextBox Text="{Binding NamePattern}" PlaceholderText="{Binding NamePlaceholder}" />
+ <ItemsControl ItemsSource="{Binding Tokens}">
+ <ItemsControl.ItemsPanel>
+ <ItemsPanelTemplate>
+ <WrapPanel />
+ </ItemsPanelTemplate>
+ </ItemsControl.ItemsPanel>
+ <ItemsControl.ItemTemplate>
+ <DataTemplate x:DataType="vm:NamePart">
+ <Button Padding="8,3" Margin="0,0,6,6" Tag="{Binding Token}" Click="OnInsertToken">
+ <StackPanel Orientation="Horizontal" Spacing="4">
+ <PathIcon Width="10" Height="10" Data="{StaticResource Icon.Plus}" />
+ <TextBlock Classes="caption" Text="{Binding Label}" />
+ </StackPanel>
+ </Button>
+ </DataTemplate>
+ </ItemsControl.ItemTemplate>
+ </ItemsControl>
+ <TextBlock Classes="caption" Text="{DynamicResource watch.name_hint}" TextWrapping="Wrap" />
+ </StackPanel>
+
+ <!-- 2. Rules applied to it -->
<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}" />
diff --git a/src/Filee.App/Views/RenameToolWindow.axaml.cs b/src/Filee.App/Views/RenameToolWindow.axaml.cs
index 75fa5a9d..05c123cc 100644
--- a/src/Filee.App/Views/RenameToolWindow.axaml.cs
+++ b/src/Filee.App/Views/RenameToolWindow.axaml.cs
@@ -22,6 +22,12 @@ public partial class RenameToolWindow : Window
recipe.AddCommand.Execute(null);
}
+ private void OnInsertToken(object? sender, RoutedEventArgs e)
+ {
+ if ((sender as Control)?.Tag is string token && DataContext is RenameToolViewModel tool)
+ tool.InsertToken(token);
+ }
+
private void OnSave(object? sender, RoutedEventArgs e)
{
if (DataContext is RenameToolViewModel { IsValid: true })
diff --git a/tests/Filee.App.Tests/RenderTests.cs b/tests/Filee.App.Tests/RenderTests.cs
index b13f9ebc..11253aca 100644
--- a/tests/Filee.App.Tests/RenderTests.cs
+++ b/tests/Filee.App.Tests/RenderTests.cs
@@ -118,6 +118,11 @@ public class RenderTests
// The rename window works on copies: a ready-made replacement becomes a rule, the preview follows.
var tool = item.CreateRenameTool();
+ Assert.Equal("{name}_scan", tool.NamePattern); // the base name is edited here too
+ tool.NamePattern = "";
+ tool.InsertToken("date"); // an empty name starts from the original one
+ Assert.Equal("{name}_{date}", tool.NamePattern);
+ tool.NamePattern = "{name}_scan";
tool.Recipes[0].AddCommand.Execute(null); // change IMG_ to Photo_
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));
@@ -144,7 +149,7 @@ public class RenderTests
Save(dialog, $"window-rename-{language}.png");
dialog.Close();
- item.SetRenames(tool.Result); // saved
+ item.SetNaming(tool.NamePattern, tool.Result); // saved
Assert.Equal("IMG_", 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);