Projects: Inital support for saving and loading projects #22
|
@ -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 crate::{gui::{self, main_tab::MainTab, MutexTIMManager, VRAM_HEIGHT, VRAM_WIDTH}, MainWindow};
|
||||||
use super::FileTab;
|
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 {
|
pub(super) fn on_load_project_clicked() -> impl FnMut(&mut FileTab, &MainWindow) -> Result<(), Error> + 'static {
|
||||||
move |_file_tab, _main_window| {
|
move |_file_tab, main_window| {
|
||||||
Err(Error::not_implemented("on_load_project_clicked"))
|
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(())
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue