use crate::AppModel;
use crate::config_edit::RealFileIo;
use crate::config_edit::branch::ConfigBranch;
use crate::config_edit::branch::edit::EditOrigin;
use crate::config_edit::brazen::row_names;
use crate::config_edit::lernie_global::{Editor, LernieGlobal};
use crate::shell::config_marks::{self, MarksPane};
use crate::xdg::Env;
use std::path::PathBuf;
mod branch_pane;
pub(crate) mod brazen_pane;
mod form_ui;
mod lernie_pane;
mod send;
mod status;
mod yog_pane;
pub(crate) use brazen_pane::BrazenPane;
const RELOAD_HINT: &str = "Throw away the edits in this box and re-read the file from disk. Nothing \
is written. Reachable by Tab, pressed with Space; `/config <destination>` with no \
text reads the same bytes.";
const NEW_WORKFLOW_HINT: &str = "Name for a new `workflows/<name>.yaml`. Create opens an empty editor for \
it; the file itself appears only when you Apply. Typed, it is \
`/config workflow <name> <text…>`.";
pub struct ConfigState {
io: RealFileIo,
lernie: LernieGlobal,
lernie_editor: Editor,
lernie_status: String,
cadence_editor: Editor,
cadence_status: String,
workflows: Vec<PathBuf>,
new_workflow: String,
new_model: String,
branches: Vec<ConfigBranch>,
cb_files: Vec<String>,
cb_name: String,
cb_origin: EditOrigin,
cb_path: String,
cb_body: String,
cb_act: crate::shell::act::Held,
marks: MarksPane,
}
impl ConfigState {
pub fn new(env: &Env) -> std::io::Result<Self> {
let io = RealFileIo;
let lernie = LernieGlobal::resolve(env);
let lernie_editor = Editor::load(lernie.models(), &io)?;
let cadence_path = env.yog_state_root().join(crate::app::cadence::CADENCE_YAML);
let mut cadence_editor = Editor::load(cadence_path.clone(), &io)?;
if cadence_editor.is_new() {
cadence_editor = Editor::seeded(cadence_path, crate::app::cadence::TEMPLATE.as_bytes());
}
Ok(Self {
io,
lernie,
lernie_editor,
lernie_status: String::new(),
cadence_editor,
cadence_status: String::new(),
workflows: Vec::new(),
new_workflow: String::new(),
new_model: String::new(),
branches: Vec::new(),
cb_files: Vec::new(),
cb_name: String::new(),
cb_origin: EditOrigin::Advance,
cb_path: String::new(),
cb_body: String::new(),
cb_act: crate::shell::act::Held::default(),
marks: MarksPane::resolve(),
})
}
pub fn open(&mut self, workspace: Option<&std::path::Path>) {
let _ = self.lernie_editor.refresh(&self.io);
let _ = self.cadence_editor.refresh(&self.io);
self.workflows = self.lernie.workflows(&self.io).unwrap_or_default();
branch_pane::reread(self, workspace);
}
}
pub fn center(ui: &mut egui::Ui, model: &mut AppModel, state: &mut super::ShellState) {
ui.weak("every setting here edits the file that holds it");
let rows = row_names(&state.wall.brazen.providers);
let mut route = None;
egui::ScrollArea::vertical().show(ui, |ui| {
super::row::shown_width(ui);
route = brazen_pane::render(ui, &mut state.wall.brazen);
ui.separator();
lernie_pane::render(ui, &mut state.config, &rows);
ui.separator();
yog_pane::render(ui, &mut state.config);
ui.separator();
config_marks::render(ui, model, &mut state.config.marks);
ui.separator();
branch_pane::render(ui, model, &mut state.config, &rows);
super::delete::danger_row(ui, model, state);
});
if let Some(tab) = route {
super::center::focus(model, state, tab);
}
}