- Properly handle multiple item selection in context/locate menu
- Don't show context menu options when >20 items selected
This commit is contained in:
parent
7a50fcafe0
commit
4783051f4e
2 changed files with 66 additions and 55 deletions
|
@ -98,8 +98,8 @@ var Zotero_LocateMenu = new function() {
|
|||
// get selected items
|
||||
var selectedItems = _getSelectedItems();
|
||||
|
||||
// if no items selected, stop now
|
||||
if(!selectedItems.length) return;
|
||||
// if no items selected or >20 items selected, stop now
|
||||
if(!selectedItems.length || selectedItems.length > 20) return;
|
||||
|
||||
// add view options
|
||||
_addViewOptions(menu, selectedItems);
|
||||
|
@ -338,13 +338,13 @@ var Zotero_LocateMenu = new function() {
|
|||
this.canHandleItem = function(item) !!_getFirstAttachmentWithMIMEType(item, this._mimeTypes);
|
||||
|
||||
this.handleItems = function(items, event) {
|
||||
var attachments = [];
|
||||
for each(var item in items) {
|
||||
var attachment = _getFirstAttachmentWithMIMEType(item, this._mimeTypes);
|
||||
if(attachment) {
|
||||
ZoteroPane_Local.viewAttachment(attachment.id, event);
|
||||
return;
|
||||
}
|
||||
if(attachment) attachments.push(attachment.id);
|
||||
}
|
||||
|
||||
ZoteroPane_Local.viewAttachment(attachments, event);
|
||||
}
|
||||
|
||||
function _getFirstAttachmentWithMIMEType(item, mimeTypes) {
|
||||
|
@ -431,13 +431,13 @@ var Zotero_LocateMenu = new function() {
|
|||
this.canHandleItem = function(item) !!_getFile(item);
|
||||
|
||||
this.handleItems = function(items, event) {
|
||||
var attachments = [];
|
||||
for each(var item in items) {
|
||||
var attachment = _getFile(item);
|
||||
if(attachment) {
|
||||
ZoteroPane_Local.viewAttachment(attachment.id, event);
|
||||
return;
|
||||
}
|
||||
if(attachment) attachments.push(attachment.id);
|
||||
}
|
||||
|
||||
ZoteroPane_Local.viewAttachment(attachments, event);
|
||||
}
|
||||
|
||||
function _getFile(item) {
|
||||
|
@ -469,13 +469,13 @@ var Zotero_LocateMenu = new function() {
|
|||
}
|
||||
|
||||
this.handleItems = function(items, event) {
|
||||
var attachments = [];
|
||||
for each(var item in items) {
|
||||
var attachment = _getBestNonNativeAttachment(item);
|
||||
if(attachment) {
|
||||
ZoteroPane_Local.viewAttachment(attachment.id, event, false, this.useExternalViewer);
|
||||
return;
|
||||
}
|
||||
if(attachment) attachments.push(attachment.id);
|
||||
}
|
||||
|
||||
ZoteroPane_Local.viewAttachment(attachments, event, false, this.useExternalViewer);
|
||||
}
|
||||
|
||||
function _getBestNonNativeAttachment(item) {
|
||||
|
@ -530,7 +530,6 @@ var Zotero_LocateMenu = new function() {
|
|||
var attachment = _getBestFile(item);
|
||||
if(attachment) {
|
||||
ZoteroPane_Local.showAttachmentInFilesystem(attachment.id);
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -3240,55 +3240,67 @@ var ZoteroPane = new function()
|
|||
}
|
||||
|
||||
|
||||
function viewAttachment(itemID, event, noLocateOnMissing, forceExternalViewer) {
|
||||
var attachment = Zotero.Items.get(itemID);
|
||||
if (!attachment.isAttachment()) {
|
||||
throw ("Item " + itemID + " is not an attachment in ZoteroPane_Local.viewAttachment()");
|
||||
function viewAttachment(itemIDs, event, noLocateOnMissing, forceExternalViewer) {
|
||||
if(typeof itemIDs != "object") itemIDs = [itemIDs];
|
||||
|
||||
// If multiple items, set up event so we open in new tab
|
||||
if(itemIDs.length > 1) {
|
||||
if(!event || (!event.metaKey && !event.shiftKey)) {
|
||||
event = {"metaKey":true, "shiftKey":true};
|
||||
}
|
||||
}
|
||||
|
||||
if (attachment.attachmentLinkMode == Zotero.Attachments.LINK_MODE_LINKED_URL) {
|
||||
this.loadURI(attachment.getField('url'), event);
|
||||
return;
|
||||
}
|
||||
|
||||
var file = attachment.getFile();
|
||||
if (file) {
|
||||
if(forceExternalViewer !== undefined) {
|
||||
var externalViewer = forceExternalViewer;
|
||||
} else {
|
||||
var mimeType = attachment.attachmentMIMEType;
|
||||
// If no MIME type specified, try to detect again (I guess in case
|
||||
// we've gotten smarter since the file was imported?)
|
||||
if (!mimeType) {
|
||||
mimeType = Zotero.MIME.getMIMETypeFromFile(file);
|
||||
for each(var itemID in itemIDs) {
|
||||
var attachment = Zotero.Items.get(itemID);
|
||||
if (!attachment.isAttachment()) {
|
||||
throw ("Item " + itemID + " is not an attachment in ZoteroPane_Local.viewAttachment()");
|
||||
}
|
||||
|
||||
if (attachment.attachmentLinkMode == Zotero.Attachments.LINK_MODE_LINKED_URL) {
|
||||
this.loadURI(attachment.getField('url'), event);
|
||||
continue;
|
||||
}
|
||||
|
||||
var file = attachment.getFile();
|
||||
if (file) {
|
||||
if(forceExternalViewer !== undefined) {
|
||||
var externalViewer = forceExternalViewer;
|
||||
} else {
|
||||
var mimeType = attachment.attachmentMIMEType;
|
||||
// If no MIME type specified, try to detect again (I guess in case
|
||||
// we've gotten smarter since the file was imported?)
|
||||
if (!mimeType) {
|
||||
mimeType = Zotero.MIME.getMIMETypeFromFile(file);
|
||||
|
||||
// TODO: update DB with new info
|
||||
}
|
||||
|
||||
// TODO: update DB with new info
|
||||
var ext = Zotero.File.getExtension(file);
|
||||
var externalViewer = Zotero.isStandalone || (!Zotero.MIME.hasNativeHandler(mimeType, ext) &&
|
||||
(!Zotero.MIME.hasInternalHandler(mimeType, ext) || Zotero.Prefs.get('launchNonNativeFiles')));
|
||||
}
|
||||
|
||||
var ext = Zotero.File.getExtension(file);
|
||||
var externalViewer = Zotero.isStandalone || (!Zotero.MIME.hasNativeHandler(mimeType, ext) &&
|
||||
(!Zotero.MIME.hasInternalHandler(mimeType, ext) || Zotero.Prefs.get('launchNonNativeFiles')));
|
||||
}
|
||||
if (!externalViewer) {
|
||||
var url = 'zotero://attachment/' + itemID + '/';
|
||||
this.loadURI(url, event, { attachmentID: itemID});
|
||||
if (!externalViewer) {
|
||||
var url = 'zotero://attachment/' + itemID + '/';
|
||||
this.loadURI(url, event, { attachmentID: itemID});
|
||||
}
|
||||
else {
|
||||
// Some platforms don't have nsILocalFile.launch, so we just load it and
|
||||
// let the Firefox external helper app window handle it
|
||||
try {
|
||||
file.launch();
|
||||
}
|
||||
catch (e) {
|
||||
Zotero.debug("launch() not supported -- passing file to loadURI()");
|
||||
var fileURL = attachment.getLocalFileURL();
|
||||
this.loadURI(fileURL);
|
||||
}
|
||||
}
|
||||
}
|
||||
else {
|
||||
// Some platforms don't have nsILocalFile.launch, so we just load it and
|
||||
// let the Firefox external helper app window handle it
|
||||
try {
|
||||
file.launch();
|
||||
}
|
||||
catch (e) {
|
||||
Zotero.debug("launch() not supported -- passing file to loadURI()");
|
||||
var fileURL = attachment.getLocalFileURL();
|
||||
this.loadURI(fileURL);
|
||||
}
|
||||
this.showAttachmentNotFoundDialog(itemID, noLocateOnMissing);
|
||||
}
|
||||
}
|
||||
else {
|
||||
this.showAttachmentNotFoundDialog(itemID, noLocateOnMissing);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue