Skip to content

Added set as background button on toolbar when selecting image #7795

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

Merged
merged 13 commits into from
Jan 20, 2022
Merged
Show file tree
Hide file tree
Changes from all 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
1 change: 1 addition & 0 deletions src/Files/Files.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -190,6 +190,7 @@
<Compile Include="Filesystem\StorageItems\ZipStorageFile.cs" />
<Compile Include="Filesystem\StorageItems\ZipStorageFolder.cs" />
<Compile Include="Helpers\CommonPaths.cs" />
<Compile Include="Helpers\FileExtensionHelpers.cs" />
<Compile Include="Helpers\RegistryToJsonSettingsMerger.cs" />
<Compile Include="Helpers\ResourceHelpers.cs" />
<Compile Include="Helpers\FtpHelpers.cs" />
Expand Down
1 change: 0 additions & 1 deletion src/Files/Filesystem/ListedItem.cs
Original file line number Diff line number Diff line change
Expand Up @@ -414,7 +414,6 @@ public override string ToString()
public bool IsLinkItem => IsShortcutItem && ((ShortcutItem)this).IsUrl;
public bool IsFtpItem => this is FtpItem;
public bool IsZipItem => this is ZipItem;

public virtual bool IsExecutable => new[] { ".exe", ".bat", ".cmd" }.Contains(Path.GetExtension(ItemPath), StringComparer.OrdinalIgnoreCase);
public bool IsPinned => App.SidebarPinnedController.Model.FavoriteItems.Contains(itemPath);

Expand Down
60 changes: 60 additions & 0 deletions src/Files/Helpers/FileExtensionHelpers.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
using System;

namespace Files.Helpers
{
public static class FileExtensionHelpers
{
/// <summary>
/// Check if the file extension is an image file.
/// </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 IsImageFile(string fileExtensionToCheck)
{
if (string.IsNullOrEmpty(fileExtensionToCheck))
{
return false;
}

return fileExtensionToCheck.Equals(".png", StringComparison.OrdinalIgnoreCase) ||
fileExtensionToCheck.Equals(".jpg", StringComparison.OrdinalIgnoreCase) ||
fileExtensionToCheck.Equals(".bmp", StringComparison.OrdinalIgnoreCase) ||
fileExtensionToCheck.Equals(".jpeg", StringComparison.OrdinalIgnoreCase);
}

/// <summary>
/// Check if the file extension is a PowerShell script.
/// </summary>
/// <param name="fileExtensionToCheck">The file extension to check.</param>
/// <returns><c>true</c> if the fileExtensionToCheck is a PowerShell script;
/// otherwise, <c>false</c>.</returns>
public static bool IsPowerShellFile(string fileExtensionToCheck)
{
if (string.IsNullOrEmpty(fileExtensionToCheck))
{
return false;
}

return fileExtensionToCheck.Equals(".ps1", StringComparison.OrdinalIgnoreCase);
}

/// <summary>
/// Check if the file extension is a zip file.
/// </summary>
/// <param name="fileExtensionToCheck">The file extension to check.</param>
/// <returns><c>true</c> if the fileExtensionToCheck is a zip bundle file;
/// otherwise <c>false</c>.</returns>
public static bool IsZipFile(string fileExtensionToCheck)
{
if (string.IsNullOrEmpty(fileExtensionToCheck))
{
return false;
}

return fileExtensionToCheck.Equals(".zip", StringComparison.OrdinalIgnoreCase) ||
fileExtensionToCheck.Equals(".msix", StringComparison.OrdinalIgnoreCase) ||
fileExtensionToCheck.Equals(".msixbundle", StringComparison.OrdinalIgnoreCase);
}
}
}
3 changes: 3 additions & 0 deletions src/Files/Strings/en-US/Resources.resw
Original file line number Diff line number Diff line change
Expand Up @@ -2720,6 +2720,9 @@ We use App Center to track which settings are being used, find bugs, and fix cra
<data name="RunWithPowerShell" xml:space="preserve">
<value>Run with PowerShell</value>
</data>
<data name="SetAsBackground" xml:space="preserve">
<value>Set as desktop background</value>
</data>
<data name="SetFilesAsDefaultWarning" xml:space="preserve">
<value>Do not remove Files from your device without turning off this option. Not doing so will prevent you from opening File Explorer.</value>
</data>
Expand Down
11 changes: 11 additions & 0 deletions src/Files/UserControls/InnerNavigationToolbar.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -274,6 +274,17 @@
<FontIcon Glyph="&#xE756;" />
</AppBarButton.Icon>
</AppBarButton>
<AppBarButton
x:Name="SetAsBackgroundButton"
x:Load="{x:Bind ViewModel.IsImage, Mode=OneWay, FallbackValue=False}"
Command="{x:Bind ViewModel.SetAsBackgroundCommand, Mode=OneWay}"
Label="{helpers:ResourceString Name=SetAsBackground}"
LabelPosition="Default"
ToolTipService.ToolTip="{helpers:ResourceString Name=SetAsBackground}">
<AppBarButton.Icon>
<FontIcon Glyph="&#xE91B;" />
</AppBarButton.Icon>
</AppBarButton>
</CommandBar.PrimaryCommands>
</CommandBar>
<CommandBar
Expand Down
10 changes: 7 additions & 3 deletions src/Files/ViewModels/NavToolbarViewModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -805,6 +805,8 @@ public void SearchRegion_LostFocus(object sender, RoutedEventArgs e)

