Skip to content

Commit 96abbcd

Browse files
Merge branch 'main' into UI_To_Create_Edit_Delete_Tags
2 parents f5bcadd + 206beeb commit 96abbcd

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

59 files changed

+118039
-117715
lines changed

src/Files.App/BaseLayout.cs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -539,7 +539,7 @@ public async void BaseContextFlyout_Opening(object? sender, object e)
539539
BaseContextMenuFlyout.PrimaryCommands.Clear();
540540
BaseContextMenuFlyout.SecondaryCommands.Clear();
541541
var (primaryElements, secondaryElements) = ItemModelListToContextFlyoutHelper.GetAppBarItemsFromModel(items);
542-
AddCloseHandler(primaryElements, secondaryElements);
542+
AddCloseHandler(BaseContextMenuFlyout, primaryElements, secondaryElements);
543543
primaryElements.ForEach(i => BaseContextMenuFlyout.PrimaryCommands.Add(i));
544544
secondaryElements.OfType<FrameworkElement>().ForEach(i => i.MinWidth = Constants.UI.ContextMenuItemsMaxWidth); // Set menu min width
545545
secondaryElements.ForEach(i => BaseContextMenuFlyout.SecondaryCommands.Add(i));
@@ -589,7 +589,7 @@ private async Task LoadMenuItemsAsync()
589589
ItemContextMenuFlyout.PrimaryCommands.Clear();
590590
ItemContextMenuFlyout.SecondaryCommands.Clear();
591591
var (primaryElements, secondaryElements) = ItemModelListToContextFlyoutHelper.GetAppBarItemsFromModel(items);
592-
AddCloseHandler(primaryElements, secondaryElements);
592+
AddCloseHandler(ItemContextMenuFlyout, primaryElements, secondaryElements);
593593
primaryElements.ForEach(i => ItemContextMenuFlyout.PrimaryCommands.Add(i));
594594
secondaryElements.OfType<FrameworkElement>().ForEach(i => i.MinWidth = Constants.UI.ContextMenuItemsMaxWidth); // Set menu min width
595595
secondaryElements.ForEach(i => ItemContextMenuFlyout.SecondaryCommands.Add(i));
@@ -605,10 +605,10 @@ private async Task LoadMenuItemsAsync()
605605
}
606606
}
607607

608-
private void AddCloseHandler(IList<ICommandBarElement> primaryElements, IList<ICommandBarElement> secondaryElements)
608+
private void AddCloseHandler(CommandBarFlyout flyout, IList<ICommandBarElement> primaryElements, IList<ICommandBarElement> secondaryElements)
609609
{
610610
// Workaround for WinUI (#5508)
611-
var closeHandler = new RoutedEventHandler((s, e) => ItemContextMenuFlyout.Hide());
611+
var closeHandler = new RoutedEventHandler((s, e) => flyout.Hide());
612612

613613
primaryElements
614614
.OfType<AppBarButton>()

src/Files.App/Filesystem/RecentItem.cs

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,17 @@
11
using CommunityToolkit.Mvvm.ComponentModel;
22
using Files.App.Filesystem.StorageItems;
33
using Files.App.Helpers;
4+
using Files.App.UserControls.Widgets;
45
using Files.Shared;
56
using Microsoft.UI.Xaml.Media.Imaging;
67
using System;
7-
using System.IO;
88
using System.Threading.Tasks;
99
using Windows.Storage;
1010
using Windows.Storage.FileProperties;
1111

1212
namespace Files.App.Filesystem
1313
{
14-
public class RecentItem : ObservableObject, IEquatable<RecentItem>
14+
public class RecentItem : WidgetCardItem, IEquatable<RecentItem>
1515
{
1616
private BitmapImage _fileImg;
1717
public BitmapImage FileImg
@@ -29,6 +29,7 @@ public BitmapImage FileImg
2929
public bool IsFile { get => Type == StorageItemTypes.File; }
3030
public DateTime LastModified { get; set; }
3131
public byte[] PIDL { get; set; }
32+
public string Path { get => RecentPath; }
3233

3334
public RecentItem()
3435
{
@@ -118,8 +119,8 @@ public bool Equals(RecentItem other)
118119
*/
119120
private static string NameOrPathWithoutExtension(string nameOrPath)
120121
{
121-
string strippedExtension = Path.GetFileNameWithoutExtension(nameOrPath);
122-
return string.IsNullOrEmpty(strippedExtension) ? Path.GetFileName(nameOrPath) : strippedExtension;
122+
string strippedExtension = System.IO.Path.GetFileNameWithoutExtension(nameOrPath);
123+
return string.IsNullOrEmpty(strippedExtension) ? System.IO.Path.GetFileName(nameOrPath) : strippedExtension;
123124
}
124125
}
125126
}

src/Files.App/Filesystem/StorageItems/ZipStorageFolder.cs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,9 @@ public static bool IsZipPath(string path, bool includeRoot = true)
7070
return false;
7171
}
7272
marker += ext.Length;
73-
return (marker == path.Length && includeRoot) || (marker < path.Length && path[marker] is '\\');
73+
// If IO.Path.Exists returns true, it is not a zip path but a normal directory path that contains ".zip".
74+
return (marker == path.Length && includeRoot && !IO.Path.Exists(path + "\\"))
75+
|| (marker < path.Length && path[marker] is '\\' && !IO.Path.Exists(path));
7476
}
7577

