Back to index

lightning-sunbird  0.9+nobinonly
Public Member Functions | Static Public Member Functions | Public Attributes | Protected Attributes
EditAggregateTxn Class Reference

base class for all document editing transactions that require aggregation. More...

#include <EditAggregateTxn.h>

Inheritance diagram for EditAggregateTxn:
Inheritance graph
[legend]
Collaboration diagram for EditAggregateTxn:
Collaboration graph
[legend]

List of all members.

Public Member Functions

 EditAggregateTxn ()
virtual ~EditAggregateTxn ()
NS_IMETHOD DoTransaction (void)
NS_IMETHOD UndoTransaction (void)
NS_IMETHOD RedoTransaction (void)
NS_IMETHOD GetIsTransient (PRBool *aIsTransient)
NS_IMETHOD Merge (nsITransaction *aTransaction, PRBool *aDidMerge)
NS_IMETHOD GetTxnDescription (nsAString &aTxnDescription)
NS_IMETHOD AppendChild (EditTxn *aTxn)
 append a transaction to this aggregate
NS_IMETHOD GetCount (PRUint32 *aCount)
 get the number of nested txns.
NS_IMETHOD GetTxnAt (PRInt32 aIndex, EditTxn **aTxn)
 get the txn at index aIndex.
NS_IMETHOD SetName (nsIAtom *aName)
 set the name assigned to this txn
NS_IMETHOD GetName (nsIAtom **aName)
 get the name assigned to this txn
void doTransaction ()
 Executes the transaction.
void undoTransaction ()
 Restores the state to what it was before the transaction was executed.
void redoTransaction ()
 Executes the transaction again.
boolean merge (in nsITransaction aTransaction)
 Attempts to merge a transaction into "this" transaction.

Static Public Member Functions

static
NS_DECL_ISUPPORTS_INHERITED
const nsIID
GetCID ()

Public Attributes

readonly attribute boolean isTransient
 The transaction's transient state.
readonly attribute DOMString txnDescription

Protected Attributes

nsCOMPtr< nsISupportsArraymChildren
nsCOMPtr< nsIAtommName

Detailed Description

base class for all document editing transactions that require aggregation.

provides a list of child transactions.

Definition at line 56 of file EditAggregateTxn.h.


Constructor & Destructor Documentation

Definition at line 41 of file EditAggregateTxn.cpp.

  : EditTxn()
{
  nsresult res = NS_NewISupportsArray(getter_AddRefs(mChildren));
  NS_POSTCONDITION(NS_SUCCEEDED(res), "EditAggregateTxn failed in constructor");
}

Here is the call graph for this function:

Definition at line 48 of file EditAggregateTxn.cpp.

{
  // nsISupportsArray cleans up array for us at destruct time
}

Member Function Documentation

append a transaction to this aggregate

Definition at line 156 of file EditAggregateTxn.cpp.

{
  if (mChildren && aTxn)
  {
    // aaahhhh! broken interfaces drive me crazy!!!
    nsCOMPtr<nsISupports> isupports;
    aTxn->QueryInterface(NS_GET_IID(nsISupports), getter_AddRefs(isupports));
    mChildren->AppendElement(isupports);
    return NS_OK;
  }
  return NS_ERROR_NULL_POINTER;
}

Here is the call graph for this function:

Here is the caller graph for this function:

Executes the transaction.

Reimplemented from EditTxn.

Reimplemented in PlaceholderTxn, and DeleteRangeTxn.

Definition at line 53 of file EditAggregateTxn.cpp.

{
  nsresult result=NS_OK;  // it's legal (but not very useful) to have an empty child list
  if (mChildren)
  {
    PRInt32 i;
    PRUint32 count;
    mChildren->Count(&count);
    for (i=0; i<((PRInt32)count); i++)
    {
      nsCOMPtr<nsITransaction> txn (do_QueryElementAt(mChildren, i));
      if (!txn) { return NS_ERROR_NULL_POINTER; }
      result = txn->DoTransaction();
      if (NS_FAILED(result))
        break;
    }  
  }
  return result;
}

Here is the call graph for this function:

Reimplemented from EditTxn.

Reimplemented in PlaceholderTxn, and DeleteRangeTxn.

Definition at line 62 of file EditAggregateTxn.h.

{ static const nsIID cid = EDIT_AGGREGATE_TXN_CID; return cid; }

Here is the caller graph for this function:

get the number of nested txns.

This is the number of top-level txns, it does not do recursive decent.

Definition at line 169 of file EditAggregateTxn.cpp.

{
  if (!aCount) {
    return NS_ERROR_NULL_POINTER;
  }
  *aCount=0;
  if (mChildren) {
    mChildren->Count(aCount);
  }
  return NS_OK;
}

Reimplemented from EditTxn.

Definition at line 114 of file EditAggregateTxn.cpp.

{
  if (aIsTransient)
    *aIsTransient = PR_FALSE;
  return NS_OK;
}

get the name assigned to this txn

Definition at line 215 of file EditAggregateTxn.cpp.

{
  if (aName && mName)
  {
    *aName = mName;
    NS_ADDREF(*aName);
    return NS_OK;
  }
  return NS_ERROR_NULL_POINTER;
}

Here is the call graph for this function:

Here is the caller graph for this function:

get the txn at index aIndex.

returns NS_ERROR_UNEXPECTED if there is no txn at aIndex.

Definition at line 181 of file EditAggregateTxn.cpp.

