feat(ui): unified modal dispatch; migrate 4 dialogs (Plan B)
Replace the per-dialog open flag with a single `active_modal: Option<ModalKind>` and one `CloseModal` message. view_main matches it to render the open dialog as an in-canvas modal. Migrated off OS windows: About (content-sized), Shortcuts, Plugin Manager and the Update notice (the latter three keep a bounded size via a wrapping container, since their lists/scroll need defined bounds). Native + web build; 75 tests pass. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
This commit is contained in:
parent
e6213eafbb
commit
6a3663b3f1
3 changed files with 70 additions and 70 deletions
|
|
@ -294,8 +294,9 @@ pub(super) struct OpenCADStudio {
|
||||||
color_pick_target: Option<ColorPickTarget>,
|
color_pick_target: Option<ColorPickTarget>,
|
||||||
shortcuts_window: Option<window::Id>,
|
shortcuts_window: Option<window::Id>,
|
||||||
about_window: Option<window::Id>,
|
about_window: Option<window::Id>,
|
||||||
/// In-canvas About modal (Plan B: shared overlay instead of an OS window).
|
/// The open in-canvas modal dialog, if any (Plan B: shared overlay instead
|
||||||
about_open: bool,
|
/// of OS windows).
|
||||||
|
active_modal: Option<ModalKind>,
|
||||||
plugin_manager_window: Option<window::Id>,
|
plugin_manager_window: Option<window::Id>,
|
||||||
/// New-release notification window — opened on startup when the
|
/// New-release notification window — opened on startup when the
|
||||||
/// GitHub releases API reports a newer version than this build.
|
/// GitHub releases API reports a newer version than this build.
|
||||||
|
|
@ -587,6 +588,17 @@ pub enum ColorPickTarget {
|
||||||
Layer(usize),
|
Layer(usize),
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Which in-canvas modal dialog is currently open (Plan B). At most one shows
|
||||||
|
/// at a time; dialog-specific data lives in its own fields. Closed via the
|
||||||
|
/// modal's ✕ (`Message::CloseModal`).
|
||||||
|
#[derive(Clone, Copy, PartialEq, Eq)]
|
||||||
|
pub enum ModalKind {
|
||||||
|
About,
|
||||||
|
Shortcuts,
|
||||||
|
PluginManager,
|
||||||
|
UpdateNotice,
|
||||||
|
}
|
||||||
|
|
||||||
/// Identifies a DimStyle field that can be edited in the dialog.
|
/// Identifies a DimStyle field that can be edited in the dialog.
|
||||||
#[derive(Debug, Clone, PartialEq, Eq)]
|
#[derive(Debug, Clone, PartialEq, Eq)]
|
||||||
pub enum DsField {
|
pub enum DsField {
|
||||||
|
|
@ -994,7 +1006,8 @@ pub enum Message {
|
||||||
ShortcutsPanelClose,
|
ShortcutsPanelClose,
|
||||||
// ── About window ────────────────────────────────────────────────────
|
// ── About window ────────────────────────────────────────────────────
|
||||||
AboutOpen,
|
AboutOpen,
|
||||||
AboutClose,
|
/// Close whatever in-canvas modal dialog is open (Plan B).
|
||||||
|
CloseModal,
|
||||||
AboutCopyInfo,
|
AboutCopyInfo,
|
||||||
// ── Plugin Manager window ───────────────────────────────────────────
|
// ── Plugin Manager window ───────────────────────────────────────────
|
||||||
PluginManagerOpen,
|
PluginManagerOpen,
|
||||||
|
|
@ -1416,7 +1429,7 @@ impl OpenCADStudio {
|
||||||
color_pick_target: None,
|
color_pick_target: None,
|
||||||
shortcuts_window: None,
|
shortcuts_window: None,
|
||||||
about_window: None,
|
about_window: None,
|
||||||
about_open: false,
|
active_modal: None,
|
||||||
plugin_manager_window: None,
|
plugin_manager_window: None,
|
||||||
update_notice_window: None,
|
update_notice_window: None,
|
||||||
assoc_prompt_window: None,
|
assoc_prompt_window: None,
|
||||||
|
|
|
||||||
|
|
@ -5449,34 +5449,22 @@ impl OpenCADStudio {
|
||||||
|
|
||||||
// ── Keyboard Shortcuts Panel ──────────────────────────────────────
|
// ── Keyboard Shortcuts Panel ──────────────────────────────────────
|
||||||
Message::ShortcutsPanelOpen => {
|
Message::ShortcutsPanelOpen => {
|
||||||
if let Some(id) = self.shortcuts_window {
|
self.active_modal = Some(super::ModalKind::Shortcuts);
|
||||||
return window::gain_focus(id);
|
|
||||||
}
|
|
||||||
let (id, task) = window::open(window::Settings {
|
|
||||||
size: iced::Size::new(720.0, 520.0),
|
|
||||||
resizable: true,
|
|
||||||
level: window::Level::AlwaysOnTop,
|
|
||||||
..Default::default()
|
|
||||||
});
|
|
||||||
self.shortcuts_window = Some(id);
|
|
||||||
task.map(|_| Message::Noop)
|
|
||||||
}
|
|
||||||
Message::ShortcutsPanelClose => {
|
|
||||||
if let Some(id) = self.shortcuts_window.take() {
|
|
||||||
window::close(id)
|
|
||||||
} else {
|
|
||||||
Task::none()
|
Task::none()
|
||||||
}
|
}
|
||||||
|
Message::ShortcutsPanelClose => {
|
||||||
|
self.active_modal = None;
|
||||||
|
Task::none()
|
||||||
}
|
}
|
||||||
|
|
||||||
// ── About window ──────────────────────────────────────────────
|
// ── About window ──────────────────────────────────────────────
|
||||||
Message::AboutOpen => {
|
Message::AboutOpen => {
|
||||||
self.about_open = true;
|
self.active_modal = Some(super::ModalKind::About);
|
||||||
Task::none()
|
Task::none()
|
||||||
}
|
}
|
||||||
|
|
||||||
Message::AboutClose => {
|
Message::CloseModal => {
|
||||||
self.about_open = false;
|
self.active_modal = None;
|
||||||
Task::none()
|
Task::none()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -5492,24 +5480,12 @@ impl OpenCADStudio {
|
||||||
|
|
||||||
// ── Plugin Manager window ─────────────────────────────────────
|
// ── Plugin Manager window ─────────────────────────────────────
|
||||||
Message::PluginManagerOpen => {
|
Message::PluginManagerOpen => {
|
||||||
if let Some(id) = self.plugin_manager_window {
|
self.active_modal = Some(super::ModalKind::PluginManager);
|
||||||
return window::gain_focus(id);
|
|
||||||
}
|
|
||||||
let (id, task) = window::open(window::Settings {
|
|
||||||
size: iced::Size::new(520.0, 460.0),
|
|
||||||
resizable: true,
|
|
||||||
level: window::Level::AlwaysOnTop,
|
|
||||||
..Default::default()
|
|
||||||
});
|
|
||||||
self.plugin_manager_window = Some(id);
|
|
||||||
task.map(|_| Message::Noop)
|
|
||||||
}
|
|
||||||
Message::PluginManagerClose => {
|
|
||||||
if let Some(id) = self.plugin_manager_window.take() {
|
|
||||||
window::close(id)
|
|
||||||
} else {
|
|
||||||
Task::none()
|
Task::none()
|
||||||
}
|
}
|
||||||
|
Message::PluginManagerClose => {
|
||||||
|
self.active_modal = None;
|
||||||
|
Task::none()
|
||||||
}
|
}
|
||||||
|
|
||||||
Message::EnterViewport(handle) => {
|
Message::EnterViewport(handle) => {
|
||||||
|
|
@ -5788,36 +5764,18 @@ impl OpenCADStudio {
|
||||||
};
|
};
|
||||||
self.update_notice_version = Some(info.version);
|
self.update_notice_version = Some(info.version);
|
||||||
self.update_notice_body = Some(info.body);
|
self.update_notice_body = Some(info.body);
|
||||||
if let Some(id) = self.update_notice_window {
|
self.active_modal = Some(super::ModalKind::UpdateNotice);
|
||||||
return window::gain_focus(id);
|
|
||||||
}
|
|
||||||
let (id, task) = window::open(window::Settings {
|
|
||||||
// Sized for the new release-notes panel — wide enough
|
|
||||||
// for typical GitHub release headlines, tall enough for
|
|
||||||
// a meaningful scroll preview without dwarfing the app.
|
|
||||||
size: iced::Size::new(560.0, 460.0),
|
|
||||||
resizable: true,
|
|
||||||
level: window::Level::AlwaysOnTop,
|
|
||||||
..Default::default()
|
|
||||||
});
|
|
||||||
self.update_notice_window = Some(id);
|
|
||||||
task.map(|_| Message::Noop)
|
|
||||||
}
|
|
||||||
Message::UpdateNoticeClose => {
|
|
||||||
if let Some(id) = self.update_notice_window.take() {
|
|
||||||
window::close(id)
|
|
||||||
} else {
|
|
||||||
Task::none()
|
Task::none()
|
||||||
}
|
}
|
||||||
|
Message::UpdateNoticeClose => {
|
||||||
|
self.active_modal = None;
|
||||||
|
Task::none()
|
||||||
}
|
}
|
||||||
Message::UpdateNoticeOpenRelease => {
|
Message::UpdateNoticeOpenRelease => {
|
||||||
crate::sys::open_url(crate::update_check::RELEASES_PAGE);
|
crate::sys::open_url(crate::update_check::RELEASES_PAGE);
|
||||||
if let Some(id) = self.update_notice_window.take() {
|
self.active_modal = None;
|
||||||
window::close(id)
|
|
||||||
} else {
|
|
||||||
Task::none()
|
Task::none()
|
||||||
}
|
}
|
||||||
}
|
|
||||||
Message::AssocPromptYes => {
|
Message::AssocPromptYes => {
|
||||||
self.mark_assoc_prompted();
|
self.mark_assoc_prompted();
|
||||||
let close = if let Some(id) = self.assoc_prompt_window.take() {
|
let close = if let Some(id) = self.assoc_prompt_window.take() {
|
||||||
|
|
|
||||||
|
|
@ -1517,14 +1517,43 @@ impl OpenCADStudio {
|
||||||
// ── In-canvas modal dialogs (Plan B) ───────────────────────────────
|
// ── In-canvas modal dialogs (Plan B) ───────────────────────────────
|
||||||
// Former pop-up windows render as overlays here, so they work on both
|
// Former pop-up windows render as overlays here, so they work on both
|
||||||
// the native (single main window) and web builds.
|
// the native (single main window) and web builds.
|
||||||
if self.about_open {
|
use crate::ui::modal::modal;
|
||||||
crate::ui::modal::modal(
|
match self.active_modal {
|
||||||
|
Some(super::ModalKind::About) => {
|
||||||
|
modal(composed, crate::ui::about::view_window(), Message::CloseModal)
|
||||||
|
}
|
||||||
|
Some(super::ModalKind::Shortcuts) => modal(
|
||||||
composed,
|
composed,
|
||||||
crate::ui::about::view_window(),
|
// Content-heavy dialogs (lists / scroll) keep a bounded size —
|
||||||
Message::AboutClose,
|
// their inner `Fill` widgets fill it — instead of shrinking.
|
||||||
|
iced::widget::container(crate::ui::shortcuts::view_window(
|
||||||
|
&self.shortcut_overrides,
|
||||||
|
))
|
||||||
|
.width(720)
|
||||||
|
.height(520),
|
||||||
|
Message::CloseModal,
|
||||||
|
),
|
||||||
|
Some(super::ModalKind::PluginManager) => modal(
|
||||||
|
composed,
|
||||||
|
iced::widget::container(crate::ui::plugin_manager::view_window(
|
||||||
|
&crate::plugin::installed_manifests(),
|
||||||
|
))
|
||||||
|
.width(520)
|
||||||
|
.height(460),
|
||||||
|
Message::CloseModal,
|
||||||
|
),
|
||||||
|
Some(super::ModalKind::UpdateNotice) => {
|
||||||
|
let latest = self.update_notice_version.as_deref().unwrap_or("?");
|
||||||
|
let body = self.update_notice_body.as_deref().unwrap_or("");
|
||||||
|
modal(
|
||||||
|
composed,
|
||||||
|
iced::widget::container(crate::ui::update_notice::view_window(latest, body))
|
||||||
|
.width(560)
|
||||||
|
.height(460),
|
||||||
|
Message::CloseModal,
|
||||||
)
|
)
|
||||||
} else {
|
}
|
||||||
composed.into()
|
None => composed.into(),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue