Skip to content

Commit

Permalink
Fix: Fixed issue where a new tab would open when trying to open a new…
Browse files Browse the repository at this point in the history
  • Loading branch information
hishitetsu committed Jan 15, 2024
1 parent e0d9dfd commit 9368719
Show file tree
Hide file tree
Showing 9 changed files with 42 additions and 34 deletions.
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 @@ internal class CommandManager : ICommandManager
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

0 comments on commit 9368719

Please sign in to comment.