commit c099bd432a71a2a688a120fc186cd8c6c4776707
parent 6c43e75d269f2a5a165ced63ab1aeaf28f0bcf04
Author: Dan Stillman <dstillman@zotero.org>
Date: Sun, 21 Feb 2016 05:19:01 -0500
Handle multi-collection/search add in collectionTreeView::notify()
Diffstat:
2 files changed, 49 insertions(+), 26 deletions(-)
diff --git a/chrome/content/zotero/xpcom/collectionTreeView.js b/chrome/content/zotero/xpcom/collectionTreeView.js
@@ -469,36 +469,40 @@ Zotero.CollectionTreeView.prototype.notify = Zotero.Promise.coroutine(function*
}
else if(action == 'add')
{
- // Multiple adds not currently supported
- let id = ids[0];
- let selectRow = !extraData[id] || !extraData[id].skipSelect;
+ // skipSelect isn't necessary if more than one object
+ let selectRow = ids.length == 1 && (!extraData[ids[0]] || !extraData[ids[0]].skipSelect);
- switch (type)
- {
- case 'collection':
- case 'search':
- yield this._addSortedRow(type, id);
-
- if (selectRow) {
- if (type == 'collection') {
- yield this.selectCollection(id);
- }
- else if (type == 'search') {
- yield this.selectSearch(id);
+ for (let id of ids) {
+ switch (type) {
+ case 'collection':
+ case 'search':
+ yield this._addSortedRow(type, id);
+
+ if (selectRow) {
+ if (type == 'collection') {
+ yield this.selectCollection(id);
+ }
+ else if (type == 'search') {
+ yield this.selectSearch(id);
+ }
}
- }
+
+ break;
- break;
-
- case 'group':
- yield this.reload();
- yield this.selectByID(currentTreeRow.id);
- break;
+ case 'group':
+ if (ids.length != 1) {
+ Zotero.logError("WARNING: Multiple groups shouldn't currently be added "
+ + "together in collectionTreeView::notify()")
+ }
+ yield this.reload();
+ yield this.selectByID(currentTreeRow.id);
+ break;
- case 'feed':
- yield this.reload();
- yield this.selectByID("L" + id);
- break;
+ case 'feed':
+ yield this.reload();
+ yield this.selectByID("L" + id);
+ break;
+ }
}
}
diff --git a/test/tests/collectionTreeViewTest.js b/test/tests/collectionTreeViewTest.js
@@ -215,6 +215,25 @@ describe("Zotero.CollectionTreeView", function() {
assert.equal(aRow, bRow + 1);
})
+
+ it("should add multiple collections", function* () {
+ var col1, col2;
+ yield Zotero.DB.executeTransaction(function* () {
+ col1 = createUnsavedDataObject('collection');
+ col2 = createUnsavedDataObject('collection');
+ yield col1.save();
+ yield col2.save();
+ });
+
+ var aRow = cv.getRowIndexByID("C" + col1.id);
+ var bRow = cv.getRowIndexByID("C" + col2.id);
+ assert.isAbove(aRow, 0);
+ assert.isAbove(bRow, 0);
+ // skipSelect is implied for multiple collections, so library should still be selected
+ assert.equal(cv.selection.currentIndex, 0);
+ });
+
+
it("shouldn't refresh the items list when a collection is modified", function* () {
var collection = yield createDataObject('collection');
yield waitForItemsLoad(win);