Skip to content

Commit 774ed27

Browse files
authored
Only show the option to set an image as the background when one file is selected (#1370)
1 parent 56b9db5 commit 774ed27

File tree

5 files changed

+41
-41
lines changed

5 files changed

+41
-41
lines changed

Files/BaseLayout.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -415,7 +415,7 @@ public void RightClickItemContextMenu_Opening(object sender, object e)
415415
}
416416

417417
//check if the selected file is an image
418-
App.InteractionViewModel.CheckForImage();
418+
App.CurrentInstance.ContentPage.SelectedItemsPropertiesViewModel.CheckForImage();
419419
}
420420

421421
private void Page_Loaded(object sender, RoutedEventArgs e)

Files/View Models/InteractionViewModel.cs

Lines changed: 2 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -28,44 +28,14 @@ public bool LeftMarginLoaded
2828
{
2929
get => _LeftMarginLoaded;
3030
set => Set(ref _LeftMarginLoaded, value);
31-
}
32-
33-
private bool _IsSelectedItemImage = false;
34-
35-
public bool IsSelectedItemImage
36-
{
37-
get => _IsSelectedItemImage;
38-
set => Set(ref _IsSelectedItemImage, value);
39-
}
31+
}
4032

4133
private bool _isPasteEnabled = false;
4234

4335
public bool IsPasteEnabled
4436
{
4537
get => _isPasteEnabled;
4638
set => Set(ref _isPasteEnabled, value);
47-
}
48-
49-
public void CheckForImage()
50-
{
51-
//check if the selected item is an image file
52-
string ItemExtension = App.CurrentInstance.ContentPage.SelectedItem.FileExtension;
53-
54-
if (!string.IsNullOrEmpty(ItemExtension))
55-
{
56-
if (ItemExtension.Equals(".png", StringComparison.OrdinalIgnoreCase)
57-
|| ItemExtension.Equals(".jpg", StringComparison.OrdinalIgnoreCase)
58-
|| ItemExtension.Equals(".bmp", StringComparison.OrdinalIgnoreCase)
59-
|| ItemExtension.Equals(".jpeg", StringComparison.OrdinalIgnoreCase))
60-
{
61-
// Since item is an image, set the IsSelectedItemImage property to true
62-
App.InteractionViewModel.IsSelectedItemImage = true;
63-
return;
64-
}
65-
}
66-
67-
// Since item is not an image, folder or file without extension, set the IsSelectedItemImage property to false
68-
App.InteractionViewModel.IsSelectedItemImage = false;
69-
}
39+
}
7040
}
7141
}

Files/View Models/SelectedItemsPropertiesViewModel.cs

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -491,5 +491,35 @@ public bool IsItemSelected
491491
public SelectedItemsPropertiesViewModel()
492492
{
493493
}
494+
495+
private bool _IsSelectedItemImage = false;
496+
497+
public bool IsSelectedItemImage
498+
{
499+
get => _IsSelectedItemImage;
500+
set => Set(ref _IsSelectedItemImage, value);
501+
}
502+
503+
public void CheckForImage()
504+
{
505+
//check if the selected item is an image file
506+
string ItemExtension = App.CurrentInstance.ContentPage.SelectedItem.FileExtension;
507+
508+
if (!string.IsNullOrEmpty(ItemExtension) && SelectedItemsCount == "1 " + ResourceController.GetTranslation("ItemSelected/Text"))
509+
{
510+
if (ItemExtension.Equals(".png", StringComparison.OrdinalIgnoreCase)
511+
|| ItemExtension.Equals(".jpg", StringComparison.OrdinalIgnoreCase)
512+
|| ItemExtension.Equals(".bmp", StringComparison.OrdinalIgnoreCase)
513+
|| ItemExtension.Equals(".jpeg", StringComparison.OrdinalIgnoreCase))
514+
{
515+
// Since item is an image, set the IsSelectedItemImage property to true
516+
IsSelectedItemImage = true;
517+
return;
518+
}
519+
}
520+
521+
// Since item is not an image, folder or file without extension, set the IsSelectedItemImage property to false
522+
IsSelectedItemImage = false;
523+
}
494524
}
495525
}

Files/Views/LayoutModes/GenericFileBrowser.xaml

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,8 @@
66
xmlns:Interactivity="using:Microsoft.Xaml.Interactivity"
77
xmlns:behaviors="using:Microsoft.Toolkit.Uwp.UI.Behaviors"
88
xmlns:controls="using:Microsoft.Toolkit.Uwp.UI.Controls"
9-
xmlns:converters="using:Microsoft.Toolkit.Uwp.UI.Converters"
109
xmlns:controlsprimitives="using:Microsoft.Toolkit.Uwp.UI.Controls.Primitives"
10+
xmlns:converters="using:Microsoft.Toolkit.Uwp.UI.Converters"
1111
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
1212
xmlns:local="using:Files"
1313
xmlns:local2="using:Files.Filesystem"
@@ -21,7 +21,7 @@
2121