{
  // preconditions
  NS_PRECONDITION(aTxn, "null out param");
  NS_PRECONDITION(mChildren, "bad internal state");

  if (!aTxn) {
    return NS_ERROR_NULL_POINTER;
  }
  *aTxn = nsnull; // initialize out param as soon as we know it's a valid pointer
  if (!mChildren) {
    return NS_ERROR_UNEXPECTED;
  }

  // get the transaction at aIndex
  PRUint32 txnCount;
  mChildren->Count(&txnCount);
  if (0>aIndex || ((PRInt32)txnCount)<=aIndex) {
    return NS_ERROR_UNEXPECTED;
  }
  // ugh, this is all wrong - what a mess we have with editor transaction interfaces
  mChildren->QueryElementAt(aIndex, EditTxn::GetCID(), (void**)aTxn);
  if (!*aTxn)
    return NS_ERROR_UNEXPECTED;
  return NS_OK;
}

Here is the call graph for this function:

NS_IMETHODIMP EditAggregateTxn::GetTxnDescription ( nsAString &  aTxnDescription)

Reimplemented from EditTxn.

Reimplemented in PlaceholderTxn, and DeleteRangeTxn.

Definition at line 142 of file EditAggregateTxn.cpp.

{
  aString.AssignLiteral("EditAggregateTxn: ");

  if (mName)
  {
    nsAutoString name;
    mName->ToString(name);
    aString += name;
  }

  return NS_OK;
}
NS_IMETHODIMP EditAggregateTxn::Merge ( nsITransaction aTransaction,
PRBool aDidMerge 
)

Reimplemented from EditTxn.

Reimplemented in PlaceholderTxn, and DeleteRangeTxn.

Definition at line 121 of file EditAggregateTxn.cpp.

{
  nsresult result=NS_OK;  // it's legal (but not very useful) to have an empty child list
  if (aDidMerge)
    *aDidMerge = PR_FALSE;
  if (mChildren)
  {
    PRInt32 i=0;
    PRUint32 count;
    mChildren->Count(&count);
    NS_ASSERTION(count>0, "bad count");
    if (0<count)
    {
      nsCOMPtr<nsITransaction> txn (do_QueryElementAt(mChildren, i));
      if (!txn) { return NS_ERROR_NULL_POINTER; }
      result = txn->Merge(aTransaction, aDidMerge);
    }
  }
  return result;
}

Here is the call graph for this function:

boolean nsITransaction::merge ( in nsITransaction  aTransaction) [inherited]

Attempts to merge a transaction into "this" transaction.

Both transactions must be in their undo state, doTransaction() methods already called. The transaction manager calls this method to coalesce a new transaction with the transaction on the top of the undo stack. This method returns a boolean value that indicates the merge result. A true value indicates that the transactions were merged successfully, a false value if the merge was not possible or failed. If true, the transaction manager will Release() the new transacton instead of pushing it on the undo stack.

Parameters:
aTransactionthe previously executed transaction to merge.

Executes the transaction again.

Can only be called on a transaction that was previously undone.

In most cases, the redoTransaction() method will actually call the doTransaction() method to execute the transaction again.

Reimplemented from EditTxn.

Reimplemented in PlaceholderTxn, and DeleteRangeTxn.

Definition at line 94 of file EditAggregateTxn.cpp.

{
  nsresult result=NS_OK;  // it's legal (but not very useful) to have an empty child list
  if (mChildren)
  {
    PRInt32 i;
    PRUint32 count;
    mChildren->Count(&count);
    for (i=0; i<((PRInt32)count); i++)
    {
      nsCOMPtr<nsITransaction> txn (do_QueryElementAt(mChildren, i));
      if (!txn) { return NS_ERROR_NULL_POINTER; }
      result = txn->RedoTransaction();
      if (NS_FAILED(result))
        break;
    }  
  }
  return result;
}

Here is the call graph for this function:

set the name assigned to this txn

Definition at line 209 of file EditAggregateTxn.cpp.

{
  mName = do_QueryInterface(aName);
  return NS_OK;
}

Here is the call graph for this function:

Restores the state to what it was before the transaction was executed.

Reimplemented from EditTxn.

Reimplemented in PlaceholderTxn, and DeleteRangeTxn.

Definition at line 73 of file EditAggregateTxn.cpp.

{
  nsresult result=NS_OK;  // it's legal (but not very useful) to have an empty child list
  if (mChildren)
  {
    PRInt32 i;
    PRUint32 count;
    mChildren->Count(&count);
    // undo goes through children backwards
    for (i=count-1; i>=0; i--)
    {
      nsCOMPtr<nsITransaction> txn (do_QueryElementAt(mChildren, i));
      if (!txn) { return NS_ERROR_NULL_POINTER; }
      result = txn->UndoTransaction();
      if (NS_FAILED(result))
        break;
    }  
  }
  return result;
}

Here is the call graph for this function:


Member Data Documentation

The transaction's transient state.

This attribute is checked by the transaction manager after the transaction's Execute() method is called. If the transient state is false, a reference to the transaction is held by the transaction manager so that the transactions' undoTransaction() and redoTransaction() methods can be called. If the transient state is true, the transaction manager returns immediately after the transaction's doTransaction() method is called, no references to the transaction are maintained. Transient transactions cannot be undone or redone by the transaction manager.

Definition at line 79 of file nsITransaction.idl.

Definition at line 101 of file EditAggregateTxn.h.

Definition at line 102 of file EditAggregateTxn.h.

readonly attribute DOMString nsPIEditorTransaction::txnDescription [inherited]

Definition at line 50 of file nsPIEditorTransaction.idl.


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