This document specifies a cohesive menu system v1 integrated with the unified Command model.
It covers:
MenuBar (top-level menus)Command and CommandPresentationRelated specs:
Command.MenuBar remains a control, but menu structures should be definable in a simple, fluent way.Shift+F10 if terminal sends it)Command.CanExecute / Command.IsVisible.Existing code:
Controls/MenuBar.cs implements a full interactive menu bar and popup submenus.Controls/MenuItem.cs is a data object with:
Header (Visual)Icon, Shortcut, ActionItemsWhat is missing:
MenuItem and Command.CommandMenuItem should be able to reference a Command directly:
public sealed partial class MenuItem
{
[Bindable] public partial Command? Command { get; set; }
}
Rules when Command is set:
IsEnabled becomes derived by default:
Command.CanExecuteFor(target) (target is resolved by menu host)Action becomes derived by default:
Command.Execute(target)Shortcut is derived by default:
Command.Sequence?.ToString() ?? Command.Gesture?.ToString()The existing explicit properties should still exist for advanced cases, but Command should be the “happy path”.
Menu execution needs a target visual.
Rules:
MenuBar, default target is TerminalApp.FocusedElement ?? root.TerminalApp.HoveredElement at open time.The target is passed to:
Command.IsVisibleFor(target)Command.CanExecuteFor(target)Command.Execute(target)MenuItemThe menu API should be easy to author without manual list management.
Examples:
var file = new MenuItem("File")
.Items(
new MenuItem("Open", openCommand),
MenuItem.Separator(),
new MenuItem("Exit", exitCommand));
In practice, MenuItem should offer:
MenuItem(string header, Command? command = null)MenuItem(Visual header, Command? command = null)Separator() factory.Items(params MenuItem[] items) generated by [Bindable] list fluent supportMenuBar.Items should remain a BindableList<MenuItem>.
MenuBar should not attempt to auto-build its structure from commands. Menu structure is explicit.
However, MenuBar can still provide helper integration:
Command by defaultIntroduce a ContextMenu control (or MenuPopup) that renders a list of MenuItem values using the same visual
building logic as menu submenus.
Introduce a lightweight host service:
public static class ContextMenuService
{
public static void Show(Visual target, IEnumerable<MenuItem> items);
public static void Close();
}
Notes:
Popup/Dialog/WindowLayer as the existing menus do.To leverage the unified command system, allow “default context menu” generation:
HoveredElement → Parent + globalCommandPresentation.ContextMenuMenuItem backed by that CommandThis makes it trivial for controls to contribute context actions:
TextArea contributes Find/Replace/Undo/RedoLogControl contributes Find, Copy selection, Clear, etc.Provide a ContextMenuFactory hook on Visual:
public abstract partial class Visual
{
public Func<Visual, IEnumerable<MenuItem>>? ContextMenuFactory { get; set; }
}
Rules:
ContextMenuFactory is set on a visual, it is used as the primary sourceCommandPresentation.ContextMenu)This allows both:
Keep the existing behavior as baseline:
TerminalMouseButton.Right (or equivalent)While a menu is open, it should capture key events so that:
Existing styles:
MenuBarStyle, MenuListStyle, etc.Add or refine:
ContextMenuStyle (or reuse menu list style + popup template factory)GroupStyle, BorderStyle, etc.)ControlsDemo:
MenuBar demo driven by Command instancesTextArea and LogControlIsEnabled follows CanExecuteCommandQuery helper (shared with command palette).MenuItem.Command and derivation logic for enable/execute/shortcut.ContextMenu control and ContextMenuService.CommandPresentation.ContextMenu.