Save tim_project files
This commit is contained in:
parent
18e6800e0f
commit
d1d590d32a
|
@ -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(())
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue