Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix: Fixed issue where a new tab would open when trying to open a new window #14463

Merged
merged 1 commit into from
Jan 15, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 29 additions & 0 deletions src/Files.App/Actions/Navigation/NewWindowAction.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
// Copyright (c) 2023 Files Community
// Licensed under the MIT License. See the LICENSE.

namespace Files.App.Actions
{
internal class NewWindowAction : IAction
{
public string Label
=> "NewWindow".GetLocalizedResource();

public string Description
=> "NewWindowDescription".GetLocalizedResource();

public HotKey HotKey
=> new(Keys.N, KeyModifiers.Ctrl);

public RichGlyph Glyph
=> new(opacityStyle: "ColorIconOpenNewWindow");

public NewWindowAction()
{
}

public Task ExecuteAsync()
{
return NavigationHelpers.LaunchNewWindowAsync();
}
}
}
1 change: 1 addition & 0 deletions src/Files.App/Data/Commands/CommandCodes.cs
Original file line number Diff line number Diff line change
Expand Up @@ -165,6 +165,7 @@ public enum CommandCodes
ToggleGroupByDateUnit,

// Navigation
NewWindow,
NewTab,
NavigateBack,
NavigateForward,
Expand Down
2 changes: 2 additions & 0 deletions src/Files.App/Data/Commands/Manager/CommandManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -159,6 +159,7 @@ public IRichCommand this[HotKey hotKey]
public IRichCommand GroupByYear => commands[CommandCodes.GroupByYear];
public IRichCommand GroupByMonth => commands[CommandCodes.GroupByMonth];
public IRichCommand ToggleGroupByDateUnit => commands[CommandCodes.ToggleGroupByDateUnit];
public IRichCommand NewWindow => commands[CommandCodes.NewWindow];
public IRichCommand NewTab => commands[CommandCodes.NewTab];
public IRichCommand FormatDrive => commands[CommandCodes.FormatDrive];
public IRichCommand NavigateBack => commands[CommandCodes.NavigateBack];
Expand Down Expand Up @@ -328,6 +329,7 @@ public CommandManager()
[CommandCodes.GroupByYear] = new GroupByYearAction(),
[CommandCodes.GroupByMonth] = new GroupByMonthAction(),
[CommandCodes.ToggleGroupByDateUnit] = new ToggleGroupByDateUnitAction(),
[CommandCodes.NewWindow] = new NewWindowAction(),
[CommandCodes.NewTab] = new NewTabAction(),
[CommandCodes.FormatDrive] = new FormatDriveAction(),
[CommandCodes.NavigateBack] = new NavigateBackAction(),
Expand Down
1 change: 1 addition & 0 deletions src/Files.App/Data/Commands/Manager/ICommandManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -148,6 +148,7 @@ public interface ICommandManager : IEnumerable<IRichCommand>
IRichCommand GroupByMonth { get; }
IRichCommand ToggleGroupByDateUnit { get; }

