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: Esc folds an open ring first; a mouse nudge keeps the keyboard's choice
SeoJCalive38adc53cf9fa
diff --git a/src/Filee.App/Controls/DonutMenu.cs b/src/Filee.App/Controls/DonutMenu.csindex 9ab7227e..009580e3 100644--- a/src/Filee.App/Controls/DonutMenu.cs+++ b/src/Filee.App/Controls/DonutMenu.cs@@ -150,6 +150,12 @@ public sealed partial class DonutMenu : Control/// <summary>Moving this far outward on a group slice opens it at once (the user is heading for its ring).</summary>private const double OutwardPixels = 10;+ // Keyboard: set by a handled key until the mouse moves KeyboardJitter away from where it was then.+ private bool _keyboardHold;+ private Point? _keyAnchor;+ private Point? _lastPointer;+ private const double KeyboardJitter = 6;+static DonutMenu(){AffectsMeasure<DonutMenu>(OuterRadiusProperty, ReserveSubRingProperty);@@ -526,6 +532,17 @@ public sealed partial class DonutMenu : Control/// Returns false for keys left to the window (Esc on the donut closes it)./// </summary>public bool HandleKey(Key key, KeyModifiers modifiers = KeyModifiers.None)+ {+ if (!HandleKeyCore(key, modifiers))+ return false;+ // The keyboard has the donut now: the mouse resting where it was (or nudged a pixel, or Windows re-sending its+ // position) doesn't take it back; moving it on purpose does.+ _keyboardHold = true;+ _keyAnchor = _lastPointer;+ return true;+ }++ private bool HandleKeyCore(Key key, KeyModifiers modifiers){if (IsEditMode || _progressMode || Count == 0)return false;@@ -537,17 +554,22 @@ public sealed partial class DonutMenu : Control_ => 0,};+ // Esc / Backspace fold an open ring first, however it was opened; only then does Esc close the donut.+ if (ExpandedChildren is not null && key is Key.Escape or Key.Back)+ {+ var group = _expanded;+ CollapseGroup();+ SetHover(group);+ return true;+ }+if (ExpandedChildren is { } children && _subHover >= 0){- switch (key)+ if (key is Key.Enter or Key.Space){- case Key.Enter or Key.Space:- if (children[_subHover].IsEnabled)- SubSegmentInvoked?.Invoke(this, (_expanded, _subHover));- return true;- case Key.Escape or Key.Back:- CollapseGroup();- return true;+ if (children[_subHover].IsEnabled)+ SubSegmentInvoked?.Invoke(this, (_expanded, _subHover));+ return true;}if (step == 0)return false;@@ -648,6 +670,16 @@ public sealed partial class DonutMenu : Controlreturn;}+ if (_keyboardHold)+ {+ if (_keyAnchor is not { } anchor)+ _keyAnchor = anchor = p;+ if (Distance(p, anchor) < KeyboardJitter)+ return;+ _keyboardHold = false;+ }+ _lastPointer = p;+var hit = HitTest(p);TrackGroups(hit, p);SetHover(hit.Kind switchdiff --git a/tests/Filee.App.Tests/DonutGroupTests.cs b/tests/Filee.App.Tests/DonutGroupTests.csindex 11e8715a..c2e7f66b 100644--- a/tests/Filee.App.Tests/DonutGroupTests.cs+++ b/tests/Filee.App.Tests/DonutGroupTests.cs@@ -242,6 +242,44 @@ public class DonutGroupTestswindow.Close();}+ [AvaloniaFact]+ public void Esc_folds_a_ring_the_mouse_opened_before_closing_the_donut()+ {+ var (donut, window) = Open();+ window.MouseMove(OnGroup(donut, donut.OuterRadius * 0.6));+ donut.ExpandPendingGroup();+ Assert.True(IsOpen(donut));+ Assert.Equal(-1, donut.ActiveSubIndex); // opened by resting the mouse: no ring slice chosen yet++ Assert.True(donut.HandleKey(Key.Escape));+ Assert.False(IsOpen(donut));+ Assert.False(donut.HandleKey(Key.Escape)); // now it's the window's+ window.Close();+ }++ [AvaloniaFact]+ public void A_mouse_nudge_keeps_what_the_keyboard_chose_a_real_move_takes_over()+ {+ var (donut, window) = Open();+ var c = Center(donut);+ window.MouseMove(c); // opened at the cursor: it rests in the hole+ donut.HandleKey(Key.Right);+ donut.HandleKey(Key.Right);+ donut.HandleKey(Key.Right); // to the group+ donut.HandleKey(Key.Enter);+ Assert.Equal(0, donut.ActiveSubIndex);++ window.MouseMove(new Point(c.X + 2, c.Y + 1)); // a nudge, or Windows re-sending the position+ Assert.Equal(0, donut.ActiveSubIndex);+ Assert.True(IsOpen(donut));++ var bmp = DonutGeometry.PointAt(c, donut.OuterRadius * 0.6, DonutGeometry.MidAngle(3, 4));+ window.MouseMove(bmp); // moved on purpose: the mouse leads again+ Assert.Equal(3, donut.ActiveIndex);+ Assert.False(IsOpen(donut));+ window.Close();+ }+[AvaloniaFact]public void With_animations_off_a_group_opens_at_once(){