use crate::reply::convs::ConvRow;
const STOP: &str = crate::verbs::STOP.word;
use crate::ui::slash::DELETE;
const FLAG: &str = crate::verbs::FLAG.word;
const RETARGET: &str = crate::verbs::RETARGET.word;
use crate::ui::{Aim, Fill, Model, theme};
pub const RECORDS_HELP: &str = "opens this conversation's own records: its steps, files and mail";
fn help_of(op: &str) -> &'static str {
match op {
o if o == crate::verbs::STOP.word => "stops this conversation where it stands",
o if o == crate::verbs::RETARGET.word => "points this conversation at another directory",
_ => "marks the ask seen; the call stays parked",
}
}
fn fill_help(fill: Fill) -> &'static str {
match fill {
Fill::Reason => "puts the box in flag mode: the words typed are the reason",
_ => "puts the box in delete mode: the conversation's own name arms it",
}
}
pub fn leads_to(word: &str) -> String {
format!("{word}…")
}
type Door = fn(String, String) -> serde_json::Value;
fn straight(row: &ConvRow) -> Vec<(&'static str, &'static str, Door)> {
let mut out: Vec<(&'static str, &'static str, Door)> = vec![
(STOP, crate::verbs::STOP.word, |workspace, agent| {
crate::verbs::stop(workspace, agent, false)
}),
(
RETARGET,
crate::verbs::RETARGET.word,
crate::verbs::retarget,
),
];
if row.attention > 0 {
out.push((
crate::ui::queue::SEEN,
crate::verbs::SEEN.word,
crate::verbs::seen,
));
}
out
}
pub fn show(response: &egui::Response, model: &mut Model, aim: &Aim, row: &ConvRow) {
response.context_menu(|ui| {
let mut chose = false;
for (word, op, door) in straight(row) {
let item = theme::paint::button(ui, word, true, help_of(op));
crate::ui::act::tag(&item, &[op]);
if item.clicked() {
model.outbox.push(crate::ui::Posted::act(door(
aim.address.clone(),
row.root_id.clone(),
)));
chose = true;
}
}
ui.separator();
let keeping = model.kept().contains(&row.root_id);
let (word, help) = if keeping {
(super::UNKEEP, super::UNKEEP_HELP)
} else {
(super::KEEP, super::KEEP_HELP)
};
if theme::paint::button(ui, word, true, help).clicked() {
model.toggle_kept(&row.root_id);
chose = true;
}
let records =
theme::paint::button(ui, &leads_to(crate::ui::records::WORD), true, RECORDS_HELP);
crate::ui::act::tag(
&records,
&[crate::verbs::STEPS.word, crate::verbs::FILES.word],
);
if records.clicked() {
model.select(&row.root_id);
model.begin_records();
chose = true;
}
for (word, fill) in [(FLAG, Fill::Reason), (DELETE, Fill::Arming)] {
if theme::paint::button(ui, &leads_to(word), true, fill_help(fill)).clicked() {
model.fill_in(&row.root_id, fill);
chose = true;
}
}
if chose {
ui.close_menu();
}
});
}
#[cfg(test)]
mod tests;