PhotoCraft: An open-source, photo editor written by scratch in pure Rust
Pen options bar: Make Selection in Path mode (#5703)
Higgs32584772209808ba2
diff --git a/crates/ui-egui/src/canvas_tool_menu.rs b/crates/ui-egui/src/canvas_tool_menu.rsindex da835a786..92861a521 100644--- a/crates/ui-egui/src/canvas_tool_menu.rs+++ b/crates/ui-egui/src/canvas_tool_menu.rs@@ -796,6 +796,20 @@ fn pen_dialog(app: &mut PhotocraftApp, command: &str, label: &str, name: &str) {spec_dialog(app, command, label, spec, fields);}+/// The Pen options bar's Make Selection (Path mode, #5703): the canvas menu's Make Selection…+/// dialog for the path being drawn (committed first, as the menu does) or the active path.+pub(crate) fn make_selection(app: &mut PhotocraftApp) -> Result<(), String> {+ let pending = app.ui.pen.as_ref().is_some_and(|p| p.knots.len() >= 2);+ let pending_layer = pending && (app.ui.tool_options.vector_mode == "shape" || app.ui.vector_mask_target);+ if pending {+ crate::vector_ui::pen_commit(app, false);+ }+ let name = if pending { Some(if pending_layer { "layer" } else { "work" }.to_string()) } else { crate::vector_ui::active_path_name(app) }+ .ok_or_else(|| "No path is available for this action".to_string())?;+ pen_dialog(app, "path.toSelection", "Make Selection…", &name);+ Ok(())+}+fn choose_pen(app: &mut PhotocraftApp, ctx: &Context, menu: &CanvasToolMenu, command: &str) -> Result<(), String> {if command == "select.isolateLayers" {crate::menus::invoke(app, ctx, command, json!({}))?;@@ -1492,6 +1506,32 @@ mod tests {assert!(app.session.active().unwrap().doc.selection.is_some());}+ /// #5703: the Pen options bar's Make Selection (Path mode) opens the same dialog for the path+ /// being drawn (finished into the Work Path first), and OK selects inside it; with no path at+ /// all it reports that instead.+ #[test]+ fn pen_options_bar_makes_a_selection_from_the_path() {+ let mut app = app();+ app.ui.tool = Tool::Pen;+ assert!(make_selection(&mut app).is_err(), "no path yet");+ assert!(app.ui.dialogs.is_empty());+ for (x, y) in [(2.0, 2.0), (20.0, 2.0), (20.0, 20.0)] {+ crate::vector_ui::pen_down(&mut app, x, y, false);+ crate::vector_ui::pen_up(&mut app);+ }+ make_selection(&mut app).unwrap();+ let dialog = app.ui.dialogs.last().map(|d| d.id).unwrap();+ crate::dialogs::confirm(&mut app, dialog).unwrap();+ let st = app.session.active().unwrap();+ assert!(st.doc.work_path.is_some() && st.doc.selection.is_some());+ // The active (Work) path again, with no pen path in progress.+ app.run("select.deselect", json!({})).unwrap();+ make_selection(&mut app).unwrap();+ let dialog = app.ui.dialogs.last().map(|d| d.id).unwrap();+ crate::dialogs::confirm(&mut app, dialog).unwrap();+ assert!(app.session.active().unwrap().doc.selection.is_some());+ }+#[test]fn pen_menu_has_all_reference_rows_in_order_and_guards_unavailable_actions() {let labels: Vec<_> = PEN_MENU.iter().map(|row| row.map(|(label, _)| label)).collect();diff --git a/crates/ui-egui/src/i18n/ko.tsv b/crates/ui-egui/src/i18n/ko.tsvindex e76a3c982..ab2bf52fd 100644--- a/crates/ui-egui/src/i18n/ko.tsv+++ b/crates/ui-egui/src/i18n/ko.tsv@@ -3353,3 +3353,4 @@ curves Smooth 매끄럽게# View › Guides › right-click a guideEdit Selected Guides 선택한 안내선 편집Clear Selected Guides 선택한 안내선 지우기+ Make Selection 선택 영역 만들기diff --git a/crates/ui-egui/src/i18n/zh-hans.tsv b/crates/ui-egui/src/i18n/zh-hans.tsvindex 2307739ed..5d420b098 100644--- a/crates/ui-egui/src/i18n/zh-hans.tsv+++ b/crates/ui-egui/src/i18n/zh-hans.tsv@@ -2790,3 +2790,4 @@ curves Smooth 平滑# View › Guides › right-click a guideEdit Selected Guides 编辑所选参考线Clear Selected Guides 清除所选参考线+ Make Selection 建立选区diff --git a/crates/ui-egui/src/i18n/zh-hant.tsv b/crates/ui-egui/src/i18n/zh-hant.tsvindex 478489f8c..f13bda17c 100644--- a/crates/ui-egui/src/i18n/zh-hant.tsv+++ b/crates/ui-egui/src/i18n/zh-hant.tsv@@ -2775,3 +2775,4 @@ curves Smooth 平滑# View › Guides › right-click a guideEdit Selected Guides 編輯所選參考線Clear Selected Guides 清除所選參考線+ Make Selection 建立選取範圍diff --git a/crates/ui-egui/src/vector_ui.rs b/crates/ui-egui/src/vector_ui.rsindex f68a4a6a4..cb0cd07ba 100644--- a/crates/ui-egui/src/vector_ui.rs+++ b/crates/ui-egui/src/vector_ui.rs@@ -1139,6 +1139,18 @@ pub fn options_bar(app: &mut PhotocraftApp, ui: &mut egui::Ui, tool: Tool) -> bo),),}+ // Path mode: Make Selection from the path being drawn or the active path, as Photoshop's+ // options bar's "Make: Selection…" does (#5703).+ if app.ui.tool_options.vector_mode == "path" {+ crate::widgets::vline(ui, 22.0);+ let has_path = active_path_name(app).is_some() || app.ui.pen.as_ref().is_some_and(|p| p.knots.len() >= 2);+ if ui.add_enabled(has_path, egui::Button::new(tl!("Make Selection"))).clicked()+ && let Err(e) = crate::canvas_tool_menu::make_selection(app)+ {+ app.ui.status = e;+ app.ui.status_error = true;+ }+ }return true;}let mut mode = "shape".to_string();