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
Donut groups: no drop where nothing converts, and say why
SeoJCalive902593c69973
diff --git a/src/Filee.App/Assets/i18n/en.json b/src/Filee.App/Assets/i18n/en.jsonindex ba8cef21..01a88cc6 100644--- a/src/Filee.App/Assets/i18n/en.json+++ b/src/Filee.App/Assets/i18n/en.json@@ -37,6 +37,7 @@"donut.files_mixed": "{0} files","donut.drop_to": "Drop → {0}","donut.pick_in_group": "Move outward to choose",+ "donut.group_empty": "No presets left in this group. Edit it in Settings → Donut toolbar","donut.click_to": "Click → {0}","donut.cancel": "Drop here to cancel","donut.close_hint": "Esc to close",diff --git a/src/Filee.App/Assets/i18n/ko.json b/src/Filee.App/Assets/i18n/ko.jsonindex e333712c..dcaaadbd 100644--- a/src/Filee.App/Assets/i18n/ko.json+++ b/src/Filee.App/Assets/i18n/ko.json@@ -37,6 +37,7 @@"donut.files_mixed": "파일 {0}개","donut.drop_to": "놓으면 {0}(으)로","donut.pick_in_group": "바깥으로 옮겨 고르세요",+ "donut.group_empty": "묶음에 남은 프리셋 없음 (설정 → 원형 툴바에서 편집)","donut.click_to": "클릭하면 {0}(으)로","donut.cancel": "여기에 놓으면 취소","donut.close_hint": "Esc로 닫기",diff --git a/src/Filee.App/Assets/i18n/zh-CN.json b/src/Filee.App/Assets/i18n/zh-CN.jsonindex cc4203fe..30a2ea98 100644--- a/src/Filee.App/Assets/i18n/zh-CN.json+++ b/src/Filee.App/Assets/i18n/zh-CN.json@@ -37,6 +37,7 @@"donut.files_mixed": "{0} 个文件","donut.drop_to": "松开 → {0}","donut.pick_in_group": "向外移动以选择",+ "donut.group_empty": "此组中已没有预设,请在“设置 → 环形工具栏”中编辑","donut.click_to": "点击 → {0}","donut.cancel": "拖到这里取消","donut.close_hint": "按 Esc 关闭",diff --git a/src/Filee.App/Controls/DonutMenu.cs b/src/Filee.App/Controls/DonutMenu.csindex d558909b..9ab7227e 100644--- a/src/Filee.App/Controls/DonutMenu.cs+++ b/src/Filee.App/Controls/DonutMenu.cs@@ -38,7 +38,11 @@ public sealed class DonutItem/// </summary>public IReadOnlyList<DonutItem>? Children { get; init; }- public bool IsGroup => Children is { Count: > 0 };+ /// <summary>A group slice (<see cref="Children"/> set), even one left with nothing to fan out.</summary>+ public bool IsGroup => Children is not null;++ /// <summary>A group with something to fan out.</summary>+ public bool CanExpand => Children is { Count: > 0 };}/// <summary>Donut-shaped menu control.</summary>@@ -452,7 +456,7 @@ public sealed partial class DonutMenu : Control{case DonutHitKind.Segment when hit.Index == _expanded:break;- case DonutHitKind.Segment when hit.Index >= 0 && hit.Index < Count && Items![hit.Index].IsGroup:+ case DonutHitKind.Segment when hit.Index >= 0 && hit.Index < Count && Items![hit.Index].CanExpand:_expanded = -1;var distance = at is { } p ? Distance(p, Center) : 0;if (_pendingGroup != hit.Index)@@ -555,7 +559,7 @@ public sealed partial class DonutMenu : Controlswitch (key){case Key.Enter or Key.Space when current >= 0:- if (Items![current].IsGroup)+ if (Items![current].CanExpand){Expand(current);SetSub(0);@@ -573,11 +577,15 @@ public sealed partial class DonutMenu : Controlreturn true;}- /// <summary>True when dropping or clicking at <paramref name="hit"/> converts: a slice that isn't a group, or a slice of a group's ring.</summary>+ /// <summary>+ /// True when dropping or clicking at <paramref name="hit"/> converts: an enabled slice that isn't a group, or an+ /// enabled slice of a group's ring. Elsewhere the drag shows "no drop".+ /// </summary>public bool Converts(DonutHit hit) => hit.Kind switch{- DonutHitKind.Segment => hit.Index >= 0 && hit.Index < Count && !Items![hit.Index].IsGroup,- DonutHitKind.SubSegment => true,+ DonutHitKind.Segment => hit.Index >= 0 && hit.Index < Count && Items![hit.Index] is { IsGroup: false, IsEnabled: true },+ DonutHitKind.SubSegment => hit.Index >= 0 && hit.Index < Count && Items![hit.Index].Children is { } children &&+ hit.Sub >= 0 && hit.Sub < children.Count && children[hit.Sub].IsEnabled,_ => false,};@@ -647,7 +655,10 @@ public sealed partial class DonutMenu : ControlDonutHitKind.Segment or DonutHitKind.EditButton or DonutHitKind.SubSegment => hit.Index,_ => -1,});- ToolTip.SetTip(this, _hoverIndex >= 0 && Items![_hoverIndex] is { IsEnabled: false } item ? item.DisabledReason : null);+ // On a group's ring, why that slice (not the group) is disabled.+ var hovered = hit.Kind == DonutHitKind.SubSegment ? Items![hit.Index].Children![hit.Sub]+ : _hoverIndex >= 0 ? Items![_hoverIndex] : null;+ ToolTip.SetTip(this, hovered is { IsEnabled: false } ? hovered.DisabledReason : null);}protected override void OnPointerExited(PointerEventArgs e)diff --git a/src/Filee.App/ViewModels/RadialViewModel.cs b/src/Filee.App/ViewModels/RadialViewModel.csindex d43bdac6..8b0fca72 100644--- a/src/Filee.App/ViewModels/RadialViewModel.cs+++ b/src/Filee.App/ViewModels/RadialViewModel.cs@@ -128,7 +128,9 @@ public sealed partial class RadialViewModel(UserDataStore store, ILocalizer loc,Label = loc.DisplayName(p),Caption = loc.Format("donut.group_caption", children.Count),IsEnabled = children.Any(c => c.IsEnabled),- DisabledReason = children.Select(c => c.DisabledReason).FirstOrDefault(r => r is not null),+ // Its presets were all deleted since it was made: say so rather than show a dead slice.+ DisabledReason = children.Count == 0 ? loc["donut.group_empty"]+ : children.Select(c => c.DisabledReason).FirstOrDefault(r => r is not null),Children = children,};}).ToList();@@ -144,7 +146,8 @@ public sealed partial class RadialViewModel(UserDataStore store, ILocalizer loc,{if (centerHot)CenterSubtitle = loc["donut.cancel"];- else if (index >= 0 && index < Items.Count && Items[index].Children is { } children)+ else if (index >= 0 && index < Items.Count && Items[index].Children is { Count: > 0 } children &&+ (sub >= 0 || Items[index].IsEnabled))CenterSubtitle = sub >= 0 && sub < children.Count? children[sub].IsEnabled? loc.Format(IsClickMode ? "donut.click_to" : "donut.drop_to", $"{Items[index].Label} · {children[sub].Label}")diff --git a/tests/Filee.App.Tests/DonutGroupTests.cs b/tests/Filee.App.Tests/DonutGroupTests.csindex 49a6403b..11e8715a 100644--- a/tests/Filee.App.Tests/DonutGroupTests.cs+++ b/tests/Filee.App.Tests/DonutGroupTests.cs@@ -9,6 +9,9 @@ using Avalonia.Input;using Avalonia.Threading;using Filee.App.Controls;using Filee.App.Services;+using Filee.App.ViewModels;+using Filee.Core.Presets;+using Filee.Core.Settings;namespace Filee.App.Tests;@@ -143,6 +146,56 @@ public class DonutGroupTestswindow.Close();}+ [AvaloniaFact]+ public void Only_enabled_slices_take_a_drop_and_an_empty_group_opens_nothing()+ {+ var empty = new DonutItem { Id = "empty", Label = "Empty", Children = [], IsEnabled = false };+ var (donut, window) = Open(Item("PNG"), Item("JPG"), GroupOf(Item("WEBP", enabled: false), Item("PDF"), Item("TIFF")), empty);+ Assert.True(donut.Converts(new DonutHit(DonutHitKind.Segment, 0)));+ Assert.False(donut.Converts(new DonutHit(DonutHitKind.Segment, Group))); // a group converts nothing itself+ Assert.False(donut.Converts(new DonutHit(DonutHitKind.SubSegment, Group, 0))); // can't take these files+ Assert.True(donut.Converts(new DonutHit(DonutHitKind.SubSegment, Group, 1)));++ // A group whose presets were all deleted: still a group (no drop), but nothing to open.+ Assert.False(donut.Converts(new DonutHit(DonutHitKind.Segment, 3)));+ var onEmpty = DonutGeometry.PointAt(Center(donut), donut.OuterRadius * 0.6, DonutGeometry.MidAngle(3, 4));+ donut.SetExternalHit(donut.HitTest(onEmpty), onEmpty);+ donut.ExpandPendingGroup();+ donut.HandleKey(Key.Enter);+ Assert.Equal(-1, donut.ActiveSubIndex);+ Assert.Equal(new DonutHit(DonutHitKind.Outside), donut.HitTest(DonutGeometry.PointAt(Center(donut), donut.OuterRadius + 40, DonutGeometry.MidAngle(3, 4))));+ window.Close();+ }++ [AvaloniaFact]+ public void A_group_left_without_presets_says_why_on_the_donut()+ {+ TestServices.EnsureInitialized("en");+ var store = AppHost.Get<UserDataStore>();+ var images = store.Profiles.Single(p => p.Id == "images");+ var before = images.PresetIds.ToList();+ var group = new Preset { Id = "test-empty-group", Name = "Gone", Kind = PresetKind.Group, SubPresetIds = ["no-such-preset"] };+ try+ {+ store.Presets.Add(group);+ images.PresetIds.Add(group.Id);+ var vm = AppHost.Get<RadialViewModel>();+ vm.Load([@"C:\photos\a.jpg"], clickMode: true);+ var index = vm.Items.Count - 1;+ Assert.True(vm.Items[index].IsGroup);+ Assert.False(vm.Items[index].IsEnabled);+ Assert.Contains("No presets left", vm.Items[index].DisabledReason);+ vm.ShowHint(index, -1, centerHot: false);+ Assert.Equal(vm.Items[index].DisabledReason, vm.CenterSubtitle); // not "Move outward to choose"+ }+ finally+ {+ images.PresetIds.Clear();+ images.PresetIds.AddRange(before);+ store.Presets.Remove(group);+ }+ }+[AvaloniaFact]public void A_donut_of_just_a_group_fans_out_slices_that_dont_overlap(){