From 20dd76fcc7dc370a02e71c724978aae5bcdb1731 Mon Sep 17 00:00:00 2001 From: 0x5BFA Date: Wed, 8 May 2024 00:53:35 +0900 Subject: [PATCH 01/17] Init --- ...toryInNewPaneAction.cs => OpenInNewPaneAction.cs} | 4 ++-- ...ectoryInNewTabAction.cs => OpenInNewTabAction.cs} | 4 ++-- ...wWindowItemAction.cs => OpenInNewWindowAction.cs} | 4 ++-- src/Files.App/Data/Commands/Manager/CommandCodes.cs | 6 +++--- .../Data/Commands/Manager/CommandManager.cs | 12 ++++++------ 5 files changed, 15 insertions(+), 15 deletions(-) rename src/Files.App/Actions/Navigation/{OpenDirectoryInNewPaneAction.cs => OpenInNewPaneAction.cs} (92%) rename src/Files.App/Actions/Navigation/{OpenDirectoryInNewTabAction.cs => OpenInNewTabAction.cs} (94%) rename src/Files.App/Actions/Navigation/{OpenInNewWindowItemAction.cs => OpenInNewWindowAction.cs} (94%) diff --git a/src/Files.App/Actions/Navigation/OpenDirectoryInNewPaneAction.cs b/src/Files.App/Actions/Navigation/OpenInNewPaneAction.cs similarity index 92% rename from src/Files.App/Actions/Navigation/OpenDirectoryInNewPaneAction.cs rename to src/Files.App/Actions/Navigation/OpenInNewPaneAction.cs index 3dc64a3bb958..3b0485070984 100644 --- a/src/Files.App/Actions/Navigation/OpenDirectoryInNewPaneAction.cs +++ b/src/Files.App/Actions/Navigation/OpenInNewPaneAction.cs @@ -3,7 +3,7 @@ namespace Files.App.Actions { - internal sealed class OpenDirectoryInNewPaneAction : ObservableObject, IAction + internal sealed class OpenInNewPaneAction : ObservableObject, IAction { private readonly IContentPageContext context; @@ -20,7 +20,7 @@ public string Description context.SelectedItem.IsFolder && userSettingsService.GeneralSettingsService.ShowOpenInNewPane; - public OpenDirectoryInNewPaneAction() + public OpenInNewPaneAction() { context = Ioc.Default.GetRequiredService(); userSettingsService = Ioc.Default.GetRequiredService(); diff --git a/src/Files.App/Actions/Navigation/OpenDirectoryInNewTabAction.cs b/src/Files.App/Actions/Navigation/OpenInNewTabAction.cs similarity index 94% rename from src/Files.App/Actions/Navigation/OpenDirectoryInNewTabAction.cs rename to src/Files.App/Actions/Navigation/OpenInNewTabAction.cs index 5b154cdf712d..8de3d4e8f234 100644 --- a/src/Files.App/Actions/Navigation/OpenDirectoryInNewTabAction.cs +++ b/src/Files.App/Actions/Navigation/OpenInNewTabAction.cs @@ -3,7 +3,7 @@ namespace Files.App.Actions { - internal sealed class OpenDirectoryInNewTabAction : ObservableObject, IAction + internal sealed class OpenInNewTabAction : ObservableObject, IAction { private readonly IContentPageContext context; @@ -25,7 +25,7 @@ public RichGlyph Glyph context.SelectedItems.Count(x => x.IsFolder) == context.SelectedItems.Count && userSettingsService.GeneralSettingsService.ShowOpenInNewTab; - public OpenDirectoryInNewTabAction() + public OpenInNewTabAction() { context = Ioc.Default.GetRequiredService(); userSettingsService = Ioc.Default.GetRequiredService(); diff --git a/src/Files.App/Actions/Navigation/OpenInNewWindowItemAction.cs b/src/Files.App/Actions/Navigation/OpenInNewWindowAction.cs similarity index 94% rename from src/Files.App/Actions/Navigation/OpenInNewWindowItemAction.cs rename to src/Files.App/Actions/Navigation/OpenInNewWindowAction.cs index b23cf3be56dc..26186d18a821 100644 --- a/src/Files.App/Actions/Navigation/OpenInNewWindowItemAction.cs +++ b/src/Files.App/Actions/Navigation/OpenInNewWindowAction.cs @@ -5,7 +5,7 @@ namespace Files.App.Actions { - internal sealed class OpenInNewWindowItemAction : ObservableObject, IAction + internal sealed class OpenInNewWindowAction : ObservableObject, IAction { private readonly IContentPageContext context; @@ -30,7 +30,7 @@ public RichGlyph Glyph context.SelectedItems.Count(x => x.IsFolder) == context.SelectedItems.Count && userSettingsService.GeneralSettingsService.ShowOpenInNewWindow; - public OpenInNewWindowItemAction() + public OpenInNewWindowAction() { context = Ioc.Default.GetRequiredService(); userSettingsService = Ioc.Default.GetRequiredService(); diff --git a/src/Files.App/Data/Commands/Manager/CommandCodes.cs b/src/Files.App/Data/Commands/Manager/CommandCodes.cs index 8dd669dba93e..100256fcc46a 100644 --- a/src/Files.App/Data/Commands/Manager/CommandCodes.cs +++ b/src/Files.App/Data/Commands/Manager/CommandCodes.cs @@ -180,9 +180,9 @@ public enum CommandCodes CloseTabsToTheRightSelected, CloseOtherTabsCurrent, CloseOtherTabsSelected, - OpenDirectoryInNewPane, - OpenDirectoryInNewTab, - OpenInNewWindowItem, + OpenInNewPane, + OpenInNewTab, + OpenInNewWindow, ReopenClosedTab, PreviousTab, NextTab, diff --git a/src/Files.App/Data/Commands/Manager/CommandManager.cs b/src/Files.App/Data/Commands/Manager/CommandManager.cs index 30887886a802..28a574c57e27 100644 --- a/src/Files.App/Data/Commands/Manager/CommandManager.cs +++ b/src/Files.App/Data/Commands/Manager/CommandManager.cs @@ -175,9 +175,9 @@ internal sealed class CommandManager : ICommandManager public IRichCommand CloseTabsToTheRightSelected => commands[CommandCodes.CloseTabsToTheRightSelected]; public IRichCommand CloseOtherTabsCurrent => commands[CommandCodes.CloseOtherTabsCurrent]; public IRichCommand CloseOtherTabsSelected => commands[CommandCodes.CloseOtherTabsSelected]; - public IRichCommand OpenDirectoryInNewPaneAction => commands[CommandCodes.OpenDirectoryInNewPane]; - public IRichCommand OpenDirectoryInNewTabAction => commands[CommandCodes.OpenDirectoryInNewTab]; - public IRichCommand OpenInNewWindowItemAction => commands[CommandCodes.OpenInNewWindowItem]; + public IRichCommand OpenDirectoryInNewPaneAction => commands[CommandCodes.OpenInNewPane]; + public IRichCommand OpenDirectoryInNewTabAction => commands[CommandCodes.OpenInNewTab]; + public IRichCommand OpenInNewWindowItemAction => commands[CommandCodes.OpenInNewWindow]; public IRichCommand ReopenClosedTab => commands[CommandCodes.ReopenClosedTab]; public IRichCommand PreviousTab => commands[CommandCodes.PreviousTab]; public IRichCommand NextTab => commands[CommandCodes.NextTab]; @@ -349,9 +349,9 @@ public CommandManager() [CommandCodes.CloseTabsToTheRightSelected] = new CloseTabsToTheRightSelectedAction(), [CommandCodes.CloseOtherTabsCurrent] = new CloseOtherTabsCurrentAction(), [CommandCodes.CloseOtherTabsSelected] = new CloseOtherTabsSelectedAction(), - [CommandCodes.OpenDirectoryInNewPane] = new OpenDirectoryInNewPaneAction(), - [CommandCodes.OpenDirectoryInNewTab] = new OpenDirectoryInNewTabAction(), - [CommandCodes.OpenInNewWindowItem] = new OpenInNewWindowItemAction(), + [CommandCodes.OpenInNewPane] = new OpenInNewPaneAction(), + [CommandCodes.OpenInNewTab] = new OpenInNewTabAction(), + [CommandCodes.OpenInNewWindow] = new OpenInNewWindowAction(), [CommandCodes.ReopenClosedTab] = new ReopenClosedTabAction(), [CommandCodes.PreviousTab] = new PreviousTabAction(), [CommandCodes.NextTab] = new NextTabAction(), From 0cd4800621946ac75bdf2adfc8c277f1bc66533b Mon Sep 17 00:00:00 2001 From: 0x5BFA Date: Wed, 8 May 2024 01:16:10 +0900 Subject: [PATCH 02/17] Added classes --- .../OpenInNew/BaseOpenInNewPaneAction.cs | 49 +++++++++++++ .../OpenInNew/BaseOpenInNewTabAction.cs | 63 +++++++++++++++++ .../OpenInNew/BaseOpenInNewWindowAction.cs | 66 +++++++++++++++++ .../OpenInNew/OpenInNewPaneAction.cs | 9 +++ .../OpenInNew/OpenInNewPaneFromHomeAction.cs | 35 ++++++++++ .../OpenInNewPaneFromSidebarAction.cs | 30 ++++++++ .../OpenInNew/OpenInNewTabAction.cs | 9 +++ .../OpenInNew/OpenInNewTabFromHomeAction.cs | 9 +++ .../OpenInNewTabFromSidebarAction.cs | 9 +++ .../OpenInNew/OpenInNewWindowAction.cs | 9 +++ .../OpenInNewWindowFromHomeAction.cs | 9 +++ .../OpenInNewWindowFromSidebarAction.cs | 9 +++ .../Actions/Navigation/OpenInNewPaneAction.cs | 53 -------------- .../Actions/Navigation/OpenInNewTabAction.cs | 67 ------------------ .../Navigation/OpenInNewWindowAction.cs | 70 ------------------- 15 files changed, 306 insertions(+), 190 deletions(-) create mode 100644 src/Files.App/Actions/Navigation/OpenInNew/BaseOpenInNewPaneAction.cs create mode 100644 src/Files.App/Actions/Navigation/OpenInNew/BaseOpenInNewTabAction.cs create mode 100644 src/Files.App/Actions/Navigation/OpenInNew/BaseOpenInNewWindowAction.cs create mode 100644 src/Files.App/Actions/Navigation/OpenInNew/OpenInNewPaneAction.cs create mode 100644 src/Files.App/Actions/Navigation/OpenInNew/OpenInNewPaneFromHomeAction.cs create mode 100644 src/Files.App/Actions/Navigation/OpenInNew/OpenInNewPaneFromSidebarAction.cs create mode 100644 src/Files.App/Actions/Navigation/OpenInNew/OpenInNewTabAction.cs create mode 100644 src/Files.App/Actions/Navigation/OpenInNew/OpenInNewTabFromHomeAction.cs create mode 100644 src/Files.App/Actions/Navigation/OpenInNew/OpenInNewTabFromSidebarAction.cs create mode 100644 src/Files.App/Actions/Navigation/OpenInNew/OpenInNewWindowAction.cs create mode 100644 src/Files.App/Actions/Navigation/OpenInNew/OpenInNewWindowFromHomeAction.cs create mode 100644 src/Files.App/Actions/Navigation/OpenInNew/OpenInNewWindowFromSidebarAction.cs delete mode 100644 src/Files.App/Actions/Navigation/OpenInNewPaneAction.cs delete mode 100644 src/Files.App/Actions/Navigation/OpenInNewTabAction.cs delete mode 100644 src/Files.App/Actions/Navigation/OpenInNewWindowAction.cs diff --git a/src/Files.App/Actions/Navigation/OpenInNew/BaseOpenInNewPaneAction.cs b/src/Files.App/Actions/Navigation/OpenInNew/BaseOpenInNewPaneAction.cs new file mode 100644 index 000000000000..edbbd20cc81b --- /dev/null +++ b/src/Files.App/Actions/Navigation/OpenInNew/BaseOpenInNewPaneAction.cs @@ -0,0 +1,49 @@ +// Copyright (c) 2024 Files Community +// Licensed under the MIT License. See the LICENSE. + +namespace Files.App.Actions +{ + internal abstract class BaseOpenInNewPaneAction : ObservableObject, IAction + { + protected IUserSettingsService UserSettingsService { get; } = Ioc.Default.GetRequiredService(); + protected IContentPageContext ContentPageContext { get; } = Ioc.Default.GetRequiredService(); + + public string Label + => "OpenInNewPane".GetLocalizedResource(); + + public string Description + => "OpenDirectoryInNewPaneDescription".GetLocalizedResource(); + + public virtual bool IsExecutable => + ContentPageContext.SelectedItem is not null && + ContentPageContext.SelectedItem.IsFolder && + UserSettingsService.GeneralSettingsService.ShowOpenInNewPane; + + public BaseOpenInNewPaneAction() + { + ContentPageContext.PropertyChanged += Context_PropertyChanged; + } + + public virtual Task ExecuteAsync() + { + NavigationHelpers.OpenInSecondaryPane( + ContentPageContext.ShellPage, + ContentPageContext.ShellPage.SlimContentPage.SelectedItems.FirstOrDefault()); + + return Task.CompletedTask; + } + + protected virtual void Context_PropertyChanged(object? sender, PropertyChangedEventArgs e) + { + switch (e.PropertyName) + { + case nameof(IContentPageContext.ShellPage): + case nameof(IContentPageContext.PageType): + case nameof(IContentPageContext.HasSelection): + case nameof(IContentPageContext.SelectedItems): + OnPropertyChanged(nameof(IsExecutable)); + break; + } + } + } +} diff --git a/src/Files.App/Actions/Navigation/OpenInNew/BaseOpenInNewTabAction.cs b/src/Files.App/Actions/Navigation/OpenInNew/BaseOpenInNewTabAction.cs new file mode 100644 index 000000000000..087d3410ff67 --- /dev/null +++ b/src/Files.App/Actions/Navigation/OpenInNew/BaseOpenInNewTabAction.cs @@ -0,0 +1,63 @@ +// Copyright (c) 2024 Files Community +// Licensed under the MIT License. See the LICENSE. + +namespace Files.App.Actions +{ + internal abstract class BaseOpenInNewTabAction : ObservableObject, IAction + { + protected IUserSettingsService UserSettingsService { get; } = Ioc.Default.GetRequiredService(); + protected IContentPageContext ContentPageContext { get; } = Ioc.Default.GetRequiredService(); + + public string Label + => "OpenInNewTab".GetLocalizedResource(); + + public string Description + => "OpenDirectoryInNewTabDescription".GetLocalizedResource(); + + public RichGlyph Glyph + => new(opacityStyle: "ColorIconOpenInNewTab"); + + public virtual bool IsExecutable => + ContentPageContext.ShellPage is not null && + ContentPageContext.ShellPage.SlimContentPage is not null && + ContentPageContext.SelectedItems.Count <= 5 && + ContentPageContext.SelectedItems.Count(x => x.IsFolder) == ContentPageContext.SelectedItems.Count && + UserSettingsService.GeneralSettingsService.ShowOpenInNewTab; + + public BaseOpenInNewTabAction() + { + ContentPageContext.PropertyChanged += Context_PropertyChanged; + } + + public virtual async Task ExecuteAsync() + { + if (ContentPageContext.ShellPage?.SlimContentPage?.SelectedItems is null) + return; + + foreach (ListedItem listedItem in ContentPageContext.SelectedItems) + { + await MainWindow.Instance.DispatcherQueue.EnqueueOrInvokeAsync(async () => + { + await NavigationHelpers.AddNewTabByPathAsync( + typeof(PaneHolderPage), + (listedItem as ShortcutItem)?.TargetPath ?? listedItem.ItemPath, + false); + }, + Microsoft.UI.Dispatching.DispatcherQueuePriority.Low); + } + } + + protected virtual void Context_PropertyChanged(object? sender, PropertyChangedEventArgs e) + { + switch (e.PropertyName) + { + case nameof(IContentPageContext.ShellPage): + case nameof(IContentPageContext.PageType): + case nameof(IContentPageContext.HasSelection): + case nameof(IContentPageContext.SelectedItems): + OnPropertyChanged(nameof(IsExecutable)); + break; + } + } + } +} diff --git a/src/Files.App/Actions/Navigation/OpenInNew/BaseOpenInNewWindowAction.cs b/src/Files.App/Actions/Navigation/OpenInNew/BaseOpenInNewWindowAction.cs new file mode 100644 index 000000000000..8378d85c71b3 --- /dev/null +++ b/src/Files.App/Actions/Navigation/OpenInNew/BaseOpenInNewWindowAction.cs @@ -0,0 +1,66 @@ +// Copyright (c) 2024 Files Community +// Licensed under the MIT License. See the LICENSE. + +using Windows.System; + +namespace Files.App.Actions +{ + internal abstract class BaseOpenInNewWindowAction : ObservableObject, IAction + { + protected IUserSettingsService UserSettingsService { get; } = Ioc.Default.GetRequiredService(); + protected IContentPageContext ContentPageContext { get; } = Ioc.Default.GetRequiredService(); + + public string Label + => "OpenInNewWindow".GetLocalizedResource(); + + public string Description + => "OpenInNewWindowDescription".GetLocalizedResource(); + + public HotKey HotKey + => new(Keys.Enter, KeyModifiers.CtrlAlt); + + public RichGlyph Glyph + => new(opacityStyle: "ColorIconOpenInNewWindow"); + + public virtual bool IsExecutable => + ContentPageContext.ShellPage is not null && + ContentPageContext.ShellPage.SlimContentPage is not null && + ContentPageContext.SelectedItems.Count <= 5 && + ContentPageContext.SelectedItems.Count(x => x.IsFolder) == ContentPageContext.SelectedItems.Count && + UserSettingsService.GeneralSettingsService.ShowOpenInNewWindow; + + public BaseOpenInNewWindowAction() + { + ContentPageContext.PropertyChanged += Context_PropertyChanged; + } + + public virtual async Task ExecuteAsync() + { + if (ContentPageContext.ShellPage?.SlimContentPage?.SelectedItems is null) + return; + + List items = ContentPageContext.ShellPage.SlimContentPage.SelectedItems; + + foreach (ListedItem listedItem in items) + { + var selectedItemPath = (listedItem as ShortcutItem)?.TargetPath ?? listedItem.ItemPath; + var folderUri = new Uri($"files-uwp:?folder={@selectedItemPath}"); + + await Launcher.LaunchUriAsync(folderUri); + } + } + + protected virtual void Context_PropertyChanged(object? sender, PropertyChangedEventArgs e) + { + switch (e.PropertyName) + { + case nameof(IContentPageContext.ShellPage): + case nameof(IContentPageContext.PageType): + case nameof(IContentPageContext.HasSelection): + case nameof(IContentPageContext.SelectedItems): + OnPropertyChanged(nameof(IsExecutable)); + break; + } + } + } +} diff --git a/src/Files.App/Actions/Navigation/OpenInNew/OpenInNewPaneAction.cs b/src/Files.App/Actions/Navigation/OpenInNew/OpenInNewPaneAction.cs new file mode 100644 index 000000000000..f995dcaa3c51 --- /dev/null +++ b/src/Files.App/Actions/Navigation/OpenInNew/OpenInNewPaneAction.cs @@ -0,0 +1,9 @@ +// Copyright (c) 2024 Files Community +// Licensed under the MIT License. See the LICENSE. + +namespace Files.App.Actions +{ + internal sealed class OpenInNewPaneAction : BaseOpenInNewPaneAction + { + } +} diff --git a/src/Files.App/Actions/Navigation/OpenInNew/OpenInNewPaneFromHomeAction.cs b/src/Files.App/Actions/Navigation/OpenInNew/OpenInNewPaneFromHomeAction.cs new file mode 100644 index 000000000000..457568f5e919 --- /dev/null +++ b/src/Files.App/Actions/Navigation/OpenInNew/OpenInNewPaneFromHomeAction.cs @@ -0,0 +1,35 @@ +// Copyright (c) 2024 Files Community +// Licensed under the MIT License. See the LICENSE. + +namespace Files.App.Actions +{ + internal sealed class OpenInNewPaneFromHomeAction : BaseOpenInNewPaneAction + { + public override bool IsExecutable => + ContentPageContext.SelectedItem is not null && + ContentPageContext.SelectedItem.IsFolder && + UserSettingsService.GeneralSettingsService.ShowOpenInNewPane; + + public override Task ExecuteAsync() + { + NavigationHelpers.OpenInSecondaryPane( + ContentPageContext.ShellPage, + ContentPageContext.ShellPage.SlimContentPage.SelectedItems.FirstOrDefault()); + + return Task.CompletedTask; + } + + protected override void Context_PropertyChanged(object? sender, PropertyChangedEventArgs e) + { + switch (e.PropertyName) + { + case nameof(IContentPageContext.ShellPage): + case nameof(IContentPageContext.PageType): + case nameof(IContentPageContext.HasSelection): + case nameof(IContentPageContext.SelectedItems): + OnPropertyChanged(nameof(IsExecutable)); + break; + } + } + } +} diff --git a/src/Files.App/Actions/Navigation/OpenInNew/OpenInNewPaneFromSidebarAction.cs b/src/Files.App/Actions/Navigation/OpenInNew/OpenInNewPaneFromSidebarAction.cs new file mode 100644 index 000000000000..452afb567160 --- /dev/null +++ b/src/Files.App/Actions/Navigation/OpenInNew/OpenInNewPaneFromSidebarAction.cs @@ -0,0 +1,30 @@ +// Copyright (c) 2024 Files Community +// Licensed under the MIT License. See the LICENSE. + +namespace Files.App.Actions +{ + internal sealed class OpenInNewPaneFromSidebarAction : BaseOpenInNewPaneAction + { + public override Task ExecuteAsync() + { + NavigationHelpers.OpenInSecondaryPane( + ContentPageContext.ShellPage, + ContentPageContext.ShellPage.SlimContentPage.SelectedItems.FirstOrDefault()); + + return Task.CompletedTask; + } + + protected override void Context_PropertyChanged(object? sender, PropertyChangedEventArgs e) + { + switch (e.PropertyName) + { + case nameof(IContentPageContext.ShellPage): + case nameof(IContentPageContext.PageType): + case nameof(IContentPageContext.HasSelection): + case nameof(IContentPageContext.SelectedItems): + OnPropertyChanged(nameof(IsExecutable)); + break; + } + } + } +} diff --git a/src/Files.App/Actions/Navigation/OpenInNew/OpenInNewTabAction.cs b/src/Files.App/Actions/Navigation/OpenInNew/OpenInNewTabAction.cs new file mode 100644 index 000000000000..e3ec0926b93d --- /dev/null +++ b/src/Files.App/Actions/Navigation/OpenInNew/OpenInNewTabAction.cs @@ -0,0 +1,9 @@ +// Copyright (c) 2024 Files Community +// Licensed under the MIT License. See the LICENSE. + +namespace Files.App.Actions +{ + internal sealed class OpenInNewTabAction : BaseOpenInNewTabAction + { + } +} diff --git a/src/Files.App/Actions/Navigation/OpenInNew/OpenInNewTabFromHomeAction.cs b/src/Files.App/Actions/Navigation/OpenInNew/OpenInNewTabFromHomeAction.cs new file mode 100644 index 000000000000..340294632629 --- /dev/null +++ b/src/Files.App/Actions/Navigation/OpenInNew/OpenInNewTabFromHomeAction.cs @@ -0,0 +1,9 @@ +// Copyright (c) 2024 Files Community +// Licensed under the MIT License. See the LICENSE. + +namespace Files.App.Actions +{ + internal sealed class OpenInNewTabFromHomeAction : BaseOpenInNewTabAction + { + } +} diff --git a/src/Files.App/Actions/Navigation/OpenInNew/OpenInNewTabFromSidebarAction.cs b/src/Files.App/Actions/Navigation/OpenInNew/OpenInNewTabFromSidebarAction.cs new file mode 100644 index 000000000000..09fb1045d99e --- /dev/null +++ b/src/Files.App/Actions/Navigation/OpenInNew/OpenInNewTabFromSidebarAction.cs @@ -0,0 +1,9 @@ +// Copyright (c) 2024 Files Community +// Licensed under the MIT License. See the LICENSE. + +namespace Files.App.Actions +{ + internal sealed class OpenInNewTabFromSidebarAction : BaseOpenInNewTabAction + { + } +} diff --git a/src/Files.App/Actions/Navigation/OpenInNew/OpenInNewWindowAction.cs b/src/Files.App/Actions/Navigation/OpenInNew/OpenInNewWindowAction.cs new file mode 100644 index 000000000000..b556f25ccb34 --- /dev/null +++ b/src/Files.App/Actions/Navigation/OpenInNew/OpenInNewWindowAction.cs @@ -0,0 +1,9 @@ +// Copyright (c) 2024 Files Community +// Licensed under the MIT License. See the LICENSE. + +namespace Files.App.Actions +{ + internal sealed class OpenInNewWindowAction : BaseOpenInNewWindowAction + { + } +} diff --git a/src/Files.App/Actions/Navigation/OpenInNew/OpenInNewWindowFromHomeAction.cs b/src/Files.App/Actions/Navigation/OpenInNew/OpenInNewWindowFromHomeAction.cs new file mode 100644 index 000000000000..109b51b47937 --- /dev/null +++ b/src/Files.App/Actions/Navigation/OpenInNew/OpenInNewWindowFromHomeAction.cs @@ -0,0 +1,9 @@ +// Copyright (c) 2024 Files Community +// Licensed under the MIT License. See the LICENSE. + +namespace Files.App.Actions +{ + internal sealed class OpenInNewWindowFromHomeAction : BaseOpenInNewWindowAction + { + } +} diff --git a/src/Files.App/Actions/Navigation/OpenInNew/OpenInNewWindowFromSidebarAction.cs b/src/Files.App/Actions/Navigation/OpenInNew/OpenInNewWindowFromSidebarAction.cs new file mode 100644 index 000000000000..a184ff89eacd --- /dev/null +++ b/src/Files.App/Actions/Navigation/OpenInNew/OpenInNewWindowFromSidebarAction.cs @@ -0,0 +1,9 @@ +// Copyright (c) 2024 Files Community +// Licensed under the MIT License. See the LICENSE. + +namespace Files.App.Actions +{ + internal sealed class OpenInNewWindowFromSidebarAction : BaseOpenInNewWindowAction + { + } +} diff --git a/src/Files.App/Actions/Navigation/OpenInNewPaneAction.cs b/src/Files.App/Actions/Navigation/OpenInNewPaneAction.cs deleted file mode 100644 index 3b0485070984..000000000000 --- a/src/Files.App/Actions/Navigation/OpenInNewPaneAction.cs +++ /dev/null @@ -1,53 +0,0 @@ -// Copyright (c) 2024 Files Community -// Licensed under the MIT License. See the LICENSE. - -namespace Files.App.Actions -{ - internal sealed class OpenInNewPaneAction : ObservableObject, IAction - { - private readonly IContentPageContext context; - - private readonly IUserSettingsService userSettingsService; - - public string Label - => "OpenInNewPane".GetLocalizedResource(); - - public string Description - => "OpenDirectoryInNewPaneDescription".GetLocalizedResource(); - - public bool IsExecutable => - context.SelectedItem is not null && - context.SelectedItem.IsFolder && - userSettingsService.GeneralSettingsService.ShowOpenInNewPane; - - public OpenInNewPaneAction() - { - context = Ioc.Default.GetRequiredService(); - userSettingsService = Ioc.Default.GetRequiredService(); - - context.PropertyChanged += Context_PropertyChanged; - } - - public Task ExecuteAsync() - { - NavigationHelpers.OpenInSecondaryPane( - context.ShellPage, - context.ShellPage.SlimContentPage.SelectedItems.FirstOrDefault()); - - return Task.CompletedTask; - } - - private void Context_PropertyChanged(object? sender, PropertyChangedEventArgs e) - { - switch (e.PropertyName) - { - case nameof(IContentPageContext.ShellPage): - case nameof(IContentPageContext.PageType): - case nameof(IContentPageContext.HasSelection): - case nameof(IContentPageContext.SelectedItems): - OnPropertyChanged(nameof(IsExecutable)); - break; - } - } - } -} diff --git a/src/Files.App/Actions/Navigation/OpenInNewTabAction.cs b/src/Files.App/Actions/Navigation/OpenInNewTabAction.cs deleted file mode 100644 index 8de3d4e8f234..000000000000 --- a/src/Files.App/Actions/Navigation/OpenInNewTabAction.cs +++ /dev/null @@ -1,67 +0,0 @@ -// Copyright (c) 2024 Files Community -// Licensed under the MIT License. See the LICENSE. - -namespace Files.App.Actions -{ - internal sealed class OpenInNewTabAction : ObservableObject, IAction - { - private readonly IContentPageContext context; - - private readonly IUserSettingsService userSettingsService; - - public string Label - => "OpenInNewTab".GetLocalizedResource(); - - public string Description - => "OpenDirectoryInNewTabDescription".GetLocalizedResource(); - - public RichGlyph Glyph - => new(opacityStyle: "ColorIconOpenInNewTab"); - - public bool IsExecutable => - context.ShellPage is not null && - context.ShellPage.SlimContentPage is not null && - context.SelectedItems.Count <= 5 && - context.SelectedItems.Count(x => x.IsFolder) == context.SelectedItems.Count && - userSettingsService.GeneralSettingsService.ShowOpenInNewTab; - - public OpenInNewTabAction() - { - context = Ioc.Default.GetRequiredService(); - userSettingsService = Ioc.Default.GetRequiredService(); - - context.PropertyChanged += Context_PropertyChanged; - } - - public async Task ExecuteAsync() - { - if (context.ShellPage?.SlimContentPage?.SelectedItems is null) - return; - - foreach (ListedItem listedItem in context.ShellPage.SlimContentPage.SelectedItems) - { - await MainWindow.Instance.DispatcherQueue.EnqueueOrInvokeAsync(async () => - { - await NavigationHelpers.AddNewTabByPathAsync( - typeof(PaneHolderPage), - (listedItem as ShortcutItem)?.TargetPath ?? listedItem.ItemPath, - false); - }, - Microsoft.UI.Dispatching.DispatcherQueuePriority.Low); - } - } - - private void Context_PropertyChanged(object? sender, PropertyChangedEventArgs e) - { - switch (e.PropertyName) - { - case nameof(IContentPageContext.ShellPage): - case nameof(IContentPageContext.PageType): - case nameof(IContentPageContext.HasSelection): - case nameof(IContentPageContext.SelectedItems): - OnPropertyChanged(nameof(IsExecutable)); - break; - } - } - } -} diff --git a/src/Files.App/Actions/Navigation/OpenInNewWindowAction.cs b/src/Files.App/Actions/Navigation/OpenInNewWindowAction.cs deleted file mode 100644 index 26186d18a821..000000000000 --- a/src/Files.App/Actions/Navigation/OpenInNewWindowAction.cs +++ /dev/null @@ -1,70 +0,0 @@ -// Copyright (c) 2024 Files Community -// Licensed under the MIT License. See the LICENSE. - -using Windows.System; - -namespace Files.App.Actions -{ - internal sealed class OpenInNewWindowAction : ObservableObject, IAction - { - private readonly IContentPageContext context; - - private readonly IUserSettingsService userSettingsService; - - public string Label - => "OpenInNewWindow".GetLocalizedResource(); - - public string Description - => "OpenInNewWindowDescription".GetLocalizedResource(); - - public HotKey HotKey - => new(Keys.Enter, KeyModifiers.CtrlAlt); - - public RichGlyph Glyph - => new(opacityStyle: "ColorIconOpenInNewWindow"); - - public bool IsExecutable => - context.ShellPage is not null && - context.ShellPage.SlimContentPage is not null && - context.SelectedItems.Count <= 5 && - context.SelectedItems.Count(x => x.IsFolder) == context.SelectedItems.Count && - userSettingsService.GeneralSettingsService.ShowOpenInNewWindow; - - public OpenInNewWindowAction() - { - context = Ioc.Default.GetRequiredService(); - userSettingsService = Ioc.Default.GetRequiredService(); - - context.PropertyChanged += Context_PropertyChanged; - } - - public async Task ExecuteAsync() - { - if (context.ShellPage?.SlimContentPage?.SelectedItems is null) - return; - - List items = context.ShellPage.SlimContentPage.SelectedItems; - - foreach (ListedItem listedItem in items) - { - var selectedItemPath = (listedItem as ShortcutItem)?.TargetPath ?? listedItem.ItemPath; - var folderUri = new Uri($"files-uwp:?folder={@selectedItemPath}"); - - await Launcher.LaunchUriAsync(folderUri); - } - } - - private void Context_PropertyChanged(object? sender, PropertyChangedEventArgs e) - { - switch (e.PropertyName) - { - case nameof(IContentPageContext.ShellPage): - case nameof(IContentPageContext.PageType): - case nameof(IContentPageContext.HasSelection): - case nameof(IContentPageContext.SelectedItems): - OnPropertyChanged(nameof(IsExecutable)); - break; - } - } - } -} From 9bcc06ed327589c985fe7fc294325146e77f758e Mon Sep 17 00:00:00 2001 From: 0x5BFA Date: Wed, 8 May 2024 01:43:39 +0900 Subject: [PATCH 03/17] Brush up --- .../OpenInNew/OpenInNewPaneFromHomeAction.cs | 35 ------------------- .../OpenInNewPaneFromSidebarAction.cs | 30 ---------------- .../OpenInNew/OpenInNewTabFromHomeAction.cs | 9 ----- .../OpenInNewTabFromSidebarAction.cs | 9 ----- .../OpenInNewWindowFromHomeAction.cs | 9 ----- .../OpenInNewWindowFromSidebarAction.cs | 9 ----- .../BaseOpenInNewPaneAction.cs | 2 ++ .../OpenInNewPaneAction.cs | 0 .../OpenInNewPaneFromHomeAction.cs | 31 ++++++++++++++++ .../OpenInNewPaneFromSidebarAction.cs | 31 ++++++++++++++++ .../BaseOpenInNewTabAction.cs | 6 ++-- .../OpenInNewTabAction.cs | 0 .../OpenInNewTabFromHomeAction.cs | 31 ++++++++++++++++ .../OpenInNewTabFromSidebarAction.cs | 31 ++++++++++++++++ .../BaseOpenInNewWindowAction.cs | 3 ++ .../OpenInNewWindowAction.cs | 0 .../OpenInNewWindowFromHomeAction.cs | 28 +++++++++++++++ .../OpenInNewWindowFromSidebarAction.cs | 28 +++++++++++++++ .../Data/Commands/Manager/CommandCodes.cs | 14 ++++++-- .../Data/Commands/Manager/CommandManager.cs | 18 ++++++++-- .../Data/Commands/Manager/ICommandManager.cs | 15 +++++--- .../ContentPageContextFlyoutFactory.cs | 6 ++-- .../UserControls/SidebarViewModel.cs | 29 ++------------- .../Widgets/BaseWidgetViewModel.cs | 1 + .../Widgets/DrivesWidgetViewModel.cs | 27 +++----------- .../Widgets/FileTagsWidgetViewModel.cs | 26 ++------------ .../Widgets/QuickAccessWidgetViewModel.cs | 26 ++------------ 27 files changed, 242 insertions(+), 212 deletions(-) delete mode 100644 src/Files.App/Actions/Navigation/OpenInNew/OpenInNewPaneFromHomeAction.cs delete mode 100644 src/Files.App/Actions/Navigation/OpenInNew/OpenInNewPaneFromSidebarAction.cs delete mode 100644 src/Files.App/Actions/Navigation/OpenInNew/OpenInNewTabFromHomeAction.cs delete mode 100644 src/Files.App/Actions/Navigation/OpenInNew/OpenInNewTabFromSidebarAction.cs delete mode 100644 src/Files.App/Actions/Navigation/OpenInNew/OpenInNewWindowFromHomeAction.cs delete mode 100644 src/Files.App/Actions/Navigation/OpenInNew/OpenInNewWindowFromSidebarAction.cs rename src/Files.App/Actions/Navigation/{OpenInNew => OpenInNewPane}/BaseOpenInNewPaneAction.cs (87%) rename src/Files.App/Actions/Navigation/{OpenInNew => OpenInNewPane}/OpenInNewPaneAction.cs (100%) create mode 100644 src/Files.App/Actions/Navigation/OpenInNewPane/OpenInNewPaneFromHomeAction.cs create mode 100644 src/Files.App/Actions/Navigation/OpenInNewPane/OpenInNewPaneFromSidebarAction.cs rename src/Files.App/Actions/Navigation/{OpenInNew => OpenInNewTab}/BaseOpenInNewTabAction.cs (88%) rename src/Files.App/Actions/Navigation/{OpenInNew => OpenInNewTab}/OpenInNewTabAction.cs (100%) create mode 100644 src/Files.App/Actions/Navigation/OpenInNewTab/OpenInNewTabFromHomeAction.cs create mode 100644 src/Files.App/Actions/Navigation/OpenInNewTab/OpenInNewTabFromSidebarAction.cs rename src/Files.App/Actions/Navigation/{OpenInNew => OpenInNewWindow}/BaseOpenInNewWindowAction.cs (88%) rename src/Files.App/Actions/Navigation/{OpenInNew => OpenInNewWindow}/OpenInNewWindowAction.cs (100%) create mode 100644 src/Files.App/Actions/Navigation/OpenInNewWindow/OpenInNewWindowFromHomeAction.cs create mode 100644 src/Files.App/Actions/Navigation/OpenInNewWindow/OpenInNewWindowFromSidebarAction.cs diff --git a/src/Files.App/Actions/Navigation/OpenInNew/OpenInNewPaneFromHomeAction.cs b/src/Files.App/Actions/Navigation/OpenInNew/OpenInNewPaneFromHomeAction.cs deleted file mode 100644 index 457568f5e919..000000000000 --- a/src/Files.App/Actions/Navigation/OpenInNew/OpenInNewPaneFromHomeAction.cs +++ /dev/null @@ -1,35 +0,0 @@ -// Copyright (c) 2024 Files Community -// Licensed under the MIT License. See the LICENSE. - -namespace Files.App.Actions -{ - internal sealed class OpenInNewPaneFromHomeAction : BaseOpenInNewPaneAction - { - public override bool IsExecutable => - ContentPageContext.SelectedItem is not null && - ContentPageContext.SelectedItem.IsFolder && - UserSettingsService.GeneralSettingsService.ShowOpenInNewPane; - - public override Task ExecuteAsync() - { - NavigationHelpers.OpenInSecondaryPane( - ContentPageContext.ShellPage, - ContentPageContext.ShellPage.SlimContentPage.SelectedItems.FirstOrDefault()); - - return Task.CompletedTask; - } - - protected override void Context_PropertyChanged(object? sender, PropertyChangedEventArgs e) - { - switch (e.PropertyName) - { - case nameof(IContentPageContext.ShellPage): - case nameof(IContentPageContext.PageType): - case nameof(IContentPageContext.HasSelection): - case nameof(IContentPageContext.SelectedItems): - OnPropertyChanged(nameof(IsExecutable)); - break; - } - } - } -} diff --git a/src/Files.App/Actions/Navigation/OpenInNew/OpenInNewPaneFromSidebarAction.cs b/src/Files.App/Actions/Navigation/OpenInNew/OpenInNewPaneFromSidebarAction.cs deleted file mode 100644 index 452afb567160..000000000000 --- a/src/Files.App/Actions/Navigation/OpenInNew/OpenInNewPaneFromSidebarAction.cs +++ /dev/null @@ -1,30 +0,0 @@ -// Copyright (c) 2024 Files Community -// Licensed under the MIT License. See the LICENSE. - -namespace Files.App.Actions -{ - internal sealed class OpenInNewPaneFromSidebarAction : BaseOpenInNewPaneAction - { - public override Task ExecuteAsync() - { - NavigationHelpers.OpenInSecondaryPane( - ContentPageContext.ShellPage, - ContentPageContext.ShellPage.SlimContentPage.SelectedItems.FirstOrDefault()); - - return Task.CompletedTask; - } - - protected override void Context_PropertyChanged(object? sender, PropertyChangedEventArgs e) - { - switch (e.PropertyName) - { - case nameof(IContentPageContext.ShellPage): - case nameof(IContentPageContext.PageType): - case nameof(IContentPageContext.HasSelection): - case nameof(IContentPageContext.SelectedItems): - OnPropertyChanged(nameof(IsExecutable)); - break; - } - } - } -} diff --git a/src/Files.App/Actions/Navigation/OpenInNew/OpenInNewTabFromHomeAction.cs b/src/Files.App/Actions/Navigation/OpenInNew/OpenInNewTabFromHomeAction.cs deleted file mode 100644 index 340294632629..000000000000 --- a/src/Files.App/Actions/Navigation/OpenInNew/OpenInNewTabFromHomeAction.cs +++ /dev/null @@ -1,9 +0,0 @@ -// Copyright (c) 2024 Files Community -// Licensed under the MIT License. See the LICENSE. - -namespace Files.App.Actions -{ - internal sealed class OpenInNewTabFromHomeAction : BaseOpenInNewTabAction - { - } -} diff --git a/src/Files.App/Actions/Navigation/OpenInNew/OpenInNewTabFromSidebarAction.cs b/src/Files.App/Actions/Navigation/OpenInNew/OpenInNewTabFromSidebarAction.cs deleted file mode 100644 index 09fb1045d99e..000000000000 --- a/src/Files.App/Actions/Navigation/OpenInNew/OpenInNewTabFromSidebarAction.cs +++ /dev/null @@ -1,9 +0,0 @@ -// Copyright (c) 2024 Files Community -// Licensed under the MIT License. See the LICENSE. - -namespace Files.App.Actions -{ - internal sealed class OpenInNewTabFromSidebarAction : BaseOpenInNewTabAction - { - } -} diff --git a/src/Files.App/Actions/Navigation/OpenInNew/OpenInNewWindowFromHomeAction.cs b/src/Files.App/Actions/Navigation/OpenInNew/OpenInNewWindowFromHomeAction.cs deleted file mode 100644 index 109b51b47937..000000000000 --- a/src/Files.App/Actions/Navigation/OpenInNew/OpenInNewWindowFromHomeAction.cs +++ /dev/null @@ -1,9 +0,0 @@ -// Copyright (c) 2024 Files Community -// Licensed under the MIT License. See the LICENSE. - -namespace Files.App.Actions -{ - internal sealed class OpenInNewWindowFromHomeAction : BaseOpenInNewWindowAction - { - } -} diff --git a/src/Files.App/Actions/Navigation/OpenInNew/OpenInNewWindowFromSidebarAction.cs b/src/Files.App/Actions/Navigation/OpenInNew/OpenInNewWindowFromSidebarAction.cs deleted file mode 100644 index a184ff89eacd..000000000000 --- a/src/Files.App/Actions/Navigation/OpenInNew/OpenInNewWindowFromSidebarAction.cs +++ /dev/null @@ -1,9 +0,0 @@ -// Copyright (c) 2024 Files Community -// Licensed under the MIT License. See the LICENSE. - -namespace Files.App.Actions -{ - internal sealed class OpenInNewWindowFromSidebarAction : BaseOpenInNewWindowAction - { - } -} diff --git a/src/Files.App/Actions/Navigation/OpenInNew/BaseOpenInNewPaneAction.cs b/src/Files.App/Actions/Navigation/OpenInNewPane/BaseOpenInNewPaneAction.cs similarity index 87% rename from src/Files.App/Actions/Navigation/OpenInNew/BaseOpenInNewPaneAction.cs rename to src/Files.App/Actions/Navigation/OpenInNewPane/BaseOpenInNewPaneAction.cs index edbbd20cc81b..980d21c006bd 100644 --- a/src/Files.App/Actions/Navigation/OpenInNew/BaseOpenInNewPaneAction.cs +++ b/src/Files.App/Actions/Navigation/OpenInNewPane/BaseOpenInNewPaneAction.cs @@ -7,6 +7,8 @@ internal abstract class BaseOpenInNewPaneAction : ObservableObject, IAction { protected IUserSettingsService UserSettingsService { get; } = Ioc.Default.GetRequiredService(); protected IContentPageContext ContentPageContext { get; } = Ioc.Default.GetRequiredService(); + protected IHomePageContext HomePageContext { get; } = Ioc.Default.GetRequiredService(); + protected ISidebarContext SidebarContext { get; } = Ioc.Default.GetRequiredService(); public string Label => "OpenInNewPane".GetLocalizedResource(); diff --git a/src/Files.App/Actions/Navigation/OpenInNew/OpenInNewPaneAction.cs b/src/Files.App/Actions/Navigation/OpenInNewPane/OpenInNewPaneAction.cs similarity index 100% rename from src/Files.App/Actions/Navigation/OpenInNew/OpenInNewPaneAction.cs rename to src/Files.App/Actions/Navigation/OpenInNewPane/OpenInNewPaneAction.cs diff --git a/src/Files.App/Actions/Navigation/OpenInNewPane/OpenInNewPaneFromHomeAction.cs b/src/Files.App/Actions/Navigation/OpenInNewPane/OpenInNewPaneFromHomeAction.cs new file mode 100644 index 000000000000..2662ce9ff74b --- /dev/null +++ b/src/Files.App/Actions/Navigation/OpenInNewPane/OpenInNewPaneFromHomeAction.cs @@ -0,0 +1,31 @@ +// Copyright (c) 2024 Files Community +// Licensed under the MIT License. See the LICENSE. + +namespace Files.App.Actions +{ + internal sealed class OpenInNewPaneFromHomeAction : BaseOpenInNewPaneAction + { + public override bool IsExecutable => + HomePageContext.IsAnyItemRightClicked && + HomePageContext.RightClickedItem is not null; + + public override async Task ExecuteAsync() + { + if (await DriveHelpers.CheckEmptyDrive(HomePageContext.RightClickedItem!.Path)) + return; + + ContentPageContext.ShellPage!.PaneHolder?.OpenPathInNewPane(HomePageContext.RightClickedItem!.Path ?? string.Empty); + } + + protected override void Context_PropertyChanged(object? sender, PropertyChangedEventArgs e) + { + switch (e.PropertyName) + { + case nameof(IHomePageContext.IsAnyItemRightClicked): + case nameof(IHomePageContext.RightClickedItem): + OnPropertyChanged(nameof(IsExecutable)); + break; + } + } + } +} diff --git a/src/Files.App/Actions/Navigation/OpenInNewPane/OpenInNewPaneFromSidebarAction.cs b/src/Files.App/Actions/Navigation/OpenInNewPane/OpenInNewPaneFromSidebarAction.cs new file mode 100644 index 000000000000..414257f38f99 --- /dev/null +++ b/src/Files.App/Actions/Navigation/OpenInNewPane/OpenInNewPaneFromSidebarAction.cs @@ -0,0 +1,31 @@ +// Copyright (c) 2024 Files Community +// Licensed under the MIT License. See the LICENSE. + +namespace Files.App.Actions +{ + internal sealed class OpenInNewPaneFromSidebarAction : BaseOpenInNewPaneAction + { + public override bool IsExecutable => + SidebarContext.IsItemRightClicked && + SidebarContext.RightClickedItem is not null; + + public override async Task ExecuteAsync() + { + if (await DriveHelpers.CheckEmptyDrive(HomePageContext.RightClickedItem!.Path)) + return; + + ContentPageContext.ShellPage!.PaneHolder?.OpenPathInNewPane(HomePageContext.RightClickedItem!.Path ?? string.Empty); + } + + protected override void Context_PropertyChanged(object? sender, PropertyChangedEventArgs e) + { + switch (e.PropertyName) + { + case nameof(ISidebarContext.IsAnyItemRightClicked): + case nameof(ISidebarContext.RightClickedItem): + OnPropertyChanged(nameof(IsExecutable)); + break; + } + } + } +} diff --git a/src/Files.App/Actions/Navigation/OpenInNew/BaseOpenInNewTabAction.cs b/src/Files.App/Actions/Navigation/OpenInNewTab/BaseOpenInNewTabAction.cs similarity index 88% rename from src/Files.App/Actions/Navigation/OpenInNew/BaseOpenInNewTabAction.cs rename to src/Files.App/Actions/Navigation/OpenInNewTab/BaseOpenInNewTabAction.cs index 087d3410ff67..f5d364bf4b6b 100644 --- a/src/Files.App/Actions/Navigation/OpenInNew/BaseOpenInNewTabAction.cs +++ b/src/Files.App/Actions/Navigation/OpenInNewTab/BaseOpenInNewTabAction.cs @@ -7,6 +7,8 @@ internal abstract class BaseOpenInNewTabAction : ObservableObject, IAction { protected IUserSettingsService UserSettingsService { get; } = Ioc.Default.GetRequiredService(); protected IContentPageContext ContentPageContext { get; } = Ioc.Default.GetRequiredService(); + protected IHomePageContext HomePageContext { get; } = Ioc.Default.GetRequiredService(); + protected ISidebarContext SidebarContext { get; } = Ioc.Default.GetRequiredService(); public string Label => "OpenInNewTab".GetLocalizedResource(); @@ -20,6 +22,7 @@ public RichGlyph Glyph public virtual bool IsExecutable => ContentPageContext.ShellPage is not null && ContentPageContext.ShellPage.SlimContentPage is not null && + ContentPageContext.SelectedItems.Count is not 0 && ContentPageContext.SelectedItems.Count <= 5 && ContentPageContext.SelectedItems.Count(x => x.IsFolder) == ContentPageContext.SelectedItems.Count && UserSettingsService.GeneralSettingsService.ShowOpenInNewTab; @@ -31,9 +34,6 @@ public BaseOpenInNewTabAction() public virtual async Task ExecuteAsync() { - if (ContentPageContext.ShellPage?.SlimContentPage?.SelectedItems is null) - return; - foreach (ListedItem listedItem in ContentPageContext.SelectedItems) { await MainWindow.Instance.DispatcherQueue.EnqueueOrInvokeAsync(async () => diff --git a/src/Files.App/Actions/Navigation/OpenInNew/OpenInNewTabAction.cs b/src/Files.App/Actions/Navigation/OpenInNewTab/OpenInNewTabAction.cs similarity index 100% rename from src/Files.App/Actions/Navigation/OpenInNew/OpenInNewTabAction.cs rename to src/Files.App/Actions/Navigation/OpenInNewTab/OpenInNewTabAction.cs diff --git a/src/Files.App/Actions/Navigation/OpenInNewTab/OpenInNewTabFromHomeAction.cs b/src/Files.App/Actions/Navigation/OpenInNewTab/OpenInNewTabFromHomeAction.cs new file mode 100644 index 000000000000..6d73de17079b --- /dev/null +++ b/src/Files.App/Actions/Navigation/OpenInNewTab/OpenInNewTabFromHomeAction.cs @@ -0,0 +1,31 @@ +// Copyright (c) 2024 Files Community +// Licensed under the MIT License. See the LICENSE. + +namespace Files.App.Actions +{ + internal sealed class OpenInNewTabFromHomeAction : BaseOpenInNewTabAction + { + public override bool IsExecutable => + HomePageContext.IsAnyItemRightClicked && + HomePageContext.RightClickedItem is not null; + + public override async Task ExecuteAsync() + { + if (await DriveHelpers.CheckEmptyDrive(HomePageContext.RightClickedItem!.Path)) + return; + + await NavigationHelpers.OpenPathInNewTab(HomePageContext.RightClickedItem!.Path ?? string.Empty, false); + } + + protected override void Context_PropertyChanged(object? sender, PropertyChangedEventArgs e) + { + switch (e.PropertyName) + { + case nameof(IHomePageContext.IsAnyItemRightClicked): + case nameof(IHomePageContext.RightClickedItem): + OnPropertyChanged(nameof(IsExecutable)); + break; + } + } + } +} diff --git a/src/Files.App/Actions/Navigation/OpenInNewTab/OpenInNewTabFromSidebarAction.cs b/src/Files.App/Actions/Navigation/OpenInNewTab/OpenInNewTabFromSidebarAction.cs new file mode 100644 index 000000000000..a0949f413e9b --- /dev/null +++ b/src/Files.App/Actions/Navigation/OpenInNewTab/OpenInNewTabFromSidebarAction.cs @@ -0,0 +1,31 @@ +// Copyright (c) 2024 Files Community +// Licensed under the MIT License. See the LICENSE. + +namespace Files.App.Actions +{ + internal sealed class OpenInNewTabFromSidebarAction : BaseOpenInNewTabAction + { + public override bool IsExecutable => + SidebarContext.IsItemRightClicked && + SidebarContext.RightClickedItem is not null; + + public override async Task ExecuteAsync() + { + if (await DriveHelpers.CheckEmptyDrive(SidebarContext.RightClickedItem!.Path)) + return; + + await NavigationHelpers.OpenPathInNewTab(SidebarContext.RightClickedItem!.Path ?? string.Empty, false); + } + + protected override void Context_PropertyChanged(object? sender, PropertyChangedEventArgs e) + { + switch (e.PropertyName) + { + case nameof(ISidebarContext.IsItemRightClicked): + case nameof(ISidebarContext.RightClickedItem): + OnPropertyChanged(nameof(IsExecutable)); + break; + } + } + } +} diff --git a/src/Files.App/Actions/Navigation/OpenInNew/BaseOpenInNewWindowAction.cs b/src/Files.App/Actions/Navigation/OpenInNewWindow/BaseOpenInNewWindowAction.cs similarity index 88% rename from src/Files.App/Actions/Navigation/OpenInNew/BaseOpenInNewWindowAction.cs rename to src/Files.App/Actions/Navigation/OpenInNewWindow/BaseOpenInNewWindowAction.cs index 8378d85c71b3..951d815075c9 100644 --- a/src/Files.App/Actions/Navigation/OpenInNew/BaseOpenInNewWindowAction.cs +++ b/src/Files.App/Actions/Navigation/OpenInNewWindow/BaseOpenInNewWindowAction.cs @@ -9,6 +9,8 @@ internal abstract class BaseOpenInNewWindowAction : ObservableObject, IAction { protected IUserSettingsService UserSettingsService { get; } = Ioc.Default.GetRequiredService(); protected IContentPageContext ContentPageContext { get; } = Ioc.Default.GetRequiredService(); + protected IHomePageContext HomePageContext { get; } = Ioc.Default.GetRequiredService(); + protected ISidebarContext SidebarContext { get; } = Ioc.Default.GetRequiredService(); public string Label => "OpenInNewWindow".GetLocalizedResource(); @@ -25,6 +27,7 @@ public RichGlyph Glyph public virtual bool IsExecutable => ContentPageContext.ShellPage is not null && ContentPageContext.ShellPage.SlimContentPage is not null && + ContentPageContext.SelectedItems.Count is not 0 && ContentPageContext.SelectedItems.Count <= 5 && ContentPageContext.SelectedItems.Count(x => x.IsFolder) == ContentPageContext.SelectedItems.Count && UserSettingsService.GeneralSettingsService.ShowOpenInNewWindow; diff --git a/src/Files.App/Actions/Navigation/OpenInNew/OpenInNewWindowAction.cs b/src/Files.App/Actions/Navigation/OpenInNewWindow/OpenInNewWindowAction.cs similarity index 100% rename from src/Files.App/Actions/Navigation/OpenInNew/OpenInNewWindowAction.cs rename to src/Files.App/Actions/Navigation/OpenInNewWindow/OpenInNewWindowAction.cs diff --git a/src/Files.App/Actions/Navigation/OpenInNewWindow/OpenInNewWindowFromHomeAction.cs b/src/Files.App/Actions/Navigation/OpenInNewWindow/OpenInNewWindowFromHomeAction.cs new file mode 100644 index 000000000000..e1da97ce4b96 --- /dev/null +++ b/src/Files.App/Actions/Navigation/OpenInNewWindow/OpenInNewWindowFromHomeAction.cs @@ -0,0 +1,28 @@ +// Copyright (c) 2024 Files Community +// Licensed under the MIT License. See the LICENSE. + +namespace Files.App.Actions +{ + internal sealed class OpenInNewWindowFromHomeAction : BaseOpenInNewWindowAction + { + public override bool IsExecutable => + HomePageContext.IsAnyItemRightClicked && + HomePageContext.RightClickedItem is not null; + + public override Task ExecuteAsync() + { + return NavigationHelpers.OpenPathInNewWindowAsync(HomePageContext.RightClickedItem!.Path ?? string.Empty); + } + + protected override void Context_PropertyChanged(object? sender, PropertyChangedEventArgs e) + { + switch (e.PropertyName) + { + case nameof(IHomePageContext.IsAnyItemRightClicked): + case nameof(IHomePageContext.RightClickedItem): + OnPropertyChanged(nameof(IsExecutable)); + break; + } + } + } +} diff --git a/src/Files.App/Actions/Navigation/OpenInNewWindow/OpenInNewWindowFromSidebarAction.cs b/src/Files.App/Actions/Navigation/OpenInNewWindow/OpenInNewWindowFromSidebarAction.cs new file mode 100644 index 000000000000..719352d01e60 --- /dev/null +++ b/src/Files.App/Actions/Navigation/OpenInNewWindow/OpenInNewWindowFromSidebarAction.cs @@ -0,0 +1,28 @@ +// Copyright (c) 2024 Files Community +// Licensed under the MIT License. See the LICENSE. + +namespace Files.App.Actions +{ + internal sealed class OpenInNewWindowFromSidebarAction : BaseOpenInNewWindowAction + { + public override bool IsExecutable => + SidebarContext.IsItemRightClicked && + SidebarContext.RightClickedItem is not null; + + public override async Task ExecuteAsync() + { + await NavigationHelpers.OpenPathInNewWindowAsync(SidebarContext.RightClickedItem!.Path ?? string.Empty); + } + + protected override void Context_PropertyChanged(object? sender, PropertyChangedEventArgs e) + { + switch (e.PropertyName) + { + case nameof(ISidebarContext.IsItemRightClicked): + case nameof(ISidebarContext.RightClickedItem): + OnPropertyChanged(nameof(IsExecutable)); + break; + } + } + } +} diff --git a/src/Files.App/Data/Commands/Manager/CommandCodes.cs b/src/Files.App/Data/Commands/Manager/CommandCodes.cs index 100256fcc46a..af5186a25ad0 100644 --- a/src/Files.App/Data/Commands/Manager/CommandCodes.cs +++ b/src/Files.App/Data/Commands/Manager/CommandCodes.cs @@ -180,9 +180,6 @@ public enum CommandCodes CloseTabsToTheRightSelected, CloseOtherTabsCurrent, CloseOtherTabsSelected, - OpenInNewPane, - OpenInNewTab, - OpenInNewWindow, ReopenClosedTab, PreviousTab, NextTab, @@ -190,6 +187,17 @@ public enum CommandCodes OpenNewPane, ClosePane, + // OpenInNew + OpenInNewPane, + OpenInNewPaneFromHome, + OpenInNewPaneFromSidebar, + OpenInNewTab, + OpenInNewTabFromHome, + OpenInNewTabFromSidebar, + OpenInNewWindow, + OpenInNewWindowFromHome, + OpenInNewWindowFromSidebar, + // Play PlayAll, diff --git a/src/Files.App/Data/Commands/Manager/CommandManager.cs b/src/Files.App/Data/Commands/Manager/CommandManager.cs index 28a574c57e27..c6f2a4e52e13 100644 --- a/src/Files.App/Data/Commands/Manager/CommandManager.cs +++ b/src/Files.App/Data/Commands/Manager/CommandManager.cs @@ -175,9 +175,15 @@ internal sealed class CommandManager : ICommandManager public IRichCommand CloseTabsToTheRightSelected => commands[CommandCodes.CloseTabsToTheRightSelected]; public IRichCommand CloseOtherTabsCurrent => commands[CommandCodes.CloseOtherTabsCurrent]; public IRichCommand CloseOtherTabsSelected => commands[CommandCodes.CloseOtherTabsSelected]; - public IRichCommand OpenDirectoryInNewPaneAction => commands[CommandCodes.OpenInNewPane]; - public IRichCommand OpenDirectoryInNewTabAction => commands[CommandCodes.OpenInNewTab]; - public IRichCommand OpenInNewWindowItemAction => commands[CommandCodes.OpenInNewWindow]; + public IRichCommand OpenInNewPaneAction => commands[CommandCodes.OpenInNewPane]; + public IRichCommand OpenInNewPaneFromHomeAction => commands[CommandCodes.OpenInNewPaneFromHome]; + public IRichCommand OpenInNewPaneFromSidebarAction => commands[CommandCodes.OpenInNewPaneFromSidebar]; + public IRichCommand OpenInNewTabAction => commands[CommandCodes.OpenInNewTab]; + public IRichCommand OpenInNewTabFromHomeAction => commands[CommandCodes.OpenInNewTabFromHome]; + public IRichCommand OpenInNewTabFromSidebarAction => commands[CommandCodes.OpenInNewTabFromSidebar]; + public IRichCommand OpenInNewWindowAction => commands[CommandCodes.OpenInNewWindow]; + public IRichCommand OpenInNewWindowFromHomeAction => commands[CommandCodes.OpenInNewWindowFromHome]; + public IRichCommand OpenInNewWindowFromSidebarAction => commands[CommandCodes.OpenInNewWindowFromSidebar]; public IRichCommand ReopenClosedTab => commands[CommandCodes.ReopenClosedTab]; public IRichCommand PreviousTab => commands[CommandCodes.PreviousTab]; public IRichCommand NextTab => commands[CommandCodes.NextTab]; @@ -350,8 +356,14 @@ public CommandManager() [CommandCodes.CloseOtherTabsCurrent] = new CloseOtherTabsCurrentAction(), [CommandCodes.CloseOtherTabsSelected] = new CloseOtherTabsSelectedAction(), [CommandCodes.OpenInNewPane] = new OpenInNewPaneAction(), + [CommandCodes.OpenInNewPaneFromHome] = new OpenInNewPaneFromHomeAction(), + [CommandCodes.OpenInNewPaneFromSidebar] = new OpenInNewPaneFromSidebarAction(), [CommandCodes.OpenInNewTab] = new OpenInNewTabAction(), + [CommandCodes.OpenInNewTabFromHome] = new OpenInNewTabFromHomeAction(), + [CommandCodes.OpenInNewTabFromSidebar] = new OpenInNewTabFromSidebarAction(), [CommandCodes.OpenInNewWindow] = new OpenInNewWindowAction(), + [CommandCodes.OpenInNewWindowFromHome] = new OpenInNewWindowFromHomeAction(), + [CommandCodes.OpenInNewWindowFromSidebar] = new OpenInNewWindowFromSidebarAction(), [CommandCodes.ReopenClosedTab] = new ReopenClosedTabAction(), [CommandCodes.PreviousTab] = new PreviousTabAction(), [CommandCodes.NextTab] = new NextTabAction(), diff --git a/src/Files.App/Data/Commands/Manager/ICommandManager.cs b/src/Files.App/Data/Commands/Manager/ICommandManager.cs index d824b7050853..ae230a54e3e7 100644 --- a/src/Files.App/Data/Commands/Manager/ICommandManager.cs +++ b/src/Files.App/Data/Commands/Manager/ICommandManager.cs @@ -165,16 +165,23 @@ public interface ICommandManager : IEnumerable IRichCommand CloseTabsToTheRightSelected { get; } IRichCommand CloseOtherTabsCurrent { get; } IRichCommand CloseOtherTabsSelected { get; } - IRichCommand OpenDirectoryInNewPaneAction { get; } - IRichCommand OpenDirectoryInNewTabAction { get; } - IRichCommand OpenInNewWindowItemAction { get; } IRichCommand ReopenClosedTab { get; } IRichCommand PreviousTab { get; } IRichCommand NextTab { get; } IRichCommand CloseSelectedTab { get; } IRichCommand OpenNewPane { get; } IRichCommand ClosePane { get; } - + + IRichCommand OpenInNewPaneAction { get; } + IRichCommand OpenInNewPaneFromHomeAction { get; } + IRichCommand OpenInNewPaneFromSidebarAction { get; } + IRichCommand OpenInNewTabAction { get; } + IRichCommand OpenInNewTabFromHomeAction { get; } + IRichCommand OpenInNewTabFromSidebarAction { get; } + IRichCommand OpenInNewWindowAction { get; } + IRichCommand OpenInNewWindowFromHomeAction { get; } + IRichCommand OpenInNewWindowFromSidebarAction { get; } + IRichCommand PlayAll { get; } IRichCommand GitFetch { get; } diff --git a/src/Files.App/Data/Factories/ContentPageContextFlyoutFactory.cs b/src/Files.App/Data/Factories/ContentPageContextFlyoutFactory.cs index e4f90c6589d8..b0837ef38e87 100644 --- a/src/Files.App/Data/Factories/ContentPageContextFlyoutFactory.cs +++ b/src/Files.App/Data/Factories/ContentPageContextFlyoutFactory.cs @@ -398,9 +398,9 @@ private static bool Check(ContextMenuFlyoutItemViewModel item, CurrentInstanceVi ShowItem = itemsSelected && showOpenItemWith }, new ContextMenuFlyoutItemViewModelBuilder(Commands.OpenFileLocation).Build(), - new ContextMenuFlyoutItemViewModelBuilder(Commands.OpenDirectoryInNewTabAction).Build(), - new ContextMenuFlyoutItemViewModelBuilder(Commands.OpenInNewWindowItemAction).Build(), - new ContextMenuFlyoutItemViewModelBuilder(Commands.OpenDirectoryInNewPaneAction).Build(), + new ContextMenuFlyoutItemViewModelBuilder(Commands.OpenInNewTabAction).Build(), + new ContextMenuFlyoutItemViewModelBuilder(Commands.OpenInNewWindowAction).Build(), + new ContextMenuFlyoutItemViewModelBuilder(Commands.OpenInNewPaneAction).Build(), new ContextMenuFlyoutItemViewModel() { Text = "BaseLayoutItemContextFlyoutSetAs/Text".GetLocalizedResource(), diff --git a/src/Files.App/ViewModels/UserControls/SidebarViewModel.cs b/src/Files.App/ViewModels/UserControls/SidebarViewModel.cs index ac792a8b34b9..6421a3d0bcb0 100644 --- a/src/Files.App/ViewModels/UserControls/SidebarViewModel.cs +++ b/src/Files.App/ViewModels/UserControls/SidebarViewModel.cs @@ -971,32 +971,9 @@ private List GetLocationItemMenuItems(INavigatio { IsVisible = options.ShowEmptyRecycleBin, }.Build(), - new ContextMenuFlyoutItemViewModel() - { - Text = "OpenInNewTab".GetLocalizedResource(), - OpacityIcon = new OpacityIconModel() - { - OpacityIconStyle = "ColorIconOpenInNewTab", - }, - Command = OpenInNewTabCommand, - ShowItem = options.IsLocationItem && UserSettingsService.GeneralSettingsService.ShowOpenInNewTab - }, - new ContextMenuFlyoutItemViewModel() - { - Text = "OpenInNewWindow".GetLocalizedResource(), - OpacityIcon = new OpacityIconModel() - { - OpacityIconStyle = "ColorIconOpenInNewWindow", - }, - Command = OpenInNewWindowCommand, - ShowItem = options.IsLocationItem && UserSettingsService.GeneralSettingsService.ShowOpenInNewTab - }, - new ContextMenuFlyoutItemViewModel() - { - Text = "OpenInNewPane".GetLocalizedResource(), - Command = OpenInNewPaneCommand, - ShowItem = options.IsLocationItem && UserSettingsService.GeneralSettingsService.ShowOpenInNewPane - }, + new ContextMenuFlyoutItemViewModelBuilder(Commands.OpenInNewTabFromSidebarAction).Build(), + new ContextMenuFlyoutItemViewModelBuilder(Commands.OpenInNewWindowFromSidebarAction).Build(), + new ContextMenuFlyoutItemViewModelBuilder(Commands.OpenInNewPaneFromSidebarAction).Build(), new ContextMenuFlyoutItemViewModel() { Text = "PinFolderToSidebar".GetLocalizedResource(), diff --git a/src/Files.App/ViewModels/UserControls/Widgets/BaseWidgetViewModel.cs b/src/Files.App/ViewModels/UserControls/Widgets/BaseWidgetViewModel.cs index 2c13dccf129b..aa6f0023fcb4 100644 --- a/src/Files.App/ViewModels/UserControls/Widgets/BaseWidgetViewModel.cs +++ b/src/Files.App/ViewModels/UserControls/Widgets/BaseWidgetViewModel.cs @@ -25,6 +25,7 @@ public abstract class BaseWidgetViewModel : ObservableObject protected IFileTagsService FileTagsService { get; } = Ioc.Default.GetRequiredService(); protected DrivesViewModel DrivesViewModel { get; } = Ioc.Default.GetRequiredService(); protected INetworkDrivesService NetworkDrivesService { get; } = Ioc.Default.GetRequiredService(); + protected ICommandManager CommandManager { get; } = Ioc.Default.GetRequiredService(); // Fields diff --git a/src/Files.App/ViewModels/UserControls/Widgets/DrivesWidgetViewModel.cs b/src/Files.App/ViewModels/UserControls/Widgets/DrivesWidgetViewModel.cs index f1e4e4152197..2c4127b8205c 100644 --- a/src/Files.App/ViewModels/UserControls/Widgets/DrivesWidgetViewModel.cs +++ b/src/Files.App/ViewModels/UserControls/Widgets/DrivesWidgetViewModel.cs @@ -1,6 +1,7 @@ // Copyright (c) 2024 Files Community // Licensed under the MIT License. See the LICENSE. +using LibGit2Sharp; using Microsoft.UI.Input; using Microsoft.UI.Xaml.Controls; using System.Collections.Specialized; @@ -98,29 +99,9 @@ public override List GetItemMenuItems(WidgetCard return new List() { - new() - { - Text = "OpenInNewTab".GetLocalizedResource(), - OpacityIcon = new OpacityIconModel() { OpacityIconStyle = "ColorIconOpenInNewTab" }, - Command = OpenInNewTabCommand, - CommandParameter = item, - ShowItem = UserSettingsService.GeneralSettingsService.ShowOpenInNewTab - }, - new() - { - Text = "OpenInNewWindow".GetLocalizedResource(), - OpacityIcon = new OpacityIconModel() { OpacityIconStyle = "ColorIconOpenInNewWindow" }, - Command = OpenInNewWindowCommand, - CommandParameter = item, - ShowItem = UserSettingsService.GeneralSettingsService.ShowOpenInNewWindow - }, - new() - { - Text = "OpenInNewPane".GetLocalizedResource(), - Command = OpenInNewPaneCommand, - CommandParameter = item, - ShowItem = UserSettingsService.GeneralSettingsService.ShowOpenInNewPane - }, + new ContextMenuFlyoutItemViewModelBuilder(CommandManager.OpenInNewTabFromHomeAction).Build(), + new ContextMenuFlyoutItemViewModelBuilder(CommandManager.OpenInNewWindowFromHomeAction).Build(), + new ContextMenuFlyoutItemViewModelBuilder(CommandManager.OpenInNewPaneFromHomeAction).Build(), new() { Text = "PinFolderToSidebar".GetLocalizedResource(), diff --git a/src/Files.App/ViewModels/UserControls/Widgets/FileTagsWidgetViewModel.cs b/src/Files.App/ViewModels/UserControls/Widgets/FileTagsWidgetViewModel.cs index 2cba6f8ad70b..382f4886d837 100644 --- a/src/Files.App/ViewModels/UserControls/Widgets/FileTagsWidgetViewModel.cs +++ b/src/Files.App/ViewModels/UserControls/Widgets/FileTagsWidgetViewModel.cs @@ -73,6 +73,9 @@ public override List GetItemMenuItems(WidgetCard { return new List() { + new ContextMenuFlyoutItemViewModelBuilder(CommandManager.OpenInNewTabFromHomeAction).Build(), + new ContextMenuFlyoutItemViewModelBuilder(CommandManager.OpenInNewWindowFromHomeAction).Build(), + new ContextMenuFlyoutItemViewModelBuilder(CommandManager.OpenInNewPaneFromHomeAction).Build(), new() { Text = "OpenWith".GetLocalizedResource(), @@ -81,22 +84,6 @@ public override List GetItemMenuItems(WidgetCard ShowItem = !isFolder }, new() - { - Text = "OpenInNewTab".GetLocalizedResource(), - OpacityIcon = new() { OpacityIconStyle = "ColorIconOpenInNewTab" }, - Command = OpenInNewTabCommand, - CommandParameter = item, - ShowItem = isFolder - }, - new() - { - Text = "OpenInNewWindow".GetLocalizedResource(), - OpacityIcon = new() { OpacityIconStyle = "ColorIconOpenInNewWindow" }, - Command = OpenInNewWindowCommand, - CommandParameter = item, - ShowItem = isFolder - }, - new() { Text = "OpenFileLocation".GetLocalizedResource(), Glyph = "\uED25", @@ -105,13 +92,6 @@ public override List GetItemMenuItems(WidgetCard ShowItem = !isFolder }, new() - { - Text = "OpenInNewPane".GetLocalizedResource(), - Command = OpenInNewPaneCommand, - CommandParameter = item, - ShowItem = UserSettingsService.GeneralSettingsService.ShowOpenInNewPane && isFolder - }, - new() { Text = "PinFolderToSidebar".GetLocalizedResource(), OpacityIcon = new() { OpacityIconStyle = "Icons.Pin.16x16" }, diff --git a/src/Files.App/ViewModels/UserControls/Widgets/QuickAccessWidgetViewModel.cs b/src/Files.App/ViewModels/UserControls/Widgets/QuickAccessWidgetViewModel.cs index 5b4674e9ba3c..5680e0cfd283 100644 --- a/src/Files.App/ViewModels/UserControls/Widgets/QuickAccessWidgetViewModel.cs +++ b/src/Files.App/ViewModels/UserControls/Widgets/QuickAccessWidgetViewModel.cs @@ -67,29 +67,9 @@ public override List GetItemMenuItems(WidgetCard { return new List() { - new() - { - Text = "OpenInNewTab".GetLocalizedResource(), - OpacityIcon = new() { OpacityIconStyle = "ColorIconOpenInNewTab" }, - Command = OpenInNewTabCommand, - CommandParameter = item, - ShowItem = UserSettingsService.GeneralSettingsService.ShowOpenInNewTab - }, - new() - { - Text = "OpenInNewWindow".GetLocalizedResource(), - OpacityIcon = new() { OpacityIconStyle = "ColorIconOpenInNewWindow" }, - Command = OpenInNewWindowCommand, - CommandParameter = item, - ShowItem = UserSettingsService.GeneralSettingsService.ShowOpenInNewWindow - }, - new() - { - Text = "OpenInNewPane".GetLocalizedResource(), - Command = OpenInNewPaneCommand, - CommandParameter = item, - ShowItem = UserSettingsService.GeneralSettingsService.ShowOpenInNewPane - }, + new ContextMenuFlyoutItemViewModelBuilder(CommandManager.OpenInNewTabFromHomeAction).Build(), + new ContextMenuFlyoutItemViewModelBuilder(CommandManager.OpenInNewWindowFromHomeAction).Build(), + new ContextMenuFlyoutItemViewModelBuilder(CommandManager.OpenInNewPaneFromHomeAction).Build(), new() { Text = "PinFolderToSidebar".GetLocalizedResource(), From d9584bd8bfd3dd1536e4d368749923e835135a07 Mon Sep 17 00:00:00 2001 From: 0x5BFA Date: Wed, 8 May 2024 01:49:55 +0900 Subject: [PATCH 04/17] Fix --- .../Navigation/OpenInNewPane/OpenInNewPaneFromSidebarAction.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Files.App/Actions/Navigation/OpenInNewPane/OpenInNewPaneFromSidebarAction.cs b/src/Files.App/Actions/Navigation/OpenInNewPane/OpenInNewPaneFromSidebarAction.cs index 414257f38f99..456c30604892 100644 --- a/src/Files.App/Actions/Navigation/OpenInNewPane/OpenInNewPaneFromSidebarAction.cs +++ b/src/Files.App/Actions/Navigation/OpenInNewPane/OpenInNewPaneFromSidebarAction.cs @@ -21,7 +21,7 @@ protected override void Context_PropertyChanged(object? sender, PropertyChangedE { switch (e.PropertyName) { - case nameof(ISidebarContext.IsAnyItemRightClicked): + case nameof(ISidebarContext.IsItemRightClicked): case nameof(ISidebarContext.RightClickedItem): OnPropertyChanged(nameof(IsExecutable)); break; From d45e0d335c25bed367f2f21b0123299047dac7ba Mon Sep 17 00:00:00 2001 From: 0x5BFA Date: Wed, 8 May 2024 02:16:09 +0900 Subject: [PATCH 05/17] Fixed runtime failure --- .../Navigation/OpenInNewWindow/BaseOpenInNewWindowAction.cs | 2 +- .../OpenInNewWindow/OpenInNewWindowFromHomeAction.cs | 3 +++ .../OpenInNewWindow/OpenInNewWindowFromSidebarAction.cs | 3 +++ src/Files.App/Helpers/Application/AppLifecycleHelper.cs | 1 + 4 files changed, 8 insertions(+), 1 deletion(-) diff --git a/src/Files.App/Actions/Navigation/OpenInNewWindow/BaseOpenInNewWindowAction.cs b/src/Files.App/Actions/Navigation/OpenInNewWindow/BaseOpenInNewWindowAction.cs index 951d815075c9..9454c0214c22 100644 --- a/src/Files.App/Actions/Navigation/OpenInNewWindow/BaseOpenInNewWindowAction.cs +++ b/src/Files.App/Actions/Navigation/OpenInNewWindow/BaseOpenInNewWindowAction.cs @@ -18,7 +18,7 @@ public string Label public string Description => "OpenInNewWindowDescription".GetLocalizedResource(); - public HotKey HotKey + public virtual HotKey HotKey => new(Keys.Enter, KeyModifiers.CtrlAlt); public RichGlyph Glyph diff --git a/src/Files.App/Actions/Navigation/OpenInNewWindow/OpenInNewWindowFromHomeAction.cs b/src/Files.App/Actions/Navigation/OpenInNewWindow/OpenInNewWindowFromHomeAction.cs index e1da97ce4b96..f12b5eee65b7 100644 --- a/src/Files.App/Actions/Navigation/OpenInNewWindow/OpenInNewWindowFromHomeAction.cs +++ b/src/Files.App/Actions/Navigation/OpenInNewWindow/OpenInNewWindowFromHomeAction.cs @@ -5,6 +5,9 @@ namespace Files.App.Actions { internal sealed class OpenInNewWindowFromHomeAction : BaseOpenInNewWindowAction { + public override HotKey HotKey + => HotKey.None; + public override bool IsExecutable => HomePageContext.IsAnyItemRightClicked && HomePageContext.RightClickedItem is not null; diff --git a/src/Files.App/Actions/Navigation/OpenInNewWindow/OpenInNewWindowFromSidebarAction.cs b/src/Files.App/Actions/Navigation/OpenInNewWindow/OpenInNewWindowFromSidebarAction.cs index 719352d01e60..941bd08741e8 100644 --- a/src/Files.App/Actions/Navigation/OpenInNewWindow/OpenInNewWindowFromSidebarAction.cs +++ b/src/Files.App/Actions/Navigation/OpenInNewWindow/OpenInNewWindowFromSidebarAction.cs @@ -5,6 +5,9 @@ namespace Files.App.Actions { internal sealed class OpenInNewWindowFromSidebarAction : BaseOpenInNewWindowAction { + public override HotKey HotKey + => HotKey.None; + public override bool IsExecutable => SidebarContext.IsItemRightClicked && SidebarContext.RightClickedItem is not null; diff --git a/src/Files.App/Helpers/Application/AppLifecycleHelper.cs b/src/Files.App/Helpers/Application/AppLifecycleHelper.cs index 67fb24dc9542..f4cca3afa54d 100644 --- a/src/Files.App/Helpers/Application/AppLifecycleHelper.cs +++ b/src/Files.App/Helpers/Application/AppLifecycleHelper.cs @@ -160,6 +160,7 @@ public static IHost ConfigureHost() .AddSingleton() .AddSingleton() .AddSingleton() + .AddSingleton() // Services .AddSingleton() .AddSingleton() From 4638d360b7eff93682da248dc7b9308ff0573ab8 Mon Sep 17 00:00:00 2001 From: 0x5bfa <62196528+0x5bfa@users.noreply.github.com> Date: Thu, 9 May 2024 08:39:01 +0900 Subject: [PATCH 06/17] Added IsContextual --- src/Files.App/Actions/IAction.cs | 6 ++++++ .../Navigation/OpenInNewPane/OpenInNewPaneFromHomeAction.cs | 3 +++ .../OpenInNewPane/OpenInNewPaneFromSidebarAction.cs | 3 +++ .../Navigation/OpenInNewTab/OpenInNewTabFromHomeAction.cs | 3 +++ .../OpenInNewTab/OpenInNewTabFromSidebarAction.cs | 3 +++ .../OpenInNewWindow/OpenInNewWindowFromHomeAction.cs | 3 +++ .../OpenInNewWindow/OpenInNewWindowFromSidebarAction.cs | 3 +++ src/Files.App/Data/Commands/ActionCommand.cs | 3 +++ src/Files.App/Data/Commands/IRichCommand.cs | 1 + src/Files.App/Data/Commands/ModifiableCommand.cs | 3 +++ src/Files.App/Data/Commands/NoneCommand.cs | 1 + .../ViewModels/UserControls/AddressToolbarViewModel.cs | 1 + .../UserControls/Widgets/DrivesWidgetViewModel.cs | 1 - 13 files changed, 33 insertions(+), 1 deletion(-) diff --git a/src/Files.App/Actions/IAction.cs b/src/Files.App/Actions/IAction.cs index 196a631b34bd..280fba663380 100644 --- a/src/Files.App/Actions/IAction.cs +++ b/src/Files.App/Actions/IAction.cs @@ -52,6 +52,12 @@ HotKey MediaHotKey bool IsExecutable => true; + /// + /// Returns whether the action is accessible in the specific context. + /// + bool IsContextual + => false; + /// /// Executes the action asynchronously. /// diff --git a/src/Files.App/Actions/Navigation/OpenInNewPane/OpenInNewPaneFromHomeAction.cs b/src/Files.App/Actions/Navigation/OpenInNewPane/OpenInNewPaneFromHomeAction.cs index 2662ce9ff74b..b94a67b4b584 100644 --- a/src/Files.App/Actions/Navigation/OpenInNewPane/OpenInNewPaneFromHomeAction.cs +++ b/src/Files.App/Actions/Navigation/OpenInNewPane/OpenInNewPaneFromHomeAction.cs @@ -9,6 +9,9 @@ internal sealed class OpenInNewPaneFromHomeAction : BaseOpenInNewPaneAction HomePageContext.IsAnyItemRightClicked && HomePageContext.RightClickedItem is not null; + public bool IsContextual + => true; + public override async Task ExecuteAsync() { if (await DriveHelpers.CheckEmptyDrive(HomePageContext.RightClickedItem!.Path)) diff --git a/src/Files.App/Actions/Navigation/OpenInNewPane/OpenInNewPaneFromSidebarAction.cs b/src/Files.App/Actions/Navigation/OpenInNewPane/OpenInNewPaneFromSidebarAction.cs index 456c30604892..159091c5d410 100644 --- a/src/Files.App/Actions/Navigation/OpenInNewPane/OpenInNewPaneFromSidebarAction.cs +++ b/src/Files.App/Actions/Navigation/OpenInNewPane/OpenInNewPaneFromSidebarAction.cs @@ -9,6 +9,9 @@ internal sealed class OpenInNewPaneFromSidebarAction : BaseOpenInNewPaneAction SidebarContext.IsItemRightClicked && SidebarContext.RightClickedItem is not null; + public bool IsContextual + => true; + public override async Task ExecuteAsync() { if (await DriveHelpers.CheckEmptyDrive(HomePageContext.RightClickedItem!.Path)) diff --git a/src/Files.App/Actions/Navigation/OpenInNewTab/OpenInNewTabFromHomeAction.cs b/src/Files.App/Actions/Navigation/OpenInNewTab/OpenInNewTabFromHomeAction.cs index 6d73de17079b..c197bf8ce8c7 100644 --- a/src/Files.App/Actions/Navigation/OpenInNewTab/OpenInNewTabFromHomeAction.cs +++ b/src/Files.App/Actions/Navigation/OpenInNewTab/OpenInNewTabFromHomeAction.cs @@ -9,6 +9,9 @@ internal sealed class OpenInNewTabFromHomeAction : BaseOpenInNewTabAction HomePageContext.IsAnyItemRightClicked && HomePageContext.RightClickedItem is not null; + public bool IsContextual + => true; + public override async Task ExecuteAsync() { if (await DriveHelpers.CheckEmptyDrive(HomePageContext.RightClickedItem!.Path)) diff --git a/src/Files.App/Actions/Navigation/OpenInNewTab/OpenInNewTabFromSidebarAction.cs b/src/Files.App/Actions/Navigation/OpenInNewTab/OpenInNewTabFromSidebarAction.cs index a0949f413e9b..72d127e25286 100644 --- a/src/Files.App/Actions/Navigation/OpenInNewTab/OpenInNewTabFromSidebarAction.cs +++ b/src/Files.App/Actions/Navigation/OpenInNewTab/OpenInNewTabFromSidebarAction.cs @@ -9,6 +9,9 @@ internal sealed class OpenInNewTabFromSidebarAction : BaseOpenInNewTabAction SidebarContext.IsItemRightClicked && SidebarContext.RightClickedItem is not null; + public bool IsContextual + => true; + public override async Task ExecuteAsync() { if (await DriveHelpers.CheckEmptyDrive(SidebarContext.RightClickedItem!.Path)) diff --git a/src/Files.App/Actions/Navigation/OpenInNewWindow/OpenInNewWindowFromHomeAction.cs b/src/Files.App/Actions/Navigation/OpenInNewWindow/OpenInNewWindowFromHomeAction.cs index f12b5eee65b7..97b3549669e3 100644 --- a/src/Files.App/Actions/Navigation/OpenInNewWindow/OpenInNewWindowFromHomeAction.cs +++ b/src/Files.App/Actions/Navigation/OpenInNewWindow/OpenInNewWindowFromHomeAction.cs @@ -8,6 +8,9 @@ internal sealed class OpenInNewWindowFromHomeAction : BaseOpenInNewWindowAction public override HotKey HotKey => HotKey.None; + public bool IsContextual + => true; + public override bool IsExecutable => HomePageContext.IsAnyItemRightClicked && HomePageContext.RightClickedItem is not null; diff --git a/src/Files.App/Actions/Navigation/OpenInNewWindow/OpenInNewWindowFromSidebarAction.cs b/src/Files.App/Actions/Navigation/OpenInNewWindow/OpenInNewWindowFromSidebarAction.cs index 941bd08741e8..962328d1fe7e 100644 --- a/src/Files.App/Actions/Navigation/OpenInNewWindow/OpenInNewWindowFromSidebarAction.cs +++ b/src/Files.App/Actions/Navigation/OpenInNewWindow/OpenInNewWindowFromSidebarAction.cs @@ -8,6 +8,9 @@ internal sealed class OpenInNewWindowFromSidebarAction : BaseOpenInNewWindowActi public override HotKey HotKey => HotKey.None; + public bool IsContextual + => true; + public override bool IsExecutable => SidebarContext.IsItemRightClicked && SidebarContext.RightClickedItem is not null; diff --git a/src/Files.App/Data/Commands/ActionCommand.cs b/src/Files.App/Data/Commands/ActionCommand.cs index 8368ee4e3648..d25d6846a67a 100644 --- a/src/Files.App/Data/Commands/ActionCommand.cs +++ b/src/Files.App/Data/Commands/ActionCommand.cs @@ -92,6 +92,9 @@ public bool IsOn public bool IsExecutable => Action.IsExecutable; + public bool IsContextual + => Action.IsContextual; + public ActionCommand(CommandManager manager, CommandCodes code, IAction action) { Code = code; diff --git a/src/Files.App/Data/Commands/IRichCommand.cs b/src/Files.App/Data/Commands/IRichCommand.cs index ec013f08979c..3eb5592e79a8 100644 --- a/src/Files.App/Data/Commands/IRichCommand.cs +++ b/src/Files.App/Data/Commands/IRichCommand.cs @@ -31,6 +31,7 @@ public interface IRichCommand : ICommand, INotifyPropertyChanging, INotifyProper bool IsToggle { get; } bool IsOn { get; set; } bool IsExecutable { get; } + bool IsContextual { get; } Task ExecuteAsync(); void ExecuteTapped(object sender, TappedRoutedEventArgs e); diff --git a/src/Files.App/Data/Commands/ModifiableCommand.cs b/src/Files.App/Data/Commands/ModifiableCommand.cs index b31f85cecc74..343c4afd57a1 100644 --- a/src/Files.App/Data/Commands/ModifiableCommand.cs +++ b/src/Files.App/Data/Commands/ModifiableCommand.cs @@ -51,6 +51,9 @@ public bool IsOn public bool IsExecutable => BaseCommand.IsExecutable; + public bool IsContextual + => BaseCommand.IsContextual; + public ModifiableCommand(IRichCommand baseCommand, Dictionary modifiedCommands) { BaseCommand = baseCommand; diff --git a/src/Files.App/Data/Commands/NoneCommand.cs b/src/Files.App/Data/Commands/NoneCommand.cs index 5df179233a6e..de9492ad6d96 100644 --- a/src/Files.App/Data/Commands/NoneCommand.cs +++ b/src/Files.App/Data/Commands/NoneCommand.cs @@ -44,6 +44,7 @@ public HotKeyCollection DefaultHotKeys public bool IsToggle => false; public bool IsOn { get => false; set { } } public bool IsExecutable => false; + public bool IsContextual => false; public bool CanExecute(object? parameter) => false; public void Execute(object? parameter) { } diff --git a/src/Files.App/ViewModels/UserControls/AddressToolbarViewModel.cs b/src/Files.App/ViewModels/UserControls/AddressToolbarViewModel.cs index 65b1207b44d2..483fe20cfebf 100644 --- a/src/Files.App/ViewModels/UserControls/AddressToolbarViewModel.cs +++ b/src/Files.App/ViewModels/UserControls/AddressToolbarViewModel.cs @@ -842,6 +842,7 @@ public async Task SetAddressBarSuggestionsAsync(AutoSuggestBox sender, IShellPag var searchText = sender.Text.Substring(1).Trim(); suggestions = Commands.Where(command => command.IsExecutable && + command.IsContextual is false && (command.Description.Contains(searchText, StringComparison.OrdinalIgnoreCase) || command.Code.ToString().Contains(searchText, StringComparison.OrdinalIgnoreCase))) .Select(command => new NavigationBarSuggestionItem() diff --git a/src/Files.App/ViewModels/UserControls/Widgets/DrivesWidgetViewModel.cs b/src/Files.App/ViewModels/UserControls/Widgets/DrivesWidgetViewModel.cs index 2c4127b8205c..a27ba6e99997 100644 --- a/src/Files.App/ViewModels/UserControls/Widgets/DrivesWidgetViewModel.cs +++ b/src/Files.App/ViewModels/UserControls/Widgets/DrivesWidgetViewModel.cs @@ -1,7 +1,6 @@ // Copyright (c) 2024 Files Community // Licensed under the MIT License. See the LICENSE. -using LibGit2Sharp; using Microsoft.UI.Input; using Microsoft.UI.Xaml.Controls; using System.Collections.Specialized; From c9e9d5a467f2f795a17018e8385418c790fa439c Mon Sep 17 00:00:00 2001 From: 0x5bfa <62196528+0x5bfa@users.noreply.github.com> Date: Thu, 9 May 2024 08:46:58 +0900 Subject: [PATCH 07/17] Renamed to IsAccessibleGlobally --- src/Files.App/Actions/IAction.cs | 6 +++--- .../Navigation/OpenInNewPane/BaseOpenInNewPaneAction.cs | 3 +++ .../Navigation/OpenInNewPane/OpenInNewPaneFromHomeAction.cs | 4 ++-- .../OpenInNewPane/OpenInNewPaneFromSidebarAction.cs | 4 ++-- .../Navigation/OpenInNewTab/BaseOpenInNewTabAction.cs | 3 +++ .../Navigation/OpenInNewTab/OpenInNewTabFromHomeAction.cs | 4 ++-- .../OpenInNewTab/OpenInNewTabFromSidebarAction.cs | 4 ++-- .../Navigation/OpenInNewWindow/BaseOpenInNewWindowAction.cs | 3 +++ .../OpenInNewWindow/OpenInNewWindowFromHomeAction.cs | 6 +++--- .../OpenInNewWindow/OpenInNewWindowFromSidebarAction.cs | 6 +++--- src/Files.App/Data/Commands/ActionCommand.cs | 4 ++-- src/Files.App/Data/Commands/IRichCommand.cs | 2 +- src/Files.App/Data/Commands/ModifiableCommand.cs | 4 ++-- src/Files.App/Data/Commands/NoneCommand.cs | 2 +- .../ViewModels/UserControls/AddressToolbarViewModel.cs | 2 +- 15 files changed, 33 insertions(+), 24 deletions(-) diff --git a/src/Files.App/Actions/IAction.cs b/src/Files.App/Actions/IAction.cs index 280fba663380..9cf796507b1a 100644 --- a/src/Files.App/Actions/IAction.cs +++ b/src/Files.App/Actions/IAction.cs @@ -53,10 +53,10 @@ bool IsExecutable => true; /// - /// Returns whether the action is accessible in the specific context. + /// Returns whether the action is accessible in any context. /// - bool IsContextual - => false; + bool IsAccessibleGlobally + => true; /// /// Executes the action asynchronously. diff --git a/src/Files.App/Actions/Navigation/OpenInNewPane/BaseOpenInNewPaneAction.cs b/src/Files.App/Actions/Navigation/OpenInNewPane/BaseOpenInNewPaneAction.cs index 980d21c006bd..2aa5e58b5e64 100644 --- a/src/Files.App/Actions/Navigation/OpenInNewPane/BaseOpenInNewPaneAction.cs +++ b/src/Files.App/Actions/Navigation/OpenInNewPane/BaseOpenInNewPaneAction.cs @@ -21,6 +21,9 @@ public string Description ContentPageContext.SelectedItem.IsFolder && UserSettingsService.GeneralSettingsService.ShowOpenInNewPane; + public virtual bool IsAccessibleGlobally + => true; + public BaseOpenInNewPaneAction() { ContentPageContext.PropertyChanged += Context_PropertyChanged; diff --git a/src/Files.App/Actions/Navigation/OpenInNewPane/OpenInNewPaneFromHomeAction.cs b/src/Files.App/Actions/Navigation/OpenInNewPane/OpenInNewPaneFromHomeAction.cs index b94a67b4b584..50fbfa12b68b 100644 --- a/src/Files.App/Actions/Navigation/OpenInNewPane/OpenInNewPaneFromHomeAction.cs +++ b/src/Files.App/Actions/Navigation/OpenInNewPane/OpenInNewPaneFromHomeAction.cs @@ -9,8 +9,8 @@ internal sealed class OpenInNewPaneFromHomeAction : BaseOpenInNewPaneAction HomePageContext.IsAnyItemRightClicked && HomePageContext.RightClickedItem is not null; - public bool IsContextual - => true; + public override bool IsAccessibleGlobally + => false; public override async Task ExecuteAsync() { diff --git a/src/Files.App/Actions/Navigation/OpenInNewPane/OpenInNewPaneFromSidebarAction.cs b/src/Files.App/Actions/Navigation/OpenInNewPane/OpenInNewPaneFromSidebarAction.cs index 159091c5d410..23a951f9199a 100644 --- a/src/Files.App/Actions/Navigation/OpenInNewPane/OpenInNewPaneFromSidebarAction.cs +++ b/src/Files.App/Actions/Navigation/OpenInNewPane/OpenInNewPaneFromSidebarAction.cs @@ -9,8 +9,8 @@ internal sealed class OpenInNewPaneFromSidebarAction : BaseOpenInNewPaneAction SidebarContext.IsItemRightClicked && SidebarContext.RightClickedItem is not null; - public bool IsContextual - => true; + public override bool IsAccessibleGlobally + => false; public override async Task ExecuteAsync() { diff --git a/src/Files.App/Actions/Navigation/OpenInNewTab/BaseOpenInNewTabAction.cs b/src/Files.App/Actions/Navigation/OpenInNewTab/BaseOpenInNewTabAction.cs index f5d364bf4b6b..31690bc73ffb 100644 --- a/src/Files.App/Actions/Navigation/OpenInNewTab/BaseOpenInNewTabAction.cs +++ b/src/Files.App/Actions/Navigation/OpenInNewTab/BaseOpenInNewTabAction.cs @@ -19,6 +19,9 @@ public string Description public RichGlyph Glyph => new(opacityStyle: "ColorIconOpenInNewTab"); + public virtual bool IsAccessibleGlobally + => true; + public virtual bool IsExecutable => ContentPageContext.ShellPage is not null && ContentPageContext.ShellPage.SlimContentPage is not null && diff --git a/src/Files.App/Actions/Navigation/OpenInNewTab/OpenInNewTabFromHomeAction.cs b/src/Files.App/Actions/Navigation/OpenInNewTab/OpenInNewTabFromHomeAction.cs index c197bf8ce8c7..104ef214e3b7 100644 --- a/src/Files.App/Actions/Navigation/OpenInNewTab/OpenInNewTabFromHomeAction.cs +++ b/src/Files.App/Actions/Navigation/OpenInNewTab/OpenInNewTabFromHomeAction.cs @@ -9,8 +9,8 @@ internal sealed class OpenInNewTabFromHomeAction : BaseOpenInNewTabAction HomePageContext.IsAnyItemRightClicked && HomePageContext.RightClickedItem is not null; - public bool IsContextual - => true; + public override bool IsAccessibleGlobally + => false; public override async Task ExecuteAsync() { diff --git a/src/Files.App/Actions/Navigation/OpenInNewTab/OpenInNewTabFromSidebarAction.cs b/src/Files.App/Actions/Navigation/OpenInNewTab/OpenInNewTabFromSidebarAction.cs index 72d127e25286..2380e34dab94 100644 --- a/src/Files.App/Actions/Navigation/OpenInNewTab/OpenInNewTabFromSidebarAction.cs +++ b/src/Files.App/Actions/Navigation/OpenInNewTab/OpenInNewTabFromSidebarAction.cs @@ -9,8 +9,8 @@ internal sealed class OpenInNewTabFromSidebarAction : BaseOpenInNewTabAction SidebarContext.IsItemRightClicked && SidebarContext.RightClickedItem is not null; - public bool IsContextual - => true; + public override bool IsAccessibleGlobally + => false; public override async Task ExecuteAsync() { diff --git a/src/Files.App/Actions/Navigation/OpenInNewWindow/BaseOpenInNewWindowAction.cs b/src/Files.App/Actions/Navigation/OpenInNewWindow/BaseOpenInNewWindowAction.cs index 9454c0214c22..4e366bb84cde 100644 --- a/src/Files.App/Actions/Navigation/OpenInNewWindow/BaseOpenInNewWindowAction.cs +++ b/src/Files.App/Actions/Navigation/OpenInNewWindow/BaseOpenInNewWindowAction.cs @@ -24,6 +24,9 @@ public virtual HotKey HotKey public RichGlyph Glyph => new(opacityStyle: "ColorIconOpenInNewWindow"); + public virtual bool IsAccessibleGlobally + => true; + public virtual bool IsExecutable => ContentPageContext.ShellPage is not null && ContentPageContext.ShellPage.SlimContentPage is not null && diff --git a/src/Files.App/Actions/Navigation/OpenInNewWindow/OpenInNewWindowFromHomeAction.cs b/src/Files.App/Actions/Navigation/OpenInNewWindow/OpenInNewWindowFromHomeAction.cs index 97b3549669e3..abeb2817f1db 100644 --- a/src/Files.App/Actions/Navigation/OpenInNewWindow/OpenInNewWindowFromHomeAction.cs +++ b/src/Files.App/Actions/Navigation/OpenInNewWindow/OpenInNewWindowFromHomeAction.cs @@ -8,13 +8,13 @@ internal sealed class OpenInNewWindowFromHomeAction : BaseOpenInNewWindowAction public override HotKey HotKey => HotKey.None; - public bool IsContextual - => true; - public override bool IsExecutable => HomePageContext.IsAnyItemRightClicked && HomePageContext.RightClickedItem is not null; + public override bool IsAccessibleGlobally + => false; + public override Task ExecuteAsync() { return NavigationHelpers.OpenPathInNewWindowAsync(HomePageContext.RightClickedItem!.Path ?? string.Empty); diff --git a/src/Files.App/Actions/Navigation/OpenInNewWindow/OpenInNewWindowFromSidebarAction.cs b/src/Files.App/Actions/Navigation/OpenInNewWindow/OpenInNewWindowFromSidebarAction.cs index 962328d1fe7e..edf42a8c9faa 100644 --- a/src/Files.App/Actions/Navigation/OpenInNewWindow/OpenInNewWindowFromSidebarAction.cs +++ b/src/Files.App/Actions/Navigation/OpenInNewWindow/OpenInNewWindowFromSidebarAction.cs @@ -8,13 +8,13 @@ internal sealed class OpenInNewWindowFromSidebarAction : BaseOpenInNewWindowActi public override HotKey HotKey => HotKey.None; - public bool IsContextual - => true; - public override bool IsExecutable => SidebarContext.IsItemRightClicked && SidebarContext.RightClickedItem is not null; + public override bool IsAccessibleGlobally + => false; + public override async Task ExecuteAsync() { await NavigationHelpers.OpenPathInNewWindowAsync(SidebarContext.RightClickedItem!.Path ?? string.Empty); diff --git a/src/Files.App/Data/Commands/ActionCommand.cs b/src/Files.App/Data/Commands/ActionCommand.cs index d25d6846a67a..d551a2f08519 100644 --- a/src/Files.App/Data/Commands/ActionCommand.cs +++ b/src/Files.App/Data/Commands/ActionCommand.cs @@ -92,8 +92,8 @@ public bool IsOn public bool IsExecutable => Action.IsExecutable; - public bool IsContextual - => Action.IsContextual; + public bool IsAccessibleGlobally + => Action.IsAccessibleGlobally; public ActionCommand(CommandManager manager, CommandCodes code, IAction action) { diff --git a/src/Files.App/Data/Commands/IRichCommand.cs b/src/Files.App/Data/Commands/IRichCommand.cs index 3eb5592e79a8..30bf3b8a5e10 100644 --- a/src/Files.App/Data/Commands/IRichCommand.cs +++ b/src/Files.App/Data/Commands/IRichCommand.cs @@ -31,7 +31,7 @@ public interface IRichCommand : ICommand, INotifyPropertyChanging, INotifyProper bool IsToggle { get; } bool IsOn { get; set; } bool IsExecutable { get; } - bool IsContextual { get; } + bool IsAccessibleGlobally { get; } Task ExecuteAsync(); void ExecuteTapped(object sender, TappedRoutedEventArgs e); diff --git a/src/Files.App/Data/Commands/ModifiableCommand.cs b/src/Files.App/Data/Commands/ModifiableCommand.cs index 343c4afd57a1..ee22c46f4f0e 100644 --- a/src/Files.App/Data/Commands/ModifiableCommand.cs +++ b/src/Files.App/Data/Commands/ModifiableCommand.cs @@ -51,8 +51,8 @@ public bool IsOn public bool IsExecutable => BaseCommand.IsExecutable; - public bool IsContextual - => BaseCommand.IsContextual; + public bool IsAccessibleGlobally + => BaseCommand.IsAccessibleGlobally; public ModifiableCommand(IRichCommand baseCommand, Dictionary modifiedCommands) { diff --git a/src/Files.App/Data/Commands/NoneCommand.cs b/src/Files.App/Data/Commands/NoneCommand.cs index de9492ad6d96..9418c8d1d2cf 100644 --- a/src/Files.App/Data/Commands/NoneCommand.cs +++ b/src/Files.App/Data/Commands/NoneCommand.cs @@ -44,7 +44,7 @@ public HotKeyCollection DefaultHotKeys public bool IsToggle => false; public bool IsOn { get => false; set { } } public bool IsExecutable => false; - public bool IsContextual => false; + public bool IsAccessibleGlobally => false; public bool CanExecute(object? parameter) => false; public void Execute(object? parameter) { } diff --git a/src/Files.App/ViewModels/UserControls/AddressToolbarViewModel.cs b/src/Files.App/ViewModels/UserControls/AddressToolbarViewModel.cs index 483fe20cfebf..8a8f9c8bd6e1 100644 --- a/src/Files.App/ViewModels/UserControls/AddressToolbarViewModel.cs +++ b/src/Files.App/ViewModels/UserControls/AddressToolbarViewModel.cs @@ -842,7 +842,7 @@ public async Task SetAddressBarSuggestionsAsync(AutoSuggestBox sender, IShellPag var searchText = sender.Text.Substring(1).Trim(); suggestions = Commands.Where(command => command.IsExecutable && - command.IsContextual is false && + command.IsAccessibleGlobally && (command.Description.Contains(searchText, StringComparison.OrdinalIgnoreCase) || command.Code.ToString().Contains(searchText, StringComparison.OrdinalIgnoreCase))) .Select(command => new NavigationBarSuggestionItem() From f896d5c941f62ab573bbba97180dda7d6e18b5cd Mon Sep 17 00:00:00 2001 From: 0x5bfa <62196528+0x5bfa@users.noreply.github.com> Date: Thu, 9 May 2024 08:53:51 +0900 Subject: [PATCH 08/17] Added comments --- src/Files.App/Data/Commands/IRichCommand.cs | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/Files.App/Data/Commands/IRichCommand.cs b/src/Files.App/Data/Commands/IRichCommand.cs index 6ff77ef6b0d3..9a563fb35d75 100644 --- a/src/Files.App/Data/Commands/IRichCommand.cs +++ b/src/Files.App/Data/Commands/IRichCommand.cs @@ -92,6 +92,10 @@ public interface IRichCommand : ICommand, INotifyPropertyChanging, INotifyProper /// Gets the value that indicates whether the command is executable. /// bool IsExecutable { get; } + + /// + /// Returns whether the action is accessible in any context. + /// bool IsAccessibleGlobally { get; } /// From 6d6d78128914a2f1017cad1fb507335577ce7c08 Mon Sep 17 00:00:00 2001 From: 0x5bfa <62196528+0x5bfa@users.noreply.github.com> Date: Thu, 9 May 2024 08:54:23 +0900 Subject: [PATCH 09/17] And more --- src/Files.App/Data/Commands/ActionCommand.cs | 1 + src/Files.App/Data/Commands/ModifiableCommand.cs | 1 + src/Files.App/Data/Commands/NoneCommand.cs | 1 + 3 files changed, 3 insertions(+) diff --git a/src/Files.App/Data/Commands/ActionCommand.cs b/src/Files.App/Data/Commands/ActionCommand.cs index c92ca093f805..0565222a585f 100644 --- a/src/Files.App/Data/Commands/ActionCommand.cs +++ b/src/Files.App/Data/Commands/ActionCommand.cs @@ -108,6 +108,7 @@ public bool IsOn public bool IsExecutable => Action.IsExecutable; + /// public bool IsAccessibleGlobally => Action.IsAccessibleGlobally; diff --git a/src/Files.App/Data/Commands/ModifiableCommand.cs b/src/Files.App/Data/Commands/ModifiableCommand.cs index 3ad2cdd369d3..5564d6d9a8eb 100644 --- a/src/Files.App/Data/Commands/ModifiableCommand.cs +++ b/src/Files.App/Data/Commands/ModifiableCommand.cs @@ -75,6 +75,7 @@ public bool IsOn public bool IsExecutable => BaseCommand.IsExecutable; + /// public bool IsAccessibleGlobally => BaseCommand.IsAccessibleGlobally; diff --git a/src/Files.App/Data/Commands/NoneCommand.cs b/src/Files.App/Data/Commands/NoneCommand.cs index b67081745056..18aba72f8dea 100644 --- a/src/Files.App/Data/Commands/NoneCommand.cs +++ b/src/Files.App/Data/Commands/NoneCommand.cs @@ -87,6 +87,7 @@ public bool IsOn public bool IsExecutable => false; + /// public bool IsAccessibleGlobally => false; From b7eda2316dcfe0100a870500941bfbb5955c12aa Mon Sep 17 00:00:00 2001 From: 0x5bfa <62196528+0x5bfa@users.noreply.github.com> Date: Thu, 9 May 2024 09:08:19 +0900 Subject: [PATCH 10/17] Added parameter to fix --- .../Actions/Navigation/OpenInNewPane/BaseOpenInNewPaneAction.cs | 2 +- .../Navigation/OpenInNewPane/OpenInNewPaneFromHomeAction.cs | 2 +- .../Navigation/OpenInNewPane/OpenInNewPaneFromSidebarAction.cs | 2 +- .../Actions/Navigation/OpenInNewTab/BaseOpenInNewTabAction.cs | 2 +- .../Navigation/OpenInNewTab/OpenInNewTabFromHomeAction.cs | 2 +- .../Navigation/OpenInNewTab/OpenInNewTabFromSidebarAction.cs | 2 +- .../Navigation/OpenInNewWindow/BaseOpenInNewWindowAction.cs | 2 +- .../Navigation/OpenInNewWindow/OpenInNewWindowFromHomeAction.cs | 2 +- .../OpenInNewWindow/OpenInNewWindowFromSidebarAction.cs | 2 +- 9 files changed, 9 insertions(+), 9 deletions(-) diff --git a/src/Files.App/Actions/Navigation/OpenInNewPane/BaseOpenInNewPaneAction.cs b/src/Files.App/Actions/Navigation/OpenInNewPane/BaseOpenInNewPaneAction.cs index 2aa5e58b5e64..e6f73a419648 100644 --- a/src/Files.App/Actions/Navigation/OpenInNewPane/BaseOpenInNewPaneAction.cs +++ b/src/Files.App/Actions/Navigation/OpenInNewPane/BaseOpenInNewPaneAction.cs @@ -29,7 +29,7 @@ public BaseOpenInNewPaneAction() ContentPageContext.PropertyChanged += Context_PropertyChanged; } - public virtual Task ExecuteAsync() + public virtual Task ExecuteAsync(object? parameter = null) { NavigationHelpers.OpenInSecondaryPane( ContentPageContext.ShellPage, diff --git a/src/Files.App/Actions/Navigation/OpenInNewPane/OpenInNewPaneFromHomeAction.cs b/src/Files.App/Actions/Navigation/OpenInNewPane/OpenInNewPaneFromHomeAction.cs index 50fbfa12b68b..1d135d1fb7c6 100644 --- a/src/Files.App/Actions/Navigation/OpenInNewPane/OpenInNewPaneFromHomeAction.cs +++ b/src/Files.App/Actions/Navigation/OpenInNewPane/OpenInNewPaneFromHomeAction.cs @@ -12,7 +12,7 @@ internal sealed class OpenInNewPaneFromHomeAction : BaseOpenInNewPaneAction public override bool IsAccessibleGlobally => false; - public override async Task ExecuteAsync() + public override async Task ExecuteAsync(object? parameter = null) { if (await DriveHelpers.CheckEmptyDrive(HomePageContext.RightClickedItem!.Path)) return; diff --git a/src/Files.App/Actions/Navigation/OpenInNewPane/OpenInNewPaneFromSidebarAction.cs b/src/Files.App/Actions/Navigation/OpenInNewPane/OpenInNewPaneFromSidebarAction.cs index 23a951f9199a..20d7eb922ff5 100644 --- a/src/Files.App/Actions/Navigation/OpenInNewPane/OpenInNewPaneFromSidebarAction.cs +++ b/src/Files.App/Actions/Navigation/OpenInNewPane/OpenInNewPaneFromSidebarAction.cs @@ -12,7 +12,7 @@ internal sealed class OpenInNewPaneFromSidebarAction : BaseOpenInNewPaneAction public override bool IsAccessibleGlobally => false; - public override async Task ExecuteAsync() + public override async Task ExecuteAsync(object? parameter = null) { if (await DriveHelpers.CheckEmptyDrive(HomePageContext.RightClickedItem!.Path)) return; diff --git a/src/Files.App/Actions/Navigation/OpenInNewTab/BaseOpenInNewTabAction.cs b/src/Files.App/Actions/Navigation/OpenInNewTab/BaseOpenInNewTabAction.cs index 31690bc73ffb..8dbf0ff5a47c 100644 --- a/src/Files.App/Actions/Navigation/OpenInNewTab/BaseOpenInNewTabAction.cs +++ b/src/Files.App/Actions/Navigation/OpenInNewTab/BaseOpenInNewTabAction.cs @@ -35,7 +35,7 @@ public BaseOpenInNewTabAction() ContentPageContext.PropertyChanged += Context_PropertyChanged; } - public virtual async Task ExecuteAsync() + public virtual async Task ExecuteAsync(object? parameter = null) { foreach (ListedItem listedItem in ContentPageContext.SelectedItems) { diff --git a/src/Files.App/Actions/Navigation/OpenInNewTab/OpenInNewTabFromHomeAction.cs b/src/Files.App/Actions/Navigation/OpenInNewTab/OpenInNewTabFromHomeAction.cs index 104ef214e3b7..985351927214 100644 --- a/src/Files.App/Actions/Navigation/OpenInNewTab/OpenInNewTabFromHomeAction.cs +++ b/src/Files.App/Actions/Navigation/OpenInNewTab/OpenInNewTabFromHomeAction.cs @@ -12,7 +12,7 @@ internal sealed class OpenInNewTabFromHomeAction : BaseOpenInNewTabAction public override bool IsAccessibleGlobally => false; - public override async Task ExecuteAsync() + public override async Task ExecuteAsync(object? parameter = null) { if (await DriveHelpers.CheckEmptyDrive(HomePageContext.RightClickedItem!.Path)) return; diff --git a/src/Files.App/Actions/Navigation/OpenInNewTab/OpenInNewTabFromSidebarAction.cs b/src/Files.App/Actions/Navigation/OpenInNewTab/OpenInNewTabFromSidebarAction.cs index 2380e34dab94..4cc935164f74 100644 --- a/src/Files.App/Actions/Navigation/OpenInNewTab/OpenInNewTabFromSidebarAction.cs +++ b/src/Files.App/Actions/Navigation/OpenInNewTab/OpenInNewTabFromSidebarAction.cs @@ -12,7 +12,7 @@ internal sealed class OpenInNewTabFromSidebarAction : BaseOpenInNewTabAction public override bool IsAccessibleGlobally => false; - public override async Task ExecuteAsync() + public override async Task ExecuteAsync(object? parameter = null) { if (await DriveHelpers.CheckEmptyDrive(SidebarContext.RightClickedItem!.Path)) return; diff --git a/src/Files.App/Actions/Navigation/OpenInNewWindow/BaseOpenInNewWindowAction.cs b/src/Files.App/Actions/Navigation/OpenInNewWindow/BaseOpenInNewWindowAction.cs index 4e366bb84cde..428447962740 100644 --- a/src/Files.App/Actions/Navigation/OpenInNewWindow/BaseOpenInNewWindowAction.cs +++ b/src/Files.App/Actions/Navigation/OpenInNewWindow/BaseOpenInNewWindowAction.cs @@ -40,7 +40,7 @@ public BaseOpenInNewWindowAction() ContentPageContext.PropertyChanged += Context_PropertyChanged; } - public virtual async Task ExecuteAsync() + public virtual async Task ExecuteAsync(object? parameter = null) { if (ContentPageContext.ShellPage?.SlimContentPage?.SelectedItems is null) return; diff --git a/src/Files.App/Actions/Navigation/OpenInNewWindow/OpenInNewWindowFromHomeAction.cs b/src/Files.App/Actions/Navigation/OpenInNewWindow/OpenInNewWindowFromHomeAction.cs index abeb2817f1db..b2f4b9808775 100644 --- a/src/Files.App/Actions/Navigation/OpenInNewWindow/OpenInNewWindowFromHomeAction.cs +++ b/src/Files.App/Actions/Navigation/OpenInNewWindow/OpenInNewWindowFromHomeAction.cs @@ -15,7 +15,7 @@ public override HotKey HotKey public override bool IsAccessibleGlobally => false; - public override Task ExecuteAsync() + public override Task ExecuteAsync(object? parameter = null) { return NavigationHelpers.OpenPathInNewWindowAsync(HomePageContext.RightClickedItem!.Path ?? string.Empty); } diff --git a/src/Files.App/Actions/Navigation/OpenInNewWindow/OpenInNewWindowFromSidebarAction.cs b/src/Files.App/Actions/Navigation/OpenInNewWindow/OpenInNewWindowFromSidebarAction.cs index edf42a8c9faa..c12880b595ce 100644 --- a/src/Files.App/Actions/Navigation/OpenInNewWindow/OpenInNewWindowFromSidebarAction.cs +++ b/src/Files.App/Actions/Navigation/OpenInNewWindow/OpenInNewWindowFromSidebarAction.cs @@ -15,7 +15,7 @@ public override HotKey HotKey public override bool IsAccessibleGlobally => false; - public override async Task ExecuteAsync() + public override async Task ExecuteAsync(object? parameter = null) { await NavigationHelpers.OpenPathInNewWindowAsync(SidebarContext.RightClickedItem!.Path ?? string.Empty); } From 858cab82730e37d42c95dfa1dc4448e9a57e1048 Mon Sep 17 00:00:00 2001 From: 0x5bfa <62196528+0x5bfa@users.noreply.github.com> Date: Wed, 29 May 2024 00:15:09 +0900 Subject: [PATCH 11/17] Fix --- .../Navigation/OpenInNewPane/OpenInNewPaneFromHomeAction.cs | 5 ++++- .../Navigation/OpenInNewTab/OpenInNewTabFromHomeAction.cs | 5 ++++- .../OpenInNewWindow/OpenInNewWindowFromHomeAction.cs | 5 ++++- 3 files changed, 12 insertions(+), 3 deletions(-) diff --git a/src/Files.App/Actions/Navigation/OpenInNewPane/OpenInNewPaneFromHomeAction.cs b/src/Files.App/Actions/Navigation/OpenInNewPane/OpenInNewPaneFromHomeAction.cs index 1d135d1fb7c6..1006784697ea 100644 --- a/src/Files.App/Actions/Navigation/OpenInNewPane/OpenInNewPaneFromHomeAction.cs +++ b/src/Files.App/Actions/Navigation/OpenInNewPane/OpenInNewPaneFromHomeAction.cs @@ -7,7 +7,10 @@ internal sealed class OpenInNewPaneFromHomeAction : BaseOpenInNewPaneAction { public override bool IsExecutable => HomePageContext.IsAnyItemRightClicked && - HomePageContext.RightClickedItem is not null; + HomePageContext.RightClickedItem is not null && + HomePageContext.RightClickedItem is WidgetFileTagCardItem fileTagItem + ? fileTagItem.IsFolder + : true; public override bool IsAccessibleGlobally => false; diff --git a/src/Files.App/Actions/Navigation/OpenInNewTab/OpenInNewTabFromHomeAction.cs b/src/Files.App/Actions/Navigation/OpenInNewTab/OpenInNewTabFromHomeAction.cs index 985351927214..076c14bd11bd 100644 --- a/src/Files.App/Actions/Navigation/OpenInNewTab/OpenInNewTabFromHomeAction.cs +++ b/src/Files.App/Actions/Navigation/OpenInNewTab/OpenInNewTabFromHomeAction.cs @@ -7,7 +7,10 @@ internal sealed class OpenInNewTabFromHomeAction : BaseOpenInNewTabAction { public override bool IsExecutable => HomePageContext.IsAnyItemRightClicked && - HomePageContext.RightClickedItem is not null; + HomePageContext.RightClickedItem is not null && + HomePageContext.RightClickedItem is WidgetFileTagCardItem fileTagItem + ? fileTagItem.IsFolder + : true; public override bool IsAccessibleGlobally => false; diff --git a/src/Files.App/Actions/Navigation/OpenInNewWindow/OpenInNewWindowFromHomeAction.cs b/src/Files.App/Actions/Navigation/OpenInNewWindow/OpenInNewWindowFromHomeAction.cs index b2f4b9808775..522a3a9efb23 100644 --- a/src/Files.App/Actions/Navigation/OpenInNewWindow/OpenInNewWindowFromHomeAction.cs +++ b/src/Files.App/Actions/Navigation/OpenInNewWindow/OpenInNewWindowFromHomeAction.cs @@ -10,7 +10,10 @@ public override HotKey HotKey public override bool IsExecutable => HomePageContext.IsAnyItemRightClicked && - HomePageContext.RightClickedItem is not null; + HomePageContext.RightClickedItem is not null && + HomePageContext.RightClickedItem is WidgetFileTagCardItem fileTagItem + ? fileTagItem.IsFolder + : true; public override bool IsAccessibleGlobally => false; From 7f75d8fea3f05bb071b33db9ea77bd91d471e2ec Mon Sep 17 00:00:00 2001 From: 0x5bfa <62196528+0x5bfa@users.noreply.github.com> Date: Sun, 2 Jun 2024 04:06:40 +0900 Subject: [PATCH 12/17] Req --- .../OpenInNewPane/OpenInNewPaneFromSidebarAction.cs | 4 ++-- src/Files.App/ViewModels/Settings/ActionsViewModel.cs | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/src/Files.App/Actions/Navigation/OpenInNewPane/OpenInNewPaneFromSidebarAction.cs b/src/Files.App/Actions/Navigation/OpenInNewPane/OpenInNewPaneFromSidebarAction.cs index 20d7eb922ff5..a1d45f290a8b 100644 --- a/src/Files.App/Actions/Navigation/OpenInNewPane/OpenInNewPaneFromSidebarAction.cs +++ b/src/Files.App/Actions/Navigation/OpenInNewPane/OpenInNewPaneFromSidebarAction.cs @@ -14,10 +14,10 @@ public override bool IsAccessibleGlobally public override async Task ExecuteAsync(object? parameter = null) { - if (await DriveHelpers.CheckEmptyDrive(HomePageContext.RightClickedItem!.Path)) + if (await DriveHelpers.CheckEmptyDrive(SidebarContext.RightClickedItem!.Path)) return; - ContentPageContext.ShellPage!.PaneHolder?.OpenPathInNewPane(HomePageContext.RightClickedItem!.Path ?? string.Empty); + ContentPageContext.ShellPage!.PaneHolder?.OpenPathInNewPane(SidebarContext.RightClickedItem!.Path ?? string.Empty); } protected override void Context_PropertyChanged(object? sender, PropertyChangedEventArgs e) diff --git a/src/Files.App/ViewModels/Settings/ActionsViewModel.cs b/src/Files.App/ViewModels/Settings/ActionsViewModel.cs index dc0557c21445..9bbb5b3e6807 100644 --- a/src/Files.App/ViewModels/Settings/ActionsViewModel.cs +++ b/src/Files.App/ViewModels/Settings/ActionsViewModel.cs @@ -111,7 +111,7 @@ private async Task ExecuteLoadAllActionsCommand() { var defaultKeyBindings = command.DefaultHotKeys; - if (command is NoneCommand) + if (command is NoneCommand || (command is IRichCommand richCommand && !richCommand.IsAccessibleGlobally)) continue; AllActionItems.Add(new() From 32ed127f35a5b1f02efc434f8ea2bbcc24169738 Mon Sep 17 00:00:00 2001 From: 0x5bfa <62196528+0x5bfa@users.noreply.github.com> Date: Mon, 3 Jun 2024 07:31:31 +0900 Subject: [PATCH 13/17] Added null-check --- .../Navigation/OpenInNewPane/OpenInNewPaneFromHomeAction.cs | 3 +++ .../Navigation/OpenInNewPane/OpenInNewPaneFromSidebarAction.cs | 3 +++ .../Navigation/OpenInNewTab/OpenInNewTabFromHomeAction.cs | 3 +++ .../Navigation/OpenInNewTab/OpenInNewTabFromSidebarAction.cs | 3 +++ 4 files changed, 12 insertions(+) diff --git a/src/Files.App/Actions/Navigation/OpenInNewPane/OpenInNewPaneFromHomeAction.cs b/src/Files.App/Actions/Navigation/OpenInNewPane/OpenInNewPaneFromHomeAction.cs index 1006784697ea..f4d8c4b9a213 100644 --- a/src/Files.App/Actions/Navigation/OpenInNewPane/OpenInNewPaneFromHomeAction.cs +++ b/src/Files.App/Actions/Navigation/OpenInNewPane/OpenInNewPaneFromHomeAction.cs @@ -17,6 +17,9 @@ public override bool IsAccessibleGlobally public override async Task ExecuteAsync(object? parameter = null) { + if (HomePageContext.RightClickedItem is null) + return; + if (await DriveHelpers.CheckEmptyDrive(HomePageContext.RightClickedItem!.Path)) return; diff --git a/src/Files.App/Actions/Navigation/OpenInNewPane/OpenInNewPaneFromSidebarAction.cs b/src/Files.App/Actions/Navigation/OpenInNewPane/OpenInNewPaneFromSidebarAction.cs index a1d45f290a8b..027ebcfa5752 100644 --- a/src/Files.App/Actions/Navigation/OpenInNewPane/OpenInNewPaneFromSidebarAction.cs +++ b/src/Files.App/Actions/Navigation/OpenInNewPane/OpenInNewPaneFromSidebarAction.cs @@ -14,6 +14,9 @@ public override bool IsAccessibleGlobally public override async Task ExecuteAsync(object? parameter = null) { + if (SidebarContext.RightClickedItem is null) + return; + if (await DriveHelpers.CheckEmptyDrive(SidebarContext.RightClickedItem!.Path)) return; diff --git a/src/Files.App/Actions/Navigation/OpenInNewTab/OpenInNewTabFromHomeAction.cs b/src/Files.App/Actions/Navigation/OpenInNewTab/OpenInNewTabFromHomeAction.cs index 076c14bd11bd..784eff81d1f2 100644 --- a/src/Files.App/Actions/Navigation/OpenInNewTab/OpenInNewTabFromHomeAction.cs +++ b/src/Files.App/Actions/Navigation/OpenInNewTab/OpenInNewTabFromHomeAction.cs @@ -17,6 +17,9 @@ public override bool IsAccessibleGlobally public override async Task ExecuteAsync(object? parameter = null) { + if (HomePageContext.RightClickedItem is null) + return; + if (await DriveHelpers.CheckEmptyDrive(HomePageContext.RightClickedItem!.Path)) return; diff --git a/src/Files.App/Actions/Navigation/OpenInNewTab/OpenInNewTabFromSidebarAction.cs b/src/Files.App/Actions/Navigation/OpenInNewTab/OpenInNewTabFromSidebarAction.cs index 4cc935164f74..f07fdd4582bf 100644 --- a/src/Files.App/Actions/Navigation/OpenInNewTab/OpenInNewTabFromSidebarAction.cs +++ b/src/Files.App/Actions/Navigation/OpenInNewTab/OpenInNewTabFromSidebarAction.cs @@ -14,6 +14,9 @@ public override bool IsAccessibleGlobally public override async Task ExecuteAsync(object? parameter = null) { + if (SidebarContext.RightClickedItem is null) + return; + if (await DriveHelpers.CheckEmptyDrive(SidebarContext.RightClickedItem!.Path)) return; From 21e6d3db5e24c7868480df6b769d76f1e15d3c63 Mon Sep 17 00:00:00 2001 From: 0x5BFA <62196528+0x5bfa@users.noreply.github.com> Date: Fri, 7 Jun 2024 03:11:38 +0900 Subject: [PATCH 14/17] Update BaseWidgetViewModel.cs --- .../ViewModels/UserControls/Widgets/BaseWidgetViewModel.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Files.App/ViewModels/UserControls/Widgets/BaseWidgetViewModel.cs b/src/Files.App/ViewModels/UserControls/Widgets/BaseWidgetViewModel.cs index ef28d13a7153..1d9a73b5dc4b 100644 --- a/src/Files.App/ViewModels/UserControls/Widgets/BaseWidgetViewModel.cs +++ b/src/Files.App/ViewModels/UserControls/Widgets/BaseWidgetViewModel.cs @@ -70,7 +70,7 @@ public void BuildItemContextMenu(object sender, RightTappedRoutedEventArgs e) // Hook events itemContextMenuFlyout.Opening += (sender, e) => App.LastOpenedFlyout = sender as CommandBarFlyout; - itemContextMenuFlyout.Closed += (sender, e) => OnRightClickedItemChanged(null, null); + //itemContextMenuFlyout.Closed += (sender, e) => OnRightClickedItemChanged(null, null); _flyoutItemPath = item.Path; From da8e1e1f839236801287cbe7a329baa11abbfc3e Mon Sep 17 00:00:00 2001 From: 0x5bfa <62196528+0x5bfa@users.noreply.github.com> Date: Fri, 7 Jun 2024 21:28:18 +0900 Subject: [PATCH 15/17] Don't make it null when closed --- src/Files.App/ViewModels/UserControls/SidebarViewModel.cs | 1 - .../ViewModels/UserControls/Widgets/BaseWidgetViewModel.cs | 1 - 2 files changed, 2 deletions(-) diff --git a/src/Files.App/ViewModels/UserControls/SidebarViewModel.cs b/src/Files.App/ViewModels/UserControls/SidebarViewModel.cs index 7b4b8cb0e327..411bbbdefa04 100644 --- a/src/Files.App/ViewModels/UserControls/SidebarViewModel.cs +++ b/src/Files.App/ViewModels/UserControls/SidebarViewModel.cs @@ -696,7 +696,6 @@ await foreach (var taggedItem in fileTagsService.GetItemsForTagAsync(tagItem.Fil }; itemContextMenuFlyout.Opening += (sender, e) => App.LastOpenedFlyout = sender as CommandBarFlyout; - itemContextMenuFlyout.Closed += (sender, e) => RightClickedItemChanged?.Invoke(this, null); var menuItems = GetLocationItemMenuItems(item, itemContextMenuFlyout); var (_, secondaryElements) = ContextFlyoutModelToElementHelper.GetAppBarItemsFromModel(menuItems); diff --git a/src/Files.App/ViewModels/UserControls/Widgets/BaseWidgetViewModel.cs b/src/Files.App/ViewModels/UserControls/Widgets/BaseWidgetViewModel.cs index 1d9a73b5dc4b..cec3cb3398c5 100644 --- a/src/Files.App/ViewModels/UserControls/Widgets/BaseWidgetViewModel.cs +++ b/src/Files.App/ViewModels/UserControls/Widgets/BaseWidgetViewModel.cs @@ -70,7 +70,6 @@ public void BuildItemContextMenu(object sender, RightTappedRoutedEventArgs e) // Hook events itemContextMenuFlyout.Opening += (sender, e) => App.LastOpenedFlyout = sender as CommandBarFlyout; - //itemContextMenuFlyout.Closed += (sender, e) => OnRightClickedItemChanged(null, null); _flyoutItemPath = item.Path; From cc13ed66e6a26a4abd5cb378b080cf5a04726f45 Mon Sep 17 00:00:00 2001 From: 0x5bfa <62196528+0x5bfa@users.noreply.github.com> Date: Fri, 7 Jun 2024 22:30:58 +0900 Subject: [PATCH 16/17] Fix --- .../Navigation/OpenInNewPane/OpenInNewPaneFromHomeAction.cs | 1 + .../OpenInNewPane/OpenInNewPaneFromSidebarAction.cs | 4 +++- .../Navigation/OpenInNewTab/OpenInNewTabFromHomeAction.cs | 1 + .../Navigation/OpenInNewTab/OpenInNewTabFromSidebarAction.cs | 4 +++- .../OpenInNewWindow/OpenInNewWindowFromHomeAction.cs | 1 + .../OpenInNewWindow/OpenInNewWindowFromSidebarAction.cs | 4 +++- 6 files changed, 12 insertions(+), 3 deletions(-) diff --git a/src/Files.App/Actions/Navigation/OpenInNewPane/OpenInNewPaneFromHomeAction.cs b/src/Files.App/Actions/Navigation/OpenInNewPane/OpenInNewPaneFromHomeAction.cs index f4d8c4b9a213..ae12ef51f661 100644 --- a/src/Files.App/Actions/Navigation/OpenInNewPane/OpenInNewPaneFromHomeAction.cs +++ b/src/Files.App/Actions/Navigation/OpenInNewPane/OpenInNewPaneFromHomeAction.cs @@ -6,6 +6,7 @@ namespace Files.App.Actions internal sealed class OpenInNewPaneFromHomeAction : BaseOpenInNewPaneAction { public override bool IsExecutable => + UserSettingsService.GeneralSettingsService.ShowOpenInNewPane && HomePageContext.IsAnyItemRightClicked && HomePageContext.RightClickedItem is not null && HomePageContext.RightClickedItem is WidgetFileTagCardItem fileTagItem diff --git a/src/Files.App/Actions/Navigation/OpenInNewPane/OpenInNewPaneFromSidebarAction.cs b/src/Files.App/Actions/Navigation/OpenInNewPane/OpenInNewPaneFromSidebarAction.cs index 027ebcfa5752..9d757d2c2ceb 100644 --- a/src/Files.App/Actions/Navigation/OpenInNewPane/OpenInNewPaneFromSidebarAction.cs +++ b/src/Files.App/Actions/Navigation/OpenInNewPane/OpenInNewPaneFromSidebarAction.cs @@ -6,8 +6,10 @@ namespace Files.App.Actions internal sealed class OpenInNewPaneFromSidebarAction : BaseOpenInNewPaneAction { public override bool IsExecutable => + UserSettingsService.GeneralSettingsService.ShowOpenInNewPane && SidebarContext.IsItemRightClicked && - SidebarContext.RightClickedItem is not null; + SidebarContext.RightClickedItem is not null && + SidebarContext.RightClickedItem.MenuOptions.IsLocationItem; public override bool IsAccessibleGlobally => false; diff --git a/src/Files.App/Actions/Navigation/OpenInNewTab/OpenInNewTabFromHomeAction.cs b/src/Files.App/Actions/Navigation/OpenInNewTab/OpenInNewTabFromHomeAction.cs index 784eff81d1f2..a670de1bfc8b 100644 --- a/src/Files.App/Actions/Navigation/OpenInNewTab/OpenInNewTabFromHomeAction.cs +++ b/src/Files.App/Actions/Navigation/OpenInNewTab/OpenInNewTabFromHomeAction.cs @@ -6,6 +6,7 @@ namespace Files.App.Actions internal sealed class OpenInNewTabFromHomeAction : BaseOpenInNewTabAction { public override bool IsExecutable => + UserSettingsService.GeneralSettingsService.ShowOpenInNewTab && HomePageContext.IsAnyItemRightClicked && HomePageContext.RightClickedItem is not null && HomePageContext.RightClickedItem is WidgetFileTagCardItem fileTagItem diff --git a/src/Files.App/Actions/Navigation/OpenInNewTab/OpenInNewTabFromSidebarAction.cs b/src/Files.App/Actions/Navigation/OpenInNewTab/OpenInNewTabFromSidebarAction.cs index f07fdd4582bf..20947764c9a9 100644 --- a/src/Files.App/Actions/Navigation/OpenInNewTab/OpenInNewTabFromSidebarAction.cs +++ b/src/Files.App/Actions/Navigation/OpenInNewTab/OpenInNewTabFromSidebarAction.cs @@ -6,8 +6,10 @@ namespace Files.App.Actions internal sealed class OpenInNewTabFromSidebarAction : BaseOpenInNewTabAction { public override bool IsExecutable => + UserSettingsService.GeneralSettingsService.ShowOpenInNewTab && SidebarContext.IsItemRightClicked && - SidebarContext.RightClickedItem is not null; + SidebarContext.RightClickedItem is not null && + SidebarContext.RightClickedItem.MenuOptions.IsLocationItem; public override bool IsAccessibleGlobally => false; diff --git a/src/Files.App/Actions/Navigation/OpenInNewWindow/OpenInNewWindowFromHomeAction.cs b/src/Files.App/Actions/Navigation/OpenInNewWindow/OpenInNewWindowFromHomeAction.cs index 522a3a9efb23..ba3ce43dee5f 100644 --- a/src/Files.App/Actions/Navigation/OpenInNewWindow/OpenInNewWindowFromHomeAction.cs +++ b/src/Files.App/Actions/Navigation/OpenInNewWindow/OpenInNewWindowFromHomeAction.cs @@ -9,6 +9,7 @@ public override HotKey HotKey => HotKey.None; public override bool IsExecutable => + UserSettingsService.GeneralSettingsService.ShowOpenInNewWindow && HomePageContext.IsAnyItemRightClicked && HomePageContext.RightClickedItem is not null && HomePageContext.RightClickedItem is WidgetFileTagCardItem fileTagItem diff --git a/src/Files.App/Actions/Navigation/OpenInNewWindow/OpenInNewWindowFromSidebarAction.cs b/src/Files.App/Actions/Navigation/OpenInNewWindow/OpenInNewWindowFromSidebarAction.cs index c12880b595ce..de2f8ab18417 100644 --- a/src/Files.App/Actions/Navigation/OpenInNewWindow/OpenInNewWindowFromSidebarAction.cs +++ b/src/Files.App/Actions/Navigation/OpenInNewWindow/OpenInNewWindowFromSidebarAction.cs @@ -9,8 +9,10 @@ public override HotKey HotKey => HotKey.None; public override bool IsExecutable => + UserSettingsService.GeneralSettingsService.ShowOpenInNewWindow && SidebarContext.IsItemRightClicked && - SidebarContext.RightClickedItem is not null; + SidebarContext.RightClickedItem is not null && + SidebarContext.RightClickedItem.MenuOptions.IsLocationItem; public override bool IsAccessibleGlobally => false; From 5468a650e1350b83f792f072fa08ba2922b81093 Mon Sep 17 00:00:00 2001 From: 0x5bfa <62196528+0x5bfa@users.noreply.github.com> Date: Fri, 7 Jun 2024 23:59:19 +0900 Subject: [PATCH 17/17] Add brackets --- .../Navigation/OpenInNewPane/OpenInNewPaneFromHomeAction.cs | 4 ++-- .../Navigation/OpenInNewTab/OpenInNewTabFromHomeAction.cs | 4 ++-- .../OpenInNewWindow/OpenInNewWindowFromHomeAction.cs | 4 ++-- 3 files changed, 6 insertions(+), 6 deletions(-) diff --git a/src/Files.App/Actions/Navigation/OpenInNewPane/OpenInNewPaneFromHomeAction.cs b/src/Files.App/Actions/Navigation/OpenInNewPane/OpenInNewPaneFromHomeAction.cs index ae12ef51f661..b7954d30e087 100644 --- a/src/Files.App/Actions/Navigation/OpenInNewPane/OpenInNewPaneFromHomeAction.cs +++ b/src/Files.App/Actions/Navigation/OpenInNewPane/OpenInNewPaneFromHomeAction.cs @@ -9,9 +9,9 @@ internal sealed class OpenInNewPaneFromHomeAction : BaseOpenInNewPaneAction UserSettingsService.GeneralSettingsService.ShowOpenInNewPane && HomePageContext.IsAnyItemRightClicked && HomePageContext.RightClickedItem is not null && - HomePageContext.RightClickedItem is WidgetFileTagCardItem fileTagItem + (HomePageContext.RightClickedItem is WidgetFileTagCardItem fileTagItem ? fileTagItem.IsFolder - : true; + : true); public override bool IsAccessibleGlobally => false; diff --git a/src/Files.App/Actions/Navigation/OpenInNewTab/OpenInNewTabFromHomeAction.cs b/src/Files.App/Actions/Navigation/OpenInNewTab/OpenInNewTabFromHomeAction.cs index a670de1bfc8b..c4648ba08754 100644 --- a/src/Files.App/Actions/Navigation/OpenInNewTab/OpenInNewTabFromHomeAction.cs +++ b/src/Files.App/Actions/Navigation/OpenInNewTab/OpenInNewTabFromHomeAction.cs @@ -9,9 +9,9 @@ internal sealed class OpenInNewTabFromHomeAction : BaseOpenInNewTabAction UserSettingsService.GeneralSettingsService.ShowOpenInNewTab && HomePageContext.IsAnyItemRightClicked && HomePageContext.RightClickedItem is not null && - HomePageContext.RightClickedItem is WidgetFileTagCardItem fileTagItem + (HomePageContext.RightClickedItem is WidgetFileTagCardItem fileTagItem ? fileTagItem.IsFolder - : true; + : true); public override bool IsAccessibleGlobally => false; diff --git a/src/Files.App/Actions/Navigation/OpenInNewWindow/OpenInNewWindowFromHomeAction.cs b/src/Files.App/Actions/Navigation/OpenInNewWindow/OpenInNewWindowFromHomeAction.cs index ba3ce43dee5f..2b419f3f6fe2 100644 --- a/src/Files.App/Actions/Navigation/OpenInNewWindow/OpenInNewWindowFromHomeAction.cs +++ b/src/Files.App/Actions/Navigation/OpenInNewWindow/OpenInNewWindowFromHomeAction.cs @@ -12,9 +12,9 @@ public override HotKey HotKey UserSettingsService.GeneralSettingsService.ShowOpenInNewWindow && HomePageContext.IsAnyItemRightClicked && HomePageContext.RightClickedItem is not null && - HomePageContext.RightClickedItem is WidgetFileTagCardItem fileTagItem + (HomePageContext.RightClickedItem is WidgetFileTagCardItem fileTagItem ? fileTagItem.IsFolder - : true; + : true); public override bool IsAccessibleGlobally => false;