diff --git a/chrome.manifest b/chrome.manifest
index 13031394f1..ca6beaca82 100644
--- a/chrome.manifest
+++ b/chrome.manifest
@@ -48,6 +48,7 @@ overlay chrome://browser/content/browser.xul chrome://zotero/content/statusBarOv
overlay chrome://browser/content/browser.xul chrome://zotero/content/overlay.xul
overlay chrome://zotero/content/preferences/preferences.xul chrome://zotero/content/preferences/preferences_firefox.xul application={ec8030f7-c20a-464f-9b0e-13a3a9e97384}
overlay chrome://zotero/content/preferences/preferences.xul#cite chrome://zotero/content/preferences/preferences_firefox.xul application={ec8030f7-c20a-464f-9b0e-13a3a9e97384}
+overlay chrome://mozapps/content/downloads/unknownContentType.xul chrome://zotero/content/downloadOverlay.xul
style chrome://browser/content/browser.xul chrome://zotero/skin/zotero.css
style chrome://global/content/customizeToolbar.xul chrome://zotero/skin/zotero.css
diff --git a/chrome/content/zotero/downloadOverlay.js b/chrome/content/zotero/downloadOverlay.js
new file mode 100644
index 0000000000..8816f3c2f4
--- /dev/null
+++ b/chrome/content/zotero/downloadOverlay.js
@@ -0,0 +1,93 @@
+/*
+ ***** BEGIN LICENSE BLOCK *****
+
+ Copyright © 2011 Center for History and New Media
+ George Mason University, Fairfax, Virginia, USA
+ http://zotero.org
+
+ This file is part of Zotero.
+
+ Zotero is free software: you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation, either version 3 of the License, or
+ (at your option) any later version.
+
+ Zotero is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with Zotero. If not, see .
+
+
+ Based on code from Greasemonkey and PiggyBank
+
+ ***** END LICENSE BLOCK *****
+*/
+var Zotero_DownloadOverlay = new function() {
+ /**
+ * Saves this item, if we are supposed to save it.
+ *
+ * @return {Boolean} True if an item was saved, false if we were not supposed to save
+ */
+ this.handleSave = function() {
+ if(!document.getElementById('zotero-radio').selected) return false;
+
+ var url = dialog.mLauncher.source.spec;
+ Zotero.debug("Downloading from "+url);
+
+ // set up progress window
+ var win = Components.classes["@mozilla.org/appshell/window-mediator;1"]
+ .getService(Components.interfaces.nsIWindowMediator)
+ .getMostRecentWindow("navigator:browser");
+ var libraryID = (win ? win.ZoteroPane.getSelectedLibraryID() : false);
+ var collection = (win ? win.ZoteroPane.getSelectedCollection() : false);
+
+ // set up callback
+ var callback = function(item) {
+ if(!win) return;
+
+ if(item) win.Zotero_Browser.itemDone(null, item);
+ win.Zotero_Browser.finishScraping(null, !!item);
+ };
+
+ // show progress dialog
+ win.Zotero_Browser.progress.show();
+
+ // perform import
+ Zotero.Attachments.importFromURL(url, false, false, false,
+ collection ? [collection.id] : [], dialog.mLauncher.MIMEInfo.MIMEType,
+ libraryID, callback);
+
+ // mimic dialog cancellation
+ dialog.onCancel();
+
+ return true;
+ };
+
+ /**
+ * Called when mode in dialog has been changed
+ */
+ this.modeChanged = function() {
+ Zotero.debug("rememberChoice");
+ document.getElementById('rememberChoice').disabled = document.getElementById('zotero-radio').selected;
+ };
+
+ /**
+ * Called when the save dialog is opened
+ */
+ this.init = function() {
+ // Hook in event listener to ondialogaccept
+ document.documentElement.setAttribute('ondialogaccept',
+ 'if(!Zotero_DownloadOverlay.handleSave()) { '
+ + document.documentElement.getAttribute('ondialogaccept')
+ +'}');
+
+ // Hook in event listener for mode change
+ var radios = document.getElementById('mode').
+ addEventListener("command", Zotero_DownloadOverlay.modeChanged, false);
+ };
+}
+
+window.addEventListener("load", Zotero_DownloadOverlay.init, false);
\ No newline at end of file
diff --git a/chrome/content/zotero/downloadOverlay.xul b/chrome/content/zotero/downloadOverlay.xul
new file mode 100644
index 0000000000..5538b8c0df
--- /dev/null
+++ b/chrome/content/zotero/downloadOverlay.xul
@@ -0,0 +1,38 @@
+
+
+
+ %zoteroDTD;
+]>
+
+
+
+
+
+
+
+
+
+
+
+
diff --git a/chrome/content/zotero/xpcom/attachments.js b/chrome/content/zotero/xpcom/attachments.js
index 13d3c94a9e..5c82bff36d 100644
--- a/chrome/content/zotero/xpcom/attachments.js
+++ b/chrome/content/zotero/xpcom/attachments.js
@@ -199,7 +199,8 @@ Zotero.Attachments = new function(){
}
- function importFromURL(url, sourceItemID, forceTitle, forceFileBaseName, parentCollectionIDs, mimeType, libraryID) {
+ function importFromURL(url, sourceItemID, forceTitle, forceFileBaseName, parentCollectionIDs,
+ mimeType, libraryID, callback) {
Zotero.debug('Importing attachment from URL');
if (sourceItemID && parentCollectionIDs) {
@@ -232,12 +233,13 @@ Zotero.Attachments = new function(){
if (imported) {
return;
}
- var callback = function () {
+ var importCallback = function (item) {
browser.removeEventListener("pageshow", onpageshow, false);
Zotero.Browser.deleteHiddenBrowser(browser);
+ callback(item);
};
Zotero.Attachments.importFromDocument(browser.contentDocument,
- sourceItemID, forceTitle, parentCollectionIDs, callback, libraryID);
+ sourceItemID, forceTitle, parentCollectionIDs, importCallback, libraryID);
imported = true;
};
browser.addEventListener("pageshow", onpageshow, false);
@@ -356,6 +358,8 @@ Zotero.Attachments = new function(){
nsIURL.spec = url;
wbp.saveURI(nsIURL, null, null, null, null, file);
+ callback(attachmentItem);
+
return attachmentItem;
}
catch (e){
diff --git a/chrome/content/zotero/xpcom/progressWindow.js b/chrome/content/zotero/xpcom/progressWindow.js
index e9c967a88c..628d67eb7e 100644
--- a/chrome/content/zotero/xpcom/progressWindow.js
+++ b/chrome/content/zotero/xpcom/progressWindow.js
@@ -139,7 +139,9 @@ Zotero.ProgressWindow = function(_window){
getService(Components.interfaces.nsIWindowWatcher);
if (!_window){
- _window = ww.activeWindow;
+ _window = Components.classes["@mozilla.org/appshell/window-mediator;1"]
+ .getService(Components.interfaces.nsIWindowMediator)
+ .getMostRecentWindow("navigator:browser");
}
if (_window) {
diff --git a/chrome/locale/en-US/zotero/zotero.dtd b/chrome/locale/en-US/zotero/zotero.dtd
index d5562076df..d6fdbfd25f 100644
--- a/chrome/locale/en-US/zotero/zotero.dtd
+++ b/chrome/locale/en-US/zotero/zotero.dtd
@@ -226,4 +226,6 @@
-
\ No newline at end of file
+
+
+
\ No newline at end of file