mirror of
https://github.com/storytold/photocraft.git
synced 2026-11-11 16:38:24 -06:00
Hiding Edit › Menus (or Keyboard Shortcuts) left no way back into the dialog, and Save, Save As, Exit and Preferences could disappear too. edit.menus now refuses to hide them, the dialog greys their Visible box, and the menus keep them even when a preferences file lists them. Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
co-authored by
Claude Opus 5.5
parent
f053a924a6
commit
a7f7f1fd1e
@@ -954,6 +954,20 @@ pub struct MenuCustomization {
|
||||
pub colors: BTreeMap<String, String>,
|
||||
}
|
||||
|
||||
impl MenuCustomization {
|
||||
/// False for the items Edit › Menus can't hide (#5096): the way back into this dialog
|
||||
/// (Edit › Menus, Edit › Keyboard Shortcuts), Preferences, Save, Save As and Exit.
|
||||
pub fn hideable(id: &str) -> bool {
|
||||
!matches!(id, "edit.menus" | "edit.keyboardShortcuts" | "file.save" | "file.saveAs" | "file.exit") && !id.starts_with("edit.preferences")
|
||||
}
|
||||
|
||||
/// Whether the menus leave `id` out. Items that can't be hidden stay shown even when an
|
||||
/// older or hand-edited preferences file lists them.
|
||||
pub fn is_hidden(&self, id: &str) -> bool {
|
||||
Self::hideable(id) && self.hidden.iter().any(|h| h == id)
|
||||
}
|
||||
}
|
||||
|
||||
/// Edit › Toolbar: hidden tools and a custom order (tool names as in `ui.set {tool}`).
|
||||
#[derive(Clone, Debug, Default, PartialEq, Serialize, Deserialize)]
|
||||
#[serde(default, rename_all = "camelCase")]
|
||||
@@ -1898,6 +1912,9 @@ fn menus(s: &mut Session, p: &Value) -> Result<Value> {
|
||||
}
|
||||
}
|
||||
let (hide, show) = (ids("hide"), ids("show"));
|
||||
if let Some(id) = hide.iter().find(|id| !MenuCustomization::hideable(id)) {
|
||||
return Err(bad("edit.menus", format!("`{id}` can't be hidden")));
|
||||
}
|
||||
s.edit_prefs(|pr| {
|
||||
if p.get("reset").and_then(Value::as_bool) == Some(true) {
|
||||
pr.menus = MenuCustomization::default();
|
||||
|
||||
@@ -397,6 +397,19 @@ fn menus_and_toolbar_customisation_persist() {
|
||||
assert_eq!(back.toolbar.hidden, vec!["Sponge".to_string()]);
|
||||
}
|
||||
|
||||
/// #5096: Edit › Menus can't hide the way back into itself, Preferences, Save or Exit.
|
||||
#[test]
|
||||
fn menus_refuse_to_hide_essential_items() {
|
||||
let mut s = session();
|
||||
for id in ["edit.menus", "edit.keyboardShortcuts", "edit.preferences.general", "file.save", "file.saveAs", "file.exit"] {
|
||||
assert!(s.execute("edit.menus", json!({"hide": ["edit.fade", id]})).is_err(), "{id}");
|
||||
assert!(s.prefs().menus.hidden.is_empty(), "{id}: a refused call changes nothing");
|
||||
}
|
||||
// A preferences file that lists them anyway still shows them.
|
||||
let menus = MenuCustomization { hidden: vec!["file.exit".into(), "edit.fade".into()], ..Default::default() };
|
||||
assert!(!menus.is_hidden("file.exit") && menus.is_hidden("edit.fade"));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn preference_sections_are_commands() {
|
||||
let mut s = Session::new();
|
||||
|
||||
@@ -1111,7 +1111,7 @@ pub fn menu_items(app: &PhotocraftApp) -> Vec<MenuItem> {
|
||||
}
|
||||
}
|
||||
if !prefs.menus.hidden.is_empty() {
|
||||
items.retain(|i| !prefs.menus.hidden.contains(&i.id));
|
||||
items.retain(|i| !prefs.menus.is_hidden(&i.id));
|
||||
}
|
||||
if prefs.interface.show_menu_colors {
|
||||
for it in &mut items {
|
||||
|
||||
@@ -1753,8 +1753,10 @@ fn shortcuts_body(app: &mut PhotocraftApp, ui: &mut egui::Ui, f: &mut Map<String
|
||||
}
|
||||
ui.label(if changed { RichText::new(tl!("modified")).color(t.text_faint).size(10.5) } else { RichText::new("") });
|
||||
} else {
|
||||
let mut visible = !hidden.contains(id);
|
||||
crate::widgets::checkbox(ui, &mut visible, tl!("Visible"));
|
||||
// Edit › Menus, Keyboard Shortcuts, Preferences, Save and Exit always stay (#5096).
|
||||
let hideable = photocraft_engine::prefs::MenuCustomization::hideable(id);
|
||||
let mut visible = !hideable || !hidden.contains(id);
|
||||
ui.add_enabled_ui(hideable, |ui| crate::widgets::checkbox(ui, &mut visible, tl!("Visible")));
|
||||
if visible {
|
||||
hidden.retain(|h| h != id);
|
||||
} else if !hidden.contains(id) {
|
||||
@@ -3183,6 +3185,16 @@ mod tests {
|
||||
assert!(!crate::menus::menu_items(&app).iter().any(|i| i.id == "edit.fade"));
|
||||
}
|
||||
|
||||
/// #5096: preferences that list Edit › Menus or File › Exit as hidden still show them.
|
||||
#[test]
|
||||
fn essential_menu_items_stay_visible() {
|
||||
let (mut app, _) = app_with_store();
|
||||
app.run("prefs.set", json!({"values": {"menus": {"hidden": ["edit.menus", "file.exit", "edit.fade"], "colors": {}}}})).unwrap();
|
||||
let items = crate::menus::menu_items(&app);
|
||||
assert!(items.iter().any(|i| i.id == "edit.menus") && items.iter().any(|i| i.id == "file.exit"));
|
||||
assert!(!items.iter().any(|i| i.id == "edit.fade"));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn autosave_runs_for_dirty_documents() {
|
||||
type Saved = Arc<Mutex<Vec<(u64, u64)>>>;
|
||||
|
||||
Reference in New Issue
Block a user