From b8fba0335daadf5d1a4d3ba150705d2b244a1580 Mon Sep 17 00:00:00 2001 From: Dan Stillman Date: Sun, 21 Jan 2007 22:56:46 +0000 Subject: [PATCH] - Make "Save Link As Zotero Snapshot" save attachment to selected collection - Fix hourglass cursor on importFromURL (happened with "Save Link As Z Snapshot") --- chrome/content/zotero/overlay.xul | 4 +-- chrome/content/zotero/xpcom/attachments.js | 29 ++++++++++++++++++---- chrome/content/zotero/xpcom/file.js | 2 -- chrome/content/zotero/xpcom/zotero.js | 2 +- 4 files changed, 27 insertions(+), 10 deletions(-) diff --git a/chrome/content/zotero/overlay.xul b/chrome/content/zotero/overlay.xul index f6b665f94..1eb1e9746 100644 --- a/chrome/content/zotero/overlay.xul +++ b/chrome/content/zotero/overlay.xul @@ -55,10 +55,10 @@ oncommand="var itemID = ZoteroPane.addItemFromPage(); ZoteroPane.newNote(false, itemID, window.content.getSelection().toString())"/> + oncommand="Zotero.Attachments.importFromURL(window.gContextMenu.linkURL, false, false, ZoteroPane.getSelectedCollection(true))"/> + oncommand="Zotero.Attachments.importFromURL(window.gContextMenu.onImage ? window.gContextMenu.imageURL : window.gContextMenu.bgImageURL, false, false, ZoteroPane.getSelectedCollection(true))"/> diff --git a/chrome/content/zotero/xpcom/attachments.js b/chrome/content/zotero/xpcom/attachments.js index 83303921f..f86beccc3 100644 --- a/chrome/content/zotero/xpcom/attachments.js +++ b/chrome/content/zotero/xpcom/attachments.js @@ -168,7 +168,7 @@ Zotero.Attachments = new function(){ } - function importFromURL(url, sourceItemID, forceTitle){ + function importFromURL(url, sourceItemID, forceTitle, parentCollectionIDs){ Zotero.debug('Importing attachment from URL'); Zotero.Utilities.HTTP.doHead(url, function(obj){ @@ -191,9 +191,13 @@ Zotero.Attachments = new function(){ if (Zotero.MIME.hasNativeHandler(mimeType, ext)){ var browser = Zotero.Browser.createHiddenBrowser(); browser.addEventListener("pageshow", function(){ - Zotero.Attachments.importFromDocument(browser.contentDocument, sourceItemID, forceTitle); - browser.removeEventListener("pageshow", arguments.callee, true); - Zotero.Browser.deleteHiddenBrowser(browser); + var callback = function () { + browser.removeEventListener("pageshow", arguments.callee, true); + Zotero.Browser.deleteHiddenBrowser(browser); + }; + + Zotero.Attachments.importFromDocument(browser.contentDocument, + sourceItemID, forceTitle, parentCollectionIDs, callback); }, true); browser.loadURI(url); } @@ -221,6 +225,15 @@ Zotero.Attachments = new function(){ attachmentItem.save(); var itemID = attachmentItem.getID(); + // Add to collections + if (parentCollectionIDs){ + var ids = Zotero.flattenArguments(parentCollectionIDs); + for each(var id in ids){ + var col = Zotero.Collections.get(id); + col.addItem(itemID); + } + } + // Create a new folder for this item in the storage directory var destDir = Zotero.getStorageDirectory(); destDir.append(itemID); @@ -351,7 +364,7 @@ Zotero.Attachments = new function(){ } - function importFromDocument(document, sourceItemID, forceTitle, parentCollectionIDs){ + function importFromDocument(document, sourceItemID, forceTitle, parentCollectionIDs, callback){ Zotero.debug('Importing attachment from document'); var url = document.location.href; @@ -444,6 +457,10 @@ Zotero.Attachments = new function(){ } Zotero.Fulltext.indexDocument(document, itemID); + + if (callback) { + callback(); + } }); // The attachment is still incomplete here, but we can't risk @@ -635,6 +652,8 @@ Zotero.Attachments = new function(){ // Chain fulltext indexer inside the charset callback, // since it's asynchronous and a prerequisite Zotero.Fulltext.indexDocument(browser.contentDocument, itemID); + + Zotero.Browser.deleteHiddenBrowser(browser); } }, itemID); diff --git a/chrome/content/zotero/xpcom/file.js b/chrome/content/zotero/xpcom/file.js index 72111772c..5f3970c35 100644 --- a/chrome/content/zotero/xpcom/file.js +++ b/chrome/content/zotero/xpcom/file.js @@ -155,8 +155,6 @@ Zotero.File = new function(){ prefService.setCharPref('intl.charset.detector', oldPref); callback(charset, args); - - Zotero.Browser.deleteHiddenBrowser(browser); }, false); } } diff --git a/chrome/content/zotero/xpcom/zotero.js b/chrome/content/zotero/xpcom/zotero.js index 9566b4145..c50b4cb86 100644 --- a/chrome/content/zotero/xpcom/zotero.js +++ b/chrome/content/zotero/xpcom/zotero.js @@ -1271,7 +1271,7 @@ Zotero.Browser = new function() { return newHiddenBrowser; } - function deleteHiddenBrowser(myBrowser) { + function deleteHiddenBrowser(myBrowser) { // Delete a hidden browser myBrowser.parentNode.removeChild(myBrowser); delete myBrowser;