added copy and delete to object and templates

This commit is contained in:
2025-07-15 14:56:28 +01:00
parent 76ec44d4e6
commit 1117ce9f13
6 changed files with 92 additions and 37 deletions
+23 -5
View File
@@ -99,7 +99,7 @@ impl Template {
pub fn ui(
&mut self,
ui: &mut egui::Ui,
new_instance: &mut RightPanelContent,
new_instance: &mut Option<RightPanelContent>,
new_field_name: &mut String,
new_field_type: &mut FieldType,
new_field_required: &mut bool,
@@ -130,22 +130,40 @@ impl Template {
// Save/Cancel buttons
ui.horizontal(|ui| {
if ui.button("Save Template").clicked() {
if ui.button("Save").clicked() {
if let Err(e) = self.save() {
eprintln!("Failed to save: {e}");
}
}
if ui.button("Create Copy").clicked() {
let mut copy = self.clone();
copy.id = uuid::Uuid::new_v4().to_string();
copy.name = format!("{} (Copy)", self.name);
copy.save().unwrap();
}
if ui.button("Delete").clicked() {
std::fs::remove_file(
PROJECT_FOLDER
.join("templates")
.join(format!("{}.json", self.id)),
)
.unwrap();
*new_instance = Some(RightPanelContent::None);
}
if ui.button("Cancel").clicked() {
// load default state
*self = Self::load(&self.id).unwrap();
}
if ui.button("Create New Instance").clicked() {
if ui.button("Use Template").clicked() {
if self.saved {
*new_instance = RightPanelContent::Object {
*new_instance = Some(RightPanelContent::Object {
object: Box::new(ObjectInstance::new(self)),
};
});
} else {
self.error = Some(Error::new(
"You must save the template before creating a new instance!"