forked from 1b-agent/opencadstudio-upstream
Sheet sets: reference menu order, new sheets stay closed, .dst reload, navigation fields
The tree menus follow the reference per row kind (New Sheet / Import on a sheet work on its subset, Remove Subset only while empty, Rename Subset), a new sheet is not opened, an open set reloads when its .dst changes on disk, ViewportScale placeholders take the version of their format and the codec pin moves to the revision with navigation fields. Co-Authored-By: Claude Opus 5.5 <[email protected]>
This commit is contained in:
1 parent
ad5d2a8599
commit
612bb26a8c
28 files changed
+112
-21
No files matched your search
@@ -254,6 +254,32 @@ impl OpenCADStudio {
|
||||
Ok(())
|
||||
}
|
||||
|
||||
/// Reload every open set whose `.dst` was changed by someone else.
|
||||
fn poll_sheet_sets(&mut self) {
|
||||
let mut changed = false;
|
||||
for db in &mut self.sheet_set.sets {
|
||||
let Some(path) = db.path.clone() else {
|
||||
continue;
|
||||
};
|
||||
let Ok(modified) = std::fs::metadata(&path).and_then(|m| m.modified()) else {
|
||||
continue;
|
||||
};
|
||||
let key = ss::path_key(&path);
|
||||
if self.sheet_set.seen.insert(key, modified).is_none_or(|t| t == modified) {
|
||||
continue;
|
||||
}
|
||||
if let Ok(fresh) = SheetSetDatabase::read(&path) {
|
||||
if fresh.root != db.root {
|
||||
*db = fresh;
|
||||
changed = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
if changed {
|
||||
self.sheet_sets_changed();
|
||||
}
|
||||
}
|
||||
|
||||
/// Write the current set back to its `.dst`.
|
||||
fn save_current_sheet_set(&mut self) {
|
||||
let Some(db) = self.sheet_set.db_mut() else {
|
||||
@@ -358,6 +384,7 @@ impl OpenCADStudio {
|
||||
self.sheet_set.collapsed.insert(id);
|
||||
}
|
||||
}
|
||||
SheetSetMsg::Poll => self.poll_sheet_sets(),
|
||||
SheetSetMsg::Refresh => {
|
||||
if let Some(path) = self.sheet_set.db().and_then(|db| db.path.clone()) {
|
||||
match SheetSetDatabase::read(&path) {
|
||||
@@ -513,6 +540,15 @@ impl OpenCADStudio {
|
||||
let Some(db) = self.sheet_set.db() else {
|
||||
return Task::none();
|
||||
};
|
||||
// On a sheet, New Sheet and Import work on the subset holding it.
|
||||
let id = match action {
|
||||
MenuAction::NewSheet | MenuAction::ImportLayout
|
||||
if db.find(&id).and_then(ComponentKind::of) == Some(ComponentKind::Sheet) =>
|
||||
{
|
||||
db.parent_of(&id).map_or(id, |p| p.id().to_string())
|
||||
}
|
||||
_ => id,
|
||||
};
|
||||
match action {
|
||||
MenuAction::Open => return self.open_sheet(&id),
|
||||
MenuAction::NewSheet => {
|
||||
@@ -1098,11 +1134,12 @@ impl OpenCADStudio {
|
||||
if let Err(e) = crate::io::save(&scene.document, &path) {
|
||||
self.command_line.push_error(&format!("{file}: {e}"));
|
||||
}
|
||||
// The new sheet is not opened ("Open in drawing editor" is off by default).
|
||||
self.close_active_modal();
|
||||
self.sheet_set.current = Some(f.set);
|
||||
self.sheet_set.selected = Some(sheet.clone());
|
||||
self.sheet_set.selected = Some(sheet);
|
||||
self.sheet_sets_changed();
|
||||
self.open_sheet(&sheet)
|
||||
Task::none()
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -2644,6 +2644,16 @@ impl OpenCADStudio {
|
||||
};
|
||||
#[cfg(target_arch = "wasm32")]
|
||||
let plugin_drain = Subscription::none();
|
||||
// Open sheet sets reload when their .dst changes on disk.
|
||||
#[cfg(not(target_arch = "wasm32"))]
|
||||
let sheet_set_poll = if self.sheet_set.sets.is_empty() {
|
||||
Subscription::none()
|
||||
} else {
|
||||
iced::time::every(std::time::Duration::from_secs(1))
|
||||
.map(|_| Message::SheetSet(crate::ui::window::sheet_set::SheetSetMsg::Poll))
|
||||
};
|
||||
#[cfg(target_arch = "wasm32")]
|
||||
let sheet_set_poll = Subscription::none();
|
||||
let hatch_pattern_keys = if self.tabs[self.active_tab]
|
||||
.properties
|
||||
.hatch_pattern_picker_open
|
||||
@@ -2845,6 +2855,7 @@ impl OpenCADStudio {
|
||||
web_fonts,
|
||||
autosave,
|
||||
plugin_drain,
|
||||
sheet_set_poll,
|
||||
single_instance,
|
||||
hatch_pattern_keys,
|
||||
keyboard_events,
|
||||
|
||||
Reference in new issue
Block a user