diff --git a/chrome/content/zotero/bindings/timedtextarea.xml b/chrome/content/zotero/bindings/timedtextarea.xml index ba36b5bf7..b0e82b4de 100644 --- a/chrome/content/zotero/bindings/timedtextarea.xml +++ b/chrome/content/zotero/bindings/timedtextarea.xml @@ -102,7 +102,7 @@ textbox.inputField.QueryInterface(CI.nsIDOMNSEditableElement).editor ); } catch(ex) { - Zotero.debug(ex); + // this throws an error on window open... } } diff --git a/chrome/content/zotero/overlay.js b/chrome/content/zotero/overlay.js index 1b3b90d18..856c07b39 100644 --- a/chrome/content/zotero/overlay.js +++ b/chrome/content/zotero/overlay.js @@ -795,20 +795,18 @@ var ZoteroPane = new function() function addAttachmentFromPage(link, id) { + if (itemsView && itemsView._itemGroup.isCollection()) + { + var parentCollectionID = itemsView._itemGroup.ref.getID(); + } + if(link) { - var attachmentID = - Zotero.Attachments.linkFromDocument(window.content.document, id); + Zotero.Attachments.linkFromDocument(window.content.document, id, parentCollectionID); } else { - var attachmentID = - Zotero.Attachments.importFromDocument(window.content.document, id); - } - - if (attachmentID && itemsView && itemsView._itemGroup.isCollection()) - { - itemsView._itemGroup.ref.addItem(attachmentID); + Zotero.Attachments.importFromDocument(window.content.document, id, false, parentCollectionID); } } diff --git a/chrome/content/zotero/xpcom/attachments.js b/chrome/content/zotero/xpcom/attachments.js index 26009956d..c8f086e66 100644 --- a/chrome/content/zotero/xpcom/attachments.js +++ b/chrome/content/zotero/xpcom/attachments.js @@ -258,7 +258,7 @@ Zotero.Attachments = new function(){ // TODO: what if called on file:// document? - function linkFromDocument(document, sourceItemID){ + function linkFromDocument(document, sourceItemID, parentCollectionIDs){ Zotero.debug('Linking attachment from document'); var url = document.location; @@ -269,6 +269,13 @@ Zotero.Attachments = new function(){ var itemID = _addToDB(null, url, title, this.LINK_MODE_LINKED_URL, mimeType, charsetID, sourceItemID); + // Add to collections + var ids = Zotero.flattenArguments(parentCollectionIDs); + for each(var id in ids){ + var col = Zotero.Collections.get(id); + col.addItem(itemID); + } + // Run the fulltext indexer asynchronously (actually, it hangs the UI // thread, but at least it lets the menu close) setTimeout(function(){ @@ -279,7 +286,7 @@ Zotero.Attachments = new function(){ } - function importFromDocument(document, sourceItemID, forceTitle){ + function importFromDocument(document, sourceItemID, forceTitle, parentCollectionIDs){ Zotero.debug('Importing attachment from document'); var url = document.location; @@ -331,6 +338,13 @@ Zotero.Attachments = new function(){ _addToDB(file, url, title, Zotero.Attachments.LINK_MODE_IMPORTED_URL, mimeType, charsetID, sourceItemID, itemID); + // Add to collections + var ids = Zotero.flattenArguments(parentCollectionIDs); + for each(var id in ids){ + var col = Zotero.Collections.get(id); + col.addItem(itemID); + } + Zotero.DB.commitTransaction(); Zotero.Fulltext.indexDocument(document, itemID); diff --git a/chrome/content/zotero/xpcom/data_access.js b/chrome/content/zotero/xpcom/data_access.js index dc1da4bf2..c2fb21cc4 100644 --- a/chrome/content/zotero/xpcom/data_access.js +++ b/chrome/content/zotero/xpcom/data_access.js @@ -1515,9 +1515,19 @@ Zotero.Item.prototype.erase = function(deleteChildren){ // Remove item from parent collections var parentCollectionIDs = this.getCollections(); if (parentCollectionIDs){ + var notifierState = Zotero.Notifier.isEnabled(); + Zotero.Notifier.disable(); + for (var i=0; i 0) { rows.sort(function(a,b) { return a-b });