Skip to content

Commit 9c7429d

Browse files
committed
Feature: Middle click sidebar item to open new tab
1 parent 1ab62de commit 9c7429d

File tree

5 files changed

+17
-14
lines changed

5 files changed

+17
-14
lines changed

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

Lines changed: 0 additions & 2 deletions
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

Lines changed: 2 additions & 1 deletion
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

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -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

Lines changed: 2 additions & 2 deletions
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/ViewModels/UserControls/SidebarViewModel.cs

Lines changed: 5 additions & 2 deletions
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,7 +722,10 @@ 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+
navigationPath is not null)
726729
{
727730
await NavigationHelpers.OpenPathInNewTab(navigationPath);
728731
return;

0 commit comments

Comments
 (0)