commit 4783051f4e8ae303cd775fc5397ec03bb931bb59
parent 7a50fcafe0d6ec607638403617a21d23ea7e38a5
Author: Simon Kornblith <simon@simonster.com>
Date: Mon, 11 Jul 2011 22:19:10 +0000
- Properly handle multiple item selection in context/locate menu
- Don't show context menu options when >20 items selected
Diffstat:
2 files changed, 65 insertions(+), 54 deletions(-)
diff --git a/chrome/content/zotero/locateMenu.js b/chrome/content/zotero/locateMenu.js
@@ -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;
}
}
}
diff --git a/chrome/content/zotero/zoteroPane.js b/chrome/content/zotero/zoteroPane.js
@@ -3240,54 +3240,66 @@ 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 (attachment.attachmentLinkMode == Zotero.Attachments.LINK_MODE_LINKED_URL) {
- this.loadURI(attachment.getField('url'), event);
- return;
+ // 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};
+ }
}
- 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});
- }
- 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();
+ if (!externalViewer) {
+ var url = 'zotero://attachment/' + itemID + '/';
+ this.loadURI(url, event, { attachmentID: itemID});
}
- 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);
+ }
}
}
- }
- else {
- this.showAttachmentNotFoundDialog(itemID, noLocateOnMissing);
+ else {
+ this.showAttachmentNotFoundDialog(itemID, noLocateOnMissing);
+ }
}
}