mirror of
https://github.com/microsoft/PowerToys.git
synced 2026-04-04 02:06:36 +02:00
Add support for filterable, nested context menus (#38776)
_targets #38573_ At first I just wanted to add support for nested context menus. But then I also had to add a search box, so the focus wouldn't get weird. End result:  This gets rid of the need to have the search box and the command bar both track item keybindings - now it's just in the command bar. Closes #38299 Closes #38442
This commit is contained in:
@@ -6,6 +6,7 @@ using System.Threading;
|
||||
using System.Threading.Tasks;
|
||||
using Microsoft.CommandPalette.Extensions;
|
||||
using Microsoft.CommandPalette.Extensions.Toolkit;
|
||||
using Windows.System;
|
||||
|
||||
namespace SamplePagesExtension;
|
||||
|
||||
@@ -76,7 +77,136 @@ public partial class EvilSamplesPage : ListPage
|
||||
{
|
||||
Body = "This is a test for GH#512. If it doesn't appear immediately, it's likely InvokeCommand is happening on the UI thread.",
|
||||
},
|
||||
}
|
||||
},
|
||||
|
||||
// More edge cases than truly evil
|
||||
new ListItem(
|
||||
new ToastCommand("Primary command invoked", MessageState.Info) { Name = "Primary command", Icon = new IconInfo("\uF146") }) // dial 1
|
||||
{
|
||||
Title = "anonymous command test",
|
||||
Subtitle = "Try pressing Ctrl+1 with me selected",
|
||||
Icon = new IconInfo("\uE712"), // "More" dots
|
||||
MoreCommands = [
|
||||
new CommandContextItem(
|
||||
new ToastCommand("Secondary command invoked", MessageState.Warning) { Name = "Secondary command", Icon = new IconInfo("\uF147") }) // dial 2
|
||||
{
|
||||
Title = "I'm a second command",
|
||||
RequestedShortcut = KeyChordHelpers.FromModifiers(ctrl: true, vkey: VirtualKey.Number1),
|
||||
},
|
||||
new CommandContextItem("nested...")
|
||||
{
|
||||
Title = "We can go deeper...",
|
||||
Icon = new IconInfo("\uF148"),
|
||||
RequestedShortcut = KeyChordHelpers.FromModifiers(ctrl: true, vkey: VirtualKey.Number2),
|
||||
MoreCommands = [
|
||||
new CommandContextItem(
|
||||
new ToastCommand("Nested A invoked") { Name = "Do it", Icon = new IconInfo("A") })
|
||||
{
|
||||
Title = "Nested A",
|
||||
RequestedShortcut = KeyChordHelpers.FromModifiers(alt: true, vkey: VirtualKey.A),
|
||||
},
|
||||
|
||||
new CommandContextItem(
|
||||
new ToastCommand("Nested B invoked") { Name = "Do it", Icon = new IconInfo("B") })
|
||||
{
|
||||
Title = "Nested B...",
|
||||
RequestedShortcut = KeyChordHelpers.FromModifiers(ctrl: true, vkey: VirtualKey.B),
|
||||
MoreCommands = [
|
||||
new CommandContextItem(
|
||||
new ToastCommand("Nested C invoked") { Name = "Do it" })
|
||||
{
|
||||
Title = "You get it",
|
||||
RequestedShortcut = KeyChordHelpers.FromModifiers(ctrl: true, vkey: VirtualKey.B),
|
||||
}
|
||||
],
|
||||
},
|
||||
],
|
||||
}
|
||||
],
|
||||
},
|
||||
new ListItem(
|
||||
new ToastCommand("Primary command invoked", MessageState.Info) { Name = "Primary command", Icon = new IconInfo("\uF146") }) // dial 1
|
||||
{
|
||||
Title = "noop command test",
|
||||
Subtitle = "Try pressing Ctrl+1 with me selected",
|
||||
Icon = new IconInfo("\uE712"), // "More" dots
|
||||
MoreCommands = [
|
||||
new CommandContextItem(
|
||||
new ToastCommand("Secondary command invoked", MessageState.Warning) { Name = "Secondary command", Icon = new IconInfo("\uF147") }) // dial 2
|
||||
{
|
||||
Title = "I'm a second command",
|
||||
RequestedShortcut = KeyChordHelpers.FromModifiers(ctrl: true, vkey: VirtualKey.Number1),
|
||||
},
|
||||
new CommandContextItem(new NoOpCommand())
|
||||
{
|
||||
Title = "We can go deeper...",
|
||||
Icon = new IconInfo("\uF148"),
|
||||
RequestedShortcut = KeyChordHelpers.FromModifiers(ctrl: true, vkey: VirtualKey.Number2),
|
||||
MoreCommands = [
|
||||
new CommandContextItem(
|
||||
new ToastCommand("Nested A invoked") { Name = "Do it", Icon = new IconInfo("A") })
|
||||
{
|
||||
Title = "Nested A",
|
||||
RequestedShortcut = KeyChordHelpers.FromModifiers(alt: true, vkey: VirtualKey.A),
|
||||
},
|
||||
|
||||
new CommandContextItem(
|
||||
new ToastCommand("Nested B invoked") { Name = "Do it", Icon = new IconInfo("B") })
|
||||
{
|
||||
Title = "Nested B...",
|
||||
RequestedShortcut = KeyChordHelpers.FromModifiers(ctrl: true, vkey: VirtualKey.B),
|
||||
MoreCommands = [
|
||||
new CommandContextItem(
|
||||
new ToastCommand("Nested C invoked") { Name = "Do it" })
|
||||
{
|
||||
Title = "You get it",
|
||||
RequestedShortcut = KeyChordHelpers.FromModifiers(ctrl: true, vkey: VirtualKey.B),
|
||||
}
|
||||
],
|
||||
},
|
||||
],
|
||||
}
|
||||
],
|
||||
},
|
||||
new ListItem(
|
||||
new ToastCommand("Primary command invoked", MessageState.Info) { Name = "Primary command", Icon = new IconInfo("\uF146") }) // dial 1
|
||||
{
|
||||
Title = "noop secondary command test",
|
||||
Subtitle = "Try pressing Ctrl+1 with me selected",
|
||||
Icon = new IconInfo("\uE712"), // "More" dots
|
||||
MoreCommands = [
|
||||
new CommandContextItem(new NoOpCommand())
|
||||
{
|
||||
Title = "We can go deeper...",
|
||||
Icon = new IconInfo("\uF148"),
|
||||
RequestedShortcut = KeyChordHelpers.FromModifiers(ctrl: true, vkey: VirtualKey.Number2),
|
||||
MoreCommands = [
|
||||
new CommandContextItem(
|
||||
new ToastCommand("Nested A invoked") { Name = "Do it", Icon = new IconInfo("A") })
|
||||
{
|
||||
Title = "Nested A",
|
||||
RequestedShortcut = KeyChordHelpers.FromModifiers(alt: true, vkey: VirtualKey.A),
|
||||
},
|
||||
|
||||
new CommandContextItem(
|
||||
new ToastCommand("Nested B invoked") { Name = "Do it", Icon = new IconInfo("B") })
|
||||
{
|
||||
Title = "Nested B...",
|
||||
RequestedShortcut = KeyChordHelpers.FromModifiers(ctrl: true, vkey: VirtualKey.B),
|
||||
MoreCommands = [
|
||||
new CommandContextItem(
|
||||
new ToastCommand("Nested C invoked") { Name = "Do it" })
|
||||
{
|
||||
Title = "You get it",
|
||||
RequestedShortcut = KeyChordHelpers.FromModifiers(ctrl: true, vkey: VirtualKey.B),
|
||||
}
|
||||
],
|
||||
},
|
||||
],
|
||||
}
|
||||
],
|
||||
},
|
||||
|
||||
];
|
||||
|
||||
public EvilSamplesPage()
|
||||
|
||||
Reference in New Issue
Block a user