7678
public async Task<long> GetUncompressedSize()

src/Files.App/Helpers/ShellContextMenuHelper.cs

Lines changed: 82 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,19 @@
1+
using CommunityToolkit.Mvvm.DependencyInjection;
12
using CommunityToolkit.Mvvm.Input;
3+
using CommunityToolkit.WinUI.UI;
24
using Files.App.Extensions;
35
using Files.App.Filesystem;
6+
using Files.App.Helpers.ContextFlyouts;
7+
using Files.App.ServicesImplementation.Settings;
48
using Files.App.Shell;
59
using Files.App.ViewModels;
610
using Files.Backend.Helpers;
11+
using Files.Backend.Services.Settings;
712
using Files.Shared;
13+
using Files.Shared.Extensions;
14+
using Microsoft.UI.Input;
15+
using Microsoft.UI.Xaml;
16+
using Microsoft.UI.Xaml.Controls;
817
using Microsoft.UI.Xaml.Media.Imaging;
918
using System;
1019
using System.Collections.Generic;
@@ -13,11 +22,14 @@
1322
using System.Threading;
1423
using System.Threading.Tasks;
1524
using Vanara.PInvoke;
25+
using Windows.System;
26+
using Windows.UI.Core;
1627

1728
namespace Files.App.Helpers
1829
{
1930
public static class ShellContextmenuHelper
2031
{
32+
public static IUserSettingsService UserSettingsService { get; } = Ioc.Default.GetRequiredService<IUserSettingsService>();
2133
public static async Task<List<ContextMenuFlyoutItemViewModel>> GetShellContextmenuAsync(bool showOpenMenu, bool shiftPressed, string workingDirectory, List<ListedItem>? selectedItems, CancellationToken cancellationToken)
2234
{
2335
bool IsItemSelected = selectedItems?.Count > 0;
@@ -210,5 +222,75 @@ void InstallFont(string path, bool asAdmin)
210222
flyout.Remove(item);
211223
return item?.Items;
212224
}
225+
226+
public static async Task LoadShellMenuItems(string path, CommandBarFlyout itemContextMenuFlyout, ContextMenuOptions options = null, bool showOpenWithMenu = false)
227+
{
228+
try
229+
{
230+
if (options is not null)
231+
{
232+
if (options.ShowEmptyRecycleBin)
233+
{
234+
var emptyRecycleBinItem = itemContextMenuFlyout.SecondaryCommands.FirstOrDefault(x => x is AppBarButton appBarButton && (appBarButton.Tag as string) == "EmptyRecycleBin") as AppBarButton;
235+
if (emptyRecycleBinItem is not null)
236+
{
237+
var binHasItems = RecycleBinHelpers.RecycleBinHasItems();
238+
emptyRecycleBinItem.IsEnabled = binHasItems;
239+
}
240+
}
241+
242+
if (!options.IsLocationItem)
243+
return;
244+
}
245+
246+
var shiftPressed = InputKeyboardSource.GetKeyStateForCurrentThread(VirtualKey.Shift).HasFlag(CoreVirtualKeyStates.Down);
247+
var shellMenuItems = await ContextFlyoutItemHelper.GetItemContextShellCommandsAsync(
248+
workingDir: null,
249+
new List<ListedItem>() { new ListedItem(null) { ItemPath = path } },
250+
shiftPressed: shiftPressed,
251+
showOpenMenu: false,
252+
default);
253+
254+
if (showOpenWithMenu)
255+
{
256+
var openWithItem = shellMenuItems.Where(x => (x.Tag as Win32ContextMenuItem)?.ID == 100).ToList().FirstOrDefault();
257+
var (_, openWithItems) = ItemModelListToContextFlyoutHelper.GetAppBarItemsFromModel(new List<ContextMenuFlyoutItemViewModel>() { openWithItem });
258+
itemContextMenuFlyout.SecondaryCommands.Insert(0, openWithItems.FirstOrDefault());
259+
}
260+
261+
if (!UserSettingsService.AppearanceSettingsService.MoveShellExtensionsToSubMenu)
262+
{
263+
var (_, secondaryElements) = ItemModelListToContextFlyoutHelper.GetAppBarItemsFromModel(shellMenuItems);
264+
if (!secondaryElements.Any())
265+
return;
266+
267+
var openedPopups = Microsoft.UI.Xaml.Media.VisualTreeHelper.GetOpenPopups(App.Window);
268+
var secondaryMenu = openedPopups.FirstOrDefault(popup => popup.Name == "OverflowPopup");
269+
270+
var itemsControl = secondaryMenu?.Child.FindDescendant<ItemsControl>();
271+
if (itemsControl is not null)
272+
{
273+
var maxWidth = itemsControl.ActualWidth - Constants.UI.ContextMenuLabelMargin;
274+
secondaryElements.OfType<FrameworkElement>()
275+
.ForEach(x => x.MaxWidth = maxWidth); // Set items max width to current menu width (#5555)
276+
}
277+
278+
itemContextMenuFlyout.SecondaryCommands.Add(new AppBarSeparator());
279+
secondaryElements.ForEach(i => itemContextMenuFlyout.SecondaryCommands.Add(i));
280+
}
281+
else
282+
{
283+
var overflowItems = ItemModelListToContextFlyoutHelper.GetMenuFlyoutItemsFromModel(shellMenuItems);
284+
if (itemContextMenuFlyout.SecondaryCommands.FirstOrDefault(x => x is AppBarButton appBarButton && (appBarButton.Tag as string) == "ItemOverflow") is not AppBarButton overflowItem)
285+
return;
286+
287+
var flyoutItems = (overflowItem.Flyout as MenuFlyout)?.Items;
288+
if (flyoutItems is not null)
289+
overflowItems.ForEach(i => flyoutItems.Add(i));
290+
overflowItem.Visibility = overflowItems.Any() ? Visibility.Visible : Visibility.Collapsed;
291+
}
292+
}
293+
catch { }
294+
}
213295
}
214296
}

src/Files.App/ServicesImplementation/QuickAccessService.cs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,9 @@
11
using Files.App.Shell;
22
using Files.App.UserControls.Widgets;
3+
using Files.Sdk.Storage.LocatableStorage;
34
using Files.Shared;
45
using Files.Shared.Extensions;
6+
using Microsoft.UI.Xaml.Shapes;
57
using System;
68
using System.Collections.Generic;
79
using System.IO;
@@ -52,5 +54,10 @@ await SafetyExtensions.IgnoreExceptions(async () => {
5254

5355
App.QuickAccessManager.UpdateQuickAccessWidget?.Invoke(this, new ModifyQuickAccessEventArgs(folderPaths, false));
5456
}
57+
58+
public bool IsItemPinned(ILocatableFolder folder)
59+
{
60+
return App.QuickAccessManager.Model.FavoriteItems.Contains(folder.Path);
61+
}
5562
}
5663
}

0 commit comments

Comments
 (0)