diff --git a/src/Files.App/Actions/Content/Background/BaseSetAsAction.cs b/src/Files.App/Actions/Content/Background/BaseSetAsAction.cs index a39a2d33fb05..d4239457c320 100644 --- a/src/Files.App/Actions/Content/Background/BaseSetAsAction.cs +++ b/src/Files.App/Actions/Content/Background/BaseSetAsAction.cs @@ -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?.IsCompatibleToSetAsWindowsWallpaper ?? false); public BaseSetAsAction() { diff --git a/src/Files.App/Actions/Content/ImageManipulation/BaseRotateAction.cs b/src/Files.App/Actions/Content/ImageManipulation/BaseRotateAction.cs index 0087b942f38b..eead57e36a66 100644 --- a/src/Files.App/Actions/Content/ImageManipulation/BaseRotateAction.cs +++ b/src/Files.App/Actions/Content/ImageManipulation/BaseRotateAction.cs @@ -21,7 +21,7 @@ internal abstract class BaseRotateAction : ObservableObject, IAction public bool IsExecutable => IsContextPageTypeAdaptedToCommand() && - (context.ShellPage?.SlimContentPage?.SelectedItemsPropertiesViewModel?.IsSelectedItemImage ?? false); + (context.ShellPage?.SlimContentPage?.SelectedItemsPropertiesViewModel?.IsCompatibleToSetAsWindowsWallpaper ?? false); public BaseRotateAction() { diff --git a/src/Files.App/Data/Factories/ContentPageContextFlyoutFactory.cs b/src/Files.App/Data/Factories/ContentPageContextFlyoutFactory.cs index fcbc75e0a82b..8f1861f451d7 100644 --- a/src/Files.App/Data/Factories/ContentPageContextFlyoutFactory.cs +++ b/src/Files.App/Data/Factories/ContentPageContextFlyoutFactory.cs @@ -405,7 +405,7 @@ public static List GetBaseItemMenuItems( new ContextMenuFlyoutItemViewModel() { Text = "BaseLayoutItemContextFlyoutSetAs/Text".GetLocalizedResource(), - ShowItem = itemsSelected && (selectedItemsPropertiesViewModel?.IsSelectedItemImage ?? false), + ShowItem = itemsSelected && (selectedItemsPropertiesViewModel?.IsCompatibleToSetAsWindowsWallpaper ?? false), ShowInSearchPage = true, Items = [ @@ -419,13 +419,13 @@ public static List GetBaseItemMenuItems( { IsVisible = !currentInstanceViewModel.IsPageTypeRecycleBin && !currentInstanceViewModel.IsPageTypeZipFolder - && (selectedItemsPropertiesViewModel?.IsSelectedItemImage ?? false) + && (selectedItemsPropertiesViewModel?.IsCompatibleToSetAsWindowsWallpaper ?? false) }.Build(), new ContextMenuFlyoutItemViewModelBuilder(Commands.RotateRight) { IsVisible = !currentInstanceViewModel.IsPageTypeRecycleBin && !currentInstanceViewModel.IsPageTypeZipFolder - && (selectedItemsPropertiesViewModel?.IsSelectedItemImage ?? false) + && (selectedItemsPropertiesViewModel?.IsCompatibleToSetAsWindowsWallpaper ?? false) }.Build(), new ContextMenuFlyoutItemViewModelBuilder(Commands.RunAsAdmin).Build(), new ContextMenuFlyoutItemViewModelBuilder(Commands.RunAsAnotherUser).Build(), diff --git a/src/Files.App/Data/Items/ListedItem.cs b/src/Files.App/Data/Items/ListedItem.cs index 136cece6e0ba..5486c5f904f6 100644 --- a/src/Files.App/Data/Items/ListedItem.cs +++ b/src/Files.App/Data/Items/ListedItem.cs @@ -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; @@ -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}"); @@ -326,6 +329,41 @@ public ObservableCollection ItemProperties set => SetProperty(ref itemProperties, value); } + public string DimensionsDisplay + { + 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; + } + } + /// /// Initializes a new instance of the class. /// diff --git a/src/Files.App/Data/Models/SelectedItemsPropertiesViewModel.cs b/src/Files.App/Data/Models/SelectedItemsPropertiesViewModel.cs index 8098777db929..68850b5f5037 100644 --- a/src/Files.App/Data/Models/SelectedItemsPropertiesViewModel.cs +++ b/src/Files.App/Data/Models/SelectedItemsPropertiesViewModel.cs @@ -530,7 +530,7 @@ public SelectedItemsPropertiesViewModel() } private bool isSelectedItemImage = false; - public bool IsSelectedItemImage + public bool IsCompatibleToSetAsWindowsWallpaper { get => isSelectedItemImage; set => SetProperty(ref isSelectedItemImage, value); @@ -546,7 +546,7 @@ public bool IsSelectedItemShortcut public void CheckAllFileExtensions(List itemExtensions) { // Checks if all the item extensions are image extensions of some kind. - IsSelectedItemImage = itemExtensions.TrueForAll(itemExtension => FileExtensionHelpers.IsImageFile(itemExtension)); + IsCompatibleToSetAsWindowsWallpaper = itemExtensions.TrueForAll(FileExtensionHelpers.IsCompatibleToSetAsWindowsWallpaper); // Checks if there is only one selected item and if it's a shortcut. IsSelectedItemShortcut = (itemExtensions.Count == 1) && (itemExtensions.TrueForAll(itemExtension => FileExtensionHelpers.IsShortcutFile(itemExtension))); } diff --git a/src/Files.Shared/Helpers/FileExtensionHelpers.cs b/src/Files.Shared/Helpers/FileExtensionHelpers.cs index 75606f5fc261..7aea2c521ab8 100644 --- a/src/Files.Shared/Helpers/FileExtensionHelpers.cs +++ b/src/Files.Shared/Helpers/FileExtensionHelpers.cs @@ -31,10 +31,20 @@ public static bool HasExtension(string? filePathToCheck, params string[] extensi /// The file extension to check. /// true if the fileExtensionToCheck is an image; otherwise, false. public static bool IsImageFile(string? fileExtensionToCheck) + { + return HasExtension(fileExtensionToCheck, ".png", ".bmp", ".jpg", ".jpeg", ".jfif", ".gif", ".tiff", ".tif", ".webp"); + } + + /// + /// Checks if the file can be set as wallpaper. + /// + /// The file extension to check. + /// true if the fileExtensionToCheck is an image; otherwise, false. + public static bool IsCompatibleToSetAsWindowsWallpaper(string? fileExtensionToCheck) { return HasExtension(fileExtensionToCheck, ".png", ".bmp", ".jpg", ".jpeg", ".jfif", ".gif", ".tiff", ".tif"); } - + /// /// Check if the file extension is an audio file. ///