Skip to content

Commit 9368719

Browse files
authored
Fix: Fixed issue where a new tab would open when trying to open a new window (files-community#14463)
1 parent e0d9dfd commit 9368719

File tree

9 files changed

+42
-34
lines changed

9 files changed

+42
-34
lines changed
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
// Copyright (c) 2023 Files Community
2+
// Licensed under the MIT License. See the LICENSE.
3+
4+
namespace Files.App.Actions
5+
{
6+
internal class NewWindowAction : IAction
7+
{
8+
public string Label
9+
=> "NewWindow".GetLocalizedResource();
10+
11+
public string Description
12+
=> "NewWindowDescription".GetLocalizedResource();
13+
14+
public HotKey HotKey
15+
=> new(Keys.N, KeyModifiers.Ctrl);
16+
17+
public RichGlyph Glyph
18+
=> new(opacityStyle: "ColorIconOpenNewWindow");
19+
20+
public NewWindowAction()
21+
{
22+
}
23+
24+
public Task ExecuteAsync()
25+
{
26+
return NavigationHelpers.LaunchNewWindowAsync();
27+
}
28+
}
29+
}

src/Files.App/Data/Commands/CommandCodes.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -165,6 +165,7 @@ public enum CommandCodes
165165
ToggleGroupByDateUnit,
166166

167167
// Navigation
168+
NewWindow,
168169
NewTab,
169170
NavigateBack,
170171
NavigateForward,

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

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -159,6 +159,7 @@ public IRichCommand this[HotKey hotKey]
159159
public IRichCommand GroupByYear => commands[CommandCodes.GroupByYear];
160160
public IRichCommand GroupByMonth => commands[CommandCodes.GroupByMonth];
161161
public IRichCommand ToggleGroupByDateUnit => commands[CommandCodes.ToggleGroupByDateUnit];
162+
public IRichCommand NewWindow => commands[CommandCodes.NewWindow];
162163
public IRichCommand NewTab => commands[CommandCodes.NewTab];
163164
public IRichCommand FormatDrive => commands[CommandCodes.FormatDrive];
164165
public IRichCommand NavigateBack => commands[CommandCodes.NavigateBack];
@@ -328,6 +329,7 @@ public CommandManager()
328329
[CommandCodes.GroupByYear] = new GroupByYearAction(),
329330
[CommandCodes.GroupByMonth] = new GroupByMonthAction(),
330331
[CommandCodes.ToggleGroupByDateUnit] = new ToggleGroupByDateUnitAction(),
332+
[CommandCodes.NewWindow] = new NewWindowAction(),
331333
[CommandCodes.NewTab] = new NewTabAction(),
332334
[CommandCodes.FormatDrive] = new FormatDriveAction(),
333335
[CommandCodes.NavigateBack] = new NavigateBackAction(),

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -148,6 +148,7 @@ public interface ICommandManager : IEnumerable<IRichCommand>
148148
IRichCommand GroupByMonth { get; }
149149
IRichCommand ToggleGroupByDateUnit { get; }
150150

151+
IRichCommand NewWindow { get; }
151152
IRichCommand NewTab { get; }
152153
IRichCommand NavigateBack { get; }
153154
IRichCommand NavigateForward { get; }

src/Files.App/Helpers/Navigation/NavigationHelpers.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -280,7 +280,7 @@ public static void OpenInSecondaryPane(IShellPage associatedInstance, ListedItem
280280

281281
public static Task LaunchNewWindowAsync()
282282
{
283-
var filesUWPUri = new Uri("files-uwp:");
283+
var filesUWPUri = new Uri("files-uwp:?window=");
284284
return Launcher.LaunchUriAsync(filesUWPUri).AsTask();
285285
}
286286

src/Files.App/Strings/en-US/Resources.resw

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -117,7 +117,7 @@
117117
<resheader name="writer">
118118
<value>System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
119119
</resheader>
120-
<data name="NavigationToolbarNewWindow.Label" xml:space="preserve">
120+
<data name="NewWindow" xml:space="preserve">
121121
<value>New window</value>
122122
</data>
123123
<data name="CopyPath" xml:space="preserve">
@@ -1650,9 +1650,6 @@
16501650
<data name="Home" xml:space="preserve">
16511651
<value>Home</value>
16521652
</data>
1653-
<data name="NavigationToolbarNewWindow.KeyboardAcceleratorTextOverride" xml:space="preserve">
1654-
<value>Ctrl+N</value>
1655-
</data>
16561653
<data name="BaseLayoutContextFlyoutDetails.KeyboardAcceleratorTextOverride" xml:space="preserve">
16571654
<value>Ctrl+Shift+1</value>
16581655
</data>
@@ -3686,4 +3683,7 @@
36863683
<data name="ScrollToPreviousFolderWhenNavigatingUp" xml:space="preserve">
36873684
<value>Scroll to previous folder when navigating up</value>
36883685
</data>
3686+
<data name="NewWindowDescription" xml:space="preserve">
3687+
<value>Open new window</value>
3688+
</data>
36893689
</root>

src/Files.App/UserControls/InnerNavigationToolbar.xaml

Lines changed: 4 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,8 @@
44
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
55
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
66
xmlns:contract8Present="http://schemas.microsoft.com/winfx/2006/xaml/presentation?IsApiContractPresent(Windows.Foundation.UniversalApiContract,8)"
7-
xmlns:converters="using:Files.App.Converters"
87
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
98
xmlns:helpers="using:Files.App.Helpers"
10-
xmlns:i="using:Microsoft.Xaml.Interactivity"
11-
xmlns:icore="using:Microsoft.Xaml.Interactions.Core"
129
xmlns:local="using:Files.App.UserControls"
1310
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
1411
xmlns:wctconverters="using:CommunityToolkit.WinUI.UI.Converters"
@@ -970,16 +967,10 @@
970967
<!-- New Window -->
971968
<AppBarButton
972969
x:Name="NavToolbarNewWindow"
973-
Command="{x:Bind ViewModel.OpenNewWindowCommand, Mode=OneWay}"
974-
KeyboardAcceleratorTextOverride="{helpers:ResourceString Name=NavigationToolbarNewWindow/KeyboardAcceleratorTextOverride}"
975-
Label="{helpers:ResourceString Name=NavigationToolbarNewWindow/Label}">
976-
<local:OpacityIcon Style="{StaticResource ColorIconOpenNewWindow}" />
977-
<AppBarButton.KeyboardAccelerators>
978-
<KeyboardAccelerator
979-
Key="N"
980-
IsEnabled="False"
981-
Modifiers="Control" />
982-
</AppBarButton.KeyboardAccelerators>
970+
Command="{x:Bind Commands.NewWindow, Mode=OneWay}"
971+
KeyboardAcceleratorTextOverride="{x:Bind Commands.NewWindow.HotKeyText, Mode=OneWay}"
972+
Label="{x:Bind Commands.NewWindow.Label}">
973+
<local:OpacityIcon Style="{x:Bind Commands.NewWindow.OpacityStyle}" />
983974
</AppBarButton>
984975

985976
<!-- Exter Compact Overlay -->

src/Files.App/ViewModels/MainPageViewModel.cs

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -60,14 +60,12 @@ public bool ShouldPreviewPaneBeDisplayed
6060
// Commands
6161

6262
public ICommand NavigateToNumberedTabKeyboardAcceleratorCommand { get; }
63-
public ICommand OpenNewWindowAcceleratorCommand { get; }
6463

6564
// Constructor
6665

6766
public MainPageViewModel()
6867
{
6968
NavigateToNumberedTabKeyboardAcceleratorCommand = new RelayCommand<KeyboardAcceleratorInvokedEventArgs>(ExecuteNavigateToNumberedTabKeyboardAcceleratorCommand);
70-
OpenNewWindowAcceleratorCommand = new AsyncRelayCommand<KeyboardAcceleratorInvokedEventArgs>(ExecuteOpenNewWindowAcceleratorCommand);
7169
}
7270

7371
// Methods
@@ -220,12 +218,5 @@ private void ExecuteNavigateToNumberedTabKeyboardAcceleratorCommand(KeyboardAcce
220218
e.Handled = true;
221219
}
222220

223-
private async Task ExecuteOpenNewWindowAcceleratorCommand(KeyboardAcceleratorInvokedEventArgs? e)
224-
{
225-
await Launcher.LaunchUriAsync(new Uri("files-uwp:"));
226-
227-
e!.Handled = true;
228-
}
229-
230221
}
231222
}

src/Files.App/Views/MainPage.xaml

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -114,13 +114,6 @@
114114
</icore:EventTriggerBehavior>
115115
</i:Interaction.Behaviors>
116116
</KeyboardAccelerator>
117-
<KeyboardAccelerator Key="N" Modifiers="Control">
118-
<i:Interaction.Behaviors>
119-
<icore:EventTriggerBehavior EventName="Invoked">
120-
<icore:InvokeCommandAction Command="{x:Bind ViewModel.OpenNewWindowAcceleratorCommand}" />
121-
</icore:EventTriggerBehavior>
122-
</i:Interaction.Behaviors>
123-
</KeyboardAccelerator>
124117
</Page.KeyboardAccelerators>
125118

126119
<Grid>

0 commit comments

Comments
 (0)