Back to index

lightning-sunbird  0.9+nobinonly
Public Member Functions | Private Member Functions | Private Attributes
nsTransactionItem Class Reference

#include <nsTransactionItem.h>

Collaboration diagram for nsTransactionItem:
Collaboration graph
[legend]

List of all members.

Public Member Functions

 nsTransactionItem (nsITransaction *aTransaction)
virtual ~nsTransactionItem ()
virtual nsresult AddChild (nsTransactionItem *aTransactionItem)
virtual nsresult GetTransaction (nsITransaction **aTransaction)
virtual nsresult GetIsBatch (PRBool *aIsBatch)
virtual nsresult GetNumberOfChildren (PRInt32 *aNumChildren)
virtual nsresult GetChild (PRInt32 aIndex, nsTransactionItem **aChild)
virtual nsresult DoTransaction (void)
virtual nsresult UndoTransaction (nsTransactionManager *aTxMgr)
virtual nsresult RedoTransaction (nsTransactionManager *aTxMgr)

Private Member Functions

virtual nsresult UndoChildren (nsTransactionManager *aTxMgr)
virtual nsresult RedoChildren (nsTransactionManager *aTxMgr)
virtual nsresult RecoverFromUndoError (nsTransactionManager *aTxMgr)
virtual nsresult RecoverFromRedoError (nsTransactionManager *aTxMgr)
virtual nsresult GetNumberOfUndoItems (PRInt32 *aNumItems)
virtual nsresult GetNumberOfRedoItems (PRInt32 *aNumItems)

Private Attributes

nsITransactionmTransaction
nsTransactionStackmUndoStack
nsTransactionRedoStackmRedoStack

Detailed Description

Definition at line 46 of file nsTransactionItem.h.


Constructor & Destructor Documentation

Definition at line 44 of file nsTransactionItem.cpp.

    : mTransaction(aTransaction), mUndoStack(0), mRedoStack(0)
{
}

Definition at line 49 of file nsTransactionItem.cpp.


Member Function Documentation

nsresult nsTransactionItem::AddChild ( nsTransactionItem aTransactionItem) [virtual]

Definition at line 61 of file nsTransactionItem.cpp.

{
  if (!aTransactionItem)
    return NS_ERROR_NULL_POINTER;

  if (!mUndoStack) {
    mUndoStack = new nsTransactionStack();
    if (!mUndoStack)
      return NS_ERROR_OUT_OF_MEMORY;
  }

  mUndoStack->Push(aTransactionItem);

  return NS_OK;
}

Here is the call graph for this function:

Here is the caller graph for this function:

Definition at line 177 of file nsTransactionItem.cpp.

{
  if (mTransaction)
    return mTransaction->DoTransaction();
  return NS_OK;
}

Here is the caller graph for this function:

nsresult nsTransactionItem::GetChild ( PRInt32  aIndex,
nsTransactionItem **  aChild 
) [virtual]

Definition at line 128 of file nsTransactionItem.cpp.

{
  if (!aChild)
    return NS_ERROR_NULL_POINTER;

  *aChild = 0;

  PRInt32 numItems = 0;
  nsresult result = GetNumberOfChildren(&numItems);

  if (NS_FAILED(result))
    return result;

  if (aIndex < 0 || aIndex >= numItems)
    return NS_ERROR_FAILURE;

  // Children are expected to be in the order they were added,
  // so the child first added would be at the bottom of the undo
  // stack, or if there are no items on the undo stack, it would
  // be at the top of the redo stack.

  result = GetNumberOfUndoItems(&numItems);

  if (NS_FAILED(result))
    return result;

  if (numItems > 0 && aIndex < numItems) {
    if (!mUndoStack)
      return NS_ERROR_FAILURE;

    return mUndoStack->GetItem(aIndex, aChild);
  }

  // Adjust the index for the redo stack:

  aIndex -=  numItems;

  result = GetNumberOfRedoItems(&numItems);

  if (NS_FAILED(result))
    return result;

  if (!mRedoStack || numItems == 0 || aIndex >= numItems)
      return NS_ERROR_FAILURE;

  return mRedoStack->GetItem(numItems - aIndex - 1, aChild);
}

Here is the call graph for this function:

nsresult nsTransactionItem::GetIsBatch ( PRBool aIsBatch) [virtual]

Definition at line 89 of file nsTransactionItem.cpp.

{
  if (!aIsBatch)
    return NS_ERROR_NULL_POINTER;

  *aIsBatch = !mTransaction;

  return NS_OK;
}

Definition at line 100 of file nsTransactionItem.cpp.

{
  nsresult result;

  if (!aNumChildren)
    return NS_ERROR_NULL_POINTER;

  *aNumChildren = 0;

  PRInt32 ui = 0;
  PRInt32 ri = 0;

  result = GetNumberOfUndoItems(&ui);

  if (NS_FAILED(result))
    return result;

  result = GetNumberOfRedoItems(&ri);

  if (NS_FAILED(result))
    return result;

  *aNumChildren = ui + ri;

  return NS_OK;
}

Here is the call graph for this function:

Here is the caller graph for this function:

nsresult nsTransactionItem::GetNumberOfRedoItems ( PRInt32 aNumItems) [private, virtual]

Definition at line 383 of file nsTransactionItem.cpp.

{
  if (!aNumItems)
    return NS_ERROR_NULL_POINTER;

  if (!mRedoStack) {
    *aNumItems = 0;
    return NS_OK;
  }

  return mRedoStack->GetSize(aNumItems);
}

Here is the call graph for this function:

Here is the caller graph for this function:

nsresult nsTransactionItem::GetNumberOfUndoItems ( PRInt32 aNumItems) [private, virtual]

Definition at line 369 of file nsTransactionItem.cpp.

