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.

Engines page: LibreOffice settings in a window, drag cards to reorder

KnifeLemon84683739bda2
diff --git a/src/Filee.App/Assets/i18n/en.json b/src/Filee.App/Assets/i18n/en.json
index 5574c844..2c50d7dc 100644
--- a/src/Filee.App/Assets/i18n/en.json
+++ b/src/Filee.App/Assets/i18n/en.json
@@ -410,6 +410,8 @@
"engines.update": "Update",
"engines.state.update_available": "New version {0}",
"engines.update_notice_title": "Engines you installed have a new version",
+ "engines.settings": "Settings",
+ "engines.all_description": "Drag a card (or use its arrows) to change the order.",
"engines.lo_title": "When LibreOffice is installed",
"engines.lo_description": "Besides the formats only it reads, LibreOffice can take over conversions it does more faithfully. Without LibreOffice these switches change nothing.",
"engines.lo_slides": "Use LibreOffice for presentations → PDF",
diff --git a/src/Filee.App/Assets/i18n/ko.json b/src/Filee.App/Assets/i18n/ko.json
index e60b3710..2c0463d2 100644
--- a/src/Filee.App/Assets/i18n/ko.json
+++ b/src/Filee.App/Assets/i18n/ko.json
@@ -410,6 +410,8 @@
"engines.update": "업데이트",
"engines.state.update_available": "새 버전 {0}",
"engines.update_notice_title": "설치한 엔진에 새 버전이 있어요",
+ "engines.settings": "설정",
+ "engines.all_description": "카드를 끌어서(또는 화살표로) 순서를 바꿀 수 있어요.",
"engines.lo_title": "LibreOffice가 설치돼 있을 때",
"engines.lo_description": "LibreOffice만 읽을 수 있는 형식 외에도, 더 정확하게 변환하는 작업을 맡길 수 있어요. LibreOffice가 없으면 아래 설정은 아무 영향이 없어요.",
"engines.lo_slides": "발표 자료 → PDF는 LibreOffice로 변환",
diff --git a/src/Filee.App/Assets/i18n/zh-CN.json b/src/Filee.App/Assets/i18n/zh-CN.json
index 6540f1b5..ffa8b785 100644
--- a/src/Filee.App/Assets/i18n/zh-CN.json
+++ b/src/Filee.App/Assets/i18n/zh-CN.json
@@ -410,6 +410,8 @@
"engines.update": "更新",
"engines.state.update_available": "新版本 {0}",
"engines.update_notice_title": "已安装的引擎有新版本",
+ "engines.settings": "设置",
+ "engines.all_description": "拖动卡片(或用箭头)即可调整顺序。",
"engines.lo_title": "安装了 LibreOffice 时",
"engines.lo_description": "除了只有它能读取的格式,还可以把它转换得更准确的工作交给 LibreOffice。没有安装 LibreOffice 时,下面的设置没有作用。",
"engines.lo_slides": "演示文稿 → PDF 使用 LibreOffice",
diff --git a/src/Filee.App/Services/EngineDownloadService.cs b/src/Filee.App/Services/EngineDownloadService.cs
index edb2f949..42c3b208 100644
--- a/src/Filee.App/Services/EngineDownloadService.cs
+++ b/src/Filee.App/Services/EngineDownloadService.cs
@@ -37,6 +37,9 @@ public sealed partial class EnginePackageState : ObservableObject
public EnginePackage Package { get; }
public string Name => _loc[$"engines.package.{Package.Id}.name"];
+
+ /// <summary>Whether the package card has a Settings button (LibreOffice: which conversions to PDF it takes over).</summary>
+ public bool HasSettings => Package.Id == "libreoffice";
public string Description => _loc[$"engines.package.{Package.Id}.description"];
public string Sizes => EngineDownloads.CanDownload(Package)
diff --git a/src/Filee.App/Styles/Icons.axaml b/src/Filee.App/Styles/Icons.axaml
index 6b8fca43..b1b2e4e8 100644
--- a/src/Filee.App/Styles/Icons.axaml
+++ b/src/Filee.App/Styles/Icons.axaml
@@ -18,6 +18,7 @@
<StreamGeometry x:Key="Icon.Delete">M19,4H15.5L14.5,3H9.5L8.5,4H5V6H19M6,19A2,2 0 0,0 8,21H16A2,2 0 0,0 18,19V7H6V19Z</StreamGeometry>
<StreamGeometry x:Key="Icon.Copy">M19,21H8V7H19M19,5H8A2,2 0 0,0 6,7V21A2,2 0 0,0 8,23H19A2,2 0 0,0 21,21V7A2,2 0 0,0 19,5M16,1H4A2,2 0 0,0 2,3V17H4V3H16V1Z</StreamGeometry>
<StreamGeometry x:Key="Icon.Close">M19,6.41L17.59,5L12,10.59L6.41,5L5,6.41L10.59,12L5,17.59L6.41,19L12,13.41L17.59,19L19,17.59L13.41,12L19,6.41Z</StreamGeometry>
+ <StreamGeometry x:Key="Icon.DragVertical">M9,3H11V5H9V3M13,3H15V5H13V3M9,7H11V9H9V7M13,7H15V9H13V7M9,11H11V13H9V11M13,11H15V13H13V11M9,15H11V17H9V15M13,15H15V17H13V15M9,19H11V21H9V19M13,19H15V21H13V19Z</StreamGeometry>
<StreamGeometry x:Key="Icon.ChevronRight">M8.59,16.58L13.17,12L8.59,7.41L10,6L16,12L10,18L8.59,16.58Z</StreamGeometry>
<StreamGeometry x:Key="Icon.Shapes">M11,13.5V21.5H3V13.5H11M9,15.5H5V19.5H9V15.5M12,2L17.5,11H6.5L12,2M12,5.86L10.08,9H13.92L12,5.86M17.5,13C20,13 22,15 22,17.5C22,20 20,22 17.5,22C15,22 13,20 13,17.5C13,15 15,13 17.5,13M17.5,15A2.5,2.5 0 0,0 15,17.5A2.5,2.5 0 0,0 17.5,20A2.5,2.5 0 0,0 20,17.5A2.5,2.5 0 0,0 17.5,15Z</StreamGeometry>
<StreamGeometry x:Key="Icon.ArrowUp">M7,15L12,10L17,15H7Z</StreamGeometry>
diff --git a/src/Filee.App/ViewModels/Pages/EnginesPageViewModel.cs b/src/Filee.App/ViewModels/Pages/EnginesPageViewModel.cs
index dd1b810a..459acbe5 100644
--- a/src/Filee.App/ViewModels/Pages/EnginesPageViewModel.cs
+++ b/src/Filee.App/ViewModels/Pages/EnginesPageViewModel.cs
@@ -13,8 +13,11 @@ using Filee.Engines.Infrastructure;
namespace Filee.App.ViewModels.Pages;
-public sealed class EngineItemViewModel(IConverter converter, EngineStatus status, ILocalizer loc)
+public sealed partial class EngineItemViewModel(IConverter converter, EngineStatus status, ILocalizer loc) : ObservableObject
{
+ /// <summary>Being dragged to a new place in the priority order.</summary>
+ [ObservableProperty] private bool _isDragging;
+
public IConverter Converter { get; } = converter;
public string Name => Converter.DisplayName;
public bool IsAvailable { get; } = status.IsAvailable;
@@ -158,11 +161,23 @@ public sealed partial class EnginesPageViewModel : ObservableObject, IDisposable
private void Move(EngineItemViewModel item, int delta)
{
- var index = Engines.IndexOf(item);
- var target = index + delta;
- if (index < 0 || target < 0 || target >= Engines.Count)
- return;
- Engines.Move(index, target);
+ if (MoveTo(item, Engines.IndexOf(item) + delta))
+ SavePriority();
+ }
+
+ /// <summary>Moves <paramref name="item"/> to <paramref name="index"/> in the list (while dragging); false when it stays.</summary>
+ public bool MoveTo(EngineItemViewModel item, int index)
+ {
+ var from = Engines.IndexOf(item);
+ if (from < 0 || index < 0 || index >= Engines.Count || index == from)
+ return false;
+ Engines.Move(from, index);
+ return true;
+ }
+
+ /// <summary>Saves the order of the list as the engine priority.</summary>
+ public void SavePriority()
+ {
_store.Settings.EnginePriority = Engines.Select(e => e.Converter.Id).ToList();
_store.SaveSettings();
}
diff --git a/src/Filee.App/Views/LibreOfficeOptionsWindow.axaml b/src/Filee.App/Views/LibreOfficeOptionsWindow.axaml
new file mode 100644
index 00000000..5551a88b
--- /dev/null
+++ b/src/Filee.App/Views/LibreOfficeOptionsWindow.axaml
@@ -0,0 +1,39 @@
+<!-- What LibreOffice converts when it is installed, besides the formats only it reads. Opened from the Settings button
+ of the LibreOffice card on the Engines page; the switches save as they change. -->
+<Window xmlns="https://github.com/avaloniaui"
+ xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
+ xmlns:vm="using:Filee.App.ViewModels.Pages"
+ x:Class="Filee.App.Views.LibreOfficeOptionsWindow"
+ x:DataType="vm:EnginesPageViewModel"
+ Title="{DynamicResource engines.lo_title}"
+ Icon="avares://Filee/Assets/Icons/filee.ico"
+ Width="520"
+ SizeToContent="Height"
+ CanResize="False"
+ WindowStartupLocation="CenterOwner"
+ ShowInTaskbar="False">
+ <StackPanel Margin="22" Spacing="12">
+ <StackPanel Spacing="4">
+ <TextBlock Classes="h2" Text="{DynamicResource engines.lo_title}" />
+ <TextBlock Classes="caption" TextWrapping="Wrap" Text="{DynamicResource engines.lo_description}" />
+ </StackPanel>
+ <StackPanel Spacing="2">
+ <ToggleSwitch IsChecked="{Binding LibreOfficeForSlides}" OnContent="{DynamicResource engines.lo_slides}" OffContent="{DynamicResource engines.lo_slides}" />
+ <TextBlock Classes="caption" TextWrapping="Wrap" Text="{DynamicResource engines.lo_slides_hint}" />
+ </StackPanel>
+ <StackPanel Spacing="2">
+ <ToggleSwitch IsChecked="{Binding LibreOfficeForDocuments}" OnContent="{DynamicResource engines.lo_documents}" OffContent="{DynamicResource engines.lo_documents}" />
+ <TextBlock Classes="caption" TextWrapping="Wrap" Text="{DynamicResource engines.lo_documents_hint}" />
+ </StackPanel>
+ <StackPanel Spacing="2">
+ <ToggleSwitch IsChecked="{Binding LibreOfficeForSheets}" OnContent="{DynamicResource engines.lo_sheets}" OffContent="{DynamicResource engines.lo_sheets}" />
+ <TextBlock Classes="caption" TextWrapping="Wrap" Text="{DynamicResource engines.lo_sheets_hint}" />
+ </StackPanel>
+ <StackPanel Spacing="2">
+ <ToggleSwitch IsChecked="{Binding LibreOfficeForHwp}" OnContent="{DynamicResource engines.lo_hwp}" OffContent="{DynamicResource engines.lo_hwp}" />
+ <TextBlock Classes="caption" TextWrapping="Wrap" Text="{DynamicResource engines.lo_hwp_hint}" />
+ </StackPanel>
+ <Button Classes="accent" HorizontalAlignment="Right" Margin="0,6,0,0" MinWidth="88" HorizontalContentAlignment="Center"
+ Content="{DynamicResource common.close}" Click="OnClose" IsDefault="True" IsCancel="True" />
+ </StackPanel>
+</Window>
diff --git a/src/Filee.App/Views/LibreOfficeOptionsWindow.axaml.cs b/src/Filee.App/Views/LibreOfficeOptionsWindow.axaml.cs
new file mode 100644
index 00000000..37ed5140
--- /dev/null
+++ b/src/Filee.App/Views/LibreOfficeOptionsWindow.axaml.cs
@@ -0,0 +1,17 @@
+using Avalonia.Controls;
+using Avalonia.Interactivity;
+using Filee.App.Services;
+
+namespace Filee.App.Views;
+
+/// <summary>Modal LibreOffice switches of the Engines page (its view model is the DataContext).</summary>
+public partial class LibreOfficeOptionsWindow : Window
+{
+ public LibreOfficeOptionsWindow()
+ {
+ InitializeComponent();
+ Motion.Track(this);
+ }
+
+ private void OnClose(object? sender, RoutedEventArgs e) => Close();
+}
diff --git a/src/Filee.App/Views/Pages/EnginesPage.axaml b/src/Filee.App/Views/Pages/EnginesPage.axaml
index 2c6b60bd..0d1b562c 100644
--- a/src/Filee.App/Views/Pages/EnginesPage.axaml
+++ b/src/Filee.App/Views/Pages/EnginesPage.axaml
@@ -4,6 +4,21 @@
xmlns:svc="using:Filee.App.Services"
x:Class="Filee.App.Views.Pages.EnginesPage"
x:DataType="vm:EnginesPageViewModel">
+ <UserControl.Styles>
+ <Style Selector="Border.card.engine">
+ <Setter Property="Transitions">
+ <Transitions>
+ <BoxShadowsTransition Property="BoxShadow" Duration="0:0:0.15" />
+ </Transitions>
+ </Setter>
+ </Style>
+ <!-- The card being dragged: lifted, with the accent outline -->
+ <Style Selector="Border.card.engine.dragging">
+ <Setter Property="BorderBrush" Value="{DynamicResource AccentBrush}" />
+ <Setter Property="BoxShadow" Value="0 8 24 0 #33000000" />
+ <Setter Property="ZIndex" Value="1" />
+ </Style>
+ </UserControl.Styles>
<StackPanel Spacing="18">
<DockPanel>
<Button DockPanel.Dock="Right" Command="{Binding RecheckCommand}">
@@ -35,6 +50,12 @@
<Border Classes="card" Padding="16,12">
<DockPanel>
<StackPanel DockPanel.Dock="Right" Orientation="Horizontal" Spacing="6" VerticalAlignment="Center" Margin="12,0,0,0">
+ <Button IsVisible="{Binding HasSettings}" Click="OnPackageSettings" ToolTip.Tip="{DynamicResource engines.lo_title}">
+ <StackPanel Orientation="Horizontal" Spacing="6">
+ <PathIcon Width="13" Height="13" Data="{StaticResource Icon.Settings}" />
+ <TextBlock Text="{DynamicResource engines.settings}" />
+ </StackPanel>
+ </Button>
<Button Classes="accent" Content="{DynamicResource engines.install}" IsVisible="{Binding CanInstall}"
Command="{Binding $parent[ItemsControl].((vm:EnginesPageViewModel)DataContext).InstallCommand}" CommandParameter="{Binding}" />
<Button Classes="accent" Content="{DynamicResource engines.update}" IsVisible="{Binding CanUpdate}"
@@ -68,33 +89,14 @@
</DataTemplate>
</ItemsControl.ItemTemplate>
</ItemsControl>
- <!-- What LibreOffice converts when it is installed, besides the formats only it reads -->
- <Border Classes="card">
- <StackPanel Spacing="10">
- <TextBlock Classes="h2" Text="{DynamicResource engines.lo_title}" />
- <TextBlock Classes="caption" TextWrapping="Wrap" Text="{DynamicResource engines.lo_description}" />
- <StackPanel Spacing="2">
- <ToggleSwitch IsChecked="{Binding LibreOfficeForSlides}" OnContent="{DynamicResource engines.lo_slides}" OffContent="{DynamicResource engines.lo_slides}" />
- <TextBlock Classes="caption" TextWrapping="Wrap" Margin="0,0,0,4" Text="{DynamicResource engines.lo_slides_hint}" />
- </StackPanel>
- <StackPanel Spacing="2">
- <ToggleSwitch IsChecked="{Binding LibreOfficeForDocuments}" OnContent="{DynamicResource engines.lo_documents}" OffContent="{DynamicResource engines.lo_documents}" />
- <TextBlock Classes="caption" TextWrapping="Wrap" Margin="0,0,0,4" Text="{DynamicResource engines.lo_documents_hint}" />
- </StackPanel>
- <StackPanel Spacing="2">
- <ToggleSwitch IsChecked="{Binding LibreOfficeForSheets}" OnContent="{DynamicResource engines.lo_sheets}" OffContent="{DynamicResource engines.lo_sheets}" />
- <TextBlock Classes="caption" TextWrapping="Wrap" Margin="0,0,0,4" Text="{DynamicResource engines.lo_sheets_hint}" />
- </StackPanel>
- <StackPanel Spacing="2">
- <ToggleSwitch IsChecked="{Binding LibreOfficeForHwp}" OnContent="{DynamicResource engines.lo_hwp}" OffContent="{DynamicResource engines.lo_hwp}" />
- <TextBlock Classes="caption" TextWrapping="Wrap" Text="{DynamicResource engines.lo_hwp_hint}" />
- </StackPanel>
- </StackPanel>
- </Border>
- <TextBlock Classes="h2" Margin="0,8,0,0" Text="{DynamicResource engines.all_title}" />
+ <StackPanel Spacing="2" Margin="0,8,0,0">
+ <TextBlock Classes="h2" Text="{DynamicResource engines.all_title}" />
+ <TextBlock Classes="muted" TextWrapping="Wrap" Text="{DynamicResource engines.all_description}" />
+ </StackPanel>
</StackPanel>
- <ItemsControl ItemsSource="{Binding Engines}">
+ <!-- Every engine in priority order: drag a card (or use the arrows) to change it -->
+ <ItemsControl x:Name="EngineList" ItemsSource="{Binding Engines}">
<ItemsControl.ItemsPanel>
<ItemsPanelTemplate>
<StackPanel Spacing="10" />
@@ -102,7 +104,8 @@
</ItemsControl.ItemsPanel>
<ItemsControl.ItemTemplate>
<DataTemplate x:DataType="vm:EngineItemViewModel">
- <Border Classes="card" Padding="16,12">
+ <Border Classes="card engine" Classes.dragging="{Binding IsDragging}" Padding="16,12" Cursor="SizeNorthSouth"
+ PointerPressed="OnEnginePressed">
<StackPanel Spacing="10">
<DockPanel>
<StackPanel DockPanel.Dock="Right" Orientation="Horizontal" Spacing="4">
@@ -115,6 +118,8 @@
<PathIcon Width="14" Height="14" Data="{StaticResource Icon.ArrowDown}" />
</Button>
</StackPanel>
+ <PathIcon DockPanel.Dock="Left" Width="16" Height="16" Margin="0,0,8,0" Opacity="0.4" VerticalAlignment="Center"
+ Data="{StaticResource Icon.DragVertical}" />
<Border DockPanel.Dock="Left" Width="10" Height="10" CornerRadius="999" Margin="2,0,12,0" VerticalAlignment="Center"
Background="{DynamicResource SuccessBrush}" IsVisible="{Binding IsAvailable}" />
<Border DockPanel.Dock="Left" Width="10" Height="10" CornerRadius="999" Margin="2,0,12,0" VerticalAlignment="Center"
diff --git a/src/Filee.App/Views/Pages/EnginesPage.axaml.cs b/src/Filee.App/Views/Pages/EnginesPage.axaml.cs
index 91510ba9..652d1eed 100644
--- a/src/Filee.App/Views/Pages/EnginesPage.axaml.cs
+++ b/src/Filee.App/Views/Pages/EnginesPage.axaml.cs
@@ -1,6 +1,17 @@
+// Engines page: optional downloads (install, use your own copy, LibreOffice settings) and the priority order, changed
+// by dragging a card or with its arrows.
+//
+// Dragging: the list captures the pointer (cards are re-created as they move), the card moves as soon as the pointer
+// passes the middle of a neighbour, and the order is saved when the button is released. Near the top or bottom edge
+// of the page the page scrolls by itself.
+
+using Avalonia;
using Avalonia.Controls;
+using Avalonia.Input;
using Avalonia.Interactivity;
using Avalonia.Platform.Storage;
+using Avalonia.Threading;
+using Avalonia.VisualTree;
using Filee.App.Services;
using Filee.App.ViewModels.Pages;
using Filee.Core.Localization;
@@ -9,7 +20,114 @@ namespace Filee.App.Views.Pages;
public partial class EnginesPage : UserControl
{
- public EnginesPage() => InitializeComponent();
+ private const double DragThreshold = 5;
+ private const double ScrollEdge = 48;
+ private const double ScrollStep = 14;
+
+ private sealed class EngineDrag(EngineItemViewModel item, Point start)
+ {
+ public EngineItemViewModel Item { get; } = item;
+ public Point Start { get; } = start;
+ public bool Active { get; set; }
+
+ /// <summary>The pointer in the page's scroll viewer, for scrolling while it rests near an edge.</summary>
+ public Point InScroller { get; set; }
+ }
+
+ private readonly DispatcherTimer _scrollTimer = new() { Interval = TimeSpan.FromMilliseconds(16) };
+ private EngineDrag? _drag;
+
+ public EnginesPage()
+ {
+ InitializeComponent();
+ EngineList.AddHandler(PointerMovedEvent, OnListPointerMoved, handledEventsToo: true);
+ EngineList.AddHandler(PointerReleasedEvent, (_, e) => EndDrag(e.Pointer), handledEventsToo: true);
+ EngineList.AddHandler(PointerCaptureLostEvent, (_, _) => EndDrag(null), handledEventsToo: true);
+ _scrollTimer.Tick += (_, _) => AutoScroll();
+ }
+
+ private EnginesPageViewModel? Vm => DataContext as EnginesPageViewModel;
+
+ private ScrollViewer? Scroller => this.FindAncestorOfType<ScrollViewer>();
+
+ /// <summary>Pressing a card (not its arrows, which handle the press) may start dragging it.</summary>
+ private void OnEnginePressed(object? sender, PointerPressedEventArgs e)
+ {
+ if (sender is not Control { DataContext: EngineItemViewModel item } || !e.GetCurrentPoint(this).Properties.IsLeftButtonPressed)
+ return;
+ _drag = new EngineDrag(item, e.GetPosition(EngineList));
+ e.Pointer.Capture(EngineList);
+ e.Handled = true;
+ }
+
+ private void OnListPointerMoved(object? sender, PointerEventArgs e)
+ {
+ if (_drag is not { } drag)
+ return;
+ var p = e.GetPosition(EngineList);
+ if (!drag.Active)
+ {
+ if (Math.Abs(p.Y - drag.Start.Y) < DragThreshold && Math.Abs(p.X - drag.Start.X) < DragThreshold)
+ return;
+ drag.Active = true;
+ drag.Item.IsDragging = true;
+ _scrollTimer.Start();
+ }
+ if (Scroller is { } scroller)
+ drag.InScroller = e.GetPosition(scroller);
+ Follow(p.Y);
+ }
+
+ /// <summary>Moves the dragged card to where <paramref name="y"/> (in the list) is: after every other card whose middle is above it.</summary>
+ private void Follow(double y)
+ {
+ if (_drag is not { Active: true } drag || Vm is not { } vm)
+ return;
+ var index = 0;
+ for (var i = 0; i < vm.Engines.Count; i++)
+ {
+ if (vm.Engines[i] == drag.Item || EngineList.ContainerFromIndex(i) is not { } card)
+ continue;
+ if (card.TranslatePoint(new Point(0, card.Bounds.Height / 2), EngineList) is { } middle && middle.Y < y)
+ index++;
+ }
+ vm.MoveTo(drag.Item, index);
+ }
+
+ private void AutoScroll()
+ {
+ if (_drag is not { Active: true } drag || Scroller is not { } scroller)
+ return;
+ var y = drag.InScroller.Y;
+ var step = y < ScrollEdge ? -ScrollStep : y > scroller.Viewport.Height - ScrollEdge ? ScrollStep : 0;
+ var max = Math.Max(0, scroller.Extent.Height - scroller.Viewport.Height);
+ var offset = Math.Clamp(scroller.Offset.Y + step, 0, max);
+ if (step == 0 || offset == scroller.Offset.Y)
+ return;
+ scroller.Offset = scroller.Offset.WithY(offset);
+ if (scroller.TranslatePoint(drag.InScroller, EngineList) is { } inList)
+ Follow(inList.Y);
+ }
+
+ private void EndDrag(IPointer? pointer)
+ {
+ if (_drag is not { } drag)
+ return;
+ _drag = null;
+ _scrollTimer.Stop();
+ pointer?.Capture(null);
+ if (!drag.Active)
+ return;
+ drag.Item.IsDragging = false;
+ Vm?.SavePriority();
+ }
+
+ /// <summary>The LibreOffice switches, in their own window.</summary>
+ private async void OnPackageSettings(object? sender, RoutedEventArgs e)
+ {
+ if (DataContext is EnginesPageViewModel vm && TopLevel.GetTopLevel(this) is Window window)
+ await new LibreOfficeOptionsWindow { DataContext = vm }.ShowDialog(window);
+ }
/// <summary>Picks the program of a copy the user already has (ffmpeg.exe, ebook-convert.exe, …) and uses it.</summary>
private async void OnUseOwnCopy(object? sender, RoutedEventArgs e)
diff --git a/tests/Filee.App.Tests/EnginesPageTests.cs b/tests/Filee.App.Tests/EnginesPageTests.cs
new file mode 100644
index 00000000..f1c6edec
--- /dev/null
+++ b/tests/Filee.App.Tests/EnginesPageTests.cs
@@ -0,0 +1,114 @@
+// The Engines page: dragging a card changes the engine priority, the LibreOffice switches open from its card.
+
+using Avalonia;
+using Avalonia.Controls;
+using Avalonia.Headless;
+using Avalonia.Headless.XUnit;
+using Avalonia.Input;
+using Avalonia.Threading;
+using Avalonia.VisualTree;
+using Filee.App.Services;
+using Filee.App.ViewModels;
+using Filee.App.ViewModels.Pages;
+using Filee.App.Views;
+using Filee.App.Views.Pages;
+using Filee.Core.Localization;
+using Filee.Core.Settings;
+
+namespace Filee.App.Tests;
+
+public class EnginesPageTests
+{
+ private static void Pump()
+ {
+ for (var i = 0; i < 40; i++)
+ {
+ Dispatcher.UIThread.RunJobs();
+ AvaloniaHeadlessPlatform.ForceRenderTimerTick();
+ }
+ }
+
+ private static Point Middle(Control card, Visual to) => card.TranslatePoint(new Point(card.Bounds.Width / 2, card.Bounds.Height / 2), to)!.Value;
+
+ [AvaloniaFact]
+ public void Dragging_a_card_below_the_next_one_moves_it_there_and_saves_the_order()
+ {
+ TestServices.EnsureInitialized("en");
+ var store = AppHost.Get<UserDataStore>();
+ var saved = store.Settings.EnginePriority.ToList();
+ var vm = new MainWindowViewModel(AppHost.Services, AppHost.Get<ILocalizer>(), AppHost.Get<UpdateService>());
+ vm.Navigate("engines");
+ var window = new MainWindow { DataContext = vm, Width = 1080, Height = 820 };
+ window.Show();
+ Pump();
+ try
+ {
+ var page = window.GetVisualDescendants().OfType<EnginesPage>().Single();
+ var engines = ((EnginesPageViewModel)page.DataContext!).Engines;
+ var (first, second, third) = (engines[0], engines[1], engines[2]);
+ var list = page.FindControl<ItemsControl>("EngineList")!;
+ // The first card a little below the top of the page, away from the edges that scroll the page while dragging.
+ var scroller = page.FindAncestorOfType<ScrollViewer>()!;
+ var top = list.ContainerFromIndex(0)!.TranslatePoint(default, scroller)!.Value.Y;
+ scroller.Offset = scroller.Offset.WithY(scroller.Offset.Y + top - 150);
+ Pump();
+
+ // Grab the first card and move past the middle of the second one: it moves there while dragging.
+ var from = Middle(list.ContainerFromIndex(0)!, window);
+ var past = Middle(list.ContainerFromIndex(1)!, window) + new Point(0, 12);
+ window.MouseDown(from, MouseButton.Left);
+ window.MouseMove(from + new Point(0, 8));
+ Assert.True(first.IsDragging);
+ window.MouseMove(past);
+ Pump();
+ Assert.Equal([second, first, third], engines.Take(3));
+ Assert.Equal(saved, store.Settings.EnginePriority); // saved on release
+
+ window.MouseUp(past, MouseButton.Left);
+ Pump();
+ Assert.False(first.IsDragging);
+ Assert.Equal(engines.Select(e => e.Converter.Id), store.Settings.EnginePriority);
+
+ // A click without moving changes nothing.
+ var order = engines.ToList();
+ var at = Middle(list.ContainerFromIndex(2)!, window);
+ window.MouseDown(at, MouseButton.Left);
+ window.MouseUp(at, MouseButton.Left);
+ Pump();
+ Assert.Equal(order, engines);
+ }
+ finally
+ {
+ window.Close();
+ store.Settings.EnginePriority = saved;
+ store.SaveSettings();
+ }
+ }
+
+ [AvaloniaFact]
+ public void Only_LibreOffice_has_settings_and_they_change_the_saved_switches()
+ {
+ TestServices.EnsureInitialized("en");
+ var store = AppHost.Get<UserDataStore>();
+ var before = store.Settings.LibreOfficeForSheets;
+ var vm = new EnginesPageViewModel(store, AppHost.Get<Filee.Core.Conversion.ConverterCatalog>(), AppHost.Get<ILocalizer>(),
+ AppHost.Get<EngineDownloadService>());
+ try
+ {
+ Assert.Equal(["libreoffice"], vm.Packages.Where(p => p.HasSettings).Select(p => p.Package.Id));
+
+ var options = new LibreOfficeOptionsWindow { DataContext = vm };
+ options.Show();
+ Pump();
+ var sheets = options.GetVisualDescendants().OfType<ToggleSwitch>().ElementAt(2);
+ sheets.IsChecked = !before;
+ Assert.Equal(!before, store.Settings.LibreOfficeForSheets);
+ options.Close();
+ }
+ finally
+ {
+ vm.LibreOfficeForSheets = before;
+ vm.Dispose();
+ }
+ }
+}
diff --git a/tests/Filee.App.Tests/RenderTests.cs b/tests/Filee.App.Tests/RenderTests.cs
index da2c5167..1027ec93 100644
--- a/tests/Filee.App.Tests/RenderTests.cs
+++ b/tests/Filee.App.Tests/RenderTests.cs
@@ -361,6 +361,19 @@ public class RenderTests
window.Close();
}
+ [AvaloniaFact]
+ public void LibreOffice_options_window_renders()
+ {
+ TestServices.EnsureInitialized("ko");
+ using var vm = new Filee.App.ViewModels.Pages.EnginesPageViewModel(AppHost.Get<Filee.Core.Settings.UserDataStore>(),
+ AppHost.Get<Filee.Core.Conversion.ConverterCatalog>(), AppHost.Get<Filee.Core.Localization.ILocalizer>(), AppHost.Get<EngineDownloadService>());
+ var window = new Filee.App.Views.LibreOfficeOptionsWindow { DataContext = vm };
+ window.Show();
+ Pump();
+ Save(window, "window-libreoffice-options-ko.png");
+ window.Close();
+ }
+
[AvaloniaTheory]
[InlineData("en")]
[InlineData("ko")]