From 31943dfba7eff72578a7fa8c3dda8067bfe67de6 Mon Sep 17 00:00:00 2001 From: Dan Stillman Date: Mon, 23 Nov 2009 10:40:24 +0000 Subject: [PATCH] - If snapshot pref is off or toggled off, save web page item for open PDF via Create New Item from Current Page rather than standalone PDF attachment - When saving open PDF via CNIfCP, select in items list (after a currently unavoidable one-second delay) --- chrome/content/zotero/overlay.js | 19 +++++++++++++++---- chrome/content/zotero/xpcom/attachments.js | 4 ++++ 2 files changed, 19 insertions(+), 4 deletions(-) diff --git a/chrome/content/zotero/overlay.js b/chrome/content/zotero/overlay.js index 012f62e2a..240acf406 100644 --- a/chrome/content/zotero/overlay.js +++ b/chrome/content/zotero/overlay.js @@ -2564,6 +2564,9 @@ var ZoteroPane = new function() progressWin.show(); progressWin.startCloseTimer(); + // Save snapshot if explicitly enabled or automatically pref is set and not explicitly disabled + saveSnapshot = saveSnapshot || (saveSnapshot !== false && Zotero.Prefs.get('automaticSnapshots')); + // TODO: this, needless to say, is a temporary hack if (itemType == 'temporaryPDFHack') { itemType = null; @@ -2586,7 +2589,7 @@ var ZoteroPane = new function() } } - if (isPDF) { + if (isPDF && saveSnapshot) { // // Duplicate newItem() checks here // @@ -2629,7 +2632,16 @@ var ZoteroPane = new function() var collectionID = false; } - Zotero.Attachments.importFromDocument(doc, false, false, collectionID, null, libraryID); + var itemID = Zotero.Attachments.importFromDocument(doc, false, false, collectionID, null, libraryID); + + // importFromDocument() doesn't trigger the notifier for a second + // + // The one-second delay is weird but better than nothing + var self = this; + setTimeout(function () { + self.selectItem(itemID); + }, 1001); + return; } } @@ -2654,8 +2666,7 @@ var ZoteroPane = new function() filesEditable = true; } - // Save snapshot if explicitly enabled or automatically pref is set and not explicitly disabled - if (saveSnapshot || (saveSnapshot !== false && Zotero.Prefs.get('automaticSnapshots'))) { + if (saveSnapshot) { var link = false; if (link) { diff --git a/chrome/content/zotero/xpcom/attachments.js b/chrome/content/zotero/xpcom/attachments.js index 382e819c3..658f73a69 100644 --- a/chrome/content/zotero/xpcom/attachments.js +++ b/chrome/content/zotero/xpcom/attachments.js @@ -644,6 +644,10 @@ Zotero.Attachments = new function(){ timer.initWithCallback({notify: f}, 1000, Components.interfaces.nsITimer.TYPE_ONE_SHOT); } + + // Caution: Take care using this itemID. The notifier may not yet have been called, + // so the attachment may not be available in, for example, the items list + return itemID; } catch (e) { Zotero.DB.rollbackTransaction();