From 496b4b6f455bf6718cde71ffdd008f1a4ace538a Mon Sep 17 00:00:00 2001 From: Simon Kornblith Date: Mon, 7 Mar 2011 17:47:01 +0000 Subject: [PATCH] Add "Save to Zotero" option to unknown content type dialog. This is probably not for 2.1. --- chrome.manifest | 1 + chrome/content/zotero/downloadOverlay.js | 93 +++++++++++++++++++ chrome/content/zotero/downloadOverlay.xul | 38 ++++++++ chrome/content/zotero/xpcom/attachments.js | 10 +- chrome/content/zotero/xpcom/progressWindow.js | 4 +- chrome/locale/en-US/zotero/zotero.dtd | 4 +- 6 files changed, 145 insertions(+), 5 deletions(-) create mode 100644 chrome/content/zotero/downloadOverlay.js create mode 100644 chrome/content/zotero/downloadOverlay.xul 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; +]> + + + +