From d1d590d32a4cf2a21ae85ff5ff71326ccfab660f Mon Sep 17 00:00:00 2001 From: Jaby Date: Wed, 19 Mar 2025 21:32:18 +0100 Subject: [PATCH] Save tim_project files --- .../tim_tool/src/gui/file_tab/callbacks.rs | 23 ++++++++++++++----- 1 file changed, 17 insertions(+), 6 deletions(-) diff --git a/src/Tools/tim_tool/src/gui/file_tab/callbacks.rs b/src/Tools/tim_tool/src/gui/file_tab/callbacks.rs index 9d3c5934..2e60d382 100644 --- a/src/Tools/tim_tool/src/gui/file_tab/callbacks.rs +++ b/src/Tools/tim_tool/src/gui/file_tab/callbacks.rs @@ -1,4 +1,6 @@ -use crate::{gui::{main_tab::MainTab, MutexTIMManager, VRAM_HEIGHT, VRAM_WIDTH}, MainWindow}; +use std::{fs::File, io::Write}; + +use crate::{gui::{self, main_tab::MainTab, MutexTIMManager, VRAM_HEIGHT, VRAM_WIDTH}, MainWindow}; use super::FileTab; use rfd::FileDialog; use slint::SharedString; @@ -66,7 +68,12 @@ pub(super) fn on_load_project_clicked() -> impl FnMut(&mut FileTab, &MainWindow) } pub(super) fn on_save_project_clicked(tim_manager: MutexTIMManager) -> impl FnMut(&mut FileTab, &MainTab, &MainWindow) -> Result<(), Error> + 'static { - move |_file_tab, main_tab, _main_window| { + move |_file_tab, main_tab, main_window| { + let save_location = main_window.get_project_widget_save_project_path(); + if save_location.is_empty() { + return Err(Error::from_str("Please specify save location for project file")); + } + let tim_info = tim_manager.lock().expect("VRAM already locked").clone_added_tims(); let vram_info = main_tab.clone_vram_info(); @@ -95,14 +102,18 @@ pub(super) fn on_save_project_clicked(tim_manager: MutexTIMManager) -> impl FnMu project.push(cur_job); } - let string = match serde_json::to_string(&project) { - Ok(string) => string, - Err(error) => { + let json_content = match serde_json::to_string(&project) { + Ok(json_content) => json_content, + Err(error) => { return Err(Error::from_error(error)); } }; - Err(Error::from_text(format!("Adding {} jobs", string))) + let mut file = File::create(save_location)?; + file.write_all(json_content.as_bytes())?; + + gui::display_information("Saving project", "Project saved successfully"); + Ok(()) } }