add ClidePane primitive + focus-driven status-bar slot
Replace the MessageBus-based pane-context slot with a focus-driven one. Panes keep their status widget locally; the FocusTracker holds the focused pane's widget (activeStatusWidget) and ClidePane conveys it to the shared slot only while its contribution is focused, re-conveying on change and clearing on blur. The status-bar item just renders focus.activeStatusWidget, height-clamped and marquee-scrolled when it overflows. Removes the publish/subscribe race the bus version had. T-150. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
This commit is contained in:
@@ -1,74 +1,44 @@
|
||||
/// The status-bar "in-pane context" slot (T-145).
|
||||
///
|
||||
/// A generic, publisher-agnostic slot: a pane publishes a short status
|
||||
/// string to [paneContextChannel] on the MessageBus, and the bottom
|
||||
/// status bar shows the latest one. The active pane publishes (an
|
||||
/// inactive pane stays quiet), so switching tabs swaps the slot to the
|
||||
/// newly-active pane's message. The Claude pane is the first publisher
|
||||
/// (model · permission-mode · context); other panes can use the same
|
||||
/// channel.
|
||||
/// Status-bar item that shows the *focused* pane's status widget
|
||||
/// (T-150). The content comes from whichever pane is focused — each pane
|
||||
/// surfaces its own [ClidePane.statusWidget] via [FocusTracker], so this
|
||||
/// item is generic: it just renders `focus.activeStatusWidget`, clamped
|
||||
/// to a fixed height and marquee-scrolled when it overflows. Nothing
|
||||
/// (and no space) when no focused pane has a status — so it clears on
|
||||
/// focus change.
|
||||
library;
|
||||
|
||||
import 'dart:async';
|
||||
|
||||
import 'package:clide/kernel/kernel.dart';
|
||||
import 'package:clide/widgets/widgets.dart';
|
||||
import 'package:flutter/widgets.dart';
|
||||
|
||||
/// MessageBus channel for the status-bar context slot. Data: `{'text': String}`.
|
||||
const paneContextChannel = 'statusbar.context';
|
||||
/// Max width the slot occupies in the status bar before marquee kicks in.
|
||||
const double _slotMaxWidth = 360;
|
||||
|
||||
/// Publish [text] to the context slot (empty string clears it).
|
||||
void publishPaneContext(MessageBus messages, String publisher, String text) {
|
||||
messages.publish(publisher, paneContextChannel, {'text': text});
|
||||
}
|
||||
/// Fixed slot height — panes can render anything, but not blow up the bar.
|
||||
const double _slotHeight = 16;
|
||||
|
||||
/// Status-bar item that shows the latest pane-context message (nothing
|
||||
/// when empty). Subscribes to the bus itself via the ambient kernel.
|
||||
class PaneContextStatusItem extends StatefulWidget {
|
||||
class PaneContextStatusItem extends StatelessWidget {
|
||||
const PaneContextStatusItem({super.key});
|
||||
|
||||
@override
|
||||
State<PaneContextStatusItem> createState() => _PaneContextStatusItemState();
|
||||
}
|
||||
|
||||
class _PaneContextStatusItemState extends State<PaneContextStatusItem> {
|
||||
StreamSubscription<Message>? _sub;
|
||||
String _text = '';
|
||||
bool _subscribed = false;
|
||||
|
||||
@override
|
||||
void didChangeDependencies() {
|
||||
super.didChangeDependencies();
|
||||
if (_subscribed) return;
|
||||
_subscribed = true;
|
||||
final messages = ClideKernel.of(context).messages;
|
||||
_sub = messages.subscribe(channel: paneContextChannel).listen((m) {
|
||||
final t = (m.data['text'] as String?) ?? '';
|
||||
if (t == _text || !mounted) return;
|
||||
setState(() => _text = t);
|
||||
});
|
||||
}
|
||||
|
||||
@override
|
||||
void dispose() {
|
||||
_sub?.cancel();
|
||||
super.dispose();
|
||||
}
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
if (_text.isEmpty) return const SizedBox.shrink();
|
||||
final tokens = ClideTheme.of(context).surface;
|
||||
return Padding(
|
||||
padding: const EdgeInsets.symmetric(horizontal: 8),
|
||||
child: ClideText(
|
||||
_text,
|
||||
fontSize: clideFontSmall,
|
||||
fontFamily: clideMonoFamily,
|
||||
color: tokens.statusBarForeground,
|
||||
maxLines: 1,
|
||||
),
|
||||
final focus = ClideKernel.of(context).focus;
|
||||
return ListenableBuilder(
|
||||
listenable: focus,
|
||||
builder: (ctx, _) {
|
||||
final widget = focus.activeStatusWidget;
|
||||
if (widget == null) return const SizedBox.shrink();
|
||||
return Padding(
|
||||
padding: const EdgeInsets.symmetric(horizontal: 8),
|
||||
child: SizedBox(
|
||||
height: _slotHeight,
|
||||
child: ConstrainedBox(
|
||||
constraints: const BoxConstraints(maxWidth: _slotMaxWidth),
|
||||
child: ClideMarquee(child: widget),
|
||||
),
|
||||
),
|
||||
);
|
||||
},
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user