Skip to content

Commit 2ebbb7e

Browse files
authored
Feature: Display recent folders in the folders widget (files-community#11155)
1 parent 721b5bd commit 2ebbb7e

File tree

15 files changed

+243
-118
lines changed

15 files changed

+243
-118
lines changed

src/Files.App/DataModels/NavigationControlItems/LocationItem.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,8 @@ public bool IsExpanded
5656

5757
public bool IsInvalid { get; set; } = false;
5858

59+
public bool IsPinned => App.QuickAccessManager.Model.FavoriteItems.Contains(path);
60+
5961
public SectionType Section { get; set; }
6062

6163
public ContextMenuOptions MenuOptions { get; set; }

src/Files.App/DataModels/SidebarPinnedModel.cs

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -75,12 +75,7 @@ public int IndexOfItem(INavigationControlItem locationItem)
7575
}
7676
}
7777

78-
/// <summary>
79-
/// Adds the item (from a path) to the navigation sidebar
80-
/// </summary>
81-
/// <param name="path">The path which to save</param>
82-
/// <returns>Task</returns>
83-
public async Task AddItemToSidebarAsync(string path)
78+
public async Task<LocationItem> CreateLocationItemFromPathAsync(string path)
8479
{
8580
var item = await FilesystemTasks.Wrap(() => DrivesManager.GetRootFromPathAsync(path));
8681
var res = await FilesystemTasks.Wrap(() => StorageFileExtensions.DangerousGetFolderFromPathAsync(path, item));
@@ -130,6 +125,18 @@ public async Task AddItemToSidebarAsync(string path)
130125
Debug.WriteLine($"Pinned item was invalid {res.ErrorCode}, item: {path}");
131126
}
132127

128+
return locationItem;
129+
}
130+
131+
/// <summary>
132+
/// Adds the item (from a path) to the navigation sidebar
133+
/// </summary>
134+
/// <param name="path">The path which to save</param>
135+
/// <returns>Task</returns>
136+
public async Task AddItemToSidebarAsync(string path)
137+
{
138+
var locationItem = await CreateLocationItemFromPathAsync(path);
139+
133140
AddLocationItemToSidebar(locationItem);
134141
}
135142

