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: Add dimensions to hover on image file #14983

Open
wants to merge 16 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
28 changes: 28 additions & 0 deletions src/Files.App/Data/Items/ListedItem.cs
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(DimensionsDisplay));
}
}

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;
btomblinson marked this conversation as resolved.
Show resolved Hide resolved

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
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>
btomblinson marked this conversation as resolved.
Show resolved Hide resolved
</data>
<data name="SizeOnDiskLabel" xml:space="preserve">
<value>Size on disk:</value>
</data>
Expand Down
@@ -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))
btomblinson marked this conversation as resolved.
Show resolved Hide resolved
{
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