progress
This commit is contained in:
+35
-2
@@ -2,6 +2,7 @@ use egui::RichText;
|
||||
|
||||
use crate::{
|
||||
PROJECT_FOLDER, RightPanelContent,
|
||||
main_editor::MainEditor,
|
||||
note::Note,
|
||||
object::ObjectInstance,
|
||||
template::{FieldType, Template},
|
||||
@@ -14,7 +15,12 @@ impl Explorer {
|
||||
Self {}
|
||||
}
|
||||
|
||||
pub fn ui(&mut self, to_load: &mut Option<RightPanelContent>, ui: &mut egui::Ui) {
|
||||
pub fn ui(
|
||||
&mut self,
|
||||
to_load: &mut Option<RightPanelContent>,
|
||||
load_doc: &mut Option<MainEditor>,
|
||||
ui: &mut egui::Ui,
|
||||
) {
|
||||
let (templates, objects) = match Self::load_templates() {
|
||||
Ok((templates, objects)) => (templates, objects),
|
||||
Err(e) => {
|
||||
@@ -116,7 +122,20 @@ impl Explorer {
|
||||
}
|
||||
});
|
||||
|
||||
egui::CollapsingHeader::new("Projects").show(ui, |ui| {});
|
||||
let documents = Self::load_documents().unwrap();
|
||||
|
||||
egui::CollapsingHeader::new("Projects").show(ui, |ui| {
|
||||
for document in &documents {
|
||||
ui.horizontal(|ui| {
|
||||
ui.add_space(10.0);
|
||||
|
||||
// load the document
|
||||
if ui.selectable_label(false, &document.name).clicked() {
|
||||
*load_doc = Some(document.clone());
|
||||
}
|
||||
});
|
||||
}
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
@@ -156,4 +175,18 @@ impl Explorer {
|
||||
|
||||
Ok(notes)
|
||||
}
|
||||
|
||||
fn load_documents() -> std::io::Result<Vec<MainEditor>> {
|
||||
let mut documents = Vec::new();
|
||||
|
||||
for entry in std::fs::read_dir(PROJECT_FOLDER.join("documents")).unwrap() {
|
||||
let path = entry.unwrap().path();
|
||||
match MainEditor::load(path.file_stem().unwrap().to_str().unwrap()) {
|
||||
Ok(document) => documents.push(document),
|
||||
Err(err) => eprintln!("Could not parse file {path:?}: {err}"),
|
||||
}
|
||||
}
|
||||
|
||||
Ok(documents)
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user