Files
pipelines/app/lib/shell/windows/windows_menu_button.dart
T
alan 26bb583f10 Refine Settings destination shell integration
Keep Settings navigation independent while preserving shell actions and destination-specific state. Add the reviewed chat, run-entry, layout, and regression-test updates needed by the destination behavior.
2026-11-12 11:21:26 +00:00

97 lines
3.5 KiB
Dart

import 'package:flutter/material.dart';
import '../../ui/adaptive/app_menu_anchor.dart';
import 'window_manager.dart';
import 'window_shortcuts.dart';
/// The shell bar's Windows button, shown while the app has floating windows:
/// a menu listing each one (choosing it shows it and brings it to the
/// front), then Show all, Minimise all and Close all.
class WindowsMenuButton extends StatelessWidget {
const WindowsMenuButton({super.key, required this.manager});
final WindowManager manager;
/// Whether [manager] has a window to list: the shell bar keeps the button
/// out of its actions otherwise, so no empty action island is drawn.
static bool hasWindows(WindowManager manager) =>
manager.windows.any((w) => manager.kinds[w.kind] != null);
@override
Widget build(BuildContext context) => ListenableBuilder(
listenable: Listenable.merge([
manager,
for (final kind in manager.kinds.all) ?kind.changes,
]),
builder: (context, _) {
final windows = manager.windows
.where((w) => manager.kinds[w.kind] != null)
.toList()
.reversed
.toList();
if (windows.isEmpty) return const SizedBox.shrink();
final active = manager.active?.id;
return AppMenuAnchor(
menuChildren: [
for (final entry in windows)
MenuItemButton(
key: ValueKey('windows-menu-${entry.id}'),
leadingIcon: Icon(manager.kinds[entry.kind]!.icon),
trailingIcon: entry.id == active
? const Icon(Icons.check)
: !manager.isVisible(entry)
? const Icon(Icons.minimize)
: null,
onPressed: () => manager.show(entry.id),
child: ConstrainedBox(
constraints: const BoxConstraints(maxWidth: 280),
child: Text(
manager.kinds[entry.kind]!.title(context, entry),
maxLines: 1,
overflow: TextOverflow.ellipsis,
semanticsLabel:
'${manager.kinds[entry.kind]!.title(context, entry)}'
'${manager.isVisible(entry) ? '' : ', minimised'}',
),
),
),
const Divider(height: 8),
MenuItemButton(
leadingIcon: const Icon(Icons.open_in_full),
onPressed: windows.every(manager.isVisible)
? null
: manager.showAll,
child: const Text('Show all'),
),
MenuItemButton(
leadingIcon: const Icon(Icons.minimize),
onPressed: windows.any(manager.isVisible)
? manager.minimizeAll
: null,
child: const Text('Minimise all'),
),
MenuItemButton(
leadingIcon: const Icon(Icons.close),
onPressed: manager.closeAll,
child: const Text('Close all'),
),
if (windows.length > 1)
Padding(
padding: const EdgeInsets.fromLTRB(12, 8, 12, 4),
child: Text(
'Next window: ${windowCycleShortcutLabel()}',
style: Theme.of(context).textTheme.bodySmall,
),
),
],
builder: (context, menu, _) => IconButton(
key: const ValueKey('shell.windows'),
tooltip: 'Windows (${windows.length})',
onPressed: () => menu.isOpen ? menu.close() : menu.open(),
icon: const Icon(Icons.web_asset_outlined),
),
);
},
);
}