Skip to content

Commit dd6696d

Browse files
Moved Sidebar context menu to INavigationControlItem (#8506)
1 parent efac043 commit dd6696d

15 files changed

+447
-444
lines changed

src/Files.Uwp/DataModels/NavigationControlItems/DriveItem.cs

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -99,6 +99,8 @@ public string SpaceText
9999

100100
public SectionType Section { get; set; }
101101

102+
public ContextMenuOptions MenuOptions { get; set; }
103+
102104
private float percentageUsed = 0.0f;
103105

104106
public float PercentageUsed
@@ -143,6 +145,13 @@ public static async Task<DriveItem> CreateFromPropertiesAsync(StorageFolder root
143145
await CoreApplication.MainView.DispatcherQueue.EnqueueAsync(async () => await item.SetBitmapImage(imageStream));
144146
item.Text = root.DisplayName;
145147
item.Type = type;
148+
item.MenuOptions = new ContextMenuOptions
149+
{
150+
IsLocationItem = true,
151+
ShowEjectDevice = item.IsRemovable,
152+
ShowShellItems = true,
153+
ShowProperties = true
154+
};
146155
item.Path = string.IsNullOrEmpty(root.Path) ? $"\\\\?\\{root.Name}\\" : root.Path;
147156
item.DeviceID = deviceId;
148157
item.Root = root;

src/Files.Uwp/DataModels/NavigationControlItems/FileTagItem.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,8 @@ public string Path
2323

2424
public SectionType Section { get; set; }
2525

26+
public ContextMenuOptions MenuOptions { get; set; }
27+
2628
public NavigationControlItemType ItemType => NavigationControlItemType.FileTag;
2729

2830
public int CompareTo(INavigationControlItem other) => Text.CompareTo(other.Text);

src/Files.Uwp/DataModels/NavigationControlItems/INavigationControlItem.cs

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,8 @@ public interface INavigationControlItem : IComparable<INavigationControlItem>
1313
public string HoverDisplayText { get; }
1414

1515
public NavigationControlItemType ItemType { get; }
16+
17+
public ContextMenuOptions MenuOptions { get; }
1618
}
1719

1820
public enum NavigationControlItemType
@@ -36,4 +38,25 @@ public enum SectionType
3638
WSL,
3739
FileTag
3840
}
41+
42+
public class ContextMenuOptions
43+
{
44+
public bool IsLibrariesHeader { get; set; }
45+
46+
public bool ShowHideSection { get; set; }
47+
48+
public bool IsLocationItem { get; set; }
49+
50+
public bool ShowUnpinItem { get; set; }
51+
52+
public bool IsItemMovable { get; set; }
53+
54+
public bool ShowProperties { get; set; }
55+
56+
public bool ShowEmptyRecycleBin { get; set; }
57+
58+
public bool ShowEjectDevice { get; set; }
59+
60+
public bool ShowShellItems { get; set; }
61+
}
3962
}

src/Files.Uwp/DataModels/NavigationControlItems/LocationItem.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,8 @@ public bool IsExpanded
5959

6060
public SectionType Section { get; set; }
6161

62+
public ContextMenuOptions MenuOptions { get; set; }
63+
6264
public int CompareTo(INavigationControlItem other) => Text.CompareTo(other.Text);
6365
}
6466
}

src/Files.Uwp/DataModels/NavigationControlItems/WslDistroItem.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,8 @@ public string Path
2727

2828
public SectionType Section { get; private set; }
2929

30+
public ContextMenuOptions MenuOptions { get; set; }
31+
3032
public int CompareTo(INavigationControlItem other) => Text.CompareTo(other.Text);
3133
}
3234
}

