Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Code Quality: Added support for middle clicking in the new BreadcrumbBar #17476

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

Merged
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
5 changes: 3 additions & 2 deletions src/Files.App.Controls/BreadcrumbBar/BreadcrumbBar.cs
View file Open in desktop
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
// Licensed under the MIT License.

using Microsoft.UI.Xaml.Automation;
using Microsoft.UI.Xaml.Input;
using Windows.Foundation;

namespace Files.App.Controls
Expand Down Expand Up @@ -67,10 +68,10 @@ protected override void OnApplyTemplate()
_itemsRepeater.ItemsSourceView.CollectionChanged += ItemsSourceView_CollectionChanged;
}

internal protected virtual void RaiseItemClickedEvent(BreadcrumbBarItem item)
internal protected virtual void RaiseItemClickedEvent(BreadcrumbBarItem item, PointerRoutedEventArgs? pointerRoutedEventArgs = null)
{
var index = _itemsRepeater?.GetElementIndex(item) ?? throw new ArgumentNullException($"{_itemsRepeater} is null.");
var eventArgs = new BreadcrumbBarItemClickedEventArgs(item, index, item == _rootBreadcrumbBarItem);
var eventArgs = new BreadcrumbBarItemClickedEventArgs(item, index, item == _rootBreadcrumbBarItem, pointerRoutedEventArgs);
ItemClicked?.Invoke(this, eventArgs);
}

Expand Down
View file Open in desktop
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,6 @@ namespace Files.App.Controls
{
public partial class BreadcrumbBarItem
{
private void ItemContentButton_Click(object sender, RoutedEventArgs e)
{
OnItemClicked();
}

private void ItemChevronButton_Click(object sender, RoutedEventArgs e)
{
FlyoutBase.ShowAttachedFlyout(_itemChevronButton);
Expand Down
20 changes: 16 additions & 4 deletions src/Files.App.Controls/BreadcrumbBar/BreadcrumbBarItem.cs
View file Open in desktop
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
// Copyright (c) Files Community
// Licensed under the MIT License.

using Microsoft.UI.Input;
using Microsoft.UI.Xaml.Input;

namespace Files.App.Controls
{
public partial class BreadcrumbBarItem : ContentControl
Expand Down Expand Up @@ -46,7 +49,16 @@ protected override void OnApplyTemplate()
if (IsEllipsis || IsLastItem)
VisualStateManager.GoToState(this, "ChevronCollapsed", true);

_itemContentButton.Click += ItemContentButton_Click;
// Handle click event with PointerReleasedEvent to get PointerPoint
_itemContentButton.AddHandler( // Bypass "IsHandled = true" done in the base class
PointerReleasedEvent,
new PointerEventHandler((s, e) =>
{
OnItemClicked(e);
e.Handled = true;
}),
handledEventsToo: true);

_itemContentButton.PreviewKeyDown += ItemContentButton_PreviewKeyDown;
_itemChevronButton.Click += ItemChevronButton_Click;
_itemChevronButton.PreviewKeyDown += ItemChevronButton_PreviewKeyDown;
Expand All @@ -55,7 +67,7 @@ protected override void OnApplyTemplate()
_itemChevronDropDownMenuFlyout.Closed += ChevronDropDownMenuFlyout_Closed;
}

public void OnItemClicked()
public void OnItemClicked(PointerRoutedEventArgs? pointerRoutedEventArgs = null)
{
if (_ownerRef is null ||
!_ownerRef.TryGetTarget(out var breadcrumbBar))
Expand All @@ -73,7 +85,7 @@ public void OnItemClicked()
{
var menuFlyoutItem = new MenuFlyoutItem() { Text = text };
_itemEllipsisDropDownMenuFlyout.Items.Add(menuFlyoutItem);
menuFlyoutItem.Click += (sender, e) => breadcrumbBar.RaiseItemClickedEvent(item);
menuFlyoutItem.Click += (sender, e) => breadcrumbBar.RaiseItemClickedEvent(item, pointerRoutedEventArgs);
}
}

Expand All @@ -83,7 +95,7 @@ public void OnItemClicked()
else
{
// Fire a click event
breadcrumbBar.RaiseItemClickedEvent(this);
breadcrumbBar.RaiseItemClickedEvent(this, pointerRoutedEventArgs);
}
}

Expand Down
4 changes: 3 additions & 1 deletion src/Files.App.Controls/BreadcrumbBar/EventArgs.cs
View file Open in desktop
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
// Copyright (c) Files Community
// Licensed under the MIT License.

using Microsoft.UI.Xaml.Input;

namespace Files.App.Controls
{
public record class BreadcrumbBarItemClickedEventArgs(BreadcrumbBarItem Item, int Index, bool IsRootItem = false);
public record class BreadcrumbBarItemClickedEventArgs(BreadcrumbBarItem Item, int Index, bool IsRootItem = false, PointerRoutedEventArgs? PointerRoutedEventArgs = null);

public record class BreadcrumbBarItemDropDownFlyoutEventArgs(MenuFlyout Flyout, BreadcrumbBarItem? Item = null, int Index = -1, bool IsRootItem = false);
}
5 changes: 4 additions & 1 deletion src/Files.App/UserControls/NavigationToolbar.xaml.cs
View file Open in desktop
Original file line number Diff line number Diff line change
Expand Up @@ -279,7 +279,10 @@ private async void BreadcrumbBar_ItemClicked(Controls.BreadcrumbBar sender, Cont
ViewModel.PathComponents[args.Index].Path is not { } path)
return;

await ViewModel.HandleFolderNavigationAsync(path);
// If user clicked the item with middle mouse button, open it in new tab
var openInNewTab = args.PointerRoutedEventArgs?.GetCurrentPoint(null).Properties.PointerUpdateKind is PointerUpdateKind.MiddleButtonReleased;

await ViewModel.HandleFolderNavigationAsync(path, openInNewTab);
}

private async void BreadcrumbBar_ItemDropDownFlyoutOpening(object sender, BreadcrumbBarItemDropDownFlyoutEventArgs e)
Expand Down
Loading

AltStyle によって変換されたページ (->オリジナル) /