Skip to content

Commit da8794f

Browse files
authored
Merge branch 'main' into more_richcommands_1
2 parents 6d57b1a + da25928 commit da8794f

File tree

9 files changed

+78
-46
lines changed

9 files changed

+78
-46
lines changed
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
using CommunityToolkit.Mvvm.DependencyInjection;
2+
using Files.App.Commands;
3+
using Files.App.Contexts;
4+
using Files.App.Extensions;
5+
using Files.App.ServicesImplementation;
6+
using System;
7+
using System.Collections.Generic;
8+
using System.Linq;
9+
using System.Text;
10+
using System.Threading.Tasks;
11+
12+
namespace Files.App.Actions.Favorites
13+
{
14+
internal class PinItemAction : IAction
15+
{
16+
public IContentPageContext context = Ioc.Default.GetRequiredService<IContentPageContext>();
17+
18+
private readonly IQuickAccessService quickAccessService = Ioc.Default.GetRequiredService<IQuickAccessService>();
19+
20+
public string Label { get; } = "BaseLayoutItemContextFlyoutPinToFavorites/Text".GetLocalizedResource();
21+
22+
public RichGlyph Glyph { get; } = new RichGlyph(opacityStyle: "ColorIconPinToFavorites");
23+
24+
public async Task ExecuteAsync()
25+
{
26+
await quickAccessService.PinToSidebar(context.SelectedItems.Select(x => x.ItemPath).ToArray());
27+
}
28+
}
29+
}
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
using CommunityToolkit.Mvvm.DependencyInjection;
2+
using Files.App.Commands;
3+
using Files.App.Contexts;
4+
using Files.App.Extensions;
5+
using Files.App.ServicesImplementation;
6+
using System;
7+
using System.Collections.Generic;
8+
using System.Linq;
9+
using System.Text;
10+
using System.Threading.Tasks;
11+
12+
namespace Files.App.Actions
13+
{
14+
internal class UnpinItemAction : IAction
15+
{
16+
public IContentPageContext context = Ioc.Default.GetRequiredService<IContentPageContext>();
17+
18+
private readonly IQuickAccessService quickAccessService = Ioc.Default.GetRequiredService<IQuickAccessService>();
19+
20+
public string Label { get; } = "UnpinFromFavorites".GetLocalizedResource();
21+
22+
public RichGlyph Glyph { get; } = new RichGlyph(opacityStyle: "ColorIconUnpinFromFavorites");
23+
24+
public async Task ExecuteAsync()
25+
{
26+
await quickAccessService.UnpinFromSidebar(context.SelectedItems.Select(x => x.ItemPath).ToArray());
27+
}
28+
}
29+
}

src/Files.App/Commands/CommandCodes.cs

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,12 @@ public enum CommandCodes
2020
RestoreRecycleBin,
2121
RestoreAllRecycleBin,
2222

23-
// Start
23+
// Start
2424
PinToStart,
2525
UnpinFromStart,
26+
27+
// Favorites
28+
PinItemToFavorites,
29+
UnpinItemFromFavorites,
2630
}
2731
}

src/Files.App/Commands/Manager/CommandManager.cs

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
using CommunityToolkit.Mvvm.ComponentModel;
22
using CommunityToolkit.Mvvm.Input;
33
using Files.App.Actions;
4+
using Files.App.Actions.Favorites;
45
using Files.App.UserControls;
56
using Microsoft.UI.Xaml.Controls;
67
using Microsoft.UI.Xaml.Input;
@@ -39,7 +40,9 @@ internal class CommandManager : ICommandManager
3940
public IRichCommand CreateFolder => commands[CommandCodes.CreateFolder];
4041
public IRichCommand PinToStart => commands[CommandCodes.PinToStart];
4142
public IRichCommand UnpinFromStart => commands[CommandCodes.UnpinFromStart];
42-
43+
public IRichCommand PinItemToFavorites => commands[CommandCodes.PinItemToFavorites];
44+
public IRichCommand UnpinItemFromFavorites => commands[CommandCodes.UnpinItemFromFavorites];
45+
4346
public CommandManager()
4447
{
4548
commands = CreateActions()
@@ -70,6 +73,8 @@ public CommandManager()
7073
[CommandCodes.CreateFolder] = new CreateFolderAction(),
7174
[CommandCodes.PinToStart] = new PinToStartAction(),
7275
[CommandCodes.UnpinFromStart] = new UnpinFromStartAction(),
76+
[CommandCodes.PinItemToFavorites] = new PinItemAction(),
77+
[CommandCodes.UnpinItemFromFavorites] = new UnpinItemAction(),
7378
};
7479

