Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature: Added dimensions to tooltip when hovering over image files #15543

Merged
merged 8 commits into from
Jun 10, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 27 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 && ImageWidth > 0 && ImageHeight > 0)
0x5bfa marked this conversation as resolved.
Show resolved Hide resolved
tooltipBuilder.Append($"{Environment.NewLine}{"PropertyDimensions".GetLocalizedResource()}: {DimensionsDisplay}");
if (SyncStatusUI.LoadSyncStatus)
tooltipBuilder.Append($"{Environment.NewLine}{"syncStatusColumn/Header".GetLocalizedResource()}: {syncStatusUI.SyncStatusString}");

Expand Down Expand Up @@ -326,6 +328,30 @@ public ObservableCollection<FileProperty> ItemProperties
set => SetProperty(ref itemProperties, value);
}

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

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

public string DimensionsDisplay => IsImage ? $"{ImageWidth} \u00D7 {ImageHeight}" : string.Empty;
0x5bfa marked this conversation as resolved.
Show resolved Hide resolved

/// <summary>
/// Initializes a new instance of the <see cref="ListedItem" /> class.
/// </summary>
Expand Down Expand Up @@ -374,6 +400,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
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.App.Services.SizeProvider;
using Files.Shared.Helpers;
using System.IO;
Expand Down Expand Up @@ -260,6 +261,23 @@ CancellationToken cancellationToken
itemType = itemFileExtension.Trim('.') + " " + itemType;
}

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

bool itemThumbnailImgVis = false;
bool itemEmptyImgVis = true;

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