added filesystem abstraction layer and implemented basic filesystem - testing not complete yet, still features missing
Continuous integration / build (push) Has been cancelled
Continuous integration / build (push) Has been cancelled
This commit is contained in:
@@ -2,10 +2,12 @@ use chrono::NaiveDate;
|
||||
use core::fmt;
|
||||
use egui::ScrollArea;
|
||||
use serde::{Deserialize, Serialize};
|
||||
use std::path::Path;
|
||||
|
||||
use crate::{
|
||||
PROJECT_FOLDER, RightPanelContent,
|
||||
RightPanelContent,
|
||||
editors::object_editor::ObjectInstance,
|
||||
filesystem::{FILESYSTEM, LegacyFileSystem},
|
||||
util::{self, Error},
|
||||
};
|
||||
|
||||
@@ -171,21 +173,14 @@ impl Default for Template {
|
||||
|
||||
impl Template {
|
||||
pub fn load(id: &str) -> Result<Self, Box<dyn std::error::Error>> {
|
||||
let path = PROJECT_FOLDER.join("templates").join(format!("{id}.json"));
|
||||
|
||||
let content = std::fs::read_to_string(&path)?;
|
||||
let mut template: Self = serde_json::from_str(&content)?;
|
||||
let mut template = FILESYSTEM.read::<Self>(Path::new(&format!("templates/{id}.json")))?;
|
||||
template.saved = true;
|
||||
Ok(template)
|
||||
}
|
||||
|
||||
pub fn save(&mut self) -> Result<(), Box<dyn std::error::Error>> {
|
||||
let path = PROJECT_FOLDER
|
||||
.join("templates")
|
||||
.join(format!("{}.json", &self.id));
|
||||
|
||||
let content = serde_json::to_string_pretty(self)?;
|
||||
std::fs::write(path, content)?;
|
||||
let id = &self.id;
|
||||
FILESYSTEM.write(Path::new(&format!("templates/{id}.json")), self.clone())?;
|
||||
self.saved = true;
|
||||
Ok(())
|
||||
}
|
||||
@@ -203,16 +198,6 @@ impl Template {
|
||||
|
||||
ScrollArea::vertical().show(ui, |ui| {
|
||||
ui.vertical(|ui| {
|
||||
// ui.group(|ui| {
|
||||
// ui.horizontal(|ui| {
|
||||
// if self.saved {
|
||||
// ui.label(RichText::new("✓ Saved").color(egui::Color32::GREEN));
|
||||
// } else {
|
||||
// ui.label(RichText::new("* Unsaved").color(egui::Color32::YELLOW));
|
||||
// }
|
||||
// ui.label(format!("id: {}", self.id));
|
||||
// });
|
||||
// });
|
||||
util::saved_status(ui, self.saved, &self.id, &self.name);
|
||||
|
||||
// Save/Cancel buttons
|
||||
@@ -231,13 +216,10 @@ impl Template {
|
||||
}
|
||||
|
||||
if ui.button("Delete").clicked() {
|
||||
std::fs::remove_file(
|
||||
PROJECT_FOLDER
|
||||
.join("templates")
|
||||
.join(format!("{}.json", self.id)),
|
||||
)
|
||||
.unwrap();
|
||||
|
||||
let id = &self.id;
|
||||
FILESYSTEM
|
||||
.delete(Path::new(&format!("templates/{id}.json")))
|
||||
.unwrap();
|
||||
*new_instance = Some(RightPanelContent::None);
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user