Skip to content

Commit

Permalink
fixup! Pop open a message when user deletes an annotation
Browse files Browse the repository at this point in the history
Fix l10n
  • Loading branch information
nicolo-ribaudo committed Oct 18, 2024
1 parent b881a4c commit a7b37b7
Show file tree
Hide file tree
Showing 5 changed files with 44 additions and 16 deletions.
11 changes: 9 additions & 2 deletions l10n/en-US/viewer.ftl
Original file line number Diff line number Diff line change
Expand Up @@ -494,9 +494,16 @@ pdfjs-editor-alt-text-settings-show-dialog-button-label = Show alt text editor r
pdfjs-editor-alt-text-settings-show-dialog-description = Helps you make sure all your images have alt text.
pdfjs-editor-alt-text-settings-close-button = Close
## "Annotations removed" bar

pdfjs-editor-undo-bar-message-highlight = Highlight removed
pdfjs-editor-undo-bar-message-freetext = Text removed
pdfjs-editor-undo-bar-message-ink = Drawing removed
pdfjs-editor-undo-bar-message-stamp = Image removed
# Variables:
# $type (String) - the type of annotation that was just removed with an optional quantity.
pdfjs-editor-undo-bar-message = { $type } removed
# $count (Number) - the number of removed annotations.
pdfjs-editor-undo-bar-message-multiple = { $count } annotations removed
pdfjs-editor-undo-bar-undo-button =
.title = Undo
pdfjs-editor-undo-bar-undo-button-label = Undo
Expand Down
4 changes: 1 addition & 3 deletions src/display/editor/tools.js
Original file line number Diff line number Diff line change
Expand Up @@ -2008,9 +2008,7 @@ class AnnotationEditorUIManager {
const cmd = () => {
this.#editorUndoBar?.show(
undo,
editors.length > 1
? `${editors.length} annotations`
: editors[0].editorType
editors.length === 1 ? editors[0].editorType : editors.length
);
for (const editor of editors) {
editor.remove();
Expand Down
9 changes: 5 additions & 4 deletions web/app.js
Original file line number Diff line number Diff line change
Expand Up @@ -452,9 +452,10 @@ const PDFViewerApplication = {
)
: null;
}
const editorUndoBar = (this.editorUndoBar = appConfig.editorUndoBar
? new EditorUndoBar(appConfig.editorUndoBar, eventBus)
: null);

if (appConfig.editorUndoBar) {
this.editorUndoBar = new EditorUndoBar(appConfig.editorUndoBar, eventBus);
}

const enableHWA = AppOptions.get("enableHWA");
const pdfViewer = new PDFViewer({
Expand All @@ -465,7 +466,7 @@ const PDFViewerApplication = {
linkService: pdfLinkService,
downloadManager,
altTextManager,
editorUndoBar,
editorUndoBar: this.editorUndoBar,
findController,
scriptingManager:
AppOptions.get("enableScripting") && pdfScriptingManager,
Expand Down
34 changes: 28 additions & 6 deletions web/editor_undo_bar.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,14 @@ class EditorUndoBar {

#undoButton;

static #l10nMessages = Object.freeze({
highlight: "pdfjs-editor-undo-bar-message-highlight",
freetext: "pdfjs-editor-undo-bar-message-freetext",
stamp: "pdfjs-editor-undo-bar-message-stamp",
ink: "pdfjs-editor-undo-bar-message-ink",
_multiple: "pdfjs-editor-undo-bar-message-multiple",
});

constructor({ container, message, undoButton, closeButton }, eventBus) {
this.#container = container;
this.#message = message;
Expand All @@ -37,22 +45,36 @@ class EditorUndoBar {
eventBus._on("download", boundHide);
}

show(action, type) {
show(undoAction, messageData) {
this.hide();
this.#message.setAttribute("data-l10n-args", JSON.stringify({ type }));
this.#container.hidden = false;

if (typeof messageData === "string") {
this.#message.setAttribute(
"data-l10n-id",
EditorUndoBar.#l10nMessages[messageData]
);
} else {
this.#message.setAttribute(
"data-l10n-id",
EditorUndoBar.#l10nMessages._multiple
);
this.#message.setAttribute(
"data-l10n-args",
JSON.stringify({ count: messageData })
);
}
this.isOpen = true;
this.#container.hidden = false;

this.#controller = new AbortController();
const opts = { signal: this.#controller.signal };

this.#undoButton.addEventListener(
"click",
() => {
action();
undoAction();
this.hide();
},
opts
{ signal: this.#controller.signal }
);
this.#undoButton.focus();
}
Expand Down
2 changes: 1 addition & 1 deletion web/viewer.html
Original file line number Diff line number Diff line change
Expand Up @@ -689,7 +689,7 @@
<div id="editorUndoBar" class="messageBar" hidden>
<div>
<div>
<span id="editorUndoBarMessage" class="description" data-l10n-id="pdfjs-editor-undo-bar-message" data-l10n-args='{ "type": "Annotation" }'>[Annotation] removed</span>
<span id="editorUndoBarMessage" class="description"></span>
</div>
<button id="editorUndoBarUndoButton" class="undoButton" type="button" tabindex="0" title="Undo" data-l10n-id="pdfjs-editor-undo-bar-undo-button">
<span data-l10n-id="pdfjs-editor-undo-bar-undo-button-label">Undo</span>
Expand Down

0 comments on commit a7b37b7

Please sign in to comment.