From 5f3b199684401c11c91c38c1d3f58da2d740b960 Mon Sep 17 00:00:00 2001 From: WanderingPenwing Date: Mon, 22 Jul 2024 13:56:31 +0200 Subject: [PATCH] fixed file tree entry id, so no more conflict --- calcifer.project | 2 +- src/core/app.rs | 15 +++++++++------ src/panels/file_tree.rs | 6 +++++- 3 files changed, 15 insertions(+), 8 deletions(-) diff --git a/calcifer.project b/calcifer.project index 459cb9b..be32f9f 100644 --- a/calcifer.project +++ b/calcifer.project @@ -1 +1 @@ -{"categories":[{"name":"to do","content":[{"name":"add id to textarea per tab","description":"to improve undo, make each code area of each tab have a unique id (no more undo into another tab)","id":1},{"name":"bug project","description":"when switching tabs between two project file, if item window is open it crashes","id":1},{"name":"update workflow .yml","description":"make a workflow compiling the calcifer and put the linux in calcifer-{version}\nand the windows in calcifer_windows_{version}\n\nupdate nix\nupdate jiji","id":5},{"name":"open dir in tree ?","description":"// Hello there","id":2},{"name":"file tree id ?","description":"// Hello there","id":1}]},{"name":"in progress","content":[{"name":"export copy paste fix","description":"// Hello there","id":1}]},{"name":"done","content":[{"name":"move .project file","description":"// Hello there","id":4},{"name":"move config","description":"config from .calcifer/save.json\nto .config/calcifer/state.json","id":1}]},{"name":"+","content":[]}]} \ No newline at end of file +{"categories":[{"name":"to do","content":[{"name":"bug project","description":"when switching tabs between two project file, if item window is open it crashes","id":1},{"name":"update workflow .yml","description":"make a workflow compiling the calcifer and put the linux in calcifer-{version}\nand the windows in calcifer_windows_{version}\n\nupdate nix\nupdate jiji","id":5},{"name":"open dir in tree ?","description":"// Hello there","id":2},{"name":"fix tab title","description":"// Hello there","id":2}]},{"name":"in progress","content":[{"name":"export copy paste fix","description":"// Hello there","id":1}]},{"name":"done","content":[{"name":"move .project file","description":"// Hello there","id":4},{"name":"move config","description":"config from .calcifer/save.json\nto .config/calcifer/state.json","id":1},{"name":"add id to textarea per tab","description":"to improve undo, make each code area of each tab have a unique id (no more undo into another tab)","id":1},{"name":"file tree id ?","description":"// Hello there","id":1}]},{"name":"+","content":[]}]} \ No newline at end of file diff --git a/src/core/app.rs b/src/core/app.rs index 89ef185..549a5bc 100644 --- a/src/core/app.rs +++ b/src/core/app.rs @@ -209,10 +209,13 @@ impl Calcifer { if let Some(folder_content) = &file.folder_content { let mut check_for_update: bool = false; - let collapsing_response = egui::CollapsingHeader::new(file.name.clone()) - .default_open(self.tree_dir_opened.contains(&file.name)) + let file_id = panels::get_file_id(&file); + + let collapsing_response = egui::CollapsingHeader::new(&file.name.clone()) + .id_source(&file_id) + .default_open(self.tree_dir_opened.contains(&file_id)) .show(ui, |ui| { - if !self.tree_dir_opened.contains(&file.name) { + if !self.tree_dir_opened.contains(&file_id) { return; } for deeper_file in folder_content { @@ -222,9 +225,9 @@ impl Calcifer { } }); if collapsing_response.fully_closed() { - self.tree_dir_opened.retain(|s| s != &file.name); - } else if !self.tree_dir_opened.contains(&file.name) { - self.tree_dir_opened.push(file.name.clone()); + self.tree_dir_opened.retain(|s| s != &file_id); + } else if !self.tree_dir_opened.contains(&file_id) { + self.tree_dir_opened.push(file_id); return !file.content_checked; } return check_for_update; diff --git a/src/panels/file_tree.rs b/src/panels/file_tree.rs index 8c84723..5b0302a 100644 --- a/src/panels/file_tree.rs +++ b/src/panels/file_tree.rs @@ -35,7 +35,7 @@ impl FileEntry { } pub fn update_file_tree(file: FileEntry, opened_dirs: Vec) -> FileEntry { - if opened_dirs.contains(&file.name) { + if opened_dirs.contains(&get_file_id(&file)) { if let Some(folder_content) = &file.folder_content { if !file.content_checked { return generate_folder_entry(&file.path); @@ -58,6 +58,10 @@ pub fn update_file_tree(file: FileEntry, opened_dirs: Vec) -> FileEntry } } +pub fn get_file_id(file: &FileEntry) -> String { + format!("#{}",file.path.clone().display()) +} + pub fn generate_folder_entry(path: &Path) -> FileEntry { if let Some(file_name) = path.file_name() { let name = file_name.to_string_lossy().into_owned();