From 99394f565bd261364ee0ebaf51caf19525fc124a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Pablo=20Garc=C3=ADa=20Ruiz?= Date: Fri, 24 Feb 2023 18:05:53 +0100 Subject: [PATCH 01/14] Add move items to sidebar --- .../NavigationControlItems/LocationItem.cs | 2 + .../DataModels/SidebarPinnedModel.cs | 3 +- .../QuickAccessService.cs | 48 +++++++++++++++---- .../UserControls/SidebarControl.xaml | 17 ++++++- .../UserControls/SidebarControl.xaml.cs | 35 ++++++++++---- src/Files.App/ViewModels/SidebarViewModel.cs | 8 ++++ .../Services/IQuickAccessService.cs | 12 ++++- 7 files changed, 101 insertions(+), 24 deletions(-) diff --git a/src/Files.App/DataModels/NavigationControlItems/LocationItem.cs b/src/Files.App/DataModels/NavigationControlItems/LocationItem.cs index c2311f86781d..b21b5fb7390a 100644 --- a/src/Files.App/DataModels/NavigationControlItems/LocationItem.cs +++ b/src/Files.App/DataModels/NavigationControlItems/LocationItem.cs @@ -72,6 +72,8 @@ public bool IsExpanded public ContextMenuOptions MenuOptions { get; set; } + public bool IsHeader { get; set; } = false; + public int CompareTo(INavigationControlItem other) => Text.CompareTo(other.Text); diff --git a/src/Files.App/DataModels/SidebarPinnedModel.cs b/src/Files.App/DataModels/SidebarPinnedModel.cs index f62552b8db6e..b2fdff8b2dcd 100644 --- a/src/Files.App/DataModels/SidebarPinnedModel.cs +++ b/src/Files.App/DataModels/SidebarPinnedModel.cs @@ -180,13 +180,12 @@ public void RemoveStaleSidebarItems() // Remove unpinned items from favoriteList foreach (var childItem in Favorites) { - if (childItem is LocationItem item && !item.IsDefaultLocation && !FavoriteItems.Contains(item.Path)) + if (childItem is LocationItem item) { lock (favoriteList) { favoriteList.Remove(item); } - DataChanged?.Invoke(SectionType.Favorites, new NotifyCollectionChangedEventArgs(NotifyCollectionChangedAction.Remove, item)); } } diff --git a/src/Files.App/ServicesImplementation/QuickAccessService.cs b/src/Files.App/ServicesImplementation/QuickAccessService.cs index f0102e262ce5..12e034f8b10f 100644 --- a/src/Files.App/ServicesImplementation/QuickAccessService.cs +++ b/src/Files.App/ServicesImplementation/QuickAccessService.cs @@ -1,12 +1,9 @@ using Files.App.Shell; using Files.App.UserControls.Widgets; -using Files.Sdk.Storage.LocatableStorage; using Files.Shared; using Files.Shared.Extensions; -using Microsoft.UI.Xaml.Shapes; using System; using System.Collections.Generic; -using System.IO; using System.Linq; using System.Threading.Tasks; @@ -27,30 +24,44 @@ public Task PinToSidebar(string folderPath) public async Task PinToSidebar(string[] folderPaths) { - await ContextMenu.InvokeVerb("pintohome", folderPaths); + foreach (string folderPath in folderPaths) + await ContextMenu.InvokeVerb("pintohome", new[] {folderPath}); await App.QuickAccessManager.Model.LoadAsync(); App.QuickAccessManager.UpdateQuickAccessWidget?.Invoke(this, new ModifyQuickAccessEventArgs(folderPaths, true)); } - public Task UnpinFromSidebar(string folderPath) - => UnpinFromSidebar(new[] { folderPath }); + public Task UnpinFromSidebar(string folderPath, bool syncItems = true) + => UnpinFromSidebar(new[] { folderPath }, syncItems); - public async Task UnpinFromSidebar(string[] folderPaths) + public async Task UnpinFromSidebar(string[] folderPaths, bool syncItems = true) { Type? shellAppType = Type.GetTypeFromProgID("Shell.Application"); object? shell = Activator.CreateInstance(shellAppType); dynamic? f2 = shellAppType.InvokeMember("NameSpace", System.Reflection.BindingFlags.InvokeMethod, null, shell, new object[] { $"shell:{guid}" }); + if (folderPaths.Length == 0) + folderPaths = (await GetPinnedFoldersAsync()) + .Where(link => (bool?)link.Properties["System.Home.IsPinned"] ?? false) + .Select(link => link.FilePath).ToArray(); + foreach (dynamic? fi in f2.Items()) + { + App.Logger.Info((string)fi.Path); if (folderPaths.Contains((string)fi.Path) || (string.Equals(fi.Path, "::{645FF040-5081-101B-9F08-00AA002F954E}") && folderPaths.Contains(Constants.CommonPaths.RecycleBinPath))) - await SafetyExtensions.IgnoreExceptions(async () => { + { + App.Logger.Info("Unpinning " + fi.Path); + await SafetyExtensions.IgnoreExceptions(async () => + { await fi.InvokeVerb("unpinfromhome"); }); + } + } - await App.QuickAccessManager.Model.LoadAsync(); + if (syncItems) + await App.QuickAccessManager.Model.LoadAsync(); App.QuickAccessManager.UpdateQuickAccessWidget?.Invoke(this, new ModifyQuickAccessEventArgs(folderPaths, false)); } @@ -59,5 +70,24 @@ public bool IsItemPinned(string folderPath) { return App.QuickAccessManager.Model.FavoriteItems.Contains(folderPath); } + + public async Task MoveTo(string toMove, string destination) + { + if (string.Equals(toMove, destination)) + return; + + App.QuickAccessManager.PinnedItemsWatcher.EnableRaisingEvents = false; + var index = App.QuickAccessManager.Model.FavoriteItems.IndexOf(destination); + var favoriteItemsCopy = new List(App.QuickAccessManager.Model.FavoriteItems); + + // Unpin every item that is below this index and then pin them all in order + await UnpinFromSidebar(Array.Empty(), false); + + favoriteItemsCopy.Remove(toMove); + favoriteItemsCopy.Insert(index, toMove); + + await PinToSidebar(favoriteItemsCopy.ToArray()); + App.QuickAccessManager.PinnedItemsWatcher.EnableRaisingEvents = true; + } } } diff --git a/src/Files.App/UserControls/SidebarControl.xaml b/src/Files.App/UserControls/SidebarControl.xaml index dab15a3ab45e..8ecced9cae42 100644 --- a/src/Files.App/UserControls/SidebarControl.xaml +++ b/src/Files.App/UserControls/SidebarControl.xaml @@ -57,7 +57,6 @@ AllowDrop="True" AutomationProperties.AutomationId="{x:Bind Text}" CanDrag="False" - Content="{x:Bind Text}" DataContext="{x:Bind}" DragEnter="NavigationViewItem_DragEnter" DragLeave="NavigationViewItem_DragLeave" @@ -75,6 +74,22 @@ + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/src/Files.App/Dialogs/ReorderSidebarItemsDialog.xaml.cs b/src/Files.App/Dialogs/ReorderSidebarItemsDialog.xaml.cs new file mode 100644 index 000000000000..6f5a9bfc0a9e --- /dev/null +++ b/src/Files.App/Dialogs/ReorderSidebarItemsDialog.xaml.cs @@ -0,0 +1,25 @@ +using Files.App.ViewModels.Dialogs; +using Files.Backend.ViewModels.Dialogs; +using Files.Shared.Enums; +using Microsoft.UI.Xaml.Controls; +using System; +using System.Threading.Tasks; + +namespace Files.App.Dialogs +{ + public sealed partial class ReorderSidebarItemsDialog : ContentDialog, IDialog + { + public ReorderSidebarItemsDialogViewModel ViewModel + { + get => (ReorderSidebarItemsDialogViewModel)DataContext; + set => DataContext = value; + } + + public ReorderSidebarItemsDialog() + { + InitializeComponent(); + } + + public new async Task ShowAsync() => (DialogResult)await base.ShowAsync(); + } +} \ No newline at end of file diff --git a/src/Files.App/ViewModels/Dialogs/ReorderSidebarItemsDialogViewModel.cs b/src/Files.App/ViewModels/Dialogs/ReorderSidebarItemsDialogViewModel.cs new file mode 100644 index 000000000000..5a2bdd98974c --- /dev/null +++ b/src/Files.App/ViewModels/Dialogs/ReorderSidebarItemsDialogViewModel.cs @@ -0,0 +1,16 @@ +using CommunityToolkit.Mvvm.ComponentModel; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace Files.App.ViewModels.Dialogs +{ + public class ReorderSidebarItemsDialogViewModel : ObservableObject + { + public string HeaderText = "Reorder sidebar items"; + + public ReorderSidebarItemsDialogViewModel() { } + } +} From e6715eca8e8374183c4fbab293a27b1c7232bffc Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Pablo=20Garc=C3=ADa=20Ruiz?= Date: Fri, 3 Mar 2023 19:58:55 +0100 Subject: [PATCH 05/14] Add dialog for reordering sidebar items --- .../DataModels/SidebarPinnedModel.cs | 2 +- .../Dialogs/ReorderSidebarItemsDialog.xaml | 78 ++++++++++++++++--- .../Dialogs/ReorderSidebarItemsDialog.xaml.cs | 25 ++++++ .../ServicesImplementation/DialogService.cs | 7 +- .../QuickAccessService.cs | 11 +-- src/Files.App/Strings/en-US/Resources.resw | 3 + .../UserControls/SidebarControl.xaml | 1 - .../UserControls/SidebarControl.xaml.cs | 55 ++----------- .../ReorderSidebarItemsDialogViewModel.cs | 27 ++++++- .../Services/IQuickAccessService.cs | 7 +- 10 files changed, 137 insertions(+), 79 deletions(-) diff --git a/src/Files.App/DataModels/SidebarPinnedModel.cs b/src/Files.App/DataModels/SidebarPinnedModel.cs index e12869d108d3..41aed0ec238c 100644 --- a/src/Files.App/DataModels/SidebarPinnedModel.cs +++ b/src/Files.App/DataModels/SidebarPinnedModel.cs @@ -29,7 +29,7 @@ public class SidebarPinnedModel public List FavoriteItems { get; set; } = new List(); - private readonly List favoriteList = new(); + public readonly List favoriteList = new(); [JsonIgnore] public IReadOnlyList Favorites diff --git a/src/Files.App/Dialogs/ReorderSidebarItemsDialog.xaml b/src/Files.App/Dialogs/ReorderSidebarItemsDialog.xaml index cca5667c9dfe..66894d192932 100644 --- a/src/Files.App/Dialogs/ReorderSidebarItemsDialog.xaml +++ b/src/Files.App/Dialogs/ReorderSidebarItemsDialog.xaml @@ -5,11 +5,14 @@ xmlns:d="http://schemas.microsoft.com/expression/blend/2008" xmlns:helpers="using:Files.App.Helpers" xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" - Title="{helpers:ResourceString Name=NewShortcutDialogTitle}" + xmlns:navigationcontrolitems="using:Files.App.DataModels.NavigationControlItems" + Title="{helpers:ResourceString Name=ReorderSidebarItemsDialogText}" DefaultButton="Primary" IsPrimaryButtonEnabled="True" - PrimaryButtonText="True" - SecondaryButtonText="True" + PrimaryButtonCommand="{x:Bind ViewModel.PrimaryButtonCommand}" + PrimaryButtonText="{helpers:ResourceString Name=Save}" + RequestedTheme="{x:Bind helpers:ThemeHelper.RootTheme}" + SecondaryButtonText="{helpers:ResourceString Name=Cancel}" Style="{StaticResource DefaultContentDialogStyle}" mc:Ignorable="d"> @@ -28,14 +31,67 @@ - - - - + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/src/Files.App/Dialogs/ReorderSidebarItemsDialog.xaml.cs b/src/Files.App/Dialogs/ReorderSidebarItemsDialog.xaml.cs index 6f5a9bfc0a9e..068cd17fb9b5 100644 --- a/src/Files.App/Dialogs/ReorderSidebarItemsDialog.xaml.cs +++ b/src/Files.App/Dialogs/ReorderSidebarItemsDialog.xaml.cs @@ -1,8 +1,11 @@ +using Files.App.DataModels.NavigationControlItems; using Files.App.ViewModels.Dialogs; using Files.Backend.ViewModels.Dialogs; using Files.Shared.Enums; +using Microsoft.UI.Xaml; using Microsoft.UI.Xaml.Controls; using System; +using System.Diagnostics; using System.Threading.Tasks; namespace Files.App.Dialogs @@ -20,6 +23,28 @@ public ReorderSidebarItemsDialog() InitializeComponent(); } + private void ReorderUp_Click(object sender, RoutedEventArgs e) + { + if (sender is not Button clickButton || clickButton.DataContext is not LocationItem item) + return; + + int index = ViewModel.SidebarFavoriteItems.IndexOf(item) - 1 >= 0 + ? ViewModel.SidebarFavoriteItems.IndexOf(item) - 1 : ViewModel.SidebarFavoriteItems.IndexOf(item); + ViewModel.SidebarFavoriteItems.Remove(item); + ViewModel.SidebarFavoriteItems.Insert(index, item); + } + + private void ReorderDown_Click(object sender, RoutedEventArgs e) + { + if (sender is not Button clickButton || clickButton.DataContext is not LocationItem item) + return; + + int index = ViewModel.SidebarFavoriteItems.IndexOf(item) + 1 < ViewModel.SidebarFavoriteItems.Count + ? ViewModel.SidebarFavoriteItems.IndexOf(item) + 1 : ViewModel.SidebarFavoriteItems.IndexOf(item); + ViewModel.SidebarFavoriteItems.Remove(item); + ViewModel.SidebarFavoriteItems.Insert(index, item); + } + public new async Task ShowAsync() => (DialogResult)await base.ShowAsync(); } } \ No newline at end of file diff --git a/src/Files.App/ServicesImplementation/DialogService.cs b/src/Files.App/ServicesImplementation/DialogService.cs index f2ae22a90c49..40cfce2fbd7b 100644 --- a/src/Files.App/ServicesImplementation/DialogService.cs +++ b/src/Files.App/ServicesImplementation/DialogService.cs @@ -9,6 +9,7 @@ using System; using System.Collections.Generic; using System.ComponentModel; +using System.Diagnostics; using System.Threading.Tasks; using Windows.Foundation.Metadata; @@ -30,7 +31,7 @@ public DialogService() { typeof(DecompressArchiveDialogViewModel), () => new DecompressArchiveDialog() }, { typeof(SettingsDialogViewModel), () => new SettingsDialog() }, { typeof(CreateShortcutDialogViewModel), () => new CreateShortcutDialog() }, - { typeof(ReorderSidebarItemsDialog), () => new ReorderSidebarItemsDialog() } + { typeof(ReorderSidebarItemsDialogViewModel), () => new ReorderSidebarItemsDialog() } }; } @@ -63,7 +64,9 @@ public Task ShowDialogAsync(TViewModel viewModel) } catch (Exception ex) { - _ = ex; + App.Logger.Warn(ex, "Failed to show dialog"); + + Debugger.Break(); } return Task.FromResult(DialogResult.None); diff --git a/src/Files.App/ServicesImplementation/QuickAccessService.cs b/src/Files.App/ServicesImplementation/QuickAccessService.cs index c8eafb018c7f..2f762e2f7c64 100644 --- a/src/Files.App/ServicesImplementation/QuickAccessService.cs +++ b/src/Files.App/ServicesImplementation/QuickAccessService.cs @@ -73,22 +73,17 @@ public bool IsItemPinned(string folderPath) return App.QuickAccessManager.Model.FavoriteItems.Contains(folderPath); } - public async Task MoveTo(string toMove, string destination) + public async Task Save(string[] items) { - if (string.Equals(toMove, destination)) + if (Equals(items, App.QuickAccessManager.Model.FavoriteItems.ToArray())) return; App.QuickAccessManager.PinnedItemsWatcher.EnableRaisingEvents = false; - var index = App.QuickAccessManager.Model.FavoriteItems.IndexOf(destination); - var favoriteItemsCopy = new List(App.QuickAccessManager.Model.FavoriteItems); // Unpin every item that is below this index and then pin them all in order await UnpinFromSidebar(Array.Empty(), false); - favoriteItemsCopy.Remove(toMove); - favoriteItemsCopy.Insert(index, toMove); - - await PinToSidebar(favoriteItemsCopy.ToArray()); + await PinToSidebar(items); App.QuickAccessManager.PinnedItemsWatcher.EnableRaisingEvents = true; } } diff --git a/src/Files.App/Strings/en-US/Resources.resw b/src/Files.App/Strings/en-US/Resources.resw index 18d83ad80ddd..1fdd93f53111 100644 --- a/src/Files.App/Strings/en-US/Resources.resw +++ b/src/Files.App/Strings/en-US/Resources.resw @@ -2607,4 +2607,7 @@ Multiselect + + Reorder sidebar items + \ No newline at end of file diff --git a/src/Files.App/UserControls/SidebarControl.xaml b/src/Files.App/UserControls/SidebarControl.xaml index 5d7f8ac8e791..029f164753a5 100644 --- a/src/Files.App/UserControls/SidebarControl.xaml +++ b/src/Files.App/UserControls/SidebarControl.xaml @@ -62,7 +62,6 @@ DragEnter="NavigationViewItem_DragEnter" DragLeave="NavigationViewItem_DragLeave" DragOver="NavigationViewLocationItem_DragOver" - DragStarting="NavigationViewItem_DragStarting" Drop="NavigationViewLocationItem_Drop" IsExpanded="{x:Bind IsExpanded, Mode=TwoWay}" IsRightTapEnabled="True" diff --git a/src/Files.App/UserControls/SidebarControl.xaml.cs b/src/Files.App/UserControls/SidebarControl.xaml.cs index 6d6ff9b7ba61..4bbf787ed598 100644 --- a/src/Files.App/UserControls/SidebarControl.xaml.cs +++ b/src/Files.App/UserControls/SidebarControl.xaml.cs @@ -196,10 +196,10 @@ private List GetLocationItemMenuItems(INavigatio { new ContextMenuFlyoutItemViewModel() { - Text = "SidebarReorderItems".GetLocalizedResource(), + Text = "ReorderSidebarItemsDialogText".GetLocalizedResource(), Glyph = "\uE8D8", Command = ReorderItemsCommand, - ShowItem = options.ShowUnpinItem + ShowItem = isFavoriteItem || item.Section is SectionType.Favorites }, new ContextMenuFlyoutItemViewModel() { @@ -350,8 +350,7 @@ private async void ReorderItems() App.Logger.Warn("Reorder items dialog popup"); var result = await dialogService.ShowDialogAsync(dialog); - if (result == Shared.Enums.DialogResult.Primary) - App.Logger.Warn("Ok"); + App.Logger.Warn("Result: " + result.ToString()); } private async void OpenInNewPane() @@ -447,19 +446,6 @@ private async void Sidebar_PointerPressed(object sender, PointerRoutedEventArgs await NavigationHelpers.OpenPathInNewTab(item?.Path); } - private async void Sidebar_MoveItem(object sender, PointerRoutedEventArgs e) - { - var properties = e.GetCurrentPoint(null).Properties; - var icon = sender as FontIcon; - var context = icon?.DataContext; - if (!properties.IsLeftButtonPressed || context is not LocationItem item || item.Section is not SectionType.Favorites || item.IsHeader) - return; - - var navItem = icon?.FindAscendant(); - if (navItem is not null) - await navItem.StartDragAsync(e.GetCurrentPoint(navItem)); - } - private void PaneRoot_RightTapped(object sender, RightTappedRoutedEventArgs e) { var contextMenu = FlyoutBase.GetAttachedFlyout(this); @@ -493,16 +479,6 @@ private void NavigationViewItem_RightTapped(object sender, RightTappedRoutedEven e.Handled = true; } - private void NavigationViewItem_DragStarting(object sender, DragStartingEventArgs e) - { - if (sender is not NavigationViewItem nav || nav.DataContext is not LocationItem) - return; - - // Adding the original Location item dragged to the DragEvents data view - e.Data.Properties.Add("sourceLocationItem", nav); - e.AllowedOperations = DataPackageOperation.Move; - } - private void NavigationViewItem_DragEnter(object sender, DragEventArgs e) { var navView = sender as NavigationViewItem; @@ -648,11 +624,7 @@ private async void NavigationViewLocationItem_DragOver(object sender, DragEventA } CompleteDragEventArgs(e, captionText, operationType); } - } - else if ((e.DataView.Properties["sourceLocationItem"] as NavigationViewItem)?.DataContext is LocationItem sourceLocationItem - && !locationItem.IsHeader && !(locationItem.Section == SectionType.Library)) - NavigationViewLocationItem_DragOver_SetCaptions(locationItem, sourceLocationItem, e); - + } deferral.Complete(); } @@ -665,20 +637,6 @@ private DragEventArgs CompleteDragEventArgs(DragEventArgs e, string captionText, return e; } - private void NavigationViewLocationItem_DragOver_SetCaptions(LocationItem senderLocationItem, LocationItem sourceLocationItem, DragEventArgs e) - { - // If the location item is the same as the original dragged item - if (sourceLocationItem.CompareTo(senderLocationItem) == 0) - { - e.AcceptedOperation = DataPackageOperation.None; - e.DragUIOverride.IsCaptionVisible = false; - } - else - { - CompleteDragEventArgs(e, "MoveItemsDialogPrimaryButtonText".GetLocalizedResource(), DataPackageOperation.Move); - } - } - private async void NavigationViewLocationItem_Drop(object sender, DragEventArgs e) { if (lockFlag) @@ -723,10 +681,7 @@ private async void NavigationViewLocationItem_Drop(object sender, DragEventArgs isDropOnProcess = false; deferral.Complete(); - } - else if ((e.DataView.Properties["sourceLocationItem"] as NavigationViewItem)?.DataContext is LocationItem sourceLocationItem && !locationItem.IsHeader && !(locationItem.Section == SectionType.Library)) - QuickAccessService.MoveTo(sourceLocationItem.Path, locationItem.Path); - + } await Task.Yield(); lockFlag = false; diff --git a/src/Files.App/ViewModels/Dialogs/ReorderSidebarItemsDialogViewModel.cs b/src/Files.App/ViewModels/Dialogs/ReorderSidebarItemsDialogViewModel.cs index 5a2bdd98974c..12e8d12b63f1 100644 --- a/src/Files.App/ViewModels/Dialogs/ReorderSidebarItemsDialogViewModel.cs +++ b/src/Files.App/ViewModels/Dialogs/ReorderSidebarItemsDialogViewModel.cs @@ -1,16 +1,39 @@ using CommunityToolkit.Mvvm.ComponentModel; +using CommunityToolkit.Mvvm.DependencyInjection; +using CommunityToolkit.Mvvm.Input; +using Files.App.DataModels.NavigationControlItems; +using Files.App.Extensions; +using Files.App.Helpers; +using Files.App.ServicesImplementation; using System; using System.Collections.Generic; +using System.Collections.ObjectModel; using System.Linq; using System.Text; using System.Threading.Tasks; +using System.Windows.Input; namespace Files.App.ViewModels.Dialogs { public class ReorderSidebarItemsDialogViewModel : ObservableObject { - public string HeaderText = "Reorder sidebar items"; + private readonly IQuickAccessService quickAccessService = Ioc.Default.GetRequiredService(); - public ReorderSidebarItemsDialogViewModel() { } + public string HeaderText = "ReorderSidebarItemsDialogText".GetLocalizedResource(); + public ICommand PrimaryButtonCommand { get; private set; } + + public ObservableCollection SidebarFavoriteItems = new ObservableCollection(App.QuickAccessManager.Model.favoriteList + .Where(x => x is LocationItem loc && loc.Section is Filesystem.SectionType.Favorites && !loc.IsHeader) + .Cast()); + + public ReorderSidebarItemsDialogViewModel() + { + PrimaryButtonCommand = new RelayCommand(SaveChanges); + } + + public void SaveChanges() + { + quickAccessService.Save(SidebarFavoriteItems.Select(x => x.Path).ToArray()); + } } } diff --git a/src/Files.Backend/Services/IQuickAccessService.cs b/src/Files.Backend/Services/IQuickAccessService.cs index 6a1832eeded8..e4fd51ccddae 100644 --- a/src/Files.Backend/Services/IQuickAccessService.cs +++ b/src/Files.Backend/Services/IQuickAccessService.cs @@ -50,11 +50,10 @@ public interface IQuickAccessService bool IsItemPinned(string folderPath); /// - /// Moves a folder to a new location in the sidebar and in the quick access widget + /// Saves a state of favorite items in the sidebar /// - /// The path of the folder to be moved in the sidebar - /// The path of the folder over which to place the moved folder in the sidebar + /// The array of items to save /// - Task MoveTo(string toMove, string destination); + Task Save(string[] items); } } \ No newline at end of file From 7c028b9a695c8d5e94c3d03a0f866eb175b301a9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Pablo=20Garc=C3=ADa=20Ruiz?= Date: Mon, 6 Mar 2023 13:32:20 +0100 Subject: [PATCH 06/14] Add drag and drop (fixed) --- .../Dialogs/ReorderSidebarItemsDialog.xaml | 28 +++----- .../Dialogs/ReorderSidebarItemsDialog.xaml.cs | 71 +++++++++++++++---- .../UserControls/SidebarControl.xaml.cs | 5 +- .../ReorderSidebarItemsDialogViewModel.cs | 2 +- 4 files changed, 71 insertions(+), 35 deletions(-) diff --git a/src/Files.App/Dialogs/ReorderSidebarItemsDialog.xaml b/src/Files.App/Dialogs/ReorderSidebarItemsDialog.xaml index 66894d192932..fbcd33d049f3 100644 --- a/src/Files.App/Dialogs/ReorderSidebarItemsDialog.xaml +++ b/src/Files.App/Dialogs/ReorderSidebarItemsDialog.xaml @@ -44,8 +44,11 @@ - - + HorizontalAlignment="Right" + DataContext="{x:Bind}" + Glyph="" + PointerPressed="MoveItem" + Visibility="{x:Bind IsPinned}" /> diff --git a/src/Files.App/Dialogs/ReorderSidebarItemsDialog.xaml.cs b/src/Files.App/Dialogs/ReorderSidebarItemsDialog.xaml.cs index 068cd17fb9b5..af4ed0e5b6c6 100644 --- a/src/Files.App/Dialogs/ReorderSidebarItemsDialog.xaml.cs +++ b/src/Files.App/Dialogs/ReorderSidebarItemsDialog.xaml.cs @@ -1,12 +1,19 @@ +using CommunityToolkit.WinUI.UI; using Files.App.DataModels.NavigationControlItems; +using Files.App.Extensions; +using Files.App.Filesystem; +using Files.App.ServicesImplementation; using Files.App.ViewModels.Dialogs; using Files.Backend.ViewModels.Dialogs; using Files.Shared.Enums; using Microsoft.UI.Xaml; using Microsoft.UI.Xaml.Controls; +using Microsoft.UI.Xaml.Input; using System; using System.Diagnostics; using System.Threading.Tasks; +using Windows.ApplicationModel.DataTransfer; +using static Vanara.Windows.Shell.ShellFileOperationDialog; namespace Files.App.Dialogs { @@ -23,26 +30,66 @@ public ReorderSidebarItemsDialog() InitializeComponent(); } - private void ReorderUp_Click(object sender, RoutedEventArgs e) + private async void MoveItem(object sender, PointerRoutedEventArgs e) { - if (sender is not Button clickButton || clickButton.DataContext is not LocationItem item) + var properties = e.GetCurrentPoint(null).Properties; + var icon = sender as FontIcon; + if (!properties.IsLeftButtonPressed) return; - int index = ViewModel.SidebarFavoriteItems.IndexOf(item) - 1 >= 0 - ? ViewModel.SidebarFavoriteItems.IndexOf(item) - 1 : ViewModel.SidebarFavoriteItems.IndexOf(item); - ViewModel.SidebarFavoriteItems.Remove(item); - ViewModel.SidebarFavoriteItems.Insert(index, item); + var navItem = icon?.FindAscendant(); + if (navItem is not null) + await navItem.StartDragAsync(e.GetCurrentPoint(navItem)); } - private void ReorderDown_Click(object sender, RoutedEventArgs e) + private void NavigationViewItem_DragStarting(object sender, DragStartingEventArgs e) { - if (sender is not Button clickButton || clickButton.DataContext is not LocationItem item) + if (sender is not NavigationViewItem nav || nav.DataContext is not LocationItem) return; - int index = ViewModel.SidebarFavoriteItems.IndexOf(item) + 1 < ViewModel.SidebarFavoriteItems.Count - ? ViewModel.SidebarFavoriteItems.IndexOf(item) + 1 : ViewModel.SidebarFavoriteItems.IndexOf(item); - ViewModel.SidebarFavoriteItems.Remove(item); - ViewModel.SidebarFavoriteItems.Insert(index, item); + // Adding the original Location item dragged to the DragEvents data view + e.Data.Properties.Add("sourceLocationItem", nav); + e.AllowedOperations = DataPackageOperation.Move; + } + + + private async void NavigationViewItem_DragOver(object sender, DragEventArgs e) + { + if ((sender as NavigationViewItem)?.DataContext is not LocationItem locationItem) + return; + var deferral = e.GetDeferral(); + + if ((e.DataView.Properties["sourceLocationItem"] as NavigationViewItem)?.DataContext is LocationItem sourceLocationItem) + { + DragOver_SetCaptions(sourceLocationItem, locationItem, e); + } + + deferral.Complete(); + } + + private void DragOver_SetCaptions(LocationItem senderLocationItem, LocationItem sourceLocationItem, DragEventArgs e) + { + // If the location item is the same as the original dragged item + if (sourceLocationItem.CompareTo(senderLocationItem) == 0) + { + e.AcceptedOperation = DataPackageOperation.None; + e.DragUIOverride.IsCaptionVisible = false; + } + else + { + e.DragUIOverride.IsCaptionVisible = true; + e.DragUIOverride.Caption = "MoveItemsDialogPrimaryButtonText".GetLocalizedResource(); + e.AcceptedOperation = DataPackageOperation.Move; + } + } + + private void NavigationViewItem_Drop(object sender, DragEventArgs e) + { + if (sender is not NavigationViewItem navView || navView.DataContext is not LocationItem locationItem) + return; + + if ((e.DataView.Properties["sourceLocationItem"] as NavigationViewItem)?.DataContext is LocationItem sourceLocationItem) + ViewModel.SidebarFavoriteItems.Move(ViewModel.SidebarFavoriteItems.IndexOf(sourceLocationItem), ViewModel.SidebarFavoriteItems.IndexOf(locationItem)); } public new async Task ShowAsync() => (DialogResult)await base.ShowAsync(); diff --git a/src/Files.App/UserControls/SidebarControl.xaml.cs b/src/Files.App/UserControls/SidebarControl.xaml.cs index 4bbf787ed598..2da0b682c14d 100644 --- a/src/Files.App/UserControls/SidebarControl.xaml.cs +++ b/src/Files.App/UserControls/SidebarControl.xaml.cs @@ -347,10 +347,7 @@ private async void ReorderItems() { var dialog = new ReorderSidebarItemsDialogViewModel(); var dialogService = Ioc.Default.GetRequiredService(); - App.Logger.Warn("Reorder items dialog popup"); var result = await dialogService.ShowDialogAsync(dialog); - - App.Logger.Warn("Result: " + result.ToString()); } private async void OpenInNewPane() @@ -681,7 +678,7 @@ private async void NavigationViewLocationItem_Drop(object sender, DragEventArgs isDropOnProcess = false; deferral.Complete(); - } + } await Task.Yield(); lockFlag = false; diff --git a/src/Files.App/ViewModels/Dialogs/ReorderSidebarItemsDialogViewModel.cs b/src/Files.App/ViewModels/Dialogs/ReorderSidebarItemsDialogViewModel.cs index 12e8d12b63f1..14c7159c7113 100644 --- a/src/Files.App/ViewModels/Dialogs/ReorderSidebarItemsDialogViewModel.cs +++ b/src/Files.App/ViewModels/Dialogs/ReorderSidebarItemsDialogViewModel.cs @@ -22,7 +22,7 @@ public class ReorderSidebarItemsDialogViewModel : ObservableObject public string HeaderText = "ReorderSidebarItemsDialogText".GetLocalizedResource(); public ICommand PrimaryButtonCommand { get; private set; } - public ObservableCollection SidebarFavoriteItems = new ObservableCollection(App.QuickAccessManager.Model.favoriteList + public ObservableCollection SidebarFavoriteItems = new(App.QuickAccessManager.Model.favoriteList .Where(x => x is LocationItem loc && loc.Section is Filesystem.SectionType.Favorites && !loc.IsHeader) .Cast()); From 13f1fb9e1c79d961d6551114415449859d9ee9d6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Pablo=20Garc=C3=ADa=20Ruiz?= Date: Mon, 6 Mar 2023 13:46:39 +0100 Subject: [PATCH 07/14] Requested changes --- src/Files.App/Dialogs/ReorderSidebarItemsDialog.xaml | 5 +---- src/Files.App/Helpers/DynamicDialogFactory.cs | 3 --- 2 files changed, 1 insertion(+), 7 deletions(-) diff --git a/src/Files.App/Dialogs/ReorderSidebarItemsDialog.xaml b/src/Files.App/Dialogs/ReorderSidebarItemsDialog.xaml index fbcd33d049f3..07ed66a0cbdc 100644 --- a/src/Files.App/Dialogs/ReorderSidebarItemsDialog.xaml +++ b/src/Files.App/Dialogs/ReorderSidebarItemsDialog.xaml @@ -64,10 +64,7 @@ - + Date: Mon, 6 Mar 2023 23:09:27 +0100 Subject: [PATCH 08/14] Requested changes --- .../Dialogs/ReorderSidebarItemsDialog.xaml | 130 +++++++++--------- 1 file changed, 64 insertions(+), 66 deletions(-) diff --git a/src/Files.App/Dialogs/ReorderSidebarItemsDialog.xaml b/src/Files.App/Dialogs/ReorderSidebarItemsDialog.xaml index 07ed66a0cbdc..93068e6c71ce 100644 --- a/src/Files.App/Dialogs/ReorderSidebarItemsDialog.xaml +++ b/src/Files.App/Dialogs/ReorderSidebarItemsDialog.xaml @@ -16,71 +16,69 @@ Style="{StaticResource DefaultContentDialogStyle}" mc:Ignorable="d"> - - - - - - - - - - - + + + + + + + + + + - - - - - - - - - - - - - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file From 688021503f7fb2d5ca5746ae9a2a075041664e4f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Pablo=20Garc=C3=ADa=20Ruiz?= Date: Tue, 7 Mar 2023 15:48:36 +0100 Subject: [PATCH 09/14] Requested changes --- src/Files.App/UserControls/SidebarControl.xaml.cs | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/src/Files.App/UserControls/SidebarControl.xaml.cs b/src/Files.App/UserControls/SidebarControl.xaml.cs index 2da0b682c14d..e43947b00bec 100644 --- a/src/Files.App/UserControls/SidebarControl.xaml.cs +++ b/src/Files.App/UserControls/SidebarControl.xaml.cs @@ -194,13 +194,6 @@ private List GetLocationItemMenuItems(INavigatio return new List() { - new ContextMenuFlyoutItemViewModel() - { - Text = "ReorderSidebarItemsDialogText".GetLocalizedResource(), - Glyph = "\uE8D8", - Command = ReorderItemsCommand, - ShowItem = isFavoriteItem || item.Section is SectionType.Favorites - }, new ContextMenuFlyoutItemViewModel() { Text = "SideBarCreateNewLibrary/Text".GetLocalizedResource(), @@ -266,6 +259,13 @@ private List GetLocationItemMenuItems(INavigatio ShowItem = options.ShowUnpinItem || isDriveItemPinned }, new ContextMenuFlyoutItemViewModel() + { + Text = "ReorderSidebarItemsDialogText".GetLocalizedResource(), + Glyph = "\uE8D8", + Command = ReorderItemsCommand, + ShowItem = isFavoriteItem || item.Section is SectionType.Favorites + }, + new ContextMenuFlyoutItemViewModel() { Text = string.Format("SideBarHideSectionFromSideBar/Text".GetLocalizedResource(), rightClickedItem.Text), Glyph = "\uE77A", From 1a4959ad403e27a575961719f75f40e798dc8f49 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Pablo=20Garc=C3=ADa=20Ruiz?= Date: Wed, 8 Mar 2023 16:04:58 +0100 Subject: [PATCH 10/14] Fix + remove arrow in functions --- src/Files.App/DataModels/SidebarPinnedModel.cs | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/src/Files.App/DataModels/SidebarPinnedModel.cs b/src/Files.App/DataModels/SidebarPinnedModel.cs index 41aed0ec238c..8a24c4c22c67 100644 --- a/src/Files.App/DataModels/SidebarPinnedModel.cs +++ b/src/Files.App/DataModels/SidebarPinnedModel.cs @@ -178,12 +178,13 @@ public void RemoveStaleSidebarItems() // Remove unpinned items from favoriteList foreach (var childItem in Favorites) { - if (childItem is LocationItem item) + if (childItem is LocationItem item && !item.IsDefaultLocation && !FavoriteItems.Contains(item.Path)) { lock (favoriteList) { favoriteList.Remove(item); } + DataChanged?.Invoke(SectionType.Favorites, new NotifyCollectionChangedEventArgs(NotifyCollectionChangedAction.Remove, item)); } } @@ -192,9 +193,13 @@ public void RemoveStaleSidebarItems() } public async void LoadAsync(object? sender, FileSystemEventArgs e) - => await LoadAsync(); + { + await LoadAsync(); + } public async Task LoadAsync() - => await UpdateItemsWithExplorer(); + { + await UpdateItemsWithExplorer(); + } } } From 7753707e767dcff50e2d7bad88cb97a6a16d2c71 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Pablo=20Garc=C3=ADa=20Ruiz?= Date: Thu, 9 Mar 2023 13:45:36 +0100 Subject: [PATCH 11/14] Fix --- .../ServicesImplementation/QuickAccessService.cs | 12 ++++++------ src/Files.Backend/Services/IQuickAccessService.cs | 6 ++---- 2 files changed, 8 insertions(+), 10 deletions(-) diff --git a/src/Files.App/ServicesImplementation/QuickAccessService.cs b/src/Files.App/ServicesImplementation/QuickAccessService.cs index 2f762e2f7c64..2d8e2e81dbcd 100644 --- a/src/Files.App/ServicesImplementation/QuickAccessService.cs +++ b/src/Files.App/ServicesImplementation/QuickAccessService.cs @@ -34,12 +34,12 @@ public async Task PinToSidebar(string[] folderPaths) App.QuickAccessManager.UpdateQuickAccessWidget?.Invoke(this, new ModifyQuickAccessEventArgs(folderPaths, true)); } - public Task UnpinFromSidebar(string folderPath, bool syncItems = true) + public Task UnpinFromSidebar(string folderPath) { - return UnpinFromSidebar(new[] { folderPath }, syncItems); + return UnpinFromSidebar(new[] { folderPath }); } - public async Task UnpinFromSidebar(string[] folderPaths, bool syncItems = true) + public async Task UnpinFromSidebar(string[] folderPaths) { Type? shellAppType = Type.GetTypeFromProgID("Shell.Application"); object? shell = Activator.CreateInstance(shellAppType); @@ -62,8 +62,7 @@ await SafetyExtensions.IgnoreExceptions(async () => } } - if (syncItems) - await App.QuickAccessManager.Model.LoadAsync(); + await App.QuickAccessManager.Model.LoadAsync(); App.QuickAccessManager.UpdateQuickAccessWidget?.Invoke(this, new ModifyQuickAccessEventArgs(folderPaths, false)); } @@ -81,10 +80,11 @@ public async Task Save(string[] items) App.QuickAccessManager.PinnedItemsWatcher.EnableRaisingEvents = false; // Unpin every item that is below this index and then pin them all in order - await UnpinFromSidebar(Array.Empty(), false); + await UnpinFromSidebar(Array.Empty()); await PinToSidebar(items); App.QuickAccessManager.PinnedItemsWatcher.EnableRaisingEvents = true; + await App.QuickAccessManager.Model.LoadAsync(); } } } diff --git a/src/Files.Backend/Services/IQuickAccessService.cs b/src/Files.Backend/Services/IQuickAccessService.cs index e4fd51ccddae..d28f1fa780e9 100644 --- a/src/Files.Backend/Services/IQuickAccessService.cs +++ b/src/Files.Backend/Services/IQuickAccessService.cs @@ -30,17 +30,15 @@ public interface IQuickAccessService /// Unpins a folder from the quick access list /// /// The folder to unpin - /// Whether to sync the items with explorer /// - Task UnpinFromSidebar(string folderPath, bool syncItems = true); + Task UnpinFromSidebar(string folderPath); /// /// Unpins folders from the quick access list /// /// The array of folders to unpin - /// Whether to sync the items with explorer /// - Task UnpinFromSidebar(string[] folderPaths, bool syncItems = true); + Task UnpinFromSidebar(string[] folderPaths); /// /// Checks if a folder is pinned to the quick access list From d7178aedc0c2c3cffa2a1c3e7e19601ad0160add Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Pablo=20Garc=C3=ADa=20Ruiz?= Date: Sun, 12 Mar 2023 17:52:45 +0100 Subject: [PATCH 12/14] Test: Add ListView instead of NavigationView --- .../Dialogs/ReorderSidebarItemsDialog.xaml | 35 +++++++------------ .../Dialogs/ReorderSidebarItemsDialog.xaml.cs | 25 +++++++------ .../ReorderSidebarItemsDialogViewModel.cs | 1 + 3 files changed, 28 insertions(+), 33 deletions(-) diff --git a/src/Files.App/Dialogs/ReorderSidebarItemsDialog.xaml b/src/Files.App/Dialogs/ReorderSidebarItemsDialog.xaml index 93068e6c71ce..a5c4a2f287fc 100644 --- a/src/Files.App/Dialogs/ReorderSidebarItemsDialog.xaml +++ b/src/Files.App/Dialogs/ReorderSidebarItemsDialog.xaml @@ -26,33 +26,25 @@ - - - - + ItemsSource="{x:Bind ViewModel.SidebarFavoriteItems, Mode=OneWay}"> + - - + @@ -72,13 +64,10 @@ PointerPressed="MoveItem" Visibility="{x:Bind IsPinned}" /> - - - - - + + - - + + \ No newline at end of file diff --git a/src/Files.App/Dialogs/ReorderSidebarItemsDialog.xaml.cs b/src/Files.App/Dialogs/ReorderSidebarItemsDialog.xaml.cs index af4ed0e5b6c6..1d2e870098d7 100644 --- a/src/Files.App/Dialogs/ReorderSidebarItemsDialog.xaml.cs +++ b/src/Files.App/Dialogs/ReorderSidebarItemsDialog.xaml.cs @@ -13,7 +13,6 @@ using System.Diagnostics; using System.Threading.Tasks; using Windows.ApplicationModel.DataTransfer; -using static Vanara.Windows.Shell.ShellFileOperationDialog; namespace Files.App.Dialogs { @@ -37,14 +36,14 @@ private async void MoveItem(object sender, PointerRoutedEventArgs e) if (!properties.IsLeftButtonPressed) return; - var navItem = icon?.FindAscendant(); + var navItem = icon?.FindAscendant(); if (navItem is not null) await navItem.StartDragAsync(e.GetCurrentPoint(navItem)); } - private void NavigationViewItem_DragStarting(object sender, DragStartingEventArgs e) + private void ListViewItem_DragStarting(object sender, DragStartingEventArgs e) { - if (sender is not NavigationViewItem nav || nav.DataContext is not LocationItem) + if (sender is not ListViewItem nav || nav.DataContext is not LocationItem) return; // Adding the original Location item dragged to the DragEvents data view @@ -53,13 +52,13 @@ private void NavigationViewItem_DragStarting(object sender, DragStartingEventArg } - private async void NavigationViewItem_DragOver(object sender, DragEventArgs e) + private void ListViewItem_DragOver(object sender, DragEventArgs e) { - if ((sender as NavigationViewItem)?.DataContext is not LocationItem locationItem) + if ((sender as ListViewItem)?.DataContext is not LocationItem locationItem) return; var deferral = e.GetDeferral(); - if ((e.DataView.Properties["sourceLocationItem"] as NavigationViewItem)?.DataContext is LocationItem sourceLocationItem) + if ((e.DataView.Properties["sourceLocationItem"] as ListViewItem)?.DataContext is LocationItem sourceLocationItem) { DragOver_SetCaptions(sourceLocationItem, locationItem, e); } @@ -83,15 +82,21 @@ private void DragOver_SetCaptions(LocationItem senderLocationItem, LocationItem } } - private void NavigationViewItem_Drop(object sender, DragEventArgs e) + private void ListViewItem_Drop(object sender, DragEventArgs e) { - if (sender is not NavigationViewItem navView || navView.DataContext is not LocationItem locationItem) + if (sender is not ListViewItem navView || navView.DataContext is not LocationItem locationItem) return; - if ((e.DataView.Properties["sourceLocationItem"] as NavigationViewItem)?.DataContext is LocationItem sourceLocationItem) + if ((e.DataView.Properties["sourceLocationItem"] as ListViewItem)?.DataContext is LocationItem sourceLocationItem) ViewModel.SidebarFavoriteItems.Move(ViewModel.SidebarFavoriteItems.IndexOf(sourceLocationItem), ViewModel.SidebarFavoriteItems.IndexOf(locationItem)); } + private void DataContextChanged(object sender, EventArgs e) + { + App.Logger.Warn("sender: " + sender); + Debugger.Break(); + } + public new async Task ShowAsync() => (DialogResult)await base.ShowAsync(); } } \ No newline at end of file diff --git a/src/Files.App/ViewModels/Dialogs/ReorderSidebarItemsDialogViewModel.cs b/src/Files.App/ViewModels/Dialogs/ReorderSidebarItemsDialogViewModel.cs index 14c7159c7113..aec3fc1de364 100644 --- a/src/Files.App/ViewModels/Dialogs/ReorderSidebarItemsDialogViewModel.cs +++ b/src/Files.App/ViewModels/Dialogs/ReorderSidebarItemsDialogViewModel.cs @@ -28,6 +28,7 @@ public class ReorderSidebarItemsDialogViewModel : ObservableObject public ReorderSidebarItemsDialogViewModel() { + //App.Logger.Warn(string.Join(", ", SidebarFavoriteItems.Select(x => x.Path))); PrimaryButtonCommand = new RelayCommand(SaveChanges); } From 66abd83d7905f1977267a2c65de36fe3e4343321 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Pablo=20Garc=C3=ADa=20Ruiz?= <55754091+hecksmosis@users.noreply.github.com> Date: Wed, 15 Mar 2023 18:06:49 +0100 Subject: [PATCH 13/14] Requested changes --- src/Files.App/Files.App.csproj | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) diff --git a/src/Files.App/Files.App.csproj b/src/Files.App/Files.App.csproj index 47f5417e463e..6a67ff2f6973 100644 --- a/src/Files.App/Files.App.csproj +++ b/src/Files.App/Files.App.csproj @@ -68,7 +68,6 @@ - @@ -126,11 +125,8 @@ - - $(DefaultXamlRuntime) - $(DefaultXamlRuntime) - \ No newline at end of file + From b2dd2996efa587a16f063ec2dcd4a718ed306352 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Pablo=20Garc=C3=ADa=20Ruiz?= Date: Wed, 15 Mar 2023 18:36:09 +0100 Subject: [PATCH 14/14] Change ListViewItem to Grid --- .../Dialogs/ReorderSidebarItemsDialog.xaml | 43 ++++++++----------- .../Dialogs/ReorderSidebarItemsDialog.xaml.cs | 18 +++----- 2 files changed, 25 insertions(+), 36 deletions(-) diff --git a/src/Files.App/Dialogs/ReorderSidebarItemsDialog.xaml b/src/Files.App/Dialogs/ReorderSidebarItemsDialog.xaml index a5c4a2f287fc..836eb11bc81c 100644 --- a/src/Files.App/Dialogs/ReorderSidebarItemsDialog.xaml +++ b/src/Files.App/Dialogs/ReorderSidebarItemsDialog.xaml @@ -34,38 +34,33 @@ ItemsSource="{x:Bind ViewModel.SidebarFavoriteItems, Mode=OneWay}"> - - - - - - - - - - - - - - - - - + + + + + + + + + + + + diff --git a/src/Files.App/Dialogs/ReorderSidebarItemsDialog.xaml.cs b/src/Files.App/Dialogs/ReorderSidebarItemsDialog.xaml.cs index 1d2e870098d7..ab3533fc471e 100644 --- a/src/Files.App/Dialogs/ReorderSidebarItemsDialog.xaml.cs +++ b/src/Files.App/Dialogs/ReorderSidebarItemsDialog.xaml.cs @@ -36,14 +36,14 @@ private async void MoveItem(object sender, PointerRoutedEventArgs e) if (!properties.IsLeftButtonPressed) return; - var navItem = icon?.FindAscendant(); + var navItem = icon?.FindAscendant(); if (navItem is not null) await navItem.StartDragAsync(e.GetCurrentPoint(navItem)); } private void ListViewItem_DragStarting(object sender, DragStartingEventArgs e) { - if (sender is not ListViewItem nav || nav.DataContext is not LocationItem) + if (sender is not Grid nav || nav.DataContext is not LocationItem) return; // Adding the original Location item dragged to the DragEvents data view @@ -54,11 +54,11 @@ private void ListViewItem_DragStarting(object sender, DragStartingEventArgs e) private void ListViewItem_DragOver(object sender, DragEventArgs e) { - if ((sender as ListViewItem)?.DataContext is not LocationItem locationItem) + if ((sender as Grid)?.DataContext is not LocationItem locationItem) return; var deferral = e.GetDeferral(); - if ((e.DataView.Properties["sourceLocationItem"] as ListViewItem)?.DataContext is LocationItem sourceLocationItem) + if ((e.DataView.Properties["sourceLocationItem"] as Grid)?.DataContext is LocationItem sourceLocationItem) { DragOver_SetCaptions(sourceLocationItem, locationItem, e); } @@ -84,19 +84,13 @@ private void DragOver_SetCaptions(LocationItem senderLocationItem, LocationItem private void ListViewItem_Drop(object sender, DragEventArgs e) { - if (sender is not ListViewItem navView || navView.DataContext is not LocationItem locationItem) + if (sender is not Grid navView || navView.DataContext is not LocationItem locationItem) return; - if ((e.DataView.Properties["sourceLocationItem"] as ListViewItem)?.DataContext is LocationItem sourceLocationItem) + if ((e.DataView.Properties["sourceLocationItem"] as Grid)?.DataContext is LocationItem sourceLocationItem) ViewModel.SidebarFavoriteItems.Move(ViewModel.SidebarFavoriteItems.IndexOf(sourceLocationItem), ViewModel.SidebarFavoriteItems.IndexOf(locationItem)); } - private void DataContextChanged(object sender, EventArgs e) - { - App.Logger.Warn("sender: " + sender); - Debugger.Break(); - } - public new async Task ShowAsync() => (DialogResult)await base.ShowAsync(); } } \ No newline at end of file