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:
@@ -4,6 +4,7 @@ import 'package:flutter/material.dart';
|
||||
import 'package:flutter/services.dart';
|
||||
|
||||
import '../../../core/api_gateway.dart';
|
||||
import '../../../shell/detached/detached_window_scope.dart';
|
||||
import '../../../shell/list_detail_policy.dart';
|
||||
import '../../../shell/windows/window_entry.dart';
|
||||
import '../../../shell/windows/window_kind.dart';
|
||||
@@ -25,6 +26,8 @@ class ChatTiling {
|
||||
required this.dock,
|
||||
required this.canFloatActive,
|
||||
required this.floatActive,
|
||||
this.release,
|
||||
this.activeSession,
|
||||
});
|
||||
|
||||
/// Whether the tiling shows [sessionId].
|
||||
@@ -36,6 +39,13 @@ class ChatTiling {
|
||||
/// Whether the chord can float the active pane now.
|
||||
final bool Function() canFloatActive;
|
||||
final VoidCallback floatActive;
|
||||
|
||||
/// Takes [sessionId]'s panes out of the tiling (it went to a window of
|
||||
/// its own).
|
||||
final void Function(String sessionId)? release;
|
||||
|
||||
/// The active pane's chat.
|
||||
final String? Function()? activeSession;
|
||||
}
|
||||
|
||||
/// The floating chat windows, for the app's lifetime: the `chat` window kind
|
||||
@@ -66,6 +76,10 @@ class ChatWindows {
|
||||
/// The mounted Chat destination's tiling, if it is built.
|
||||
ChatTiling? tiling;
|
||||
|
||||
/// Opens a chat in a window of its own (a browser window or app process);
|
||||
/// null where the platform has none.
|
||||
DetachedWindowOpener? detached;
|
||||
|
||||
late final ChatWindowKind kind = ChatWindowKind(this);
|
||||
bool _started = false;
|
||||
|
||||
@@ -86,7 +100,8 @@ class ChatWindows {
|
||||
manager.kinds.register(kind);
|
||||
FocusManager.instance
|
||||
..addEarlyKeyEventHandler(_key)
|
||||
..addEarlyKeyEventHandler(_tabKey);
|
||||
..addEarlyKeyEventHandler(_tabKey)
|
||||
..addEarlyKeyEventHandler(_detachKey);
|
||||
runtime.addSessionReplacedListener(_replacedElsewhere);
|
||||
runtime.sessions.addListener(_rowsChanged);
|
||||
manager.addListener(_rowsChanged);
|
||||
@@ -98,7 +113,8 @@ class ChatWindows {
|
||||
_started = false;
|
||||
FocusManager.instance
|
||||
..removeEarlyKeyEventHandler(_key)
|
||||
..removeEarlyKeyEventHandler(_tabKey);
|
||||
..removeEarlyKeyEventHandler(_tabKey)
|
||||
..removeEarlyKeyEventHandler(_detachKey);
|
||||
runtime.removeSessionReplacedListener(_replacedElsewhere);
|
||||
runtime.sessions.removeListener(_rowsChanged);
|
||||
manager.removeListener(_rowsChanged);
|
||||
@@ -154,6 +170,35 @@ class ChatWindows {
|
||||
}
|
||||
}
|
||||
|
||||
/// Opens [sessionId] in a window of its own. Once that window is open the
|
||||
/// chat leaves this one: its floating window closes and its tiled panes
|
||||
/// close, as Float takes a pane out of the tiling.
|
||||
void detach(String sessionId) {
|
||||
final opener = detached;
|
||||
if (opener == null || sessionId.isEmpty) return;
|
||||
opener.openChat(
|
||||
sessionId,
|
||||
title: runtime.titleFor(sessionId),
|
||||
onOpened: () {
|
||||
final entry = manager.find(chatWindowKind, sessionId);
|
||||
if (entry != null) manager.close(entry.id);
|
||||
tiling?.release?.call(sessionId);
|
||||
},
|
||||
);
|
||||
}
|
||||
|
||||
/// A detached window gave [sessionId] back: it goes into the tiling, or
|
||||
/// opens in the Chat destination when that is not built.
|
||||
void bringBack(String sessionId) {
|
||||
if (sessionId.isEmpty) return;
|
||||
final tiling = this.tiling;
|
||||
if (tiling != null) {
|
||||
tiling.dock(sessionId);
|
||||
} else {
|
||||
openInChat(sessionId);
|
||||
}
|
||||
}
|
||||
|
||||
/// `/new` in a window's chat: the window follows the new session, unless
|
||||
/// that session is already open elsewhere.
|
||||
void startedNewSession(
|
||||
@@ -242,6 +287,29 @@ class ChatWindows {
|
||||
return KeyEventResult.handled;
|
||||
}
|
||||
|
||||
/// Alt+Shift+Y sends the chat with the keyboard (a floating window's, else
|
||||
/// the active tiled pane's) to a new window. Left alone when there is no
|
||||
/// such chat or no platform window.
|
||||
KeyEventResult _detachKey(KeyEvent event) {
|
||||
if (detached == null ||
|
||||
!detachedWindowShortcut(event, HardwareKeyboard.instance)) {
|
||||
return KeyEventResult.ignored;
|
||||
}
|
||||
final scope = keyboardWindow();
|
||||
String? id;
|
||||
if (scope != null) {
|
||||
if (scope.entry.kind == chatWindowKind) id = scope.entry.contentId;
|
||||
} else {
|
||||
final tiling = this.tiling;
|
||||
if (tiling != null && tiling.canFloatActive()) {
|
||||
id = tiling.activeSession?.call();
|
||||
}
|
||||
}
|
||||
if (id == null || id.isEmpty) return KeyEventResult.ignored;
|
||||
if (event is KeyDownEvent) detach(id);
|
||||
return KeyEventResult.handled;
|
||||
}
|
||||
|
||||
/// Ctrl+Tab and Ctrl+Shift+Tab while a floating chat window holds the
|
||||
/// keyboard: the next (previous) shown chat window, in open order and
|
||||
/// wrapping, comes to the top. The window host then gives it the keyboard,
|
||||
@@ -350,6 +418,12 @@ class ChatWindowKind extends WindowKind {
|
||||
icon: Icons.vertical_split_outlined,
|
||||
onPressed: () => windows.dock(entry),
|
||||
),
|
||||
if (windows.detached != null)
|
||||
WindowAction(
|
||||
label: detachedChatWindowLabel(),
|
||||
icon: Icons.open_in_browser,
|
||||
onPressed: () => windows.detach(entry.contentId),
|
||||
),
|
||||
];
|
||||
|
||||
@override
|
||||
|
||||
Reference in New Issue
Block a user