{
  if (!aNumItems)
    return NS_ERROR_NULL_POINTER;

  if (!mUndoStack) {
    *aNumItems = 0;
    return NS_OK;
  }

  return mUndoStack->GetSize(aNumItems);
}

Here is the call graph for this function:

Here is the caller graph for this function:

Definition at line 78 of file nsTransactionItem.cpp.

{
  if (!aTransaction)
    return NS_ERROR_NULL_POINTER;

  *aTransaction = mTransaction;

  return NS_OK;
}

Here is the caller graph for this function:

Definition at line 408 of file nsTransactionItem.cpp.

{
  //
  // If this method gets called, we already successfully called
  // RedoTransaction() for the transaction item itself. Undo all
  // the children that successfully called RedoTransaction(),
  // then undo the transaction item itself.
  //

  nsresult result;

  result = UndoChildren(aTxMgr);

  if (NS_FAILED(result)) {
    return result;
  }

  if (!mTransaction)
    return NS_OK;

  return mTransaction->UndoTransaction();
}

Here is the call graph for this function:

Here is the caller graph for this function:

Definition at line 397 of file nsTransactionItem.cpp.

{
  //
  // If this method gets called, we never got to the point where we
  // successfully called UndoTransaction() for the transaction item itself.
  // Just redo any children that successfully called undo!
  //
  return RedoChildren(aTxMgr);
}

Here is the call graph for this function:

Here is the caller graph for this function:

Definition at line 302 of file nsTransactionItem.cpp.

{
  nsTransactionItem *item;
  nsresult result = NS_OK;
  PRInt32 sz = 0;

  if (!mRedoStack)
    return NS_OK;

  /* Redo all of the transaction items children! */
  result = mRedoStack->GetSize(&sz);

  if (NS_FAILED(result))
    return result;


  while (sz-- > 0) {
    result = mRedoStack->Peek(&item);

    if (NS_FAILED(result)) {
      return result;
    }

    nsITransaction *t = 0;

    result = item->GetTransaction(&t);

    if (NS_FAILED(result)) {
      return result;
    }

    PRBool doInterrupt = PR_FALSE;

    result = aTxMgr->WillRedoNotify(t, &doInterrupt);

    if (NS_FAILED(result)) {
      return result;
    }

    if (doInterrupt) {
      return NS_OK;
    }

    result = item->RedoTransaction(aTxMgr);

    if (NS_SUCCEEDED(result)) {
      result = mRedoStack->Pop(&item);

      if (NS_SUCCEEDED(result)) {
        result = mUndoStack->Push(item);

        // XXX: If we got an error here, I doubt we can recover!
        // XXX: Should we just push the item back on the redo stack?
      }
    }

    nsresult result2 = aTxMgr->DidUndoNotify(t, result);

    if (NS_SUCCEEDED(result)) {
      result = result2;
    }
  }

  return result;
}

Here is the call graph for this function:

Here is the caller graph for this function:

Definition at line 280 of file nsTransactionItem.cpp.

{
  nsresult result;

  if (mTransaction) {
    result = mTransaction->RedoTransaction();

    if (NS_FAILED(result))
      return result;
  }

  result = RedoChildren(aTxMgr);

  if (NS_FAILED(result)) {
    RecoverFromRedoError(aTxMgr);
    return result;
  }

  return NS_OK;
}

Here is the call graph for this function:

Here is the caller graph for this function:

Definition at line 208 of file nsTransactionItem.cpp.

{
  nsTransactionItem *item;
  nsresult result = NS_OK;
  PRInt32 sz = 0;

  if (mUndoStack) {
    if (!mRedoStack && mUndoStack) {
      mRedoStack = new nsTransactionRedoStack();
      if (!mRedoStack)
        return NS_ERROR_OUT_OF_MEMORY;
    }

    /* Undo all of the transaction items children! */
    result = mUndoStack->GetSize(&sz);

    if (NS_FAILED(result))
      return result;

    while (sz-- > 0) {
      result = mUndoStack->Peek(&item);

      if (NS_FAILED(result)) {
        return result;
      }

      nsITransaction *t = 0;

      result = item->GetTransaction(&t);

      if (NS_FAILED(result)) {
        return result;
      }

      PRBool doInterrupt = PR_FALSE;

      result = aTxMgr->WillUndoNotify(t, &doInterrupt);

      if (NS_FAILED(result)) {
        return result;
      }

      if (doInterrupt) {
        return NS_OK;
      }

      result = item->UndoTransaction(aTxMgr);

      if (NS_SUCCEEDED(result)) {
        result = mUndoStack->Pop(&item);

        if (NS_SUCCEEDED(result)) {
          result = mRedoStack->Push(item);

          /* XXX: If we got an error here, I doubt we can recover!
           * XXX: Should we just push the item back on the undo stack?
           */
        }
      }

      nsresult result2 = aTxMgr->DidUndoNotify(t, result);

      if (NS_SUCCEEDED(result)) {
        result = result2;
      }
    }
  }

  return result;
}

Here is the call graph for this function:

Here is the caller graph for this function:

Definition at line 185 of file nsTransactionItem.cpp.

{
  nsresult result = UndoChildren(aTxMgr);

  if (NS_FAILED(result)) {
    RecoverFromUndoError(aTxMgr);
    return result;
  }

  if (!mTransaction)
    return NS_OK;

  result = mTransaction->UndoTransaction();

  if (NS_FAILED(result)) {
    RecoverFromUndoError(aTxMgr);
    return result;
  }

  return NS_OK;
}

Here is the call graph for this function:

Here is the caller graph for this function:


Member Data Documentation

Definition at line 50 of file nsTransactionItem.h.

Definition at line 48 of file nsTransactionItem.h.

Definition at line 49 of file nsTransactionItem.h.


The documentation for this class was generated from the following files: