-
-
Notifications
You must be signed in to change notification settings - Fork 2.5k
Code Quality: Added design and basic functionality for the upcoming Shelf feature #16673
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
Merged
Merged
Changes from all commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
4b0b85f
Added design and basic functionality for Shelf
d2dyno1 5cd2700
Localize
yaira2 a39e0f4
Improved xaml
yaira2 ce5b661
Fix icon transparency issues (Shelf and Tags)
d2dyno1 2e5a997
Localize string
d2dyno1 6bdb741
Improved xaml
yaira2 8eab222
Fix icon size
yaira2 f57a649
Added caption when drag & dropping items
yaira2 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,40 @@ | ||
| using Files.Shared.Utils; | ||
|
|
||
| namespace Files.App.Data.Items | ||
| { | ||
| [Bindable(true)] | ||
| public sealed partial class ShelfItem : ObservableObject, IWrapper<IStorable>, IAsyncInitialize | ||
| { | ||
| private readonly IImageService _imageService; | ||
| private readonly ICollection<ShelfItem> _sourceCollection; | ||
|
|
||
| [ObservableProperty] private IImage? _Icon; | ||
| [ObservableProperty] private string? _Name; | ||
| [ObservableProperty] private string? _Path; | ||
|
|
||
| /// <inheritdoc/> | ||
| public IStorable Inner { get; } | ||
|
|
||
| public ShelfItem(IStorable storable, ICollection<ShelfItem> sourceCollection, IImage? icon = null) | ||
| { | ||
| _imageService = Ioc.Default.GetRequiredService<IImageService>(); | ||
| _sourceCollection = sourceCollection; | ||
| Inner = storable; | ||
| Icon = icon; | ||
| Name = storable.Name; | ||
| Path = storable.Id; | ||
| } | ||
|
|
||
| /// <inheritdoc/> | ||
| public async Task InitAsync(CancellationToken cancellationToken = default) | ||
| { | ||
| Icon = await _imageService.GetIconAsync(Inner, cancellationToken); | ||
| } | ||
|
|
||
| [RelayCommand] | ||
| private void Remove() | ||
| { | ||
| _sourceCollection.Remove(this); | ||
| } | ||
| } | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,15 +1,103 @@ | ||
| // Copyright (c) Files Community | ||
| // Licensed under the MIT License. | ||
|
|
||
| using Microsoft.UI.Xaml; | ||
| using Microsoft.UI.Xaml.Controls; | ||
| using System.Runtime.InteropServices.ComTypes; | ||
| using System.Windows.Input; | ||
| using Vanara.PInvoke; | ||
yaira2 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| using Windows.ApplicationModel.DataTransfer; | ||
| using WinRT; | ||
|
|
||
| namespace Files.App.UserControls | ||
| { | ||
| public sealed partial class ShelfPane : UserControl | ||
| { | ||
| public ShelfPane() | ||
| { | ||
| // TODO: [Shelf] Remove once view model is connected | ||
| ItemsSource = new ObservableCollection<ShelfItem>(); | ||
|
|
||
| InitializeComponent(); | ||
| } | ||
|
|
||
| private void Shelf_DragOver(object sender, DragEventArgs e) | ||
| { | ||
| if (!FilesystemHelpers.HasDraggedStorageItems(e.DataView)) | ||
| return; | ||
|
|
||
| e.Handled = true; | ||
| e.DragUIOverride.Caption = Strings.AddToShelf.GetLocalizedResource(); | ||
| e.AcceptedOperation = DataPackageOperation.Link; | ||
| } | ||
|
|
||
| private async void Shelf_Drop(object sender, DragEventArgs e) | ||
| { | ||
| if (ItemsSource is null) | ||
| return; | ||
|
|
||
| // Get items | ||
| var storageService = Ioc.Default.GetRequiredService<IStorageService>(); | ||
| var storageItems = (await FilesystemHelpers.GetDraggedStorageItems(e.DataView)).ToArray(); | ||
|
|
||
| // Add to list | ||
| foreach (var item in storageItems) | ||
| { | ||
| var storable = item switch | ||
| { | ||
| StorageFileWithPath => (IStorable?)await storageService.TryGetFileAsync(item.Path), | ||
| StorageFolderWithPath => (IStorable?)await storageService.TryGetFolderAsync(item.Path), | ||
| _ => null | ||
| }; | ||
|
|
||
| if (storable is null) | ||
| continue; | ||
|
|
||
| var shelfItem = new ShelfItem(storable, ItemsSource); | ||
| _ = shelfItem.InitAsync(); | ||
|
|
||
| ItemsSource.Add(shelfItem); | ||
| } | ||
| } | ||
|
|
||
| private void ListView_DragItemsStarting(object sender, DragItemsStartingEventArgs e) | ||
| { | ||
| if (ItemsSource is null) | ||
| return; | ||
|
|
||
| var shellItemList = SafetyExtensions.IgnoreExceptions(() => ItemsSource.Select(x => new Vanara.Windows.Shell.ShellItem(x.Inner.Id)).ToArray()); | ||
| if (shellItemList?[0].FileSystemPath is not null) | ||
| { | ||
| var iddo = shellItemList[0].Parent?.GetChildrenUIObjects<IDataObject>(HWND.NULL, shellItemList); | ||
| if (iddo is null) | ||
| return; | ||
|
|
||
| shellItemList.ForEach(x => x.Dispose()); | ||
| var dataObjectProvider = e.Data.As<Shell32.IDataObjectProvider>(); | ||
| dataObjectProvider.SetDataObject(iddo); | ||
| } | ||
| else | ||
| { | ||
| // Only support IStorageItem capable paths | ||
| var storageItems = ItemsSource.Select(x => VirtualStorageItem.FromPath(x.Inner.Id)); | ||
| e.Data.SetStorageItems(storageItems, false); | ||
| } | ||
| } | ||
|
|
||
| public IList<ShelfItem>? ItemsSource | ||
| { | ||
| get => (IList<ShelfItem>?)GetValue(ItemsSourceProperty); | ||
| set => SetValue(ItemsSourceProperty, value); | ||
| } | ||
| public static readonly DependencyProperty ItemsSourceProperty = | ||
| DependencyProperty.Register(nameof(ItemsSource), typeof(IList<ShelfItem>), typeof(ShelfPane), new PropertyMetadata(null)); | ||
|
|
||
| public ICommand? ClearCommand | ||
| { | ||
| get => (ICommand?)GetValue(ClearCommandProperty); | ||
| set => SetValue(ClearCommandProperty, value); | ||
| } | ||
| public static readonly DependencyProperty ClearCommandProperty = | ||
| DependencyProperty.Register(nameof(ClearCommand), typeof(ICommand), typeof(ShelfPane), new PropertyMetadata(null)); | ||
| } | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,14 @@ | ||
| namespace Files.Shared.Utils | ||
| { | ||
| /// <summary> | ||
| /// Wraps and exposes <typeparamref name="T"/> implementation for access. | ||
| /// </summary> | ||
| /// <typeparam name="T">The wrapped type.</typeparam> | ||
| public interface IWrapper<out T> | ||
| { | ||
| /// <summary> | ||
| /// Gets the inner member wrapped by the implementation. | ||
| /// </summary> | ||
| T Inner { get; } | ||
| } | ||
| } |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.