Projects: Inital support for saving and loading projects #22

Merged
cody merged 17 commits from topic/jb/project-files into main 2025-04-05 19:56:33 +00:00
1 changed files with 16 additions and 3 deletions
Showing only changes of commit 5cc88e0b87 - Show all commits

View File

@ -1,4 +1,4 @@
use std::{fs::File, io::Write};
use std::{fs::File, io::Write, path::PathBuf};
use crate::{gui::{self, main_tab::MainTab, MutexTIMManager, VRAM_HEIGHT, VRAM_WIDTH}, MainWindow};
use super::FileTab;
@ -62,8 +62,21 @@ pub(super) fn on_add_image(tim_manager: MutexTIMManager) -> impl FnMut(&mut File
}
pub(super) fn on_load_project_clicked() -> impl FnMut(&mut FileTab, &MainWindow) -> Result<(), Error> + 'static {
move |_file_tab, _main_window| {
Err(Error::not_implemented("on_load_project_clicked"))
move |_file_tab, main_window| {
let open_location = main_window.get_project_widget_open_project_path();
if open_location.is_empty() {
return Err(Error::from_str("Please specify location for project file to open"));
}
let file_content = tool_helper::read_file_to_string(&PathBuf::from(open_location.as_str()))?;
let _new_project = match serde_json::from_str::<Project>(&file_content) {
Ok(project) => project,
Err(error) => {
return Err(Error::from_error(error));
}
};
Ok(())
}
}