3ce7f7a5dd
Share the open chat pane menu choices with session rows so list actions use the same handlers and target the selected chat. Add command routing, pane movement support, and focused coverage for wide and narrow layouts.
48 lines
1.6 KiB
Dart
48 lines
1.6 KiB
Dart
import 'package:flutter/foundation.dart';
|
|
|
|
/// A pane menu action that lives in the conversation itself (its own state),
|
|
/// so a chat list choice asks the open conversation to run it.
|
|
enum ChatPaneCommand {
|
|
details,
|
|
files,
|
|
runCommand,
|
|
openTerminal,
|
|
dismissFinished,
|
|
}
|
|
|
|
/// Hands a chat list choice to the open conversation of one chat. The list
|
|
/// opens the chat first; its conversation takes the request once it is built
|
|
/// and runs the same handler its own More menu runs.
|
|
///
|
|
/// It also records which chats have finished command runs, so the list offers
|
|
/// Dismiss all finished commands where the pane would.
|
|
class ChatPaneCommands extends ChangeNotifier {
|
|
final List<(String, ChatPaneCommand)> _pending = [];
|
|
final Set<String> _finished = {};
|
|
|
|
/// Asks [sessionId]'s conversation to run [command].
|
|
void request(String sessionId, ChatPaneCommand command) {
|
|
_pending.add((sessionId, command));
|
|
notifyListeners();
|
|
}
|
|
|
|
/// Takes the oldest request for [sessionId], or null when there is none.
|
|
ChatPaneCommand? take(String sessionId) {
|
|
final index = _pending.indexWhere((entry) => entry.$1 == sessionId);
|
|
if (index < 0) return null;
|
|
return _pending.removeAt(index).$2;
|
|
}
|
|
|
|
/// Whether [sessionId]'s conversation holds finished command runs.
|
|
bool hasFinished(String sessionId) => _finished.contains(sessionId);
|
|
|
|
/// Called by a conversation as its finished runs change.
|
|
void setFinished(String sessionId, bool finished) {
|
|
if (finished) {
|
|
_finished.add(sessionId);
|
|
} else {
|
|
_finished.remove(sessionId);
|
|
}
|
|
}
|
|
}
|