From ef257405108a9236b9230c041e99db27e68bd451 Mon Sep 17 00:00:00 2001 From: Simon Kornblith Date: Thu, 5 Jul 2012 18:12:00 -0400 Subject: [PATCH 1/4] Use the same rules for creating links and snapshots, regardless of whether attachments can be saved to the current library --- .../xpcom/translation/translate_item.js | 28 ++++++++----------- 1 file changed, 12 insertions(+), 16 deletions(-) diff --git a/chrome/content/zotero/xpcom/translation/translate_item.js b/chrome/content/zotero/xpcom/translation/translate_item.js index 06de3957f2..b7340099d4 100644 --- a/chrome/content/zotero/xpcom/translation/translate_item.js +++ b/chrome/content/zotero/xpcom/translation/translate_item.js @@ -309,17 +309,16 @@ Zotero.Translate.ItemSaver.prototype = { "_saveAttachmentDownload":function(attachment, parentID) { Zotero.debug("Translate: Adding attachment", 4); - // determine whether to save attachments at all - var automaticSnapshots = Zotero.Prefs.get("automaticSnapshots"); - var downloadAssociatedFiles = Zotero.Prefs.get("downloadAssociatedFiles"); - if(!attachment.url && !attachment.document) { Zotero.debug("Translate: Not adding attachment: no URL specified", 2); } else { - var shouldAttach = ((attachment.document - || (attachment.mimeType && attachment.mimeType == "text/html")) && automaticSnapshots) - || downloadAssociatedFiles; - if(!shouldAttach) return; + // Determine whether to save an attachment + if(attachment.document + || (attachment.mimeType && attachment.mimeType == "text/html")) { + if(!Zotero.Prefs.get("automaticSnapshots")) return; + } else { + if(!Zotero.Prefs.get("downloadAssociatedFiles")) return; + } if(attachment.document && "__wrappedDOMObject" in attachment.document) { attachment.document = attachment.document.__wrappedDOMObject; @@ -347,17 +346,14 @@ Zotero.Translate.ItemSaver.prototype = { } else { // if snapshot is not explicitly set to false, retrieve snapshot if(attachment.document) { - if(automaticSnapshots) { - try { - Zotero.Attachments.importFromDocument(attachment.document, parentID, attachment.title); - } catch(e) { - Zotero.debug("Translate: Error attaching document", 2); - } + try { + Zotero.Attachments.importFromDocument(attachment.document, parentID, attachment.title); + } catch(e) { + Zotero.debug("Translate: Error attaching document", 2); } // Save attachment if snapshot pref enabled or not HTML // (in which case downloadAssociatedFiles applies) - } else if(this._saveFiles && (automaticSnapshots || !attachment.mimeType - || attachment.mimeType != "text/html")) { + } else { var mimeType = (attachment.mimeType ? attachment.mimeType : null); var title = (attachment.title ? attachment.title : null); From d2dcf2bbc70efbb4e3d4ee09a3e59ebbceadd69f Mon Sep 17 00:00:00 2001 From: Simon Kornblith Date: Sun, 8 Jul 2012 11:00:11 -0400 Subject: [PATCH 2/4] LibreOffice does not support saving custom properties to docx, and corrupts properties read from docx, so change message --- chrome/locale/en-US/zotero/zotero.properties | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/chrome/locale/en-US/zotero/zotero.properties b/chrome/locale/en-US/zotero/zotero.properties index 2431ba905e..0b2d7c4784 100644 --- a/chrome/locale/en-US/zotero/zotero.properties +++ b/chrome/locale/en-US/zotero/zotero.properties @@ -583,7 +583,7 @@ annotations.oneWindowWarning = Annotations for a snapshot may only be opened in integration.fields.label = Fields integration.referenceMarks.label = ReferenceMarks integration.fields.caption = Microsoft Word Fields are less likely to be accidentally modified, but cannot be shared with OpenOffice. -integration.fields.fileFormatNotice = The document must be saved in the .doc or .docx file format. +integration.fields.fileFormatNotice = The document must be saved in the .doc file format. integration.referenceMarks.caption = OpenOffice ReferenceMarks are less likely to be accidentally modified, but cannot be shared with Microsoft Word. integration.referenceMarks.fileFormatNotice = The document must be saved in the .odt file format. From f07a42a7ec8321411e91f7d60d0d0274845ccebf Mon Sep 17 00:00:00 2001 From: Simon Kornblith Date: Sun, 8 Jul 2012 11:19:41 -0400 Subject: [PATCH 3/4] If document data is corrupted, just show a new Document Preferences window --- chrome/content/zotero/xpcom/integration.js | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/chrome/content/zotero/xpcom/integration.js b/chrome/content/zotero/xpcom/integration.js index a1e8fe03b8..c40f6576e0 100644 --- a/chrome/content/zotero/xpcom/integration.js +++ b/chrome/content/zotero/xpcom/integration.js @@ -860,10 +860,18 @@ Zotero.Integration.Document.prototype._createNewSession = function(data) { */ Zotero.Integration.Document.prototype._getSession = function(require, dontRunSetDocPrefs, callback) { var dataString = this._doc.getDocumentData(), + data, me = this; - if(!dataString) { + + if(dataString) { + try { + data = new Zotero.Integration.DocumentData(dataString); + } catch(e) {}; + } + + if(!data) { var haveFields = false; - var data = new Zotero.Integration.DocumentData(); + data = new Zotero.Integration.DocumentData(); if(require) { // check to see if fields already exist @@ -906,7 +914,6 @@ Zotero.Integration.Document.prototype._getSession = function(require, dontRunSet callback(true); }); } else { - var data = new Zotero.Integration.DocumentData(dataString); if(data.dataVersion < DATA_VERSION) { if(data.dataVersion == 1 && data.prefs.fieldType == "Field" From b13d066062ce15d63f40c9034f415fc1f687e24c Mon Sep 17 00:00:00 2001 From: Simon Kornblith Date: Sun, 8 Jul 2012 13:04:09 -0400 Subject: [PATCH 4/4] Fix "TypeError: invalid 'in' operand arg" error introduced by d02fe6d9ab87f6bb888c8f00ac433da414643222 (thanks @adam3smith) --- .../content/zotero/xpcom/translation/translate_firefox.js | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/chrome/content/zotero/xpcom/translation/translate_firefox.js b/chrome/content/zotero/xpcom/translation/translate_firefox.js index d43e158ab0..d1154ef639 100644 --- a/chrome/content/zotero/xpcom/translation/translate_firefox.js +++ b/chrome/content/zotero/xpcom/translation/translate_firefox.js @@ -103,8 +103,10 @@ Zotero.Translate.SandboxManager.Fx5DOMWrapper = function(obj, parent) { var args = new Array(nArgs); for(var i=0; i