use crate::AppModel;
use crate::cli_outbound::Cli;
use crate::theme;
use super::ShellState;
#[derive(Default)]
pub struct NewWsState {
pub open: bool,
pub typed: String,
}
pub(super) fn open(state: &mut ShellState) {
state.new_ws = NewWsState {
open: true,
typed: String::new(),
};
}
pub(super) fn dialog(
ctx: &egui::Context,
model: &mut AppModel,
state: &mut ShellState,
lernie: &Cli,
bl: &Cli,
) {
if !state.new_ws.open {
return;
}
let mut shown = true;
egui::Window::new("new workspace")
.collapsible(false)
.resizable(false)
.open(&mut shown)
.show(ctx, |ui| body(ui, model, state, lernie, bl));
if !shown {
super::modal::dismiss(state);
}
}
fn body(ui: &mut egui::Ui, model: &mut AppModel, state: &mut ShellState, lernie: &Cli, bl: &Cli) {
ui.label("name this sphere — a client, an employer, personal vs. work:");
let edit = ui
.add(
egui::TextEdit::singleline(&mut state.new_ws.typed)
.desired_width(220.0)
.hint_text("ops"),
)
.on_hover_text(
"The name for this sphere of work. It must not be empty and must not \
collide with a workspace you already have; the reason appears here if \
it is refused. The form itself opens on (w) / Ctrl+Shift+N, and Enter \
submits it.",
);
let verdict = model.validate_workspace_name(&state.new_ws.typed);
let entered = edit.lost_focus() && ui.input(|i| i.key_pressed(egui::Key::Enter));
let submitted = entered && verdict.is_ok();
if !submitted && ui.memory(|m| m.focused().is_none()) {
edit.request_focus();
}
if let Err(e) = &verdict
&& !crate::names::normalize(&state.new_ws.typed).is_empty()
{
ui.colored_label(theme::ICHOR, e.to_string());
}
let clicked = ui
.add_enabled(verdict.is_ok(), egui::Button::new("Create workspace"))
.on_hover_text(
"Raise the wall and focus it: a separate world of conversations, config \
and claimed balls that touches nothing in your other workspaces. Enter \
does the same from the name box; Escape drops the form.",
)
.on_disabled_hover_text("the name above is empty or already taken")
.clicked();
if let Ok(name) = verdict
&& (clicked || submitted)
{
let inputs = model.new_workspace_inputs(&name);
state.new_ws = NewWsState::default();
super::start_pane::run_prepare(model, state, lernie, bl, inputs);
}
}