2001-09-26 02:53:13 +04:00
|
|
|
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
2012-05-21 15:12:37 +04:00
|
|
|
/* This Source Code Form is subject to the terms of the Mozilla Public
|
|
|
|
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
|
|
|
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
|
1999-01-21 04:51:09 +03:00
|
|
|
|
|
|
|
#include "EditAggregateTxn.h"
|
2012-07-13 10:33:42 +04:00
|
|
|
#include "nsAString.h"
|
|
|
|
#include "nsCOMPtr.h" // for nsCOMPtr
|
|
|
|
#include "nsError.h" // for NS_OK, etc
|
|
|
|
#include "nsISupportsUtils.h" // for NS_ADDREF
|
|
|
|
#include "nsITransaction.h" // for nsITransaction
|
|
|
|
#include "nsString.h" // for nsAutoString
|
1999-01-21 04:51:09 +03:00
|
|
|
|
|
|
|
EditAggregateTxn::EditAggregateTxn()
|
|
|
|
: EditTxn()
|
|
|
|
{
|
|
|
|
}
|
2009-05-09 08:59:25 +04:00
|
|
|
|
|
|
|
NS_IMPL_CYCLE_COLLECTION_UNLINK_BEGIN_INHERITED(EditAggregateTxn, EditTxn)
|
|
|
|
tmp->mChildren.Clear();
|
|
|
|
NS_IMPL_CYCLE_COLLECTION_UNLINK_END
|
|
|
|
|
|
|
|
NS_IMPL_CYCLE_COLLECTION_TRAVERSE_BEGIN_INHERITED(EditAggregateTxn, EditTxn)
|
2012-08-22 19:56:38 +04:00
|
|
|
for (uint32_t i = 0; i < tmp->mChildren.Length(); ++i) {
|
2009-05-09 08:59:25 +04:00
|
|
|
NS_CYCLE_COLLECTION_NOTE_EDGE_NAME(cb, "mChildren[i]");
|
|
|
|
cb.NoteXPCOMChild(static_cast<nsITransaction*>(tmp->mChildren[i]));
|
|
|
|
}
|
|
|
|
NS_IMPL_CYCLE_COLLECTION_TRAVERSE_END
|
|
|
|
|
2011-02-20 01:18:37 +03:00
|
|
|
NS_IMPL_ADDREF_INHERITED(EditAggregateTxn, EditTxn)
|
|
|
|
NS_IMPL_RELEASE_INHERITED(EditAggregateTxn, EditTxn)
|
2009-05-09 08:59:25 +04:00
|
|
|
NS_INTERFACE_MAP_BEGIN_CYCLE_COLLECTION(EditAggregateTxn)
|
|
|
|
NS_INTERFACE_MAP_END_INHERITING(EditTxn)
|
1999-01-21 04:51:09 +03:00
|
|
|
|
2001-03-09 17:23:59 +03:00
|
|
|
NS_IMETHODIMP EditAggregateTxn::DoTransaction(void)
|
1999-01-21 04:51:09 +03:00
|
|
|
{
|
|
|
|
nsresult result=NS_OK; // it's legal (but not very useful) to have an empty child list
|
2012-08-22 19:56:38 +04:00
|
|
|
for (uint32_t i = 0, length = mChildren.Length(); i < length; ++i)
|
1999-01-21 04:51:09 +03:00
|
|
|
{
|
2009-04-25 02:45:34 +04:00
|
|
|
nsITransaction *txn = mChildren[i];
|
|
|
|
if (!txn) { return NS_ERROR_NULL_POINTER; }
|
|
|
|
result = txn->DoTransaction();
|
|
|
|
if (NS_FAILED(result))
|
|
|
|
break;
|
1999-01-21 04:51:09 +03:00
|
|
|
}
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
2001-03-09 17:23:59 +03:00
|
|
|
NS_IMETHODIMP EditAggregateTxn::UndoTransaction(void)
|
1999-01-21 04:51:09 +03:00
|
|
|
{
|
|
|
|
nsresult result=NS_OK; // it's legal (but not very useful) to have an empty child list
|
2009-04-25 02:45:34 +04:00
|
|
|
// undo goes through children backwards
|
2012-08-22 19:56:38 +04:00
|
|
|
for (uint32_t i = mChildren.Length(); i-- != 0; )
|
1999-01-21 04:51:09 +03:00
|
|
|
{
|
2009-04-25 02:45:34 +04:00
|
|
|
nsITransaction *txn = mChildren[i];
|
|
|
|
if (!txn) { return NS_ERROR_NULL_POINTER; }
|
|
|
|
result = txn->UndoTransaction();
|
|
|
|
if (NS_FAILED(result))
|
|
|
|
break;
|
1999-01-21 04:51:09 +03:00
|
|
|
}
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
2001-03-09 17:23:59 +03:00
|
|
|
NS_IMETHODIMP EditAggregateTxn::RedoTransaction(void)
|
1999-01-21 04:51:09 +03:00
|
|
|
{
|
|
|
|
nsresult result=NS_OK; // it's legal (but not very useful) to have an empty child list
|
2012-08-22 19:56:38 +04:00
|
|
|
for (uint32_t i = 0, length = mChildren.Length(); i < length; ++i)
|
1999-01-21 04:51:09 +03:00
|
|
|
{
|
2009-04-25 02:45:34 +04:00
|
|
|
nsITransaction *txn = mChildren[i];
|
|
|
|
if (!txn) { return NS_ERROR_NULL_POINTER; }
|
|
|
|
result = txn->RedoTransaction();
|
|
|
|
if (NS_FAILED(result))
|
|
|
|
break;
|
1999-01-21 04:51:09 +03:00
|
|
|
}
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
2011-09-29 10:19:26 +04:00
|
|
|
NS_IMETHODIMP EditAggregateTxn::Merge(nsITransaction *aTransaction, bool *aDidMerge)
|
1999-01-21 04:51:09 +03:00
|
|
|
{
|
1999-02-15 21:25:30 +03:00
|
|
|
nsresult result=NS_OK; // it's legal (but not very useful) to have an empty child list
|
2003-06-30 18:20:49 +04:00
|
|
|
if (aDidMerge)
|
2011-10-17 18:59:28 +04:00
|
|
|
*aDidMerge = false;
|
2009-04-25 02:45:34 +04:00
|
|
|
// FIXME: Is this really intended not to loop? It looks like the code
|
|
|
|
// that used to be here sort of intended to loop, but didn't.
|
|
|
|
if (mChildren.Length() > 0)
|
1999-02-15 21:25:30 +03:00
|
|
|
{
|
2009-04-25 02:45:34 +04:00
|
|
|
nsITransaction *txn = mChildren[0];
|
|
|
|
if (!txn) { return NS_ERROR_NULL_POINTER; }
|
|
|
|
result = txn->Merge(aTransaction, aDidMerge);
|
1999-02-15 21:25:30 +03:00
|
|
|
}
|
|
|
|
return result;
|
1999-01-21 04:51:09 +03:00
|
|
|
}
|
|
|
|
|
2002-03-24 01:16:54 +03:00
|
|
|
NS_IMETHODIMP EditAggregateTxn::GetTxnDescription(nsAString& aString)
|
1999-01-21 04:51:09 +03:00
|
|
|
{
|
2004-06-17 04:13:25 +04:00
|
|
|
aString.AssignLiteral("EditAggregateTxn: ");
|
1999-01-21 04:51:09 +03:00
|
|
|
|
2001-03-09 17:23:59 +03:00
|
|
|
if (mName)
|
|
|
|
{
|
|
|
|
nsAutoString name;
|
|
|
|
mName->ToString(name);
|
|
|
|
aString += name;
|
|
|
|
}
|
1999-01-21 04:51:09 +03:00
|
|
|
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
1999-03-02 08:30:53 +03:00
|
|
|
NS_IMETHODIMP EditAggregateTxn::AppendChild(EditTxn *aTxn)
|
1999-01-21 04:51:09 +03:00
|
|
|
{
|
2009-04-25 02:45:34 +04:00
|
|
|
if (!aTxn) {
|
|
|
|
return NS_ERROR_NULL_POINTER;
|
1999-01-21 04:51:09 +03:00
|
|
|
}
|
2009-04-25 02:45:34 +04:00
|
|
|
|
|
|
|
nsRefPtr<EditTxn> *slot = mChildren.AppendElement();
|
|
|
|
if (!slot) {
|
|
|
|
return NS_ERROR_OUT_OF_MEMORY;
|
|
|
|
}
|
|
|
|
|
|
|
|
*slot = aTxn;
|
|
|
|
return NS_OK;
|
1999-01-21 04:51:09 +03:00
|
|
|
}
|
|
|
|
|
1999-03-15 03:57:32 +03:00
|
|
|
NS_IMETHODIMP EditAggregateTxn::GetName(nsIAtom **aName)
|
|
|
|
{
|
2003-06-30 18:20:49 +04:00
|
|
|
if (aName && mName)
|
1999-03-15 03:57:32 +03:00
|
|
|
{
|
2003-06-30 18:20:49 +04:00
|
|
|
*aName = mName;
|
|
|
|
NS_ADDREF(*aName);
|
|
|
|
return NS_OK;
|
1999-03-15 03:57:32 +03:00
|
|
|
}
|
|
|
|
return NS_ERROR_NULL_POINTER;
|
|
|
|
}
|