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
|
@ -231,6 +231,14 @@ Zotero.ItemTreeView.prototype._refreshGenerator = function()
|
||||||
|
|
||||||
this._searchMode = this._itemGroup.isSearchMode();
|
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;
|
var oldRows = this.rowCount;
|
||||||
this._dataItems = [];
|
this._dataItems = [];
|
||||||
this._searchItemIDs = {}; // items matching the search
|
this._searchItemIDs = {}; // items matching the search
|
||||||
|
@ -311,6 +319,15 @@ Zotero.ItemTreeView.prototype._refreshGenerator = function()
|
||||||
Zotero.UnresponsiveScriptIndicator.enable();
|
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;
|
yield false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -399,6 +416,7 @@ Zotero.ItemTreeView.prototype.notify = function(action, type, ids, extraData)
|
||||||
}
|
}
|
||||||
|
|
||||||
this.selection.selectEventsSuppressed = true;
|
this.selection.selectEventsSuppressed = true;
|
||||||
|
this._treebox.beginUpdateBatch();
|
||||||
|
|
||||||
if ((action == 'remove' && !itemGroup.isLibrary(true))
|
if ((action == 'remove' && !itemGroup.isLibrary(true))
|
||||||
|| action == 'delete' || action == 'trash') {
|
|| action == 'delete' || action == 'trash') {
|
||||||
|
@ -729,6 +747,7 @@ Zotero.ItemTreeView.prototype.notify = function(action, type, ids, extraData)
|
||||||
this.rememberSelection(savedSelection);
|
this.rememberSelection(savedSelection);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
this._treebox.endUpdateBatch();
|
||||||
this.selection.selectEventsSuppressed = false;
|
this.selection.selectEventsSuppressed = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1380,6 +1399,11 @@ Zotero.ItemTreeView.prototype.sort = function(itemID)
|
||||||
}
|
}
|
||||||
|
|
||||||
// Need to close all containers before sorting
|
// 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);
|
var openItemIDs = this.saveOpenState(true);
|
||||||
|
|
||||||
// Single-row sort
|
// Single-row sort
|
||||||
|
@ -1423,6 +1447,12 @@ Zotero.ItemTreeView.prototype.sort = function(itemID)
|
||||||
this._refreshHashMap();
|
this._refreshHashMap();
|
||||||
|
|
||||||
this.rememberOpenState(openItemIDs);
|
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) {
|
Zotero.ItemTreeView.prototype.setFilter = function(type, data) {
|
||||||
if (!this._treebox || !this._treebox.treeBody) {
|
if (!this._treebox || !this._treebox.treeBody) {
|
||||||
|
@ -1647,9 +1677,7 @@ Zotero.ItemTreeView.prototype.setFilter = function(type, data) {
|
||||||
}
|
}
|
||||||
|
|
||||||
this.selection.selectEventsSuppressed = true;
|
this.selection.selectEventsSuppressed = true;
|
||||||
var savedSelection = this.saveSelection();
|
this._treebox.beginUpdateBatch();
|
||||||
var savedOpenState = this.saveOpenState();
|
|
||||||
var savedFirstRow = this.saveFirstRow();
|
|
||||||
|
|
||||||
switch (type) {
|
switch (type) {
|
||||||
case 'search':
|
case 'search':
|
||||||
|
@ -1666,11 +1694,7 @@ Zotero.ItemTreeView.prototype.setFilter = function(type, data) {
|
||||||
|
|
||||||
this.sort();
|
this.sort();
|
||||||
|
|
||||||
this.rememberOpenState(savedOpenState);
|
this._treebox.endUpdateBatch();
|
||||||
this.expandMatchParents();
|
|
||||||
this.rememberFirstRow(savedFirstRow);
|
|
||||||
this.rememberSelection(savedSelection);
|
|
||||||
this._treebox.invalidate();
|
|
||||||
this.selection.selectEventsSuppressed = false;
|
this.selection.selectEventsSuppressed = false;
|
||||||
|
|
||||||
//Zotero.debug('Running callbacks in itemTreeView.setFilter()', 4);
|
//Zotero.debug('Running callbacks in itemTreeView.setFilter()', 4);
|
||||||
|
@ -1751,6 +1775,10 @@ Zotero.ItemTreeView.prototype.rememberSelection = function(selection)
|
||||||
{
|
{
|
||||||
this.selection.clearSelection();
|
this.selection.clearSelection();
|
||||||
|
|
||||||
|
if (!this.selection.selectEventsSuppressed) {
|
||||||
|
var unsuppress = this.selection.selectEventsSuppressed = true;
|
||||||
|
this._treebox.beginUpdateBatch();
|
||||||
|
}
|
||||||
for(var i=0; i < selection.length; i++)
|
for(var i=0; i < selection.length; i++)
|
||||||
{
|
{
|
||||||
if (this._itemRowMap[selection[i]] != null) {
|
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) {
|
Zotero.ItemTreeView.prototype.saveOpenState = function(close) {
|
||||||
var itemIDs = [];
|
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++) {
|
for (var i=0; i<this._dataItems.length; i++) {
|
||||||
if (this.isContainer(i) && this.isContainerOpen(i)) {
|
if (this.isContainer(i) && this.isContainerOpen(i)) {
|
||||||
itemIDs.push(this._getItemAtRow(i).ref.id);
|
itemIDs.push(this._getItemAtRow(i).ref.id);
|
||||||
|
@ -1806,6 +1844,10 @@ Zotero.ItemTreeView.prototype.saveOpenState = function(close) {
|
||||||
}
|
}
|
||||||
if (close) {
|
if (close) {
|
||||||
this._refreshHashMap();
|
this._refreshHashMap();
|
||||||
|
if (unsuppress) {
|
||||||
|
this._treebox.endUpdateBatch();
|
||||||
|
this.selection.selectEventsSuppressed = false;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
return itemIDs;
|
return itemIDs;
|
||||||
}
|
}
|
||||||
|
@ -1825,13 +1867,19 @@ Zotero.ItemTreeView.prototype.rememberOpenState = function(itemIDs) {
|
||||||
return a - b;
|
return a - b;
|
||||||
});
|
});
|
||||||
|
|
||||||
|
if (!this.selection.selectEventsSuppressed) {
|
||||||
|
var unsuppress = this.selection.selectEventsSuppressed = true;
|
||||||
this._treebox.beginUpdateBatch();
|
this._treebox.beginUpdateBatch();
|
||||||
|
}
|
||||||
// Reopen from bottom up
|
// Reopen from bottom up
|
||||||
for (var i=rowsToOpen.length-1; i>=0; i--) {
|
for (var i=rowsToOpen.length-1; i>=0; i--) {
|
||||||
this.toggleOpenState(rowsToOpen[i], true);
|
this.toggleOpenState(rowsToOpen[i], true);
|
||||||
}
|
}
|
||||||
this._treebox.endUpdateBatch();
|
|
||||||
this._refreshHashMap();
|
this._refreshHashMap();
|
||||||
|
if (unsuppress) {
|
||||||
|
this._treebox.endUpdateBatch();
|
||||||
|
this.selection.selectEventsSuppressed = false;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -1846,7 +1894,10 @@ Zotero.ItemTreeView.prototype.expandMatchParents = function () {
|
||||||
hash[id] = true;
|
hash[id] = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (!this.selection.selectEventsSuppressed) {
|
||||||
|
var unsuppress = this.selection.selectEventsSuppressed = true;
|
||||||
this._treebox.beginUpdateBatch();
|
this._treebox.beginUpdateBatch();
|
||||||
|
}
|
||||||
for (var i=0; i<this.rowCount; i++) {
|
for (var i=0; i<this.rowCount; i++) {
|
||||||
var id = this._getItemAtRow(i).ref.id;
|
var id = this._getItemAtRow(i).ref.id;
|
||||||
if (hash[id] && this.isContainer(i) && !this.isContainerOpen(i)) {
|
if (hash[id] && this.isContainer(i) && !this.isContainerOpen(i)) {
|
||||||
|
@ -1854,7 +1905,10 @@ Zotero.ItemTreeView.prototype.expandMatchParents = function () {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
this._refreshHashMap();
|
this._refreshHashMap();
|
||||||
|
if (unsuppress) {
|
||||||
this._treebox.endUpdateBatch();
|
this._treebox.endUpdateBatch();
|
||||||
|
this.selection.selectEventsSuppressed = false;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -1875,7 +1929,7 @@ Zotero.ItemTreeView.prototype.rememberFirstRow = function(firstRow) {
|
||||||
|
|
||||||
|
|
||||||
Zotero.ItemTreeView.prototype.expandAllRows = function() {
|
Zotero.ItemTreeView.prototype.expandAllRows = function() {
|
||||||
this.selection.selectEventsSuppressed = true;
|
var unsuppress = this.selection.selectEventsSuppressed = true;
|
||||||
this._treebox.beginUpdateBatch();
|
this._treebox.beginUpdateBatch();
|
||||||
for (var i=0; i<this.rowCount; i++) {
|
for (var i=0; i<this.rowCount; i++) {
|
||||||
if (this.isContainer(i) && !this.isContainerOpen(i)) {
|
if (this.isContainer(i) && !this.isContainerOpen(i)) {
|
||||||
|
@ -1889,6 +1943,7 @@ Zotero.ItemTreeView.prototype.expandAllRows = function() {
|
||||||
|
|
||||||
|
|
||||||
Zotero.ItemTreeView.prototype.collapseAllRows = function() {
|
Zotero.ItemTreeView.prototype.collapseAllRows = function() {
|
||||||
|
var unsuppress = this.selection.selectEventsSuppressed = true;
|
||||||
this._treebox.beginUpdateBatch();
|
this._treebox.beginUpdateBatch();
|
||||||
for (var i=0; i<this.rowCount; i++) {
|
for (var i=0; i<this.rowCount; i++) {
|
||||||
if (this.isContainer(i) && this.isContainerOpen(i)) {
|
if (this.isContainer(i) && this.isContainerOpen(i)) {
|
||||||
|
@ -1897,11 +1952,13 @@ Zotero.ItemTreeView.prototype.collapseAllRows = function() {
|
||||||
}
|
}
|
||||||
this._refreshHashMap();
|
this._refreshHashMap();
|
||||||
this._treebox.endUpdateBatch();
|
this._treebox.endUpdateBatch();
|
||||||
|
this.selection.selectEventsSuppressed = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
Zotero.ItemTreeView.prototype.expandSelectedRows = function() {
|
Zotero.ItemTreeView.prototype.expandSelectedRows = function() {
|
||||||
var start = {}, end = {};
|
var start = {}, end = {};
|
||||||
|
this.selection.selectEventsSuppressed = true;
|
||||||
this._treebox.beginUpdateBatch();
|
this._treebox.beginUpdateBatch();
|
||||||
for (var i = 0, len = this.selection.getRangeCount(); i<len; i++) {
|
for (var i = 0, len = this.selection.getRangeCount(); i<len; i++) {
|
||||||
this.selection.getRangeAt(i, start, end);
|
this.selection.getRangeAt(i, start, end);
|
||||||
|
@ -1913,11 +1970,13 @@ Zotero.ItemTreeView.prototype.expandSelectedRows = function() {
|
||||||
}
|
}
|
||||||
this._refreshHashMap();
|
this._refreshHashMap();
|
||||||
this._treebox.endUpdateBatch();
|
this._treebox.endUpdateBatch();
|
||||||
|
this.selection.selectEventsSuppressed = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
Zotero.ItemTreeView.prototype.collapseSelectedRows = function() {
|
Zotero.ItemTreeView.prototype.collapseSelectedRows = function() {
|
||||||
var start = {}, end = {};
|
var start = {}, end = {};
|
||||||
|
this.selection.selectEventsSuppressed = true;
|
||||||
this._treebox.beginUpdateBatch();
|
this._treebox.beginUpdateBatch();
|
||||||
for (var i = 0, len = this.selection.getRangeCount(); i<len; i++) {
|
for (var i = 0, len = this.selection.getRangeCount(); i<len; i++) {
|
||||||
this.selection.getRangeAt(i, start, end);
|
this.selection.getRangeAt(i, start, end);
|
||||||
|
@ -1929,6 +1988,7 @@ Zotero.ItemTreeView.prototype.collapseSelectedRows = function() {
|
||||||
}
|
}
|
||||||
this._refreshHashMap();
|
this._refreshHashMap();
|
||||||
this._treebox.endUpdateBatch();
|
this._treebox.endUpdateBatch();
|
||||||
|
this.selection.selectEventsSuppressed = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue
Block a user