Skip to content
Merged
Show file tree
Hide file tree
Changes from 5 commits
Commits
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 @@ -56,6 +56,7 @@ public bool IsExpanded

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

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

public ContextMenuOptions MenuOptions { get; set; }
Expand Down
19 changes: 13 additions & 6 deletions src/Files.App/DataModels/SidebarPinnedModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -75,12 +75,7 @@ public int IndexOfItem(INavigationControlItem locationItem)
}
}

/// <summary>
/// Adds the item (from a path) to the navigation sidebar
/// </summary>
/// <param name="path">The path which to save</param>
/// <returns>Task</returns>
public async Task AddItemToSidebarAsync(string path)
public async Task<LocationItem> CreateLocationItemFromPathAsync(string path)
{
var item = await FilesystemTasks.Wrap(() => DrivesManager.GetRootFromPathAsync(path));
var res = await FilesystemTasks.Wrap(() => StorageFileExtensions.DangerousGetFolderFromPathAsync(path, item));
Expand Down Expand Up @@ -130,6 +125,18 @@ public async Task AddItemToSidebarAsync(string path)
Debug.WriteLine($"Pinned item was invalid {res.ErrorCode}, item: {path}");
}

return locationItem;
}

/// <summary>
/// Adds the item (from a path) to the navigation sidebar
/// </summary>
/// <param name="path">The path which to save</param>
/// <returns>Task</returns>
public async Task AddItemToSidebarAsync(string path)
{
var locationItem = await CreateLocationItemFromPathAsync(path);

AddLocationItemToSidebar(locationItem);
}

