commit 60830c27eebc7fffbd37fe3736277328b4c7b288
parent 6b509820b35837b686d9b022fb91e631f430a5f9
Author: Dan Stillman <dstillman@zotero.org>
Date: Sun, 13 Mar 2016 22:59:19 -0400
Remove items from open Unfiled Items view when added to collection
Diffstat:
2 files changed, 29 insertions(+), 9 deletions(-)
diff --git a/chrome/content/zotero/xpcom/itemTreeView.js b/chrome/content/zotero/xpcom/itemTreeView.js
@@ -590,7 +590,7 @@ Zotero.ItemTreeView.prototype.notify = Zotero.Promise.coroutine(function* (actio
// If no quicksearch, process modifications manually
else if (!quicksearch || quicksearch.value == '')
{
- var items = yield Zotero.Items.getAsync(ids);
+ var items = Zotero.Items.get(ids);
for (let i = 0; i < items.length; i++) {
let item = items[i];
@@ -609,9 +609,16 @@ Zotero.ItemTreeView.prototype.notify = Zotero.Promise.coroutine(function* (actio
let parentItemID = this.getRow(row).ref.parentItemID;
let parentIndex = this.getParentIndex(row);
- // Top-level items just have to be resorted
+ // Top-level item
if (this.isContainer(row)) {
- sort = id;
+ // If Unfiled Items and itm was added to a collection, remove from view
+ if (collectionTreeRow.isUnfiled() && item.getCollections().length) {
+ this._removeRow(row);
+ }
+ // Otherwise just resort
+ else {
+ sort = id;
+ }
}
// If item moved from top-level to under another item, remove the old row.
else if (parentIndex == -1 && parentItemID) {
@@ -1585,7 +1592,7 @@ Zotero.ItemTreeView.prototype.selectItem = Zotero.Promise.coroutine(function* (i
// Clear the quicksearch and tag selection and try again (once)
if (!noRecurse && this._ownerDocument.defaultView.ZoteroPane_Local) {
let cleared1 = yield this._ownerDocument.defaultView.ZoteroPane_Local.clearQuicksearch();
- let cleared2 = yield this._ownerDocument.defaultView.ZoteroPane_Local.clearTagSelection();
+ let cleared2 = this._ownerDocument.defaultView.ZoteroPane_Local.clearTagSelection();
if (cleared1 || cleared2) {
return this.selectItem(id, expand, true);
}
diff --git a/test/tests/itemTreeViewTest.js b/test/tests/itemTreeViewTest.js
@@ -1,31 +1,31 @@
"use strict";
describe("Zotero.ItemTreeView", function() {
- var win, zp, itemsView, existingItemID;
+ var win, zp, cv, itemsView, existingItemID;
// Load Zotero pane and select library
before(function* () {
win = yield loadZoteroPane();
zp = win.ZoteroPane;
+ cv = zp.collectionsView;
var item = new Zotero.Item('book');
existingItemID = yield item.saveTx();
});
beforeEach(function* () {
- yield zp.collectionsView.selectLibrary();
- yield waitForItemsLoad(win)
+ yield selectLibrary(win);
itemsView = zp.itemsView;
})
after(function () {
win.close();
});
- it("shouldn't show items in trash", function* () {
+ it("shouldn't show items in trash in library root", function* () {
var item = yield createDataObject('item', { title: "foo" });
var itemID = item.id;
item.deleted = true;
yield item.saveTx();
- assert.notOk(itemsView.getRowIndexByID(itemID));
+ assert.isFalse(itemsView.getRowIndexByID(itemID));
})
describe("#selectItem()", function () {
@@ -231,6 +231,19 @@ describe("Zotero.ItemTreeView", function() {
yield Zotero.Items.erase(items.map(item => item.id));
})
+
+
+ it("should remove items from Unfiled Items when added to a collection", function* () {
+ var collection = yield createDataObject('collection');
+ var item = yield createDataObject('item', { title: "Unfiled Item" });
+ yield cv.selectByID("U" + Zotero.Libraries.userLibraryID);
+ yield waitForItemsLoad(win);
+ assert.isNumber(zp.itemsView.getRowIndexByID(item.id));
+ yield Zotero.DB.executeTransaction(function* () {
+ yield collection.addItem(item.id);
+ });
+ assert.isFalse(zp.itemsView.getRowIndexByID(item.id));
+ });
})
describe("#drop()", function () {