* claim: #7188 * macOS menu: disable design commands behind an open Report a bug draft (#7188) The native menu bar kept running its actions while a Report a bug draft was open, although the app's own toolbar and shortcuts wait behind it: Edit > Undo or Cmd+Z removed the last feature, so the report described a design that no longer existed. FileAction::enabled now refuses every action but Quit while a draft is open. Settings, Keyboard Shortcuts and Agent Chat are refused too: their windows open over the report but take no input until it closes. The menu's Undo and Redo still go to a focused report field (FileAction::menu_enabled), which no longer leans on Settings being enabled. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> * Menus: Quit and Help's windows wait behind an open Report a bug draft Quit switched to the first design with unsaved changes under the draft and asked about it in a prompt that can't be answered while the report blocks the app; with nothing unsaved it quit and lost the typed report. Like any modal window, the draft now turns Quit off. Help's items that open a window (About, Keyboard Shortcuts, Messages, Crash Reports, Connect AI assistants) wait too, in the native menu and in the app's Help menu; Documentation and Report an Issue… stay. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> --------- Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
@@ -146,8 +146,7 @@ impl NativeMenu {
|
||||
}
|
||||
|
||||
fn action_enabled(action: &FileAction, app: &SolveApp, ctx: &egui::Context) -> bool {
|
||||
action.enabled(app)
|
||||
|| (matches!(action, FileAction::Undo | FileAction::Redo) && ctx.egui_wants_keyboard_input() && FileAction::Settings.enabled(app))
|
||||
action.menu_enabled(app, ctx.egui_wants_keyboard_input())
|
||||
}
|
||||
|
||||
pub fn tick(&mut self, app: &mut SolveApp, ctx: &egui::Context) {
|
||||
@@ -157,6 +156,12 @@ impl NativeMenu {
|
||||
item.set_enabled(enabled);
|
||||
}
|
||||
}
|
||||
for (item, action) in &self.help_actions {
|
||||
let enabled = solidcraft_ui_egui::help::available(app, action);
|
||||
if item.is_enabled() != enabled {
|
||||
item.set_enabled(enabled);
|
||||
}
|
||||
}
|
||||
if !self.recent_paths.iter().eq(app.home.recent.iter().take(32))
|
||||
&& let Err(error) = self.update_recent(app)
|
||||
{
|
||||
|
||||
@@ -40,9 +40,18 @@ pub fn diagnostics(app: &SolveApp) -> String {
|
||||
)
|
||||
}
|
||||
|
||||
/// Whether a Help menu item can run now: behind an open bug report, the items that open a
|
||||
/// window would cover it (#7188). Report an Issue… shows the report.
|
||||
pub fn available(app: &SolveApp, item: &str) -> bool {
|
||||
app.issue_report.draft.is_none() || !matches!(item, "about" | "shortcuts" | "messages" | "crashes" | "connect")
|
||||
}
|
||||
|
||||
/// Run a Help menu item: `docs`, `about`, `shortcuts`, `messages`, `report`, `crashes`, `connect`, `install_cli` (macOS).
|
||||
pub fn run(app: &mut SolveApp, ctx: &egui::Context, item: &str) {
|
||||
app.help.menu = false;
|
||||
if !available(app, item) {
|
||||
return;
|
||||
}
|
||||
match item {
|
||||
"docs" => ctx.open_url(egui::OpenUrl::new_tab(DOCS_URL)),
|
||||
"about" => app.help.about = true,
|
||||
@@ -131,7 +140,8 @@ pub fn show(app: &mut SolveApp, ctx: &egui::Context, anchor: egui::Pos2) {
|
||||
.into_iter()
|
||||
.filter(|(id, ..)| *id != "install_cli" || cfg!(target_os = "macos"))
|
||||
{
|
||||
if crate::context_menu::list_row(ui, &crate::context_menu::Item::action(id, label, icon)).is_some() {
|
||||
let item = crate::context_menu::Item::action(id, label, icon).on_if(available(app, id));
|
||||
if crate::context_menu::list_row(ui, &item).is_some() {
|
||||
pick = Some(id);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -529,10 +529,14 @@ pub enum FileAction {
|
||||
}
|
||||
|
||||
impl FileAction {
|
||||
/// Whether this action is available in the current document and picker state.
|
||||
/// Whether this action is available in the current document, picker and report state.
|
||||
pub fn enabled(&self, app: &SolveApp) -> bool {
|
||||
let needs_design = matches!(self, Self::Save | Self::SaveAs | Self::Undo | Self::Redo | Self::ExportMesh(_) | Self::Command(_))
|
||||
|| matches!(self, Self::Export(extension) if *extension != "json");
|
||||
// An open bug report describes the designs as they are, and a window opened behind it
|
||||
// covers it (#7188). Quit too, as behind any modal window: it would switch to a design
|
||||
// with unsaved changes under the report, and ask about it where it can't be answered.
|
||||
let behind_report = app.issue_report.draft.is_some();
|
||||
let available = match self {
|
||||
Self::Undo => !app.session.undo.is_empty(),
|
||||
Self::Redo => !app.session.redo.is_empty(),
|
||||
@@ -540,7 +544,13 @@ impl FileAction {
|
||||
Self::AgentChat => crate::agent_chat::app_bar_button_shown(app),
|
||||
_ => true,
|
||||
};
|
||||
!app.file_picker_busy() && !app.file_load.busy() && (!needs_design || design_shown(app)) && available
|
||||
!app.file_picker_busy() && !app.file_load.busy() && !behind_report && (!needs_design || design_shown(app)) && available
|
||||
}
|
||||
|
||||
/// Whether the native menu offers this action: while a widget has keyboard focus (a report's
|
||||
/// text field too), its Undo and Redo go to that widget instead of the design.
|
||||
pub fn menu_enabled(&self, app: &SolveApp, keyboard_focus: bool) -> bool {
|
||||
self.enabled(app) || (matches!(self, Self::Undo | Self::Redo) && keyboard_focus && !app.file_picker_busy() && !app.file_load.busy())
|
||||
}
|
||||
|
||||
/// Execute through the same document, save-job and preferences paths as the toolbar.
|
||||
@@ -2308,6 +2318,57 @@ mod header_report_tests {
|
||||
assert!(FileAction::Export("step").enabled(&h.app));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn native_menu_actions_are_disabled_behind_an_open_issue_report() {
|
||||
let mut h = crate::scenario::Harness::new();
|
||||
h.app.home.open = false;
|
||||
h.app.run("solid.box", json!({"length":2,"width":3,"height":4})).unwrap();
|
||||
h.app.home.recent = vec!["elsewhere.solidcraft".into()];
|
||||
h.app.issue_report.draft = Some(crate::issue_report::draft_for(&h.app, None, None));
|
||||
let before = (h.app.session.doc.to_json(), h.app.session.undo.len(), h.app.docs.count(), h.app.home.recent.clone());
|
||||
for action in [
|
||||
FileAction::Undo,
|
||||
FileAction::New,
|
||||
FileAction::Open,
|
||||
FileAction::OpenRecent("elsewhere.solidcraft".into()),
|
||||
FileAction::ClearRecent,
|
||||
FileAction::Command("file.insert_step"),
|
||||
FileAction::Save,
|
||||
FileAction::SaveAs,
|
||||
FileAction::SaveJson,
|
||||
FileAction::ExportMesh("stl"),
|
||||
FileAction::Export("step"),
|
||||
FileAction::Export("json"),
|
||||
FileAction::Command("document.metadata"),
|
||||
FileAction::Settings,
|
||||
FileAction::Shortcuts,
|
||||
FileAction::AgentChat,
|
||||
] {
|
||||
assert!(!action.enabled(&h.app), "{action:?} behind the report");
|
||||
action.run(&mut h.app);
|
||||
}
|
||||
assert_eq!(before, (h.app.session.doc.to_json(), h.app.session.undo.len(), h.app.docs.count(), h.app.home.recent.clone()));
|
||||
assert!(h.app.dialog.is_none() && h.app.file_picker.is_none() && !h.app.prefs_window.open && !h.app.keymap.open && !h.app.agent_chat.open);
|
||||
// A focused report field still gets the menu's Undo and Redo.
|
||||
assert!(FileAction::Undo.menu_enabled(&h.app, true) && !FileAction::Undo.menu_enabled(&h.app, false));
|
||||
assert!(!FileAction::Save.menu_enabled(&h.app, true));
|
||||
// Quit waits as behind any modal window: it would switch to a design with unsaved changes
|
||||
// under the report.
|
||||
assert!(!FileAction::Quit.enabled(&h.app));
|
||||
FileAction::Quit.run(&mut h.app);
|
||||
assert!(h.app.docs.quitting.is_none() && h.app.docs.closing.is_none());
|
||||
// Help's windows wait too; Report an Issue… shows the report.
|
||||
for item in ["about", "shortcuts", "messages", "crashes", "connect"] {
|
||||
assert!(!crate::help::available(&h.app, item), "{item}");
|
||||
crate::help::run(&mut h.app, &h.ctx, item);
|
||||
}
|
||||
assert!(!h.app.help.about && !h.app.keymap.open && !h.app.messages.open && h.app.help.connect.is_none());
|
||||
assert!(crate::help::available(&h.app, "report") && crate::help::available(&h.app, "docs"));
|
||||
h.app.issue_report.draft = None;
|
||||
assert!(FileAction::Undo.enabled(&h.app) && FileAction::Settings.enabled(&h.app) && FileAction::Quit.enabled(&h.app));
|
||||
assert!(crate::help::available(&h.app, "shortcuts"));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn native_menu_actions_share_json_save_and_recent_cleanup() {
|
||||
let mut h = crate::scenario::Harness::new();
|
||||
|
||||
Reference in New Issue
Block a user