Expand Down
2 changes: 2 additions & 0 deletions src/Files.App/Filesystem/QuickAccessManager.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
using CommunityToolkit.Mvvm.DependencyInjection;
using Files.App.DataModels;
using Files.App.ServicesImplementation;
using Files.App.UserControls.Widgets;
using Files.Shared.Extensions;
using System;
using System.Collections.Generic;
Expand All @@ -17,6 +18,7 @@ public sealed class QuickAccessManager
{
public FileSystemWatcher? PinnedItemsWatcher;
public event FileSystemEventHandler? PinnedItemsModified;
public EventHandler<ModifyQuickAccessEventArgs>? UpdateFolderWidget;
public IQuickAccessService QuickAccessService { get; } = Ioc.Default.GetRequiredService<IQuickAccessService>();

public SidebarPinnedModel Model;
Expand Down
4 changes: 2 additions & 2 deletions src/Files.App/Helpers/WidgetsHelpers.cs
Original file line number Diff line number Diff line change
Expand Up @@ -37,9 +37,9 @@ public static class WidgetsHelpers

public static bool TryGetIsWidgetSettingEnabled<TWidget>(IPreferencesSettingsService preferencesSettingsService) where TWidget : IWidgetItemModel
{
if (typeof(TWidget) == typeof(FolderWidget))
if (typeof(TWidget) == typeof(QuickAccessWidget))
{
return preferencesSettingsService.ShowFoldersWidget;
return preferencesSettingsService.ShowQuickAccessWidget;
}
if (typeof(TWidget) == typeof(DrivesWidget))
{
Expand Down
19 changes: 13 additions & 6 deletions src/Files.App/ServicesImplementation/QuickAccessService.cs
Original file line number Diff line number Diff line change
@@ -1,37 +1,43 @@
using Files.App.Shell;
using Files.App.DataModels.NavigationControlItems;
using Files.App.Filesystem;
using Files.App.Shell;
using Files.App.UserControls.Widgets;
using Files.Shared;
using Files.Shared.Extensions;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Security.Permissions;
using System.Threading.Tasks;

namespace Files.App.ServicesImplementation
{
internal class QuickAccessService : IQuickAccessService
{
private readonly static string guid = "::{679f85cb-0220-4080-b29b-5540cc05aab6}";
public async Task<List<string>> GetPinnedFoldersAsync()

public async Task<List<string>> GetPinnedFoldersAsync(bool getRecentItems = false)
{
var sidebarItems = (await Win32Shell.GetShellFolderAsync(guid, "Enumerate", 0, 10000)).Enumerate
.Where(link => link.IsFolder)
.Select(link => link.FilePath).ToList();

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

return sidebarItems;
}

public async Task PinToSidebar(string folderPath)
=> await PinToSidebar(new[] { folderPath });

public async Task PinToSidebar(string[] folderPaths)
{
await ContextMenu.InvokeVerb("pintohome", folderPaths);
await App.QuickAccessManager.Model.LoadAsync();
App.QuickAccessManager.UpdateFolderWidget?.Invoke(this, new ModifyQuickAccessEventArgs(folderPaths, true));
}

public async Task UnpinFromSidebar(string folderPath)
=> await UnpinFromSidebar(new[] { folderPath });

Expand All @@ -48,6 +54,7 @@ await SafetyExtensions.IgnoreExceptions(async () => {
});

await App.QuickAccessManager.Model.LoadAsync();
App.QuickAccessManager.UpdateFolderWidget?.Invoke(this, new ModifyQuickAccessEventArgs(folderPaths, false));
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ public bool AlwaysOpenDualPaneInNewTab
set => Set(value);
}

public bool ShowFoldersWidget
public bool ShowQuickAccessWidget
{
get => Get(true);
set => Set(value);
Expand Down Expand Up @@ -194,7 +194,7 @@ protected override void RaiseOnSettingChangedEvent(object sender, SettingChanged
case nameof(AlwaysOpenNewInstance):
case nameof(IsDualPaneEnabled):
case nameof(AlwaysOpenDualPaneInNewTab):
case nameof(ShowFoldersWidget):
case nameof(ShowQuickAccessWidget):
case nameof(ShowRecentFilesWidget):
case nameof(ShowDrivesWidget):
case nameof(ShowBundlesWidget):
Expand Down
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 @@ -2901,4 +2901,7 @@
<data name="DisplayEditTagsMenu" xml:space="preserve">
<value>Display the edit tags flyout</value>
</data>
<data name="QuickAccess" xml:space="preserve">
<value>Quick access</value>
</data>
</root>
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<UserControl
x:Class="Files.App.UserControls.Widgets.FolderWidget"
x:Class="Files.App.UserControls.Widgets.QuickAccessWidget"
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"
Expand Down Expand Up @@ -72,10 +72,29 @@
<FontIcon Glyph="&#xE737;" />
</MenuFlyoutItem.Icon>
</MenuFlyoutItem>
<MenuFlyoutItem
x:Name="PinToFavorites"
Click="PinToFavorites_Click"
DataContext="{x:Bind}"
Text="{helpers:ResourceString Name=BaseLayoutItemContextFlyoutPinToFavorites/Text}"
Visibility="Collapsed">
<MenuFlyoutItem.Icon>
<FontIcon Glyph="&#xE840;" />
</MenuFlyoutItem.Icon>
</MenuFlyoutItem>
<MenuFlyoutItem
x:Name="UnpinFromFavorites"
Click="UnpinFromFavorites_Click"
DataContext="{x:Bind}"
Text="{helpers:ResourceString Name=BaseLayoutContextFlyoutUnpinFromFavorites/Text}"
Visibility="Collapsed">
<MenuFlyoutItem.Icon>
<FontIcon Glyph="&#xE77A;" />
</MenuFlyoutItem.Icon>
</MenuFlyoutItem>
<MenuFlyoutItem
x:Name="Properties"
x:Load="{x:Bind IsLibrary}"
Click="OpenLibraryProperties_Click"
Click="OpenProperties_Click"
DataContext="{x:Bind}"
Text="{helpers:ResourceString Name=BaseLayoutContextFlyoutPropertiesFolder/Text}">
<MenuFlyoutItem.Icon>
Expand All @@ -85,7 +104,6 @@
</MenuFlyout.Items>
</MenuFlyout>
</Button.ContextFlyout>

<Grid
HorizontalAlignment="Stretch"
VerticalAlignment="Stretch"
Expand All @@ -94,6 +112,13 @@
<RowDefinition Height="*" />
<RowDefinition Height="Auto" />
</Grid.RowDefinitions>
<FontIcon
x:Name="PinIcon"
HorizontalAlignment="Right"
VerticalAlignment="Top"
FontSize="12"
Glyph="&#xE840;"
x:Load="{x:Bind IsPinned, Mode=OneWay}" />
<Image
Grid.Row="0"
Width="32"
Expand Down
Loading