mirror of
https://github.com/microsoft/PowerToys.git
synced 2026-04-09 20:57:22 +02:00
[Peek]Add Drive Previewer (#31476)
* Add drives previewer to Peek * minor fixes * fix spellcheck
This commit is contained in:
committed by
GitHub
parent
92c85630a9
commit
7c91dada64
114
src/modules/peek/Peek.FilePreviewer/Controls/DriveControl.xaml
Normal file
114
src/modules/peek/Peek.FilePreviewer/Controls/DriveControl.xaml
Normal file
@@ -0,0 +1,114 @@
|
||||
<!-- 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.DriveControl"
|
||||
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="using:Peek.FilePreviewer.Controls"
|
||||
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
|
||||
SizeChanged="SizeChanged_Handler"
|
||||
mc:Ignorable="d">
|
||||
<Grid
|
||||
MaxWidth="1000"
|
||||
Margin="48"
|
||||
VerticalAlignment="Center"
|
||||
ColumnSpacing="16"
|
||||
RowSpacing="16">
|
||||
<Grid.RowDefinitions>
|
||||
<RowDefinition Height="auto" />
|
||||
<RowDefinition Height="auto" />
|
||||
</Grid.RowDefinitions>
|
||||
<Grid.ColumnDefinitions>
|
||||
<ColumnDefinition Width="auto" />
|
||||
<ColumnDefinition Width="*" />
|
||||
</Grid.ColumnDefinitions>
|
||||
<Image
|
||||
Grid.Row="0"
|
||||
Grid.Column="0"
|
||||
Width="180"
|
||||
Height="180"
|
||||
HorizontalAlignment="Right"
|
||||
VerticalAlignment="Bottom"
|
||||
Source="{x:Bind Source.IconPreview, Mode=OneWay}" />
|
||||
<StackPanel
|
||||
Grid.Row="0"
|
||||
Grid.Column="1"
|
||||
HorizontalAlignment="Left"
|
||||
VerticalAlignment="Center"
|
||||
Spacing="5">
|
||||
<TextBlock
|
||||
FontSize="26"
|
||||
FontWeight="SemiBold"
|
||||
Text="{x:Bind Source.Name, Mode=OneWay}"
|
||||
TextTrimming="CharacterEllipsis">
|
||||
<ToolTipService.ToolTip>
|
||||
<ToolTip Content="{x:Bind Source.Name, Mode=OneWay}" />
|
||||
</ToolTipService.ToolTip>
|
||||
</TextBlock>
|
||||
<TextBlock Text="{x:Bind FormatType(Source.Type), Mode=OneWay}">
|
||||
<ToolTipService.ToolTip>
|
||||
<ToolTip Content="{x:Bind FormatType(Source.Type), Mode=OneWay}" />
|
||||
</ToolTipService.ToolTip>
|
||||
</TextBlock>
|
||||
<TextBlock Text="{x:Bind FormatFileSystem(Source.FileSystem), Mode=OneWay}">
|
||||
<ToolTipService.ToolTip>
|
||||
<ToolTip Content="{x:Bind FormatFileSystem(Source.FileSystem), Mode=OneWay}" />
|
||||
</ToolTipService.ToolTip>
|
||||
</TextBlock>
|
||||
<TextBlock Text="{x:Bind FormatCapacity(Source.Capacity), Mode=OneWay}">
|
||||
<ToolTipService.ToolTip>
|
||||
<ToolTip Content="{x:Bind FormatCapacity(Source.Capacity), Mode=OneWay}" />
|
||||
</ToolTipService.ToolTip>
|
||||
</TextBlock>
|
||||
</StackPanel>
|
||||
|
||||
<Grid
|
||||
Grid.Row="1"
|
||||
Grid.ColumnSpan="2"
|
||||
RowSpacing="5">
|
||||
<Grid.RowDefinitions>
|
||||
<RowDefinition Height="auto" />
|
||||
<RowDefinition Height="auto" />
|
||||
</Grid.RowDefinitions>
|
||||
<Grid.ColumnDefinitions>
|
||||
<ColumnDefinition Width="auto" />
|
||||
<ColumnDefinition Width="*" />
|
||||
</Grid.ColumnDefinitions>
|
||||
<Border
|
||||
x:Name="CapacityBar"
|
||||
Grid.Row="0"
|
||||
Grid.ColumnSpan="2"
|
||||
Height="20"
|
||||
Background="{ThemeResource AccentFillColorDisabledBrush}"
|
||||
CornerRadius="10" />
|
||||
|
||||
<Border
|
||||
Grid.Row="0"
|
||||
Grid.ColumnSpan="2"
|
||||
Height="20"
|
||||
Background="{ThemeResource AccentFillColorDefaultBrush}"
|
||||
CornerRadius="10">
|
||||
<Border.Clip>
|
||||
<RectangleGeometry Rect="{x:Bind SpaceBarClip, Mode=OneWay}" />
|
||||
</Border.Clip>
|
||||
</Border>
|
||||
|
||||
<TextBlock
|
||||
Grid.Row="1"
|
||||
Grid.Column="0"
|
||||
HorizontalAlignment="Left"
|
||||
VerticalAlignment="Top"
|
||||
Foreground="{ThemeResource TextFillColorSecondaryBrush}"
|
||||
Text="{x:Bind FormatUsedSpace(Source.UsedSpace), Mode=OneWay}" />
|
||||
<TextBlock
|
||||
Grid.Row="1"
|
||||
Grid.Column="1"
|
||||
HorizontalAlignment="Right"
|
||||
VerticalAlignment="Top"
|
||||
Foreground="{ThemeResource TextFillColorSecondaryBrush}"
|
||||
Text="{x:Bind FormatFreeSpace(Source.FreeSpace), Mode=OneWay}" />
|
||||
</Grid>
|
||||
</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.Globalization;
|
||||
using CommunityToolkit.Mvvm.ComponentModel;
|
||||
using Microsoft.UI.Xaml;
|
||||
using Microsoft.UI.Xaml.Controls;
|
||||
using Peek.Common.Helpers;
|
||||
using Peek.FilePreviewer.Previewers.Drive.Models;
|
||||
using Windows.Foundation;
|
||||
|
||||
namespace Peek.FilePreviewer.Controls
|
||||
{
|
||||
[INotifyPropertyChanged]
|
||||
public sealed partial class DriveControl : UserControl
|
||||
{
|
||||
[ObservableProperty]
|
||||
private Rect _spaceBarClip;
|
||||
|
||||
public static readonly DependencyProperty SourceProperty = DependencyProperty.Register(
|
||||
nameof(Source),
|
||||
typeof(DrivePreviewData),
|
||||
typeof(DriveControl),
|
||||
new PropertyMetadata(null, new PropertyChangedCallback((d, e) => ((DriveControl)d).UpdateSpaceBar())));
|
||||
|
||||
public DrivePreviewData? Source
|
||||
{
|
||||
get { return (DrivePreviewData)GetValue(SourceProperty); }
|
||||
set { SetValue(SourceProperty, value); }
|
||||
}
|
||||
|
||||
public DriveControl()
|
||||
{
|
||||
this.InitializeComponent();
|
||||
}
|
||||
|
||||
public string FormatType(string type)
|
||||
{
|
||||
return string.Format(CultureInfo.CurrentCulture, ResourceLoaderInstance.ResourceLoader.GetString("Drive_Type"), type);
|
||||
}
|
||||
|
||||
public string FormatFileSystem(string fileSystem)
|
||||
{
|
||||
return string.Format(CultureInfo.CurrentCulture, ResourceLoaderInstance.ResourceLoader.GetString("Drive_FileSystem"), fileSystem);
|
||||
}
|
||||
|
||||
public string FormatCapacity(ulong capacity)
|
||||
{
|
||||
return string.Format(CultureInfo.CurrentCulture, ResourceLoaderInstance.ResourceLoader.GetString("Drive_Capacity"), ReadableStringHelper.BytesToReadableString(capacity, false));
|
||||
}
|
||||
|
||||
public string FormatFreeSpace(ulong freeSpace)
|
||||
{
|
||||
return string.Format(CultureInfo.CurrentCulture, ResourceLoaderInstance.ResourceLoader.GetString("Drive_FreeSpace"), ReadableStringHelper.BytesToReadableString(freeSpace, false));
|
||||
}
|
||||
|
||||
public string FormatUsedSpace(ulong usedSpace)
|
||||
{
|
||||
return string.Format(CultureInfo.CurrentCulture, ResourceLoaderInstance.ResourceLoader.GetString("Drive_UsedSpace"), ReadableStringHelper.BytesToReadableString(usedSpace, false));
|
||||
}
|
||||
|
||||
private void SizeChanged_Handler(object sender, SizeChangedEventArgs e)
|
||||
{
|
||||
UpdateSpaceBar();
|
||||
}
|
||||
|
||||
private void UpdateSpaceBar()
|
||||
{
|
||||
if (Source != null && Source.PercentageUsage > 0)
|
||||
{
|
||||
var usedWidth = CapacityBar.ActualWidth * Source!.PercentageUsage;
|
||||
SpaceBarClip = new(0, 0, usedWidth, 20);
|
||||
}
|
||||
else
|
||||
{
|
||||
SpaceBarClip = new(0, 0, 0, 0);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user