2222
<local:BaseLayout.Resources>
2323
<converters:BoolNegationConverter x:Key="BoolNegationConverter" />
24-
24+
2525
<MenuFlyout x:Key="BaseLayoutContextFlyout">
2626
<MenuFlyoutSubItem
2727
x:Name="SortByEmptySpace"
@@ -279,7 +279,7 @@
279279
x:Uid="BaseLayoutItemContextFlyoutSetAsDesktopBackground"
280280
Click="{x:Bind local:App.CurrentInstance.InteractionOperations.SetAsDesktopBackgroundItem_Click}"
281281
Text="Set as desktop background"
282-
Visibility="{x:Bind local:App.InteractionViewModel.IsSelectedItemImage, Mode=OneWay}">
282+
Visibility="{x:Bind SelectedItemsPropertiesViewModel.IsSelectedItemImage, Mode=OneWay}">
283283
<MenuFlyoutItem.Icon>
284284
<FontIcon Glyph="&#xE7F4;" />
285285
</MenuFlyoutItem.Icon>
@@ -289,7 +289,7 @@
289289
x:Uid="BaseLayoutItemContextFlyoutSetAsLockscreenBackground"
290290
Click="{x:Bind local:App.CurrentInstance.InteractionOperations.SetAsLockscreenBackgroundItem_Click}"
291291
Text="Set as lockscreen background"
292-
Visibility="{x:Bind local:App.InteractionViewModel.IsSelectedItemImage, Mode=OneWay}">
292+
Visibility="{x:Bind SelectedItemsPropertiesViewModel.IsSelectedItemImage, Mode=OneWay}">
293293
<MenuFlyoutItem.Icon>
294294
<FontIcon Glyph="&#xEE3F;" />
295295
</MenuFlyoutItem.Icon>

Files/Views/LayoutModes/GridViewBrowser.xaml

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,20 +4,20 @@
44
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
55
xmlns:Core="using:Microsoft.Xaml.Interactions.Core"
66
xmlns:Interactivity="using:Microsoft.Xaml.Interactivity"
7+
xmlns:converters="using:Microsoft.Toolkit.Uwp.UI.Converters"
78
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
89
xmlns:local="using:Files"
910
xmlns:local2="using:Files.Filesystem"
1011
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
1112
xmlns:muxc="using:Microsoft.UI.Xaml.Controls"
12-
xmlns:converters="using:Microsoft.Toolkit.Uwp.UI.Converters"
1313
Background="{ThemeResource ApplicationPageBackgroundThemeBrush}"
1414
NavigationCacheMode="Required"
1515
PointerPressed="GridViewBrowserViewer_PointerPressed"
1616
PointerWheelChanged="BaseLayout_PointerWheelChanged"
1717
mc:Ignorable="d">
1818
<local:BaseLayout.Resources>
1919
<converters:BoolNegationConverter x:Key="BoolNegationConverter" />
20-
20+
2121
<MenuFlyout x:Key="BaseLayoutContextFlyout">
2222
<MenuFlyoutSubItem
2323
x:Name="SortByEmptySpace"
@@ -275,7 +275,7 @@
275275
x:Uid="BaseLayoutItemContextFlyoutSetAsDesktopBackground"
276276
Click="{x:Bind local:App.CurrentInstance.InteractionOperations.SetAsDesktopBackgroundItem_Click}"
277277
Text="Set as desktop background"
278-
Visibility="{x:Bind local:App.InteractionViewModel.IsSelectedItemImage, Mode=OneWay}">
278+
Visibility="{x:Bind SelectedItemsPropertiesViewModel.IsSelectedItemImage, Mode=OneWay}">
279279
<MenuFlyoutItem.Icon>
280280
<FontIcon Glyph="&#xE7F4;" />
281281
</MenuFlyoutItem.Icon>
@@ -285,7 +285,7 @@
285285
x:Uid="BaseLayoutItemContextFlyoutSetAsLockscreenBackground"
286286
Click="{x:Bind local:App.CurrentInstance.InteractionOperations.SetAsLockscreenBackgroundItem_Click}"
287287
Text="Set as lockscreen background"
288-
Visibility="{x:Bind local:App.InteractionViewModel.IsSelectedItemImage, Mode=OneWay}">
288+
Visibility="{x:Bind SelectedItemsPropertiesViewModel.IsSelectedItemImage, Mode=OneWay}">
289289
<MenuFlyoutItem.Icon>
290290
<FontIcon Glyph="&#xEE3F;" />
291291
</MenuFlyoutItem.Icon>

0 commit comments

Comments
 (0)