Dramatically speed up adding/removing items to/from collections
This commit is contained in:
parent
eef19de220
commit
1f3f9ea2e1
|
@ -647,16 +647,22 @@ Zotero.CollectionTreeView.prototype.drop = function(row, orient)
|
|||
}
|
||||
else if (dataType == 'zotero/item') {
|
||||
var ids = data.data.split(',');
|
||||
var targetCollection = this._getItemAtRow(row).ref;
|
||||
for each(var id in ids)
|
||||
{
|
||||
var item = Zotero.Items.get(id);
|
||||
if (ids.length < 1) {
|
||||
return;
|
||||
}
|
||||
|
||||
var toAdd = [];
|
||||
for (var i=0; i<ids.length; i++) {
|
||||
var item = Zotero.Items.get(ids[i]);
|
||||
// Only accept top-level items
|
||||
if (item.isRegularItem() || !item.getSource())
|
||||
{
|
||||
targetCollection.addItem(id);
|
||||
if (item.isRegularItem() || !item.getSource()) {
|
||||
toAdd.push(ids[i]);
|
||||
}
|
||||
}
|
||||
|
||||
if (toAdd.length > 0) {
|
||||
this._getItemAtRow(row).ref.addItems(toAdd);
|
||||
}
|
||||
}
|
||||
else if (dataType == 'text/x-moz-url') {
|
||||
var url = data.data.split("\n")[0];
|
||||
|
|
|
@ -3013,6 +3013,22 @@ Zotero.Collection.prototype.addItem = function(itemID){
|
|||
}
|
||||
|
||||
|
||||
/**
|
||||
* Add multiple items to the collection in batch
|
||||
*/
|
||||
Zotero.Collection.prototype.addItems = function(itemIDs) {
|
||||
if (!itemIDs || !itemIDs.length) {
|
||||
return;
|
||||
}
|
||||
|
||||
Zotero.DB.beginTransaction();
|
||||
for (var i=0; i<itemIDs.length; i++) {
|
||||
this.addItem(itemIDs[i]);
|
||||
}
|
||||
Zotero.DB.commitTransaction();
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Remove an item from the collection (does not delete item from library)
|
||||
**/
|
||||
|
@ -3032,6 +3048,22 @@ Zotero.Collection.prototype.removeItem = function(itemID){
|
|||
}
|
||||
|
||||
|
||||
/**
|
||||
* Remove multiple items from the collection in batch
|
||||
* (does not delete item from library)
|
||||
*/
|
||||
Zotero.Collection.prototype.removeItems = function(itemIDs) {
|
||||
if (!itemIDs || !itemIDs.length) {
|
||||
return;
|
||||
}
|
||||
|
||||
Zotero.DB.beginTransaction();
|
||||
for (var i=0; i<itemIDs.length; i++) {
|
||||
this.removeItem(itemIDs[i]);
|
||||
}
|
||||
Zotero.DB.commitTransaction();
|
||||
}
|
||||
|
||||
/**
|
||||
* Check if an item belongs to the collection
|
||||
**/
|
||||
|
|
|
@ -992,9 +992,7 @@ Zotero.ItemTreeView.prototype.deleteSelection = function(eraseChildren, force)
|
|||
Zotero.Items.erase(ids, eraseChildren);
|
||||
}
|
||||
else if (this._itemGroup.isCollection()) {
|
||||
for each(var id in ids) {
|
||||
this._itemGroup.ref.removeItem(id);
|
||||
}
|
||||
this._itemGroup.ref.removeItems(ids);
|
||||
}
|
||||
this._treebox.endUpdateBatch();
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue
Block a user