import AppKit import ParcelConfig /// The panel and native menu share validated actions and the workspace captured when opened. @MainActor struct MenuPanelContent { let snapshot: LayoutSnapshot let scope: String let items: [NSMenuItem] let dismiss: @MainActor () -> Void var status: String { item("menu.status")?.title ?? snapshot.accessibilityDescription } var canArrange: Bool { item("menu.quick-controls") != nil } var layoutItems: [NSMenuItem] { item("menu.layout")?.submenu?.items ?? [] } var countItems: [NSMenuItem] { item("menu.windows")?.submenu?.items ?? [] } var countWarning: String? { countItems.first { $0.state == .on && !$0.isEnabled }?.toolTip } var quickActions: [CommandMenuItem] { [ConfigCommand.retile, .toggleBorders, .toggleHoverFocus].compactMap(command) } var modeToggles: [CommandMenuItem] { [ConfigCommand.toggleFocus, .toggleNoPeek, .toggleCleanSpace].compactMap(command) } func item(_ identifier: String) -> NSMenuItem? { items.first { $0.identifier?.rawValue == identifier } } func command(_ command: ConfigCommand) -> CommandMenuItem? { (items + layoutItems + countItems).compactMap { $0 as? CommandMenuItem }.first { $0.command == command } } func perform(_ item: NSMenuItem) { guard item.isEnabled, let action = item.action else { return } let target = item.target dismiss() NSApp.sendAction(action, to: target, from: item) } }