App: open a chat, the terminal or a diff in a new window
"Open in new window" sits beside Float: the chat pane and chat list row menus, a floating chat window's title bar, the terminal options menu and the diff bar, plus Alt+Shift+Y for the chat with the keyboard (listed in the shortcut help). Once the window opens the item leaves the main window as Float takes a pane out of the tiling. The window is its own app instance at /window/chat/<id>, /window/terminal?tab=<key> or /window/diff/<token>: only that item, named after it, with "Bring back to main window". It has its own connection and writes no shared layout (no open-chat workspace, window store or terminal layout) and posts no notifications, so they stay the main window's. Web opens a popup window (a blocked popup offers a tab); Linux and macOS start a second process with --detached (Flutter's multi-window API is still experimental); Android and iOS hide the action. The capture kit gains a follow step for windows a page opens. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
@@ -0,0 +1,107 @@
|
||||
import 'dart:async';
|
||||
import 'dart:convert';
|
||||
|
||||
import 'package:flutter/material.dart';
|
||||
|
||||
import '../../features/changes/domain/file_change.dart';
|
||||
import '../../features/changes/widgets/file_diff_page.dart';
|
||||
import 'detached_platform.dart';
|
||||
import 'detached_route.dart';
|
||||
import 'detached_window_body.dart';
|
||||
|
||||
/// The diff a window was handed: its files and the one it opened on.
|
||||
typedef DetachedDiffContent = ({List<FileChange> files, int index});
|
||||
|
||||
/// Reads the hand-over [json] (`{"files": [...], "index": n}`); null when it
|
||||
/// holds no file.
|
||||
DetachedDiffContent? decodeDetachedDiff(String? json) {
|
||||
if (json == null) return null;
|
||||
try {
|
||||
final value = jsonDecode(json);
|
||||
if (value is! Map) return null;
|
||||
final raw = value['files'];
|
||||
final files = [
|
||||
if (raw is List)
|
||||
for (final entry in raw) ?FileChange.fromHandover(entry),
|
||||
];
|
||||
if (files.isEmpty) return null;
|
||||
final index = value['index'];
|
||||
return (
|
||||
files: files,
|
||||
index: index is int ? index.clamp(0, files.length - 1) : 0,
|
||||
);
|
||||
} on FormatException {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
/// A diff alone in a detached window. Its files are in memory only, handed
|
||||
/// over through the platform (see [DetachedPlatform.take]); there is nothing
|
||||
/// to read from the server.
|
||||
class DetachedDiff extends StatefulWidget {
|
||||
const DetachedDiff({
|
||||
super.key,
|
||||
required this.token,
|
||||
required this.platform,
|
||||
required this.window,
|
||||
});
|
||||
|
||||
final String token;
|
||||
final DetachedPlatform platform;
|
||||
final DetachedWindowControls window;
|
||||
|
||||
@override
|
||||
State<DetachedDiff> createState() => _DetachedDiffState();
|
||||
}
|
||||
|
||||
class _DetachedDiffState extends State<DetachedDiff> {
|
||||
late final Future<DetachedDiffContent?> _content = widget.platform
|
||||
.take(widget.token)
|
||||
.then(decodeDetachedDiff);
|
||||
|
||||
@override
|
||||
void initState() {
|
||||
super.initState();
|
||||
unawaited(_content.then(_retitle));
|
||||
}
|
||||
|
||||
void _retitle(DetachedDiffContent? content) {
|
||||
final files = content?.files;
|
||||
widget.window.setTitle(switch (files) {
|
||||
null || [] => 'Diff',
|
||||
[final file] => file.path.split('/').last,
|
||||
_ => '${files.length} files changed',
|
||||
});
|
||||
}
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) => FutureBuilder<DetachedDiffContent?>(
|
||||
future: _content,
|
||||
builder: (context, snapshot) {
|
||||
if (snapshot.connectionState != ConnectionState.done) {
|
||||
return const Material(child: SizedBox.expand());
|
||||
}
|
||||
final content = snapshot.data;
|
||||
if (content == null) {
|
||||
return const Material(
|
||||
child: Center(child: Text('This diff is no longer available.')),
|
||||
);
|
||||
}
|
||||
return FileDiffPage(
|
||||
files: content.files,
|
||||
initialIndex: content.index,
|
||||
inWindow: true,
|
||||
actions: [
|
||||
DetachedBringBackButton(
|
||||
onPressed: () => widget.window.bringBack(
|
||||
DetachedKind.diff,
|
||||
widget.token,
|
||||
files: [for (final file in content.files) file.toJson()],
|
||||
initialIndex: content.index,
|
||||
),
|
||||
),
|
||||
],
|
||||
);
|
||||
},
|
||||
);
|
||||
}
|
||||
Reference in New Issue
Block a user