commit ac19b0490ae260ce5f971794fdfd313f4c49c8d2
parent 83aeae942c6ba0d553d1673d2bd1fb6cbced19bc
Author: Simon Kornblith <simon@simonster.com>
Date: Sun, 10 Jun 2012 22:39:41 -0400
Merge branch 'no-new-collection-on-import'
Diffstat:
4 files changed, 81 insertions(+), 46 deletions(-)
diff --git a/chrome/content/zotero/fileInterface.js b/chrome/content/zotero/fileInterface.js
@@ -110,7 +110,7 @@ Zotero_File_Exporter.prototype._exportDone = function(obj, worked) {
* capabilities
**/
var Zotero_File_Interface = new function() {
- var _importCollection, _unlock;
+ var _unlock;
this.exportFile = exportFile;
this.exportCollection = exportCollection;
@@ -195,7 +195,7 @@ var Zotero_File_Interface = new function() {
/**
* Creates Zotero.Translate instance and shows file picker for file import
*/
- function importFile(file) {
+ function importFile(file, createNewCollectionOverride) {
var translation = new Zotero.Translate.Import();
if(!file) {
var translators = translation.getTranslators();
@@ -218,9 +218,22 @@ var Zotero_File_Interface = new function() {
file = fp.file;
}
+ var createNewCollection = createNewCollectionOverride;
+ if(createNewCollectionOverride === undefined) {
+ createNewCollection = Zotero.Prefs.get("import.createNewCollection.fromFile");
+ } else if(!createNewCollectionOverride) {
+ try {
+ if (!ZoteroPane.collectionsView.editable) {
+ ZoteroPane.collectionsView.selectLibrary(null);
+ }
+ } catch(e) {}
+ }
+
translation.setLocation(file);
// get translators again, bc now we can check against the file
- translation.setHandler("translators", function(obj, item) { _importTranslatorsAvailable(obj, item) });
+ translation.setHandler("translators", function(obj, item) {
+ _importTranslatorsAvailable(obj, item, createNewCollection);
+ });
translators = translation.getTranslators();
}
@@ -258,14 +271,16 @@ var Zotero_File_Interface = new function() {
var translate = new Zotero.Translate.Import();
translate.setString(str);
translate.setHandler("translators", function(obj, item) {
- _importTranslatorsAvailable(obj, item)
+ _importTranslatorsAvailable(obj, item, Zotero.Prefs.get("import.createNewCollection.fromClipboard"));
});
translators = translate.getTranslators();
}
- function _importTranslatorsAvailable(translation, translators) {
+ function _importTranslatorsAvailable(translation, translators, createNewCollection) {
if(translators.length) {
+ var importCollection = null, libraryID = null;
+
if(translation.location instanceof Components.interfaces.nsIFile) {
var leafName = translation.location.leafName;
var collectionName = (translation.location.isDirectory() || leafName.indexOf(".") === -1 ? leafName
@@ -281,14 +296,57 @@ var Zotero_File_Interface = new function() {
var collectionName = Zotero.getString("fileInterface.imported")+" "+(new Date()).toLocaleString();
}
- // create a new collection to take in imported items
- _importCollection = Zotero.Collections.add(collectionName);
+ if(createNewCollection) {
+ // Create a new collection to take imported items
+ importCollection = Zotero.Collections.add(collectionName);
+ } else {
+ // Import into currently selected collection
+ try {
+ libraryID = ZoteroPane.getSelectedLibraryID();
+ importCollection = ZoteroPane.getSelectedCollection();
+ } catch(e) {}
+ }
// import items
translation.setTranslator(translators[0]);
- translation.setHandler("collectionDone", _importCollectionDone);
+
+ if(importCollection) {
+ /*
+ * Saves collections after they've been imported. Input item is of the
+ * type outputted by Zotero.Collection.toArray(); only receives top-level
+ * collections
+ */
+ translation.setHandler("collectionDone", function(obj, collection) {
+ collection.parent = importCollection.id;
+ collection.save();
+ });
+ }
+
translation.setHandler("itemDone", Zotero_File_Interface.updateProgress);
- translation.setHandler("done", _importDone);
+
+ /*
+ * closes items imported indicator
+ */
+ translation.setHandler("done", function(obj, worked) {
+ // add items to import collection
+ if(importCollection) {
+ importCollection.addItems([item.id for each(item in obj.newItems)]);
+ }
+
+ Zotero.DB.commitTransaction();
+
+ Zotero_File_Interface.Progress.close();
+ Zotero.UnresponsiveScriptIndicator.enable();
+
+ if (worked) {
+ if(importCollection) {
+ Zotero.Notifier.trigger('refresh', 'collection', importCollection.id);
+ }
+ } else {
+ if(importCollection) importCollection.erase();
+ window.alert(Zotero.getString("fileInterface.importError"));
+ }
+ });
Zotero.UnresponsiveScriptIndicator.disable();
// show progress indicator
@@ -298,7 +356,7 @@ var Zotero_File_Interface = new function() {
window.setTimeout(function() {
Zotero.DB.beginTransaction();
- translation.translate();
+ translation.translate(libraryID);
}, 0);
} else {
// TODO: localize and remove fileInterface.fileFormatUnsupported string
@@ -325,37 +383,6 @@ var Zotero_File_Interface = new function() {
}
/*
- * Saves collections after they've been imported. Input item is of the type
- * outputted by Zotero.Collection.toArray(); only receives top-level
- * collections
- */
- function _importCollectionDone(obj, collection) {
- collection.parent = _importCollection.id;
- collection.save();
- }
-
- /*
- * closes items imported indicator
- */
- function _importDone(obj, worked) {
- // add items to import collection
- _importCollection.addItems([item.id for each(item in obj.newItems)]);
-
- Zotero.DB.commitTransaction();
-
- Zotero_File_Interface.Progress.close();
- Zotero.UnresponsiveScriptIndicator.enable();
-
- if (worked) {
- Zotero.Notifier.trigger('refresh', 'collection', _importCollection.id);
- }
- else {
- _importCollection.erase();
- window.alert(Zotero.getString("fileInterface.importError"));
- }
- }
-
- /*
* Creates a bibliography from a collection or saved search
*/
function bibliographyFromCollection() {
diff --git a/chrome/locale/en-US/zotero/zotero.properties b/chrome/locale/en-US/zotero/zotero.properties
@@ -424,7 +424,8 @@ ingester.importReferRISDialog.text = Do you want to import items from "%1$S" int
ingester.importReferRISDialog.checkMsg = Always allow for this site
ingester.importFile.title = Import File
-ingester.importFile.text = Do you want to import the file "%S"?\n\nItems will be added to a new collection.
+ingester.importFile.text = Do you want to import the file "%S"?
+ingester.importFile.intoNewCollection = Import into new collection
ingester.lookup.performing = Performing Lookup…
ingester.lookup.error = An error occurred while performing lookup for this item.
diff --git a/components/zotero-service.js b/components/zotero-service.js
@@ -377,7 +377,7 @@ ZoteroCommandLineHandler.prototype = {
.createInstance(Components.interfaces.nsIProtocolHandler).newChannel(uri);
}
} else {
- Zotero.debug("Not handling URL: "+uri.spec);
+ this.Zotero.debug("Not handling URL: "+uri.spec);
}
}
@@ -393,15 +393,19 @@ ZoteroCommandLineHandler.prototype = {
this.Zotero.Styles.install(file);
} else {
// Ask before importing
+ var checkState = {"value":this.Zotero.Prefs.get('import.createNewCollection.fromFileOpenHandler')};
if(Components.classes["@mozilla.org/embedcomp/prompt-service;1"]
.getService(Components.interfaces.nsIPromptService)
- .confirm(null, this.Zotero.getString('ingester.importFile.title'),
- this.Zotero.getString('ingester.importFile.text', [file.leafName]))) {
+ .confirmCheck(null, this.Zotero.getString('ingester.importFile.title'),
+ this.Zotero.getString('ingester.importFile.text', [file.leafName]),
+ this.Zotero.getString('ingester.importFile.intoNewCollection'),
+ checkState)) {
// Perform file import in front window
var wm = Components.classes["@mozilla.org/appshell/window-mediator;1"]
.getService(Components.interfaces.nsIWindowMediator);
var browserWindow = wm.getMostRecentWindow("navigator:browser");
- browserWindow.Zotero_File_Interface.importFile(file);
+ browserWindow.Zotero_File_Interface.importFile(file, checkState.value);
+ this.Zotero.Prefs.set('import.createNewCollection.fromFileOpenHandler', checkState.value);
}
}
}
diff --git a/defaults/preferences/zotero.js b/defaults/preferences/zotero.js
@@ -94,6 +94,9 @@ pref("extensions.zotero.export.bibliographyLocale", '');
pref("extensions.zotero.export.citePaperJournalArticleURL", false);
pref("extensions.zotero.export.displayCharsetOption", false);
pref("extensions.zotero.import.charset", "auto");
+pref("extensions.zotero.import.createNewCollection.fromFile", true);
+pref("extensions.zotero.import.createNewCollection.fromClipboard", true);
+pref("extensions.zotero.import.createNewCollection.fromFileOpenHandler", true);
pref("extensions.zotero.rtfScan.lastInputFile", "");
pref("extensions.zotero.rtfScan.lastOutputFile", "");