Skip to content

Commit d8508d3

Browse files
committedNov 2, 2023
Feature: Middle click sidebar item to open new tab (#13639)
1 parent f1750fb commit d8508d3

File tree

6 files changed

+21
-17
lines changed

6 files changed

+21
-17
lines changed
 

‎src/Files.App/Data/Items/FileTagItem.cs

-2
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,6 @@
22
// Licensed under the MIT License. See the LICENSE.
33

44
using CommunityToolkit.WinUI.Helpers;
5-
using Files.App.Converters;
6-
using Files.Core.ViewModels.FileTags;
75
using Microsoft.UI.Xaml;
86
using Microsoft.UI.Xaml.Controls;
97
using Microsoft.UI.Xaml.Markup;

‎src/Files.App/UserControls/SideBar/ISideBarViewModel.cs

+2-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
// Copyright (c) 2023 Files Community
22
// Licensed under the MIT License. See the LICENSE.
33

4+
using Microsoft.UI.Input;
45
using Microsoft.UI.Xaml;
56
using Windows.ApplicationModel.DataTransfer;
67
using Windows.Foundation;
@@ -42,6 +43,6 @@ public interface ISidebarViewModel
4243
/// Gets invoked when an item is invoked (double clicked) on any item of the sidebar.
4344
/// </summary>
4445
/// <param name="item">The item that was invoked.</param>
45-
void HandleItemInvokedAsync(object item);
46+
void HandleItemInvokedAsync(object item, PointerUpdateKind pointerUpdateKind);
4647
}
4748
}

‎src/Files.App/UserControls/SideBar/SideBarItem.cs

+9-8
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ public SidebarItem()
3737
{
3838
if (args.Key == Windows.System.VirtualKey.Enter)
3939
{
40-
Clicked();
40+
Clicked(PointerUpdateKind.Other);
4141
args.Handled = true;
4242
}
4343
};
@@ -237,7 +237,7 @@ private void ChildrenPresenter_ElementPrepared(ItemsRepeater sender, ItemsRepeat
237237
}
238238
}
239239

240-
internal void Clicked()
240+
internal void Clicked(PointerUpdateKind pointerUpdateKind)
241241
{
242242
if (IsGroupHeader)
243243
{
@@ -250,12 +250,12 @@ internal void Clicked()
250250
SetFlyoutOpen(true);
251251
}
252252
}
253-
RaiseItemInvoked();
253+
RaiseItemInvoked(pointerUpdateKind);
254254
}
255255

256-
internal void RaiseItemInvoked()
256+
internal void RaiseItemInvoked(PointerUpdateKind pointerUpdateKind)
257257
{
258-
Owner?.RaiseItemInvoked(this);
258+
Owner?.RaiseItemInvoked(this, pointerUpdateKind);
259259
}
260260

261261
private void SidebarDisplayModeChanged(SidebarDisplayMode oldValue)
@@ -386,10 +386,11 @@ private void Item_PointerReleased(object sender, Microsoft.UI.Xaml.Input.Pointer
386386
UpdatePointerState();
387387

388388
VisualStateManager.GoToState(this, IsExpanded ? "ExpandedIconNormal" : "CollapsedIconNormal", true);
389-
var updateKind = e.GetCurrentPoint(null).Properties.PointerUpdateKind;
390-
if (updateKind == PointerUpdateKind.LeftButtonReleased)
389+
var pointerUpdateKind = e.GetCurrentPoint(null).Properties.PointerUpdateKind;
390+
if (pointerUpdateKind == PointerUpdateKind.LeftButtonReleased ||
391+
pointerUpdateKind == PointerUpdateKind.MiddleButtonReleased)
391392
{
392-
Clicked();
393+
Clicked(pointerUpdateKind);
393394
}
394395
}
395396

‎src/Files.App/UserControls/SideBar/SideBarView.xaml.cs

+2-2
Original file line numberDiff line numberDiff line change
@@ -39,14 +39,14 @@ internal void UpdateSelectedItemContainer(SidebarItem container)
3939
SelectedItemContainer = container;
4040
}
4141

42-
internal void RaiseItemInvoked(SidebarItem item)
42+
internal void RaiseItemInvoked(SidebarItem item, PointerUpdateKind pointerUpdateKind)
4343
{
4444
// Only leaves can be selected
4545
if (item.Item is null || item.IsGroupHeader) return;
4646

4747
SelectedItem = item.Item;
4848
ItemInvoked?.Invoke(item, item.Item);
49-
ViewModel.HandleItemInvokedAsync(item.Item);
49+
ViewModel.HandleItemInvokedAsync(item.Item, pointerUpdateKind);
5050
}
5151

5252
internal void RaiseContextRequested(SidebarItem item, Point e)

‎src/Files.App/UserControls/SideBar/SidebarItemAutomationPeer.cs

+2-1
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
// Licensed under the MIT License. See the LICENSE.
33

44
using CommunityToolkit.WinUI.UI;
5+
using Microsoft.UI.Input;
56
using Microsoft.UI.Xaml.Automation;
67
using Microsoft.UI.Xaml.Automation.Peers;
78
using Microsoft.UI.Xaml.Automation.Provider;
@@ -74,7 +75,7 @@ public void Expand()
7475

7576
public void Invoke()
7677
{
77-
Owner.RaiseItemInvoked();
78+
Owner.RaiseItemInvoked(PointerUpdateKind.Other);
7879
}
7980

8081
public void AddToSelection()

‎src/Files.App/ViewModels/UserControls/SidebarViewModel.cs

+6-3
Original file line numberDiff line numberDiff line change
@@ -713,7 +713,7 @@ private async void ItemContextMenuFlyout_Opened(object? sender, object e)
713713
await ShellContextmenuHelper.LoadShellMenuItemsAsync(rightClickedItem.Path, itemContextMenuFlyout, rightClickedItem.MenuOptions);
714714
}
715715

716-
public async void HandleItemInvokedAsync(object item)
716+
public async void HandleItemInvokedAsync(object item, PointerUpdateKind pointerUpdateKind)
717717
{
718718
if (item is not INavigationControlItem navigationControlItem) return;
719719
var navigationPath = item as string;
@@ -722,9 +722,12 @@ public async void HandleItemInvokedAsync(object item)
722722
return;
723723

724724
var ctrlPressed = InputKeyboardSource.GetKeyStateForCurrentThread(VirtualKey.Control).HasFlag(CoreVirtualKeyStates.Down);
725-
if (ctrlPressed && navigationPath is not null)
725+
var middleClickPressed = pointerUpdateKind == PointerUpdateKind.MiddleButtonReleased;
726+
if ((ctrlPressed ||
727+
middleClickPressed) &&
728+
navigationControlItem.Path is not null)
726729
{
727-
await NavigationHelpers.OpenPathInNewTab(navigationPath);
730+
await NavigationHelpers.OpenPathInNewTab(navigationControlItem.Path);
728731
return;
729732
}
730733

0 commit comments

Comments
 (0)
Please sign in to comment.