Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature: Added support for reordering items in the sidebar #11456

Merged
merged 47 commits into from
Mar 15, 2023
Merged
Show file tree
Hide file tree
Changes from 41 commits
Commits
Show all changes
47 commits
Select commit Hold shift + click to select a range
99394f5
Add move items to sidebar
hecksmosis Feb 24, 2023
e737769
Merge branch 'main' into add_move_in_sidebar
hecksmosis Feb 24, 2023
96fb86b
Merge branch 'main' into add_move_in_sidebar
yaira2 Feb 24, 2023
ddb2cdc
Merge branch 'main' into add_move_in_sidebar
yaira2 Feb 24, 2023
af99ff3
Requested changes
hecksmosis Feb 25, 2023
b495bae
Merge branch 'main' into add_move_in_sidebar
hecksmosis Feb 26, 2023
e1d3e08
Merge branch 'main' into add_move_in_sidebar
yaira2 Feb 26, 2023
22cf956
Merge branch 'main' into add_move_in_sidebar
hecksmosis Feb 27, 2023
e8df7cb
[WIP]
hecksmosis Feb 27, 2023
bb90ab5
[WIP]
hecksmosis Feb 27, 2023
19a45e3
Merge branch 'add_move_in_sidebar' of https://github.com/hecksmosis/F…
hecksmosis Feb 27, 2023
20af668
Merge branch 'main' of https://github.com/files-community/Files into …
hecksmosis Mar 1, 2023
b16528f
Merge branch 'main' into add_move_in_sidebar
hecksmosis Mar 3, 2023
e6715ec
Add dialog for reordering sidebar items
hecksmosis Mar 3, 2023
eb77d08
Merge branch 'add_move_in_sidebar' of https://github.com/hecksmosis/F…
hecksmosis Mar 3, 2023
3ee0216
Merge branch 'main' into add_move_in_sidebar
hecksmosis Mar 3, 2023
b3091ea
Merge branch 'main' into add_move_in_sidebar
hecksmosis Mar 6, 2023
7c028b9
Add drag and drop (fixed)
hecksmosis Mar 6, 2023
2c64099
Merge branch 'add_move_in_sidebar' of https://github.com/hecksmosis/F…
hecksmosis Mar 6, 2023
13f1fb9
Requested changes
hecksmosis Mar 6, 2023
07e25d6
Requested changes
hecksmosis Mar 6, 2023
c10e35b
Merge branch 'main' into add_move_in_sidebar
hecksmosis Mar 6, 2023
6880215
Requested changes
hecksmosis Mar 7, 2023
37cf1fe
Merge branch 'main' into add_move_in_sidebar
hecksmosis Mar 7, 2023
6af86a7
Merge branch 'add_move_in_sidebar' of https://github.com/hecksmosis/F…
hecksmosis Mar 7, 2023
250eedf
Merge branch 'main' into add_move_in_sidebar
hecksmosis Mar 8, 2023
84bcbe6
Merge branch 'main' into add_move_in_sidebar
hecksmosis Mar 8, 2023
1a4959a
Fix + remove arrow in functions
hecksmosis Mar 8, 2023
d615ba1
Merge branch 'add_move_in_sidebar' of https://github.com/hecksmosis/F…
hecksmosis Mar 8, 2023
50671c2
Merge branch 'main' into add_move_in_sidebar
hecksmosis Mar 9, 2023
7753707
Fix
hecksmosis Mar 9, 2023
68ca1db
Merge branch 'add_move_in_sidebar' of https://github.com/hecksmosis/F…
hecksmosis Mar 9, 2023
b68e83c
Merge branch 'main' into add_move_in_sidebar
hecksmosis Mar 10, 2023
55c36ee
Merge branch 'main' into add_move_in_sidebar
hecksmosis Mar 12, 2023
d7178ae
Test: Add ListView instead of NavigationView
hecksmosis Mar 12, 2023
e1e719a
Merge branch 'add_move_in_sidebar' of https://github.com/hecksmosis/F…
hecksmosis Mar 12, 2023
5f5cf80
Merge branch 'main' into add_move_in_sidebar
hecksmosis Mar 12, 2023
12dcf1b
Merge branch 'main' into add_move_in_sidebar
hecksmosis Mar 12, 2023
055dcc2
Merge branch 'main' into add_move_in_sidebar
hecksmosis Mar 12, 2023
32d6376
Merge branch 'main' into add_move_in_sidebar
hecksmosis Mar 14, 2023
4809596
Merge branch 'main' into add_move_in_sidebar
yaira2 Mar 15, 2023
66abd83
Requested changes
hecksmosis Mar 15, 2023
a83ac77
Merge branch 'main' into add_move_in_sidebar
hecksmosis Mar 15, 2023
b2dd299
Change ListViewItem to Grid
hecksmosis Mar 15, 2023
15c0873
Merge branch 'add_move_in_sidebar' of https://github.com/hecksmosis/F…
hecksmosis Mar 15, 2023
1aa7f4a
Merge branch 'main' into add_move_in_sidebar
hecksmosis Mar 15, 2023
bf8c1c2
Merge branch 'main' into add_move_in_sidebar
hecksmosis Mar 15, 2023
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -173,7 +173,6 @@ public static async Task<DriveItem> CreateFromPropertiesAsync(StorageFolder root
ShowProperties = true
};
item.Path = string.IsNullOrEmpty(root.Path) ? $"\\\\?\\{root.Name}\\" : root.Path;
App.Logger.Warn(item.Path);
item.DeviceID = deviceId;
item.Root = root;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,8 @@ public bool IsExpanded

