Skip to content

Commit

Permalink
Feature: View storage information for drives in the Details Pane (#16513
Browse files Browse the repository at this point in the history
)
  • Loading branch information
ferrariofilippo authored Nov 27, 2024
1 parent 5e5e4f3 commit aa39885
Show file tree
Hide file tree
Showing 7 changed files with 170 additions and 12 deletions.
1 change: 0 additions & 1 deletion src/Files.App.Controls/Storage/StorageBar/StorageBar.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@
<Setter Property="TrackBarHeight" Value="{ThemeResource StorageBarTrackHeight}" />
<Setter Property="CornerRadius" Value="{ThemeResource StorageBarCornerRadius}" />
<Setter Property="VerticalAlignment" Value="Center" />
<Setter Property="Width" Value="240" />
<Setter Property="Minimum" Value="0" />
<Setter Property="Maximum" Value="100" />
<Setter Property="MinWidth" Value="32" />
Expand Down
7 changes: 6 additions & 1 deletion src/Files.App/Data/Enums/PreviewPaneStates.cs
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,11 @@ public enum PreviewPaneStates
/// <summary>
/// Loading preview status.
/// </summary>
LoadingPreview
LoadingPreview,

/// <summary>
/// Drive preview and details available status.
/// </summary>
DriveStorageDetailsAvailable,
}
}
23 changes: 20 additions & 3 deletions src/Files.App/Data/Items/DriveItem.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
// Licensed under the MIT License. See the LICENSE.

using Files.App.Controls;
using Files.App.Storage.Storables;
using Microsoft.UI.Xaml;
using Microsoft.UI.Xaml.Controls;
using Microsoft.UI.Xaml.Media.Imaging;
Expand Down Expand Up @@ -116,15 +115,27 @@ public bool ShowDriveDetails
private DriveType type;
public DriveType Type
{
get => type; set
get => type;
set
{
type = value;

if (value is DriveType.Network or DriveType.CloudDrive)
ToolTip = Text;

OnPropertyChanged(nameof(TypeText));
}
}

public string TypeText => string.Format("DriveType{0}", Type).GetLocalizedResource();

private string filesystem = string.Empty;
public string Filesystem
{
get => filesystem;
set => SetProperty(ref filesystem, value);
}

