Fix for collections not refreshing on item delete (thanks Simon) and new snapshots not getting added to the active collection (since yesterday)

This commit is contained in:
Dan Stillman 2006-10-24 08:04:41 +00:00
parent 9762d768e1
commit 99f7badf42
5 changed files with 41 additions and 16 deletions

View File

@ -102,7 +102,7 @@
textbox.inputField.QueryInterface(CI.nsIDOMNSEditableElement).editor
);
} catch(ex) {
Zotero.debug(ex);
// this throws an error on window open...
}
}

View File

@ -795,20 +795,18 @@ var ZoteroPane = new function()
function addAttachmentFromPage(link, id)
{
if (itemsView && itemsView._itemGroup.isCollection())
{
var parentCollectionID = itemsView._itemGroup.ref.getID();
}
if(link)
{
var attachmentID =
Zotero.Attachments.linkFromDocument(window.content.document, id);
Zotero.Attachments.linkFromDocument(window.content.document, id, parentCollectionID);
}
else
{
var attachmentID =
Zotero.Attachments.importFromDocument(window.content.document, id);
}
if (attachmentID && itemsView && itemsView._itemGroup.isCollection())
{
itemsView._itemGroup.ref.addItem(attachmentID);
Zotero.Attachments.importFromDocument(window.content.document, id, false, parentCollectionID);
}
}

View File

@ -258,7 +258,7 @@ Zotero.Attachments = new function(){
// TODO: what if called on file:// document?
function linkFromDocument(document, sourceItemID){
function linkFromDocument(document, sourceItemID, parentCollectionIDs){
Zotero.debug('Linking attachment from document');
var url = document.location;
@ -269,6 +269,13 @@ Zotero.Attachments = new function(){
var itemID = _addToDB(null, url, title, this.LINK_MODE_LINKED_URL,
mimeType, charsetID, sourceItemID);
// Add to collections
var ids = Zotero.flattenArguments(parentCollectionIDs);
for each(var id in ids){
var col = Zotero.Collections.get(id);
col.addItem(itemID);
}
// Run the fulltext indexer asynchronously (actually, it hangs the UI
// thread, but at least it lets the menu close)
setTimeout(function(){
@ -279,7 +286,7 @@ Zotero.Attachments = new function(){
}
function importFromDocument(document, sourceItemID, forceTitle){
function importFromDocument(document, sourceItemID, forceTitle, parentCollectionIDs){
Zotero.debug('Importing attachment from document');
var url = document.location;
@ -331,6 +338,13 @@ Zotero.Attachments = new function(){
_addToDB(file, url, title, Zotero.Attachments.LINK_MODE_IMPORTED_URL, mimeType,
charsetID, sourceItemID, itemID);
// Add to collections
var ids = Zotero.flattenArguments(parentCollectionIDs);
for each(var id in ids){
var col = Zotero.Collections.get(id);
col.addItem(itemID);
}
Zotero.DB.commitTransaction();
Zotero.Fulltext.indexDocument(document, itemID);

View File

@ -1515,9 +1515,19 @@ Zotero.Item.prototype.erase = function(deleteChildren){
// Remove item from parent collections
var parentCollectionIDs = this.getCollections();
if (parentCollectionIDs){
var notifierState = Zotero.Notifier.isEnabled();
Zotero.Notifier.disable();
for (var i=0; i<parentCollectionIDs.length; i++){
Zotero.Collections.get(parentCollectionIDs[i]).removeItem(this.getID());
}
if (notifierState){
Zotero.Notifier.enable();
}
else {
Zotero.Notifier.disable();
}
}
// Note
@ -2331,7 +2341,7 @@ Zotero.Collection.prototype.removeItem = function(itemID){
// If this was the last item, set collection to empty
if (!this._childItems.length){
this._hasChildItems = false;
// DEBUG: is this necessary?
// DEBUG: is this necessary? if so, it's no longer called during item deletes...
Zotero.Notifier.trigger('modify', 'collection', this.getID());
}

View File

@ -105,17 +105,20 @@ Zotero.ItemTreeView.prototype.notify = function(action, type, ids)
var quicksearch = this._treebox.treeBody.ownerDocument.getElementById('tb-search');
if((action == 'remove' && !this._itemGroup.isLibrary())
|| (action == 'delete' && (this._itemGroup.isLibrary() || this._itemGroup.isSearch())))
if((action == 'remove' && !this._itemGroup.isLibrary()) || action == 'delete')
{
//Since a remove involves shifting of rows, we have to do it in order
//sort the ids by row
var rows = new Array();
for(var i=0, len=ids.length; i<len; i++)
{
if(action == 'delete' || !this._itemGroup.ref.hasItem(ids[i]))
{
rows.push(this._itemRowMap[ids[i]]);
}
}
if(rows.length > 0)
{
rows.sort(function(a,b) { return a-b });