mirror of
https://github.com/storytold/photocraft.git
synced 2026-12-02 06:20:48 +01:00
Home screen: window.home is available with a document open; Next and Previous Document leave Home
Self-review fixes (#16802): - `window.home` is enabled whenever a document is open (`menus::state::is_enabled`), instead of a command source routing the rail's click around the menu gate. Availability and the click now agree, and with no document open the click is still reported as unavailable, as before. - Window › Next Document and Previous Document (Ctrl+Tab) leave Home as choosing a document does. - The Window menu tests fire their rows through the gate a menu click passes, and the Home row test checks that nothing opened or closed rather than a count. Co-Authored-By: Claude Opus 5.5 <[email protected]> Claude-Session: https://claude.ai/code/session_01Gr84Vw42Y1h9tPLDK7SFRm
This commit is contained in:
1 parent
bdd5ae31c8
commit
eabb2e2781
4 files changed
+29
-19
No files matched your search
@@ -623,8 +623,6 @@ pub(crate) const COMMAND_SOURCES: &[CommandSource] = &[
|
||||
CommandSource { name: "artboard", states: crate::artboard_tool::source_states, run: crate::artboard_tool::run_fired },
|
||||
// Space+F: the pasteboard colour keys of the held Hand.
|
||||
CommandSource { name: "canvasColor", states: no_states, run: crate::canvas_tool_menu::run_canvas_color },
|
||||
// The Home screen rail's Home row fires `window.home` (#16802), which no menu item makes available.
|
||||
CommandSource { name: "home", states: no_states, run: run_home },
|
||||
// The options bar's engine-command buttons: their commands run through `shortcuts::handle`.
|
||||
CommandSource { name: "selection", states: crate::panels::options_bar::selection::source_states, run: |_, _, _| false },
|
||||
];
|
||||
@@ -689,16 +687,6 @@ fn command_states(app: &PhotocraftApp, held: &mut HeldStates) {
|
||||
#[cfg(test)]
|
||||
mod catalog_tests;
|
||||
|
||||
/// `window.home`, fired by the Home screen rail's Home row: leaves Home for the open documents, as the options bar's
|
||||
/// Home button does, and does nothing with no document open ([`crate::canvas::start_screen::toggle_home`]).
|
||||
fn run_home(app: &mut PhotocraftApp, _ctx: &egui::Context, command: &CommandRef) -> bool {
|
||||
if command.id != "window.home" {
|
||||
return false;
|
||||
}
|
||||
crate::canvas::start_screen::toggle_home(app);
|
||||
true
|
||||
}
|
||||
|
||||
/// Selects the tool a tool command names.
|
||||
fn run_tool(app: &mut PhotocraftApp, _ctx: &egui::Context, command: &CommandRef) -> bool {
|
||||
let Some(command) = crate::panels::tool_commands::ToolCommand::from_ref(command) else {
|
||||
|
||||
@@ -47,11 +47,18 @@ fn the_rails_home_row_returns_to_the_open_document() {
|
||||
let mut h = harness(1);
|
||||
show_home(&mut h);
|
||||
assert!(home(&mut h), "Home is up over the document");
|
||||
let doc = h.state().session.active().map(|d| d.doc.id);
|
||||
let (doc, open) = (h.state().session.active().map(|d| d.doc.id), h.state().session.documents().len());
|
||||
click_home_row(&mut h);
|
||||
assert!(!home(&mut h), "the Home row leaves Home: {}", h.state().ui.status);
|
||||
assert_eq!(h.state().session.active().map(|d| d.doc.id), doc, "back on the same document, unchanged");
|
||||
assert_eq!(h.state().session.documents().len(), 1);
|
||||
assert_eq!(h.state().session.active().map(|d| d.doc.id), doc, "back on the same document");
|
||||
assert_eq!(h.state().session.documents().len(), open, "nothing opened or closed");
|
||||
}
|
||||
|
||||
/// Chooses Window menu item `id`, through the gate a menu click passes (its enabled state included).
|
||||
fn choose(h: &mut H, id: &str) {
|
||||
let ctx = h.ctx.clone();
|
||||
crate::shortcut_dispatch::dispatch(h.state_mut(), &ctx, id);
|
||||
h.run_steps(4);
|
||||
}
|
||||
|
||||
#[test]
|
||||
@@ -60,13 +67,23 @@ fn choosing_an_open_document_in_the_window_menu_leaves_home() {
|
||||
let first = h.state().session.documents()[0].doc.id;
|
||||
show_home(&mut h);
|
||||
assert!(home(&mut h));
|
||||
let ctx = h.ctx.clone();
|
||||
crate::menus::invoke(h.state_mut(), &ctx, "window.document.0", json!({})).unwrap();
|
||||
h.run_steps(4);
|
||||
assert!(!home(&mut h), "choosing the document leaves Home");
|
||||
choose(&mut h, "window.document.0");
|
||||
assert!(!home(&mut h), "choosing the document leaves Home: {}", h.state().ui.status);
|
||||
assert_eq!(h.state().session.active().map(|d| d.doc.id), Some(first), "and shows that document");
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn next_and_previous_document_leave_home() {
|
||||
for id in ["window.nextDocument", "window.previousDocument"] {
|
||||
let mut h = harness(2);
|
||||
let before = h.state().session.active().map(|d| d.doc.id);
|
||||
show_home(&mut h);
|
||||
choose(&mut h, id);
|
||||
assert!(!home(&mut h), "{id} leaves Home: {}", h.state().ui.status);
|
||||
assert_ne!(h.state().session.active().map(|d| d.doc.id), before, "{id} shows the other document");
|
||||
}
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn with_no_document_open_home_stays_up() {
|
||||
let mut h = harness(0);
|
||||
|
||||
@@ -854,6 +854,8 @@ fn invoke_window_command(app: &mut PhotocraftApp, ctx: &egui::Context, id: &str,
|
||||
app.run("document.activate", json!({"document": next}))?;
|
||||
}
|
||||
app.jobs.focus = None;
|
||||
// Next and Previous Document show the document they choose, so they leave Home too (#16802).
|
||||
app.ui.chrome.home = None;
|
||||
Ok(json!({"document": next}))
|
||||
})()),
|
||||
_ if id.starts_with(DOCUMENT_ITEM) => Some((|| {
|
||||
|
||||
@@ -84,6 +84,9 @@ pub fn is_enabled(app: &PhotocraftApp, id: &str) -> bool {
|
||||
"window.togglePanels" => true,
|
||||
// With one document open the key stays quiet, as in Photoshop, rather than reporting why.
|
||||
"window.nextDocument" | "window.previousDocument" => app.session.active().is_some(),
|
||||
// Home over the open documents, or back to them (the Home rail's Home row fires it, #16802). With no document
|
||||
// open there is nothing behind Home.
|
||||
"window.home" => !app.session.documents().is_empty(),
|
||||
i if panel_alias(i).is_some() || workspace_id(i).is_some() => true,
|
||||
i if proof_preset(i).is_some() => app.session.active().is_some(),
|
||||
// "Custom…" is the full Proof Setup dialog.
|
||||
|
||||
Reference in new issue
Block a user