Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 15 additions & 1 deletion .github/workflows/msbuild.yml
Original file line number Diff line number Diff line change
Expand Up @@ -30,11 +30,15 @@ jobs:
with:
submodules: recursive
fetch-depth: 0
ref: master

- name: Add MSBuild to PATH
uses: microsoft/setup-msbuild@v3

- name: Set up .NET SDK for archive regression tests
uses: actions/setup-dotnet@v4
with:
dotnet-version: '10.0.x'

- name: Restore NuGet packages
working-directory: ${{env.GITHUB_WORKSPACE}}
run: msbuild /t:Restore /p:Configuration=${{env.BUILD_CONFIGURATION}} ${{env.SOLUTION_FILE_PATH}}
Expand All @@ -45,12 +49,22 @@ jobs:
# See https://docs.microsoft.com/visualstudio/msbuild/msbuild-command-line-reference
run: msbuild /m /p:BuildInParallel=true /p:Configuration=${{env.BUILD_CONFIGURATION}} ${{env.SOLUTION_FILE_PATH}}

# Preserve packaged build artifacts before the regression runner rebuilds referenced projects.
# upload msi and zip artifacts so the publish job below can download and then update latest release via Linux
- uses: actions/upload-artifact@v6
with:
name: quicklook-build-files
path: Build/QuickLook-*.*

- name: Test archive view interaction and virtualization
working-directory: ${{env.GITHUB_WORKSPACE}}
shell: pwsh
run: |
$solutionDir = (Get-Location).Path + '\'
dotnet run --project ./Tests/ArchiveViewer.Regression/ArchiveViewer.Regression.csproj --configuration Release -p:Platform=AnyCPU -p:SolutionDir=$solutionDir
if ($LASTEXITCODE -ne 0) { exit $LASTEXITCODE }


publish:
# don't run in parallel - wait for build to complete first
needs: build
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,86 @@
// Copyright © 2017-2026 QL-Win Contributors
// Licensed under the GNU General Public License, version 3 or later.

using System;
using System.Collections.Generic;
using System.Globalization;
using System.Windows.Automation;
using System.Windows.Automation.Peers;
using System.Windows.Automation.Provider;
using System.Windows.Controls;

namespace QuickLook.Plugin.ArchiveViewer.ArchiveFile;

