Improve menubar for reader tab and window

This commit is contained in:
Martynas Bagdonas 2020-10-26 14:09:56 +02:00 committed by Dan Stillman
parent 51db52a5ea
commit 8e3dc61070
4 changed files with 147 additions and 27 deletions

View file

@ -3,10 +3,12 @@
<?xml-stylesheet href="chrome://global/skin/" type="text/css"?>
<?xml-stylesheet href="chrome://zotero/skin/zotero.css" type="text/css"?>
<?xul-overlay href="chrome://zotero/content/standalone/editMenuOverlay.xul"?>
<?xul-overlay href="chrome://zotero-platform/content/standalone/menuOverlay.xul"?>
<!DOCTYPE window [
<!ENTITY % globalDTD SYSTEM "chrome://global/locale/global.dtd"> %globalDTD;
<!ENTITY % standaloneDTD SYSTEM "chrome://zotero/locale/standalone.dtd" > %standaloneDTD;
<!ENTITY % zoteroDTD SYSTEM "chrome://zotero/locale/zotero.dtd"> %zoteroDTD;
]>
@ -22,19 +24,54 @@
<script type="application/javascript">
Components.utils.import('resource://gre/modules/Services.jsm');
</script>
<script type="application/javascript" src="chrome://global/content/globalOverlay.js"/>
<script type="application/javascript" src="chrome://global/content/contentAreaUtils.js"/>
<script type="application/javascript" src="chrome://global/content/inlineSpellCheckUI.js"/>
<commandset id="mainCommandSet">
<!--FILE-->
<command id="cmd_quitApplication" oncommand="goQuitApplication();"/>
<command id="cmd_close" oncommand="window.close();"/>
<!--EDIT-->
<commandset id="editMenuCommands"/>
<command id="cmd_find"
oncommand="document.getElementById('zotero-tb-search').select()"/>
</commandset>
<!-- TODO: Localize -->
<tooltip id="iframeTooltip" onpopupshowing="if (tooltipTitleNode = document.tooltipNode.closest('*[title]')) {this.setAttribute('label', tooltipTitleNode.getAttribute('title')); return true; } return false"/>
<menubar>
<menu label="File">
<menupopup>
<menuitem label="Save As" oncommand="menuCmd('export')"/>
<menu id="fileMenu" label="&fileMenu.label;" accesskey="&fileMenu.accesskey;">
<menupopup id="menu_FilePopup">
<menuitem label="Export" oncommand="menuCmd('export')"/>
<menuitem label="Print" oncommand="menuCmd('print')"/>
<menuseparator/>
<menuitem id="menu_close" label="&closeCmd.label;" key="key_close"
accesskey="&closeCmd.accesskey;" command="cmd_close"/>
</menupopup>
</menu>
<menu id="menu_edit">
<menupopup id="menu_EditPopup">
<menuitem id="menu_undo"/>
<menuitem id="menu_redo"/>
<menuseparator/>
<menuitem id="menu_cut"/>
<menuitem id="menu_copy"/>
<menuitem id="menu_paste"/>
<menuitem id="menu_delete"/>
</menupopup>
</menu>
<menu label="View">
<menupopup>
<menuitem label="Switch to Presentation Mode" oncommand="menuCmd('presentationmode')"/>
<menuseparator/>
<!--
To make presentation mode work it's necessary to set
full-screen-api.enabled=true
full-screen-api.allow-trusted-requests-only=false
and then hide all other visible window elements like toolbar, note sidebar, tabs, etc.
-->
<!-- <menuitem label="Switch to Presentation Mode" oncommand="menuCmd('presentationmode')"/>-->
<!-- <menuseparator/>-->
<menuitem label="Go to First Page" oncommand="menuCmd('firstpage')"/>
<menuitem label="Go to Last Page" oncommand="menuCmd('lastpage')"/>
<menuseparator/>
@ -53,10 +90,16 @@
<menuitem label="Even Spreads" oncommand="menuCmd('switchspreadmode_even')"/>
</menupopup>
</menu>
<menu label="Tools">
<menupopup>
<menuitem label="Remove password (not implemented)" oncommand="menuCmd('remove_password')"/>
</menupopup>
<!-- <menu label="Tools">-->
<!-- <menupopup>-->
<!-- <menuitem label="Remove password (not implemented)" oncommand="menuCmd('remove_password')"/>-->
<!-- </menupopup>-->
<!-- </menu>-->
<menu id="windowMenu"
label="&windowMenu.label;"
onpopupshowing="macWindowMenuDidShow();"
onpopuphidden="macWindowMenuDidHide();"
>
</menu>
</menubar>

