Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Peek] Support for archives #26839

Merged
merged 5 commits into from
Jun 28, 2023
Merged
Show file tree
Hide file tree
Changes from 4 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
6 changes: 6 additions & 0 deletions .github/actions/spell-check/expect.txt
Original file line number Diff line number Diff line change
Expand Up @@ -1087,6 +1087,7 @@ LIGHTORANGE
LIGHTTURQUOISE
lindex
linkedin
LINKOVERLAY
linq
LINQTo
listview
Expand Down Expand Up @@ -1415,6 +1416,7 @@ nullonfailure
numberbox
NUMLOCK
numpad
nupkg
nwc
Objbase
OBJID
Expand Down Expand Up @@ -1613,6 +1615,7 @@ psapi
pscid
PSECURITY
psfgao
psfi
Psr
psrm
psrree
Expand Down Expand Up @@ -1851,6 +1854,7 @@ shellscalingapi
SHFILEINFO
SHGDNF
SHGFI
shinfo
Shl
shldisp
shlobj
Expand Down Expand Up @@ -2056,6 +2060,7 @@ TEXCOORD
textblock
TEXTEXTRACTOR
TEXTINCLUDE
tgz
themeresources
THH
THICKFRAME
Expand Down Expand Up @@ -2123,6 +2128,7 @@ ULONGLONG
unapply
unassign
uncompilable
Uncompress
UNCPRIORITY
UNDNAME
UNICODETEXT
Expand Down
1 change: 1 addition & 0 deletions Directory.Packages.props
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@
<PackageVersion Include="NLog.Extensions.Logging" Version="5.0.4" />
<PackageVersion Include="NLog.Schema" Version="5.0.4" />
<PackageVersion Include="ScipBe.Common.Office.OneNote" Version="3.0.1" />
<PackageVersion Include="SharpCompress" Version="0.33.0" />
<PackageVersion Include="StreamJsonRpc" Version="2.14.24" />
<PackageVersion Include="StyleCop.Analyzers" Version="1.2.0-beta.435" />
<PackageVersion Include="System.CommandLine" Version="2.0.0-beta4.22272.1" />
Expand Down
1 change: 1 addition & 0 deletions NOTICE.md
Original file line number Diff line number Diff line change
Expand Up @@ -318,6 +318,7 @@ SOFTWARE.
- NLog.Extensions.Logging 5.0.4
- NLog.Schema 5.0.4
- ScipBe.Common.Office.OneNote 3.0.1
- SharpCompress 0.33.0
- StreamJsonRpc 2.14.24
- StyleCop.Analyzers 1.2.0-beta.435
- System.CommandLine 2.0.0-beta4.22272.1
Expand Down
27 changes: 27 additions & 0 deletions src/modules/peek/Peek.Common/Converters/SizeToStringConverter.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
// Copyright (c) Microsoft Corporation
// The Microsoft Corporation licenses this file to you under the MIT license.
// See the LICENSE file in the project root for more information.

using System;
using Microsoft.UI.Xaml.Data;
using Peek.Common.Helpers;

namespace Peek.Common.Converters
{
public class SizeToStringConverter : IValueConverter
{
public object Convert(object value, Type targetType, object parameter, string language)
{
if (value is long size)
{
return SizeHelper.GetHumanSize(size);
}
else
{
return value;
}
}

public object ConvertBack(object value, Type targetType, object parameter, string language) => throw new NotImplementedException();
}
}
21 changes: 21 additions & 0 deletions src/modules/peek/Peek.Common/Helpers/SizeHelper.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
// Copyright (c) Microsoft Corporation
// The Microsoft Corporation licenses this file to you under the MIT license.
// See the LICENSE file in the project root for more information.

namespace Peek.Common.Helpers
{
public static class SizeHelper
{
public static string GetHumanSize(long size)
{
return size switch
{
< 1024 => $"{size} bytes",
< 1024 * 1024 => $"{size / 1024.0:0.00} KB",
< 1024 * 1024 * 1024 => $"{size / 1024.0 / 1024.0:0.00} MB",
< 1024L * 1024 * 1024 * 1024 => $"{size / 1024.0 / 1024.0 / 1024.0:0.00} GB",
_ => $"{size / 1024.0 / 1024.0 / 1024.0 / 1024.0:0.00} TB",
};
}
}
}
137 changes: 137 additions & 0 deletions src/modules/peek/Peek.FilePreviewer/Controls/ArchiveControl.xaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,137 @@
<!-- Copyright (c) Microsoft Corporation. All rights reserved. -->
<!-- Licensed under the MIT License. See LICENSE in the project root for license information. -->