7580
[DebuggerDisplay("Command None")]

src/Files.App/Commands/Manager/ICommandManager.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,5 +27,7 @@ public interface ICommandManager : IEnumerable<IRichCommand>
2727

2828
IRichCommand PinToStart { get; }
2929
IRichCommand UnpinFromStart { get; }
30+
IRichCommand PinItemToFavorites { get; }
31+
IRichCommand UnpinItemFromFavorites { get; }
3032
}
3133
}

src/Files.App/Helpers/ContextFlyoutItemHelper.cs

Lines changed: 7 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
using CommunityToolkit.Mvvm.DependencyInjection;
22
using CommunityToolkit.Mvvm.Input;
33
using Files.App.Commands;
4+
using Files.App.DataModels.NavigationControlItems;
45
using Files.App.Extensions;
56
using Files.App.Filesystem;
67
using Files.App.Interacts;
@@ -915,30 +916,14 @@ public static List<ContextMenuFlyoutItemViewModel> GetBaseItemMenuItems(
915916
SingleItemOnly = true,
916917
ShowInSearchPage = true,
917918
},
918-
new ContextMenuFlyoutItemViewModel()
919+
new ContextMenuFlyoutItemViewModelBuilder(commands.PinItemToFavorites)
919920
{
920-
Text = "BaseLayoutItemContextFlyoutPinToFavorites/Text".GetLocalizedResource(),
921-
OpacityIcon = new OpacityIconModel()
922-
{
923-
OpacityIconStyle = "ColorIconPinToFavorites",
924-
},
925-
Command = commandsViewModel.SidebarPinItemCommand,
926-
ShowItem = userSettingsService.PreferencesSettingsService.ShowFavoritesSection && selectedItems.All(x => x.PrimaryItemAttribute == StorageItemTypes.Folder && !x.IsArchive && !x.IsPinned),
927-
ShowInSearchPage = true,
928-
ShowInFtpPage = true,
929-
},
930-
new ContextMenuFlyoutItemViewModel()
921+
IsVisible = userSettingsService.PreferencesSettingsService.ShowFavoritesSection && selectedItems.All(x => x.PrimaryItemAttribute == StorageItemTypes.Folder && !x.IsArchive && !x.IsPinned),
922+
}.Build(),
923+
new ContextMenuFlyoutItemViewModelBuilder(commands.UnpinItemFromFavorites)
931924
{
932-
Text = "UnpinFromFavorites".GetLocalizedResource(),
933-
OpacityIcon = new OpacityIconModel()
934-
{
935-
OpacityIconStyle = "ColorIconUnpinFromFavorites",
936-
},
937-
Command = commandsViewModel.SidebarUnpinItemCommand,
938-
ShowItem = userSettingsService.PreferencesSettingsService.ShowFavoritesSection && selectedItems.All(x => x.PrimaryItemAttribute == StorageItemTypes.Folder && !x.IsArchive && x.IsPinned),
939-
ShowInSearchPage = true,
940-
ShowInFtpPage = true,
941-
},
925+
IsVisible = userSettingsService.PreferencesSettingsService.ShowFavoritesSection && selectedItems.All(x => x.PrimaryItemAttribute == StorageItemTypes.Folder && !x.IsArchive && x.IsPinned),
926+
}.Build(),
942927
new ContextMenuFlyoutItemViewModelBuilder(commands.PinToStart)
943928
{
944929
IsVisible = selectedItems.All(x => !x.IsShortcut && (x.PrimaryItemAttribute == StorageItemTypes.Folder || x.IsExecutable) && !x.IsArchive && !x.IsItemPinnedToStart),

src/Files.App/Interacts/BaseLayoutCommandImplementationModel.cs

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -127,11 +127,6 @@ public virtual void OpenItem(RoutedEventArgs e)
127127
_ = NavigationHelpers.OpenSelectedItems(associatedInstance, false);
128128
}
129129

130-
public virtual void UnpinDirectoryFromFavorites(RoutedEventArgs e)
131-
{
132-
_ = QuickAccessService.UnpinFromSidebar(associatedInstance.FilesystemViewModel.WorkingDirectory);
133-
}
134-
135130
public virtual async void RestoreRecycleBin(RoutedEventArgs e)
136131
{
137132
await RecycleBinHelpers.RestoreRecycleBin(associatedInstance);
@@ -368,11 +363,6 @@ async void Manager_DataRequested(DataTransferManager sender, DataRequestedEventA
368363
}
369364
}
370365

