Files
pipelines/app/lib/shell/windows/windows_menu_button.dart
T
alan ef1c120f57 Add the Windows menu, window cycling, edge snapping and size per kind
Phase 4 of docs/plans/floating-windows.md. A bar button lists the app's
windows on every tab (show one, Show all, Minimise all, Close all). Alt+`
and Alt+Shift+` bring the next or previous window to the front. Dropping a
title at the left or right edge fills that half, at the top it maximises.
A new window of a kind opens at the size that kind was last given.
2026-11-11 00:05:16 +00:00

92 lines
3.3 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;
@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),
),
);
},
);
}