Skip to content

Commit e713a35

Browse files
authored
Feature: Added right click context menu to the Home Page (#18233)
1 parent 8c9a828 commit e713a35

File tree

3 files changed

+122
-1
lines changed

3 files changed

+122
-1
lines changed

src/Files.App/ViewModels/HomeViewModel.cs

Lines changed: 76 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,56 @@ public sealed partial class HomeViewModel : ObservableObject, IDisposable
1515

1616
public ObservableCollection<WidgetContainerItem> WidgetItems { get; } = [];
1717

18+
public bool ShowQuickAccessWidget
19+
{
20+
get => UserSettingsService.GeneralSettingsService.ShowQuickAccessWidget;
21+
set
22+
{
23+
if (value != UserSettingsService.GeneralSettingsService.ShowQuickAccessWidget)
24+
UserSettingsService.GeneralSettingsService.ShowQuickAccessWidget = value;
25+
}
26+
}
27+
28+
public bool ShowDrivesWidget
29+
{
30+
get => UserSettingsService.GeneralSettingsService.ShowDrivesWidget;
31+
set
32+
{
33+
if (value != UserSettingsService.GeneralSettingsService.ShowDrivesWidget)
34+
UserSettingsService.GeneralSettingsService.ShowDrivesWidget = value;
35+
}
36+
}
37+
38+
public bool ShowNetworkLocationsWidget
39+
{
40+
get => UserSettingsService.GeneralSettingsService.ShowNetworkLocationsWidget;
41+
set
42+
{
43+
if (value != UserSettingsService.GeneralSettingsService.ShowNetworkLocationsWidget)
44+
UserSettingsService.GeneralSettingsService.ShowNetworkLocationsWidget = value;
45+
}
46+
}
47+
48+
public bool ShowFileTagsWidget
49+
{
50+
get => UserSettingsService.GeneralSettingsService.ShowFileTagsWidget;
51+
set
52+
{
53+
if (value != UserSettingsService.GeneralSettingsService.ShowFileTagsWidget)
54+
UserSettingsService.GeneralSettingsService.ShowFileTagsWidget = value;
55+
}
56+
}
57+
58+
public bool ShowRecentFilesWidget
59+
{
60+
get => UserSettingsService.GeneralSettingsService.ShowRecentFilesWidget;
61+
set
62+
{
63+
if (value != UserSettingsService.GeneralSettingsService.ShowRecentFilesWidget)
64+
UserSettingsService.GeneralSettingsService.ShowRecentFilesWidget = value;
65+
}
66+
}
67+
1868
// Commands
1969

2070
public ICommand ReloadWidgetsCommand { get; }
@@ -24,6 +74,30 @@ public sealed partial class HomeViewModel : ObservableObject, IDisposable
2474
public HomeViewModel()
2575
{
2676
ReloadWidgetsCommand = new AsyncRelayCommand(ExecuteReloadWidgetsCommand);
77+
78+
UserSettingsService.GeneralSettingsService.PropertyChanged += GeneralSettingsService_PropertyChanged;
79+
}
80+
81+
private void GeneralSettingsService_PropertyChanged(object? sender, PropertyChangedEventArgs e)
82+
{
83+
switch (e.PropertyName)
84+
{
85+
case nameof(IGeneralSettingsService.ShowQuickAccessWidget):
86+
OnPropertyChanged(nameof(ShowQuickAccessWidget));
87+
break;
88+
case nameof(IGeneralSettingsService.ShowDrivesWidget):
89+
OnPropertyChanged(nameof(ShowDrivesWidget));
90+
break;
91+
case nameof(IGeneralSettingsService.ShowNetworkLocationsWidget):
92+
OnPropertyChanged(nameof(ShowNetworkLocationsWidget));
93+
break;
94+
case nameof(IGeneralSettingsService.ShowFileTagsWidget):
95+
OnPropertyChanged(nameof(ShowFileTagsWidget));
96+
break;
97+
case nameof(IGeneralSettingsService.ShowRecentFilesWidget):
98+
OnPropertyChanged(nameof(ShowRecentFilesWidget));
99+
break;
100+
}
27101
}
28102

29103
// Methods
@@ -213,6 +287,8 @@ private async Task ExecuteReloadWidgetsCommand()
213287

214288
public void Dispose()
215289
{
290+
UserSettingsService.GeneralSettingsService.PropertyChanged -= GeneralSettingsService_PropertyChanged;
291+
216292
MainWindow.Instance.DispatcherQueue.EnqueueOrInvokeAsync(() =>
217293
{
218294
for (int i = 0; i < WidgetItems.Count; i++)

src/Files.App/Views/HomePage.xaml

Lines changed: 35 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
xmlns:helpers="using:Files.App.Helpers"
1010
xmlns:i="using:Microsoft.Xaml.Interactivity"
1111
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
12+
xmlns:uc="using:Files.App.UserControls"
1213
DataContext="{x:Bind ViewModel, Mode=OneWay}"
1314
mc:Ignorable="d">
1415

@@ -421,7 +422,40 @@
421422
</UserControl.Resources>
422423

423424
<!-- Widget List -->
424-
<ScrollViewer>
425+
<ScrollViewer Background="Transparent" RightTapped="ScrollViewer_RightTapped">
426+
<FlyoutBase.AttachedFlyout>
427+
<MenuFlyout x:Name="HomePageContextMenu">
428+
<MenuFlyoutSubItem Text="{helpers:ResourceString Name=Widgets}">
429+
<MenuFlyoutSubItem.Icon>
430+
<FontIcon Glyph="&#xF246;" />
431+
</MenuFlyoutSubItem.Icon>
432+
<ToggleMenuFlyoutItem IsChecked="{x:Bind ViewModel.ShowQuickAccessWidget, Mode=TwoWay}" Text="{helpers:ResourceString Name=QuickAccess}" />
433+
<ToggleMenuFlyoutItem IsChecked="{x:Bind ViewModel.ShowDrivesWidget, Mode=TwoWay}" Text="{helpers:ResourceString Name=Drives}" />
434+
<ToggleMenuFlyoutItem IsChecked="{x:Bind ViewModel.ShowNetworkLocationsWidget, Mode=TwoWay}" Text="{helpers:ResourceString Name=NetworkLocations}" />
435+
<ToggleMenuFlyoutItem IsChecked="{x:Bind ViewModel.ShowFileTagsWidget, Mode=TwoWay}" Text="{helpers:ResourceString Name=FileTags}" />
436+
<ToggleMenuFlyoutItem IsChecked="{x:Bind ViewModel.ShowRecentFilesWidget, Mode=TwoWay}" Text="{helpers:ResourceString Name=RecentFiles}" />
437+
</MenuFlyoutSubItem>
438+
<MenuFlyoutSubItem
439+
x:Name="SplitPaneSubMenu"
440+
x:Load="{x:Bind Commands.SplitPaneHorizontally.IsExecutable, Mode=OneWay}"
441+
Text="{helpers:ResourceString Name=SplitPane}">
442+
<uc:MenuFlyoutItemWithThemedIcon
443+
Command="{x:Bind Commands.SplitPaneVertically, Mode=OneWay}"
444+
Text="{x:Bind Commands.SplitPaneVertically.Label}"
445+
ThemedIconStyle="{x:Bind Commands.SplitPaneVertically.ThemedIconStyle}" />
446+
<uc:MenuFlyoutItemWithThemedIcon
447+
Command="{x:Bind Commands.SplitPaneHorizontally, Mode=OneWay}"
448+
Text="{x:Bind Commands.SplitPaneHorizontally.Label}"
449+
ThemedIconStyle="{x:Bind Commands.SplitPaneHorizontally.ThemedIconStyle}" />
450+
</MenuFlyoutSubItem>
451+
<uc:MenuFlyoutItemWithThemedIcon
452+
x:Name="CloseActivePaneMenuItem"
453+
x:Load="{x:Bind Commands.CloseActivePane.IsExecutable, Mode=OneWay}"
454+
Command="{x:Bind Commands.CloseActivePane}"
455+
Text="{x:Bind Commands.CloseActivePane.Label}"
456+
ThemedIconStyle="{x:Bind Commands.CloseActivePane.ThemedIconStyle}" />
457+
</MenuFlyout>
458+
</FlyoutBase.AttachedFlyout>
425459
<ListView ItemsSource="{x:Bind ViewModel.WidgetItems, Mode=OneWay}" SelectionMode="None">
426460

427461
<ListView.ItemTemplate>

src/Files.App/Views/HomePage.xaml.cs

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,9 @@
11
// Copyright (c) Files Community
22
// Licensed under the MIT License.
33

4+
using Microsoft.UI.Xaml;
45
using Microsoft.UI.Xaml.Controls;
6+
using Microsoft.UI.Xaml.Input;
57
using Microsoft.UI.Xaml.Navigation;
68

79
namespace Files.App.Views
@@ -10,6 +12,7 @@ public sealed partial class HomePage : Page, IDisposable
1012
{
1113
// Dependency injections
1214

15+
private readonly ICommandManager Commands = Ioc.Default.GetRequiredService<ICommandManager>();
1316
public HomeViewModel ViewModel { get; } = Ioc.Default.GetRequiredService<HomeViewModel>();
1417

1518
// Properties
@@ -77,6 +80,14 @@ protected override async void OnNavigatedTo(NavigationEventArgs e)
7780
base.OnNavigatedTo(e);
7881
}
7982

83+
private void ScrollViewer_RightTapped(object sender, RightTappedRoutedEventArgs e)
84+
{
85+
if (sender is FrameworkElement element)
86+
HomePageContextMenu.ShowAt(element, e.GetPosition(element));
87+
88+
e.Handled = true;
89+
}
90+
8091
protected override void OnNavigatedFrom(NavigationEventArgs e)
8192
{
8293
Dispose();

0 commit comments

Comments
 (0)