The previous items list nsITreeView object wasn't being destroyed when changing collections. This could cause slow expand/collapse operations (since it was trying to expand each item in each collection you'd viewed since starting Zotero the number of times you'd viewed the collection) and was also causing a potentially large memory leak.

This commit is contained in:
Dan Stillman 2009-04-11 07:54:17 +00:00
parent 14862edb2c
commit f38f5e9c7c
2 changed files with 15 additions and 2 deletions

View file

@ -838,6 +838,11 @@ var ZoteroPane = new function()
if (this.itemsView) if (this.itemsView)
{ {
this.itemsView.unregister(); this.itemsView.unregister();
document.getElementById('zotero-items-tree').removeEventListener(
'keypress', this.itemsView.wrappedJSObject.listener, false
);
this.itemsView.wrappedJSObject.listener = null;
document.getElementById('zotero-items-tree').view = this.itemsView = null;
} }
document.getElementById('zotero-tb-search').value = ""; document.getElementById('zotero-tb-search').value = "";

View file

@ -112,7 +112,7 @@ Zotero.ItemTreeView.prototype.setTree = function(treebox)
var expandAllRows = obj.expandAllRows; var expandAllRows = obj.expandAllRows;
var collapseAllRows = obj.collapseAllRows; var collapseAllRows = obj.collapseAllRows;
var tree = obj._treebox.treeBody.parentNode; var tree = obj._treebox.treeBody.parentNode;
tree.addEventListener('keypress', function(event) { var listener = function(event) {
var key = String.fromCharCode(event.which); var key = String.fromCharCode(event.which);
if (key == '+' && !(event.ctrlKey || event.altKey || event.metaKey)) { if (key == '+' && !(event.ctrlKey || event.altKey || event.metaKey)) {
@ -124,7 +124,11 @@ Zotero.ItemTreeView.prototype.setTree = function(treebox)
obj.collapseAllRows(treebox); obj.collapseAllRows(treebox);
return; return;
} }
}, false); };
// Store listener so we can call removeEventListener()
// in overlay.js::onCollectionSelected()
obj.listener = listener;
tree.addEventListener('keypress', listener, false);
obj.sort(); obj.sort();
obj.expandMatchParents(); obj.expandMatchParents();
@ -774,6 +778,10 @@ Zotero.ItemTreeView.prototype.toggleOpenState = function(row, skipItemMapRefresh
} }
} }
if (!count) {
return;
}
this._dataItems[row].isOpen = !this._dataItems[row].isOpen; this._dataItems[row].isOpen = !this._dataItems[row].isOpen;
this._treebox.rowCountChanged(row+1, count); //tell treebox to repaint these this._treebox.rowCountChanged(row+1, count); //tell treebox to repaint these
this._treebox.invalidateRow(row); this._treebox.invalidateRow(row);