Back to index

lightning-sunbird  0.9+nobinonly
Public Member Functions | Static Public Member Functions | Public Attributes | Protected Attributes | Private Member Functions | Friends
ChangeAttributeTxn Class Reference

A transaction that changes an attribute of a content node. More...

#include <ChangeAttributeTxn.h>

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

List of all members.

Public Member Functions

virtual ~ChangeAttributeTxn ()
NS_IMETHOD Init (nsIEditor *aEditor, nsIDOMElement *aNode, const nsAString &aAttribute, const nsAString &aValue, PRBool aRemoveAttribute)
 Initialize the transaction.
NS_IMETHOD DoTransaction (void)
NS_IMETHOD UndoTransaction (void)
NS_IMETHOD RedoTransaction (void)
NS_IMETHOD Merge (nsITransaction *aTransaction, PRBool *aDidMerge)
NS_IMETHOD GetTxnDescription (nsAString &aTxnDescription)
NS_IMETHOD GetIsTransient (PRBool *aIsTransient)
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 const nsIIDGetCID ()

Public Attributes

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

Protected Attributes

nsIEditormEditor
 the editor that created this transaction
nsCOMPtr< nsIDOMElementmElement
 the element to operate upon
nsString mAttribute
 the attribute to change
nsString mValue
 the value to set the attribute to (ignored if mRemoveAttribute==PR_TRUE)
nsString mUndoValue
 the value to set the attribute to for undo
PRBool mAttributeWasSet
 PR_TRUE if the mAttribute was set on mElement at the time of execution.
PRBool mRemoveAttribute
 PR_TRUE if the operation is to remove mAttribute from mElement.

Private Member Functions

 ChangeAttributeTxn ()

Friends

class TransactionFactory

Detailed Description

A transaction that changes an attribute of a content node.

This transaction covers add, remove, and change attribute.

Definition at line 55 of file ChangeAttributeTxn.h.


Constructor & Destructor Documentation

Definition at line 46 of file ChangeAttributeTxn.cpp.

{
}

Definition at line 41 of file ChangeAttributeTxn.cpp.

  : EditTxn()
{
}

Member Function Documentation

Executes the transaction.

Reimplemented from EditTxn.

Definition at line 69 of file ChangeAttributeTxn.cpp.

{
  NS_ASSERTION(mEditor && mElement, "bad state");
  if (!mEditor || !mElement) { return NS_ERROR_NOT_INITIALIZED; }

  // need to get the current value of the attribute and save it, and set mAttributeWasSet
  nsresult result = mEditor->GetAttributeValue(mElement, mAttribute, mUndoValue, &mAttributeWasSet);
  // XXX: hack until attribute-was-set code is implemented
  if (!mUndoValue.IsEmpty())
    mAttributeWasSet = PR_TRUE;
  // XXX: end hack
  
  // now set the attribute to the new value
  if (!mRemoveAttribute)
    result = mElement->SetAttribute(mAttribute, mValue);
  else
    result = mElement->RemoveAttribute(mAttribute);

  return result;
}
static const nsIID& ChangeAttributeTxn::GetCID ( ) [inline, static]

Reimplemented from EditTxn.

Definition at line 59 of file ChangeAttributeTxn.h.

{ static const nsIID iid = CHANGE_ATTRIBUTE_TXN_CID; return iid; }

Here is the caller graph for this function:

NS_IMETHODIMP EditTxn::GetIsTransient ( PRBool aIsTransient) [inherited]

Reimplemented in JoinElementTxn, SetDocTitleTxn, and EditAggregateTxn.

Definition at line 66 of file EditTxn.cpp.

{
  if (aIsTransient)
    *aIsTransient = PR_FALSE;
  return NS_OK;
}
NS_IMETHODIMP ChangeAttributeTxn::GetTxnDescription ( nsAString &  aTxnDescription)

Reimplemented from EditTxn.

Definition at line 125 of file ChangeAttributeTxn.cpp.

{
  aString.AssignLiteral("ChangeAttributeTxn: [mRemoveAttribute == ");

  if (!mRemoveAttribute)
    aString.AppendLiteral("false] ");
  else
    aString.AppendLiteral("true] ");
  aString += mAttribute;
  return NS_OK;
}
NS_IMETHODIMP ChangeAttributeTxn::Init ( nsIEditor aEditor,
nsIDOMElement aNode,
const nsAString &  aAttribute,
const nsAString &  aValue,
PRBool  aRemoveAttribute 
)

Initialize the transaction.

Parameters:
aEditorthe object providing core editing operations
aNodethe node whose attribute will be changed
aAttributethe name of the attribute to change
aValuethe new value for aAttribute, if aRemoveAttribute is false
aRemoveAttributeif PR_TRUE, remove aAttribute from aNode

Definition at line 50 of file ChangeAttributeTxn.cpp.

{
  NS_ASSERTION(aEditor && aElement, "bad arg");
  if (!aEditor || !aElement) { return NS_ERROR_NULL_POINTER; }

  mEditor = aEditor;
  mElement = do_QueryInterface(aElement);
  mAttribute = aAttribute;
  mValue = aValue;
  mRemoveAttribute = aRemoveAttribute;
  mAttributeWasSet=PR_FALSE;
  mUndoValue.Truncate();
  return NS_OK;
}

Here is the call graph for this function:

NS_IMETHODIMP ChangeAttributeTxn::Merge ( nsITransaction aTransaction,
PRBool aDidMerge 
)

Reimplemented from EditTxn.

Definition at line 118 of file ChangeAttributeTxn.cpp.

{
  if (aDidMerge)
    *aDidMerge=PR_FALSE;
  return NS_OK;
}
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.

Definition at line 104 of file ChangeAttributeTxn.cpp.

{
  NS_ASSERTION(mEditor && mElement, "bad state");
  if (!mEditor || !mElement) { return NS_ERROR_NOT_INITIALIZED; }

  nsresult result;
  if (!mRemoveAttribute)
    result = mElement->SetAttribute(mAttribute, mValue);
  else
    result = mElement->RemoveAttribute(mAttribute);

  return result;
}

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

Reimplemented from EditTxn.

Definition at line 90 of file ChangeAttributeTxn.cpp.

{
  NS_ASSERTION(mEditor && mElement, "bad state");
  if (!mEditor || !mElement) { return NS_ERROR_NOT_INITIALIZED; }

  nsresult result;
  if (mAttributeWasSet)
    result = mElement->SetAttribute(mAttribute, mUndoValue);
  else
    result = mElement->RemoveAttribute(mAttribute);

  return result;
}

Friends And Related Function Documentation

friend class TransactionFactory [friend]

Definition at line 114 of file ChangeAttributeTxn.h.


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.

the attribute to change

Definition at line 100 of file ChangeAttributeTxn.h.

PR_TRUE if the mAttribute was set on mElement at the time of execution.

Definition at line 109 of file ChangeAttributeTxn.h.

the editor that created this transaction

Definition at line 94 of file ChangeAttributeTxn.h.

the element to operate upon

Definition at line 97 of file ChangeAttributeTxn.h.

PR_TRUE if the operation is to remove mAttribute from mElement.

Definition at line 112 of file ChangeAttributeTxn.h.

the value to set the attribute to for undo

Definition at line 106 of file ChangeAttributeTxn.h.

the value to set the attribute to (ignored if mRemoveAttribute==PR_TRUE)

Definition at line 103 of file ChangeAttributeTxn.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: