use crate::actions::{assign_enabled, close_enabled, unclaim_enabled};
use crate::projects::join::JoinState;
#[derive(Debug, Clone, PartialEq, Eq)]
pub enum Verb {
DeleteWorkspace,
Unpin,
Stop { children: bool },
Flush,
DeleteAgent,
Assign(String),
Release,
CloseBall,
}
#[derive(Debug, Clone, PartialEq, Eq)]
pub struct Entry {
pub label: String,
pub carrier: String,
pub verb: Verb,
}
#[derive(Debug, Clone, PartialEq, Eq)]
pub enum Seat {
WorkspaceTab { named: bool, pinned: bool },
ConversationRow {
stoppable: bool,
has_children: bool,
named: bool,
},
BallRow {
state: JoinState,
assign_to: Option<String>,
},
}
pub fn entries(seat: Seat) -> Vec<Entry> {
match seat {
Seat::WorkspaceTab { named, pinned } => workspace_tab(named, pinned),
Seat::ConversationRow {
stoppable,
has_children,
named,
} => conversation_row(stoppable, has_children, named),
Seat::BallRow { state, assign_to } => ball_row(state, assign_to),
}
}
fn workspace_tab(named: bool, pinned: bool) -> Vec<Entry> {
let mut out = Vec::new();
if named {
out.push(fires(
"delete this workspace…",
"config mode's per-workspace danger row",
Verb::DeleteWorkspace,
));
}
if pinned {
out.push(fires(
"unpin",
"the overflow menu's ★ toggle, lit while pinned",
Verb::Unpin,
));
}
out
}
fn conversation_row(stoppable: bool, has_children: bool, named: bool) -> Vec<Entry> {
let mut out = Vec::new();
if stoppable {
out.push(fires(
"stop",
"the composer's Stop button and the `x` key",
Verb::Stop { children: false },
));
if has_children {
out.push(fires(
"stop + children",
"the composer's Stop with its `children` checkbox",
Verb::Stop { children: true },
));
}
}
out.push(fires(
"flush the inbox",
"the Inbox tab's Scan button and the `f` key",
Verb::Flush,
));
if named {
out.push(fires(
"delete this conversation…",
"the inspector Config tab's per-conversation danger row",
Verb::DeleteAgent,
));
}
out
}
fn ball_row(state: JoinState, assign_to: Option<String>) -> Vec<Entry> {
let mut out = Vec::new();
if let Some(to) = assign_to.filter(|_| assign_enabled(state)) {
out.push(fires(
&format!("assign → {to}"),
"the ready ball row's `assign → <workspace>` button",
Verb::Assign(to),
));
}
if unclaim_enabled(state) {
out.push(fires(
"release",
"the composer's ball row Release button and the `r` key",
Verb::Release,
));
}
if close_enabled(state) {
out.push(fires(
"close",
"the composer's ball row Close button and the `c` key",
Verb::CloseBall,
));
}
out
}
fn fires(label: &str, carrier: &str, verb: Verb) -> Entry {
Entry {
label: label.to_owned(),
carrier: carrier.to_owned(),
verb,
}
}
#[cfg(test)]
mod tests;