private string text;
public string Text
{
Expand Down Expand Up @@ -267,7 +278,7 @@ public async Task UpdatePropertiesAsync()
{
try
{
var properties = await Root.Properties.RetrievePropertiesAsync(["System.FreeSpace", "System.Capacity"])
var properties = await Root.Properties.RetrievePropertiesAsync(["System.FreeSpace", "System.Capacity", "System.Volume.FileSystem"])
.AsTask().WithTimeoutAsync(TimeSpan.FromSeconds(5));

if (properties is not null && properties["System.Capacity"] is not null && properties["System.FreeSpace"] is not null)
Expand All @@ -287,12 +298,18 @@ public async Task UpdatePropertiesAsync()
MaxSpace = SpaceUsed = FreeSpace = ByteSize.FromBytes(0);
}

if (properties is not null && properties["System.Volume.FileSystem"] is not null)
Filesystem = (string)properties["System.Volume.FileSystem"];
else
Filesystem = string.Empty;

OnPropertyChanged(nameof(ShowDriveDetails));
}
catch (Exception)
{
SpaceText = "Unknown".GetLocalizedResource();
MaxSpace = SpaceUsed = FreeSpace = ByteSize.FromBytes(0);
Filesystem = string.Empty;

OnPropertyChanged(nameof(ShowDriveDetails));
}
Expand Down
6 changes: 6 additions & 0 deletions src/Files.App/Strings/en-US/Resources.resw
Original file line number Diff line number Diff line change
Expand Up @@ -4004,4 +4004,10 @@
<data name="ManageTags" xml:space="preserve">
<value>Manage tags</value>
</data>
<data name="Available" xml:space="preserve">
<value>Available</value>
</data>
<data name="Total" xml:space="preserve">
<value>Total</value>
</data>
</root>
103 changes: 103 additions & 0 deletions src/Files.App/UserControls/Pane/InfoPane.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -238,6 +238,92 @@
TextAlignment="Center"
TextWrapping="Wrap"
Visibility="Collapsed" />

<!-- Drive Details -->
<TextBlock
x:Name="DriveFormatAndTypeTextBlock"
Margin="12,12,12,24"
HorizontalAlignment="Center"
IsTextSelectionEnabled="True"
Style="{ThemeResource BodyTextBlockStyle}"
TextAlignment="Center"
TextWrapping="Wrap"
Visibility="Collapsed">
<Run Text="{x:Bind ViewModel.SelectedDriveItem.Filesystem, Mode=OneWay}" />
<Run Foreground="{ThemeResource TextFillColorTertiaryBrush}" Text="{x:Bind ViewModel.SelectedDriveItem.TypeText, Mode=OneWay}" />
</TextBlock>

<TextBlock
x:Name="UsedSpaceTextBlock"
HorizontalAlignment="Center"
Foreground="{ThemeResource SystemAccentColor}"
IsTextSelectionEnabled="True"
Style="{ThemeResource SubtitleTextBlockStyle}"
Text="{x:Bind ViewModel.SelectedDriveItem.UsedSpaceText, Mode=OneWay}"
TextAlignment="Center"
TextWrapping="Wrap"
Visibility="Collapsed" />
<controls:StorageBar
x:Name="DriveSpaceProgressBar"
Margin="8,8,8,8"
HorizontalAlignment="Stretch"
TrackBarHeight="4"
ValueBarHeight="8"
Visibility="Collapsed"
Value="{x:Bind ViewModel.SelectedDriveItem.PercentageUsed, Mode=OneWay}" />
<Grid
x:Name="DriveSpaceGrid"
Margin="12,0,12,24"
Visibility="Collapsed">
<Grid.RowDefinitions>
<RowDefinition />
<RowDefinition />
</Grid.RowDefinitions>

<Grid.ColumnDefinitions>
<ColumnDefinition Width="Auto" />
<ColumnDefinition />
<ColumnDefinition Width="Auto" />
</Grid.ColumnDefinitions>

<TextBlock
x:Name="AvailableSpaceTextBlock"
FontFamily="{ThemeResource ContentControlThemeFontFamily}"
FontSize="14"
IsTextSelectionEnabled="True"
Style="{ThemeResource BodyStrongTextBlockStyle}"
Text="{x:Bind ViewModel.SelectedDriveItem.FreeSpaceText, Mode=OneWay}"
TextAlignment="Left"
TextWrapping="Wrap" />
<TextBlock
x:Name="TotalDriveSpaceTextBlock"
Grid.Column="2"
Foreground="{ThemeResource TextFillColorTertiaryBrush}"
IsTextSelectionEnabled="True"
Style="{ThemeResource BodyStrongTextBlockStyle}"
Text="{x:Bind ViewModel.SelectedDriveItem.MaxSpaceText, Mode=OneWay}"
TextAlignment="Right"
TextWrapping="Wrap" />
<TextBlock
x:Name="AvailableSpaceLabel"
Grid.Row="1"
HorizontalAlignment="Left"
Style="{ThemeResource BodyTextBlockStyle}"
Text="{helpers:ResourceString Name=Available}"
TextAlignment="Left"
TextWrapping="Wrap" />
<TextBlock
x:Name="TotalDriveSpaceLabel"
Grid.Row="1"
Grid.Column="2"
HorizontalAlignment="Right"
Foreground="{ThemeResource TextFillColorTertiaryBrush}"
Style="{ThemeResource BodyTextBlockStyle}"
Text="{helpers:ResourceString Name=Total}"
TextAlignment="Right"
TextWrapping="Wrap" />
</Grid>

<ItemsControl
x:Name="FileDetailsRepeater"
Margin="12,12,12,0"
Expand Down Expand Up @@ -467,6 +553,23 @@
<Setter Target="PreviewLoadingIndicator.Visibility" Value="Visible" />
</VisualState.Setters>
</VisualState>
<VisualState x:Name="DriveStorageDetailsAvailable">
<VisualState.StateTriggers>
<triggers:IsEqualStateTrigger Value="{x:Bind ViewModel.PreviewPaneState, Mode=OneWay}" To="5" />
</VisualState.StateTriggers>
<VisualState.Setters>
<Setter Target="PreviewErrorText.Visibility" Value="Collapsed" />
<Setter Target="FileDetailsRepeater.Visibility" Value="Collapsed" />
<Setter Target="DetailsTagsList.Visibility" Value="Collapsed" />
<Setter Target="DetailsOpenProperties.Visibility" Value="Visible" />
<Setter Target="PreviewControlPresenter.Visibility" Value="Visible" />
<Setter Target="DetailsListHeader.Visibility" Value="Visible" />
<Setter Target="DriveFormatAndTypeTextBlock.Visibility" Value="Visible" />
<Setter Target="UsedSpaceTextBlock.Visibility" Value="Visible" />
<Setter Target="DriveSpaceProgressBar.Visibility" Value="Visible" />
<Setter Target="DriveSpaceGrid.Visibility" Value="Visible" />
</VisualState.Setters>
</VisualState>
</VisualStateGroup>
<VisualStateGroup>
<VisualState>
Expand Down
33 changes: 29 additions & 4 deletions src/Files.App/ViewModels/UserControls/InfoPaneViewModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@ namespace Files.App.ViewModels.UserControls
public sealed class InfoPaneViewModel : ObservableObject, IDisposable
{
private IInfoPaneSettingsService infoPaneSettingsService { get; } = Ioc.Default.GetRequiredService<IInfoPaneSettingsService>();
private IGeneralSettingsService generalSettingsService { get; } = Ioc.Default.GetRequiredService<IGeneralSettingsService>();
private IContentPageContext contentPageContext { get; } = Ioc.Default.GetRequiredService<IContentPageContext>();
private DrivesViewModel drivesViewModel { get; } = Ioc.Default.GetRequiredService<DrivesViewModel>();

private CancellationTokenSource loadCancellationTokenSource;

Expand Down Expand Up @@ -50,6 +50,7 @@ public ListedItem? SelectedItem
if (SetProperty(ref selectedItem, value))
{
UpdateTagsItems();
SetDriveItem();
OnPropertyChanged(nameof(LoadTagsList));

if (value is not null)
Expand All @@ -58,6 +59,19 @@ public ListedItem? SelectedItem
}
}

/// <summary>
/// Current selected drive if any.
/// </summary>
private DriveItem? selectedDriveItem;
public DriveItem? SelectedDriveItem
{
get => selectedDriveItem;
set
{
SetProperty(ref selectedDriveItem, value);
}
}

/// <summary>
/// Enum indicating whether to show the details or preview tab
/// </summary>
Expand Down Expand Up @@ -177,7 +191,7 @@ private async Task LoadPreviewControlAsync(CancellationToken token, bool downloa
if (control is not null)
{
PreviewPaneContent = control;
PreviewPaneState = PreviewPaneStates.PreviewAndDetailsAvailable;
PreviewPaneState = SelectedItem.IsDriveRoot ? PreviewPaneStates.DriveStorageDetailsAvailable : PreviewPaneStates.PreviewAndDetailsAvailable;
return;
}

Expand All @@ -190,7 +204,7 @@ private async Task LoadPreviewControlAsync(CancellationToken token, bool downloa
return;

PreviewPaneContent = control;
PreviewPaneState = PreviewPaneStates.PreviewAndDetailsAvailable;
PreviewPaneState = SelectedItem.IsDriveRoot ? PreviewPaneStates.DriveStorageDetailsAvailable : PreviewPaneStates.PreviewAndDetailsAvailable;
}

private async Task<UserControl> GetBuiltInPreviewControlAsync(ListedItem item, bool downloadItem)
Expand Down Expand Up @@ -449,7 +463,7 @@ private async Task LoadBasicPreviewAsync()
await basicModel.LoadAsync();

PreviewPaneContent = new BasicPreview(basicModel);
PreviewPaneState = PreviewPaneStates.PreviewAndDetailsAvailable;
PreviewPaneState = SelectedItem.IsDriveRoot ? PreviewPaneStates.DriveStorageDetailsAvailable : PreviewPaneStates.PreviewAndDetailsAvailable;
}
catch (Exception ex)
{
Expand All @@ -474,6 +488,17 @@ private void UpdateTagsItems()
Items.Add(new FlyoutItem(new Files.App.UserControls.Menus.FileTagsContextMenu(new List<ListedItem>() { SelectedItem })));
}

private void SetDriveItem()
{
if (!(selectedItem?.IsDriveRoot ?? false))
{
selectedDriveItem = null;
return;
}

SelectedDriveItem = drivesViewModel.Drives.FirstOrDefault(drive => drive.Path == selectedItem.ItemPath) as DriveItem;
}

public void Dispose()
{

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,11 @@
using Files.App.ViewModels.Properties;
using Microsoft.UI.Xaml.Media.Imaging;
using System.IO;
using Windows.Storage.FileProperties;

namespace Files.App.ViewModels.Previews
{
public sealed class FolderPreviewViewModel
{
private static readonly IDateTimeFormatter dateTimeFormatter = Ioc.Default.GetRequiredService<IDateTimeFormatter>();

public ListedItem Item { get; }

public BitmapImage Thumbnail { get; set; } = new();
Expand Down Expand Up @@ -39,6 +36,12 @@ private async Task LoadPreviewAndDetailsAsync()
if (result is not null)
Thumbnail = await result.ToBitmapAsync();

// If the selected item is the root of a drive (e.g. "C:\")
// we do not need to load the properties below, since they will not be shown.
// Drive properties will be obtained through the DrivesViewModel service.
if (Item.IsDriveRoot)
return;

var info = await Folder.GetBasicPropertiesAsync();

Item.FileDetails =
Expand Down

0 comments on commit aa39885

Please sign in to comment.