diff --git a/src/Files.Uwp/DataModels/NavigationControlItems/DriveItem.cs b/src/Files.Uwp/DataModels/NavigationControlItems/DriveItem.cs index e37727b12bba..8002a7fa3e28 100644 --- a/src/Files.Uwp/DataModels/NavigationControlItems/DriveItem.cs +++ b/src/Files.Uwp/DataModels/NavigationControlItems/DriveItem.cs @@ -99,6 +99,8 @@ public string SpaceText public SectionType Section { get; set; } + public ContextMenuOptions MenuOptions { get; set; } + private float percentageUsed = 0.0f; public float PercentageUsed @@ -143,6 +145,13 @@ public static async Task CreateFromPropertiesAsync(StorageFolder root await CoreApplication.MainView.DispatcherQueue.EnqueueAsync(async () => await item.SetBitmapImage(imageStream)); item.Text = root.DisplayName; item.Type = type; + item.MenuOptions = new ContextMenuOptions + { + IsLocationItem = true, + ShowEjectDevice = item.IsRemovable, + ShowShellItems = true, + ShowProperties = true + }; item.Path = string.IsNullOrEmpty(root.Path) ? $"\\\\?\\{root.Name}\\" : root.Path; item.DeviceID = deviceId; item.Root = root; diff --git a/src/Files.Uwp/DataModels/NavigationControlItems/FileTagItem.cs b/src/Files.Uwp/DataModels/NavigationControlItems/FileTagItem.cs index ae9aef1e7bf1..dcc8cbdbc9f3 100644 --- a/src/Files.Uwp/DataModels/NavigationControlItems/FileTagItem.cs +++ b/src/Files.Uwp/DataModels/NavigationControlItems/FileTagItem.cs @@ -23,6 +23,8 @@ public string Path public SectionType Section { get; set; } + public ContextMenuOptions MenuOptions { get; set; } + public NavigationControlItemType ItemType => NavigationControlItemType.FileTag; public int CompareTo(INavigationControlItem other) => Text.CompareTo(other.Text); diff --git a/src/Files.Uwp/DataModels/NavigationControlItems/INavigationControlItem.cs b/src/Files.Uwp/DataModels/NavigationControlItems/INavigationControlItem.cs index 178893924ce4..7cc38f237312 100644 --- a/src/Files.Uwp/DataModels/NavigationControlItems/INavigationControlItem.cs +++ b/src/Files.Uwp/DataModels/NavigationControlItems/INavigationControlItem.cs @@ -13,6 +13,8 @@ public interface INavigationControlItem : IComparable public string HoverDisplayText { get; } public NavigationControlItemType ItemType { get; } + + public ContextMenuOptions MenuOptions { get; } } public enum NavigationControlItemType @@ -36,4 +38,25 @@ public enum SectionType WSL, FileTag } + + public class ContextMenuOptions + { + public bool IsLibrariesHeader { get; set; } + + public bool ShowHideSection { get; set; } + + public bool IsLocationItem { get; set; } + + public bool ShowUnpinItem { get; set; } + + public bool IsItemMovable { get; set; } + + public bool ShowProperties { get; set; } + + public bool ShowEmptyRecycleBin { get; set; } + + public bool ShowEjectDevice { get; set; } + + public bool ShowShellItems { get; set; } + } } \ No newline at end of file diff --git a/src/Files.Uwp/DataModels/NavigationControlItems/LocationItem.cs b/src/Files.Uwp/DataModels/NavigationControlItems/LocationItem.cs index 58965984acba..8387fd3c5ce2 100644 --- a/src/Files.Uwp/DataModels/NavigationControlItems/LocationItem.cs +++ b/src/Files.Uwp/DataModels/NavigationControlItems/LocationItem.cs @@ -59,6 +59,8 @@ public bool IsExpanded public SectionType Section { get; set; } + public ContextMenuOptions MenuOptions { get; set; } + public int CompareTo(INavigationControlItem other) => Text.CompareTo(other.Text); } } \ No newline at end of file diff --git a/src/Files.Uwp/DataModels/NavigationControlItems/WslDistroItem.cs b/src/Files.Uwp/DataModels/NavigationControlItems/WslDistroItem.cs index d1de04d9b72b..154e2133c0b4 100644 --- a/src/Files.Uwp/DataModels/NavigationControlItems/WslDistroItem.cs +++ b/src/Files.Uwp/DataModels/NavigationControlItems/WslDistroItem.cs @@ -27,6 +27,8 @@ public string Path public SectionType Section { get; private set; } + public ContextMenuOptions MenuOptions { get; set; } + public int CompareTo(INavigationControlItem other) => Text.CompareTo(other.Text); } } \ No newline at end of file diff --git a/src/Files.Uwp/DataModels/SidebarPinnedModel.cs b/src/Files.Uwp/DataModels/SidebarPinnedModel.cs index 346709b34a02..d2360e63cfa7 100644 --- a/src/Files.Uwp/DataModels/SidebarPinnedModel.cs +++ b/src/Files.Uwp/DataModels/SidebarPinnedModel.cs @@ -122,6 +122,13 @@ public async Task ShowHideRecycleBinItemAsync(bool show) { Text = ApplicationData.Current.LocalSettings.Values.Get("RecycleBin_Title", "Recycle Bin"), IsDefaultLocation = true, + MenuOptions = new ContextMenuOptions + { + IsLocationItem = true, + ShowUnpinItem = true, + ShowShellItems = true, + ShowEmptyRecycleBin = true + }, Icon = await CoreApplication.MainView.DispatcherQueue.EnqueueAsync(() => UIHelpers.GetIconResource(Constants.ImageRes.RecycleBin)), Path = CommonPaths.RecycleBinPath }; @@ -266,6 +273,14 @@ public async Task AddItemToSidebarAsync(string path) Font = MainViewModel.FontName, Path = path, Section = SectionType.Favorites, + MenuOptions = new ContextMenuOptions + { + IsLocationItem = true, + ShowProperties = true, + ShowUnpinItem = true, + ShowShellItems = true, + IsItemMovable = true + }, IsDefaultLocation = false, Text = res.Result?.DisplayName ?? Path.GetFileName(path.TrimEnd('\\')) }; @@ -337,6 +352,10 @@ public async Task AddAllItemsToSidebar() { Text = "Home".GetLocalized(), Section = SectionType.Home, + MenuOptions = new ContextMenuOptions + { + IsLocationItem = true + }, Font = MainViewModel.FontName, IsDefaultLocation = true, Icon = await CoreApplication.MainView.DispatcherQueue.EnqueueAsync(() => new BitmapImage(new Uri("ms-appx:///Assets/FluentIcons/Home.png"))), @@ -347,6 +366,10 @@ public async Task AddAllItemsToSidebar() { Text = "SidebarFavorites".GetLocalized(), Section = SectionType.Favorites, + MenuOptions = new ContextMenuOptions + { + ShowHideSection = true + }, SelectsOnInvoked = false, Icon = await CoreApplication.MainView.DispatcherQueue.EnqueueAsync(() => UIHelpers.GetIconResource(Constants.Shell32.QuickAccess)), Font = MainViewModel.FontName, diff --git a/src/Files.Uwp/Filesystem/CloudDrivesManager.cs b/src/Files.Uwp/Filesystem/CloudDrivesManager.cs index 31be662d9b91..8bda52a4ca87 100644 --- a/src/Files.Uwp/Filesystem/CloudDrivesManager.cs +++ b/src/Files.Uwp/Filesystem/CloudDrivesManager.cs @@ -51,9 +51,15 @@ public async Task EnumerateDrivesAsync() { Text = provider.Name, Path = provider.SyncFolder, - Type = DriveType.CloudDrive, + Type = DriveType.CloudDrive + }; + cloudProviderItem.MenuOptions = new ContextMenuOptions + { + IsLocationItem = true, + ShowEjectDevice = cloudProviderItem.IsRemovable, + ShowShellItems = true, + ShowProperties = true }; - var iconData = await FileThumbnailHelper.LoadIconWithoutOverlayAsync(provider.SyncFolder, 24); if (iconData != null) { @@ -111,6 +117,10 @@ await CoreApplication.MainView.CoreWindow.Dispatcher.RunAsync(CoreDispatcherPrio { Text = "SidebarCloudDrives".GetLocalized(), Section = SectionType.CloudDrives, + MenuOptions = new ContextMenuOptions + { + ShowHideSection = true + }, SelectsOnInvoked = false, Icon = new Windows.UI.Xaml.Media.Imaging.BitmapImage(new Uri("ms-appx:///Assets/FluentIcons/CloudDrive.png")), ChildItems = new BulkConcurrentObservableCollection() diff --git a/src/Files.Uwp/Filesystem/Drives.cs b/src/Files.Uwp/Filesystem/Drives.cs index 024217c286d9..f89f319106a7 100644 --- a/src/Files.Uwp/Filesystem/Drives.cs +++ b/src/Files.Uwp/Filesystem/Drives.cs @@ -143,6 +143,10 @@ await CoreApplication.MainView.CoreWindow.Dispatcher.RunAsync(CoreDispatcherPrio { Text = "Drives".GetLocalized(), Section = SectionType.Drives, + MenuOptions = new ContextMenuOptions + { + ShowHideSection = true + }, SelectsOnInvoked = false, Icon = await UIHelpers.GetIconResource(Constants.ImageRes.ThisPC), ChildItems = new BulkConcurrentObservableCollection() diff --git a/src/Files.Uwp/Filesystem/FileTagsManager.cs b/src/Files.Uwp/Filesystem/FileTagsManager.cs index 82c88046a8d6..3cc573610440 100644 --- a/src/Files.Uwp/Filesystem/FileTagsManager.cs +++ b/src/Files.Uwp/Filesystem/FileTagsManager.cs @@ -55,6 +55,10 @@ await CoreApplication.MainView.CoreWindow.Dispatcher.RunAsync(CoreDispatcherPrio { Text = "FileTags".GetLocalized(), Section = SectionType.FileTag, + MenuOptions = new ContextMenuOptions + { + ShowHideSection = true + }, SelectsOnInvoked = false, Icon = new Windows.UI.Xaml.Media.Imaging.BitmapImage(new Uri("ms-appx:///Assets/FluentIcons/FileTags.png")), ChildItems = new BulkConcurrentObservableCollection() @@ -80,7 +84,11 @@ await CoreApplication.MainView.CoreWindow.Dispatcher.RunAsync(CoreDispatcherPrio { Text = tag.TagName, Path = $"tag:{tag.TagName}", - FileTag = tag + FileTag = tag, + MenuOptions = new ContextMenuOptions + { + IsLocationItem = true + } }); } } diff --git a/src/Files.Uwp/Filesystem/LibraryLocationItem.cs b/src/Files.Uwp/Filesystem/LibraryLocationItem.cs index 97d9659ffe1f..b3148d08595f 100644 --- a/src/Files.Uwp/Filesystem/LibraryLocationItem.cs +++ b/src/Files.Uwp/Filesystem/LibraryLocationItem.cs @@ -16,11 +16,19 @@ public class LibraryLocationItem : LocationItem public LibraryLocationItem(ShellLibraryItem shellLibrary) { Section = SectionType.Library; + MenuOptions = new ContextMenuOptions + { + IsLocationItem = true, + ShowProperties = true, + ShowShellItems = true, + ShowUnpinItem = !shellLibrary.IsPinned + }; Text = shellLibrary.DisplayName; Path = shellLibrary.FullPath; DefaultSaveFolder = shellLibrary.DefaultSaveFolder; Folders = shellLibrary.Folders == null ? null : new ReadOnlyCollection(shellLibrary.Folders); IsDefaultLocation = shellLibrary.IsPinned; + } public override bool Equals(object obj) diff --git a/src/Files.Uwp/Filesystem/LibraryManager.cs b/src/Files.Uwp/Filesystem/LibraryManager.cs index 8ae9ea2de815..fa7a55ae2462 100644 --- a/src/Files.Uwp/Filesystem/LibraryManager.cs +++ b/src/Files.Uwp/Filesystem/LibraryManager.cs @@ -197,6 +197,11 @@ await CoreApplication.MainView.CoreWindow.Dispatcher.RunAsync(CoreDispatcherPrio { Text = "SidebarLibraries".GetLocalized(), Section = SectionType.Library, + MenuOptions = new ContextMenuOptions + { + IsLibrariesHeader = true, + ShowHideSection = true + }, SelectsOnInvoked = false, Icon = await UIHelpers.GetIconResource(Constants.ImageRes.Libraries), ChildItems = new BulkConcurrentObservableCollection() diff --git a/src/Files.Uwp/Filesystem/NetworkDrivesManager.cs b/src/Files.Uwp/Filesystem/NetworkDrivesManager.cs index 2213f50efc50..e261be9f90fb 100644 --- a/src/Files.Uwp/Filesystem/NetworkDrivesManager.cs +++ b/src/Files.Uwp/Filesystem/NetworkDrivesManager.cs @@ -46,6 +46,13 @@ public NetworkDrivesManager() Type = DriveType.Network, ItemType = NavigationControlItemType.Drive }; + networkItem.MenuOptions = new ContextMenuOptions + { + IsLocationItem = true, + ShowShellItems = true, + ShowEjectDevice = networkItem.IsRemovable, + ShowProperties = true + }; lock (drivesList) { drivesList.Add(networkItem); @@ -80,6 +87,13 @@ public async Task EnumerateDrivesAsync() Type = DriveType.Network, ItemType = NavigationControlItemType.Drive }; + networkItem.MenuOptions = new ContextMenuOptions + { + IsLocationItem = true, + ShowEjectDevice = networkItem.IsRemovable, + ShowShellItems = true, + ShowProperties = true + }; lock (drivesList) { if (!drivesList.Any(x => x.Path == networkItem.Path)) @@ -128,6 +142,10 @@ await CoreApplication.MainView.CoreWindow.Dispatcher.RunAsync(CoreDispatcherPrio { Text = "SidebarNetworkDrives".GetLocalized(), Section = SectionType.Network, + MenuOptions = new ContextMenuOptions + { + ShowHideSection = true + }, SelectsOnInvoked = false, Icon = await UIHelpers.GetIconResource(Constants.ImageRes.NetworkDrives), ChildItems = new BulkConcurrentObservableCollection() diff --git a/src/Files.Uwp/Filesystem/WSLDistroManager.cs b/src/Files.Uwp/Filesystem/WSLDistroManager.cs index 8972a19ba1be..ba8eb42d2ee6 100644 --- a/src/Files.Uwp/Filesystem/WSLDistroManager.cs +++ b/src/Files.Uwp/Filesystem/WSLDistroManager.cs @@ -55,6 +55,10 @@ await CoreApplication.MainView.CoreWindow.Dispatcher.RunAsync(CoreDispatcherPrio { Text = "WSL".GetLocalized(), Section = SectionType.WSL, + MenuOptions = new ContextMenuOptions + { + ShowHideSection = true + }, SelectsOnInvoked = false, Icon = new Windows.UI.Xaml.Media.Imaging.BitmapImage(new Uri("ms-appx:///Assets/WSL/genericpng.png")), ChildItems = new BulkConcurrentObservableCollection() @@ -105,7 +109,11 @@ await CoreApplication.MainView.CoreWindow.Dispatcher.RunAsync(CoreDispatcherPrio { Text = folder.DisplayName, Path = folder.Path, - Logo = logoURI + Logo = logoURI, + MenuOptions = new ContextMenuOptions + { + IsLocationItem = true + } }); } } diff --git a/src/Files.Uwp/UserControls/SidebarControl.xaml b/src/Files.Uwp/UserControls/SidebarControl.xaml index 9d5bd4f855b1..182fe9ca1c7e 100644 --- a/src/Files.Uwp/UserControls/SidebarControl.xaml +++ b/src/Files.Uwp/UserControls/SidebarControl.xaml @@ -56,7 +56,7 @@ IsRightTapEnabled="True" MenuItemsSource="{x:Bind ChildItems}" PointerPressed="Sidebar_PointerPressed" - RightTapped="NavigationViewLocationItem_RightTapped" + RightTapped="NavigationViewItem_RightTapped" SelectsOnInvoked="{x:Bind SelectsOnInvoked}" Tag="{x:Bind Path}" ToolTipService.ToolTip="{x:Bind HoverDisplayText}"> @@ -81,7 +81,7 @@ Drop="NavigationViewDriveItem_Drop" IsRightTapEnabled="True" PointerPressed="Sidebar_PointerPressed" - RightTapped="NavigationViewDriveItem_RightTapped" + RightTapped="NavigationViewItem_RightTapped" Tag="{x:Bind Path}" ToolTipService.ToolTip="{x:Bind HoverDisplayText, Mode=OneWay}" Visibility="{x:Bind ItemVisibility}"> @@ -99,7 +99,7 @@ DragEnter="NavigationViewItem_DragEnter" DragLeave="NavigationViewItem_DragLeave" PointerPressed="Sidebar_PointerPressed" - RightTapped="NavigationViewWSLItem_RightTapped" + RightTapped="NavigationViewItem_RightTapped" Tag="{x:Bind Path}" ToolTipService.ToolTip="{x:Bind HoverDisplayText}"> @@ -124,7 +124,7 @@ Drop="NavigationViewFileTag_Drop" IsRightTapEnabled="True" PointerPressed="Sidebar_PointerPressed" - RightTapped="NavigationViewFileTagsItem_RightTapped" + RightTapped="NavigationViewItem_RightTapped" Tag="{x:Bind Path}" ToolTipService.ToolTip="{x:Bind HoverDisplayText}"> diff --git a/src/Files.Uwp/UserControls/SidebarControl.xaml.cs b/src/Files.Uwp/UserControls/SidebarControl.xaml.cs index be2e5192623b..b7afb401aeb6 100644 --- a/src/Files.Uwp/UserControls/SidebarControl.xaml.cs +++ b/src/Files.Uwp/UserControls/SidebarControl.xaml.cs @@ -54,41 +54,27 @@ public sealed partial class SidebarControl : Microsoft.UI.Xaml.Controls.Navigati public event SidebarItemDroppedEventHandler SidebarItemDropped; - /// - /// The Model for the pinned sidebar items - /// - public SidebarPinnedModel SidebarPinnedModel => App.SidebarPinnedController.Model; + private INavigationControlItem rightClickedItem; - public static readonly DependencyProperty EmptyRecycleBinCommandProperty = DependencyProperty.Register(nameof(EmptyRecycleBinCommand), typeof(ICommand), typeof(SidebarControl), new PropertyMetadata(null)); - - public ICommand EmptyRecycleBinCommand - { - get => (ICommand)GetValue(EmptyRecycleBinCommandProperty); - set => SetValue(EmptyRecycleBinCommandProperty, value); - } - - public readonly RelayCommand CreateLibraryCommand = new RelayCommand(LibraryHelper.ShowCreateNewLibraryDialog); + private object dragOverSection, dragOverItem = null; - public readonly RelayCommand RestoreLibrariesCommand = new RelayCommand(LibraryHelper.ShowRestoreDefaultLibrariesDialog); + private bool isDropOnProcess = false; - private bool IsInPointerPressed = false; + /// + /// true if the user is currently resizing the sidebar + /// + private bool dragging; - private DispatcherQueueTimer dragOverSectionTimer, dragOverItemTimer; + private double originalSize = 0; - public SidebarControl() - { - this.InitializeComponent(); - this.Loaded += SidebarNavView_Loaded; + private bool lockFlag = false; - dragOverSectionTimer = DispatcherQueue.GetForCurrentThread().CreateTimer(); - dragOverItemTimer = DispatcherQueue.GetForCurrentThread().CreateTimer(); - } + /// + /// The Model for the pinned sidebar items + /// + public SidebarPinnedModel SidebarPinnedModel => App.SidebarPinnedController.Model; - public SidebarViewModel ViewModel - { - get => (SidebarViewModel)GetValue(ViewModelProperty); - set => SetValue(ViewModelProperty, value); - } + public static readonly DependencyProperty EmptyRecycleBinCommandProperty = DependencyProperty.Register(nameof(EmptyRecycleBinCommand), typeof(ICommand), typeof(SidebarControl), new PropertyMetadata(null)); // Using a DependencyProperty as the backing store for ViewModel. This enables animation, styling, binding, etc... public static readonly DependencyProperty ViewModelProperty = @@ -116,6 +102,69 @@ public UIElement TabContent set => SetValue(TabContentProperty, value); } + public ICommand EmptyRecycleBinCommand + { + get => (ICommand)GetValue(EmptyRecycleBinCommandProperty); + set => SetValue(EmptyRecycleBinCommandProperty, value); + } + + public readonly ICommand CreateLibraryCommand = new RelayCommand(LibraryHelper.ShowCreateNewLibraryDialog); + + public readonly ICommand RestoreLibrariesCommand = new RelayCommand(LibraryHelper.ShowRestoreDefaultLibrariesDialog); + + private ICommand HideSectionCommand { get; } + + private ICommand UnpinItemCommand { get; } + + private ICommand MoveItemToTopCommand { get; } + + private ICommand MoveItemUpCommand { get; } + + private ICommand MoveItemDownCommand { get; } + + private ICommand MoveItemToBottomCommand { get; } + + private ICommand OpenInNewTabCommand { get; } + + private ICommand OpenInNewWindowCommand { get; } + + private ICommand OpenInNewPaneCommand { get; } + + private ICommand EjectDeviceCommand { get; } + + private ICommand OpenPropertiesCommand { get; } + + private bool IsInPointerPressed = false; + + private DispatcherQueueTimer dragOverSectionTimer, dragOverItemTimer; + + public SidebarControl() + { + this.InitializeComponent(); + this.Loaded += SidebarNavView_Loaded; + + dragOverSectionTimer = DispatcherQueue.GetForCurrentThread().CreateTimer(); + dragOverItemTimer = DispatcherQueue.GetForCurrentThread().CreateTimer(); + + HideSectionCommand = new RelayCommand(HideSection); + UnpinItemCommand = new RelayCommand(UnpinItem); + MoveItemToTopCommand = new RelayCommand(MoveItemToTop); + MoveItemUpCommand = new RelayCommand(MoveItemUp); + MoveItemDownCommand = new RelayCommand(MoveItemDown); + MoveItemToBottomCommand = new RelayCommand(MoveItemToBottom); + OpenInNewTabCommand = new RelayCommand(OpenInNewTab); + OpenInNewWindowCommand = new RelayCommand(OpenInNewWindow); + OpenInNewPaneCommand = new RelayCommand(OpenInNewPane); + EjectDeviceCommand = new RelayCommand(EjectDevice); + OpenPropertiesCommand = new RelayCommand(OpenProperties); + } + + public SidebarViewModel ViewModel + { + get => (SidebarViewModel)GetValue(ViewModelProperty); + set => SetValue(ViewModelProperty, value); + } + private bool canOpenInNewPane; public bool CanOpenInNewPane @@ -131,26 +180,6 @@ public bool CanOpenInNewPane } } - public bool ShowMoveItemUp { get; set; } - - public bool ShowMoveItemDown { get; set; } - - public bool ShowUnpinItem { get; set; } - - public bool ShowHideSection { get; set; } - - public bool ShowProperties { get; set; } - - public bool ShowEmptyRecycleBin { get; set; } - - public bool ShowEjectDevice { get; set; } - - public bool IsLocationItem { get; set; } - - public bool IsLibrariesHeader { get; set; } - - public INavigationControlItem RightClickedItem; - public event PropertyChangedEventHandler PropertyChanged; private void NotifyPropertyChanged([CallerMemberName] string propertyName = "") @@ -158,151 +187,299 @@ private void NotifyPropertyChanged([CallerMemberName] string propertyName = "") PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(propertyName)); } - public void HideSection_Click(object sender, RoutedEventArgs e) + private List GetLocationItemMenuItems(INavigationControlItem item) { - if ("SidebarFavorites".GetLocalized().Equals(RightClickedItem.Text)) - { - UserSettingsService.AppearanceSettingsService.ShowFavoritesSection = false; - App.SidebarPinnedController.Model.UpdateFavoritesSectionVisibility(); - } - else if ("SidebarLibraries".GetLocalized().Equals(RightClickedItem.Text)) - { - UserSettingsService.AppearanceSettingsService.ShowLibrarySection = false; - App.LibraryManager.UpdateLibrariesSectionVisibility(); - } - else if ("SidebarCloudDrives".GetLocalized().Equals(RightClickedItem.Text)) - { - UserSettingsService.AppearanceSettingsService.ShowCloudDrivesSection = false; - App.CloudDrivesManager.UpdateCloudDrivesSectionVisibility(); - } - else if ("Drives".GetLocalized().Equals(RightClickedItem.Text)) + ContextMenuOptions options = item.MenuOptions; + + bool showMoveItemUp = options.IsItemMovable? App.SidebarPinnedController.Model.IndexOfItem(item) > 1:false; + bool showMoveItemDown = options.IsItemMovable? App.SidebarPinnedController.Model.IndexOfItem(item) < App.SidebarPinnedController.Model.FavoriteItems.Count:false; + + return new List() { - UserSettingsService.AppearanceSettingsService.ShowDrivesSection = false; - App.DrivesManager.UpdateDrivesSectionVisibility(); + new ContextMenuFlyoutItemViewModel() + { + Text = "SideBarCreateNewLibrary/Text".GetLocalized(), + Glyph = "\uE710", + Command = CreateLibraryCommand, + ShowItem = options.IsLibrariesHeader + }, + new ContextMenuFlyoutItemViewModel() + { + Text = "SideBarRestoreLibraries/Text".GetLocalized(), + Glyph = "\uE10E", + Command = RestoreLibrariesCommand, + ShowItem = options.IsLibrariesHeader + }, + new ContextMenuFlyoutItemViewModel() + { + Text = "BaseLayoutContextFlyoutEmptyRecycleBin/Text".GetLocalized(), + Glyph = "\uEF88", + GlyphFontFamilyName = "RecycleBinIcons", + Command = EmptyRecycleBinCommand, + ShowItem = options.ShowEmptyRecycleBin, + IsEnabled = false, + ID = "EmptyRecycleBin", + Tag = "EmptyRecycleBin", + }, + new ContextMenuFlyoutItemViewModel() + { + Text = "SideBarOpenInNewPane/Text".GetLocalized(), + Glyph = "\uF117", + GlyphFontFamilyName = "CustomGlyph", + Command = OpenInNewPaneCommand, + ShowItem = options.IsLocationItem && CanOpenInNewPane + }, + new ContextMenuFlyoutItemViewModel() + { + Text = "SideBarOpenInNewTab/Text".GetLocalized(), + Glyph = "\uF113", + GlyphFontFamilyName = "CustomGlyph", + Command = OpenInNewTabCommand, + ShowItem = options.IsLocationItem + }, + new ContextMenuFlyoutItemViewModel() + { + Text = "SideBarOpenInNewWindow/Text".GetLocalized(), + Glyph = "\uE737", + Command = OpenInNewWindowCommand, + ShowItem = options.IsLocationItem + }, + new ContextMenuFlyoutItemViewModel() + { + Text = "SideBarFavoritesMoveToTop".GetLocalized(), + Glyph = "\uE11C", + Command = MoveItemToTopCommand, + ShowItem = showMoveItemUp + }, + new ContextMenuFlyoutItemViewModel() + { + Text = "SideBarFavoritesMoveOneUp".GetLocalized(), + Glyph = "\uE70E", + Command = MoveItemUpCommand, + ShowItem = showMoveItemUp + }, + new ContextMenuFlyoutItemViewModel() + { + Text = "SideBarFavoritesMoveOneDown".GetLocalized(), + Glyph = "\uE70D", + Command = MoveItemDownCommand, + ShowItem = showMoveItemDown + }, + new ContextMenuFlyoutItemViewModel() + { + Text = "SideBarFavoritesMoveToBottom".GetLocalized(), + Glyph = "\uE118", + Command = MoveItemToBottomCommand, + ShowItem = showMoveItemDown + }, + new ContextMenuFlyoutItemViewModel() + { + Text = "SideBarUnpinFromFavorites/Text".GetLocalized(), + Glyph = "\uE77A", + Command = UnpinItemCommand, + ShowItem = options.ShowUnpinItem + }, + new ContextMenuFlyoutItemViewModel() + { + Text = string.Format("SideBarHideSectionFromSideBar/Text".GetLocalized(), rightClickedItem.Text), + Glyph = "\uE77A", + Command = HideSectionCommand, + ShowItem = options.ShowHideSection + }, + new ContextMenuFlyoutItemViewModel() + { + Text = "SideBarEjectDevice/Text".GetLocalized(), + Glyph = "\uF10B", + GlyphFontFamilyName = "CustomGlyph", + Command = EjectDeviceCommand, + ShowItem = options.ShowEjectDevice + }, + new ContextMenuFlyoutItemViewModel() + { + Text = "BaseLayoutContextFlyoutPropertiesFolder/Text".GetLocalized(), + Glyph = "\uE946", + Command = OpenPropertiesCommand, + ShowItem = options.ShowProperties + }, + new ContextMenuFlyoutItemViewModel() + { + Text = "ContextMenuMoreItemsLabel".GetLocalized(), + Glyph = "\xE712", + Items = new List(), + ID = "ItemOverflow", + Tag = "ItemOverflow", + IsHidden = true, + } + }.Where(x => x.ShowItem).ToList(); + } + + private void HideSection() + { + switch (rightClickedItem.Section) + { + case SectionType.Favorites: + UserSettingsService.AppearanceSettingsService.ShowFavoritesSection = false; + App.SidebarPinnedController.Model.UpdateFavoritesSectionVisibility(); + break; + case SectionType.Library: + UserSettingsService.AppearanceSettingsService.ShowLibrarySection = false; + App.LibraryManager.UpdateLibrariesSectionVisibility(); + break; + case SectionType.CloudDrives: + UserSettingsService.AppearanceSettingsService.ShowCloudDrivesSection = false; + App.CloudDrivesManager.UpdateCloudDrivesSectionVisibility(); + break; + case SectionType.Drives: + UserSettingsService.AppearanceSettingsService.ShowDrivesSection = false; + App.DrivesManager.UpdateDrivesSectionVisibility(); + break; + case SectionType.Network: + UserSettingsService.AppearanceSettingsService.ShowNetworkDrivesSection = false; + App.NetworkDrivesManager.UpdateNetworkDrivesSectionVisibility(); + break; + case SectionType.WSL: + UserSettingsService.AppearanceSettingsService.ShowWslSection = false; + App.WSLDistroManager.UpdateWslSectionVisibility(); + break; + case SectionType.FileTag: + UserSettingsService.AppearanceSettingsService.ShowFileTagsSection = false; + App.FileTagsManager.UpdateFileTagsSectionVisibility(); + break; } - else if ("SidebarNetworkDrives".GetLocalized().Equals(RightClickedItem.Text)) + } + + private async void OpenInNewPane() + { + if (await CheckEmptyDrive((rightClickedItem as INavigationControlItem)?.Path)) { - UserSettingsService.AppearanceSettingsService.ShowNetworkDrivesSection = false; - App.NetworkDrivesManager.UpdateNetworkDrivesSectionVisibility(); + return; } - else if ("WSL".GetLocalized().Equals(RightClickedItem.Text)) + SidebarItemNewPaneInvoked?.Invoke(this, new SidebarItemNewPaneInvokedEventArgs(rightClickedItem)); + } + + private async void OpenInNewTab() + { + if (await CheckEmptyDrive(rightClickedItem.Path)) { - UserSettingsService.AppearanceSettingsService.ShowWslSection = false; - App.WSLDistroManager.UpdateWslSectionVisibility(); + return; } - else if ("FileTags".GetLocalized().Equals(RightClickedItem.Text)) + await NavigationHelpers.OpenPathInNewTab(rightClickedItem.Path); + } + + private async void OpenInNewWindow() + { + if (await CheckEmptyDrive(rightClickedItem.Path)) { - UserSettingsService.AppearanceSettingsService.ShowFileTagsSection = false; - App.FileTagsManager.UpdateFileTagsSectionVisibility(); + return; } + await NavigationHelpers.OpenPathInNewWindowAsync(rightClickedItem.Path); } - public void UnpinItem_Click(object sender, RoutedEventArgs e) + private void UnpinItem() { - if (string.Equals(CommonPaths.RecycleBinPath, RightClickedItem.Path, StringComparison.OrdinalIgnoreCase)) + if (rightClickedItem.MenuOptions.ShowEmptyRecycleBin) { UserSettingsService.AppearanceSettingsService.PinRecycleBinToSidebar = false; + _ = App.SidebarPinnedController.Model.ShowHideRecycleBinItemAsync(false); } - else if (RightClickedItem.Section == SectionType.Favorites) + else if (rightClickedItem.Section == SectionType.Favorites) { - App.SidebarPinnedController.Model.RemoveItem(RightClickedItem.Path); + App.SidebarPinnedController.Model.RemoveItem(rightClickedItem.Path); } } - public void MoveItemToTop_Click(object sender, RoutedEventArgs e) + private void MoveItemToTop() { - if (RightClickedItem.Section == SectionType.Favorites) + if (rightClickedItem.Section == SectionType.Favorites) { bool isSelectedSidebarItem = false; - if (SelectedSidebarItem == RightClickedItem) + if (SelectedSidebarItem == rightClickedItem) { isSelectedSidebarItem = true; } - int oldIndex = App.SidebarPinnedController.Model.IndexOfItem(RightClickedItem); - App.SidebarPinnedController.Model.MoveItem(RightClickedItem, oldIndex, 1); + int oldIndex = App.SidebarPinnedController.Model.IndexOfItem(rightClickedItem); + App.SidebarPinnedController.Model.MoveItem(rightClickedItem, oldIndex, 1); if (isSelectedSidebarItem) { - SetValue(SelectedSidebarItemProperty, RightClickedItem); + SetValue(SelectedSidebarItemProperty, rightClickedItem); } } } - public void MoveItemUp_Click(object sender, RoutedEventArgs e) + private void MoveItemUp() { - if (RightClickedItem.Section == SectionType.Favorites) + if (rightClickedItem.Section == SectionType.Favorites) { bool isSelectedSidebarItem = false; - if (SelectedSidebarItem == RightClickedItem) + if (SelectedSidebarItem == rightClickedItem) { isSelectedSidebarItem = true; } - int oldIndex = App.SidebarPinnedController.Model.IndexOfItem(RightClickedItem); - App.SidebarPinnedController.Model.MoveItem(RightClickedItem, oldIndex, oldIndex - 1); + int oldIndex = App.SidebarPinnedController.Model.IndexOfItem(rightClickedItem); + App.SidebarPinnedController.Model.MoveItem(rightClickedItem, oldIndex, oldIndex - 1); if (isSelectedSidebarItem) { - SetValue(SelectedSidebarItemProperty, RightClickedItem); + SetValue(SelectedSidebarItemProperty, rightClickedItem); } } } - public void MoveItemDown_Click(object sender, RoutedEventArgs e) + private void MoveItemDown() { - if (RightClickedItem.Section == SectionType.Favorites) + if (rightClickedItem.Section == SectionType.Favorites) { bool isSelectedSidebarItem = false; - if (SelectedSidebarItem == RightClickedItem) + if (SelectedSidebarItem == rightClickedItem) { isSelectedSidebarItem = true; } - int oldIndex = App.SidebarPinnedController.Model.IndexOfItem(RightClickedItem); - App.SidebarPinnedController.Model.MoveItem(RightClickedItem, oldIndex, oldIndex + 1); + int oldIndex = App.SidebarPinnedController.Model.IndexOfItem(rightClickedItem); + App.SidebarPinnedController.Model.MoveItem(rightClickedItem, oldIndex, oldIndex + 1); if (isSelectedSidebarItem) { - SetValue(SelectedSidebarItemProperty, RightClickedItem); + SetValue(SelectedSidebarItemProperty, rightClickedItem); } } } - public void MoveItemToBottom_Click(object sender, RoutedEventArgs e) + private void MoveItemToBottom() { - if (RightClickedItem.Section == SectionType.Favorites) + if (rightClickedItem.Section == SectionType.Favorites) { bool isSelectedSidebarItem = false; - if (SelectedSidebarItem == RightClickedItem) + if (SelectedSidebarItem == rightClickedItem) { isSelectedSidebarItem = true; } - int oldIndex = App.SidebarPinnedController.Model.IndexOfItem(RightClickedItem); - App.SidebarPinnedController.Model.MoveItem(RightClickedItem, oldIndex, App.SidebarPinnedController.Model.FavoriteItems.Count); + int oldIndex = App.SidebarPinnedController.Model.IndexOfItem(rightClickedItem); + App.SidebarPinnedController.Model.MoveItem(rightClickedItem, oldIndex, App.SidebarPinnedController.Model.FavoriteItems.Count); if (isSelectedSidebarItem) { - SetValue(SelectedSidebarItemProperty, RightClickedItem); + SetValue(SelectedSidebarItemProperty, rightClickedItem); } } } - public static GridLength GetSidebarCompactSize() + private void OpenProperties() { - if (App.Current.Resources.TryGetValue("NavigationViewCompactPaneLength", out object paneLength)) - { - if (paneLength is double paneLengthDouble) - { - return new GridLength(paneLengthDouble); - } - } - return new GridLength(200); + SidebarItemPropertiesInvoked?.Invoke(this, new SidebarItemPropertiesInvokedEventArgs(rightClickedItem)); + } + + private async void EjectDevice() + { + await DriveHelpers.EjectDeviceAsync(rightClickedItem.Path); } private async void Sidebar_ItemInvoked(Microsoft.UI.Xaml.Controls.NavigationView sender, Microsoft.UI.Xaml.Controls.NavigationViewItemInvokedEventArgs args) @@ -348,111 +525,21 @@ private async void Sidebar_PointerPressed(object sender, PointerRoutedEventArgs private void PaneRoot_RightTapped(object sender, RightTappedRoutedEventArgs e) { - var contextMenu= FlyoutBase.GetAttachedFlyout(this); + var contextMenu = FlyoutBase.GetAttachedFlyout(this); contextMenu.ShowAt(this, new FlyoutShowOptions() { Position = e.GetPosition(this) }); e.Handled = true; } - private void NavigationViewLocationItem_RightTapped(object sender, RightTappedRoutedEventArgs e) + private void NavigationViewItem_RightTapped(object sender, RightTappedRoutedEventArgs e) { var itemContextMenuFlyout = new Microsoft.UI.Xaml.Controls.CommandBarFlyout(); var sidebarItem = sender as Microsoft.UI.Xaml.Controls.NavigationViewItem; - var item = sidebarItem.DataContext as LocationItem; - - bool drivesHeader = "Drives".GetLocalized().Equals(item.Text); - bool networkDrivesHeader = "SidebarNetworkDrives".GetLocalized().Equals(item.Text); - bool cloudDrivesHeader = "SidebarCloudDrives".GetLocalized().Equals(item.Text); - bool librariesHeader = "SidebarLibraries".GetLocalized().Equals(item.Text); - bool wslHeader = "WSL".GetLocalized().Equals(item.Text); - bool fileTagsHeader = "FileTags".GetLocalized().Equals(item.Text); - bool favoritesHeader = "SidebarFavorites".GetLocalized().Equals(item.Text); - bool header = drivesHeader || networkDrivesHeader || cloudDrivesHeader || librariesHeader || wslHeader || fileTagsHeader || favoritesHeader; - - if (!header) - { - bool library = item.Section == SectionType.Library; - bool favorite = item.Section == SectionType.Favorites; - - IsLocationItem = true; - ShowProperties = true; - IsLibrariesHeader = false; - ShowUnpinItem = ((library || favorite) && !item.IsDefaultLocation); - ShowMoveItemUp = ShowUnpinItem && App.SidebarPinnedController.Model.IndexOfItem(item) > 1; - ShowMoveItemDown = ShowUnpinItem && App.SidebarPinnedController.Model.IndexOfItem(item) < App.SidebarPinnedController.Model.FavoriteItems.Count; - ShowHideSection = false; - ShowEjectDevice = false; - - if (string.Equals(item.Path, "Home".GetLocalized(), StringComparison.OrdinalIgnoreCase)) - { - ShowProperties = false; - } + var item = sidebarItem.DataContext as INavigationControlItem; - if (string.Equals(item.Path, CommonPaths.RecycleBinPath, StringComparison.OrdinalIgnoreCase)) - { - ShowEmptyRecycleBin = true; - ShowUnpinItem = true; - ShowProperties = false; - } - else - { - ShowEmptyRecycleBin = false; - } - - RightClickedItem = item; - var menuItems = GetLocationItemMenuItems(); - var (_, secondaryElements) = ItemModelListToContextFlyoutHelper.GetAppBarItemsFromModel(menuItems); + rightClickedItem = item; - if (!UserSettingsService.AppearanceSettingsService.MoveOverflowMenuItemsToSubMenu) - { - secondaryElements.OfType().ForEach(i => i.MinWidth = Constants.UI.ContextMenuItemsMaxWidth); // Set menu min width if the overflow menu setting is disabled - } - - secondaryElements.ForEach(i => itemContextMenuFlyout.SecondaryCommands.Add(i)); - itemContextMenuFlyout.ShowAt(sidebarItem, new FlyoutShowOptions() { Position = e.GetPosition(sidebarItem) }); - - LoadShellMenuItems(itemContextMenuFlyout); - } - else - { - IsLocationItem = false; - ShowProperties = false; - IsLibrariesHeader = librariesHeader; - ShowUnpinItem = false; - ShowMoveItemUp = false; - ShowMoveItemDown = false; - ShowHideSection = true; - ShowEjectDevice = false; - ShowEmptyRecycleBin = false; - - RightClickedItem = item; - var menuItems = GetLocationItemMenuItems(); - var (_, secondaryElements) = ItemModelListToContextFlyoutHelper.GetAppBarItemsFromModel(menuItems); - secondaryElements.ForEach(i => itemContextMenuFlyout.SecondaryCommands.Add(i)); - itemContextMenuFlyout.ShowAt(sidebarItem, new FlyoutShowOptions() { Position = e.GetPosition(sidebarItem) }); - } - - e.Handled = true; - } - - private void NavigationViewDriveItem_RightTapped(object sender, RightTappedRoutedEventArgs e) - { - var itemContextMenuFlyout = new Microsoft.UI.Xaml.Controls.CommandBarFlyout(); - var sidebarItem = sender as Microsoft.UI.Xaml.Controls.NavigationViewItem; - var item = sidebarItem.DataContext as DriveItem; - - IsLocationItem = true; - IsLibrariesHeader = false; - ShowEjectDevice = item.IsRemovable; - ShowUnpinItem = false; - ShowMoveItemUp = false; - ShowMoveItemDown = false; - ShowEmptyRecycleBin = false; - ShowProperties = true; - ShowHideSection = false; - - RightClickedItem = item; - var menuItems = GetLocationItemMenuItems(); + var menuItems = GetLocationItemMenuItems(item); var (_, secondaryElements) = ItemModelListToContextFlyoutHelper.GetAppBarItemsFromModel(menuItems); if (!UserSettingsService.AppearanceSettingsService.MoveOverflowMenuItemsToSubMenu) @@ -463,77 +550,12 @@ private void NavigationViewDriveItem_RightTapped(object sender, RightTappedRoute secondaryElements.ForEach(i => itemContextMenuFlyout.SecondaryCommands.Add(i)); itemContextMenuFlyout.ShowAt(sidebarItem, new FlyoutShowOptions() { Position = e.GetPosition(sidebarItem) }); - LoadShellMenuItems(itemContextMenuFlyout); - - e.Handled = true; - } - - private void NavigationViewWSLItem_RightTapped(object sender, RightTappedRoutedEventArgs e) - { - var itemContextMenuFlyout = new Microsoft.UI.Xaml.Controls.CommandBarFlyout(); - var sidebarItem = sender as Microsoft.UI.Xaml.Controls.NavigationViewItem; - var item = sidebarItem.DataContext as WslDistroItem; - - IsLocationItem = true; - IsLibrariesHeader = false; - ShowEjectDevice = false; - ShowUnpinItem = false; - ShowMoveItemUp = false; - ShowMoveItemDown = false; - ShowEmptyRecycleBin = false; - ShowProperties = false; - ShowHideSection = false; - - RightClickedItem = item; - var menuItems = GetLocationItemMenuItems(); - var (_, secondaryElements) = ItemModelListToContextFlyoutHelper.GetAppBarItemsFromModel(menuItems); - secondaryElements.ForEach(i => itemContextMenuFlyout.SecondaryCommands.Add(i)); - itemContextMenuFlyout.ShowAt(sidebarItem, new FlyoutShowOptions() { Position = e.GetPosition(sidebarItem) }); - - e.Handled = true; - } - - private void NavigationViewFileTagsItem_RightTapped(object sender, RightTappedRoutedEventArgs e) - { - var itemContextMenuFlyout = new Microsoft.UI.Xaml.Controls.CommandBarFlyout(); - var sidebarItem = sender as Microsoft.UI.Xaml.Controls.NavigationViewItem; - var item = sidebarItem.DataContext as FileTagItem; - - IsLocationItem = true; - IsLibrariesHeader = false; - ShowEjectDevice = false; - ShowUnpinItem = false; - ShowMoveItemUp = false; - ShowMoveItemDown = false; - ShowEmptyRecycleBin = false; - ShowProperties = false; - ShowHideSection = false; - - RightClickedItem = item; - var menuItems = GetLocationItemMenuItems(); - var (_, secondaryElements) = ItemModelListToContextFlyoutHelper.GetAppBarItemsFromModel(menuItems); - secondaryElements.ForEach(i => itemContextMenuFlyout.SecondaryCommands.Add(i)); - itemContextMenuFlyout.ShowAt(sidebarItem, new FlyoutShowOptions() { Position = e.GetPosition(sidebarItem) }); - - e.Handled = true; - } - - private async void OpenInNewTab_Click(object sender, RoutedEventArgs e) - { - if (await CheckEmptyDrive(RightClickedItem.Path)) + if (item.MenuOptions.ShowShellItems) { - return; + LoadShellMenuItems(itemContextMenuFlyout, item.MenuOptions); } - await NavigationHelpers.OpenPathInNewTab(RightClickedItem.Path); - } - private async void OpenInNewWindow_Click(object sender, RoutedEventArgs e) - { - if (await CheckEmptyDrive(RightClickedItem.Path)) - { - return; - } - await NavigationHelpers.OpenPathInNewWindowAsync(RightClickedItem.Path); + e.Handled = true; } private void NavigationViewItem_DragStarting(UIElement sender, DragStartingEventArgs args) @@ -548,10 +570,6 @@ private void NavigationViewItem_DragStarting(UIElement sender, DragStartingEvent args.Data.Properties.Add("sourceLocationItem", navItem); } - private object dragOverSection, dragOverItem = null; - - private bool isDropOnProcess = false; - private void NavigationViewItem_DragEnter(object sender, DragEventArgs e) { VisualStateManager.GoToState(sender as Microsoft.UI.Xaml.Controls.NavigationViewItem, "DragEnter", false); @@ -749,8 +767,6 @@ private void NavigationViewLocationItem_DragOver_SetCaptions(LocationItem sender } } - private bool lockFlag = false; - private async void NavigationViewLocationItem_Drop(object sender, DragEventArgs e) { if (lockFlag) @@ -982,16 +998,6 @@ private async void NavigationViewFileTag_Drop(object sender, DragEventArgs e) lockFlag = false; } - private void Properties_Click(object sender, RoutedEventArgs e) - { - SidebarItemPropertiesInvoked?.Invoke(this, new SidebarItemPropertiesInvokedEventArgs(RightClickedItem)); - } - - private async void EjectDevice_Click(object sender, RoutedEventArgs e) - { - await DriveHelpers.EjectDeviceAsync(RightClickedItem.Path); - } - private void SidebarNavView_Loaded(object sender, RoutedEventArgs e) { (this.FindDescendant("TabContentBorder") as Border).Child = TabContent; @@ -1043,13 +1049,6 @@ private void Border_KeyDown(object sender, KeyRoutedEventArgs e) UserSettingsService.AppearanceSettingsService.SidebarWidth = OpenPaneLength; } - /// - /// true if the user is currently resizing the sidebar - /// - private bool dragging; - - private double originalSize = 0; - private void Border_ManipulationDelta(object sender, ManipulationDeltaRoutedEventArgs e) { if (DisplayMode == Microsoft.UI.Xaml.Controls.NavigationViewDisplayMode.Expanded) @@ -1067,6 +1066,15 @@ private void Border_PointerExited(object sender, PointerRoutedEventArgs e) } } + private void Border_PointerEntered(object sender, PointerRoutedEventArgs e) + { + if (DisplayMode == Microsoft.UI.Xaml.Controls.NavigationViewDisplayMode.Expanded) + { + Window.Current.CoreWindow.PointerCursor = new CoreCursor(CoreCursorType.SizeWestEast, 0); + VisualStateManager.GoToState((sender as Grid).FindAscendant(), "ResizerPointerOver", true); + } + } + private void SetSize(double val, bool closeImmediatleyOnOversize = false) { if (IsPaneOpen) @@ -1095,15 +1103,6 @@ private void SetSize(double val, bool closeImmediatleyOnOversize = false) } } - private void Border_PointerEntered(object sender, PointerRoutedEventArgs e) - { - if (DisplayMode == Microsoft.UI.Xaml.Controls.NavigationViewDisplayMode.Expanded) - { - Window.Current.CoreWindow.PointerCursor = new CoreCursor(CoreCursorType.SizeWestEast, 0); - VisualStateManager.GoToState((sender as Grid).FindAscendant(), "ResizerPointerOver", true); - } - } - private void ResizeElementBorder_ManipulationCompleted(object sender, ManipulationCompletedRoutedEventArgs e) { Window.Current.CoreWindow.PointerCursor = new CoreCursor(CoreCursorType.Arrow, 0); @@ -1117,15 +1116,6 @@ private void ResizeElementBorder_DoubleTapped(object sender, DoubleTappedRoutedE IsPaneOpen = !IsPaneOpen; } - private async void OpenInNewPane_Click(object sender, RoutedEventArgs e) - { - if (await CheckEmptyDrive((RightClickedItem as INavigationControlItem)?.Path)) - { - return; - } - SidebarItemNewPaneInvoked?.Invoke(this, new SidebarItemNewPaneInvokedEventArgs(RightClickedItem)); - } - private void ResizeElementBorder_ManipulationStarted(object sender, ManipulationStartedRoutedEventArgs e) { if (DisplayMode == Microsoft.UI.Xaml.Controls.NavigationViewDisplayMode.Expanded) @@ -1155,11 +1145,11 @@ private async Task CheckEmptyDrive(string drivePath) return false; } - private async void LoadShellMenuItems(Microsoft.UI.Xaml.Controls.CommandBarFlyout itemContextMenuFlyout) + private async void LoadShellMenuItems(Microsoft.UI.Xaml.Controls.CommandBarFlyout itemContextMenuFlyout, ContextMenuOptions options) { try { - if (ShowEmptyRecycleBin) + if (options.ShowEmptyRecycleBin) { var emptyRecycleBinItem = itemContextMenuFlyout.SecondaryCommands.FirstOrDefault(x => x is AppBarButton appBarButton && (appBarButton.Tag as string) == "EmptyRecycleBin") as AppBarButton; if (emptyRecycleBinItem is not null) @@ -1168,11 +1158,11 @@ private async void LoadShellMenuItems(Microsoft.UI.Xaml.Controls.CommandBarFlyou emptyRecycleBinItem.IsEnabled = binHasItems; } } - if (IsLocationItem) + if (options.IsLocationItem) { var shiftPressed = Window.Current.CoreWindow.GetKeyState(VirtualKey.Shift).HasFlag(CoreVirtualKeyStates.Down); var shellMenuItems = await ContextFlyoutItemHelper.GetItemContextShellCommandsAsync(connection: await AppServiceConnectionHelper.Instance, currentInstanceViewModel: null, workingDir: null, - new List() { new ListedItem(null) { ItemPath = RightClickedItem.Path } }, shiftPressed: shiftPressed, showOpenMenu: false); + new List() { new ListedItem(null) { ItemPath = rightClickedItem.Path } }, shiftPressed: shiftPressed, showOpenMenu: false); if (!UserSettingsService.AppearanceSettingsService.MoveOverflowMenuItemsToSubMenu) { var (_, secondaryElements) = ItemModelListToContextFlyoutHelper.GetAppBarItemsFromModel(shellMenuItems); @@ -1205,125 +1195,16 @@ private async void LoadShellMenuItems(Microsoft.UI.Xaml.Controls.CommandBarFlyou catch { } } - public List GetLocationItemMenuItems() + public static GridLength GetSidebarCompactSize() { - return new List() + if (App.Current.Resources.TryGetValue("NavigationViewCompactPaneLength", out object paneLength)) { - new ContextMenuFlyoutItemViewModel() - { - Text = "SideBarCreateNewLibrary/Text".GetLocalized(), - Glyph = "\uE710", - Command = CreateLibraryCommand, - ShowItem = IsLibrariesHeader - }, - new ContextMenuFlyoutItemViewModel() - { - Text = "SideBarRestoreLibraries/Text".GetLocalized(), - Glyph = "\uE10E", - Command = RestoreLibrariesCommand, - ShowItem = IsLibrariesHeader - }, - new ContextMenuFlyoutItemViewModel() - { - Text = "BaseLayoutContextFlyoutEmptyRecycleBin/Text".GetLocalized(), - Glyph = "\uEF88", - GlyphFontFamilyName = "RecycleBinIcons", - Command = EmptyRecycleBinCommand, - ShowItem = ShowEmptyRecycleBin, - IsEnabled = false, - ID = "EmptyRecycleBin", - Tag = "EmptyRecycleBin", - }, - new ContextMenuFlyoutItemViewModel() - { - Text = "SideBarOpenInNewPane/Text".GetLocalized(), - Glyph = "\uF117", - GlyphFontFamilyName = "CustomGlyph", - Command = new RelayCommand(() => OpenInNewPane_Click(null, null)), - ShowItem = IsLocationItem && CanOpenInNewPane - }, - new ContextMenuFlyoutItemViewModel() - { - Text = "SideBarOpenInNewTab/Text".GetLocalized(), - Glyph = "\uF113", - GlyphFontFamilyName = "CustomGlyph", - Command = new RelayCommand(() => OpenInNewTab_Click(null, null)), - ShowItem = IsLocationItem - }, - new ContextMenuFlyoutItemViewModel() - { - Text = "SideBarOpenInNewWindow/Text".GetLocalized(), - Glyph = "\uE737", - Command = new RelayCommand(() => OpenInNewWindow_Click(null, null)), - ShowItem = IsLocationItem - }, - new ContextMenuFlyoutItemViewModel() - { - Text = "SideBarFavoritesMoveToTop".GetLocalized(), - Glyph = "\uE11C", - Command = new RelayCommand(() => MoveItemToTop_Click(null, null)), - ShowItem = ShowMoveItemUp - }, - new ContextMenuFlyoutItemViewModel() - { - Text = "SideBarFavoritesMoveOneUp".GetLocalized(), - Glyph = "\uE70E", - Command = new RelayCommand(() => MoveItemUp_Click(null, null)), - ShowItem = ShowMoveItemUp - }, - new ContextMenuFlyoutItemViewModel() - { - Text = "SideBarFavoritesMoveOneDown".GetLocalized(), - Glyph = "\uE70D", - Command = new RelayCommand(() => MoveItemDown_Click(null, null)), - ShowItem = ShowMoveItemDown - }, - new ContextMenuFlyoutItemViewModel() - { - Text = "SideBarFavoritesMoveToBottom".GetLocalized(), - Glyph = "\uE118", - Command = new RelayCommand(() => MoveItemToBottom_Click(null, null)), - ShowItem = ShowMoveItemDown - }, - new ContextMenuFlyoutItemViewModel() - { - Text = "SideBarUnpinFromFavorites/Text".GetLocalized(), - Glyph = "\uE77A", - Command = new RelayCommand(() => UnpinItem_Click(null, null)), - ShowItem = ShowUnpinItem - }, - new ContextMenuFlyoutItemViewModel() - { - Text = string.Format("SideBarHideSectionFromSideBar/Text".GetLocalized(), RightClickedItem.Text), - Glyph = "\uE77A", - Command = new RelayCommand(() => HideSection_Click(null, null)), - ShowItem = ShowHideSection - }, - new ContextMenuFlyoutItemViewModel() - { - Text = "SideBarEjectDevice/Text".GetLocalized(), - Glyph = "\uF10B", - GlyphFontFamilyName = "CustomGlyph", - Command = new RelayCommand(() => EjectDevice_Click(null, null)), - ShowItem = ShowEjectDevice - }, - new ContextMenuFlyoutItemViewModel() - { - Text = "BaseLayoutContextFlyoutPropertiesFolder/Text".GetLocalized(), - Glyph = "\uE946", - Command = new RelayCommand(() => Properties_Click(null, null)), - ShowItem = ShowProperties - }, - new ContextMenuFlyoutItemViewModel() + if (paneLength is double paneLengthDouble) { - Text = "ContextMenuMoreItemsLabel".GetLocalized(), - Glyph = "\xE712", - Items = new List(), - ID = "ItemOverflow", - Tag = "ItemOverflow", - IsHidden = true, + return new GridLength(paneLengthDouble); } - }.Where(x => x.ShowItem).ToList(); + } + return new GridLength(200); } }