commit f7893ef4002d3a85355d8226e8c535906f5634fa
parent 3f3666c972d35ec5a3321b9e94358d5af7a13a17
Author: Aurimas Vinckevicius <aurimas.dev@gmail.com>
Date: Tue, 20 Jan 2015 22:46:30 -0600
Don't require Zotero restart to change RIS/BibTeX handling preference
Diffstat:
1 file changed, 49 insertions(+), 17 deletions(-)
diff --git a/chrome/content/zotero/xpcom/mimeTypeHandler.js b/chrome/content/zotero/xpcom/mimeTypeHandler.js
@@ -55,30 +55,50 @@ Zotero.MIMETypeHandler = new function () {
_observers = [];
if(Zotero.Prefs.get("parseEndNoteMIMETypes")) {
- this.addHandler("application/x-endnote-refer", _importHandler, true);
- this.addHandler("application/x-research-info-systems", _importHandler, true);
- this.addHandler("application/x-inst-for-scientific-info", _importHandler, true);
-
- this.addHandler("text/x-bibtex", _importHandler, true);
- this.addHandler("application/x-bibtex", _importHandler, true);
-
- //
- // And some non-standard ones
- //
- this.addHandler("text/x-research-info-systems", _importHandler, true);
- // Nature uses this one
- this.addHandler("text/application/x-research-info-systems", _importHandler, true);
- // Cell uses this one
- this.addHandler("text/ris", _importHandler, true);
- // Not even trying
- this.addHandler("ris", _importHandler, true);
+ this.registerMetadataHandlers();
}
+ Zotero.Prefs.registerObserver("parseEndNoteMIMETypes", function(val) {
+ if (val) this.registerMetadataHandlers();
+ else this.unregisterMetadataHandlers();
+ }.bind(this));
+
this.addHandler("application/vnd.citationstyles.style+xml", function(a1, a2) { Zotero.Styles.install(a1, a2) });
this.addHandler("text/x-csl", function(a1, a2) { Zotero.Styles.install(a1, a2) }); // deprecated
this.addHandler("application/x-zotero-schema", Zotero.Schema.importSchema);
this.addHandler("application/x-zotero-settings", Zotero.Prefs.importSettings);
}
+ // MIME types that Zotero should handle when parseEndNoteMIMETypes preference
+ // is enabled
+ var metadataMIMETypes = [
+ "application/x-endnote-refer", "application/x-research-info-systems",
+ "application/x-inst-for-scientific-info",
+ "text/x-bibtex", "application/x-bibtex",
+ // Non-standard
+ "text/x-research-info-systems",
+ "text/application/x-research-info-systems", // Nature serves this
+ "text/ris", // Cell serves this
+ "ris" // Not even trying
+ ];
+
+ /**
+ * Registers MIME types for parseEndNoteMIMETypes preference
+ */
+ this.registerMetadataHandlers = function() {
+ for (var i=0; i<metadataMIMETypes.length; i++) {
+ this.addHandler(metadataMIMETypes[i], _importHandler, true);
+ }
+ }
+
+ /**
+ * Unregisters MIME types for parseEndNoteMIMETypes preference
+ */
+ this.unregisterMetadataHandlers = function() {
+ for (var i=0; i<metadataMIMETypes.length; i++) {
+ this.removeHandler(metadataMIMETypes[i]);
+ }
+ }
+
/**
* Adds a handler to handle a specific MIME type
* @param {String} type MIME type to handle
@@ -93,6 +113,18 @@ Zotero.MIMETypeHandler = new function () {
}
/**
+ * Removes a handler for a specific MIME type
+ * @param {String} type MIME type to handle
+ */
+ this.removeHandler = function(type) {
+ delete _typeHandlers[type];
+ var i = _ignoreContentDispositionTypes.indexOf(type);
+ if (i != -1) {
+ _ignoreContentDispositionTypes.splice(i, 1);
+ }
+ }
+
+ /**
* Adds an observer to inspect and possibly modify page headers
*/
this.addObserver = function(fn) {