import 'package:flutter/foundation.dart'; import 'package:flutter/material.dart'; import 'detached_route.dart'; /// The action that hands a detached item back to the main window. const detachedBringBackLabel = 'Bring back to main window'; /// What a detached window offers the item it shows. class DetachedWindowControls { const DetachedWindowControls({ required this.ready, required this.sync, required this.setTitle, required this.close, required this.bringBackItem, }); /// Whether the server has been reached, so the item can be read. final ValueListenable ready; /// Advances when the connection is replaced; open views re-subscribe. final ValueListenable sync; /// Names the window after the item (the browser or desktop title). final ValueChanged setTitle; /// Closes this window. final VoidCallback close; /// Gives the item back to the main window and closes this one. final void Function( DetachedKind kind, String id, List> files, int initialIndex, ) bringBackItem; void bringBack( DetachedKind kind, String id, { List> files = const [], int initialIndex = 0, }) => bringBackItem(kind, id, files, initialIndex); } /// Shown until the window's connection first succeeds. class DetachedConnecting extends StatelessWidget { const DetachedConnecting({super.key}); @override Widget build(BuildContext context) => Center( child: Text('Connecting…', style: Theme.of(context).textTheme.bodyMedium), ); } /// The "Bring back to main window" button of a window without a menu of its /// own (the terminal's tab strip, the diff's bar). class DetachedBringBackButton extends StatelessWidget { const DetachedBringBackButton({super.key, required this.onPressed}); final VoidCallback onPressed; @override Widget build(BuildContext context) => IconButton( key: const ValueKey('detached-bring-back'), tooltip: detachedBringBackLabel, onPressed: onPressed, icon: const Icon(Icons.login), ); }