use super::{
CenterTab, Cli, ModelRow, ShellState, birth_scope, conversation_scope, lines, marks, pane,
refresh, roster_fault, row_names, select, settled, write,
};
use crate::AppModel;
use crate::git_tree::CommitNode;
use crate::model_pick::{NEW_CONVERSATION_EXIT, Pick, row_role};
use std::path::Path;
pub(crate) fn conversation_seat(
ui: &mut egui::Ui,
model: &mut AppModel,
state: &mut ShellState,
ws: &Path,
tip_oid: &str,
config_tip: Option<&CommitNode>,
clis: (&Cli, &Cli, &Cli),
) -> bool {
let Some((frozen_oid, row)) =
lines::conversation_row_of(ws, tip_oid, config_tip, &mut state.wall.picker)
else {
return false;
};
let scope = conversation_scope(ws, &frozen_oid);
seat(ui, model, state, ws, &row, &scope, clis)
}
pub(crate) fn birth_seat(
ui: &mut egui::Ui,
model: &mut AppModel,
state: &mut ShellState,
ws: &Path,
config_tip: Option<&CommitNode>,
clis: (&Cli, &Cli, &Cli),
) -> bool {
let Some(row) = lines::birth_row_of(ws, config_tip, &mut state.wall.picker) else {
return false;
};
let scope = birth_scope(ws);
seat(ui, model, state, ws, &row, &scope, clis);
true
}
fn seat(
ui: &mut egui::Ui,
model: &mut AppModel,
state: &mut ShellState,
ws: &Path,
row: &ModelRow,
scope: &str,
clis: (&Cli, &Cli, &Cli),
) -> bool {
let (bz, lernie_cli, bl) = clis;
let role = row_role(state.wall.picker.role.as_deref());
let rows = marks::provider_rows(&mut state.wall.picker);
let view = settled(&mut state.wall.picker);
let models = view.as_ref().map(|v| v.models.clone()).unwrap_or_default();
let choice = select::pair_row(
ui,
&mut state.wall.picker,
row,
&row_names(&rows),
&models,
view.is_none(),
);
if choice.list_open {
refresh(&mut state.wall.picker, &choice.provider, bz);
}
let mut route = choice.add_provider.then_some(CenterTab::Config);
if let Some(view) = &view {
route = route.or(roster_fault(
ui,
view,
rows.iter().find(|r| r.name == choice.provider),
));
}
if let Some(chosen) = choice.chosen {
let pick = Pick {
role: role.clone(),
provider: choice.provider,
model: chosen,
};
write::apply(&mut state.wall.picker, model, ws, (lernie_cli, bl), &pick);
}
if !state.wall.picker.status.is_empty() {
ui.label(&state.wall.picker.status);
}
let exit = drift_exit(ui, row);
route = route.or(pane(ui, &mut state.wall.picker, ws, scope, &role));
if let Some(tab) = route {
state.wall.picker.toggle();
crate::shell::center::focus(model, state, tab);
}
exit
}
fn drift_exit(ui: &mut egui::Ui, row: &ModelRow) -> bool {
let Some(clause) = &row.drift else {
return false;
};
ui.horizontal(|ui| {
ui.weak(clause).on_hover_text(&row.hover);
ui.button(NEW_CONVERSATION_EXIT)
.on_hover_text(
"Clear the selection and put the cursor in the composer, so the \
next thing you send starts a conversation on the config this \
workspace has now. This one cannot move off the commit it \
started from (n).",
)
.clicked()
})
.inner
}