refactor(config): consolidate settings into one grouped settings.json
App preferences were spread across six flat plain-text files (settings.txt,
recent.txt, recent_limit.txt, statusbar.txt, ribbon.txt, plot.txt), each with a
bespoke line parser and no grouping. Replace them with a single grouped JSON,
serialized via serde (enabling the derive feature; serde_json was already a
dependency).
- New app/config.rs: AppConfig { settings, recent, statusbar, ribbon, plot } →
<config>/settings.json (pretty JSON), load()/save().
- Make UserSettings, StatusBarConfig/StatusPill, CollapseMode and
PlotDialogState serde-derived; #[serde(skip)] marks the plot dialog's runtime
fields so only print preferences persist. Their bespoke .txt load/save is
removed.
- App gains current_config/apply_config/save_config: one AppConfig::load at
startup distributes into live state; every settings-change site
(persist_settings_if_changed, recent add/remove/limit, status-bar pill
toggle, ribbon density, plot commit) routes through save_config, which diffs
against the last write to avoid thrashing.
- Clean start: the old flat files are ignored (no migration). ocad.pgp stays a
separate hand-editable file.
Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
2026-07-10 16:41:34 +03:00
|
|
|
//! Recent-files list backing the Start page's Recent Documents panel. The list
|
2026-07-29 00:41:51 +03:00
|
|
|
//! itself lives in the consolidated app config (native `settings.json` or web
|
|
|
|
|
//! `localStorage`, in the "recent" section); this module mutates the in-memory
|
|
|
|
|
//! list, persists it via `save_config`, and evicts matching web OPFS copies.
|
feat(ui): replace app-menu logo with a quick-access file toolbar
Remove the OCS-logo button and the dropdown menu it opened; the top strip
now shows direct New / Open / Save / Save As / Print buttons ahead of the
undo/redo controls. Drop the HELP and OPTIONS commands (HELP dumped text to
the command line, OPTIONS aliased the drafting-settings popup).
The app-menu overlay is gone, so its rendering code, MENU_ITEMS, four dead
messages, and the LOGO_RED / GEAR / HELP assets are removed. The recents
list it held is the only survivor — moved into OpenCADStudio.recent_files
via a new app/recent.rs, backing the Start page's Recent Documents panel.
Quick-access icons are redrawn in a cleaner style (file-plus, folder-open,
device-floppy, file-export, printer) and tinted light so they read on the
dark strip; FOLDER / DOC keep their old glyphs for the file browser.
Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
2026-07-03 09:51:49 +03:00
|
|
|
|
|
|
|
|
use super::OpenCADStudio;
|
|
|
|
|
use std::path::{Path, PathBuf};
|
|
|
|
|
|
2026-07-06 01:06:01 +03:00
|
|
|
/// Bounds and default for how many recent files are kept.
|
|
|
|
|
pub(super) const RECENT_MIN: usize = 5;
|
|
|
|
|
pub(super) const RECENT_MAX: usize = 100;
|
refactor(config): consolidate settings into one grouped settings.json
App preferences were spread across six flat plain-text files (settings.txt,
recent.txt, recent_limit.txt, statusbar.txt, ribbon.txt, plot.txt), each with a
bespoke line parser and no grouping. Replace them with a single grouped JSON,
serialized via serde (enabling the derive feature; serde_json was already a
dependency).
- New app/config.rs: AppConfig { settings, recent, statusbar, ribbon, plot } →
<config>/settings.json (pretty JSON), load()/save().
- Make UserSettings, StatusBarConfig/StatusPill, CollapseMode and
PlotDialogState serde-derived; #[serde(skip)] marks the plot dialog's runtime
fields so only print preferences persist. Their bespoke .txt load/save is
removed.
- App gains current_config/apply_config/save_config: one AppConfig::load at
startup distributes into live state; every settings-change site
(persist_settings_if_changed, recent add/remove/limit, status-bar pill
toggle, ribbon density, plot commit) routes through save_config, which diffs
against the last write to avoid thrashing.
- Clean start: the old flat files are ignored (no migration). ocad.pgp stays a
separate hand-editable file.
Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
2026-07-10 16:41:34 +03:00
|
|
|
pub(super) const RECENT_DEFAULT: usize = 20;
|
2026-07-06 01:06:01 +03:00
|
|
|
|
feat(ui): replace app-menu logo with a quick-access file toolbar
Remove the OCS-logo button and the dropdown menu it opened; the top strip
now shows direct New / Open / Save / Save As / Print buttons ahead of the
undo/redo controls. Drop the HELP and OPTIONS commands (HELP dumped text to
the command line, OPTIONS aliased the drafting-settings popup).
The app-menu overlay is gone, so its rendering code, MENU_ITEMS, four dead
messages, and the LOGO_RED / GEAR / HELP assets are removed. The recents
list it held is the only survivor — moved into OpenCADStudio.recent_files
via a new app/recent.rs, backing the Start page's Recent Documents panel.
Quick-access icons are redrawn in a cleaner style (file-plus, folder-open,
device-floppy, file-export, printer) and tinted light so they read on the
dark strip; FOLDER / DOC keep their old glyphs for the file browser.
Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
2026-07-03 09:51:49 +03:00
|
|
|
impl OpenCADStudio {
|
2026-07-21 10:06:55 +03:00
|
|
|
/// Record a freshly opened file at the top of the recents list. Returns
|
|
|
|
|
/// the background task that decodes its thumbnail.
|
|
|
|
|
pub(super) fn push_recent(&mut self, path: PathBuf) -> iced::Task<crate::app::Message> {
|
feat(ui): replace app-menu logo with a quick-access file toolbar
Remove the OCS-logo button and the dropdown menu it opened; the top strip
now shows direct New / Open / Save / Save As / Print buttons ahead of the
undo/redo controls. Drop the HELP and OPTIONS commands (HELP dumped text to
the command line, OPTIONS aliased the drafting-settings popup).
The app-menu overlay is gone, so its rendering code, MENU_ITEMS, four dead
messages, and the LOGO_RED / GEAR / HELP assets are removed. The recents
list it held is the only survivor — moved into OpenCADStudio.recent_files
via a new app/recent.rs, backing the Start page's Recent Documents panel.
Quick-access icons are redrawn in a cleaner style (file-plus, folder-open,
device-floppy, file-export, printer) and tinted light so they read on the
dark strip; FOLDER / DOC keep their old glyphs for the file browser.
Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
2026-07-03 09:51:49 +03:00
|
|
|
self.recent_files.retain(|r| r != &path);
|
2026-07-29 01:09:13 +03:00
|
|
|
self.recent_thumbs.remove(&path);
|
feat(ui): replace app-menu logo with a quick-access file toolbar
Remove the OCS-logo button and the dropdown menu it opened; the top strip
now shows direct New / Open / Save / Save As / Print buttons ahead of the
undo/redo controls. Drop the HELP and OPTIONS commands (HELP dumped text to
the command line, OPTIONS aliased the drafting-settings popup).
The app-menu overlay is gone, so its rendering code, MENU_ITEMS, four dead
messages, and the LOGO_RED / GEAR / HELP assets are removed. The recents
list it held is the only survivor — moved into OpenCADStudio.recent_files
via a new app/recent.rs, backing the Start page's Recent Documents panel.
Quick-access icons are redrawn in a cleaner style (file-plus, folder-open,
device-floppy, file-export, printer) and tinted light so they read on the
dark strip; FOLDER / DOC keep their old glyphs for the file browser.
Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
2026-07-03 09:51:49 +03:00
|
|
|
self.recent_files.insert(0, path);
|
2026-07-29 00:41:51 +03:00
|
|
|
let evicted = self
|
|
|
|
|
.recent_files
|
|
|
|
|
.split_off(self.recent_limit.min(self.recent_files.len()));
|
2026-07-29 01:09:13 +03:00
|
|
|
for path in &evicted {
|
|
|
|
|
self.recent_thumbs.remove(path);
|
|
|
|
|
}
|
2026-07-29 00:41:51 +03:00
|
|
|
remove_cached_copies(evicted);
|
refactor(config): consolidate settings into one grouped settings.json
App preferences were spread across six flat plain-text files (settings.txt,
recent.txt, recent_limit.txt, statusbar.txt, ribbon.txt, plot.txt), each with a
bespoke line parser and no grouping. Replace them with a single grouped JSON,
serialized via serde (enabling the derive feature; serde_json was already a
dependency).
- New app/config.rs: AppConfig { settings, recent, statusbar, ribbon, plot } →
<config>/settings.json (pretty JSON), load()/save().
- Make UserSettings, StatusBarConfig/StatusPill, CollapseMode and
PlotDialogState serde-derived; #[serde(skip)] marks the plot dialog's runtime
fields so only print preferences persist. Their bespoke .txt load/save is
removed.
- App gains current_config/apply_config/save_config: one AppConfig::load at
startup distributes into live state; every settings-change site
(persist_settings_if_changed, recent add/remove/limit, status-bar pill
toggle, ribbon density, plot commit) routes through save_config, which diffs
against the last write to avoid thrashing.
- Clean start: the old flat files are ignored (no migration). ocad.pgp stays a
separate hand-editable file.
Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
2026-07-10 16:41:34 +03:00
|
|
|
self.save_config();
|
2026-07-21 10:06:55 +03:00
|
|
|
self.refresh_recent_thumbs()
|
feat(ui): replace app-menu logo with a quick-access file toolbar
Remove the OCS-logo button and the dropdown menu it opened; the top strip
now shows direct New / Open / Save / Save As / Print buttons ahead of the
undo/redo controls. Drop the HELP and OPTIONS commands (HELP dumped text to
the command line, OPTIONS aliased the drafting-settings popup).
The app-menu overlay is gone, so its rendering code, MENU_ITEMS, four dead
messages, and the LOGO_RED / GEAR / HELP assets are removed. The recents
list it held is the only survivor — moved into OpenCADStudio.recent_files
via a new app/recent.rs, backing the Start page's Recent Documents panel.
Quick-access icons are redrawn in a cleaner style (file-plus, folder-open,
device-floppy, file-export, printer) and tinted light so they read on the
dark strip; FOLDER / DOC keep their old glyphs for the file browser.
Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
2026-07-03 09:51:49 +03:00
|
|
|
}
|
|
|
|
|
|
2026-07-21 10:06:55 +03:00
|
|
|
/// Decode any not-yet-cached DWG preview thumbnails for the current
|
|
|
|
|
/// recents on a background thread, delivering them via
|
|
|
|
|
/// [`Message::RecentThumbsLoaded`]. The synchronous version of this ran on
|
|
|
|
|
/// the boot path and stalled the first frame for as long as it took to
|
|
|
|
|
/// parse every recent DWG's preview — the Start page appeared seconds
|
|
|
|
|
/// late. Cached per path (a `None` result is cached too); safe to call
|
|
|
|
|
/// repeatedly.
|
|
|
|
|
pub(super) fn refresh_recent_thumbs(&mut self) -> iced::Task<crate::app::Message> {
|
|
|
|
|
let missing: Vec<std::path::PathBuf> = self
|
|
|
|
|
.recent_files
|
|
|
|
|
.iter()
|
|
|
|
|
.filter(|p| !self.recent_thumbs.contains_key(*p))
|
|
|
|
|
.cloned()
|
|
|
|
|
.collect();
|
|
|
|
|
if missing.is_empty() {
|
|
|
|
|
return iced::Task::none();
|
|
|
|
|
}
|
|
|
|
|
#[cfg(target_arch = "wasm32")]
|
|
|
|
|
{
|
2026-07-29 01:09:13 +03:00
|
|
|
return iced::Task::perform(
|
|
|
|
|
async move {
|
|
|
|
|
let mut thumbnails = Vec::with_capacity(missing.len());
|
|
|
|
|
for path in missing {
|
|
|
|
|
let handle = if let Some(name) = path
|
|
|
|
|
.file_name()
|
|
|
|
|
.map(|name| name.to_string_lossy().into_owned())
|
|
|
|
|
{
|
|
|
|
|
crate::io::web_recent::read_thumbnail(&name)
|
|
|
|
|
.await
|
|
|
|
|
.ok()
|
|
|
|
|
.flatten()
|
|
|
|
|
.map(|thumbnail| {
|
|
|
|
|
iced::widget::image::Handle::from_rgba(
|
|
|
|
|
thumbnail.width,
|
|
|
|
|
thumbnail.height,
|
|
|
|
|
thumbnail.rgba,
|
|
|
|
|
)
|
|
|
|
|
})
|
|
|
|
|
} else {
|
|
|
|
|
None
|
|
|
|
|
};
|
|
|
|
|
thumbnails.push((path, handle));
|
|
|
|
|
}
|
|
|
|
|
thumbnails
|
|
|
|
|
},
|
|
|
|
|
crate::app::Message::RecentThumbsLoaded,
|
|
|
|
|
);
|
2026-07-21 10:06:55 +03:00
|
|
|
}
|
|
|
|
|
#[cfg(not(target_arch = "wasm32"))]
|
|
|
|
|
{
|
|
|
|
|
let (tx, rx) = iced::futures::channel::oneshot::channel();
|
|
|
|
|
std::thread::spawn(move || {
|
|
|
|
|
let thumbs: Vec<_> = missing
|
|
|
|
|
.into_iter()
|
|
|
|
|
.map(|p| {
|
|
|
|
|
let h = crate::io::thumbnail::read_handle(&p);
|
|
|
|
|
(p, h)
|
|
|
|
|
})
|
|
|
|
|
.collect();
|
|
|
|
|
let _ = tx.send(thumbs);
|
|
|
|
|
});
|
|
|
|
|
iced::Task::perform(
|
|
|
|
|
async move { rx.await.unwrap_or_default() },
|
|
|
|
|
crate::app::Message::RecentThumbsLoaded,
|
|
|
|
|
)
|
2026-07-10 23:03:23 +03:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
feat(ui): replace app-menu logo with a quick-access file toolbar
Remove the OCS-logo button and the dropdown menu it opened; the top strip
now shows direct New / Open / Save / Save As / Print buttons ahead of the
undo/redo controls. Drop the HELP and OPTIONS commands (HELP dumped text to
the command line, OPTIONS aliased the drafting-settings popup).
The app-menu overlay is gone, so its rendering code, MENU_ITEMS, four dead
messages, and the LOGO_RED / GEAR / HELP assets are removed. The recents
list it held is the only survivor — moved into OpenCADStudio.recent_files
via a new app/recent.rs, backing the Start page's Recent Documents panel.
Quick-access icons are redrawn in a cleaner style (file-plus, folder-open,
device-floppy, file-export, printer) and tinted light so they read on the
dark strip; FOLDER / DOC keep their old glyphs for the file browser.
Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
2026-07-03 09:51:49 +03:00
|
|
|
/// Drop a path from the recents list (manual removal from the Start page).
|
|
|
|
|
pub(super) fn remove_recent(&mut self, path: &Path) {
|
|
|
|
|
self.recent_files.retain(|r| r.as_path() != path);
|
2026-07-29 01:09:13 +03:00
|
|
|
self.recent_thumbs.remove(path);
|
2026-07-29 00:41:51 +03:00
|
|
|
remove_cached_copies([path.to_path_buf()]);
|
refactor(config): consolidate settings into one grouped settings.json
App preferences were spread across six flat plain-text files (settings.txt,
recent.txt, recent_limit.txt, statusbar.txt, ribbon.txt, plot.txt), each with a
bespoke line parser and no grouping. Replace them with a single grouped JSON,
serialized via serde (enabling the derive feature; serde_json was already a
dependency).
- New app/config.rs: AppConfig { settings, recent, statusbar, ribbon, plot } →
<config>/settings.json (pretty JSON), load()/save().
- Make UserSettings, StatusBarConfig/StatusPill, CollapseMode and
PlotDialogState serde-derived; #[serde(skip)] marks the plot dialog's runtime
fields so only print preferences persist. Their bespoke .txt load/save is
removed.
- App gains current_config/apply_config/save_config: one AppConfig::load at
startup distributes into live state; every settings-change site
(persist_settings_if_changed, recent add/remove/limit, status-bar pill
toggle, ribbon density, plot commit) routes through save_config, which diffs
against the last write to avoid thrashing.
- Clean start: the old flat files are ignored (no migration). ocad.pgp stays a
separate hand-editable file.
Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
2026-07-10 16:41:34 +03:00
|
|
|
self.save_config();
|
feat(ui): replace app-menu logo with a quick-access file toolbar
Remove the OCS-logo button and the dropdown menu it opened; the top strip
now shows direct New / Open / Save / Save As / Print buttons ahead of the
undo/redo controls. Drop the HELP and OPTIONS commands (HELP dumped text to
the command line, OPTIONS aliased the drafting-settings popup).
The app-menu overlay is gone, so its rendering code, MENU_ITEMS, four dead
messages, and the LOGO_RED / GEAR / HELP assets are removed. The recents
list it held is the only survivor — moved into OpenCADStudio.recent_files
via a new app/recent.rs, backing the Start page's Recent Documents panel.
Quick-access icons are redrawn in a cleaner style (file-plus, folder-open,
device-floppy, file-export, printer) and tinted light so they read on the
dark strip; FOLDER / DOC keep their old glyphs for the file browser.
Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
2026-07-03 09:51:49 +03:00
|
|
|
}
|
2026-07-06 01:06:01 +03:00
|
|
|
|
|
|
|
|
/// Set how many recent files are kept, trim the current list to fit, and
|
refactor(config): consolidate settings into one grouped settings.json
App preferences were spread across six flat plain-text files (settings.txt,
recent.txt, recent_limit.txt, statusbar.txt, ribbon.txt, plot.txt), each with a
bespoke line parser and no grouping. Replace them with a single grouped JSON,
serialized via serde (enabling the derive feature; serde_json was already a
dependency).
- New app/config.rs: AppConfig { settings, recent, statusbar, ribbon, plot } →
<config>/settings.json (pretty JSON), load()/save().
- Make UserSettings, StatusBarConfig/StatusPill, CollapseMode and
PlotDialogState serde-derived; #[serde(skip)] marks the plot dialog's runtime
fields so only print preferences persist. Their bespoke .txt load/save is
removed.
- App gains current_config/apply_config/save_config: one AppConfig::load at
startup distributes into live state; every settings-change site
(persist_settings_if_changed, recent add/remove/limit, status-bar pill
toggle, ribbon density, plot commit) routes through save_config, which diffs
against the last write to avoid thrashing.
- Clean start: the old flat files are ignored (no migration). ocad.pgp stays a
separate hand-editable file.
Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
2026-07-10 16:41:34 +03:00
|
|
|
/// persist both.
|
2026-07-06 01:06:01 +03:00
|
|
|
pub(super) fn set_recent_limit(&mut self, limit: usize) {
|
|
|
|
|
self.recent_limit = limit.clamp(RECENT_MIN, RECENT_MAX);
|
2026-07-29 00:41:51 +03:00
|
|
|
let evicted = self
|
|
|
|
|
.recent_files
|
|
|
|
|
.split_off(self.recent_limit.min(self.recent_files.len()));
|
2026-07-29 01:09:13 +03:00
|
|
|
for path in &evicted {
|
|
|
|
|
self.recent_thumbs.remove(path);
|
|
|
|
|
}
|
2026-07-29 00:41:51 +03:00
|
|
|
remove_cached_copies(evicted);
|
refactor(config): consolidate settings into one grouped settings.json
App preferences were spread across six flat plain-text files (settings.txt,
recent.txt, recent_limit.txt, statusbar.txt, ribbon.txt, plot.txt), each with a
bespoke line parser and no grouping. Replace them with a single grouped JSON,
serialized via serde (enabling the derive feature; serde_json was already a
dependency).
- New app/config.rs: AppConfig { settings, recent, statusbar, ribbon, plot } →
<config>/settings.json (pretty JSON), load()/save().
- Make UserSettings, StatusBarConfig/StatusPill, CollapseMode and
PlotDialogState serde-derived; #[serde(skip)] marks the plot dialog's runtime
fields so only print preferences persist. Their bespoke .txt load/save is
removed.
- App gains current_config/apply_config/save_config: one AppConfig::load at
startup distributes into live state; every settings-change site
(persist_settings_if_changed, recent add/remove/limit, status-bar pill
toggle, ribbon density, plot commit) routes through save_config, which diffs
against the last write to avoid thrashing.
- Clean start: the old flat files are ignored (no migration). ocad.pgp stays a
separate hand-editable file.
Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
2026-07-10 16:41:34 +03:00
|
|
|
self.save_config();
|
2026-07-06 01:06:01 +03:00
|
|
|
}
|
feat(ui): replace app-menu logo with a quick-access file toolbar
Remove the OCS-logo button and the dropdown menu it opened; the top strip
now shows direct New / Open / Save / Save As / Print buttons ahead of the
undo/redo controls. Drop the HELP and OPTIONS commands (HELP dumped text to
the command line, OPTIONS aliased the drafting-settings popup).
The app-menu overlay is gone, so its rendering code, MENU_ITEMS, four dead
messages, and the LOGO_RED / GEAR / HELP assets are removed. The recents
list it held is the only survivor — moved into OpenCADStudio.recent_files
via a new app/recent.rs, backing the Start page's Recent Documents panel.
Quick-access icons are redrawn in a cleaner style (file-plus, folder-open,
device-floppy, file-export, printer) and tinted light so they read on the
dark strip; FOLDER / DOC keep their old glyphs for the file browser.
Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
2026-07-03 09:51:49 +03:00
|
|
|
}
|
2026-07-29 00:41:51 +03:00
|
|
|
|
|
|
|
|
fn remove_cached_copies(paths: impl IntoIterator<Item = PathBuf>) {
|
|
|
|
|
#[cfg(not(target_arch = "wasm32"))]
|
|
|
|
|
let _ = paths;
|
|
|
|
|
|
|
|
|
|
#[cfg(target_arch = "wasm32")]
|
|
|
|
|
for path in paths {
|
|
|
|
|
let Some(name) = path
|
|
|
|
|
.file_name()
|
|
|
|
|
.map(|name| name.to_string_lossy().into_owned())
|
|
|
|
|
else {
|
|
|
|
|
continue;
|
|
|
|
|
};
|
|
|
|
|
wasm_bindgen_futures::spawn_local(async move {
|
|
|
|
|
let _ = crate::io::web_recent::remove(&name).await;
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
}
|