src/Files.Uwp/DataModels/SidebarPinnedModel.cs

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -122,6 +122,13 @@ public async Task ShowHideRecycleBinItemAsync(bool show)
122122
{
123123
Text = ApplicationData.Current.LocalSettings.Values.Get("RecycleBin_Title", "Recycle Bin"),
124124
IsDefaultLocation = true,
125+
MenuOptions = new ContextMenuOptions
126+
{
127+
IsLocationItem = true,
128+
ShowUnpinItem = true,
129+
ShowShellItems = true,
130+
ShowEmptyRecycleBin = true
131+
},
125132
Icon = await CoreApplication.MainView.DispatcherQueue.EnqueueAsync(() => UIHelpers.GetIconResource(Constants.ImageRes.RecycleBin)),
126133
Path = CommonPaths.RecycleBinPath
127134
};
@@ -266,6 +273,14 @@ public async Task AddItemToSidebarAsync(string path)
266273
Font = MainViewModel.FontName,
267274
Path = path,
268275
Section = SectionType.Favorites,
276+
MenuOptions = new ContextMenuOptions
277+
{
278+
IsLocationItem = true,
279+
ShowProperties = true,
280+
ShowUnpinItem = true,
281+
ShowShellItems = true,
282+
IsItemMovable = true
283+
},
269284
IsDefaultLocation = false,
270285
Text = res.Result?.DisplayName ?? Path.GetFileName(path.TrimEnd('\\'))
271286
};
@@ -337,6 +352,10 @@ public async Task AddAllItemsToSidebar()
337352
{
338353
Text = "Home".GetLocalized(),
339354
Section = SectionType.Home,
355+
MenuOptions = new ContextMenuOptions
356+
{
357+
IsLocationItem = true
358+
},
340359
Font = MainViewModel.FontName,
341360
IsDefaultLocation = true,
342361
Icon = await CoreApplication.MainView.DispatcherQueue.EnqueueAsync(() => new BitmapImage(new Uri("ms-appx:///Assets/FluentIcons/Home.png"))),
@@ -347,6 +366,10 @@ public async Task AddAllItemsToSidebar()
347366
{
348367
Text = "SidebarFavorites".GetLocalized(),
349368
Section = SectionType.Favorites,
369+
MenuOptions = new ContextMenuOptions
370+
{
371+
ShowHideSection = true
372+
},
350373
SelectsOnInvoked = false,
351374
Icon = await CoreApplication.MainView.DispatcherQueue.EnqueueAsync(() => UIHelpers.GetIconResource(Constants.Shell32.QuickAccess)),
352375
Font = MainViewModel.FontName,

src/Files.Uwp/Filesystem/CloudDrivesManager.cs

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -51,9 +51,15 @@ public async Task EnumerateDrivesAsync()
5151
{
5252
Text = provider.Name,
5353
Path = provider.SyncFolder,
54-
Type = DriveType.CloudDrive,
54+
Type = DriveType.CloudDrive
55+
};
56+
cloudProviderItem.MenuOptions = new ContextMenuOptions
57+
{
58+
IsLocationItem = true,
59+
ShowEjectDevice = cloudProviderItem.IsRemovable,
60+
ShowShellItems = true,
61+
ShowProperties = true
5562
};
56-
5763
var iconData = await FileThumbnailHelper.LoadIconWithoutOverlayAsync(provider.SyncFolder, 24);
5864
if (iconData != null)
5965
{
@@ -111,6 +117,10 @@ await CoreApplication.MainView.CoreWindow.Dispatcher.RunAsync(CoreDispatcherPrio
111117
{
112118
Text = "SidebarCloudDrives".GetLocalized(),
113119
Section = SectionType.CloudDrives,
120+
MenuOptions = new ContextMenuOptions
121+
{
122+
ShowHideSection = true
123+
},
114124
SelectsOnInvoked = false,
115125
Icon = new Windows.UI.Xaml.Media.Imaging.BitmapImage(new Uri("ms-appx:///Assets/FluentIcons/CloudDrive.png")),
116126
ChildItems = new BulkConcurrentObservableCollection<INavigationControlItem>()

src/Files.Uwp/Filesystem/Drives.cs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -143,6 +143,10 @@ await CoreApplication.MainView.CoreWindow.Dispatcher.RunAsync(CoreDispatcherPrio
143143
{
144144
Text = "Drives".GetLocalized(),
145145
Section = SectionType.Drives,
146+
MenuOptions = new ContextMenuOptions
147+
{
148+
ShowHideSection = true
149+
},
146150
SelectsOnInvoked = false,
147151
Icon = await UIHelpers.GetIconResource(Constants.ImageRes.ThisPC),
148152
ChildItems = new BulkConcurrentObservableCollection<INavigationControlItem>()

src/Files.Uwp/Filesystem/FileTagsManager.cs

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,10 @@ await CoreApplication.MainView.CoreWindow.Dispatcher.RunAsync(CoreDispatcherPrio
5555
{
5656
Text = "FileTags".GetLocalized(),
5757
Section = SectionType.FileTag,
58+
MenuOptions = new ContextMenuOptions
59+
{
60+
ShowHideSection = true
61+
},
5862
SelectsOnInvoked = false,
5963
Icon = new Windows.UI.Xaml.Media.Imaging.BitmapImage(new Uri("ms-appx:///Assets/FluentIcons/FileTags.png")),
6064
ChildItems = new BulkConcurrentObservableCollection<INavigationControlItem>()
@@ -80,7 +84,11 @@ await CoreApplication.MainView.CoreWindow.Dispatcher.RunAsync(CoreDispatcherPrio
8084
{
8185
Text = tag.TagName,
8286
Path = $"tag:{tag.TagName}",
83-
FileTag = tag
87+
FileTag = tag,
88+
MenuOptions = new ContextMenuOptions
89+
{
90+
IsLocationItem = true
91+
}
8492
});
8593
}
8694
}

src/Files.Uwp/Filesystem/LibraryLocationItem.cs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,11 +16,19 @@ public class LibraryLocationItem : LocationItem
1616
public LibraryLocationItem(ShellLibraryItem shellLibrary)
1717
{
1818
Section = SectionType.Library;
19+
MenuOptions = new ContextMenuOptions
20+
{
21+
IsLocationItem = true,
22+
ShowProperties = true,
23+
ShowShellItems = true,
24+
ShowUnpinItem = !shellLibrary.IsPinned
25+
};
1926
Text = shellLibrary.DisplayName;
2027
Path = shellLibrary.FullPath;
2128
DefaultSaveFolder = shellLibrary.DefaultSaveFolder;
2229
Folders = shellLibrary.Folders == null ? null : new ReadOnlyCollection<string>(shellLibrary.Folders);
2330
IsDefaultLocation = shellLibrary.IsPinned;
31+
2432
}
2533

2634
public override bool Equals(object obj)

src/Files.Uwp/Filesystem/LibraryManager.cs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -197,6 +197,11 @@ await CoreApplication.MainView.CoreWindow.Dispatcher.RunAsync(CoreDispatcherPrio
197197
{
198198
Text = "SidebarLibraries".GetLocalized(),
199199
Section = SectionType.Library,
200+
MenuOptions = new ContextMenuOptions
201+
{
202+
IsLibrariesHeader = true,
203+
ShowHideSection = true
204+
},
200205
SelectsOnInvoked = false,
201206
Icon = await UIHelpers.GetIconResource(Constants.ImageRes.Libraries),
202207
ChildItems = new BulkConcurrentObservableCollection<INavigationControlItem>()

src/Files.Uwp/Filesystem/NetworkDrivesManager.cs

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,13 @@ public NetworkDrivesManager()
4646
Type = DriveType.Network,
4747
ItemType = NavigationControlItemType.Drive
4848
};
49+
networkItem.MenuOptions = new ContextMenuOptions
50+
{
51+
IsLocationItem = true,
52+
ShowShellItems = true,
53+
ShowEjectDevice = networkItem.IsRemovable,
54+
ShowProperties = true
55+
};
4956
lock (drivesList)
5057
{
5158
drivesList.Add(networkItem);
@@ -80,6 +87,13 @@ public async Task EnumerateDrivesAsync()
8087
Type = DriveType.Network,
8188
ItemType = NavigationControlItemType.Drive
8289
};
90+
networkItem.MenuOptions = new ContextMenuOptions
91+
{
92+
IsLocationItem = true,
93+
ShowEjectDevice = networkItem.IsRemovable,
94+
ShowShellItems = true,
95+
ShowProperties = true
96+
};
8397
lock (drivesList)
8498
{
8599
if (!drivesList.Any(x => x.Path == networkItem.Path))
@@ -128,6 +142,10 @@ await CoreApplication.MainView.CoreWindow.Dispatcher.RunAsync(CoreDispatcherPrio
128142
{
129143
Text = "SidebarNetworkDrives".GetLocalized(),
130144
Section = SectionType.Network,
145+
MenuOptions = new ContextMenuOptions
146+
{
147+
ShowHideSection = true
148+
},
131149
SelectsOnInvoked = false,
132150
Icon = await UIHelpers.GetIconResource(Constants.ImageRes.NetworkDrives),
133151
ChildItems = new BulkConcurrentObservableCollection<INavigationControlItem>()

src/Files.Uwp/Filesystem/WSLDistroManager.cs

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,10 @@ await CoreApplication.MainView.CoreWindow.Dispatcher.RunAsync(CoreDispatcherPrio
5555
{
5656
Text = "WSL".GetLocalized(),
5757
Section = SectionType.WSL,
58+
MenuOptions = new ContextMenuOptions
59+
{
60+
ShowHideSection = true
61+
},
5862
SelectsOnInvoked = false,
5963
Icon = new Windows.UI.Xaml.Media.Imaging.BitmapImage(new Uri("ms-appx:///Assets/WSL/genericpng.png")),
6064
ChildItems = new BulkConcurrentObservableCollection<INavigationControlItem>()
@@ -105,7 +109,11 @@ await CoreApplication.MainView.CoreWindow.Dispatcher.RunAsync(CoreDispatcherPrio
105109
{
106110
Text = folder.DisplayName,
107111
Path = folder.Path,
108-
Logo = logoURI
112+
Logo = logoURI,
113+
MenuOptions = new ContextMenuOptions
114+
{
115+
IsLocationItem = true
116+
}
109117
});
110118
}
111119
}

src/Files.Uwp/UserControls/SidebarControl.xaml

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@
5656
IsRightTapEnabled="True"
5757
MenuItemsSource="{x:Bind ChildItems}"
5858
PointerPressed="Sidebar_PointerPressed"
59-
RightTapped="NavigationViewLocationItem_RightTapped"
59+
RightTapped="NavigationViewItem_RightTapped"
6060
SelectsOnInvoked="{x:Bind SelectsOnInvoked}"
6161
Tag="{x:Bind Path}"
6262
ToolTipService.ToolTip="{x:Bind HoverDisplayText}">
@@ -81,7 +81,7 @@
8181
Drop="NavigationViewDriveItem_Drop"
8282
IsRightTapEnabled="True"
8383
PointerPressed="Sidebar_PointerPressed"
84-
RightTapped="NavigationViewDriveItem_RightTapped"
84+
RightTapped="NavigationViewItem_RightTapped"
8585
Tag="{x:Bind Path}"
8686
ToolTipService.ToolTip="{x:Bind HoverDisplayText, Mode=OneWay}"
8787
Visibility="{x:Bind ItemVisibility}">
@@ -99,7 +99,7 @@
9999
DragEnter="NavigationViewItem_DragEnter"
100100
DragLeave="NavigationViewItem_DragLeave"
101101
PointerPressed="Sidebar_PointerPressed"
102-
RightTapped="NavigationViewWSLItem_RightTapped"
102+
RightTapped="NavigationViewItem_RightTapped"
103103
Tag="{x:Bind Path}"
104104
ToolTipService.ToolTip="{x:Bind HoverDisplayText}">
105105
<muxc:NavigationViewItem.Icon>
@@ -124,7 +124,7 @@
124124
Drop="NavigationViewFileTag_Drop"
125125
IsRightTapEnabled="True"
126126
PointerPressed="Sidebar_PointerPressed"
127-
RightTapped="NavigationViewFileTagsItem_RightTapped"
127+
RightTapped="NavigationViewItem_RightTapped"
128128
Tag="{x:Bind Path}"
129129
ToolTipService.ToolTip="{x:Bind HoverDisplayText}">
130130
<muxc:NavigationViewItem.Icon>

0 commit comments

Comments
 (0)