Fixes #286, if a quick search is entered in the item pane, and a new item is added to the library, the item appears regardless
New logic in itemTreeView notify() target: - Items are only selected on add in the active window -- this fixes a fairly major flaw in the previous system that would cause new items to be selected in all open windows - If a quicksearch is open in the active window and a new item is added, clear the search - If quicksearch and active window and item modify, rerun search - If quicksearch and not active window, rerun search - If not quicksearch and not active window, update list but retain previous selection
This commit is contained in:
parent
7b7d3d85e3
commit
ad5ce20c82
|
@ -139,12 +139,6 @@ var ScholarPane = new function()
|
||||||
*/
|
*/
|
||||||
function newItem(typeID)
|
function newItem(typeID)
|
||||||
{
|
{
|
||||||
if(document.getElementById('tb-search').value != "")
|
|
||||||
{
|
|
||||||
document.getElementById('tb-search').value = "";
|
|
||||||
document.getElementById('tb-search').doCommand();
|
|
||||||
}
|
|
||||||
|
|
||||||
var item = new Scholar.Item(typeID);
|
var item = new Scholar.Item(typeID);
|
||||||
item.save();
|
item.save();
|
||||||
if(itemsView && itemsView._itemGroup.isCollection())
|
if(itemsView && itemsView._itemGroup.isCollection())
|
||||||
|
|
|
@ -74,12 +74,21 @@ Scholar.ItemTreeView.prototype.refresh = function()
|
||||||
Scholar.ItemTreeView.prototype.notify = function(action, type, ids)
|
Scholar.ItemTreeView.prototype.notify = function(action, type, ids)
|
||||||
{
|
{
|
||||||
var madeChanges = false;
|
var madeChanges = false;
|
||||||
|
|
||||||
this.selection.selectEventsSuppressed = true;
|
this.selection.selectEventsSuppressed = true;
|
||||||
var savedSelection = this.saveSelection();
|
var savedSelection = this.saveSelection();
|
||||||
|
|
||||||
ids = Scholar.flattenArguments(ids);
|
ids = Scholar.flattenArguments(ids);
|
||||||
|
|
||||||
|
// See if we're in the active window
|
||||||
|
var wm = Components.classes["@mozilla.org/appshell/window-mediator;1"]
|
||||||
|
.getService(Components.interfaces.nsIWindowMediator);
|
||||||
|
if (wm.getMostRecentWindow("navigator:browser") ==
|
||||||
|
this._treebox.treeBody.ownerDocument.defaultView){
|
||||||
|
var activeWindow = true;
|
||||||
|
}
|
||||||
|
|
||||||
|
var quicksearch = this._treebox.treeBody.ownerDocument.getElementById('tb-search');
|
||||||
|
|
||||||
if((action == 'remove' && !this._itemGroup.isLibrary()) || (action == 'delete' && this._itemGroup.isLibrary()))
|
if((action == 'remove' && !this._itemGroup.isLibrary()) || (action == 'delete' && this._itemGroup.isLibrary()))
|
||||||
{
|
{
|
||||||
//Since a remove involves shifting of rows, we have to do it in order
|
//Since a remove involves shifting of rows, we have to do it in order
|
||||||
|
@ -109,6 +118,9 @@ Scholar.ItemTreeView.prototype.notify = function(action, type, ids)
|
||||||
|
|
||||||
}
|
}
|
||||||
else if(action == 'modify') //must check for null because it could legitimately be 0
|
else if(action == 'modify') //must check for null because it could legitimately be 0
|
||||||
|
{
|
||||||
|
// If no quicksearch, process modifications manually
|
||||||
|
if (quicksearch.value == '')
|
||||||
{
|
{
|
||||||
for(var i=0, len=ids.length; i<len; i++)
|
for(var i=0, len=ids.length; i<len; i++)
|
||||||
{
|
{
|
||||||
|
@ -144,11 +156,23 @@ Scholar.ItemTreeView.prototype.notify = function(action, type, ids)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// If quicksearch, re-run it, since the results may have changed
|
||||||
|
else
|
||||||
|
{
|
||||||
|
quicksearch.doCommand();
|
||||||
|
madeChanges = true;
|
||||||
|
}
|
||||||
|
}
|
||||||
else if(action == 'add')
|
else if(action == 'add')
|
||||||
|
{
|
||||||
|
// If no quicksearch, process new items manually
|
||||||
|
if (quicksearch.value == '')
|
||||||
{
|
{
|
||||||
var items = Scholar.Items.get(ids);
|
var items = Scholar.Items.get(ids);
|
||||||
|
|
||||||
for (var i in items){
|
for (var i in items)
|
||||||
|
{
|
||||||
if((this._itemGroup.isLibrary() || items[i].inCollection(this._itemGroup.ref.getID())) // if the item belongs in this collection
|
if((this._itemGroup.isLibrary() || items[i].inCollection(this._itemGroup.ref.getID())) // if the item belongs in this collection
|
||||||
&& this._itemRowMap[items[i].getID()] == null // if we haven't already added it to our hash map
|
&& this._itemRowMap[items[i].getID()] == null // if we haven't already added it to our hash map
|
||||||
&& (items[i].isRegularItem() || !items[i].getSource())) // if it's stand-alone
|
&& (items[i].isRegularItem() || !items[i].getSource())) // if it's stand-alone
|
||||||
|
@ -160,6 +184,18 @@ Scholar.ItemTreeView.prototype.notify = function(action, type, ids)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
// Otherwise rerun the search, which refreshes the item list
|
||||||
|
else
|
||||||
|
{
|
||||||
|
// If active window, clear search first
|
||||||
|
if (activeWindow)
|
||||||
|
{
|
||||||
|
quicksearch.value = '';
|
||||||
|
}
|
||||||
|
quicksearch.doCommand();
|
||||||
|
madeChanges = true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
if(madeChanges)
|
if(madeChanges)
|
||||||
{
|
{
|
||||||
|
@ -173,16 +209,15 @@ Scholar.ItemTreeView.prototype.notify = function(action, type, ids)
|
||||||
this._refreshHashMap();
|
this._refreshHashMap();
|
||||||
}
|
}
|
||||||
|
|
||||||
if(action == 'add')
|
// If adding and this is the active window, select the item
|
||||||
|
if(action == 'add' && ids.length===1 && activeWindow)
|
||||||
{
|
{
|
||||||
if (ids.length===1){
|
|
||||||
// Reset to Info tab
|
// Reset to Info tab
|
||||||
this._treebox.treeBody.ownerDocument.
|
this._treebox.treeBody.ownerDocument.
|
||||||
getElementById('scholar-view-tabs').selectedIndex = 0;
|
getElementById('scholar-view-tabs').selectedIndex = 0;
|
||||||
|
|
||||||
this.selectItem(ids[0]);
|
this.selectItem(ids[0]);
|
||||||
}
|
}
|
||||||
}
|
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
this.rememberSelection(savedSelection);
|
this.rememberSelection(savedSelection);
|
||||||
|
|
Loading…
Reference in New Issue
Block a user