From 47ffa1188a1e21e231c3f5381ce2d9000b99b26e Mon Sep 17 00:00:00 2001 From: retorquere Date: Mon, 11 May 2015 20:26:50 +0200 Subject: [PATCH] export groups, unify library export --- chrome/content/zotero/fileInterface.js | 10 ++++- .../zotero/xpcom/translation/translate.js | 38 ++++++++++++------- .../xpcom/translation/translate_item.js | 6 +-- chrome/content/zotero/zoteroPane.js | 2 +- 4 files changed, 38 insertions(+), 18 deletions(-) diff --git a/chrome/content/zotero/fileInterface.js b/chrome/content/zotero/fileInterface.js index cbc7cb961..67dd69056 100644 --- a/chrome/content/zotero/fileInterface.js +++ b/chrome/content/zotero/fileInterface.js @@ -76,6 +76,10 @@ Zotero_File_Exporter.prototype.save = function() { translation.setCollection(this.collection); } else if(this.items) { translation.setItems(this.items); + } else if(this.libraryID === undefined) { + throw new Error('No export configured'); + } else { + translation.setLibraryID(this.libraryID); } translation.setLocation(fp.file); @@ -129,7 +133,11 @@ var Zotero_File_Interface = new function() { */ function exportFile() { var exporter = new Zotero_File_Exporter(); - exporter.name = Zotero.getString("pane.collections.library"); + exporter.libraryID = ZoteroPane_Local.getSelectedLibraryID(); + if (exporter.libraryID === false) { + throw new Error('No library selected'); + } + exporter.name = Zotero.Libraries.getName(exporter.libraryID); exporter.save(); } diff --git a/chrome/content/zotero/xpcom/translation/translate.js b/chrome/content/zotero/xpcom/translation/translate.js index 88027e9ab..060d1d2f1 100644 --- a/chrome/content/zotero/xpcom/translation/translate.js +++ b/chrome/content/zotero/xpcom/translation/translate.js @@ -2110,17 +2110,23 @@ Zotero.Translate.Export.prototype.Sandbox = Zotero.Translate.Sandbox._inheritFro * @param {Zotero.Item[]} items */ Zotero.Translate.Export.prototype.setItems = function(items) { - this._items = items; - delete this._collection; + this._export = {type: 'items', items: items}; } /** - * Sets the collection to be exported (overrides setItems) + * Sets the group to be exported (overrides setItems/setCollection) + * @param {Zotero.Group[]} group + */ +Zotero.Translate.Export.prototype.setLibraryID = function(libraryID) { + this._export = {type: 'library', id: libraryID}; +} + +/** + * Sets the collection to be exported (overrides setItems/setGroup) * @param {Zotero.Collection[]} collection */ Zotero.Translate.Export.prototype.setCollection = function(collection) { - this._collection = collection; - delete this._items; + this._export = {type: 'collection', collection: collection}; } /** @@ -2182,15 +2188,21 @@ Zotero.Translate.Export.prototype._prepareTranslation = function() { this._itemGetter = new Zotero.Translate.ItemGetter(); var configOptions = this._translatorInfo.configOptions || {}, getCollections = configOptions.getCollections || false; - if(this._collection) { - this._itemGetter.setCollection(this._collection, getCollections); - delete this._collection; - } else if(this._items) { - this._itemGetter.setItems(this._items); - delete this._items; - } else { - this._itemGetter.setAll(getCollections); + switch (this._export.type) { + case 'collection': + this._itemGetter.setCollection(this._export.collection, getCollections); + break; + case 'items': + this._itemGetter.setItems(this._export.items); + break; + case 'library': + this._itemGetter.setAll(this._export.id, getCollections); + break; + default: + throw new Error('No export set up'); + break; } + delete this._export; // export file data, if requested if(this._displayOptions["exportFileData"]) { diff --git a/chrome/content/zotero/xpcom/translation/translate_item.js b/chrome/content/zotero/xpcom/translation/translate_item.js index 89f263c92..616040b87 100644 --- a/chrome/content/zotero/xpcom/translation/translate_item.js +++ b/chrome/content/zotero/xpcom/translation/translate_item.js @@ -786,11 +786,11 @@ Zotero.Translate.ItemGetter.prototype = { this.numItems = this._itemsLeft.length; }, - "setAll":function(getChildCollections) { - this._itemsLeft = Zotero.Items.getAll(true); + "setAll":function(libraryID, getChildCollections) { + this._itemsLeft = Zotero.Items.getAll(true, libraryID); if(getChildCollections) { - this._collectionsLeft = Zotero.getCollections(); + this._collectionsLeft = Zotero.getCollections(null, true, libraryID); } this.numItems = this._itemsLeft.length; diff --git a/chrome/content/zotero/zoteroPane.js b/chrome/content/zotero/zoteroPane.js index 0b7a9b231..14edc7029 100644 --- a/chrome/content/zotero/zoteroPane.js +++ b/chrome/content/zotero/zoteroPane.js @@ -2173,7 +2173,7 @@ var ZoteroPane = new function() show = [m.emptyTrash]; } else if (itemGroup.isGroup()) { - show = [m.newCollection, m.newSavedSearch, m.sep1, m.showDuplicates, m.showUnfiled]; + show = [m.newCollection, m.newSavedSearch, m.sep1, m.showDuplicates, m.showUnfiled, m.sep2, m.exportFile]; } else if (itemGroup.isDuplicates() || itemGroup.isUnfiled()) { show = [