-
Notifications
You must be signed in to change notification settings - Fork 6.8k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[Peek] Support for archives (#26839)
* support for archives in peek * fix spellcheck * horizontal scrolling * fix height * removed redundant helper
- Loading branch information
1 parent
67ce81d
commit 6ba8596
Showing
19 changed files
with
735 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
27 changes: 27 additions & 0 deletions
27
src/modules/peek/Peek.Common/Converters/BytesToStringConverter.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 BytesToStringConverter : IValueConverter | ||
{ | ||
public object Convert(object value, Type targetType, object parameter, string language) | ||
{ | ||
if (value is ulong size) | ||
{ | ||
return ReadableStringHelper.BytesToReadableString(size); | ||
} | ||
else | ||
{ | ||
return value; | ||
} | ||
} | ||
|
||
public object ConvertBack(object value, Type targetType, object parameter, string language) => throw new NotImplementedException(); | ||
} | ||
} |
137 changes: 137 additions & 0 deletions
137
src/modules/peek/Peek.FilePreviewer/Controls/ArchiveControl.xaml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 BytesToStringConverter}}" /> | ||
</Grid> | ||
</TreeViewItem> | ||
</DataTemplate> | ||
|
||
<models:ArchiveItemTemplateSelector | ||
x:Key="ArchiveItemTemplateSelector" | ||
DirectoryTemplate="{StaticResource DirectoryTemplate}" | ||
FileTemplate="{StaticResource FileTemplate}" /> | ||
|
||
<converters:BytesToStringConverter x:Key="BytesToStringConverter" /> | ||
</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> |
81 changes: 81 additions & 0 deletions
81
src/modules/peek/Peek.FilePreviewer/Controls/ArchiveControl.xaml.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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(); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.