Add rotation options to Edit menu to rotate the current PDF page

This commit is contained in:
Martynas Bagdonas 2022-10-17 12:06:27 +03:00
parent 410ebc288b
commit d8d6054927
4 changed files with 60 additions and 0 deletions

View file

@ -69,6 +69,25 @@
<menuitem id="menu_copy"/>
<menuitem id="menu_paste"/>
<menuitem id="menu_delete"/>
<menuseparator class="menu-type-reader"/>
<menuitem
id="edit-menuitem-rotate-left"
class="menu-type-reader"
label="&zotero.pdfReader.rotateLeft;"
oncommand="menuCmd('rotateLeft')"
/>
<menuitem
id="edit-menuitem-rotate-right"
class="menu-type-reader"
label="&zotero.pdfReader.rotateRight;"
oncommand="menuCmd('rotateRight')"
/>
<menuitem
id="edit-menuitem-rotate-180"
class="menu-type-reader"
label="&zotero.pdfReader.rotate180;"
oncommand="menuCmd('rotate180')"
/>
</menupopup>
</menu>
<menu label="View" onpopupshowing="onViewMenuOpen()">

View file

@ -232,6 +232,25 @@
label="&bidiSwitchTextDirectionItem.label;"
accesskey="&bidiSwitchTextDirectionItem.accesskey;"
hidden="true"/>
<menuseparator class="menu-type-reader"/>
<menuitem
id="edit-menuitem-rotate-left"
class="menu-type-reader"
label="&zotero.pdfReader.rotateLeft;"
oncommand="ZoteroStandalone.onReaderCmd('rotateLeft')"
/>
<menuitem
id="edit-menuitem-rotate-right"
class="menu-type-reader"
label="&zotero.pdfReader.rotateRight;"
oncommand="ZoteroStandalone.onReaderCmd('rotateRight')"
/>
<menuitem
id="edit-menuitem-rotate-180"
class="menu-type-reader"
label="&zotero.pdfReader.rotate180;"
oncommand="ZoteroStandalone.onReaderCmd('rotate180')"
/>
</menupopup>
</menu>

View file

@ -389,6 +389,18 @@ class ReaderInstance {
}
return;
}
else if (cmd === 'rotateLeft') {
await this._rotateCurrentPage(270);
return;
}
else if (cmd === 'rotateRight') {
await this._rotateCurrentPage(90);
return;
}
else if (cmd === 'rotate180') {
await this._rotateCurrentPage(180);
return;
}
else if (cmd === 'splitVertically') {
this._splitVertically();
}
@ -610,6 +622,13 @@ class ReaderInstance {
return `data:image/svg+xml,<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 16 16"><rect shape-rendering="geometricPrecision" fill="${fill}" stroke-width="2" x="2" y="2" stroke="${stroke}" width="12" height="12" rx="3"/></svg>`;
}
async _rotateCurrentPage(degrees) {
let pageIndex = this._iframeWindow.wrappedJSObject.PDFViewerApplication.pdfViewer.currentPageNumber - 1;
this._postMessage({ action: 'reloading' });
await Zotero.PDFWorker.rotatePages(this._itemID, [pageIndex], degrees, true);
await this.reload({ rotatedPageIndexes: [pageIndex] });
}
_splitVertically() {
if (this.isSplitVerticallyActive()) {
this._iframeWindow.wrappedJSObject.unsplitView();

View file

@ -326,3 +326,6 @@
<!ENTITY zotero.pdfReader.splitVertically "Split Vertically">
<!ENTITY zotero.pdfReader.splitHorizontally "Split Horizontally">
<!ENTITY zotero.pdfReader.transferFromPDF "Import Annotations…">
<!ENTITY zotero.pdfReader.rotateLeft "Rotate Left">
<!ENTITY zotero.pdfReader.rotateRight "Rotate Right">
<!ENTITY zotero.pdfReader.rotate180 "Rotate 180°">