commit 020553607df1f2d0375f8292b94e2d676b79703f
parent 1c3a10909a29bf31f0291371ba665e736a0b7eb2
Author: Dan Stillman <dstillman@zotero.org>
Date: Wed, 16 Sep 2009 09:23:57 +0000
- Double-clicking an item without a URL didn't open child attachment
- Fixed various issues with adding/dragging files/links to group libraries
Diffstat:
6 files changed, 58 insertions(+), 27 deletions(-)
diff --git a/chrome/content/zotero/bindings/itembox.xml b/chrome/content/zotero/bindings/itembox.xml
@@ -240,7 +240,7 @@
createInstance(Components.interfaces.nsIURI);
// First try to find a snapshot matching the item's URL field
- var snapID = this.item.getBestSnapshot();
+ var snapID = this.item.getBestAttachment();
if (snapID) {
spec = Zotero.Items.get(snapID).getLocalFileURL();
uri.spec = spec;
diff --git a/chrome/content/zotero/overlay.js b/chrome/content/zotero/overlay.js
@@ -1121,8 +1121,8 @@ var ZoteroPane = new function()
this.updateNoteButtonMenu = function () {
var items = ZoteroPane.getSelectedItems();
var button = document.getElementById('zotero-tb-add-child-note');
- button.disabled = this.canEdit() && !(items.length == 1
- && (items[0].isRegularItem() || !items[0].isTopLevelItem()));
+ button.disabled = !this.canEdit() ||
+ !(items.length == 1 && (items[0].isRegularItem() || !items[0].isTopLevelItem()));
}
@@ -2130,7 +2130,7 @@ var ZoteroPane = new function()
var uri = Components.classes["@mozilla.org/network/standard-url;1"].
createInstance(Components.interfaces.nsIURI);
- var snapID = item.getBestSnapshot();
+ var snapID = item.getBestAttachment();
if (snapID) {
spec = Zotero.Items.get(snapID).getLocalFileURL();
if (spec) {
@@ -2482,11 +2482,22 @@ var ZoteroPane = new function()
return;
}
+ var itemGroup = ZoteroPane.collectionsView._getItemAtRow(this.collectionsView.selection.currentIndex);
+ if (link && itemGroup.isWithinGroup()) {
+ var pr = Components.classes["@mozilla.org/network/default-prompt;1"]
+ .getService(Components.interfaces.nsIPrompt);
+ pr.alert("", "Linked files cannot be added to group libraries.");
+ return;
+ }
+
+ // TODO: disable in menu
if (!this.canEditFiles()) {
this.displayCannotEditLibraryFilesMessage();
return;
}
+ var libraryID = itemGroup.ref.libraryID;
+
var nsIFilePicker = Components.interfaces.nsIFilePicker;
var fp = Components.classes["@mozilla.org/filepicker;1"]
.createInstance(nsIFilePicker);
@@ -2503,7 +2514,7 @@ var ZoteroPane = new function()
if(link)
attachmentID = Zotero.Attachments.linkFromFile(file, id);
else
- attachmentID = Zotero.Attachments.importFromFile(file, id);
+ attachmentID = Zotero.Attachments.importFromFile(file, id, libraryID);
if(attachmentID && !id)
{
@@ -2703,10 +2714,8 @@ var ZoteroPane = new function()
//
//
- if (libraryID) {
- var pr = Components.classes["@mozilla.org/network/default-prompt;1"]
- .getService(Components.interfaces.nsIPrompt);
- pr.alert("", "Files cannot currently be added to group libraries.");
+ if (!ZoteroPane.canEditFiles(row)) {
+ ZoteroPane.displayCannotEditLibraryFilesMessage();
return;
}
@@ -2717,7 +2726,7 @@ var ZoteroPane = new function()
var collectionID = false;
}
- Zotero.Attachments.importFromURL(url, false, false, false, collectionID);
+ Zotero.Attachments.importFromURL(url, false, false, false, collectionID, null, libraryID);
return;
}
}
diff --git a/chrome/content/zotero/xpcom/attachments.js b/chrome/content/zotero/xpcom/attachments.js
@@ -190,7 +190,7 @@ Zotero.Attachments = new function(){
}
- function importFromURL(url, sourceItemID, forceTitle, forceFileBaseName, parentCollectionIDs, mimeType) {
+ function importFromURL(url, sourceItemID, forceTitle, forceFileBaseName, parentCollectionIDs, mimeType, libraryID) {
Zotero.debug('Importing attachment from URL');
if (sourceItemID && parentCollectionIDs) {
@@ -228,7 +228,7 @@ Zotero.Attachments = new function(){
Zotero.Browser.deleteHiddenBrowser(browser);
};
Zotero.Attachments.importFromDocument(browser.contentDocument,
- sourceItemID, forceTitle, parentCollectionIDs, callback);
+ sourceItemID, forceTitle, parentCollectionIDs, callback, libraryID);
imported = true;
};
browser.addEventListener("pageshow", onpageshow, false);
@@ -259,7 +259,10 @@ Zotero.Attachments = new function(){
try {
// Create a new attachment
var attachmentItem = new Zotero.Item('attachment');
- if (sourceItemID) {
+ if (libraryID) {
+ attachmentItem.libraryID = libraryID;
+ }
+ else if (sourceItemID) {
var parentItem = Zotero.Items.get(sourceItemID);
attachmentItem.libraryID = parentItem.libraryID;
}
diff --git a/chrome/content/zotero/xpcom/collectionTreeView.js b/chrome/content/zotero/xpcom/collectionTreeView.js
@@ -1468,7 +1468,7 @@ Zotero.CollectionTreeView.prototype.drop = function(row, orient)
var wm = Components.classes["@mozilla.org/appshell/window-mediator;1"]
.getService(Components.interfaces.nsIWindowMediator);
var win = wm.getMostRecentWindow("navigator:browser");
- win.ZoteroPane.addItemFromURL(url, 'temporaryPDFHack', row); // TODO: don't do this
+ win.ZoteroPane.addItemFromURL(url, 'temporaryPDFHack', null, row); // TODO: don't do this
continue;
}
diff --git a/chrome/content/zotero/xpcom/data/item.js b/chrome/content/zotero/xpcom/data/item.js
@@ -3108,27 +3108,34 @@ Zotero.Item.prototype.getAttachments = function(includeTrashed) {
}
+Zotero.Item.prototype.getBestSnapshot = function () {
+ var msg = "Zotero.Item.getBestSnapshot() is deprecated -- use getBestAttachment";
+ Zotero.debug(msg, 2);
+ Components.utils.reportError(msg);
+ return this.getBestAttachment();
+}
+
+
/*
- * Returns the itemID of the latest child snapshot of this item with the
- * same URL as the item itself, or false if none
+ * Looks for attachment in the following order: oldest PDF attachment matching parent URL,
+ * oldest non-PDF attachment matching parent URL, oldest PDF attachment not matching URL,
+ * old non-PDF attachment not matching URL
+ *
+ * @return {Integer} itemID for attachment
*/
-Zotero.Item.prototype.getBestSnapshot = function() {
+Zotero.Item.prototype.getBestAttachment = function() {
if (!this.isRegularItem()) {
- throw ("getBestSnapshot() can only be called on regular items");
+ throw ("getBestAttachment() can only be called on regular items");
}
var url = this.getField('url');
- if (!url) {
- return false;
- }
- var sql = "SELECT IA.itemID, value FROM itemAttachments IA NATURAL JOIN items I "
+ var sql = "SELECT IA.itemID FROM itemAttachments IA NATURAL JOIN items I "
+ "LEFT JOIN itemData ID ON (IA.itemID=ID.itemID AND fieldID=1) "
+ "LEFT JOIN itemDataValues IDV ON (ID.valueID=IDV.valueID) "
+ "WHERE sourceItemID=? AND linkMode NOT IN (?) "
+ "AND IA.itemID NOT IN (SELECT itemID FROM deletedItems) "
+ "ORDER BY value=? DESC, mimeType='application/pdf' DESC, dateAdded ASC";
-
return Zotero.DB.valueQuery(sql, [this.id, Zotero.Attachments.LINK_MODE_LINKED_URL, url]);
}
diff --git a/chrome/content/zotero/xpcom/itemTreeView.js b/chrome/content/zotero/xpcom/itemTreeView.js
@@ -2274,10 +2274,22 @@ Zotero.ItemTreeView.prototype.drop = function(row, orient)
// Still string, so remote URL
if (typeof file == 'string') {
- var wm = Components.classes["@mozilla.org/appshell/window-mediator;1"]
- .getService(Components.interfaces.nsIWindowMediator);
- var win = wm.getMostRecentWindow("navigator:browser");
- win.ZoteroPane.addItemFromURL(url, 'temporaryPDFHack', row); // TODO: don't do this
+ if (sourceItemID) {
+ if (!itemGroup.filesEditable) {
+ var wm = Components.classes["@mozilla.org/appshell/window-mediator;1"]
+ .getService(Components.interfaces.nsIWindowMediator);
+ var win = wm.getMostRecentWindow("navigator:browser");
+ win.ZoteroPane.displayCannotEditLibraryFilesMessage();
+ return;
+ }
+ Zotero.Attachments.importFromURL(url, sourceItemID, false, false, null, null, targetLibraryID);
+ }
+ else {
+ var wm = Components.classes["@mozilla.org/appshell/window-mediator;1"]
+ .getService(Components.interfaces.nsIWindowMediator);
+ var win = wm.getMostRecentWindow("navigator:browser");
+ win.ZoteroPane.addItemFromURL(url, 'temporaryPDFHack'); // TODO: don't do this
+ }
continue;
}