371-
public virtual void PinDirectoryToFavorites(RoutedEventArgs e)
372-
{
373-
QuickAccessService.PinToSidebar(new[] { associatedInstance.FilesystemViewModel.WorkingDirectory });
374-
}
375-
376366
public virtual async void ItemPointerPressed(PointerRoutedEventArgs e)
377367
{
378368
if (e.GetCurrentPoint(null).Properties.IsMiddleButtonPressed)

src/Files.App/Interacts/BaseLayoutCommandsViewModel.cs

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -33,9 +33,6 @@ private void InitializeCommands()
3333
SetAsSlideshowItemCommand = new RelayCommand<RoutedEventArgs>(CommandsModel.SetAsSlideshowItem);
3434
RunAsAdminCommand = new RelayCommand<RoutedEventArgs>(CommandsModel.RunAsAdmin);
3535
RunAsAnotherUserCommand = new RelayCommand<RoutedEventArgs>(CommandsModel.RunAsAnotherUser);
36-
SidebarPinItemCommand = new RelayCommand<RoutedEventArgs>(CommandsModel.SidebarPinItem);
37-
SidebarUnpinItemCommand = new RelayCommand<RoutedEventArgs>(CommandsModel.SidebarUnpinItem);
38-
UnpinDirectoryFromFavoritesCommand = new RelayCommand<RoutedEventArgs>(CommandsModel.UnpinDirectoryFromFavorites);
3936
OpenItemCommand = new RelayCommand<RoutedEventArgs>(CommandsModel.OpenItem);
4037
RestoreRecycleBinCommand = new RelayCommand<RoutedEventArgs>(CommandsModel.RestoreRecycleBin);
4138
RestoreSelectionRecycleBinCommand = new RelayCommand<RoutedEventArgs>(CommandsModel.RestoreSelectionRecycleBin);
@@ -56,7 +53,6 @@ private void InitializeCommands()
5653
PasteItemsFromClipboardCommand = new RelayCommand<RoutedEventArgs>(CommandsModel.PasteItemsFromClipboard);
5754
CopyPathOfSelectedItemCommand = new RelayCommand<RoutedEventArgs>(CommandsModel.CopyPathOfSelectedItem);
5855
ShareItemCommand = new RelayCommand<RoutedEventArgs>(CommandsModel.ShareItem);
59-
PinDirectoryToFavoritesCommand = new RelayCommand<RoutedEventArgs>(CommandsModel.PinDirectoryToFavorites);
6056
ItemPointerPressedCommand = new RelayCommand<PointerRoutedEventArgs>(CommandsModel.ItemPointerPressed);
6157
PointerWheelChangedCommand = new RelayCommand<PointerRoutedEventArgs>(CommandsModel.PointerWheelChanged);
6258
GridViewSizeDecreaseCommand = new RelayCommand<KeyboardAcceleratorInvokedEventArgs>(CommandsModel.GridViewSizeDecrease);
@@ -102,8 +98,6 @@ private void InitializeCommands()
10298

10399
public ICommand OpenItemCommand { get; private set; }
104100

105-
public ICommand UnpinDirectoryFromFavoritesCommand { get; private set; }
106-
107101
public ICommand RestoreRecycleBinCommand { get; private set; }
108102

109103
public ICommand RestoreSelectionRecycleBinCommand { get; private set; }
@@ -142,8 +136,6 @@ private void InitializeCommands()
142136

143137
public ICommand ShareItemCommand { get; private set; }
144138

145-
public ICommand PinDirectoryToFavoritesCommand { get; private set; }
146-
147139
public ICommand ItemPointerPressedCommand { get; private set; }
148140

149141
public ICommand PointerWheelChangedCommand { get; private set; }

src/Files.App/Interacts/IBaseLayoutCommandImplementationModel.cs

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -25,8 +25,6 @@ public interface IBaseLayoutCommandImplementationModel : IDisposable
2525

2626
void SidebarUnpinItem(RoutedEventArgs e);
2727

28-
void UnpinDirectoryFromFavorites(RoutedEventArgs e);
29-
3028
void OpenItem(RoutedEventArgs e);
3129

3230
void RestoreRecycleBin(RoutedEventArgs e);
@@ -67,8 +65,6 @@ public interface IBaseLayoutCommandImplementationModel : IDisposable
6765

6866
void ShareItem(RoutedEventArgs e);
6967

70-
void PinDirectoryToFavorites(RoutedEventArgs e);
71-
7268
void ItemPointerPressed(PointerRoutedEventArgs e);
7369

7470
void PointerWheelChanged(PointerRoutedEventArgs e);

0 commit comments

Comments
 (0)