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.

Donut toolbar: add and edit palette chips with the keyboard

cre8ive-marketingfe1e138d68e8
diff --git a/src/Filee.App/Views/Pages/ToolbarPage.axaml b/src/Filee.App/Views/Pages/ToolbarPage.axaml
index dbd3310b..b06fa708 100644
--- a/src/Filee.App/Views/Pages/ToolbarPage.axaml
+++ b/src/Filee.App/Views/Pages/ToolbarPage.axaml
@@ -16,6 +16,11 @@
<Style Selector="Border.chip.dimmed">
<Setter Property="Opacity" Value="0.55" />
</Style>
+ <!-- A chip reached with Tab shows where the keyboard is: Enter adds it, Shift+F10 edits it. -->
+ <Style Selector="Border.chip:focus-visible">
+ <Setter Property="BorderBrush" Value="{DynamicResource AccentBrush}" />
+ <Setter Property="Background" Value="{DynamicResource AccentFaintBrush}" />
+ </Style>
<Style Selector="Border#PaletteBox.over">
<Setter Property="BorderBrush" Value="{DynamicResource DangerBrush}" />
<Setter Property="Background" Value="{DynamicResource AccentFaintBrush}" />
@@ -416,7 +421,9 @@
<ItemsControl.ItemTemplate>
<DataTemplate x:DataType="vm:PaletteChip">
<Border Classes="chip" Classes.dimmed="{Binding IsDimmed}" ToolTip.Tip="{Binding Reason}"
- PointerPressed="OnChipPressed" DoubleTapped="OnChipDoubleTapped">
+ PointerPressed="OnChipPressed" DoubleTapped="OnChipDoubleTapped"
+ Focusable="True" KeyDown="OnChipKeyDown"
+ AutomationProperties.Name="{Binding Label}">
<!-- A chip wider than the palette ends its caption with "…" instead of being cut at the edge. -->
<DockPanel>
<TextBlock Text="{Binding Label}" FontWeight="SemiBold" TextTrimming="CharacterEllipsis" />
diff --git a/src/Filee.App/Views/Pages/ToolbarPage.axaml.cs b/src/Filee.App/Views/Pages/ToolbarPage.axaml.cs
index 78455219..a11b9c89 100644
--- a/src/Filee.App/Views/Pages/ToolbarPage.axaml.cs
+++ b/src/Filee.App/Views/Pages/ToolbarPage.axaml.cs
@@ -126,6 +126,24 @@ public partial class ToolbarPage : UserControl
vm.Insert(chip.PresetId, vm.SliceCount);
}
+ /// <summary>The keyboard's double- and right-click on a chip: Enter appends it, Shift+F10 or the menu key edits it.</summary>
+ private void OnChipKeyDown(object? sender, KeyEventArgs e)
+ {
+ if (sender is not Border { DataContext: PaletteChip chip } || Vm is not { } vm)
+ return;
+ if (e.Key == Key.Enter && e.KeyModifiers == KeyModifiers.None)
+ {
+ if (chip.CanAdd)
+ vm.Insert(chip.PresetId, vm.SliceCount);
+ e.Handled = true;
+ }
+ else if (e.Key == Key.Apps || (e.Key == Key.F10 && e.KeyModifiers == KeyModifiers.Shift))
+ {
+ _ = vm.EditChipAsync(chip.PresetId);
+ e.Handled = true;
+ }
+ }
+
private void OnRootPointerMoved(object? sender, PointerEventArgs e)
{
if (_drag is null)
diff --git a/tests/Filee.App.Tests/ToolbarEditorTests.cs b/tests/Filee.App.Tests/ToolbarEditorTests.cs
index d9307422..5ae44b9d 100644
--- a/tests/Filee.App.Tests/ToolbarEditorTests.cs
+++ b/tests/Filee.App.Tests/ToolbarEditorTests.cs
@@ -3,6 +3,7 @@
using System.Reflection;
using Avalonia;
+using Avalonia.Automation;
using Avalonia.Controls;
using Avalonia.Data;
using Avalonia.Headless;
@@ -798,6 +799,42 @@ public class PresetAvailabilityTests
window.Close();
}
+ [AvaloniaFact]
+ public void The_keyboard_adds_a_focused_chip_with_enter_and_edits_it_with_shift_f10()
+ {
+ using var f = new Fixture();
+ using var vm = f.PageWithPalette("png", "mp4");
+ Dispatcher.UIThread.RunJobs();
+ var window = new Window { Width = 1080, Height = 820, Content = new ToolbarPage { DataContext = vm } };
+ window.Show();
+ Dispatcher.UIThread.RunJobs();
+ Border Chip(string id) => window.GetVisualDescendants().OfType<Border>().Single(b => b.DataContext is PaletteChip c && c.PresetId == id);
+
+ var jpg = Chip("test-jpg");
+ Assert.True(jpg.Focus(NavigationMethod.Tab));
+ Assert.Equal(((PaletteChip)jpg.DataContext!).Label, AutomationProperties.GetName(jpg));
+ window.KeyPress(Key.Enter, RawInputModifiers.None, PhysicalKey.Enter, null);
+ Dispatcher.UIThread.RunJobs();
+ Assert.Equal("test-jpg", vm.SelectedProfile!.Profile.PresetIds[^1]);
+
+ var windows = OpenMain();
+ try
+ {
+ // Opening the main window made it the active one; the keys go to the page's window again.
+ window.Activate();
+ Assert.True(Chip("test-mp4").Focus(NavigationMethod.Tab));
+ window.KeyPress(Key.F10, RawInputModifiers.Shift, PhysicalKey.F10, null);
+ SaveInEditor(windows, "jpg");
+ Dispatcher.UIThread.RunJobs();
+ Assert.Null(vm.Palette.Single(c => c.PresetId == "test-mp4").Reason);
+ }
+ finally
+ {
+ CloseMain(windows);
+ window.Close();
+ }
+ }
+
[AvaloniaFact]
public void Editing_a_preset_judges_it_again()
{