mirror of
https://github.com/microsoft/PowerToys.git
synced 2026-04-07 03:36:44 +02:00
Context menu cleanup (#40584)
Addressing items in #40583 - [x] When navigating the context menu with the up/down keys, separators should not be selectable. - [x] [For context items with a super long title, we need to trim those with an ellipsis. Ideally, we'd show a tooltip for just those items.](https://github.com/microsoft/PowerToys/issues/40313) - [x] [Context menu search bar text size doesn't update after changing system text size](https://github.com/microsoft/PowerToys/issues/39648) - [x] Weird "kick out" on first context menu item - [x] [Primary button doesn't work if the command has more items (fix regression)](https://github.com/microsoft/PowerToys/issues/40624) Example of long context menu item titles with tooltips: (@niels9001, look okay?) https://github.com/user-attachments/assets/fc0a4034-9c22-48ee-a3f0-44fcc2f294a6 closes #40624
This commit is contained in:
@@ -178,34 +178,97 @@ public sealed partial class ContextMenu : UserControl,
|
||||
{
|
||||
if (e.Key == VirtualKey.Up)
|
||||
{
|
||||
// navigate previous
|
||||
if (CommandsDropdown.SelectedIndex > 0)
|
||||
{
|
||||
CommandsDropdown.SelectedIndex--;
|
||||
}
|
||||
else
|
||||
{
|
||||
CommandsDropdown.SelectedIndex = CommandsDropdown.Items.Count - 1;
|
||||
}
|
||||
NavigateUp();
|
||||
|
||||
e.Handled = true;
|
||||
}
|
||||
else if (e.Key == VirtualKey.Down)
|
||||
{
|
||||
// navigate next
|
||||
if (CommandsDropdown.SelectedIndex < CommandsDropdown.Items.Count - 1)
|
||||
{
|
||||
CommandsDropdown.SelectedIndex++;
|
||||
}
|
||||
else
|
||||
{
|
||||
CommandsDropdown.SelectedIndex = 0;
|
||||
}
|
||||
NavigateDown();
|
||||
|
||||
e.Handled = true;
|
||||
}
|
||||
}
|
||||
|
||||
private void NavigateUp()
|
||||
{
|
||||
var newIndex = CommandsDropdown.SelectedIndex;
|
||||
|
||||
if (CommandsDropdown.SelectedIndex > 0)
|
||||
{
|
||||
newIndex--;
|
||||
|
||||
while (
|
||||
newIndex >= 0 &&
|
||||
IsSeparator(CommandsDropdown.Items[newIndex]) &&
|
||||
newIndex != CommandsDropdown.SelectedIndex)
|
||||
{
|
||||
newIndex--;
|
||||
}
|
||||
|
||||
if (newIndex < 0)
|
||||
{
|
||||
newIndex = CommandsDropdown.Items.Count - 1;
|
||||
|
||||
while (
|
||||
newIndex >= 0 &&
|
||||
IsSeparator(CommandsDropdown.Items[newIndex]) &&
|
||||
newIndex != CommandsDropdown.SelectedIndex)
|
||||
{
|
||||
newIndex--;
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
newIndex = CommandsDropdown.Items.Count - 1;
|
||||
}
|
||||
|
||||
CommandsDropdown.SelectedIndex = newIndex;
|
||||
}
|
||||
|
||||
private void NavigateDown()
|
||||
{
|
||||
var newIndex = CommandsDropdown.SelectedIndex;
|
||||
|
||||
if (CommandsDropdown.SelectedIndex == CommandsDropdown.Items.Count - 1)
|
||||
{
|
||||
newIndex = 0;
|
||||
}
|
||||
else
|
||||
{
|
||||
newIndex++;
|
||||
|
||||
while (
|
||||
newIndex < CommandsDropdown.Items.Count &&
|
||||
IsSeparator(CommandsDropdown.Items[newIndex]) &&
|
||||
newIndex != CommandsDropdown.SelectedIndex)
|
||||
{
|
||||
newIndex++;
|
||||
}
|
||||
|
||||
if (newIndex >= CommandsDropdown.Items.Count)
|
||||
{
|
||||
newIndex = 0;
|
||||
|
||||
while (
|
||||
newIndex < CommandsDropdown.Items.Count &&
|
||||
IsSeparator(CommandsDropdown.Items[newIndex]) &&
|
||||
newIndex != CommandsDropdown.SelectedIndex)
|
||||
{
|
||||
newIndex++;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
CommandsDropdown.SelectedIndex = newIndex;
|
||||
}
|
||||
|
||||
private bool IsSeparator(object item)
|
||||
{
|
||||
return item is SeparatorContextItemViewModel;
|
||||
}
|
||||
|
||||
private void UpdateUiForStackChange()
|
||||
{
|
||||
ContextFilterBox.Text = string.Empty;
|
||||
|
||||
Reference in New Issue
Block a user