Skip to content

Commit

Permalink
Add dimensions to hover on iamge file files-community#14975
Browse files Browse the repository at this point in the history
  • Loading branch information
btomblinson committed Mar 22, 2024
1 parent cb822b1 commit 5ab6bcf
Show file tree
Hide file tree
Showing 3 changed files with 44 additions and 1 deletion.
28 changes: 28 additions & 0 deletions src/Files.App/Data/Items/ListedItem.cs
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,8 @@ public string ItemTooltipText
tooltipBuilder.Append($"{"ToolTipDescriptionDate".GetLocalizedResource()} {ItemDateModified}");
if (!string.IsNullOrWhiteSpace(FileSize))
tooltipBuilder.Append($"{Environment.NewLine}{"SizeLabel".GetLocalizedResource()} {FileSize}");
if (IsImage)
tooltipBuilder.Append($"{Environment.NewLine}{"DimensionsLabel".GetLocalizedResource()} {DimensionsDisplay}");
if (SyncStatusUI.LoadSyncStatus)
tooltipBuilder.Append($"{Environment.NewLine}{"syncStatusColumn/Header".GetLocalizedResource()}: {syncStatusUI.SyncStatusString}");

Expand Down Expand Up @@ -268,6 +270,31 @@ public string FileSize

public long FileSizeBytes { get; set; }

private int imageWidth;
public int ImageWidth
{
get => imageWidth;
set
{
SetProperty(ref imageWidth, value);
OnPropertyChanged(nameof(FileSizeDisplay));
}
}

private int imageHeight;

public int ImageHeight
{
get => imageHeight;
set
{
SetProperty(ref imageHeight, value);
OnPropertyChanged(nameof(DimensionsDisplay));
}
}

public string DimensionsDisplay => IsImage ? $"{ImageWidth} x {ImageHeight}" : string.Empty;

public string ItemDateModified { get; private set; }

public string ItemDateCreated { get; private set; }
Expand Down Expand Up @@ -365,6 +392,7 @@ public override string ToString()
public bool IsArchive => this is ZipItem;
public bool IsAlternateStream => this is AlternateStreamItem;
public bool IsGitItem => this is GitItem;
public virtual bool IsImage => FileExtensionHelpers.IsImageFile(ItemPath);
public virtual bool IsExecutable => FileExtensionHelpers.IsExecutableFile(ItemPath);
public virtual bool IsScriptFile => FileExtensionHelpers.IsScriptFile(ItemPath);
public bool IsPinned => App.QuickAccessManager.Model.PinnedFolders.Contains(itemPath);
Expand Down
3 changes: 3 additions & 0 deletions src/Files.App/Strings/en-US/Resources.resw
Original file line number Diff line number Diff line change
Expand Up @@ -141,6 +141,9 @@
<data name="SizeLabel" xml:space="preserve">
<value>Size:</value>
</data>
<data name="DimensionsLabel" xml:space="preserve">
<value>Dimensions:</value>
</data>
<data name="SizeOnDiskLabel" xml:space="preserve">
<value>Size on disk:</value>
</data>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
// Copyright (c) 2024 Files Community
// Licensed under the MIT License. See the LICENSE.

using System.Drawing;
using Files.Core.Services.SizeProvider;
using Files.Shared.Helpers;
using System.IO;
Expand Down Expand Up @@ -261,6 +262,15 @@ CancellationToken cancellationToken
itemType = itemFileExtension.Trim('.') + " " + itemType;
}

int imageHeight = 0, imageWidth = 0;
if (FileExtensionHelpers.IsImageFile(itemFileExtension))
{
await using FileStream fileStream = new FileStream(itemPath, FileMode.Open, FileAccess.Read, FileShare.Read);
using Image image = Image.FromStream(fileStream, false, false);
imageHeight = image.Height;
imageWidth = image.Width;
}

bool itemThumbnailImgVis = false;
bool itemEmptyImgVis = true;

Expand Down Expand Up @@ -397,7 +407,9 @@ CancellationToken cancellationToken
ItemType = itemType,
ItemPath = itemPath,
FileSize = itemSize,
FileSizeBytes = itemSizeBytes
FileSizeBytes = itemSizeBytes,
ImageHeight = imageHeight,
ImageWidth = imageWidth
};
}
}
Expand Down

0 comments on commit 5ab6bcf

Please sign in to comment.