Avoid unnecessary UI updates in various situations
beginUpdateBatch() doesn't suppress select events, so various batch operations were triggering lots of extra selects. This hopefully fixes the long hang some people were seeing when making changes with an open quick search (which I was only able to reproduce in Standalone).
This commit is contained in:
parent
dfdfbf1258
commit
2cd45be191
1 changed files with 74 additions and 14 deletions
|
@ -231,6 +231,14 @@ Zotero.ItemTreeView.prototype._refreshGenerator = function()
|
|||
|
||||
this._searchMode = this._itemGroup.isSearchMode();
|
||||
|
||||
if (!this.selection.selectEventsSuppressed) {
|
||||
var unsuppress = this.selection.selectEventsSuppressed = true;
|
||||
this._treebox.beginUpdateBatch();
|
||||
}
|
||||
var savedSelection = this.saveSelection();
|
||||
var savedOpenState = this.saveOpenState();
|
||||
var savedFirstRow = this.saveFirstRow();
|
||||
|
||||
var oldRows = this.rowCount;
|
||||
this._dataItems = [];
|
||||
this._searchItemIDs = {}; // items matching the search
|
||||
|
@ -311,6 +319,15 @@ Zotero.ItemTreeView.prototype._refreshGenerator = function()
|
|||
Zotero.UnresponsiveScriptIndicator.enable();
|
||||
}
|
||||
|
||||
this.rememberOpenState(savedOpenState);
|
||||
this.rememberFirstRow(savedFirstRow);
|
||||
this.rememberSelection(savedSelection);
|
||||
this.expandMatchParents();
|
||||
if (unsuppress) {
|
||||
this._treebox.endUpdateBatch();
|
||||
this.selection.selectEventsSuppressed = false;
|
||||
}
|
||||
|
||||
yield false;
|
||||
}
|
||||
|
||||
|
@ -399,6 +416,7 @@ Zotero.ItemTreeView.prototype.notify = function(action, type, ids, extraData)
|
|||
}
|
||||
|
||||
this.selection.selectEventsSuppressed = true;
|
||||
this._treebox.beginUpdateBatch();
|
||||
|
||||
if ((action == 'remove' && !itemGroup.isLibrary(true))
|
||||
|| action == 'delete' || action == 'trash') {
|
||||
|
@ -729,6 +747,7 @@ Zotero.ItemTreeView.prototype.notify = function(action, type, ids, extraData)
|
|||
this.rememberSelection(savedSelection);
|
||||
}
|
||||
|
||||
this._treebox.endUpdateBatch();
|
||||
this.selection.selectEventsSuppressed = false;
|
||||
}
|
||||
|
||||
|
@ -1380,6 +1399,11 @@ Zotero.ItemTreeView.prototype.sort = function(itemID)
|
|||
}
|
||||
|
||||
// Need to close all containers before sorting
|
||||
if (!this.selection.selectEventsSuppressed) {
|
||||
var unsuppress = this.selection.selectEventsSuppressed = true;
|
||||
this._treebox.beginUpdateBatch();
|
||||
}
|
||||
var savedSelection = this.saveSelection();
|
||||
var openItemIDs = this.saveOpenState(true);
|
||||
|
||||
// Single-row sort
|
||||
|
@ -1423,6 +1447,12 @@ Zotero.ItemTreeView.prototype.sort = function(itemID)
|
|||
this._refreshHashMap();
|
||||
|
||||
this.rememberOpenState(openItemIDs);
|
||||
this.rememberSelection(savedSelection);
|
||||
|
||||
if (unsuppress) {
|
||||
this.selection.selectEventsSuppressed = false;
|
||||
this._treebox.endUpdateBatch();
|
||||
}
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
|
@ -1638,7 +1668,7 @@ Zotero.ItemTreeView.prototype.deleteSelection = function (force)
|
|||
|
||||
|
||||
/*
|
||||
* Set the tags filter on the view
|
||||
* Set the search/tags filter on the view
|
||||
*/
|
||||
Zotero.ItemTreeView.prototype.setFilter = function(type, data) {
|
||||
if (!this._treebox || !this._treebox.treeBody) {
|
||||
|
@ -1647,9 +1677,7 @@ Zotero.ItemTreeView.prototype.setFilter = function(type, data) {
|
|||
}
|
||||
|
||||
this.selection.selectEventsSuppressed = true;
|
||||
var savedSelection = this.saveSelection();
|
||||
var savedOpenState = this.saveOpenState();
|
||||
var savedFirstRow = this.saveFirstRow();
|
||||
this._treebox.beginUpdateBatch();
|
||||
|
||||
switch (type) {
|
||||
case 'search':
|
||||
|
@ -1666,11 +1694,7 @@ Zotero.ItemTreeView.prototype.setFilter = function(type, data) {
|
|||
|
||||
this.sort();
|
||||
|
||||
this.rememberOpenState(savedOpenState);
|
||||
this.expandMatchParents();
|
||||
this.rememberFirstRow(savedFirstRow);
|
||||
this.rememberSelection(savedSelection);
|
||||
this._treebox.invalidate();
|
||||
this._treebox.endUpdateBatch();
|
||||
this.selection.selectEventsSuppressed = false;
|
||||
|
||||
//Zotero.debug('Running callbacks in itemTreeView.setFilter()', 4);
|
||||
|
@ -1751,6 +1775,10 @@ Zotero.ItemTreeView.prototype.rememberSelection = function(selection)
|
|||
{
|
||||
this.selection.clearSelection();
|
||||
|
||||
if (!this.selection.selectEventsSuppressed) {
|
||||
var unsuppress = this.selection.selectEventsSuppressed = true;
|
||||
this._treebox.beginUpdateBatch();
|
||||
}
|
||||
for(var i=0; i < selection.length; i++)
|
||||
{
|
||||
if (this._itemRowMap[selection[i]] != null) {
|
||||
|
@ -1777,6 +1805,10 @@ Zotero.ItemTreeView.prototype.rememberSelection = function(selection)
|
|||
}
|
||||
}
|
||||
}
|
||||
if (unsuppress) {
|
||||
this._treebox.endUpdateBatch();
|
||||
this.selection.selectEventsSuppressed = false;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
@ -1796,6 +1828,12 @@ Zotero.ItemTreeView.prototype.selectSearchMatches = function () {
|
|||
|
||||
Zotero.ItemTreeView.prototype.saveOpenState = function(close) {
|
||||
var itemIDs = [];
|
||||
if (close) {
|
||||
if (!this.selection.selectEventsSuppressed) {
|
||||
var unsuppress = this.selection.selectEventsSuppressed = true;
|
||||
this._treebox.beginUpdateBatch();
|
||||
}
|
||||
}
|
||||
for (var i=0; i<this._dataItems.length; i++) {
|
||||
if (this.isContainer(i) && this.isContainerOpen(i)) {
|
||||
itemIDs.push(this._getItemAtRow(i).ref.id);
|
||||
|
@ -1806,6 +1844,10 @@ Zotero.ItemTreeView.prototype.saveOpenState = function(close) {
|
|||
}
|
||||
if (close) {
|
||||
this._refreshHashMap();
|
||||
if (unsuppress) {
|
||||
this._treebox.endUpdateBatch();
|
||||
this.selection.selectEventsSuppressed = false;
|
||||
}
|
||||
}
|
||||
return itemIDs;
|
||||
}
|
||||
|
@ -1825,13 +1867,19 @@ Zotero.ItemTreeView.prototype.rememberOpenState = function(itemIDs) {
|
|||
return a - b;
|
||||
});
|
||||
|
||||
this._treebox.beginUpdateBatch();
|
||||
if (!this.selection.selectEventsSuppressed) {
|
||||
var unsuppress = this.selection.selectEventsSuppressed = true;
|
||||
this._treebox.beginUpdateBatch();
|
||||
}
|
||||
// Reopen from bottom up
|
||||
for (var i=rowsToOpen.length-1; i>=0; i--) {
|
||||
this.toggleOpenState(rowsToOpen[i], true);
|
||||
}
|
||||
this._treebox.endUpdateBatch();
|
||||
this._refreshHashMap();
|
||||
if (unsuppress) {
|
||||
this._treebox.endUpdateBatch();
|
||||
this.selection.selectEventsSuppressed = false;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
@ -1846,7 +1894,10 @@ Zotero.ItemTreeView.prototype.expandMatchParents = function () {
|
|||
hash[id] = true;
|
||||
}
|
||||
|
||||
this._treebox.beginUpdateBatch();
|
||||
if (!this.selection.selectEventsSuppressed) {
|
||||
var unsuppress = this.selection.selectEventsSuppressed = true;
|
||||
this._treebox.beginUpdateBatch();
|
||||
}
|
||||
for (var i=0; i<this.rowCount; i++) {
|
||||
var id = this._getItemAtRow(i).ref.id;
|
||||
if (hash[id] && this.isContainer(i) && !this.isContainerOpen(i)) {
|
||||
|
@ -1854,7 +1905,10 @@ Zotero.ItemTreeView.prototype.expandMatchParents = function () {
|
|||
}
|
||||
}
|
||||
this._refreshHashMap();
|
||||
this._treebox.endUpdateBatch();
|
||||
if (unsuppress) {
|
||||
this._treebox.endUpdateBatch();
|
||||
this.selection.selectEventsSuppressed = false;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
@ -1875,7 +1929,7 @@ Zotero.ItemTreeView.prototype.rememberFirstRow = function(firstRow) {
|
|||
|
||||
|
||||
Zotero.ItemTreeView.prototype.expandAllRows = function() {
|
||||
this.selection.selectEventsSuppressed = true;
|
||||
var unsuppress = this.selection.selectEventsSuppressed = true;
|
||||
this._treebox.beginUpdateBatch();
|
||||
for (var i=0; i<this.rowCount; i++) {
|
||||
if (this.isContainer(i) && !this.isContainerOpen(i)) {
|
||||
|
@ -1889,6 +1943,7 @@ Zotero.ItemTreeView.prototype.expandAllRows = function() {
|
|||
|
||||
|
||||
Zotero.ItemTreeView.prototype.collapseAllRows = function() {
|
||||
var unsuppress = this.selection.selectEventsSuppressed = true;
|
||||
this._treebox.beginUpdateBatch();
|
||||
for (var i=0; i<this.rowCount; i++) {
|
||||
if (this.isContainer(i) && this.isContainerOpen(i)) {
|
||||
|
@ -1897,11 +1952,13 @@ Zotero.ItemTreeView.prototype.collapseAllRows = function() {
|
|||
}
|
||||
this._refreshHashMap();
|
||||
this._treebox.endUpdateBatch();
|
||||
this.selection.selectEventsSuppressed = false;
|
||||
}
|
||||
|
||||
|
||||
Zotero.ItemTreeView.prototype.expandSelectedRows = function() {
|
||||
var start = {}, end = {};
|
||||
this.selection.selectEventsSuppressed = true;
|
||||
this._treebox.beginUpdateBatch();
|
||||
for (var i = 0, len = this.selection.getRangeCount(); i<len; i++) {
|
||||
this.selection.getRangeAt(i, start, end);
|
||||
|
@ -1913,11 +1970,13 @@ Zotero.ItemTreeView.prototype.expandSelectedRows = function() {
|
|||
}
|
||||
this._refreshHashMap();
|
||||
this._treebox.endUpdateBatch();
|
||||
this.selection.selectEventsSuppressed = false;
|
||||
}
|
||||
|
||||
|
||||
Zotero.ItemTreeView.prototype.collapseSelectedRows = function() {
|
||||
var start = {}, end = {};
|
||||
this.selection.selectEventsSuppressed = true;
|
||||
this._treebox.beginUpdateBatch();
|
||||
for (var i = 0, len = this.selection.getRangeCount(); i<len; i++) {
|
||||
this.selection.getRangeAt(i, start, end);
|
||||
|
@ -1929,6 +1988,7 @@ Zotero.ItemTreeView.prototype.collapseSelectedRows = function() {
|
|||
}
|
||||
this._refreshHashMap();
|
||||
this._treebox.endUpdateBatch();
|
||||
this.selection.selectEventsSuppressed = false;
|
||||
}
|
||||
|
||||
|
||||
|
|
Loading…
Add table
Reference in a new issue