// Map, wardley map editor for linux // Copyright (C) 2026 Rubén Beltrán del Río // This program is free software: you can redistribute it and/or modify // it under the terms of the GNU Affero General Public License as published by // the Free Software Foundation, either version 3 of the License, or // (at your option) any later version. // This program is distributed in the hope that it will be useful, // but WITHOUT ANY WARRANTY; without even the implied warranty of // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the // GNU Affero General Public License for more details. // You should have received a copy of the GNU Affero General Public License // along with this program. If not, see . use gtk::prelude::*; use relm4::prelude::*; use uuid::Uuid; use crate::preferences::models::{CustomStage, StageLabel}; use crate::tr; #[derive(Debug)] pub struct StageForm { pub stage: CustomStage, } #[derive(Debug)] pub enum StageFormAction { SetName(String), SetLabel(StageLabel, String), Remove, } #[derive(Debug)] pub enum StageFormOutput { SetName(Uuid, String), SetLabel(Uuid, StageLabel, String), Remove(Uuid), } #[relm4::factory(pub)] impl FactoryComponent for StageForm { type Init = CustomStage; type Input = StageFormAction; type Output = StageFormOutput; type CommandOutput = (); type ParentWidget = gtk::ListBox; view! { #[root] gtk::ListBoxRow { gtk::Box { set_orientation: gtk::Orientation::Horizontal, set_margin_all: 5, set_spacing: 5, gtk::Entry { set_text: &self.stage.name, set_width_chars: 15, connect_changed[sender] => move |entry| { sender.input(StageFormAction::SetName( entry.text().to_string() )); }, }, gtk::Entry { set_text: &self.stage.stage.i, set_width_chars: 12, connect_changed[sender] => move |entry| { sender.input(StageFormAction::SetLabel( StageLabel::I, entry.text().to_string() )); }, }, gtk::Entry { set_text: &self.stage.stage.ii, set_width_chars: 12, connect_changed[sender] => move |entry| { sender.input(StageFormAction::SetLabel( StageLabel::Ii, entry.text().to_string() )); }, }, gtk::Entry { set_text: &self.stage.stage.iii, set_width_chars: 12, connect_changed[sender] => move |entry| { sender.input(StageFormAction::SetLabel( StageLabel::Iii, entry.text().to_string() )); }, }, gtk::Entry { set_text: &self.stage.stage.iv, set_width_chars: 12, connect_changed[sender] => move |entry| { sender.input(StageFormAction::SetLabel( StageLabel::Iv, entry.text().to_string() )); }, }, gtk::Button::from_icon_name("list-remove-symbolic") { add_css_class: "flat", set_tooltip_text: Some(&tr!("Remove stage")), connect_clicked[sender] => move |_| { sender.input(StageFormAction::Remove); } } } } } fn init_model(stage: Self::Init, _index: &DynamicIndex, _sender: FactorySender) -> Self { Self { stage } } fn update(&mut self, message: Self::Input, sender: FactorySender) { match message { StageFormAction::SetName(name) => { sender .output(StageFormOutput::SetName(self.stage.id, name)) .ok(); } StageFormAction::SetLabel(label, value) => { sender .output(StageFormOutput::SetLabel(self.stage.id, label, value)) .ok(); } StageFormAction::Remove => { sender.output(StageFormOutput::Remove(self.stage.id)).ok(); } } } }