View file

@ -47,6 +47,20 @@ const ZoteroStandalone = new function() {
document.documentElement.setAttribute('tabsintitlebar', true);
document.documentElement.setAttribute('chromemargin', '0,-1,-1,-1');
}
this.switchMenuType('library');
Zotero.Notifier.registerObserver(
{
notify: async (action, type, ids, extraData) => {
if (action == 'select') {
// "library" or "reader"
this.switchMenuType(extraData.type);
}
}
},
['tab'],
'tab'
);
Zotero.Promise.try(function () {
if(!Zotero) {
@ -96,7 +110,16 @@ const ZoteroStandalone = new function() {
return;
});
}
this.switchMenuType = function (type) {
document.querySelectorAll('.menu-type-library, .menu-type-reader').forEach(el => el.collapsed = true);
document.querySelectorAll('.menu-type-' + type).forEach(el => el.collapsed = false);
};
this.onReaderCmd = function (cmd) {
let reader = Zotero.Reader.getByTabID(Zotero_Tabs.selectedID);
reader.menuCmd(cmd);
};
this.onFileMenuOpen = function () {
var active = false;

View file

@ -128,28 +128,38 @@
mode="icons" iconsize="small" defaulticonsize="small"
context="toolbar-context-menu">
<toolbaritem id="menubar-items" align="center">
<!-- TODO: Localize labels -->
<!--
On macOS the document's top-most menubar node is used and
there is no way to change it after the initialization, only
the children can be modified. All non-menu nodes are ignored
-->
<menubar id="main-menubar"
style="border:0px;padding:0px;margin:0px;-moz-appearance:none">
<menu id="fileMenu" label="&fileMenu.label;" accesskey="&fileMenu.accesskey;"
onpopupshowing="ZoteroStandalone.onFileMenuOpen()">
<menupopup id="menu_FilePopup">
<menu id="menu_newItem" label="&zotero.toolbar.newItem.label;">
<menu id="menu_newItem" class="menu-type-library" label="&zotero.toolbar.newItem.label;">
<menupopup id="menu_NewItemPopup"
onpopupshowing="ZoteroStandalone.buildNewItemMenu()"/>
</menu>
<menuitem id="menu_newNote" label="&zotero.toolbar.newNote;"
<menuitem id="menu_newNote" class="menu-type-library" label="&zotero.toolbar.newNote;"
command="cmd_zotero_newStandaloneNote"/>
<menuitem id="menu_newCollection" label="&zotero.toolbar.newCollection.label;"
<menuitem id="menu_newCollection" class="menu-type-library" label="&zotero.toolbar.newCollection.label;"
command="cmd_zotero_newCollection"/>
<menuitem label="Save As" class="menu-type-reader" oncommand="ZoteroStandalone.onReaderCmd('export')"/>
<menuitem label="Print" class="menu-type-reader" oncommand="ZoteroStandalone.onReaderCmd('print')"/>
<menuseparator/>
<menuitem id="menu_close" label="&closeCmd.label;" key="key_close"
<menuitem id="menu_close" class="menu-type-library" label="&closeCmd.label;" key="key_close"
accesskey="&closeCmd.accesskey;" command="cmd_close"/>
<menuseparator/>
<menuitem id="menu_import" label="&importCmd.label;"
<menuitem id="menu_close_tab" class="menu-type-reader" label="&closeCmd.label;" key="key_close"
accesskey="&closeCmd.accesskey;" oncommand="Zotero_Tabs.close()"/>
<menuseparator class="menu-type-library"/>
<menuitem id="menu_import" class="menu-type-library" label="&importCmd.label;"
command="cmd_zotero_import" key="key_import"/>
<menuitem id="menu_importFromClipboard" label="&importFromClipboardCmd.label;"
<menuitem id="menu_importFromClipboard" class="menu-type-library" label="&importFromClipboardCmd.label;"
command="cmd_zotero_importFromClipboard" key="key_importFromClipboard"/>
<menuitem id="menu_exportLibrary" label="&zotero.toolbar.export.label;"
<menuitem id="menu_exportLibrary" class="menu-type-library" label="&zotero.toolbar.export.label;"
command="cmd_zotero_exportLibrary"/>
</menupopup>
</menu>
@ -163,29 +173,33 @@
<menuitem id="menu_cut"/>
<menuitem id="menu_copy"/>
<menuitem id="menu_copyCitation"
class="menu-type-library"
label="&copyCitationCmd.label;"
command="cmd_zotero_copyCitation"
key="key_copyCitation"
hidden="true"/>
<menuitem id="menu_copyBibliography"
class="menu-type-library"
label="&copyBibliographyCmd.label;"
command="cmd_zotero_copyBibliography"
key="key_copyBibliography"
hidden="true"/>
<menuitem id="menu_copyExport"
class="menu-type-library"
key="key_copyBibliography"
command="cmd_zotero_copyBibliography"
hidden="true"/>
<menuitem id="menu_paste"/>
<menuitem id="menu_delete"/>
<menuseparator/>
<menuitem id="menu_selectAll"/>
<menuseparator/>
<menuitem id="menu_find"/>
<menuseparator class="menu-type-library"/>
<menuitem id="menu_selectAll" class="menu-type-library"/>
<menuseparator class="menu-type-library"/>
<menuitem id="menu_find" class="menu-type-library"/>
<menuitem id="menu_advancedSearch"
class="menu-type-library"
label="&zotero.toolbar.advancedSearch;"
command="cmd_zotero_advancedSearch"/>
<menuseparator hidden="true" id="textfieldDirection-separator"/>
<menuseparator class="menu-type-library" hidden="true" id="textfieldDirection-separator"/>
<menuitem id="textfieldDirection-swap"
command="cmd_switchTextDirection"
key="key_switchTextDirection"
@ -199,7 +213,28 @@
label="&viewMenu.label;"
onpopupshowing="ZoteroStandalone.onViewMenuOpen()">
<menupopup id="menu_viewPopup">
<!-- <menuitem class="menu-type-reader" label="Switch to Presentation Mode" oncommand="ZoteroStandalone.onReaderCmd('presentationmode')"/>-->
<!-- <menuseparator class="menu-type-reader"/>-->
<menuitem class="menu-type-reader" label="Go to First Page" oncommand="ZoteroStandalone.onReaderCmd('firstpage')"/>
<menuitem class="menu-type-reader" label="Go to Last Page" oncommand="ZoteroStandalone.onReaderCmd('lastpage')"/>
<menuseparator class="menu-type-reader"/>
<menuitem class="menu-type-reader" label="Rotate Clockwise" oncommand="ZoteroStandalone.onReaderCmd('rotatecw')"/>
<menuitem class="menu-type-reader" label="Rotate Counterclockwise" oncommand="ZoteroStandalone.onReaderCmd('rotateccw')"/>
<menuseparator class="menu-type-reader"/>
<menuitem class="menu-type-reader" label="Text Selection Tool" oncommand="ZoteroStandalone.onReaderCmd('switchcursortool_select')"/>
<menuitem class="menu-type-reader" label="Hand Tool" oncommand="ZoteroStandalone.onReaderCmd('switchcursortool_hand')"/>
<menuseparator class="menu-type-reader"/>
<menuitem class="menu-type-reader" label="Vertical Scrolling" oncommand="ZoteroStandalone.onReaderCmd('switchscrollmode_vertical')"/>
<menuitem class="menu-type-reader" label="Horizontal Scrolling" oncommand="ZoteroStandalone.onReaderCmd('switchscrollmode_horizontal')"/>
<menuitem class="menu-type-reader" label="Wrapped Scrolling" oncommand="ZoteroStandalone.onReaderCmd('switchscrollmode_wrapped')"/>
<menuseparator class="menu-type-reader"/>
<menuitem class="menu-type-reader" label="No Spreads" oncommand="ZoteroStandalone.onReaderCmd('switchspreadmode_none')"/>
<menuitem class="menu-type-reader" label="Odd Spreads" oncommand="ZoteroStandalone.onReaderCmd('switchspreadmode_odd')"/>
<menuitem class="menu-type-reader" label="Even Spreads" oncommand="ZoteroStandalone.onReaderCmd('switchspreadmode_even')"/>
<menuseparator class="menu-type-reader"/>
<menu id="layout-menu"
class="menu-type-library"
label="&layout.label;">
<menupopup oncommand="ZoteroStandalone.onViewMenuItemClick(event)">
<menuitem
@ -268,6 +303,7 @@
</menu>
<menuseparator/>
<menuitem id="view-menuitem-recursive-collections"
class="menu-type-library"
label="&recursiveCollections.label;"
oncommand="ZoteroStandalone.onViewMenuItemClick(event)"
type="checkbox"
@ -277,16 +313,17 @@
<menu id="toolsMenu" label="&toolsMenu.label;" accesskey="&toolsMenu.accesskey;">
<menupopup id="menu_ToolsPopup">
<menuitem id="menu_createTimeline" label="&zotero.toolbar.timeline.label;"
<menuitem id="menu_createTimeline" class="menu-type-library" label="&zotero.toolbar.timeline.label;"
command="cmd_zotero_createTimeline"/>
<menuitem id="menu_rtfScan" label="&zotero.toolbar.rtfScan.label;"
<menuitem id="menu_rtfScan" class="menu-type-library" label="&zotero.toolbar.rtfScan.label;"
command="cmd_zotero_rtfScan"/>
<menuseparator/>
<menuitem id="installConnector"
class="menu-type-library"
accessKey="&installConnector.accesskey;"
label="&installConnector.label;"
oncommand="ZoteroStandalone.openHelp('connectors');"/>
<menuitem id="menu_addons" label="&addons.label;"
<menuitem id="menu_addons" class="menu-type-library" label="&addons.label;"
oncommand="Zotero.openInViewer('chrome://mozapps/content/extensions/extensions.xul', ZoteroStandalone.updateAddonsPane)"/>
<menu id="developer-menu"
label="&developer.label;">
@ -298,7 +335,7 @@
</menupopup>
</menu>
<menuseparator/>
<menu id="manage-attachments-menu" label="&manageAttachments.label;"
<menu id="manage-attachments-menu" class="menu-type-library" label="&manageAttachments.label;"
onpopupshowing="ZoteroStandalone.onManageAttachmentsMenuOpen()"
oncommand="ZoteroStandalone.onManageAttachmentsMenuItemClick(event)">
<menupopup id="manage-attachments-menupopup">

View file

@ -506,6 +506,19 @@ class ReaderTab extends ReaderInstance {
}
}
menuCmd(cmd) {
if (cmd === 'export') {
let zp = Zotero.getActiveZoteroPane();
zp.exportPDF(this._itemID);
return;
}
let data = {
action: 'menuCmd',
cmd
};
this._postMessage(data);
}
_toggleNoteSidebar(isToggled) {
let itemPane = this._window.document.getElementById('zotero-item-pane');
var noteEditor = this._window.document.getElementById('zotero-note-editor');
@ -727,6 +740,10 @@ class Reader {
}
}
}
getByTabID(tabID) {
return this._readers.find(r => (r instanceof ReaderTab) && r.tabID === tabID);
}
async openURI(itemURI, location, openWindow) {
let item = await Zotero.URI.getURIItem(itemURI);