Skip to content

Commit 0bb34ac

Browse files
yaira2gave92
andauthored
Added a right click context menu to the drives widget (#2343)
Co-authored-by: Marco Gavelli <[email protected]>
1 parent 76e111a commit 0bb34ac

File tree

4 files changed

+60
-9
lines changed

4 files changed

+60
-9
lines changed

Files/Filesystem/DriveItem.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ public class DriveItem : ObservableObject, INavigationControlItem
2222
public ByteSize FreeSpace { get; set; }
2323
public ByteSize SpaceUsed { get; set; }
2424
public Visibility ItemVisibility { get; set; } = Visibility.Visible;
25+
public bool IsRemovable { get; set; }
2526

2627
private DriveType type;
2728

@@ -62,6 +63,7 @@ public DriveItem(StorageFolder root, DriveType type)
6263
Type = type;
6364
Path = string.IsNullOrEmpty(root.Path) ? $"\\\\?\\{root.Name}\\" : root.Path;
6465
Root = root;
66+
IsRemovable = (Type == DriveType.Removable || Type == DriveType.CDRom);
6567

6668
CoreApplication.MainView.ExecuteOnUIThreadAsync(() => GetDriveItemProperties());
6769
}

Files/UserControls/SidebarControl.xaml.cs

Lines changed: 1 addition & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -241,15 +241,7 @@ private void NavigationViewDriveItem_RightTapped(object sender, RightTappedRoute
241241
Microsoft.UI.Xaml.Controls.NavigationViewItem sidebarItem = (Microsoft.UI.Xaml.Controls.NavigationViewItem)sender;
242242
var item = sidebarItem.DataContext as DriveItem;
243243

244-
if (item.Type == DriveType.Removable || item.Type == DriveType.CDRom)
245-
{
246-
ShowEjectDevice = true;
247-
}
248-
else
249-
{
250-
ShowEjectDevice = false;
251-
}
252-
244+
ShowEjectDevice = item.IsRemovable;
253245
ShowUnpinItem = false;
254246
ShowEmptyRecycleBin = false;
255247
ShowProperties = true;

Files/UserControls/Widgets/DrivesWidget.xaml

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,43 @@
7575
Style="{StaticResource ButtonRevealStyle}"
7676
Tag="{x:Bind Path}"
7777
ToolTipService.ToolTip="{x:Bind Text, Mode=OneWay}">
78+
<Button.ContextFlyout>
79+
<MenuFlyout>
80+
<MenuFlyout.Items>
81+
<MenuFlyoutItem
82+
x:Name="OpenInNewTab"
83+
x:Uid="SideBarOpenInNewTab"
84+
Click="OpenInNewTab_Click"
85+
DataContext="{x:Bind}"
86+
Text="Open in new tab">
87+
<MenuFlyoutItem.Icon>
88+
<FontIcon FontFamily="{StaticResource CustomGlyph}" Glyph="&#xF106;" />
89+
</MenuFlyoutItem.Icon>
90+
</MenuFlyoutItem>
91+
<MenuFlyoutItem
92+
x:Name="OpenInNewWindow"
93+
x:Uid="SideBarOpenInNewWindow"
94+
Click="OpenInNewWindow_Click"
95+
DataContext="{x:Bind}"
96+
Text="Open in new window">
97+
<MenuFlyoutItem.Icon>
98+
<FontIcon FontFamily="{StaticResource CustomGlyph}" Glyph="&#xF107;" />
99+
</MenuFlyoutItem.Icon>
100+
</MenuFlyoutItem>
101+
<MenuFlyoutItem
102+
x:Name="EjectDevice"
103+
x:Uid="SideBarEjectDevice"
104+
x:Load="{x:Bind IsRemovable, Mode=OneWay}"
105+
Click="EjectDevice_Click"
106+
DataContext="{x:Bind}"
107+
Text="Eject">
108+
<MenuFlyoutItem.Icon>
109+
<FontIcon FontFamily="{StaticResource CustomGlyph}" Glyph="&#xF10B;" />
110+
</MenuFlyoutItem.Icon>
111+
</MenuFlyoutItem>
112+
</MenuFlyout.Items>
113+
</MenuFlyout>
114+
</Button.ContextFlyout>
78115
<Grid
79116
Margin="12"
80117
HorizontalAlignment="Stretch"

Files/UserControls/Widgets/DrivesWidget.xaml.cs

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,11 @@
33
using System;
44
using System.Collections.ObjectModel;
55
using System.Numerics;
6+
using Files.Interacts;
67
using Windows.UI.Xaml;
78
using Windows.UI.Xaml.Controls;
89
using Windows.UI.Xaml.Hosting;
10+
using System.Linq;
911

1012
namespace Files
1113
{
@@ -24,6 +26,24 @@ public DrivesWidget()
2426
InitializeComponent();
2527
}
2628

29+
private async void EjectDevice_Click(object sender, RoutedEventArgs e)
30+
{
31+
var item = ((MenuFlyoutItem)sender).DataContext as DriveItem;
32+
await Interaction.EjectDeviceAsync(item.Path);
33+
}
34+
35+
private void OpenInNewTab_Click(object sender, RoutedEventArgs e)
36+
{
37+
var item = ((MenuFlyoutItem)sender).DataContext as DriveItem;
38+
Interaction.OpenPathInNewTab(item.Path);
39+
}
40+
41+
private async void OpenInNewWindow_Click(object sender, RoutedEventArgs e)
42+
{
43+
var item = ((MenuFlyoutItem)sender).DataContext as DriveItem;
44+
await Interaction.OpenPathInNewWindowAsync(item.Path);
45+
}
46+
2747
private void Button_Click(object sender, RoutedEventArgs e)
2848
{
2949
string NavigationPath = ""; // path to navigate

0 commit comments

Comments
 (0)