Skip to content
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

Moved Sidebar item context menu options from SidebarControl.xaml.cs into INavigationControlItem #8506

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
9 changes: 9 additions & 0 deletions src/Files.Uwp/DataModels/NavigationControlItems/DriveItem.cs
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,8 @@ public string SpaceText

public SectionType Section { get; set; }

public ContextMenuOptions MenuOptions { get; set; }

private float percentageUsed = 0.0f;

public float PercentageUsed
Expand Down Expand Up @@ -143,6 +145,13 @@ public static async Task<DriveItem> CreateFromPropertiesAsync(StorageFolder root
await CoreApplication.MainView.DispatcherQueue.EnqueueAsync(async () => await item.SetBitmapImage(imageStream));
item.Text = root.DisplayName;
item.Type = type;
item.MenuOptions = new ContextMenuOptions
{
IsLocationItem = true,
ShowEjectDevice = item.IsRemovable,
ShowShellItems = true,
ShowProperties = true
};
item.Path = string.IsNullOrEmpty(root.Path) ? $"\\\\?\\{root.Name}\\" : root.Path;
item.DeviceID = deviceId;
item.Root = root;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@ public string Path

public SectionType Section { get; set; }

public ContextMenuOptions MenuOptions { get; set; }

public NavigationControlItemType ItemType => NavigationControlItemType.FileTag;

public int CompareTo(INavigationControlItem other) => Text.CompareTo(other.Text);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@ public interface INavigationControlItem : IComparable<INavigationControlItem>
public string HoverDisplayText { get; }

public NavigationControlItemType ItemType { get; }

public ContextMenuOptions MenuOptions { get; }
}

public enum NavigationControlItemType
Expand All @@ -36,4 +38,25 @@ public enum SectionType
WSL,
FileTag
}

