-
-
Notifications
You must be signed in to change notification settings - Fork 2.4k
Feature: Implement more RichCommands #11493
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
using CommunityToolkit.Mvvm.DependencyInjection; | ||
using Files.App.Commands; | ||
using Files.App.Contexts; | ||
using Files.App.Extensions; | ||
using Files.App.Helpers; | ||
using Files.Backend.Enums; | ||
using System.Threading.Tasks; | ||
|
||
namespace Files.App.Actions | ||
{ | ||
internal class CreateFolderAction : IAction | ||
{ | ||
public IContentPageContext context = Ioc.Default.GetRequiredService<IContentPageContext>(); | ||
|
||
public string Label { get; } = "Folder".GetLocalizedResource(); | ||
|
||
public RichGlyph Glyph { get; } = new RichGlyph(baseGlyph: "\uE8B7"); | ||
|
||
public async Task ExecuteAsync() | ||
{ | ||
UIFilesystemHelpers.CreateFileFromDialogResultType(AddItemDialogItemType.Folder, null!, context.ShellPage!); | ||
} | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
using CommunityToolkit.Mvvm.DependencyInjection; | ||
using Files.App.Commands; | ||
using Files.App.Contexts; | ||
using Files.App.Extensions; | ||
using Files.App.Filesystem; | ||
using Files.App.Helpers; | ||
using System.IO; | ||
using System.Threading.Tasks; | ||
|
||
namespace Files.App.Actions | ||
{ | ||
internal class CreateShortcutAction : IAction | ||
{ | ||
public IContentPageContext context = Ioc.Default.GetRequiredService<IContentPageContext>(); | ||
|
||
public string Label { get; } = "BaseLayoutItemContextFlyoutShortcut/Text".GetLocalizedResource(); | ||
|
||
public RichGlyph Glyph { get; } = new RichGlyph(opacityStyle: "ColorIconShortcut"); | ||
|
||
public async Task ExecuteAsync() | ||
{ | ||
var currentPath = context.ShellPage?.FilesystemViewModel.WorkingDirectory; | ||
|
||
if (App.LibraryManager.TryGetLibrary(currentPath ?? string.Empty, out var library) && !library.IsEmpty) | ||
{ | ||
currentPath = library.DefaultSaveFolder; | ||
} | ||
|
||
foreach (ListedItem selectedItem in context.SelectedItems) | ||
{ | ||
var fileName = string.Format("ShortcutCreateNewSuffix".GetLocalizedResource(), selectedItem.Name) + ".lnk"; | ||
var filePath = Path.Combine(currentPath ?? string.Empty, fileName); | ||
|
||
if (!await FileOperationsHelpers.CreateOrUpdateLinkAsync(filePath, selectedItem.ItemPath)) | ||
await UIFilesystemHelpers.HandleShortcutCannotBeCreated(fileName, selectedItem.ItemPath); | ||
} | ||
} | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
using CommunityToolkit.Mvvm.DependencyInjection; | ||
using Files.App.Commands; | ||
using Files.App.Contexts; | ||
using Files.App.Extensions; | ||
using Files.App.Helpers; | ||
using System.Threading.Tasks; | ||
|
||
namespace Files.App.Actions | ||
{ | ||
internal class CreateShortcutFromDialogAction : IAction | ||
{ | ||
public IContentPageContext context = Ioc.Default.GetRequiredService<IContentPageContext>(); | ||
|
||
public string Label { get; } = "Shortcut".GetLocalizedResource(); | ||
|
||
public RichGlyph Glyph { get; } = new RichGlyph(baseGlyph: "\uF10A", fontFamily: "CustomGlyph"); | ||
|
||
public async Task ExecuteAsync() | ||
{ | ||
await UIFilesystemHelpers.CreateShortcutFromDialogAsync(context.ShellPage); | ||
} | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
using CommunityToolkit.Mvvm.DependencyInjection; | ||
using Files.App.Commands; | ||
using Files.App.Contexts; | ||
using Files.App.Extensions; | ||
using Files.App.Filesystem; | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Linq; | ||
using System.Text; | ||
using System.Threading.Tasks; | ||
|
||
namespace Files.App.Actions | ||
{ | ||
internal class PinToStartAction : IAction | ||
{ | ||
public IContentPageContext context = Ioc.Default.GetRequiredService<IContentPageContext>(); | ||
|
||
public string Label { get; } = "PinItemToStart/Text".GetLocalizedResource(); | ||
|
||
public RichGlyph Glyph { get; } = new RichGlyph(opacityStyle: "ColorIconPinToFavorites"); | ||
|
||
public async Task ExecuteAsync() | ||
{ | ||
if (context.SelectedItems.Count > 0) | ||
{ | ||
foreach (ListedItem listedItem in context.ShellPage?.SlimContentPage.SelectedItems) | ||
await App.SecondaryTileHelper.TryPinFolderAsync(listedItem.ItemPath, listedItem.Name); | ||
} | ||
else | ||
{ | ||
await App.SecondaryTileHelper.TryPinFolderAsync(context.ShellPage?.FilesystemViewModel.CurrentFolder.ItemPath, context.ShellPage?.FilesystemViewModel.CurrentFolder.Name); | ||
} | ||
} | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
using CommunityToolkit.Mvvm.DependencyInjection; | ||
using Files.App.Commands; | ||
using Files.App.Contexts; | ||
using Files.App.Extensions; | ||
using Files.App.Filesystem; | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Linq; | ||
using System.Text; | ||
using System.Threading.Tasks; | ||
|
||
namespace Files.App.Actions | ||
{ | ||
internal class UnpinFromStartAction : IAction | ||
{ | ||
public IContentPageContext context = Ioc.Default.GetRequiredService<IContentPageContext>(); | ||
|
||
public string Label { get; } = "UnpinItemFromStart/Text".GetLocalizedResource(); | ||
|
||
public RichGlyph Glyph { get; } = new RichGlyph(opacityStyle: "ColorIconUnpinFromFavorites"); | ||
|
||
public async Task ExecuteAsync() | ||
{ | ||
if (context.SelectedItems.Count > 0) | ||
{ | ||
foreach (ListedItem listedItem in context.ShellPage?.SlimContentPage.SelectedItems) | ||
await App.SecondaryTileHelper.TryPinFolderAsync(listedItem.ItemPath, listedItem.Name); | ||
} | ||
else | ||
{ | ||
await App.SecondaryTileHelper.TryPinFolderAsync(context.ShellPage?.FilesystemViewModel.CurrentFolder.ItemPath, context.ShellPage?.FilesystemViewModel.CurrentFolder.Name); | ||
} | ||
} | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -838,18 +838,10 @@ public static List<ContextMenuFlyoutItemViewModel> GetBaseItemMenuItems( | |
Command = commandsViewModel.CreateFolderWithSelection, | ||
ShowItem = itemsSelected, | ||
}, | ||
new ContextMenuFlyoutItemViewModel() | ||
new ContextMenuFlyoutItemViewModelBuilder(commands.CreateShortcut) | ||
{ | ||
Text = "BaseLayoutItemContextFlyoutShortcut/Text".GetLocalizedResource(), | ||
OpacityIcon = new OpacityIconModel() | ||
{ | ||
OpacityIconStyle = "ColorIconShortcut", | ||
}, | ||
Command = commandsViewModel.CreateShortcutCommand, | ||
ShowItem = itemsSelected && (!selectedItems.FirstOrDefault()?.IsShortcut ?? false), | ||
SingleItemOnly = true, | ||
ShowInSearchPage = true, | ||
}, | ||
IsVisible = itemsSelected && (!selectedItems.FirstOrDefault()?.IsShortcut ?? false), | ||
}.Build(), | ||
new ContextMenuFlyoutItemViewModel() | ||
{ | ||
Text = "Rename".GetLocalizedResource(), | ||
|
@@ -932,34 +924,14 @@ public static List<ContextMenuFlyoutItemViewModel> GetBaseItemMenuItems( | |
{ | ||
IsVisible = userSettingsService.PreferencesSettingsService.ShowFavoritesSection && selectedItems.All(x => x.PrimaryItemAttribute == StorageItemTypes.Folder && !x.IsArchive && x.IsPinned), | ||
}.Build(), | ||
new ContextMenuFlyoutItemViewModel() | ||
new ContextMenuFlyoutItemViewModelBuilder(commands.PinToStart) | ||
{ | ||
Text = "PinItemToStart/Text".GetLocalizedResource(), | ||
OpacityIcon = new OpacityIconModel() | ||
{ | ||
OpacityIconStyle = "ColorIconPinToFavorites", | ||
}, | ||
Command = commandsViewModel.PinItemToStartCommand, | ||
ShowOnShift = true, | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Looks like show on shift was also removed, can you add this back? |
||
ShowItem = selectedItems.All(x => !x.IsShortcut && (x.PrimaryItemAttribute == StorageItemTypes.Folder || x.IsExecutable) && !x.IsArchive && !x.IsItemPinnedToStart), | ||
ShowInSearchPage = true, | ||
ShowInFtpPage = true, | ||
SingleItemOnly = true, | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This too |
||
}, | ||
new ContextMenuFlyoutItemViewModel() | ||
IsVisible = selectedItems.All(x => !x.IsShortcut && (x.PrimaryItemAttribute == StorageItemTypes.Folder || x.IsExecutable) && !x.IsArchive && !x.IsItemPinnedToStart), | ||
}.Build(), | ||
new ContextMenuFlyoutItemViewModelBuilder(commands.UnpinFromStart) | ||
{ | ||
Text = "UnpinItemFromStart/Text".GetLocalizedResource(), | ||
OpacityIcon = new OpacityIconModel() | ||
{ | ||
OpacityIconStyle = "ColorIconUnpinFromFavorites", | ||
}, | ||
Command = commandsViewModel.UnpinItemFromStartCommand, | ||
ShowOnShift = true, | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This as well |
||
ShowItem = selectedItems.All(x => !x.IsShortcut && (x.PrimaryItemAttribute == StorageItemTypes.Folder || x.IsExecutable) && !x.IsArchive && x.IsItemPinnedToStart), | ||
ShowInSearchPage = true, | ||
ShowInFtpPage = true, | ||
SingleItemOnly = true, | ||
}, | ||
IsVisible = selectedItems.All(x => !x.IsShortcut && (x.PrimaryItemAttribute == StorageItemTypes.Folder || x.IsExecutable) && !x.IsArchive && x.IsItemPinnedToStart), | ||
}.Build(), | ||
new ContextMenuFlyoutItemViewModel | ||
{ | ||
Text = "Archive".GetLocalizedResource(), | ||
|
@@ -1070,14 +1042,7 @@ public static List<ContextMenuFlyoutItemViewModel> GetNewItemItems(BaseLayoutCom | |
{ | ||
var list = new List<ContextMenuFlyoutItemViewModel>() | ||
{ | ||
new ContextMenuFlyoutItemViewModel() | ||
{ | ||
Text = "Folder".GetLocalizedResource(), | ||
Glyph = "\uE8B7", | ||
Command = commandsViewModel.CreateNewFolderCommand, | ||
ShowInFtpPage = true, | ||
ShowInZipPage = true, | ||
}, | ||
new ContextMenuFlyoutItemViewModelBuilder(commands.CreateFolder).Build(), | ||
new ContextMenuFlyoutItemViewModel() | ||
{ | ||
Text = "File".GetLocalizedResource(), | ||
|
@@ -1088,13 +1053,7 @@ public static List<ContextMenuFlyoutItemViewModel> GetNewItemItems(BaseLayoutCom | |
ShowInZipPage = true, | ||
IsEnabled = canCreateFileInPage | ||
}, | ||
new ContextMenuFlyoutItemViewModel | ||
{ | ||
Text = "Shortcut".GetLocalizedResource(), | ||
Glyph = "\uF10A", | ||
GlyphFontFamilyName = "CustomGlyph", | ||
Command = commandsViewModel.CreateShortcutFromDialogCommand | ||
}, | ||
new ContextMenuFlyoutItemViewModelBuilder(commands.CreateShortcutFromDialog).Build(), | ||
new ContextMenuFlyoutItemViewModel() | ||
{ | ||
ItemType = ItemType.Separator, | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Just noticed this was removed, create shortcut should only show if a single item is selected.