Move "Show File" out of Locate menu and into File menu (#4124)

This commit is contained in:
Abe Jellinek 2024-05-14 11:35:37 -04:00 committed by Dan Stillman
parent e1f1003318
commit c47617c809
7 changed files with 74 additions and 39 deletions

View file

@ -122,11 +122,12 @@ var Zotero_LocateMenu = new function() {
function _addViewOption(selectedItems, optionName, optionObject, showIcons) {
var menuitem;
if (optionObject.l10nKey) {
if (optionObject.l10nId) {
menuitem = _createMenuItem('', null, null); // Set by Fluent
menuitem.setAttribute("data-l10n-id", optionObject.l10nKey);
if (optionObject.l10nArgs) {
menuitem.setAttribute("data-l10n-args", optionObject.l10nArgs);
menuitem.dataset.l10nId = optionObject.l10nId;
let l10nArgs = optionObject.l10nArgs;
if (l10nArgs) {
menuitem.dataset.l10nArgs = JSON.stringify(l10nArgs);
}
}
else {
@ -395,7 +396,7 @@ var Zotero_LocateMenu = new function() {
// "in New Tab" when it's true) in toolbar Locate menu
this.hideInToolbar = alternateWindowBehavior;
this.l10nKey = "item-menu-viewAttachment";
this.l10nId = "item-menu-viewAttachment";
Object.defineProperty(this, "l10nArgs", {
get: () => {
let openIn;
@ -409,11 +410,11 @@ var Zotero_LocateMenu = new function() {
}
openIn = openInNewWindow ? "window" : "tab";
}
return JSON.stringify({
return {
attachmentType: this._attachmentType,
numAttachments: this._numAttachments,
openIn,
});
};
}
});
@ -598,30 +599,24 @@ var Zotero_LocateMenu = new function() {
* file or web attachment
*/
ViewOptions.showFile = new function() {
this.className = "zotero-menuitem-view-file";
this.useExternalViewer = true;
this.className = "zotero-menuitem-show-file";
this.hideInToolbar = true;
this.l10nId = "menu-show-file";
this.l10nArgs = { count: 0 };
this.canHandleItem = function (item) {
return _getBestFile(item).then(item => !!item);
}
return ZoteroPane.canShowItemInFilesystem(item);
};
this.handleItems = Zotero.Promise.coroutine(function* (items, event) {
for (let item of items) {
var attachment = yield _getBestFile(item);
if(attachment) {
ZoteroPane_Local.showAttachmentInFilesystem(attachment.id);
}
}
});
this.updateMenuItem = function (items) {
let count = items.filter(item => ZoteroPane.canShowItemInFilesystem(item))
.length;
this.l10nArgs = { count };
};
var _getBestFile = Zotero.Promise.coroutine(function* (item) {
if(item.isAttachment()) {
if(item.attachmentLinkMode === Zotero.Attachments.LINK_MODE_LINKED_URL) return false;
return item;
} else {
return yield item.getBestAttachment();
}
});
this.handleItems = async function (items) {
await ZoteroPane.showItemsInFilesystem(items);
};
};
/**

View file

@ -157,8 +157,9 @@ const ZoteroStandalone = new function() {
};
this.onFileMenuOpen = function () {
// PDF annotation transfer ("Import Annotation"/"Store Annotations in File")
let reader = Zotero.Reader.getByTabID(Zotero_Tabs.selectedID);
// PDF annotation transfer ("Import Annotation"/"Store Annotations in File")
if (reader) {
let item = Zotero.Items.get(reader.itemID);
let library = Zotero.Libraries.get(item.libraryID);
@ -175,14 +176,20 @@ const ZoteroStandalone = new function() {
}
}
let showFileMenuitem = document.getElementById('menu_showFile');
let numFiles = ZoteroPane.getSelectedItems()
.filter(item => ZoteroPane.canShowItemInFilesystem(item))
.length;
showFileMenuitem.disabled = !numFiles;
document.l10n.setArgs(showFileMenuitem, {
count: numFiles
});
// TEMP: Quick implementation
try {
let menuitem = document.getElementById('menu_export_files');
let sep = menuitem.nextSibling;
let zp = Zotero.getActiveZoteroPane();
if (zp && !reader) {
let numFiles = zp.getSelectedItems().reduce((num, item) => {
if (!reader) {
let numFiles = ZoteroPane.getSelectedItems().reduce((num, item) => {
if (item.isPDFAttachment()) {
return num + 1;
}
@ -193,19 +200,16 @@ const ZoteroStandalone = new function() {
}, 0);
if (numFiles) {
menuitem.hidden = false;
sep.hidden = false;
menuitem.label = Zotero.getString(
'pane.items.menu.exportPDF' + (numFiles == 1 ? '' : '.multiple')
);
}
else {
menuitem.hidden = true;
sep.hidden = true;
}
}
else {
menuitem.hidden = true;
sep.hidden = true;
}
}
catch (e) {

View file

@ -4901,6 +4901,31 @@ var ZoteroPane = new function()
}
this.canShowItemInFilesystem = function (item) {
return (item.isRegularItem() && item.numFileAttachments()) || item.isFileAttachment();
};
this.showItemsInFilesystem = async function (items = this.getSelectedItems()) {
let attachments = (await Promise.all(
items.map((item) => {
if (item.isRegularItem()) {
return item.getBestAttachment();
}
else if (item.isFileAttachment()) {
return item;
}
else {
return null;
}
})
)).filter(Boolean);
for (let attachment of attachments) {
await this.showAttachmentInFilesystem(attachment.id);
}
};
this.showAttachmentInFilesystem = async function (itemID, noLocateOnMissing) {
var attachment = await Zotero.Items.getAsync(itemID)
if (attachment.attachmentLinkMode == Zotero.Attachments.LINK_MODE_LINKED_URL) return;

View file

@ -319,10 +319,13 @@
<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 data-l10n-id="menu-show-file" id="menu_showFile"
class="menu-type-library"
oncommand="ZoteroPane.showItemsInFilesystem()"/>
<menuitem id="menu_export_files" class="menu-type-library"
oncommand="ZoteroPane.exportSelectedFiles()"
hidden="true"/>
<menuseparator class="menu-type-library" hidden="true"/>
<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" class="menu-type-library" label="&importFromClipboardCmd.label;"

View file

@ -10,6 +10,15 @@ general-add = Add
menu-print =
.label = { general-print }
menu-show-file =
.label = { PLATFORM() ->
[macos] Show in Finder
*[other] { $count ->
[0] Show File
[one] Show File
*[other] Show Files
}
}
menu-density =
.label = Density

View file

@ -1231,7 +1231,6 @@ locate.snapshot.label = View Snapshot
locate.file.label = View File
locate.externalViewer.label = Open in External Viewer
locate.internalViewer.label = Open in Internal Viewer
locate.showFile.label = Show File
locate.libraryLookup.label = Library Lookup
locate.libraryLookup.noResolver.title = No OpenURL Resolver
locate.libraryLookup.noResolver.text = You must choose an OpenURL resolver from the Advanced pane of the %S preferences.

View file

@ -22,7 +22,7 @@ $menu-icons: (
attach: "attachment",
attachments-web-link: "link",
view-online: "globe",
view-file: "folder-open",
show-file: "folder-open",
view-external: "page",
library-lookup: "library-lookup",
new-feed: "feed",