/// <summary>
/// Keeps data-item automation peers when visual containers are recycled.
/// The flat list remains a List (not a falsely advertised hierarchical UIA tree).
/// </summary>
public sealed class ArchiveFileListBox : ListBox
{
private ArchiveListPeer _peer;
internal Action<ArchiveFileRow, bool> ExpansionRequested { get; set; }

protected override AutomationPeer OnCreateAutomationPeer() => _peer = new ArchiveListPeer(this);

internal void ResetAutomationPeers() => _peer?.ClearRows();

internal void RaiseExpansionChanged(ArchiveFileRow row, bool previous) => _peer?.RaiseExpansionChanged(row, previous);

private sealed class ArchiveListPeer(ArchiveFileListBox owner) : ListBoxAutomationPeer(owner)
{
private readonly Dictionary<ArchiveFileRow, WeakReference<ArchiveRowPeer>> _rows = [];

protected override ItemAutomationPeer CreateItemAutomationPeer(object item)
{
var row = (ArchiveFileRow)item;
if (_rows.TryGetValue(row, out var reference) && reference.TryGetTarget(out var peer))
return peer;
peer = new ArchiveRowPeer(item, this, owner);
_rows[row] = new WeakReference<ArchiveRowPeer>(peer);
return peer;
}

public void ClearRows() => _rows.Clear();

public void RaiseExpansionChanged(ArchiveFileRow row, bool previous)
{
if (_rows.TryGetValue(row, out var reference) && reference.TryGetTarget(out var peer))
peer.RaisePropertyChangedEvent(ExpandCollapsePatternIdentifiers.ExpandCollapseStateProperty,
previous ? ExpandCollapseState.Expanded : ExpandCollapseState.Collapsed,
row.IsExpanded ? ExpandCollapseState.Expanded : ExpandCollapseState.Collapsed);
}
}

private sealed class ArchiveRowPeer(object item, ListBoxAutomationPeer parent, ArchiveFileListBox owner)
: ListBoxItemAutomationPeer(item, parent), IExpandCollapseProvider
{
private ArchiveFileRow Row => (ArchiveFileRow)Item;

protected override string GetNameCore() => Row.Entry.Name;

protected override string GetHelpTextCore() =>
string.Format(CultureInfo.CurrentUICulture, ArchiveFileStrings.LevelFormat, Row.Depth + 1);

public override object GetPattern(PatternInterface patternInterface) =>
patternInterface == PatternInterface.ExpandCollapse && Row.HasChildren
? this : base.GetPattern(patternInterface);

ExpandCollapseState IExpandCollapseProvider.ExpandCollapseState =>
!Row.HasChildren ? ExpandCollapseState.LeafNode :
Row.IsExpanded ? ExpandCollapseState.Expanded : ExpandCollapseState.Collapsed;

void IExpandCollapseProvider.Expand() => SetExpanded(true);
void IExpandCollapseProvider.Collapse() => SetExpanded(false);

private void SetExpanded(bool expanded)
{
owner.Dispatcher.Invoke(() =>
{
if (!owner.IsEnabled) throw new ElementNotEnabledException();
if (!owner.Items.Contains(Row) || owner.ExpansionRequested == null)
throw new ElementNotAvailableException();
owner.ExpansionRequested(Row, expanded);
});
}
}
}
Original file line number Diff line number Diff line change
@@ -1,133 +1,154 @@
<UserControl x:Class="QuickLook.Plugin.ArchiveViewer.ArchiveFile.ArchiveFileListView"
<UserControl x:Class="QuickLook.Plugin.ArchiveViewer.ArchiveFile.ArchiveFileListView"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:local="clr-namespace:QuickLook.Plugin.ArchiveViewer.ArchiveFile"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
x:Name="archiveListView"
d:DesignHeight="300"
d:DesignWidth="300"
d:DesignWidth="800"
mc:Ignorable="d">
<Grid x:Name="treeGrid" Grid.IsSharedSizeScope="True">
<Grid>
<Grid.RowDefinitions>
<!-- Header row -->
<RowDefinition Height="Auto" />
<!-- Row for data -->
<RowDefinition />
</Grid.RowDefinitions>

<Grid.Resources>

<!-- Converts the level in the tree to the width of the spacer column -->
<local:LevelToIndentConverter x:Key="LevelToIndentConverter" />
<local:BooleanToAsteriskConverter x:Key="BooleanToAsteriskConverter" />
<local:SizePrettyPrintConverter x:Key="SizePrettyPrintConverter" />
<local:DatePrintConverter x:Key="DatePrintConverter" />
<local:FileExtToIconConverter x:Key="FileExtToIconConverter" />
<local:LevelToBooleanConverter x:Key="LevelToBooleanConverter" />
<local:AvailableIndentWidthConverter x:Key="AvailableIndentWidthConverter" />
</Grid.Resources>

<!-- Fixed column widths avoid a shared-size measurement pass across the entire archive. -->
<Grid Grid.Row="0" Margin="0,0,0,4">
<Grid.ColumnDefinitions>
<ColumnDefinition />
<ColumnDefinition Width="{x:Static SystemParameters.VerticalScrollBarWidth}" />
</Grid.ColumnDefinitions>
<ScrollViewer x:Name="columnHeaders"
HorizontalScrollBarVisibility="Hidden"
VerticalScrollBarVisibility="Disabled"
Focusable="False">
<!-- Hidden scrollbars do not constrain their content width: bind it to the viewport. -->
<Grid x:Name="headerColumns" MinWidth="500"
Width="{Binding ActualWidth, ElementName=columnHeaders}">
<Grid.ColumnDefinitions>
<ColumnDefinition Width="*" MinWidth="200" />
<ColumnDefinition Width="135" />
<ColumnDefinition Width="165" />
</Grid.ColumnDefinitions>
<TextBlock Grid.Column="1" Text="Original Size" />
<TextBlock Grid.Column="2" Text="Modified Date" />
</Grid>
</ScrollViewer>
</Grid>

