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 6 commits
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
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ internal abstract class BaseSetAsAction : ObservableObject, IAction
context.ShellPage is not null &&
context.PageType != ContentPageTypes.RecycleBin &&
context.PageType != ContentPageTypes.ZipFolder &&
(context.ShellPage?.SlimContentPage?.SelectedItemsPropertiesViewModel?.IsSelectedItemImage ?? false);
(context.ShellPage?.SlimContentPage?.SelectedItemsPropertiesViewModel?.CanSelectedItemBeManipulated ?? false);

public BaseSetAsAction()
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ internal abstract class BaseRotateAction : ObservableObject, IAction

public bool IsExecutable =>
IsContextPageTypeAdaptedToCommand() &&
(context.ShellPage?.SlimContentPage?.SelectedItemsPropertiesViewModel?.IsSelectedItemImage ?? false);
(context.ShellPage?.SlimContentPage?.SelectedItemsPropertiesViewModel?.CanSelectedItemBeManipulated ?? false);

public BaseRotateAction()
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -405,7 +405,7 @@ public static List<ContextMenuFlyoutItemViewModel> GetBaseItemMenuItems(
new ContextMenuFlyoutItemViewModel()
{
Text = "BaseLayoutItemContextFlyoutSetAs/Text".GetLocalizedResource(),
ShowItem = itemsSelected && (selectedItemsPropertiesViewModel?.IsSelectedItemImage ?? false),
ShowItem = itemsSelected && (selectedItemsPropertiesViewModel?.CanSelectedItemBeManipulated ?? false),
yaira2 marked this conversation as resolved.
Show resolved Hide resolved
ShowInSearchPage = true,
Items =
[
Expand All @@ -419,13 +419,13 @@ public static List<ContextMenuFlyoutItemViewModel> GetBaseItemMenuItems(
{
IsVisible = !currentInstanceViewModel.IsPageTypeRecycleBin
&& !currentInstanceViewModel.IsPageTypeZipFolder
&& (selectedItemsPropertiesViewModel?.IsSelectedItemImage ?? false)
&& (selectedItemsPropertiesViewModel?.CanSelectedItemBeManipulated ?? false)
}.Build(),
new ContextMenuFlyoutItemViewModelBuilder(Commands.RotateRight)
{
IsVisible = !currentInstanceViewModel.IsPageTypeRecycleBin
&& !currentInstanceViewModel.IsPageTypeZipFolder
&& (selectedItemsPropertiesViewModel?.IsSelectedItemImage ?? false)
&& (selectedItemsPropertiesViewModel?.CanSelectedItemBeManipulated ?? false)
}.Build(),
new ContextMenuFlyoutItemViewModelBuilder(Commands.RunAsAdmin).Build(),
new ContextMenuFlyoutItemViewModelBuilder(Commands.RunAsAnotherUser).Build(),
Expand Down
38 changes: 38 additions & 0 deletions src/Files.App/Data/Items/ListedItem.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
using FluentFTP;
using Microsoft.UI.Xaml;
using Microsoft.UI.Xaml.Media.Imaging;
using System.Drawing;
using System.IO;
using System.Text;
using Windows.Storage;
Expand Down Expand Up @@ -45,6 +46,8 @@ public string ItemTooltipText
tooltipBuilder.Append($"{"ToolTipDescriptionDate".GetLocalizedResource()} {ItemDateModified}");
if (!string.IsNullOrWhiteSpace(FileSize))
tooltipBuilder.Append($"{Environment.NewLine}{"SizeLabel".GetLocalizedResource()} {FileSize}");
if (!string.IsNullOrWhiteSpace(DimensionsDisplay))
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 +329,41 @@ public ObservableCollection<FileProperty> ItemProperties
set => SetProperty(ref itemProperties, value);
}

public string DimensionsDisplay
Copy link
Member

@yaira2 yaira2 Jun 26, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I discovered this is fetching as soon as the location is opened, it should only be fetched when hovered for the first time.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This also causes #15202

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'll be commenting this out because the feature is low priority, but it'll be nice to add back once these issues are resolved.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@hishitetsu The first implementer said this way is the fastest however speaking of this should we use WinRT API to retrieve the dimentions of images?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think the tooltip value can be empty at first, since the tooltip value is updated each time the pointer is entered.

private void Grid_PointerEntered(object sender, PointerRoutedEventArgs e)
{
if (sender is FrameworkElement element && element.DataContext is ListedItem item)
// Reassign values to update date display
ToolTipService.SetToolTip(element, item.ItemTooltipText);
}

@hishitetsu The first implementer said this way is the fastest however speaking of this should we use WinRT API to retrieve the dimentions of images?

I don't know if using the WinRT API will solve any problems.

{
get
{
int imageHeight = 0;
int imageWidth = 0;

var isImageFile = FileExtensionHelpers.IsImageFile(FileExtension);
if (isImageFile)
{
try
{
// TODO: Consider to use 'System.Kind' instead.
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 { }
}


return
isImageFile &&
imageWidth > 0 &&
imageHeight > 0
? $"{imageWidth} \u00D7 {imageHeight}"
: string.Empty;
}
}

/// <summary>
/// Initializes a new instance of the <see cref="ListedItem" /> class.
/// </summary>
Expand Down
4 changes: 2 additions & 2 deletions src/Files.App/Data/Models/SelectedItemsPropertiesViewModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -530,7 +530,7 @@ public SelectedItemsPropertiesViewModel()
}

private bool isSelectedItemImage = false;
public bool IsSelectedItemImage
public bool CanSelectedItemBeManipulated
{
get => isSelectedItemImage;
set => SetProperty(ref isSelectedItemImage, value);
Expand All @@ -546,7 +546,7 @@ public bool IsSelectedItemShortcut
public void CheckAllFileExtensions(List<string> itemExtensions)
{
// Checks if all the item extensions are image extensions of some kind.
IsSelectedItemImage = itemExtensions.TrueForAll(itemExtension => FileExtensionHelpers.IsImageFile(itemExtension));
CanSelectedItemBeManipulated = itemExtensions.TrueForAll(FileExtensionHelpers.IsManipulateableImageFile);
// Checks if there is only one selected item and if it's a shortcut.
IsSelectedItemShortcut = (itemExtensions.Count == 1) && (itemExtensions.TrueForAll(itemExtension => FileExtensionHelpers.IsShortcutFile(itemExtension)));
}
Expand Down
12 changes: 11 additions & 1 deletion src/Files.Shared/Helpers/FileExtensionHelpers.cs
Original file line number Diff line number Diff line change
Expand Up @@ -31,10 +31,20 @@ public static bool HasExtension(string? filePathToCheck, params string[] extensi
/// <param name="fileExtensionToCheck">The file extension to check.</param>
/// <returns><c>true</c> if the fileExtensionToCheck is an image; otherwise, <c>false</c>.</returns>
public static bool IsImageFile(string? fileExtensionToCheck)
{
return HasExtension(fileExtensionToCheck, ".png", ".bmp", ".jpg", ".jpeg", ".jfif", ".gif", ".tiff", ".tif", ".webp");
}

/// <summary>
/// Checks if the file can be set as wallpaper.
/// </summary>
/// <param name="fileExtensionToCheck">The file extension to check.</param>
/// <returns><c>true</c> if the fileExtensionToCheck is an image; otherwise, <c>false</c>.</returns>
public static bool IsManipulateableImageFile(string? fileExtensionToCheck)
yaira2 marked this conversation as resolved.
Show resolved Hide resolved
{
return HasExtension(fileExtensionToCheck, ".png", ".bmp", ".jpg", ".jpeg", ".jfif", ".gif", ".tiff", ".tif");
}

/// <summary>
/// Check if the file extension is an audio file.
/// </summary>
Expand Down
Loading