Files
pipelines/app/tool/capture/window_probe.dart
T
alan a99f7014f5 Add the shell window host with layering acceptance tests
Phase 1.3 and 1.4 of docs/plans/floating-windows.md. Windows are plain
children of the terminal stage's stack in the shell page, outside every
destination, so popups opened from one are above all of them. Each window
has its own page navigator: pushed pages open inside the window, and popup
routes go to the root navigator. One WindowFrame chrome (move, resize,
minimise, maximise, close), a focus scope per window, a ScaffoldMessenger
per window.

No feature uses it yet. The capture fixture opens probe windows with
?windows=N, and window_layering_test.dart covers every popup type from a
window over Chat and over another destination.
2026-11-10 20:48:31 +00:00

162 lines
4.8 KiB
Dart

import 'package:flutter/material.dart';
import 'package:pipelines_app/shell/windows/window_entry.dart';
import 'package:pipelines_app/shell/windows/window_kind.dart';
import 'package:pipelines_app/shell/windows/window_manager.dart';
/// A window kind for tests and for the capture fixture (`?windows=N` opens N
/// of them): every kind of popup and a pushed page, opened from inside a
/// window.
class ProbeWindowKind extends WindowKind {
final closed_ = <String>[];
@override
String get key => 'probe';
@override
bool get serverScoped => false;
@override
IconData get icon => Icons.science_outlined;
@override
Size get minSize => const Size(240, 160);
@override
Rect get defaultFrame => const Rect.fromLTWH(100, 80, 360, 420);
@override
String title(BuildContext context, WindowEntry entry) =>
'Probe ${entry.contentId}';
@override
Widget build(BuildContext context, WindowEntry entry) => ProbeContent(
key: ValueKey('content-${entry.contentId}'),
id: entry.contentId,
);
@override
List<WindowAction> actions(BuildContext context, WindowEntry entry) => [
WindowAction(label: 'Probe action', icon: Icons.star, onPressed: () {}),
];
@override
void closed(WindowEntry entry) => closed_.add(entry.id);
}
const probeTooltipColor = Color(0xFFFF00FF);
class ProbeContent extends StatefulWidget {
const ProbeContent({super.key, required this.id});
final String id;
@override
State<ProbeContent> createState() => ProbeContentState();
}
class ProbeContentState extends State<ProbeContent> {
final text = TextEditingController(text: 'select me');
final menu = MenuController();
int builds = 0;
String? picked;
@override
void dispose() {
text.dispose();
super.dispose();
}
Widget _button(String label, VoidCallback onPressed) => TextButton(
key: ValueKey('${widget.id}-$label'),
onPressed: onPressed,
child: Text(label),
);
@override
Widget build(BuildContext context) {
builds++;
final id = widget.id;
return ListView(
children: [
TextField(key: ValueKey('$id-field'), controller: text),
Tooltip(
message: 'Tip text',
decoration: const BoxDecoration(color: probeTooltipColor),
child: Icon(Icons.info, key: ValueKey('$id-tip')),
),
_button(
'sheet',
() => showModalBottomSheet<void>(
context: context,
builder: (sheet) => SizedBox(
height: 200,
child: TextButton(
onPressed: () => Navigator.of(sheet).pop(),
child: const Text('Sheet item'),
),
),
),
),
_button(
'dialog',
() => showDialog<void>(
context: context,
builder: (_) => const AlertDialog(title: Text('Dialog title')),
),
),
_button(
'page',
() => Navigator.of(context).push(
MaterialPageRoute<void>(
builder: (_) => Scaffold(
appBar: AppBar(title: Text('Page of $id')),
body: const Center(child: Text('Page body')),
),
),
),
),
_button(
'snack',
() => ScaffoldMessenger.of(
context,
).showSnackBar(const SnackBar(content: Text('Snack text'))),
),
MenuAnchor(
controller: menu,
useRootOverlay: true,
menuChildren: [
MenuItemButton(
onPressed: () => setState(() => picked = 'anchor'),
child: const Text('Anchor item'),
),
],
child: _button('anchor', menu.open),
),
PopupMenuButton<String>(
key: ValueKey('$id-popup'),
onSelected: (value) => setState(() => picked = value),
itemBuilder: (_) => const [
PopupMenuItem(value: 'popup', child: Text('Popup item')),
],
),
DropdownButton<String>(
key: ValueKey('$id-dropdown'),
value: 'one',
onChanged: (value) => setState(() => picked = value),
items: const [
DropdownMenuItem(value: 'one', child: Text('Drop one')),
DropdownMenuItem(value: 'two', child: Text('Drop two')),
],
),
Text('picked: $picked'),
],
);
}
}
WindowManager probeManager() =>
WindowManager(kinds: WindowKinds()..register(ProbeWindowKind()));
/// The capture fixture's windows: `?windows=N` opens N probe windows (not
/// saved); without the parameter the app keeps its own.
WindowManager? probeWindows(Map<String, String> params) {
final count = int.tryParse(params['windows'] ?? '');
if (count == null) return null;
final manager = probeManager();
for (var i = 0; i < count; i++) {
manager.open('probe', String.fromCharCode(0x61 + i));
}
return manager;
}