Skip to content

SolidCraft: an open-source parametric 3D CAD application built in pure Rust. Desktop, web, and automation through MCP.

Home: keep a removed recent design removed (#4660) (#4718)

neosandeep249ad96fb81b35
diff --git a/apps/solidcraft-web/src/main.rs b/apps/solidcraft-web/src/main.rs
index 1c8ad471e7..c66b56bd05 100644
--- a/apps/solidcraft-web/src/main.rs
+++ b/apps/solidcraft-web/src/main.rs
@@ -230,13 +230,15 @@ mod web {
fn sync_recents(&mut self) {
let mut entries = self.files.entries.borrow().clone();
entries.sort_by(|a, b| b.modified.total_cmp(&a.modified));
+ let forgotten = self.app.home.forgotten.clone();
let recent = &mut self.app.home.recent;
let known = self.files.disk_known.borrow().clone();
// A design on the computer's disk stays listed while its file is remembered.
recent.retain(|p| vfs::exists(p) || disk::parse(p).is_some_and(|(id, _)| known.contains(id)));
for e in entries.iter().filter(|e| solidcraft_engine::io::is_design_path(&e.name)) {
let p = format!("{}{}", files::OPFS, e.name);
- if !recent.contains(&p) {
+ // A design the user removed from the list is not added back while it is stored.
+ if !recent.contains(&p) && !forgotten.contains(&p) {
recent.push(p);
}
}
@@ -245,6 +247,10 @@ mod web {
let recovered = self.files.recovery.borrow().as_ref().and_then(|(_, p)| p.clone());
let keep = recent.iter().chain(recovered.as_ref()).filter_map(|p| disk::parse(p)).map(|(id, _)| id.to_string()).collect();
disk::prune(keep);
+ // Drop forgotten entries whose stored design is gone, so the set does not grow without bound.
+ let stored: std::collections::BTreeSet<String> =
+ entries.iter().filter(|e| solidcraft_engine::io::is_design_path(&e.name)).map(|e| format!("{}{}", files::OPFS, e.name)).collect();
+ self.app.home.forgotten.retain(|p| stored.contains(p));
}
/// The stored designs: open, insert, rename, delete, download; open from the computer.
@@ -383,6 +389,8 @@ mod web {
"delete" => {
files::delete(&self.files, &name);
self.app.home.recent.retain(|r| *r != path);
+ // The file is gone, so there is nothing left to keep forgotten.
+ self.app.home.forgotten.remove(&path);
}
"rename_cancel" => self.renaming = None,
"rename" => {
@@ -396,6 +404,10 @@ mod web {
*r = new.clone();
}
}
+ // A forgotten design follows its new name.
+ if self.app.home.forgotten.remove(&old) {
+ self.app.home.forgotten.insert(new);
+ }
}
Err(e) => self.app.set_status(e, true),
}
diff --git a/crates/ui-egui/src/home.rs b/crates/ui-egui/src/home.rs
index 993d250e59..63782e5fa7 100644
--- a/crates/ui-egui/src/home.rs
+++ b/crates/ui-egui/src/home.rs
@@ -35,6 +35,10 @@ pub struct HomeState {
/// Recent design paths, newest first (kept in the preferences).
pub recent: Vec<String>,
pub opened_at: std::collections::BTreeMap<String, u64>,
+ /// Designs the user removed from the list. Kept in the preferences so a host that rebuilds
+ /// the recent list from its stored designs (the web build, see `sync_recents`) does not add
+ /// them back. Opening or saving a design clears it from here.
+ pub forgotten: std::collections::BTreeSet<String>,
thumbs: HashMap<String, Option<egui::TextureHandle>>,
samples: HashMap<usize, Session>,
/// Keys asked for and not made yet.
@@ -94,6 +98,17 @@ impl HomeState {
self.opened_at.insert(path.to_string(), web_time::SystemTime::now().duration_since(web_time::UNIX_EPOCH).map(|d| d.as_secs()).unwrap_or(0));
self.opened_at.retain(|p, _| self.recent.contains(p));
self.thumbs.remove(path);
+ // Opening or saving a design undoes an earlier removal from the list.
+ self.forgotten.remove(path);
+ }
+
+ /// Drop a design from the recent list and remember that the user did so, so a host that
+ /// rebuilds the list from its stored designs (the web build) does not add it back.
+ pub fn forget(&mut self, path: &str) {
+ self.recent.retain(|p| p != path);
+ self.opened_at.remove(path);
+ self.thumbs.remove(path);
+ self.forgotten.insert(path.to_string());
}
}
@@ -796,8 +811,7 @@ fn start_content(app: &mut SolveApp, ui: &mut egui::Ui, action: &mut Option<File
publish(&format!("home:recent:{index}"), &response);
ui_kit::Menu::context(&response, |ui| {
if crate::context_menu::button(ui, app.tr_label("Remove from list"), "delete").clicked() {
- app.home.recent.retain(|x| x != path);
- app.home.opened_at.remove(path);
+ app.home.forget(path);
ui.close();
}
if !cfg!(target_arch = "wasm32") && crate::context_menu::button(ui, app.tr_label("Show in folder"), "folder").clicked() {
diff --git a/crates/ui-egui/src/lib.rs b/crates/ui-egui/src/lib.rs
index 7c959bf797..e53a3626cd 100644
--- a/crates/ui-egui/src/lib.rs
+++ b/crates/ui-egui/src/lib.rs
@@ -720,6 +720,7 @@ impl SolveApp {
"browser_expanded": self.tree.expanded,
"recent": self.home.recent,
"recent_opened_at": self.home.opened_at,
+ "recent_forgotten": self.home.forgotten,
"shortcut_box": self.sbox.prefs(),
"shortcuts": self.keymap.prefs(),
"toolbar": self.toolbar_custom.prefs(),
@@ -775,6 +776,7 @@ impl SolveApp {
.and_then(Value::as_array)
.map(|a| a.iter().filter_map(Value::as_str).take(home::MAX_RECENT).map(str::to_string).collect())
.unwrap_or_default();
+ self.home.forgotten = keys("recent_forgotten");
if let Some(s) = v.get("shortcut_box") {
self.sbox.load(s);
}