IRichCommand NewWindow { get; }
IRichCommand NewTab { get; }
IRichCommand NavigateBack { get; }
IRichCommand NavigateForward { get; }
Expand Down
2 changes: 1 addition & 1 deletion src/Files.App/Helpers/Navigation/NavigationHelpers.cs
Original file line number Diff line number Diff line change
Expand Up @@ -280,7 +280,7 @@ public static void OpenInSecondaryPane(IShellPage associatedInstance, ListedItem

public static Task LaunchNewWindowAsync()
{
var filesUWPUri = new Uri("files-uwp:");
var filesUWPUri = new Uri("files-uwp:?window=");
return Launcher.LaunchUriAsync(filesUWPUri).AsTask();
}

Expand Down
8 changes: 4 additions & 4 deletions src/Files.App/Strings/en-US/Resources.resw
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,7 @@
<resheader name="writer">
<value>System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
</resheader>
<data name="NavigationToolbarNewWindow.Label" xml:space="preserve">
<data name="NewWindow" xml:space="preserve">
<value>New window</value>
</data>
<data name="CopyPath" xml:space="preserve">
Expand Down Expand Up @@ -1650,9 +1650,6 @@
<data name="Home" xml:space="preserve">
<value>Home</value>
</data>
<data name="NavigationToolbarNewWindow.KeyboardAcceleratorTextOverride" xml:space="preserve">
<value>Ctrl+N</value>
</data>
<data name="BaseLayoutContextFlyoutDetails.KeyboardAcceleratorTextOverride" xml:space="preserve">
<value>Ctrl+Shift+1</value>
</data>
Expand Down Expand Up @@ -3686,4 +3683,7 @@
<data name="ScrollToPreviousFolderWhenNavigatingUp" xml:space="preserve">
<value>Scroll to previous folder when navigating up</value>
</data>
<data name="NewWindowDescription" xml:space="preserve">
<value>Open new window</value>
</data>
</root>
17 changes: 4 additions & 13 deletions src/Files.App/UserControls/InnerNavigationToolbar.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,8 @@
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:contract8Present="http://schemas.microsoft.com/winfx/2006/xaml/presentation?IsApiContractPresent(Windows.Foundation.UniversalApiContract,8)"
xmlns:converters="using:Files.App.Converters"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:helpers="using:Files.App.Helpers"
xmlns:i="using:Microsoft.Xaml.Interactivity"
xmlns:icore="using:Microsoft.Xaml.Interactions.Core"
xmlns:local="using:Files.App.UserControls"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:wctconverters="using:CommunityToolkit.WinUI.UI.Converters"
Expand Down Expand Up @@ -970,16 +967,10 @@
<!-- New Window -->
<AppBarButton
x:Name="NavToolbarNewWindow"
Command="{x:Bind ViewModel.OpenNewWindowCommand, Mode=OneWay}"
KeyboardAcceleratorTextOverride="{helpers:ResourceString Name=NavigationToolbarNewWindow/KeyboardAcceleratorTextOverride}"
Label="{helpers:ResourceString Name=NavigationToolbarNewWindow/Label}">
<local:OpacityIcon Style="{StaticResource ColorIconOpenNewWindow}" />
<AppBarButton.KeyboardAccelerators>
<KeyboardAccelerator
Key="N"
IsEnabled="False"
Modifiers="Control" />
</AppBarButton.KeyboardAccelerators>
Command="{x:Bind Commands.NewWindow, Mode=OneWay}"
KeyboardAcceleratorTextOverride="{x:Bind Commands.NewWindow.HotKeyText, Mode=OneWay}"
Label="{x:Bind Commands.NewWindow.Label}">
<local:OpacityIcon Style="{x:Bind Commands.NewWindow.OpacityStyle}" />
</AppBarButton>

<!-- Exter Compact Overlay -->
Expand Down
9 changes: 0 additions & 9 deletions src/Files.App/ViewModels/MainPageViewModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -60,14 +60,12 @@ public bool ShouldPreviewPaneBeDisplayed
// Commands

public ICommand NavigateToNumberedTabKeyboardAcceleratorCommand { get; }
public ICommand OpenNewWindowAcceleratorCommand { get; }

// Constructor

public MainPageViewModel()
{
NavigateToNumberedTabKeyboardAcceleratorCommand = new RelayCommand<KeyboardAcceleratorInvokedEventArgs>(ExecuteNavigateToNumberedTabKeyboardAcceleratorCommand);
OpenNewWindowAcceleratorCommand = new AsyncRelayCommand<KeyboardAcceleratorInvokedEventArgs>(ExecuteOpenNewWindowAcceleratorCommand);
}

// Methods
Expand Down Expand Up @@ -220,12 +218,5 @@ private void ExecuteNavigateToNumberedTabKeyboardAcceleratorCommand(KeyboardAcce
e.Handled = true;
}

private async Task ExecuteOpenNewWindowAcceleratorCommand(KeyboardAcceleratorInvokedEventArgs? e)
{
await Launcher.LaunchUriAsync(new Uri("files-uwp:"));

e!.Handled = true;
}

}
}
7 changes: 0 additions & 7 deletions src/Files.App/Views/MainPage.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -114,13 +114,6 @@
</icore:EventTriggerBehavior>
</i:Interaction.Behaviors>
</KeyboardAccelerator>
<KeyboardAccelerator Key="N" Modifiers="Control">
<i:Interaction.Behaviors>
<icore:EventTriggerBehavior EventName="Invoked">
<icore:InvokeCommandAction Command="{x:Bind ViewModel.OpenNewWindowAcceleratorCommand}" />
</icore:EventTriggerBehavior>
</i:Interaction.Behaviors>
</KeyboardAccelerator>
</Page.KeyboardAccelerators>

<Grid>
Expand Down