mirror of
https://github.com/microsoft/PowerToys.git
synced 2026-04-09 20:57:22 +02:00
[Peek] Support for archives (#26839)
* support for archives in peek * fix spellcheck * horizontal scrolling * fix height * removed redundant helper
This commit is contained in:
committed by
GitHub
parent
67ce81ded8
commit
6ba8596d52
137
src/modules/peek/Peek.FilePreviewer/Controls/ArchiveControl.xaml
Normal file
137
src/modules/peek/Peek.FilePreviewer/Controls/ArchiveControl.xaml
Normal file
@@ -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>
|
||||
@@ -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();
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user