mirror of
https://github.com/storytold/deckcraft.git
synced 2026-12-05 22:59:52 +00:00
Merge pull request #2734
This commit is contained in:
@@ -229,7 +229,7 @@ pub(crate) fn slide_menu(ui: &mut Ui, app: &mut SlideApp, key: u64, opener: &Res
|
||||
menu = menu.anchor(anchor);
|
||||
}
|
||||
}
|
||||
let out = menu.show(ui, |ui, _| {
|
||||
let out = menu.show(ui, |ui, cx| {
|
||||
if !craft::ui::runtime::measure::active(ui.ctx())
|
||||
&& app
|
||||
.session
|
||||
@@ -258,6 +258,8 @@ pub(crate) fn slide_menu(ui: &mut Ui, app: &mut SlideApp, key: u64, opener: &Res
|
||||
let _ = MenuItem::command(pane).label(tl!("Format Background…")).show(ui);
|
||||
// The row toggles every selected slide, as the ribbon's toggle does, so it reads "Show Slide" only when every
|
||||
// slide it targets is already hidden; a mixed selection hides. The targets are the engine's `slide.hide` ones.
|
||||
// It stays a plain item: that command's checked state follows the current slide alone, so borrowing it would
|
||||
// stamp a selection-wide row with one slide's on/off mark, against the label here.
|
||||
let all_hidden = app.session.active().is_some_and(|state| {
|
||||
let sel = &state.selection;
|
||||
let mut targets: Vec<usize> = sel.slides.iter().filter_map(|id| state.doc.slide_index(*id)).collect();
|
||||
@@ -267,7 +269,10 @@ pub(crate) fn slide_menu(ui: &mut Ui, app: &mut SlideApp, key: u64, opener: &Res
|
||||
targets.iter().all(|at| state.doc.slides.get(*at).is_some_and(|slide| slide.hidden))
|
||||
});
|
||||
let label = if all_hidden { words.show_slide.clone() } else { words.hide_slide.clone() };
|
||||
let _ = MenuItem::command(CommandRef::new("slide.hide")).label(label).show(ui);
|
||||
if MenuItem::new(label).show(ui).ran {
|
||||
let _ = app.run("slide.hide", json!({}));
|
||||
cx.request_close();
|
||||
}
|
||||
});
|
||||
if out.closed.is_some() && requested {
|
||||
app.pane_menu = None;
|
||||
@@ -546,22 +551,47 @@ mod tests {
|
||||
// A half-hidden selection offers to hide, as the engine's all-hidden toggle does.
|
||||
h.state_mut().pane_menu = Some(("thumbs".into(), 0));
|
||||
h.run_steps(4);
|
||||
assert!(h.query_by_role_and_label(Role::MenuItemCheckBox, words.show_slide.as_str()).is_none(), "a mixed selection reads Hide Slide");
|
||||
assert!(h.query_by_label(words.show_slide.as_str()).is_none(), "a mixed selection reads Hide Slide");
|
||||
let undo = deck(&h)?.history.undo.len();
|
||||
h.get_by_role_and_label(Role::MenuItemCheckBox, words.hide_slide.as_str()).click();
|
||||
h.get_by_label(words.hide_slide.as_str()).click();
|
||||
h.run_steps(3);
|
||||
let flags: Vec<bool> = deck(&h)?.doc.slides.iter().map(|slide| slide.hidden).collect();
|
||||
assert_eq!(flags, [true, true, true, false], "the click hides every selected slide, not only the one it opened on");
|
||||
assert_eq!(deck(&h)?.history.undo.len(), undo + 1, "hiding a whole selection is one undo step");
|
||||
h.state_mut().pane_menu = Some(("thumbs".into(), 0));
|
||||
h.run_steps(4);
|
||||
h.get_by_role_and_label(Role::MenuItemCheckBox, words.show_slide.as_str()).click();
|
||||
h.get_by_label(words.show_slide.as_str()).click();
|
||||
h.run_steps(3);
|
||||
let flags: Vec<bool> = deck(&h)?.doc.slides.iter().map(|slide| slide.hidden).collect();
|
||||
assert_eq!(flags, [false, false, false, false], "a second click shows the whole selection again");
|
||||
Ok(())
|
||||
}
|
||||
|
||||
/// The slide menu's Hide/Show row names a selection-wide action, so it carries no on/off mark: the bare command's
|
||||
/// checked state follows only the current slide, and that would contradict the row whenever a mixed selection is
|
||||
/// led by a hidden slide.
|
||||
#[test]
|
||||
fn the_slide_menu_hide_row_carries_no_single_slide_toggle() -> Result<(), String> {
|
||||
let words = ThumbWords::english();
|
||||
let mut h = editor(slides(4)?, 900.0);
|
||||
h.state_mut().run("slide.hide", json!({"index": 0, "hidden": true}))?;
|
||||
// A backward range makes the hidden slide 0 the current one, leading a selection that is only half hidden.
|
||||
h.state_mut().run("slide.selectRange", json!({"from": 2, "to": 0}))?;
|
||||
assert_eq!(deck(&h)?.selection.slide, 0, "the range's end is the current slide");
|
||||
h.run_steps(3);
|
||||
h.state_mut().pane_menu = Some(("thumbs".into(), 0));
|
||||
h.run_steps(4);
|
||||
let row = h.get_by_label(words.hide_slide.as_str());
|
||||
assert_eq!(row.accesskit_node().toggled(), None, "a selection-wide row shows no current slide's mark");
|
||||
let undo = deck(&h)?.history.undo.len();
|
||||
row.click();
|
||||
h.run_steps(3);
|
||||
let flags: Vec<bool> = deck(&h)?.doc.slides.iter().map(|slide| slide.hidden).collect();
|
||||
assert_eq!(flags, [true, true, true, false], "the label it showed is what the click did");
|
||||
assert_eq!(deck(&h)?.history.undo.len(), undo + 1, "the whole selection flips in one undo step");
|
||||
Ok(())
|
||||
}
|
||||
|
||||
/// A header counts in the grid's destination, but never in the engine's slide order.
|
||||
#[test]
|
||||
fn slides_move_dest_counts_without_the_moved_slides() -> Result<(), String> {
|
||||
|
||||
Reference in New Issue
Block a user