Skip to content

Commit a31cfc6

Browse files
authored
Code Quality: Improved Shelf pane (#17069)
1 parent 5f1f185 commit a31cfc6

File tree

3 files changed

+38
-10
lines changed

3 files changed

+38
-10
lines changed

src/Files.App/UserControls/Pane/ShelfPane.xaml

+2-10
Original file line numberDiff line numberDiff line change
@@ -103,8 +103,10 @@
103103
Padding="8,4,8,4"
104104
CanDragItems="True"
105105
DragItemsStarting="ListView_DragItemsStarting"
106+
GotFocus="ShelfItemsList_GotFocus"
106107
ItemContainerTransitions="{x:Null}"
107108
ItemsSource="{x:Bind ItemsSource, Mode=OneWay}"
109+
RightTapped="ShelfItemsList_RightTapped"
108110
ScrollViewer.VerticalScrollBarVisibility="Auto"
109111
ScrollViewer.VerticalScrollMode="Auto"
110112
SelectionMode="Extended">
@@ -126,16 +128,6 @@
126128
TextTrimming="CharacterEllipsis"
127129
TextWrapping="NoWrap"
128130
ToolTipService.ToolTip="{x:Bind Path, Mode=OneWay}" />
129-
130-
<Grid.ContextFlyout>
131-
<MenuFlyout>
132-
<MenuFlyoutItem Command="{x:Bind RemoveCommand}" Text="{helpers:ResourceString Name=RemoveFromShelf}">
133-
<MenuFlyoutItem.Icon>
134-
<FontIcon Glyph="&#xE738;" />
135-
</MenuFlyoutItem.Icon>
136-
</MenuFlyoutItem>
137-
</MenuFlyout>
138-
</Grid.ContextFlyout>
139131
</Grid>
140132
</DataTemplate>
141133
</ListView.ItemTemplate>

src/Files.App/UserControls/Pane/ShelfPane.xaml.cs

+35
Original file line numberDiff line numberDiff line change
@@ -86,6 +86,32 @@ private void ListView_DragItemsStarting(object sender, DragItemsStartingEventArg
8686
dataObjectProvider.SetDataObject(ppDataObject);
8787
}
8888

89+
private void ShelfItemsList_RightTapped(object sender, Microsoft.UI.Xaml.Input.RightTappedRoutedEventArgs e)
90+
{
91+
if (e.OriginalSource is not Microsoft.UI.Xaml.FrameworkElement widgetCardItem ||
92+
widgetCardItem.DataContext is not ShelfItem item ||
93+
item.Path is null)
94+
return;
95+
96+
var menuFlyout = new MenuFlyout();
97+
98+
menuFlyout.Items.Add (new MenuFlyoutItem
99+
{
100+
Text = Strings.RemoveFromShelf.GetLocalizedResource(),
101+
Icon = new FontIcon { Glyph = "\uE738" },
102+
Command = new RelayCommand(item.Remove)
103+
});
104+
105+
menuFlyout.ShowAt(widgetCardItem);
106+
e.Handled = true;
107+
}
108+
109+
private void ShelfItemsList_GotFocus(object sender, RoutedEventArgs e)
110+
{
111+
if (ItemFocusedCommand is not null)
112+
ItemFocusedCommand.Execute(null);
113+
}
114+
89115
public ObservableCollection<ShelfItem>? ItemsSource
90116
{
91117
get => (ObservableCollection<ShelfItem>?)GetValue(ItemsSourceProperty);
@@ -101,5 +127,14 @@ public ICommand? ClearCommand
101127
}
102128
public static readonly DependencyProperty ClearCommandProperty =
103129
DependencyProperty.Register(nameof(ClearCommand), typeof(ICommand), typeof(ShelfPane), new PropertyMetadata(null));
130+
131+
public ICommand? ItemFocusedCommand
132+
{
133+
get => (ICommand?)GetValue(ItemFocusedCommandProperty);
134+
set => SetValue(ItemFocusedCommandProperty, value);
135+
}
136+
public static readonly DependencyProperty ItemFocusedCommandProperty =
137+
DependencyProperty.Register(nameof(ItemFocusedCommand), typeof(ICommand), typeof(ShelfPane), new PropertyMetadata(null));
138+
104139
}
105140
}

src/Files.App/Views/MainPage.xaml

+1
Original file line numberDiff line numberDiff line change
@@ -273,6 +273,7 @@
273273
Margin="4,0,0,8"
274274
x:Load="{x:Bind ViewModel.ShowShelfPane, Mode=OneWay}"
275275
ClearCommand="{x:Bind ViewModel.ShelfViewModel.ClearItemsCommand}"
276+
ItemFocusedCommand="{x:Bind Commands.ClearSelection, Mode=OneWay}"
276277
ItemsSource="{x:Bind ViewModel.ShelfViewModel.Items}" />
277278
</Grid>
278279
</controls:SidebarView.InnerContent>

0 commit comments

Comments
 (0)