-
-
Notifications
You must be signed in to change notification settings - Fork 2.2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
18 changed files
with
541 additions
and
544 deletions.
There are no files selected for viewing
This file contains 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 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 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
58 changes: 58 additions & 0 deletions
58
src/Files.App/Data/Contracts/IWindowsRecentItemsService.cs
This file contains 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,58 @@ | ||
// Copyright (c) 2024 Files Community | ||
// Licensed under the MIT License. See the LICENSE. | ||
|
||
using System.Collections.Specialized; | ||
|
||
namespace Files.App.Data.Contracts | ||
{ | ||
/// <summary> | ||
/// Provides manager of recent files and folders of File Explorer on Windows. | ||
/// </summary> | ||
public interface IWindowsRecentItemsService | ||
{ | ||
/// <summary> | ||
/// Gets recent files of File Explorer. | ||
/// </summary> | ||
IReadOnlyList<RecentItem> RecentFiles { get; } | ||
|
||
/// <summary> | ||
/// Gets recent folders of File Explorer. | ||
/// </summary> | ||
IReadOnlyList<RecentItem> RecentFolders { get; } | ||
|
||
/// <summary> | ||
/// Gets invoked when recent files of File Explorer have changed. | ||
/// </summary> | ||
event EventHandler<NotifyCollectionChangedEventArgs>? RecentFilesChanged; | ||
|
||
/// <summary> | ||
/// Gets invoked when recent folders of File Explorer have changed. | ||
/// </summary> | ||
event EventHandler<NotifyCollectionChangedEventArgs>? RecentFoldersChanged; | ||
|
||
/// <summary> | ||
/// Updates recent files of File Explorer. | ||
/// </summary> | ||
Task<bool> UpdateRecentFilesAsync(); | ||
|
||
/// <summary> | ||
/// Updates recent folders of File Explorer. | ||
/// </summary> | ||
Task<bool> UpdateRecentFoldersAsync(); | ||
|
||
/// <summary> | ||
/// Adds a recent file for File Explorer. | ||
/// </summary> | ||
bool Add(string path); | ||
|
||
/// <summary> | ||
/// Removes a recent folder for File Explorer. | ||
/// </summary> | ||
bool Remove(RecentItem item); | ||
|
||
/// <summary> | ||
/// Clears recent files and folders of File Explorer. | ||
/// </summary> | ||
bool Clear(); | ||
} | ||
} |
This file contains 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,65 @@ | ||
// Copyright (c) 2024 Files Community | ||
// Licensed under the MIT License. See the LICENSE. | ||
|
||
using Microsoft.UI.Xaml.Media.Imaging; | ||
using Windows.Win32; | ||
using Windows.Win32.UI.Shell; | ||
|
||
namespace Files.App.Data.Items | ||
{ | ||
/// <summary> | ||
/// Represents an item for recent item of File Explorer on Windows. | ||
/// </summary> | ||
public sealed class RecentItem : WidgetCardItem, IEquatable<RecentItem>, IDisposable | ||
{ | ||
private BitmapImage? _Icon; | ||
/// <summary> | ||
/// Gets or sets thumbnail icon of the recent item. | ||
/// </summary> | ||
public BitmapImage? Icon | ||
{ | ||
get => _Icon; | ||
set => SetProperty(ref _Icon, value); | ||
} | ||
|
||
/// <summary> | ||
/// Gets or sets name of the recent item. | ||
/// </summary> | ||
public required string Name { get; set; } | ||
|
||
/// <summary> | ||
/// Gets or sets target path of the recent item. | ||
/// </summary> | ||
public required DateTime LastModified { get; set; } | ||
|
||
/// <summary> | ||
/// Gets or initializes PIDL of the recent item. | ||
/// </summary> | ||
/// <remarks> | ||
/// This has to be removed in the future. | ||
/// </remarks> | ||
public unsafe required ComPtr<IShellItem> ShellItem { get; init; } | ||
|
||
/// <summary> | ||
/// Loads thumbnail icon of the recent item. | ||
/// </summary> | ||
/// <returns></returns> | ||
public async Task LoadRecentItemIconAsync() | ||
{ | ||
var result = await FileThumbnailHelper.GetIconAsync(Path, Constants.ShellIconSizes.Small, false, IconOptions.UseCurrentScale); | ||
|
||
var bitmapImage = await result.ToBitmapAsync(); | ||
if (bitmapImage is not null) | ||
Icon = bitmapImage; | ||
} | ||
|
||
public override int GetHashCode() => (Path, Name).GetHashCode(); | ||
public override bool Equals(object? other) => other is RecentItem item && Equals(item); | ||
public bool Equals(RecentItem? other) => other is not null && other.Name == Name && other.Path == Path; | ||
|
||
public unsafe void Dispose() | ||
{ | ||
ShellItem.Dispose(); | ||
} | ||
} | ||
} |
This file contains 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 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 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 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 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
Oops, something went wrong.