<!-- Template for directory information at all levels -->
<HierarchicalDataTemplate DataType="{x:Type local:ArchiveFileEntry}" ItemsSource="{Binding Children.Keys}">
<Grid>
<Grid.RowDefinitions>
<RowDefinition Height="2" />
<RowDefinition />
<RowDefinition Height="2" />
</Grid.RowDefinitions>
<Grid Grid.Row="1" ShowGridLines="False">
<!--
All column widths are shared except for column 1 which is sized
to compensate for different indentation at each level
-->
<!--
A single flat item host is essential: nesting TreeViewItem hosts can generate
thousands of containers while an expanded node is measured. The backing
collection contains only visible (expanded) rows, while this ListBox only
realizes rows in the viewport.
-->
<local:ArchiveFileListBox x:Name="fileList"
Grid.Row="1"
ItemsSource="{Binding Rows, ElementName=archiveListView}"
Background="Transparent"
BorderThickness="0"
Focusable="True"
SelectionMode="Single"
KeyboardNavigation.TabNavigation="Once"
PreviewKeyDown="NavigateTree"
MouseDoubleClick="ToggleRowByDoubleClick"
ScrollViewer.ScrollChanged="SynchronizeHeaders"
AutomationProperties.Name="{x:Static local:ArchiveFileStrings.ArchiveContents}"
ScrollViewer.CanContentScroll="True"
ScrollViewer.HorizontalScrollBarVisibility="Auto"
ScrollViewer.VerticalScrollBarVisibility="Visible"
VirtualizingStackPanel.IsVirtualizing="True"
VirtualizingStackPanel.VirtualizationMode="Recycling">
<ListBox.ItemsPanel>
<ItemsPanelTemplate>
<VirtualizingStackPanel />
</ItemsPanelTemplate>
</ListBox.ItemsPanel>
<ListBox.ItemContainerStyle>
<Style TargetType="{x:Type ListBoxItem}">
<Setter Property="HorizontalContentAlignment" Value="Stretch" />
<Setter Property="Padding" Value="0" />
<Setter Property="Focusable" Value="True" />
<Setter Property="ToolTip" Value="{Binding Entry.Name}" />
<Setter Property="AutomationProperties.Name" Value="{Binding Entry.Name}" />
<Setter Property="MinHeight" Value="24" />
</Style>
</ListBox.ItemContainerStyle>
<ListBox.ItemTemplate>
<DataTemplate DataType="{x:Type local:ArchiveFileRow}">
<!-- Keep the row at the measured header width; long filenames must not expand its star column. -->
<Grid MinHeight="24" MinWidth="500" Width="{Binding ActualWidth, ElementName=headerColumns}">
<Grid.ColumnDefinitions>
<ColumnDefinition MinWidth="300" SharedSizeGroup="rowHeaderColumn" />
<ColumnDefinition />
<ColumnDefinition MinWidth="100" SharedSizeGroup="column1" />
<ColumnDefinition MinWidth="100" SharedSizeGroup="column2" />
<ColumnDefinition Width="*" MinWidth="200" />
<ColumnDefinition Width="135" />
<ColumnDefinition Width="165" />
</Grid.ColumnDefinitions>
<StackPanel Grid.Column="0" Orientation="Horizontal">
<Image Width="16" Height="16">
<Grid x:Name="nameColumns" Grid.Column="0" ClipToBounds="True">
<Grid.ColumnDefinitions>
<ColumnDefinition Width="Auto" />
<ColumnDefinition Width="20" />
<ColumnDefinition Width="18" />
<ColumnDefinition Width="*" />
</Grid.ColumnDefinitions>
<!-- Reserve room for the expander, icon and a readable filename even in deep trees. -->
<Border Grid.Column="0" Width="{Binding IndentWidth}"
MaxWidth="{Binding ActualWidth, ElementName=nameColumns, Converter={StaticResource AvailableIndentWidthConverter}}" />
<Button Grid.Column="1"
Background="Transparent"
BorderThickness="0"
Focusable="False"
IsTabStop="False"
AutomationProperties.Name="{Binding Entry.Name}"
AutomationProperties.HelpText="{x:Static local:ArchiveFileStrings.ExpandOrCollapseFolder}"
FontSize="13"
Padding="0"
Content="{Binding ExpansionGlyph}"
IsEnabled="{Binding HasChildren}"
Click="ToggleFolder" />
<Image Grid.Column="2" Width="16" Height="16">
<Image.Source>
<MultiBinding Converter="{StaticResource FileExtToIconConverter}">
<Binding Path="Name" />
<Binding Path="IsFolder" />
<Binding Path="Entry.Name" />
<Binding Path="Entry.IsFolder" />
</MultiBinding>
</Image.Source>
</Image>
<TextBlock Text="{Binding Name}" />
<TextBlock Text="{Binding Encrypted, Converter={StaticResource BooleanToAsteriskConverter}}" />
</StackPanel>
<Rectangle Grid.Column="1">
<Rectangle.Width>
<MultiBinding Converter="{StaticResource LevelToIndentConverter}">
<Binding Path="Level" />
<Binding ElementName="treeViewItemToMeasure" Path="ActualWidth" />
</MultiBinding>
</Rectangle.Width>
</Rectangle>
<TextBlock Grid.Column="2">
<TextBlock Grid.Column="3" VerticalAlignment="Center"
TextTrimming="CharacterEllipsis">
<Run Text="{Binding Entry.Name, Mode=OneWay}" />
<Run Text="{Binding Entry.Encrypted, Converter={StaticResource BooleanToAsteriskConverter}}" />
</TextBlock>
</Grid>
<TextBlock Grid.Column="1" VerticalAlignment="Center" TextTrimming="CharacterEllipsis"
ToolTip="{Binding Text, RelativeSource={RelativeSource Self}}">
<TextBlock.Text>
<MultiBinding Converter="{StaticResource SizePrettyPrintConverter}">
<Binding Path="Size" />
<Binding Path="IsFolder" />
<Binding Path="Entry.Size" />
<Binding Path="Entry.IsFolder" />
</MultiBinding>
</TextBlock.Text>
</TextBlock>
<TextBlock Grid.Column="3">
<TextBlock Grid.Column="2" VerticalAlignment="Center" TextTrimming="CharacterEllipsis"
ToolTip="{Binding Text, RelativeSource={RelativeSource Self}}">
<TextBlock.Text>
<MultiBinding Converter="{StaticResource DatePrintConverter}">
<Binding Path="ModifiedDate" />
<Binding Path="IsFolder" />
<Binding Path="Entry.ModifiedDate" />
<Binding Path="Entry.IsFolder" />
</MultiBinding>
</TextBlock.Text>
</TextBlock>
</Grid>
</Grid>
</HierarchicalDataTemplate>
</Grid.Resources>

<!-- Tree view with one item for the header row -->

<TreeView Background="Transparent"
BorderThickness="0"
Focusable="False"
ScrollViewer.HorizontalScrollBarVisibility="Disabled">
<TreeViewItem Focusable="False" Visibility="Collapsed">
<TreeViewItem.Header>
<Grid ShowGridLines="False">
<Grid.ColumnDefinitions>
<ColumnDefinition SharedSizeGroup="rowHeaderColumn" />
<ColumnDefinition />
<ColumnDefinition SharedSizeGroup="column1" />
<ColumnDefinition SharedSizeGroup="column2" />
</Grid.ColumnDefinitions>
<TextBlock Grid.Column="0" Text=" " />
<TreeViewItem Grid.Column="1">
<TreeViewItem.Header>
<TreeViewItem x:Name="treeViewItemToMeasure" Padding="0" />
</TreeViewItem.Header>

<!--
Set the width of Column 1 to the same width as the top level
in the data
-->
<TreeViewItem.Width>
<MultiBinding Converter="{StaticResource LevelToIndentConverter}">
<Binding Path="Level" />
<Binding ElementName="treeViewItemToMeasure" Path="ActualWidth" />
</MultiBinding>
</TreeViewItem.Width>
</TreeViewItem>
<TextBlock Grid.Column="2" Text="Original Size" />
<TextBlock Grid.Column="3" Text="Modified Date" />
</Grid>
</TreeViewItem.Header>
</TreeViewItem>
</TreeView>

<!-- Tree view that will display hierarchical data rows -->

<TreeView x:Name="treeView"
Grid.Row="1"
ItemsSource="{Binding}" />
</DataTemplate>
</ListBox.ItemTemplate>
</local:ArchiveFileListBox>
</Grid>
</UserControl>
</UserControl>
Loading