<UserControl
x:Class="Peek.FilePreviewer.Controls.ArchiveControl"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:local="using:Peek.FilePreviewer.Controls"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:models="using:Peek.FilePreviewer.Previewers.Archives.Models"
xmlns:converters="using:Peek.Common.Converters"
mc:Ignorable="d">
<UserControl.Resources>
<DataTemplate
x:Key="DirectoryTemplate"
x:DataType="models:ArchiveItem">
<TreeViewItem
AutomationProperties.Name="{x:Bind Name}"
ItemsSource="{x:Bind Children}"
IsExpanded="{x:Bind IsExpanded}">
<Grid ColumnSpacing="10">
<Grid.ColumnDefinitions>
<ColumnDefinition Width="auto" />
<ColumnDefinition Width="auto" />
</Grid.ColumnDefinitions>
<Image
Width="16"
Height="16"
Grid.Column="0"
Source="{x:Bind Icon}" />
<TextBlock
Grid.Column="1"
Text="{x:Bind Name}" />
</Grid>
</TreeViewItem>
</DataTemplate>

<DataTemplate
x:Key="FileTemplate"
x:DataType="models:ArchiveItem">
<TreeViewItem
AutomationProperties.Name="{x:Bind Name}">
<Grid ColumnSpacing="10">
<Grid.ColumnDefinitions>
<ColumnDefinition Width="auto" />
<ColumnDefinition Width="auto" />
<ColumnDefinition Width="auto" />
</Grid.ColumnDefinitions>
<Image
Width="16"
Height="16"
Grid.Column="0"
Source="{x:Bind Icon}" />
<TextBlock
Grid.Column="1"
Text="{x:Bind Name}" />
<TextBlock
Grid.Column="2"
Foreground="{ThemeResource TextFillColorSecondaryBrush}"
Text="{Binding Size, Converter={StaticResource SizeToStringConverter}}" />
</Grid>
</TreeViewItem>
</DataTemplate>

<models:ArchiveItemTemplateSelector
x:Key="ArchiveItemTemplateSelector"
DirectoryTemplate="{StaticResource DirectoryTemplate}"
FileTemplate="{StaticResource FileTemplate}" />

<converters:SizeToStringConverter x:Key="SizeToStringConverter" />
</UserControl.Resources>
<Grid>
<Grid.RowDefinitions>
<RowDefinition Height="*" />
<RowDefinition Height="auto" />
</Grid.RowDefinitions>
<ScrollViewer
Grid.Row="0"
HorizontalScrollBarVisibility="Auto">
<TreeView
x:Name="ArchivePreview"
ItemsSource="{x:Bind Source, Mode=OneWay}"
ItemTemplateSelector="{StaticResource ArchiveItemTemplateSelector}"
SelectionMode="None"
CanReorderItems="False"
CanDragItems="False" />
</ScrollViewer>
<Border
Grid.Row="1"
MinWidth="300"
Background="{ThemeResource CardBackgroundFillColorDefaultBrush}"
BorderBrush="{ThemeResource CardStrokeColorDefaultBrush}"
BorderThickness="1"
CornerRadius="8"
Margin="16"
HorizontalAlignment="Center">
<Grid
ColumnSpacing="16"
Padding="16">
<Grid.ColumnDefinitions>
<ColumnDefinition Width="*" />
<ColumnDefinition Width="auto" />
<ColumnDefinition Width="*" />
<ColumnDefinition Width="auto" />
<ColumnDefinition Width="*" />
</Grid.ColumnDefinitions>
<TextBlock
Grid.Column="0"
Text="{x:Bind DirectoryCount, Mode=OneWay}"
IsTextSelectionEnabled="True"
VerticalAlignment="Center"
TextWrapping="Wrap" />
<Border
Grid.Column="1"
BorderBrush="{ThemeResource TextFillColorPrimaryBrush}"
BorderThickness="0 0 1 0" />
<TextBlock
Grid.Column="2"
Text="{x:Bind FileCount, Mode=OneWay}"
IsTextSelectionEnabled="True"
VerticalAlignment="Center"
TextWrapping="Wrap" />
<Border
Grid.Column="3"
BorderBrush="{ThemeResource TextFillColorPrimaryBrush}"
BorderThickness="0 0 1 0" />
<TextBlock
Grid.Column="4"
Text="{x:Bind Size, Mode=OneWay}"
IsTextSelectionEnabled="True"
VerticalAlignment="Center"
TextWrapping="Wrap" />
</Grid>
</Border>
</Grid>
</UserControl>
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
// Copyright (c) Microsoft Corporation
// The Microsoft Corporation licenses this file to you under the MIT license.
// See the LICENSE file in the project root for more information.

using System.Collections.ObjectModel;
using Microsoft.UI.Xaml;
using Microsoft.UI.Xaml.Controls;
using Peek.FilePreviewer.Previewers;
using Peek.FilePreviewer.Previewers.Archives;
using Peek.FilePreviewer.Previewers.Archives.Models;