public ContextMenuOptions MenuOptions { get; set; }

public bool IsHeader { get; set; }

public int CompareTo(INavigationControlItem other)
=> Text.CompareTo(other.Text);

Expand Down
6 changes: 4 additions & 2 deletions src/Files.App/DataModels/SidebarPinnedModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ public class SidebarPinnedModel

public List<string> FavoriteItems { get; set; } = new List<string>();

private readonly List<INavigationControlItem> favoriteList = new();
public readonly List<INavigationControlItem> favoriteList = new();

[JsonIgnore]
public IReadOnlyList<INavigationControlItem> Favorites
Expand Down Expand Up @@ -205,6 +205,8 @@ public async void LoadAsync(object? sender, FileSystemEventArgs e)
}

public async Task LoadAsync()
=> await UpdateItemsWithExplorer();
{
await UpdateItemsWithExplorer();
}
}
}
73 changes: 73 additions & 0 deletions src/Files.App/Dialogs/ReorderSidebarItemsDialog.xaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
<ContentDialog
x:Class="Files.App.Dialogs.ReorderSidebarItemsDialog"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:helpers="using:Files.App.Helpers"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:navigationcontrolitems="using:Files.App.DataModels.NavigationControlItems"
Title="{helpers:ResourceString Name=ReorderSidebarItemsDialogText}"
DefaultButton="Primary"
IsPrimaryButtonEnabled="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">

<Grid
x:Name="DestinationPathGrid"
ColumnSpacing="8"
RowSpacing="8">
<Grid.ColumnDefinitions>
<ColumnDefinition />
<ColumnDefinition Width="Auto" />
</Grid.ColumnDefinitions>
<Grid.RowDefinitions>
<RowDefinition Height="Auto" />
</Grid.RowDefinitions>

<ListView
x:Name="SidebarNavView"
Grid.Row="1"
ItemsSource="{x:Bind ViewModel.SidebarFavoriteItems, Mode=OneWay}">
<ListView.ItemTemplate>
<DataTemplate x:DataType="navigationcontrolitems:LocationItem">
<ListViewItem
AllowDrop="True"
AutomationProperties.AutomationId="{x:Bind Text}"
CanDrag="True"
DataContext="{x:Bind}"
DragOver="ListViewItem_DragOver"
DragStarting="ListViewItem_DragStarting"
Drop="ListViewItem_Drop"
Tag="{x:Bind Path}"
ToolTipService.ToolTip="{x:Bind ToolTipText, Mode=OneWay}">
<ListViewItem.Content>
<Grid>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="*" />
<ColumnDefinition Width="Auto" />
<ColumnDefinition Width="Auto" />
</Grid.ColumnDefinitions>
<Grid.RowDefinitions>
<RowDefinition Height="Auto" />
<RowDefinition Height="Auto" />
</Grid.RowDefinitions>
<TextBlock Grid.RowSpan="2" Text="{x:Bind Text}" />
<FontIcon
Grid.Row="1"
HorizontalAlignment="Right"
DataContext="{x:Bind}"
Glyph="&#xE76F;"
PointerPressed="MoveItem"
Visibility="{x:Bind IsPinned}" />
</Grid>
</ListViewItem.Content>
</ListViewItem>
</DataTemplate>
</ListView.ItemTemplate>
</ListView>
</Grid>
</ContentDialog>
102 changes: 102 additions & 0 deletions src/Files.App/Dialogs/ReorderSidebarItemsDialog.xaml.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,102 @@
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;

