mirror of
https://github.com/storytold/pdfcraft.git
synced 2026-11-26 03:49:11 +00:00
Comments look: yellow default note popup, Copy comment / Paste comments rows, page menu icons and Paste gating
This commit is contained in:
@@ -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)) => {
|
||||
|
||||
@@ -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 {
|
||||
|
||||
@@ -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<String> {
|
||||
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))
|
||||
}
|
||||
|
||||
|
||||
@@ -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<Edit>),
|
||||
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<CanvasAction> {
|
||||
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<C
|
||||
// from the command board.
|
||||
// The command board owns both gates: the Paste handler (pdf-canvas-w16) reads `allowed`, the
|
||||
// clipboard and the paste place (`view.comments.context_at`).
|
||||
MenuItem::command(CommandRef::new("edit.copy")).show(ui);
|
||||
MenuItem::command(CommandRef::new("edit.paste")).show(ui);
|
||||
// Worded and gated as the comment clipboard works: Paste comments waits for copied comments.
|
||||
let chord = |ui: &egui::Ui, id: &str| crate::commands::chord_label(ui.ctx(), id);
|
||||
let mut copy = MenuItem::new(tl!(if several { "Copy comments" } else { "Copy comment" }));
|
||||
if let Some(text) = chord(ui, "edit.copy") {
|
||||
copy = copy.shortcut(text);
|
||||
}
|
||||
if copy.show(ui).ran {
|
||||
action = Some(CanvasAction::Command("edit.copy"));
|
||||
}
|
||||
let mut paste = MenuItem::new(tl!("Paste comments")).enabled(allowed && can_paste);
|
||||
if let Some(text) = chord(ui, "edit.paste") {
|
||||
paste = paste.shortcut(text);
|
||||
}
|
||||
if paste.show(ui).ran {
|
||||
action = Some(CanvasAction::Command("edit.paste"));
|
||||
}
|
||||
Divider::horizontal().show(ui);
|
||||
// The engine's own check, for each selected comment: a locked comment, or one with a locked
|
||||
// reply, stays. On a group subordinate, Delete takes just it, as Acrobat's does.
|
||||
|
||||
@@ -210,7 +210,8 @@ pub(crate) fn note_popups(
|
||||
.collect();
|
||||
let mark = pcx.screen_rects(a).next();
|
||||
// PLAN: `Annotation::color` is f32 components in 0..=1; the window takes 8-bit.
|
||||
let color = a.color.map(|c| c.map(|v| (v.clamp(0.0, 1.0) * 255.0).round() as u8));
|
||||
// A comment with no colour has the note yellow, as the page icon does.
|
||||
let color = Some(a.color.map_or([0xFF, 0xD6, 0x5C], |c| c.map(|v| (v.clamp(0.0, 1.0) * 255.0).round() as u8)));
|
||||
let selected = view.session.comments.is_selected((page, a.index));
|
||||
let popup_id = view.session.comments.popup_id((page, a.index));
|
||||
let window_label = match owned.first() {
|
||||
|
||||
@@ -3964,6 +3964,24 @@ const BLUE_NOTE_WITH_OPEN_POP_UP: &[u8] = b"%PDF-1.7
|
||||
trailer << /Root 1 0 R >>
|
||||
%%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
|
||||
|
||||
Reference in New Issue
Block a user