046de9db4d
On phones the chat's More menu, chat list rows and Files entries open a Material bottom sheet headed by the chat or file, with full-width icon rows and destructive actions last in the error colour; desktop menus show icons, a minimum width and destructive actions after a divider. The chat menu drops Run command and Open chats, keeps a single terminal entry and lists Close pane last.
155 lines
5.5 KiB
Dart
155 lines
5.5 KiB
Dart
part of 'screen.dart';
|
|
|
|
/// The move choices in the pane menu's order, with their pane label.
|
|
const _paneMoveChoices = [
|
|
(direction: ChatPaneDirection.up, action: SessionPaneAction.moveUp),
|
|
(direction: ChatPaneDirection.down, action: SessionPaneAction.moveDown),
|
|
(direction: ChatPaneDirection.left, action: SessionPaneAction.moveLeft),
|
|
(direction: ChatPaneDirection.right, action: SessionPaneAction.moveRight),
|
|
];
|
|
|
|
String _paneMoveLabel(ChatPaneDirection direction) => switch (direction) {
|
|
ChatPaneDirection.up => 'Move up',
|
|
ChatPaneDirection.down => 'Move down',
|
|
ChatPaneDirection.left => 'Move left',
|
|
ChatPaneDirection.right => 'Move right',
|
|
};
|
|
|
|
/// The chat list's row menu reaches the open panes' More choices. Each choice
|
|
/// is offered with the pane's own label and visibility, and runs the pane's
|
|
/// own handler for the row's chat, which is opened first.
|
|
mixin _ChatScreenPaneMenu on State<ChatScreen>, _ChatScreenWorkspace
|
|
implements SessionPaneMenu {
|
|
@override
|
|
ChatPaneCommands get _paneCommands;
|
|
void _openBySelection(JsonMap session);
|
|
|
|
/// The open pane showing [id]'s chat, or null when it is not open.
|
|
ChatWorkspacePane? _paneShowing(String id) {
|
|
for (final pane in _workspace.panes) {
|
|
if (pane.sessionId == id) return pane;
|
|
}
|
|
return null;
|
|
}
|
|
|
|
@override
|
|
List<SessionPaneChoice> choicesFor(BuildContext context, JsonMap session) {
|
|
final id = '${session['id'] ?? ''}';
|
|
final panes = _workspace.paneCount;
|
|
final tiled = panes > 1;
|
|
final pane = _paneShowing(id);
|
|
// Moves exist only while the panes are tiled (the pane's own rule); the
|
|
// targets are absent otherwise.
|
|
final moves = pane == null ? null : _paneMoveTargets[pane.id];
|
|
final directory = '${session['directory'] ?? ''}'.trim();
|
|
return [
|
|
(
|
|
action: SessionPaneAction.addPane,
|
|
label: 'Add chat pane',
|
|
enabled: true,
|
|
),
|
|
if (tiled && showsListBesideDetail(context))
|
|
(
|
|
action: SessionPaneAction.centerStage,
|
|
label: chatCenterStageLabel(ChatCenterStageController.instance),
|
|
enabled: true,
|
|
),
|
|
if (moves != null)
|
|
for (final move in _paneMoveChoices)
|
|
(
|
|
action: move.action,
|
|
label:
|
|
'${_paneMoveLabel(move.direction)} '
|
|
'(${chatPaneMoveShortcutLabel(move.direction)})',
|
|
enabled: moves[move.direction] != null,
|
|
),
|
|
if (WindowScope.maybeOf(context) != null)
|
|
(
|
|
action: SessionPaneAction.chatDetails,
|
|
label: 'Chat details',
|
|
enabled: true,
|
|
),
|
|
(action: SessionPaneAction.files, label: 'Files', enabled: true),
|
|
if (_paneCommands.hasFinished(id))
|
|
(
|
|
action: SessionPaneAction.dismissFinished,
|
|
label: chatShellDismissAllLabel,
|
|
enabled: true,
|
|
),
|
|
if (TerminalScope.maybeOf(context) != null && directory.isNotEmpty)
|
|
(
|
|
action: SessionPaneAction.openTerminal,
|
|
label: terminalOpenActionLabel,
|
|
enabled: true,
|
|
),
|
|
// Closing comes last.
|
|
if (pane != null && tiled)
|
|
(
|
|
action: SessionPaneAction.closePane,
|
|
label: 'Close pane',
|
|
enabled: true,
|
|
),
|
|
];
|
|
}
|
|
|
|
@override
|
|
void run(BuildContext context, JsonMap session, SessionPaneAction action) {
|
|
final id = '${session['id'] ?? ''}';
|
|
if (id.isEmpty) return;
|
|
switch (action) {
|
|
case SessionPaneAction.addPane:
|
|
_openBySelection(session);
|
|
_addPane(context);
|
|
case SessionPaneAction.openChats:
|
|
_openBySelection(session);
|
|
_pickPane(context);
|
|
case SessionPaneAction.centerStage:
|
|
_openBySelection(session);
|
|
ChatCenterStageController.instance.toggle();
|
|
case SessionPaneAction.moveUp:
|
|
_moveRowPane(session, ChatPaneDirection.up);
|
|
case SessionPaneAction.moveDown:
|
|
_moveRowPane(session, ChatPaneDirection.down);
|
|
case SessionPaneAction.moveLeft:
|
|
_moveRowPane(session, ChatPaneDirection.left);
|
|
case SessionPaneAction.moveRight:
|
|
_moveRowPane(session, ChatPaneDirection.right);
|
|
case SessionPaneAction.closePane:
|
|
for (final pane
|
|
in _workspace.panes
|
|
.where((pane) => pane.sessionId == id)
|
|
.toList()) {
|
|
_closePane(pane.id);
|
|
}
|
|
case SessionPaneAction.chatDetails:
|
|
_requestInOpenChat(session, ChatPaneCommand.details);
|
|
case SessionPaneAction.files:
|
|
_requestInOpenChat(session, ChatPaneCommand.files);
|
|
case SessionPaneAction.runCommand:
|
|
_requestInOpenChat(session, ChatPaneCommand.runCommand);
|
|
case SessionPaneAction.openTerminal:
|
|
_requestInOpenChat(session, ChatPaneCommand.openTerminal);
|
|
case SessionPaneAction.dismissFinished:
|
|
_requestInOpenChat(session, ChatPaneCommand.dismissFinished);
|
|
}
|
|
}
|
|
|
|
/// Swaps the pane showing [session]'s chat with its neighbour across
|
|
/// [direction], as that pane's own move does. The chat is already open here,
|
|
/// so nothing is opened first.
|
|
void _moveRowPane(JsonMap session, ChatPaneDirection direction) {
|
|
final pane = _paneShowing('${session['id'] ?? ''}');
|
|
if (pane == null) return;
|
|
final target = _paneMoveTargets[pane.id]?[direction];
|
|
if (target == null) return;
|
|
_movePane(pane.id, target);
|
|
}
|
|
|
|
/// Opens [session] and hands [command] to its conversation, which runs it
|
|
/// once built.
|
|
void _requestInOpenChat(JsonMap session, ChatPaneCommand command) {
|
|
_openBySelection(session);
|
|
_paneCommands.request('${session['id'] ?? ''}', command);
|
|
}
|
|
}
|