public class ContextMenuOptions
{
public bool IsLibrariesHeader { get; set; }

public bool ShowHideSection { get; set; }

public bool IsLocationItem { get; set; }

public bool ShowUnpinItem { get; set; }

public bool IsItemMovable { get; set; }

public bool ShowProperties { get; set; }

public bool ShowEmptyRecycleBin { get; set; }

public bool ShowEjectDevice { get; set; }

public bool ShowShellItems { get; set; }
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,8 @@ public bool IsExpanded

public SectionType Section { get; set; }

public ContextMenuOptions MenuOptions { get; set; }

public int CompareTo(INavigationControlItem other) => Text.CompareTo(other.Text);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,8 @@ public string Path

public SectionType Section { get; private set; }

public ContextMenuOptions MenuOptions { get; set; }

public int CompareTo(INavigationControlItem other) => Text.CompareTo(other.Text);
}
}
23 changes: 23 additions & 0 deletions src/Files.Uwp/DataModels/SidebarPinnedModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,13 @@ public async Task ShowHideRecycleBinItemAsync(bool show)
{
Text = ApplicationData.Current.LocalSettings.Values.Get("RecycleBin_Title", "Recycle Bin"),
IsDefaultLocation = true,
MenuOptions = new ContextMenuOptions
{
IsLocationItem = true,
ShowUnpinItem = true,
ShowShellItems = true,
ShowEmptyRecycleBin = true
},
Icon = await CoreApplication.MainView.DispatcherQueue.EnqueueAsync(() => UIHelpers.GetIconResource(Constants.ImageRes.RecycleBin)),
Path = CommonPaths.RecycleBinPath
};
Expand Down Expand Up @@ -266,6 +273,14 @@ public async Task AddItemToSidebarAsync(string path)
Font = MainViewModel.FontName,
Path = path,
Section = SectionType.Favorites,
MenuOptions = new ContextMenuOptions
{
IsLocationItem = true,
ShowProperties = true,
ShowUnpinItem = true,
ShowShellItems = true,
IsItemMovable = true
},
IsDefaultLocation = false,
Text = res.Result?.DisplayName ?? Path.GetFileName(path.TrimEnd('\\'))
};
Expand Down Expand Up @@ -337,6 +352,10 @@ public async Task AddAllItemsToSidebar()
{
Text = "Home".GetLocalized(),
Section = SectionType.Home,
MenuOptions = new ContextMenuOptions
{
IsLocationItem = true
},
Font = MainViewModel.FontName,
IsDefaultLocation = true,
Icon = await CoreApplication.MainView.DispatcherQueue.EnqueueAsync(() => new BitmapImage(new Uri("ms-appx:///Assets/FluentIcons/Home.png"))),
Expand All @@ -347,6 +366,10 @@ public async Task AddAllItemsToSidebar()
{
Text = "SidebarFavorites".GetLocalized(),
Section = SectionType.Favorites,
MenuOptions = new ContextMenuOptions
{
ShowHideSection = true
},
SelectsOnInvoked = false,
Icon = await CoreApplication.MainView.DispatcherQueue.EnqueueAsync(() => UIHelpers.GetIconResource(Constants.Shell32.QuickAccess)),
Font = MainViewModel.FontName,
Expand Down
14 changes: 12 additions & 2 deletions src/Files.Uwp/Filesystem/CloudDrivesManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -51,9 +51,15 @@ public async Task EnumerateDrivesAsync()
{
Text = provider.Name,
Path = provider.SyncFolder,
Type = DriveType.CloudDrive,
Type = DriveType.CloudDrive
};
cloudProviderItem.MenuOptions = new ContextMenuOptions
{
IsLocationItem = true,
ShowEjectDevice = cloudProviderItem.IsRemovable,
ShowShellItems = true,
ShowProperties = true
};

var iconData = await FileThumbnailHelper.LoadIconWithoutOverlayAsync(provider.SyncFolder, 24);
if (iconData != null)
{
Expand Down Expand Up @@ -111,6 +117,10 @@ await CoreApplication.MainView.CoreWindow.Dispatcher.RunAsync(CoreDispatcherPrio
{
Text = "SidebarCloudDrives".GetLocalized(),
Section = SectionType.CloudDrives,
MenuOptions = new ContextMenuOptions
{
ShowHideSection = true
},
SelectsOnInvoked = false,
Icon = new Windows.UI.Xaml.Media.Imaging.BitmapImage(new Uri("ms-appx:///Assets/FluentIcons/CloudDrive.png")),
ChildItems = new BulkConcurrentObservableCollection<INavigationControlItem>()
Expand Down
4 changes: 4 additions & 0 deletions src/Files.Uwp/Filesystem/Drives.cs
Original file line number Diff line number Diff line change
Expand Up @@ -143,6 +143,10 @@ await CoreApplication.MainView.CoreWindow.Dispatcher.RunAsync(CoreDispatcherPrio
{
Text = "Drives".GetLocalized(),
Section = SectionType.Drives,
MenuOptions = new ContextMenuOptions
{
ShowHideSection = true
},
SelectsOnInvoked = false,
Icon = await UIHelpers.GetIconResource(Constants.ImageRes.ThisPC),
ChildItems = new BulkConcurrentObservableCollection<INavigationControlItem>()
Expand Down
10 changes: 9 additions & 1 deletion src/Files.Uwp/Filesystem/FileTagsManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,10 @@ await CoreApplication.MainView.CoreWindow.Dispatcher.RunAsync(CoreDispatcherPrio
{
Text = "FileTags".GetLocalized(),
Section = SectionType.FileTag,
MenuOptions = new ContextMenuOptions
{
ShowHideSection = true
},
SelectsOnInvoked = false,
Icon = new Windows.UI.Xaml.Media.Imaging.BitmapImage(new Uri("ms-appx:///Assets/FluentIcons/FileTags.png")),
ChildItems = new BulkConcurrentObservableCollection<INavigationControlItem>()
Expand All @@ -80,7 +84,11 @@ await CoreApplication.MainView.CoreWindow.Dispatcher.RunAsync(CoreDispatcherPrio
{
Text = tag.TagName,
Path = $"tag:{tag.TagName}",
FileTag = tag
FileTag = tag,
MenuOptions = new ContextMenuOptions
{
IsLocationItem = true
}
});
}
}
Expand Down
8 changes: 8 additions & 0 deletions src/Files.Uwp/Filesystem/LibraryLocationItem.cs
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,19 @@ public class LibraryLocationItem : LocationItem
public LibraryLocationItem(ShellLibraryItem shellLibrary)
{
Section = SectionType.Library;
MenuOptions = new ContextMenuOptions
{
IsLocationItem = true,
ShowProperties = true,
ShowShellItems = true,
ShowUnpinItem = !shellLibrary.IsPinned
};
Text = shellLibrary.DisplayName;
Path = shellLibrary.FullPath;
DefaultSaveFolder = shellLibrary.DefaultSaveFolder;
Folders = shellLibrary.Folders == null ? null : new ReadOnlyCollection<string>(shellLibrary.Folders);
IsDefaultLocation = shellLibrary.IsPinned;

}

public override bool Equals(object obj)
Expand Down
5 changes: 5 additions & 0 deletions src/Files.Uwp/Filesystem/LibraryManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -197,6 +197,11 @@ await CoreApplication.MainView.CoreWindow.Dispatcher.RunAsync(CoreDispatcherPrio
{
Text = "SidebarLibraries".GetLocalized(),
Section = SectionType.Library,
MenuOptions = new ContextMenuOptions
{
IsLibrariesHeader = true,
ShowHideSection = true
},
SelectsOnInvoked = false,
Icon = await UIHelpers.GetIconResource(Constants.ImageRes.Libraries),
ChildItems = new BulkConcurrentObservableCollection<INavigationControlItem>()
Expand Down
18 changes: 18 additions & 0 deletions src/Files.Uwp/Filesystem/NetworkDrivesManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,13 @@ public NetworkDrivesManager()
Type = DriveType.Network,
ItemType = NavigationControlItemType.Drive
};
networkItem.MenuOptions = new ContextMenuOptions
{
IsLocationItem = true,
ShowShellItems = true,
ShowEjectDevice = networkItem.IsRemovable,
ShowProperties = true
};
lock (drivesList)
{
drivesList.Add(networkItem);
Expand Down Expand Up @@ -80,6 +87,13 @@ public async Task EnumerateDrivesAsync()
Type = DriveType.Network,
ItemType = NavigationControlItemType.Drive
};
networkItem.MenuOptions = new ContextMenuOptions
{
IsLocationItem = true,
ShowEjectDevice = networkItem.IsRemovable,
ShowShellItems = true,
ShowProperties = true
};
lock (drivesList)
{
if (!drivesList.Any(x => x.Path == networkItem.Path))
Expand Down Expand Up @@ -128,6 +142,10 @@ await CoreApplication.MainView.CoreWindow.Dispatcher.RunAsync(CoreDispatcherPrio
{
Text = "SidebarNetworkDrives".GetLocalized(),
Section = SectionType.Network,
MenuOptions = new ContextMenuOptions
{
ShowHideSection = true
},
SelectsOnInvoked = false,
Icon = await UIHelpers.GetIconResource(Constants.ImageRes.NetworkDrives),
ChildItems = new BulkConcurrentObservableCollection<INavigationControlItem>()
Expand Down
10 changes: 9 additions & 1 deletion src/Files.Uwp/Filesystem/WSLDistroManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,10 @@ await CoreApplication.MainView.CoreWindow.Dispatcher.RunAsync(CoreDispatcherPrio
{
Text = "WSL".GetLocalized(),
Section = SectionType.WSL,
MenuOptions = new ContextMenuOptions
{
ShowHideSection = true
},
SelectsOnInvoked = false,
Icon = new Windows.UI.Xaml.Media.Imaging.BitmapImage(new Uri("ms-appx:///Assets/WSL/genericpng.png")),
ChildItems = new BulkConcurrentObservableCollection<INavigationControlItem>()
Expand Down Expand Up @@ -105,7 +109,11 @@ await CoreApplication.MainView.CoreWindow.Dispatcher.RunAsync(CoreDispatcherPrio
{
Text = folder.DisplayName,
Path = folder.Path,
Logo = logoURI
Logo = logoURI,
MenuOptions = new ContextMenuOptions
{
IsLocationItem = true
}
});
}
}
Expand Down
8 changes: 4 additions & 4 deletions src/Files.Uwp/UserControls/SidebarControl.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@
IsRightTapEnabled="True"
MenuItemsSource="{x:Bind ChildItems}"
PointerPressed="Sidebar_PointerPressed"
RightTapped="NavigationViewLocationItem_RightTapped"
RightTapped="NavigationViewItem_RightTapped"
SelectsOnInvoked="{x:Bind SelectsOnInvoked}"
Tag="{x:Bind Path}"
ToolTipService.ToolTip="{x:Bind HoverDisplayText}">
Expand All @@ -81,7 +81,7 @@
Drop="NavigationViewDriveItem_Drop"
IsRightTapEnabled="True"
PointerPressed="Sidebar_PointerPressed"
RightTapped="NavigationViewDriveItem_RightTapped"
RightTapped="NavigationViewItem_RightTapped"
Tag="{x:Bind Path}"
ToolTipService.ToolTip="{x:Bind HoverDisplayText, Mode=OneWay}"
Visibility="{x:Bind ItemVisibility}">
Expand All @@ -99,7 +99,7 @@
DragEnter="NavigationViewItem_DragEnter"
DragLeave="NavigationViewItem_DragLeave"
PointerPressed="Sidebar_PointerPressed"
RightTapped="NavigationViewWSLItem_RightTapped"
RightTapped="NavigationViewItem_RightTapped"
Tag="{x:Bind Path}"
ToolTipService.ToolTip="{x:Bind HoverDisplayText}">
<muxc:NavigationViewItem.Icon>
Expand All @@ -124,7 +124,7 @@
Drop="NavigationViewFileTag_Drop"
IsRightTapEnabled="True"
PointerPressed="Sidebar_PointerPressed"
RightTapped="NavigationViewFileTagsItem_RightTapped"
RightTapped="NavigationViewItem_RightTapped"
Tag="{x:Bind Path}"
ToolTipService.ToolTip="{x:Bind HoverDisplayText}">
<muxc:NavigationViewItem.Icon>
Expand Down
Loading