src/Files.App/Filesystem/QuickAccessManager.cs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
using CommunityToolkit.Mvvm.DependencyInjection;
22
using Files.App.DataModels;
33
using Files.App.ServicesImplementation;
4+
using Files.App.UserControls.Widgets;
45
using Files.Shared.Extensions;
56
using System;
67
using System.Collections.Generic;
@@ -16,7 +17,11 @@ namespace Files.App.Filesystem
1617
public sealed class QuickAccessManager
1718
{
1819
public FileSystemWatcher? PinnedItemsWatcher;
20+
1921
public event FileSystemEventHandler? PinnedItemsModified;
22+
23+
public EventHandler<ModifyQuickAccessEventArgs>? UpdateQuickAccessWidget;
24+
2025
public IQuickAccessService QuickAccessService { get; } = Ioc.Default.GetRequiredService<IQuickAccessService>();
2126

2227
public SidebarPinnedModel Model;

src/Files.App/Helpers/WidgetsHelpers.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,9 +37,9 @@ public static class WidgetsHelpers
3737

3838
public static bool TryGetIsWidgetSettingEnabled<TWidget>(IPreferencesSettingsService preferencesSettingsService) where TWidget : IWidgetItemModel
3939
{
40-
if (typeof(TWidget) == typeof(FolderWidget))
40+
if (typeof(TWidget) == typeof(QuickAccessWidget))
4141
{
42-
return preferencesSettingsService.ShowFoldersWidget;
42+
return preferencesSettingsService.ShowQuickAccessWidget;
4343
}
4444
if (typeof(TWidget) == typeof(DrivesWidget))
4545
{

src/Files.App/ServicesImplementation/QuickAccessService.cs

Lines changed: 15 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,37 +1,44 @@
1-
using Files.App.Shell;
1+
using Files.App.DataModels.NavigationControlItems;
2+
using Files.App.Filesystem;
3+
using Files.App.Shell;
4+
using Files.App.UserControls.Widgets;
5+
using Files.Shared;
26
using Files.Shared.Extensions;
37
using System;
48
using System.Collections.Generic;
59
using System.Linq;
10+
using System.Security.Permissions;
611
using System.Threading.Tasks;
712

813
namespace Files.App.ServicesImplementation
914
{
1015
internal class QuickAccessService : IQuickAccessService
1116
{
1217
private readonly static string guid = "::{679f85cb-0220-4080-b29b-5540cc05aab6}";
13-
14-
public async Task<List<string>> GetPinnedFoldersAsync()
18+
19+
public async Task<List<string>> GetPinnedFoldersAsync(bool getRecentItems = false)
1520
{
1621
var sidebarItems = (await Win32Shell.GetShellFolderAsync(guid, "Enumerate", 0, 10000)).Enumerate
1722
.Where(link => link.IsFolder)
1823
.Select(link => link.FilePath).ToList();
1924

20-
if (sidebarItems.Count > 4) // Avoid first opening crash #11139
25+
if (sidebarItems.Count > 4 && !getRecentItems) // Avoid first opening crash #11139
2126
sidebarItems.RemoveRange(sidebarItems.Count - 4, 4); // 4 is the number of recent items shown in explorer sidebar
2227

2328
return sidebarItems;
2429
}
25-
30+
2631
public async Task PinToSidebar(string folderPath)
2732
=> await PinToSidebar(new[] { folderPath });
2833

2934
public async Task PinToSidebar(string[] folderPaths)
3035
{
3136
await ContextMenu.InvokeVerb("pintohome", folderPaths);
3237
await App.QuickAccessManager.Model.LoadAsync();
38+
39+
App.QuickAccessManager.UpdateQuickAccessWidget?.Invoke(this, new ModifyQuickAccessEventArgs(folderPaths, true));
3340
}
34-
41+
3542
public async Task UnpinFromSidebar(string folderPath)
3643
=> await UnpinFromSidebar(new[] { folderPath });
3744

@@ -48,6 +55,8 @@ await SafetyExtensions.IgnoreExceptions(async () => {
4855
});
4956

5057
await App.QuickAccessManager.Model.LoadAsync();
58+
59+
App.QuickAccessManager.UpdateQuickAccessWidget?.Invoke(this, new ModifyQuickAccessEventArgs(folderPaths, false));
5160
}
5261
}
5362
}

src/Files.App/ServicesImplementation/Settings/PreferencesSettingsService.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,7 @@ public bool AlwaysOpenDualPaneInNewTab
8181
set => Set(value);
8282
}
8383

84-
public bool ShowFoldersWidget
84+
public bool ShowQuickAccessWidget
8585
{
8686
get => Get(true);
8787
set => Set(value);
@@ -194,7 +194,7 @@ protected override void RaiseOnSettingChangedEvent(object sender, SettingChanged
194194
case nameof(AlwaysOpenNewInstance):
195195
case nameof(IsDualPaneEnabled):
196196
case nameof(AlwaysOpenDualPaneInNewTab):
197-
case nameof(ShowFoldersWidget):
197+
case nameof(ShowQuickAccessWidget):
198198
case nameof(ShowRecentFilesWidget):
199199
case nameof(ShowDrivesWidget):
200200
case nameof(ShowBundlesWidget):

src/Files.App/Strings/en-US/Resources.resw

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2289,9 +2289,6 @@
22892289
<data name="DrivesWidgetAutomationProperties.Name" xml:space="preserve">
22902290
<value>Drives Widget</value>
22912291
</data>
2292-
<data name="FolderWidgetAutomationProperties.Name" xml:space="preserve">
2293-
<value>Folders Widget</value>
2294-
</data>
22952292
<data name="RecentFilesWidgetAutomationProperties.Name" xml:space="preserve">
22962293
<value>Recent Files Widget</value>
22972294
</data>
@@ -2900,6 +2897,9 @@
29002897
</data>
29012898
<data name="DisplayEditTagsMenu" xml:space="preserve">
29022899
<value>Display the edit tags flyout</value>
2900+
</data>
2901+
<data name="QuickAccess" xml:space="preserve">
2902+
<value>Quick access</value>
29032903
</data>
29042904
<data name="NetworkAuthenticationDialogMessage" xml:space="preserve">
29052905
<value>Enter your credentials to connect to: {0}</value>

src/Files.App/UserControls/Widgets/FolderWidget.xaml renamed to src/Files.App/UserControls/Widgets/QuickAccessWidget.xaml

Lines changed: 29 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
<UserControl
2-
x:Class="Files.App.UserControls.Widgets.FolderWidget"
2+
x:Class="Files.App.UserControls.Widgets.QuickAccessWidget"
33
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
44
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
55
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
@@ -72,10 +72,29 @@
7272
<FontIcon Glyph="&#xE737;" />
7373
</MenuFlyoutItem.Icon>
7474
</MenuFlyoutItem>
75+
<MenuFlyoutItem
76+
x:Name="PinToFavorites"
77+
Click="PinToFavorites_Click"
78+
DataContext="{x:Bind}"
79+
Text="{helpers:ResourceString Name=BaseLayoutItemContextFlyoutPinToFavorites/Text}"
80+
Visibility="Collapsed">
81+
<MenuFlyoutItem.Icon>
82+
<FontIcon Glyph="&#xE840;" />
83+
</MenuFlyoutItem.Icon>
84+
</MenuFlyoutItem>
85+
<MenuFlyoutItem
86+
x:Name="UnpinFromFavorites"
87+
Click="UnpinFromFavorites_Click"
88+
DataContext="{x:Bind}"
89+
Text="{helpers:ResourceString Name=BaseLayoutContextFlyoutUnpinFromFavorites/Text}"
90+
Visibility="Collapsed">
91+
<MenuFlyoutItem.Icon>
92+
<FontIcon Glyph="&#xE77A;" />
93+
</MenuFlyoutItem.Icon>
94+
</MenuFlyoutItem>
7595
<MenuFlyoutItem
7696
x:Name="Properties"
77-
x:Load="{x:Bind IsLibrary}"
78-
Click="OpenLibraryProperties_Click"
97+
Click="OpenProperties_Click"
7998
DataContext="{x:Bind}"
8099
Text="{helpers:ResourceString Name=BaseLayoutContextFlyoutPropertiesFolder/Text}">
81100
<MenuFlyoutItem.Icon>
@@ -85,7 +104,6 @@
85104
</MenuFlyout.Items>
86105
</MenuFlyout>
87106
</Button.ContextFlyout>
88-
89107
<Grid
90108
HorizontalAlignment="Stretch"
91109
VerticalAlignment="Stretch"
@@ -94,6 +112,13 @@
94112
<RowDefinition Height="*" />
95113
<RowDefinition Height="Auto" />
96114
</Grid.RowDefinitions>
115+
<FontIcon
116+
x:Name="PinIcon"
117+
HorizontalAlignment="Right"
118+
VerticalAlignment="Top"
119+
FontSize="12"
120+
Glyph="&#xE840;"
121+
x:Load="{x:Bind IsPinned, Mode=OneWay}" />
97122
<Image
98123
Grid.Row="0"
99124
Width="32"

0 commit comments

Comments
 (0)