mPersistStateStore->HasAssertion(container, nsXULContentUtils::NC_open, nsXULContentUtils::true_, PR_TRUE, &open);
if (mPersistStateStore) mPersistStateStore->HasAssertion(container, nsXULContentUtils::NC_open, nsXULContentUtils::true_, PR_TRUE, &open);
nsXULOutlinerBuilder::ReplaceMatch(nsIRDFResource* aMember,                                   const nsTemplateMatch* aOldMatch,                                   nsTemplateMatch* aNewMatch){    if (! mBoxObject)        return NS_OK;    if (aOldMatch) {        // Either replacement or removal. Grovel through the rows        // looking for aOldMatch.        nsOutlinerRows::iterator iter = mRows.Find(mConflictSet, aMember);        NS_ASSERTION(iter != mRows.Last(), "couldn't find row");        if (iter == mRows.Last())            return NS_ERROR_FAILURE;        if (aNewMatch) {            // replacement            iter->mMatch = aNewMatch;            mBoxObject->InvalidateRow(iter.GetRowIndex());        }        else {            // Removal. Clean up the conflict set.            RemoveMatchesFor(aMember);            // Remove the rows from the view            PRInt32 row = iter.GetRowIndex();            PRInt32 delta = mRows.GetSubtreeSizeFor(iter);            mRows.RemoveRowAt(iter);            // XXX Could potentially invalidate the iterator's            // mContainer[Type|State] caching here, but it'll work            // itself out.            // Notify the box object            mBoxObject->RowCountChanged(row, -delta - 1);        }    }    else if (aNewMatch) {        // Insertion.        Value val;        aNewMatch->GetAssignmentFor(mConflictSet, mContainerVar, &val);        nsIRDFResource* container = VALUE_TO_IRDFRESOURCE(val);        PRInt32 row = -1;        nsOutlinerRows::Subtree* parent = nsnull;        if (container != mRows.GetRootResource()) {            nsOutlinerRows::iterator iter =                mRows.Find(mConflictSet, container);            row = iter.GetRowIndex();            NS_ASSERTION(iter != mRows.Last(), "couldn't find container row");            if (iter == mRows.Last())                return NS_ERROR_FAILURE;            // Use the persist store to remember if the container            // is open or closed.            PRBool open = PR_FALSE;            mPersistStateStore->HasAssertion(container,                                             nsXULContentUtils::NC_open,                                             nsXULContentUtils::true_,                                             PR_TRUE,                                             &open);            if (open) {                parent = mRows.EnsureSubtreeFor(iter);            }            else if ((iter->mContainerType != nsOutlinerRows::eContainerType_Container) ||                     (iter->mContainerState != nsOutlinerRows::eContainerState_Nonempty)) {                // The container is closed, but we know something has                // just been inserted into it.                iter->mContainerType  = nsOutlinerRows::eContainerType_Container;                iter->mContainerState = nsOutlinerRows::eContainerState_Nonempty;                mBoxObject->InvalidateRow(iter.GetRowIndex());            }        }        else            parent = mRows.GetRoot();         if (parent) {            // If we get here, then we're inserting into an open            // container. By default, place the new element at the            // end of the container            PRInt32 index = parent->Count();            if (mSortVariable) {                // Figure out where to put the new element by doing an                // insertion sort.                PRInt32 left = 0;                PRInt32 right = parent->Count();                while (left < right) {                    index = (left + right) / 2;                    PRInt32 cmp = CompareMatches((*parent)[index].mMatch, aNewMatch);                    if (cmp < 0)                        left = ++index;                    else if (cmp > 0)                        right = index - 1;                    else                        break;                }            }            mRows.InsertRowAt(aNewMatch, parent, index);            mBoxObject->RowCountChanged(row + index + 1, +1);        }    }    return NS_OK;}