namespace Peek.FilePreviewer.Controls
{
public sealed partial class ArchiveControl : UserControl
{
public static readonly DependencyProperty SourceProperty = DependencyProperty.Register(
nameof(Source),
typeof(ObservableCollection<ArchiveItem>),
typeof(ArchivePreviewer),
new PropertyMetadata(null));

public static readonly DependencyProperty LoadingStateProperty = DependencyProperty.Register(
nameof(LoadingState),
typeof(PreviewState),
typeof(ArchivePreviewer),
new PropertyMetadata(PreviewState.Uninitialized));

public static readonly DependencyProperty DirectoryCountProperty = DependencyProperty.Register(
nameof(DirectoryCount),
typeof(string),
typeof(ArchivePreviewer),
new PropertyMetadata(null));

public static readonly DependencyProperty FileCountProperty = DependencyProperty.Register(
nameof(FileCount),
typeof(string),
typeof(ArchivePreviewer),
new PropertyMetadata(null));

public static readonly DependencyProperty SizeProperty = DependencyProperty.Register(
nameof(Size),
typeof(string),
typeof(ArchivePreviewer),
new PropertyMetadata(null));

public ObservableCollection<ArchiveItem>? Source
{
get { return (ObservableCollection<ArchiveItem>)GetValue(SourceProperty); }
set { SetValue(SourceProperty, value); }
}

public PreviewState? LoadingState
{
get { return (PreviewState)GetValue(LoadingStateProperty); }
set { SetValue(LoadingStateProperty, value); }
}

public string? DirectoryCount
{
get { return (string)GetValue(DirectoryCountProperty); }
set { SetValue(DirectoryCountProperty, value); }
}

public string? FileCount
{
get { return (string)GetValue(FileCountProperty); }
set { SetValue(FileCountProperty, value); }
}

public string? Size
{
get { return (string)GetValue(SizeProperty); }
set { SetValue(SizeProperty, value); }
}

public ArchiveControl()
{
this.InitializeComponent();
}
}
}
11 changes: 10 additions & 1 deletion src/modules/peek/Peek.FilePreviewer/FilePreview.xaml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<!-- Copyright (c) Microsoft Corporation and Contributors. -->
<!-- Copyright (c) Microsoft Corporation and Contributors. -->
<!-- Licensed under the MIT License. -->

<UserControl
Expand Down Expand Up @@ -51,6 +51,15 @@
Source="{x:Bind BrowserPreviewer.Preview, Mode=OneWay}"
Visibility="{x:Bind IsPreviewVisible(BrowserPreviewer, Previewer.State), Mode=OneWay, FallbackValue=Collapsed}" />

<controls:ArchiveControl
x:Name="ArchivePreview"
LoadingState="{x:Bind ArchivePreviewer.State, Mode=OneWay}"
Source="{x:Bind ArchivePreviewer.Tree, Mode=OneWay}"
FileCount="{x:Bind ArchivePreviewer.FileCountText, Mode=OneWay}"
DirectoryCount="{x:Bind ArchivePreviewer.DirectoryCountText, Mode=OneWay}"
Size="{x:Bind ArchivePreviewer.SizeText, Mode=OneWay}"
Visibility="{x:Bind IsPreviewVisible(ArchivePreviewer, Previewer.State), Mode=OneWay}" />

<controls:UnsupportedFilePreview
x:Name="UnsupportedFilePreview"
LoadingState="{x:Bind UnsupportedFilePreviewer.State, Mode=OneWay}"
Expand Down
7 changes: 6 additions & 1 deletion src/modules/peek/Peek.FilePreviewer/FilePreview.xaml.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright (c) Microsoft Corporation
// Copyright (c) Microsoft Corporation
// The Microsoft Corporation licenses this file to you under the MIT license.
// See the LICENSE file in the project root for more information.

Expand Down Expand Up @@ -49,6 +49,7 @@ public sealed partial class FilePreview : UserControl, IDisposable
[NotifyPropertyChangedFor(nameof(ImagePreviewer))]
[NotifyPropertyChangedFor(nameof(VideoPreviewer))]
[NotifyPropertyChangedFor(nameof(BrowserPreviewer))]
[NotifyPropertyChangedFor(nameof(ArchivePreviewer))]
[NotifyPropertyChangedFor(nameof(UnsupportedFilePreviewer))]

private IPreviewer? previewer;
Expand Down Expand Up @@ -94,6 +95,8 @@ private async void Previewer_PropertyChanged(object? sender, System.ComponentMod

public IBrowserPreviewer? BrowserPreviewer => Previewer as IBrowserPreviewer;

public IArchivePreviewer? ArchivePreviewer => Previewer as IArchivePreviewer;

public IUnsupportedFilePreviewer? UnsupportedFilePreviewer => Previewer as IUnsupportedFilePreviewer;

public IFileSystemItem Item
Expand Down Expand Up @@ -145,6 +148,7 @@ private async Task OnItemPropertyChanged()
ImagePreview.Visibility = Visibility.Collapsed;
VideoPreview.Visibility = Visibility.Collapsed;
BrowserPreview.Visibility = Visibility.Collapsed;
ArchivePreview.Visibility = Visibility.Collapsed;
UnsupportedFilePreview.Visibility = Visibility.Collapsed;
return;
}
Expand Down Expand Up @@ -207,6 +211,7 @@ partial void OnPreviewerChanging(IPreviewer? value)
VideoPreview.Source = null;

ImagePreview.Source = null;
ArchivePreview.Source = null;
BrowserPreview.Source = null;

if (Previewer != null)
Expand Down
Loading
Loading