namespace Files.App.Dialogs
{
public sealed partial class ReorderSidebarItemsDialog : ContentDialog, IDialog<ReorderSidebarItemsDialogViewModel>
{
public ReorderSidebarItemsDialogViewModel ViewModel
yaira2 marked this conversation as resolved.
Show resolved Hide resolved
{
get => (ReorderSidebarItemsDialogViewModel)DataContext;
set => DataContext = value;
}

public ReorderSidebarItemsDialog()
{
InitializeComponent();
}

private async void MoveItem(object sender, PointerRoutedEventArgs e)
{
var properties = e.GetCurrentPoint(null).Properties;
var icon = sender as FontIcon;
if (!properties.IsLeftButtonPressed)
return;

var navItem = icon?.FindAscendant<ListViewItem>();
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)
return;

// Adding the original Location item dragged to the DragEvents data view
e.Data.Properties.Add("sourceLocationItem", nav);
e.AllowedOperations = DataPackageOperation.Move;
}


private void ListViewItem_DragOver(object sender, DragEventArgs e)
{
if ((sender as ListViewItem)?.DataContext is not LocationItem locationItem)
return;
var deferral = e.GetDeferral();

if ((e.DataView.Properties["sourceLocationItem"] as ListViewItem)?.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 ListViewItem_Drop(object sender, DragEventArgs e)
{
if (sender is not ListViewItem navView || navView.DataContext is not LocationItem locationItem)
return;

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<DialogResult> ShowAsync() => (DialogResult)await base.ShowAsync();
}
}
4 changes: 4 additions & 0 deletions src/Files.App/Files.App.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,7 @@
<Content Remove="Assets\FilesHome.png" />
</ItemGroup>
<ItemGroup>
<None Remove="Dialogs\ReorderSidebarItemsDialog.xaml" />
<None Remove="UserControls\OpacityIcon.xaml" />
yaira2 marked this conversation as resolved.
Show resolved Hide resolved
</ItemGroup>
<ItemGroup>
Expand Down Expand Up @@ -125,6 +126,9 @@
<TrimmerRootAssembly Include="CommunityToolkit.WinUI.UI.Controls.Primitives" />
</ItemGroup>
<ItemGroup>
<Page Update="Dialogs\ReorderSidebarItemsDialog.xaml">
<XamlRuntime>$(DefaultXamlRuntime)</XamlRuntime>
</Page>
yaira2 marked this conversation as resolved.
Show resolved Hide resolved
<Page Update="UserControls\OpacityIcon.xaml">
<XamlRuntime>$(DefaultXamlRuntime)</XamlRuntime>
</Page>
Expand Down
8 changes: 6 additions & 2 deletions src/Files.App/ServicesImplementation/DialogService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Diagnostics;
using System.Threading.Tasks;
using Windows.Foundation.Metadata;

Expand All @@ -29,7 +30,8 @@ public DialogService()
{ typeof(FileSystemDialogViewModel), () => new FilesystemOperationDialog() },
{ typeof(DecompressArchiveDialogViewModel), () => new DecompressArchiveDialog() },
{ typeof(SettingsDialogViewModel), () => new SettingsDialog() },
{ typeof(CreateShortcutDialogViewModel), () => new CreateShortcutDialog() }
{ typeof(CreateShortcutDialogViewModel), () => new CreateShortcutDialog() },
{ typeof(ReorderSidebarItemsDialogViewModel), () => new ReorderSidebarItemsDialog() }
};
}

Expand Down Expand Up @@ -62,7 +64,9 @@ public Task<DialogResult> ShowDialogAsync<TViewModel>(TViewModel viewModel)
}
catch (Exception ex)
{
_ = ex;
App.Logger.Warn(ex, "Failed to show dialog");

Debugger.Break();
}

return Task.FromResult(DialogResult.None);
Expand Down
43 changes: 35 additions & 8 deletions src/Files.App/ServicesImplementation/QuickAccessService.cs
Original file line number Diff line number Diff line change
@@ -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;

Expand All @@ -23,32 +20,47 @@ public async Task<IEnumerable<ShellFileItem>> GetPinnedFoldersAsync()
}

public Task PinToSidebar(string folderPath)
=> PinToSidebar(new[] { folderPath });
{
return PinToSidebar(new[] { 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 });
{
return UnpinFromSidebar(new[] { folderPath });
}

public async Task UnpinFromSidebar(string[] folderPaths)
{
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())
{
if (folderPaths.Contains((string)fi.Path)
|| (string.Equals(fi.Path, "::{645FF040-5081-101B-9F08-00AA002F954E}") && folderPaths.Contains(Constants.CommonPaths.RecycleBinPath)))
await SafetyExtensions.IgnoreExceptions(async () => {
{
await SafetyExtensions.IgnoreExceptions(async () =>
{
await fi.InvokeVerb("unpinfromhome");
});
}
}

await App.QuickAccessManager.Model.LoadAsync();

Expand All @@ -59,5 +71,20 @@ public bool IsItemPinned(string folderPath)
{
return App.QuickAccessManager.Model.FavoriteItems.Contains(folderPath);
}

public async Task Save(string[] items)
{
if (Equals(items, App.QuickAccessManager.Model.FavoriteItems.ToArray()))
return;

App.QuickAccessManager.PinnedItemsWatcher.EnableRaisingEvents = false;

// Unpin every item that is below this index and then pin them all in order
await UnpinFromSidebar(Array.Empty<string>());

await PinToSidebar(items);
App.QuickAccessManager.PinnedItemsWatcher.EnableRaisingEvents = true;
await App.QuickAccessManager.Model.LoadAsync();
}
}
}
3 changes: 3 additions & 0 deletions src/Files.App/Strings/en-US/Resources.resw
Original file line number Diff line number Diff line change
Expand Up @@ -2595,6 +2595,9 @@
<data name="MultiSelect" xml:space="preserve">
<value>Multiselect</value>
</data>
<data name="ReorderSidebarItemsDialogText" xml:space="preserve">
<value>Reorder sidebar items</value>
</data>
<data name="Hashes" xml:space="preserve">
<value>Hashes</value>
</data>
Expand Down
1 change: 0 additions & 1 deletion src/Files.App/UserControls/SidebarControl.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
Loading