A language switch re-read computed properties only: the job bar of a running job,
the Jobs rows, the editor's chart legends and summaries, Auto chips, markers and
info line, the Archive figures and the Import session table kept the old language
until their next change. LocalizedViewModel gains OnLanguageChanged, where each of
them makes those texts again.
Meta lines joined their fields with a plain " · ": in Arabic or Hebrew a number
after a Latin field ("Canon EOS R5 · 2 h") joined the Latin run and split its own
field. Loc.Separator puts right-to-left marks around the dot in right-to-left
languages and is used for every such line. Desktop file sizes use the Common.Size
formats, as the Setup and the Uploader do.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_012iLMBNwBE2GnphAsu4cjaC
87 lines
3.5 KiB
C#
87 lines
3.5 KiB
C#
using System.Windows.Input;
|
|
using Titano.Core.Localization;
|
|
using Titano.Ui.Mvvm;
|
|
using Titano.Uploader.Text;
|
|
|
|
namespace Titano.Uploader.Shell;
|
|
|
|
/// <summary>An entry of a watch folder chip's menu: an interval choice, a separator (no text) or "Remove".</summary>
|
|
public sealed record WatchMenuOption(string? Text, string? ToolTip, ICommand? Command, bool IsChecked)
|
|
{
|
|
public bool IsSeparator => Text is null;
|
|
}
|
|
|
|
/// <summary>One watch folder chip: path, interval, reachability.</summary>
|
|
public sealed class WatchFolderViewModel : ObservableObject
|
|
{
|
|
/// <summary>Intervals offered in the chip menu.</summary>
|
|
public static readonly int[] IntervalChoices = [30, 60, 300, 900];
|
|
|
|
private readonly Action<WatchFolderViewModel, int> _setInterval;
|
|
private readonly Action<WatchFolderViewModel> _remove;
|
|
private int _intervalSeconds;
|
|
private bool? _isAvailable;
|
|
|
|
public WatchFolderViewModel(string path, int intervalSeconds, bool isNetwork, Action<WatchFolderViewModel, int> setInterval, Action<WatchFolderViewModel> remove)
|
|
{
|
|
Path = path;
|
|
IsNetwork = isNetwork;
|
|
_intervalSeconds = intervalSeconds;
|
|
_setInterval = setInterval;
|
|
_remove = remove;
|
|
}
|
|
|
|
public string Path { get; }
|
|
public bool IsNetwork { get; }
|
|
|
|
public int IntervalSeconds
|
|
{
|
|
get => _intervalSeconds;
|
|
set
|
|
{
|
|
if (!Set(ref _intervalSeconds, value)) return;
|
|
OnPropertyChanged(nameof(Text));
|
|
OnPropertyChanged(nameof(IntervalText));
|
|
OnPropertyChanged(nameof(ToolTip));
|
|
OnPropertyChanged(nameof(MenuOptions));
|
|
}
|
|
}
|
|
|
|
/// <summary>Null until the first check finished.</summary>
|
|
public bool? IsAvailable
|
|
{
|
|
get => _isAvailable;
|
|
set
|
|
{
|
|
if (Set(ref _isAvailable, value)) OnPropertyChanged(nameof(ToolTip));
|
|
}
|
|
}
|
|
|
|
/// <summary>"D:\Cam\Roof · every 1 min": the chip's accessible name.</summary>
|
|
public string Text => Loc.L("Uploader.Watch.Chip", Path, Interval(IntervalSeconds));
|
|
|
|
/// <summary>"every 1 min", shown after the path, which the chip draws left to right on its own and may shorten.</summary>
|
|
public string IntervalText => Loc.L("Uploader.Watch.Interval", Interval(IntervalSeconds));
|
|
|
|
/// <summary>The full path (the chip may shorten it), then the folder's state and interval.</summary>
|
|
public string ToolTip => LeftToRight(Path) + Loc.Separator + (IsAvailable == false ? Loc.L("Tooltips.Uploader.WatchFolderMissing", Interval(IntervalSeconds))
|
|
: IsNetwork ? Loc.L("Tooltips.Uploader.WatchFolderNetwork", Interval(IntervalSeconds))
|
|
: Loc.L("Tooltips.Uploader.WatchFolder", Interval(IntervalSeconds)));
|
|
|
|
public IReadOnlyList<WatchMenuOption> MenuOptions =>
|
|
[
|
|
.. IntervalChoices.Select(s => new WatchMenuOption(
|
|
Loc.L("Uploader.Watch.Every", Interval(s)),
|
|
Loc.L("Tooltips.Uploader.WatchInterval"),
|
|
new RelayCommand(() => _setInterval(this, s)),
|
|
s == IntervalSeconds)),
|
|
new WatchMenuOption(null, null, null, false),
|
|
new WatchMenuOption(Loc.L("Uploader.Watch.Remove"), Loc.L("Tooltips.Uploader.RemoveWatchFolder"), new RelayCommand(() => _remove(this)), false),
|
|
];
|
|
|
|
private static string Interval(int seconds) => UploaderText.Duration(TimeSpan.FromSeconds(seconds), Loc.Culture);
|
|
|
|
/// <summary>Embeds a path left to right (LRE … PDF) so a right-to-left tooltip does not reorder its separators.</summary>
|
|
private static string LeftToRight(string text) => "\u202A" + text + "\u202C";
|
|
}
|