Simplify quick search handling in itemTreeView notify()
This commit is contained in:
parent
7bbb4a8e2d
commit
baeb846b5c
|
@ -622,7 +622,8 @@ Zotero.ItemTreeView.prototype.notify = Zotero.Promise.coroutine(function* (actio
|
||||||
var zp = Zotero.getActiveZoteroPane();
|
var zp = Zotero.getActiveZoteroPane();
|
||||||
var activeWindow = zp && zp.itemsView == this;
|
var activeWindow = zp && zp.itemsView == this;
|
||||||
|
|
||||||
var quicksearch = this._ownerDocument.getElementById('zotero-tb-search');
|
var quickSearch = this._ownerDocument.getElementById('zotero-tb-search');
|
||||||
|
var hasQuickSearch = quickSearch && quickSearch.value != '';
|
||||||
|
|
||||||
// 'collection-item' ids are in the form collectionID-itemID
|
// 'collection-item' ids are in the form collectionID-itemID
|
||||||
if (type == 'collection-item') {
|
if (type == 'collection-item') {
|
||||||
|
@ -699,7 +700,8 @@ Zotero.ItemTreeView.prototype.notify = Zotero.Promise.coroutine(function* (actio
|
||||||
// If saved search, publications, or trash, just re-run search
|
// If saved search, publications, or trash, just re-run search
|
||||||
if (collectionTreeRow.isSearch()
|
if (collectionTreeRow.isSearch()
|
||||||
|| collectionTreeRow.isPublications()
|
|| collectionTreeRow.isPublications()
|
||||||
|| collectionTreeRow.isTrash()) {
|
|| collectionTreeRow.isTrash()
|
||||||
|
|| hasQuickSearch) {
|
||||||
let skipExpandMatchParents = collectionTreeRow.isPublications();
|
let skipExpandMatchParents = collectionTreeRow.isPublications();
|
||||||
yield this.refresh(skipExpandMatchParents);
|
yield this.refresh(skipExpandMatchParents);
|
||||||
refreshed = true;
|
refreshed = true;
|
||||||
|
@ -710,14 +712,11 @@ Zotero.ItemTreeView.prototype.notify = Zotero.Promise.coroutine(function* (actio
|
||||||
sort = true;
|
sort = true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
else if (collectionTreeRow.isFeed()) {
|
else if (collectionTreeRow.isFeed()) {
|
||||||
this._ownerDocument.defaultView.ZoteroPane.updateReadLabel();
|
this._ownerDocument.defaultView.ZoteroPane.updateReadLabel();
|
||||||
}
|
}
|
||||||
|
// If not a search, process modifications manually
|
||||||
// If no quicksearch, process modifications manually
|
else {
|
||||||
else if (!quicksearch || quicksearch.value == '')
|
|
||||||
{
|
|
||||||
var items = Zotero.Items.get(ids);
|
var items = Zotero.Items.get(ids);
|
||||||
|
|
||||||
for (let i = 0; i < items.length; i++) {
|
for (let i = 0; i < items.length; i++) {
|
||||||
|
@ -797,33 +796,6 @@ Zotero.ItemTreeView.prototype.notify = Zotero.Promise.coroutine(function* (actio
|
||||||
sort = true;
|
sort = true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// If quicksearch, re-run it, since the results may have changed
|
|
||||||
else
|
|
||||||
{
|
|
||||||
var allDeleted = true;
|
|
||||||
var isTrash = collectionTreeRow.isTrash();
|
|
||||||
var items = Zotero.Items.get(ids);
|
|
||||||
for (let item of items) {
|
|
||||||
// If not viewing trash and all items were deleted, ignore modify
|
|
||||||
if (allDeleted && !isTrash && !item.deleted) {
|
|
||||||
allDeleted = false;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!allDeleted) {
|
|
||||||
quicksearch.doCommand();
|
|
||||||
// See _refreshPromise note below
|
|
||||||
if (this._refreshPromise) {
|
|
||||||
try {
|
|
||||||
yield this._refreshPromise;
|
|
||||||
}
|
|
||||||
catch (e) {}
|
|
||||||
}
|
|
||||||
madeChanges = true;
|
|
||||||
sort = true;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
else if(type == 'item' && action == 'add')
|
else if(type == 'item' && action == 'add')
|
||||||
{
|
{
|
||||||
|
@ -833,16 +805,32 @@ Zotero.ItemTreeView.prototype.notify = Zotero.Promise.coroutine(function* (actio
|
||||||
if (collectionTreeRow.isSearch()
|
if (collectionTreeRow.isSearch()
|
||||||
|| collectionTreeRow.isPublications()
|
|| collectionTreeRow.isPublications()
|
||||||
|| collectionTreeRow.isTrash()
|
|| collectionTreeRow.isTrash()
|
||||||
|| collectionTreeRow.isUnfiled()) {
|
|| collectionTreeRow.isUnfiled()
|
||||||
|
|| hasQuickSearch) {
|
||||||
|
if (hasQuickSearch) {
|
||||||
|
// For item adds, clear the quick search, unless all the new items have
|
||||||
|
// skipSelect or are child items
|
||||||
|
if (activeWindow && type == 'item') {
|
||||||
|
let clear = false;
|
||||||
|
for (let i=0; i<items.length; i++) {
|
||||||
|
if (!extraData[items[i].id].skipSelect && items[i].isTopLevelItem()) {
|
||||||
|
clear = true;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (clear) {
|
||||||
|
quickSearch.value = '';
|
||||||
|
collectionTreeRow.setSearch('');
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
yield this.refresh();
|
yield this.refresh();
|
||||||
refreshed = true;
|
refreshed = true;
|
||||||
madeChanges = true;
|
madeChanges = true;
|
||||||
sort = true;
|
sort = true;
|
||||||
}
|
}
|
||||||
|
// Otherwise process new items manually
|
||||||
// If not a quicksearch, process new items manually
|
else {
|
||||||
else if (!quicksearch || quicksearch.value == '')
|
|
||||||
{
|
|
||||||
for (let i=0; i<items.length; i++) {
|
for (let i=0; i<items.length; i++) {
|
||||||
let item = items[i];
|
let item = items[i];
|
||||||
// if the item belongs in this collection
|
// if the item belongs in this collection
|
||||||
|
@ -862,36 +850,6 @@ Zotero.ItemTreeView.prototype.notify = Zotero.Promise.coroutine(function* (actio
|
||||||
sort = (items.length == 1) ? items[0].id : true;
|
sort = (items.length == 1) ? items[0].id : true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
// Otherwise re-run the quick search, which refreshes the item list
|
|
||||||
else
|
|
||||||
{
|
|
||||||
// For item adds, clear the quicksearch, unless all the new items have skipSelect or are
|
|
||||||
// child items
|
|
||||||
if (activeWindow && type == 'item') {
|
|
||||||
let clear = false;
|
|
||||||
for (let i=0; i<items.length; i++) {
|
|
||||||
if (!extraData[items[i].id].skipSelect && items[i].isTopLevelItem()) {
|
|
||||||
clear = true;
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if (clear) {
|
|
||||||
quicksearch.value = '';
|
|
||||||
}
|
|
||||||
}
|
|
||||||
quicksearch.doCommand();
|
|
||||||
// We have to wait for the search in order to select new items properly, but doCommand()
|
|
||||||
// doesn't provide the return value from the oncommand handler, so we can't wait for an
|
|
||||||
// asynchronous handler. But really they just end up calling refresh(), so we wait for that.
|
|
||||||
if (this._refreshPromise) {
|
|
||||||
try {
|
|
||||||
yield this._refreshPromise;
|
|
||||||
}
|
|
||||||
catch (e) {}
|
|
||||||
}
|
|
||||||
madeChanges = true;
|
|
||||||
sort = true;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
var reselect = false;
|
var reselect = false;
|
||||||
|
@ -1324,7 +1282,7 @@ Zotero.ItemTreeView.prototype.toggleOpenState = function (row, skipRowMapRefresh
|
||||||
this._treebox.invalidateRow(row);
|
this._treebox.invalidateRow(row);
|
||||||
|
|
||||||
if (!skipRowMapRefresh) {
|
if (!skipRowMapRefresh) {
|
||||||
Zotero.debug('Refreshing hash map');
|
Zotero.debug('Refreshing item row map');
|
||||||
this._refreshItemRowMap();
|
this._refreshItemRowMap();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1357,7 +1315,7 @@ Zotero.ItemTreeView.prototype._closeContainer = function (row, skipRowMapRefresh
|
||||||
this._treebox.invalidateRow(row);
|
this._treebox.invalidateRow(row);
|
||||||
|
|
||||||
if (!skipRowMapRefresh) {
|
if (!skipRowMapRefresh) {
|
||||||
Zotero.debug('Refreshing hash map');
|
Zotero.debug('Refreshing item row map');
|
||||||
this._refreshItemRowMap();
|
this._refreshItemRowMap();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1882,7 +1840,7 @@ Zotero.ItemTreeView.prototype.selectItem = Zotero.Promise.coroutine(function* (i
|
||||||
if (!parent || parentRow === null) {
|
if (!parent || parentRow === null) {
|
||||||
// No parent -- it's not here
|
// No parent -- it's not here
|
||||||
|
|
||||||
// Clear the quicksearch and tag selection and try again (once)
|
// Clear the quick search and tag selection and try again (once)
|
||||||
if (!noRecurse && this._ownerDocument.defaultView.ZoteroPane_Local) {
|
if (!noRecurse && this._ownerDocument.defaultView.ZoteroPane_Local) {
|
||||||
let cleared1 = yield this._ownerDocument.defaultView.ZoteroPane_Local.clearQuicksearch();
|
let cleared1 = yield this._ownerDocument.defaultView.ZoteroPane_Local.clearQuicksearch();
|
||||||
let cleared2 = this._ownerDocument.defaultView.ZoteroPane_Local.clearTagSelection();
|
let cleared2 = this._ownerDocument.defaultView.ZoteroPane_Local.clearTagSelection();
|
||||||
|
|
Loading…
Reference in New Issue
Block a user