diff --git a/crates/ui-egui/src/canvas.rs b/crates/ui-egui/src/canvas.rs index 6354f5e447..f796722a72 100644 --- a/crates/ui-egui/src/canvas.rs +++ b/crates/ui-egui/src/canvas.rs @@ -1865,8 +1865,16 @@ pub fn document_area_at(app: &mut PdfCraftApp, index: usize, rect: Rect, ui: &mu view.want_text(&app.session, &visible_pages, &rest_pages); find_bar(view, info.pages.len(), rect, tool == QuickTool::EditText && can_modify, ui); - // The clipboard is read when Paste is invoked, so its menu stays enabled while the document is open. - let can_paste_image = true; + // Whether the clipboard holds a picture is asked when the secondary button goes down, and the menu keeps + // that answer while it is open. + let can_paste_key = egui::Id::new(("can-paste-image", index)); + let can_paste_image = if ui.input(|i| i.pointer.secondary_pressed()) { + let can = app.can_paste_image(); + ui.data_mut(|d| d.insert_temp(can_paste_key, can)); + can + } else { + ui.data(|d| d.get_temp(can_paste_key)).unwrap_or(false) + }; let doc = app.session.get(doc_id)?; let info = &doc.info; let view = &mut app.views[index]; @@ -1919,7 +1927,7 @@ pub fn document_area_at(app: &mut PdfCraftApp, index: usize, rect: Rect, ui: &mu doc, info, prefs: &app.comment_prefs, - rights: comments::MenuRights { allowed, can_modify }, + rights: comments::MenuRights { allowed, can_modify, can_paste: app.comment_clipboard.is_some() }, recent: &app.recent_colours, tool, preparing, @@ -1941,6 +1949,9 @@ pub fn document_area_at(app: &mut PdfCraftApp, index: usize, rect: Rect, ui: &mu app.comments_panel_closed = false; crate::side_panels::set_panel_visible(app, RightPanel::Comments.into(), true); } + Some(comments::CanvasAction::Command(id)) => { + app.execute(ui.ctx(), id); + } Some(comments::CanvasAction::Properties(p, i)) => open_props = Some((p, i)), Some(comments::CanvasAction::Colour(c)) => recolour = Some(c), Some(comments::CanvasAction::CopyText(text)) => { diff --git a/crates/ui-egui/src/canvas/page_menu.rs b/crates/ui-egui/src/canvas/page_menu.rs index 8297ccd942..c25e4a6c70 100644 --- a/crates/ui-egui/src/canvas/page_menu.rs +++ b/crates/ui-egui/src/canvas/page_menu.rs @@ -130,11 +130,11 @@ pub(crate) fn default_rows(perms: &PageMenuPerms, page: usize, at: [f64; 2], pic rows.push(PageMenuRow::Separator); } rows.push(PageMenuRow::Icons(vec![ - (IconId::new("rotate-ccw"), tl!("Rotate view counterclockwise").to_string(), true, A::RotateCCW), + (IconId::new("rotate_ccw"), tl!("Rotate view counterclockwise").to_string(), true, A::RotateCCW), (IconId::new("printer"), tl!("Print").to_string(), perms.can_print, A::Print), - (IconId::new("mouse-pointer-2"), tl!("Select Tool").to_string(), true, A::SelectTool), + (IconId::new("pointer"), tl!("Select Tool").to_string(), true, A::SelectTool), (IconId::new("hand"), tl!("Hand Tool").to_string(), true, A::HandTool), - (IconId::new("zoom-in"), tl!("Marquee Zoom").to_string(), true, A::MarqueeZoom), + (IconId::new("zoom_in"), tl!("Marquee Zoom").to_string(), true, A::MarqueeZoom), ])); rows.push(PageMenuRow::Separator); rows.push(PageMenuRow::Item { diff --git a/crates/ui-egui/src/commands.rs b/crates/ui-egui/src/commands.rs index c0473c57dc..e2b45b8cd1 100644 --- a/crates/ui-egui/src/commands.rs +++ b/crates/ui-egui/src/commands.rs @@ -44,10 +44,13 @@ pub(crate) fn mac_shortcuts(ctx: &egui::Context) -> bool { } /// How a command's chord is written in a menu row (`⌘C` or `Ctrl+C`): the registry's shortcut, and the -/// clipboard chord for Copy, which the framework's clipboard commands own. +/// clipboard chords for Copy and Paste, which the framework's clipboard commands own. pub(crate) fn chord_label(ctx: &egui::Context, id: &str) -> Option { let mac = mac_shortcuts(ctx); - let shortcut = commands::command(id)?.shortcut_for(mac).or((id == "edit.copy").then_some(COPY))?; + let shortcut = commands::command(id) + .and_then(|c| c.shortcut_for(mac)) + .or((id == "edit.copy").then_some(COPY)) + .or((id == "edit.paste").then_some(Shortcut::cmd("V")))?; Some(shortcut.label(mac)) } diff --git a/crates/ui-egui/src/tools/comments/menu.rs b/crates/ui-egui/src/tools/comments/menu.rs index 78208bab3d..6de9afac60 100644 --- a/crates/ui-egui/src/tools/comments/menu.rs +++ b/crates/ui-egui/src/tools/comments/menu.rs @@ -1,5 +1,4 @@ use craft::behavior::{IconId, Mixed}; -use craft::keymap::CommandRef; use craft::ui::buttons::{IconButton, ToggleButton}; use craft::ui::choice::Swatch; use craft::ui::contract::{Bind, Props as _, Show as _, ShowContainer as _}; @@ -56,6 +55,8 @@ pub(crate) struct MenuRights { pub(crate) allowed: bool, /// The document's pages may change (Flatten comments draws into them). pub(crate) can_modify: bool, + /// Comments are on the comment clipboard, to paste. + pub(crate) can_paste: bool, } /// What the canvas asks the app to do. @@ -63,6 +64,8 @@ pub(crate) struct MenuRights { pub enum CanvasAction { Edit(Box), OpenComments, + /// Run this command of the command board (Copy and Paste of the comments). + Command(&'static str), /// Comment Properties for (page, index). Properties(usize, usize), /// Put this text on the clipboard, through the app's clipboard service. @@ -98,7 +101,7 @@ fn row(ui: &mut egui::Ui, label: &str, enabled: bool) -> bool { /// Rows of the canvas context menu for the selected comment (or the page), inside `Menu::context`. pub(crate) fn context_rows(ui: &mut egui::Ui, cx: CommentMenuCx<'_>) -> Option { let CommentMenuCx { view, info, deletable, prefs, rights, recent, tool } = cx; - let MenuRights { allowed, can_modify } = rights; + let MenuRights { allowed, can_modify, can_paste } = rights; let mut action = None; // Connected lines, a polygon or a cloud being drawn: finish it from the menu, as other editors do (Enter // and a double-click finish it too), take the last point back, or stop. @@ -174,8 +177,22 @@ pub(crate) fn context_rows(ui: &mut egui::Ui, cx: CommentMenuCx<'_>) -> Option> %%EOF"; +#[test] +fn an_uncoloured_notes_popup_uses_the_yellow_note_default() { + let _gpu = crate::gpu(); + let pdf = String::from_utf8_lossy(BLUE_NOTE_WITH_OPEN_POP_UP).replace("/C [0 0 1]", ""); + let mut h = harness_with_bytes(pdf.into_bytes(), |_| {}); + let window = popup_rect(&h, "Alpha"); + let pixels = h.render().unwrap(); + let x0 = window.left().max(0.0) as u32; + let x1 = window.right().min(pixels.width() as f32) as u32; + let y0 = window.top().max(0.0) as u32; + let y1 = (window.top() + 16.0).min(pixels.height() as f32) as u32; + let yellow = (y0..y1).any(|y| (x0..x1).any(|x| { + let [r, g, b, _] = pixels.get_pixel(x, y).0; + r > 200 && g > 150 && b < 150 + })); + assert!(yellow, "a note without a colour has a yellow popup header"); +} + /// A note with an open pop-up and a thread of replies: "Second" and "Third" answer the note, /// "Second, first answer" answers "Second" (`/IRT` to a reply). const NOTE_WITH_A_THREAD: &[u8] = b"%PDF-1.7