public ICommand RunWithPowerShellCommand { get; set; }

public ICommand SetAsBackgroundCommand { get; set; }

public async Task SetPathBoxDropDownFlyoutAsync(MenuFlyout flyout, PathBoxItem pathItem, IShellPage shellPage)
{
var nextPathItemTitle = PathComponents[PathComponents.IndexOf(pathItem) + 1].Title;
Expand Down Expand Up @@ -1089,23 +1091,25 @@ public List<ListedItem> SelectedItems
OnPropertyChanged(nameof(CanRename));
OnPropertyChanged(nameof(IsPowerShellScript));
OnPropertyChanged(nameof(CanViewProperties));
OnPropertyChanged(nameof(IsImage));
OnPropertyChanged(nameof(CanExtract));
OnPropertyChanged(nameof(ExtractToText));
OnPropertyChanged(nameof(HasAdditionnalAction));
}
}
}

public bool HasAdditionnalAction => InstanceViewModel.IsPageTypeRecycleBin || IsPowerShellScript || CanExtract;
public bool HasAdditionnalAction => InstanceViewModel.IsPageTypeRecycleBin || IsPowerShellScript || CanExtract || IsImage;

public bool CanCopy => SelectedItems is not null && SelectedItems.Any();
public bool CanShare => SelectedItems is not null && SelectedItems.Any() && DataTransferManager.IsSupported() && !SelectedItems.Any(x => (x.IsShortcutItem && !x.IsLinkItem) || x.IsHiddenItem || (x.PrimaryItemAttribute == StorageItemTypes.Folder && !x.IsZipItem));
public bool CanRename => SelectedItems is not null && SelectedItems.Count == 1;
public bool CanViewProperties => SelectedItems is not null && SelectedItems.Any();
public bool CanEmptyRecycleBin => InstanceViewModel.IsPageTypeRecycleBin && HasItem;
public bool CanExtract => SelectedItems is not null && SelectedItems.Any() && (SelectedItems.First().IsZipItem || SelectedItems.First().PrimaryItemAttribute == StorageItemTypes.File && new[] { ".zip", ".msix", ".msixbundle" }.Contains(SelectedItems.First().FileExtension, StringComparer.OrdinalIgnoreCase));
public bool CanExtract => SelectedItems is not null && SelectedItems.Any() && FileExtensionHelpers.IsZipFile(SelectedItems.First().FileExtension);
public string ExtractToText => SelectedItems is not null && SelectedItems.Any() ? string.Format("ExtractToChildFolder".GetLocalized() + "\\", Path.GetFileNameWithoutExtension(selectedItems.First().ItemName)) : "ExtractToChildFolder".GetLocalized();
public bool IsPowerShellScript => SelectedItems is not null && SelectedItems.Any() && SelectedItems.First().PrimaryItemAttribute == StorageItemTypes.File && new[] { ".ps1", }.Contains(SelectedItems.First().FileExtension, StringComparer.OrdinalIgnoreCase);
public bool IsPowerShellScript => SelectedItems is not null && SelectedItems.Any() && FileExtensionHelpers.IsPowerShellFile(SelectedItems.First().FileExtension);
public bool IsImage => SelectedItems is not null && SelectedItems.Any() && FileExtensionHelpers.IsImageFile(SelectedItems.First().FileExtension);

public void Dispose()
{
Expand Down
1 change: 1 addition & 0 deletions src/Files/Views/ModernShellPage.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -205,6 +205,7 @@ private void InitToolbarCommands()
NavToolbarViewModel.EmptyRecycleBinCommand = new RelayCommand(() => SlimContentPage?.CommandsViewModel.EmptyRecycleBinCommand.Execute(null));
NavToolbarViewModel.RunWithPowerShellCommand = new RelayCommand(async () => await Win32Helpers.InvokeWin32ComponentAsync("powershell", this, PathNormalization.NormalizePath(SlimContentPage?.SelectedItems.First().ItemPath)));
NavToolbarViewModel.PropertiesCommand = new RelayCommand(() => SlimContentPage?.CommandsViewModel.ShowPropertiesCommand.Execute(null));
NavToolbarViewModel.SetAsBackgroundCommand = new RelayCommand(() => SlimContentPage?.CommandsViewModel.SetAsDesktopBackgroundItemCommand.Execute(null));
NavToolbarViewModel.ExtractCommand = new RelayCommand(() => SlimContentPage?.CommandsViewModel.DecompressArchiveCommand.Execute(null));
NavToolbarViewModel.ExtractHereCommand = new RelayCommand(() => SlimContentPage?.CommandsViewModel.DecompressArchiveHereCommand.Execute(null));
NavToolbarViewModel.ExtractToCommand = new RelayCommand(() => SlimContentPage?.CommandsViewModel.DecompressArchiveToChildFolderCommand.Execute(null));
Expand Down