Add "Save to Zotero" option to unknown content type dialog. This is probably not for 2.1.

This commit is contained in:
Simon Kornblith 2011-03-07 17:47:01 +00:00
parent 0ebe917dba
commit 496b4b6f45
6 changed files with 145 additions and 5 deletions

View file

@ -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

View file

@ -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 <http://www.gnu.org/licenses/>.
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);

View file

@ -0,0 +1,38 @@
<?xml version="1.0" encoding="UTF-8"?>
<!-- ***** BEGIN LICENSE BLOCK *****
FlashGot - a Firefox extension for external download managers integration
Copyright (C) 2004-2011 Giorgio Maone - g.maone@informaction.com
This program 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 2 of the License, or
(at your option) any later version.
This program 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 this program; if not, write to the Free Software
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
***** END LICENSE BLOCK ***** -->
<!DOCTYPE overlay [
<!ENTITY % zoteroDTD SYSTEM "chrome://zotero/locale/zotero.dtd"> %zoteroDTD;
]>
<overlay id="flashgotDMOverlayFF"
xmlns="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul">
<script type="application/x-javascript" src="include.js"/>
<script type="application/x-javascript" src="downloadOverlay.js"/>
<radiogroup id="mode">
<vbox insertbefore="save" id="zotero-container" flex="1">
<radio id="zotero-radio" label="&zotero.downloadManager.label;"/>
</vbox>
</radiogroup>
</overlay>

View file

@ -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){

View file

@ -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) {

View file

@ -226,4 +226,6 @@
<!ENTITY zotero.rtfScan.outputFile.label "Output File">
<!ENTITY zotero.file.choose.label "Choose File...">
<!ENTITY zotero.file.noneSelected.label "No file selected">
<!ENTITY zotero.file.noneSelected.label "No file selected">
<!ENTITY zotero.downloadManager.label "Save to Zotero">