fdc730422d
Phase 2.3 and 2.4 of docs/plans/floating-windows.md. A floating chat is a window of the chat kind over the app's WindowManager, built from the app-lifetime ChatRuntime, so it shows over every destination and at start without the Chat destination being built. Float and Dock move the same keyed view between the tiling and the window host. The pipelines app keeps one runtime and one ChatWindows; saved chatFloat records (v1 and v2) are brought over once. ChatFloatHost, ChatFloatWindow, the float frames and binding, the controller's float list and FloatingFocusRoot are gone; the workspace only asks whether a chat is out in a window. Every MenuAnchor targets the root overlay (guarded by a test), and menus and tooltips name the Alt chords.
86 lines
2.6 KiB
Dart
86 lines
2.6 KiB
Dart
import 'package:flutter/widgets.dart';
|
|
|
|
import 'window_entry.dart';
|
|
|
|
/// One action in a window's title bar, before Minimise and Close (Dock on a
|
|
/// chat, a kind's own menu).
|
|
class WindowAction {
|
|
const WindowAction({
|
|
required this.label,
|
|
required this.icon,
|
|
required this.onPressed,
|
|
});
|
|
|
|
/// The tooltip and semantics label.
|
|
final String label;
|
|
final IconData icon;
|
|
final VoidCallback onPressed;
|
|
}
|
|
|
|
/// What a kind of window is: how its content is built, titled and saved.
|
|
/// Kinds register once at app start (see [WindowKinds]); the host and the
|
|
/// manager know nothing else about a window's content.
|
|
abstract class WindowKind {
|
|
const WindowKind();
|
|
|
|
/// Stable identifier, saved with each window.
|
|
String get key;
|
|
|
|
/// Whether this kind's windows belong to one server (a chat) rather than
|
|
/// the device (the terminal).
|
|
bool get serverScoped;
|
|
|
|
Size get minSize => const Size(320, 240);
|
|
|
|
/// The frame of this kind's first window; later ones cascade from it.
|
|
Rect get defaultFrame => const Rect.fromLTWH(120, 96, 480, 560);
|
|
|
|
IconData get icon;
|
|
|
|
String title(BuildContext context, WindowEntry entry);
|
|
|
|
/// The window's content, below the title bar.
|
|
Widget build(BuildContext context, WindowEntry entry);
|
|
|
|
/// Title-bar actions before Minimise and Close.
|
|
List<WindowAction> actions(BuildContext context, WindowEntry entry) =>
|
|
const [];
|
|
|
|
/// Notifies when a title or the actions of this kind's windows change.
|
|
Listenable? get changes => null;
|
|
|
|
/// The narrowest app this kind's windows show in; below it they hide (and
|
|
/// come back when the app widens).
|
|
double get minHostWidth => 0;
|
|
|
|
/// Puts the keyboard where [entry]'s content wants it (a chat's composer)
|
|
/// as its window takes focus. The default leaves it on the window.
|
|
void focusContent(WindowEntry entry) {}
|
|
|
|
/// Called after the user closes the window (the X).
|
|
void closed(WindowEntry entry) {}
|
|
|
|
/// Validates a saved window's [WindowEntry.data]; null drops the window.
|
|
/// The default keeps no state.
|
|
Map<String, Object?>? decodeData(Object? raw) => const {};
|
|
|
|
/// What is saved for [entry] besides its identity and frame.
|
|
Object? encodeData(WindowEntry entry) => null;
|
|
}
|
|
|
|
/// The registered window kinds, by key.
|
|
class WindowKinds {
|
|
final Map<String, WindowKind> _kinds = {};
|
|
|
|
void register(WindowKind kind) {
|
|
assert(!_kinds.containsKey(kind.key), 'window kind ${kind.key} twice');
|
|
_kinds[kind.key] = kind;
|
|
}
|
|
|
|
void unregister(String key) => _kinds.remove(key);
|
|
|
|
WindowKind? operator [](String key) => _kinds[key];
|
|
|
|
Iterable<WindowKind> get all => _kinds.values;
|
|
}
|