2007-03-22 10:30:00 -07:00
|
|
|
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
2012-05-21 04:12:37 -07: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/. */
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2012-07-12 23:33:42 -07:00
|
|
|
#include "mozilla/Assertions.h"
|
|
|
|
#include "mozilla/mozalloc.h"
|
|
|
|
#include "nsAutoPtr.h"
|
|
|
|
#include "nsCOMPtr.h"
|
|
|
|
#include "nsDebug.h"
|
|
|
|
#include "nsError.h"
|
|
|
|
#include "nsISupportsBase.h"
|
|
|
|
#include "nsISupportsUtils.h"
|
2007-03-22 10:30:00 -07:00
|
|
|
#include "nsITransaction.h"
|
2012-07-12 23:33:42 -07:00
|
|
|
#include "nsITransactionList.h"
|
2007-03-22 10:30:00 -07:00
|
|
|
#include "nsITransactionListener.h"
|
2012-07-12 23:33:42 -07:00
|
|
|
#include "nsIWeakReference.h"
|
2007-03-22 10:30:00 -07:00
|
|
|
#include "nsTransactionItem.h"
|
|
|
|
#include "nsTransactionList.h"
|
2012-07-12 23:33:42 -07:00
|
|
|
#include "nsTransactionManager.h"
|
|
|
|
#include "nsTransactionStack.h"
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2012-08-22 08:56:38 -07:00
|
|
|
nsTransactionManager::nsTransactionManager(int32_t aMaxTransactionCount)
|
2009-04-24 15:45:34 -07:00
|
|
|
: mMaxTransactionCount(aMaxTransactionCount)
|
2012-03-02 12:08:40 -08:00
|
|
|
, mDoStack(nsTransactionStack::FOR_UNDO)
|
|
|
|
, mUndoStack(nsTransactionStack::FOR_UNDO)
|
|
|
|
, mRedoStack(nsTransactionStack::FOR_REDO)
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
nsTransactionManager::~nsTransactionManager()
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2013-08-01 18:29:05 -07:00
|
|
|
NS_IMPL_CYCLE_COLLECTION_CLASS(nsTransactionManager)
|
|
|
|
|
2009-05-08 21:59:25 -07:00
|
|
|
NS_IMPL_CYCLE_COLLECTION_UNLINK_BEGIN(nsTransactionManager)
|
2012-11-14 23:32:40 -08:00
|
|
|
NS_IMPL_CYCLE_COLLECTION_UNLINK(mListeners)
|
2009-05-08 21:59:25 -07:00
|
|
|
tmp->mDoStack.DoUnlink();
|
|
|
|
tmp->mUndoStack.DoUnlink();
|
|
|
|
tmp->mRedoStack.DoUnlink();
|
|
|
|
NS_IMPL_CYCLE_COLLECTION_UNLINK_END
|
|
|
|
|
|
|
|
NS_IMPL_CYCLE_COLLECTION_TRAVERSE_BEGIN(nsTransactionManager)
|
2012-11-14 23:32:40 -08:00
|
|
|
NS_IMPL_CYCLE_COLLECTION_TRAVERSE(mListeners)
|
2009-05-08 21:59:25 -07:00
|
|
|
tmp->mDoStack.DoTraverse(cb);
|
|
|
|
tmp->mUndoStack.DoTraverse(cb);
|
|
|
|
tmp->mRedoStack.DoTraverse(cb);
|
|
|
|
NS_IMPL_CYCLE_COLLECTION_TRAVERSE_END
|
|
|
|
|
|
|
|
NS_INTERFACE_MAP_BEGIN_CYCLE_COLLECTION(nsTransactionManager)
|
|
|
|
NS_INTERFACE_MAP_ENTRY(nsITransactionManager)
|
|
|
|
NS_INTERFACE_MAP_ENTRY(nsISupportsWeakReference)
|
|
|
|
NS_INTERFACE_MAP_ENTRY_AMBIGUOUS(nsISupports, nsITransactionManager)
|
|
|
|
NS_INTERFACE_MAP_END
|
|
|
|
|
2011-03-06 03:11:31 -08:00
|
|
|
NS_IMPL_CYCLE_COLLECTING_ADDREF(nsTransactionManager)
|
|
|
|
NS_IMPL_CYCLE_COLLECTING_RELEASE(nsTransactionManager)
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
nsTransactionManager::DoTransaction(nsITransaction *aTransaction)
|
|
|
|
{
|
|
|
|
nsresult result;
|
|
|
|
|
2010-06-17 13:40:48 -07:00
|
|
|
NS_ENSURE_TRUE(aTransaction, NS_ERROR_NULL_POINTER);
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2011-09-28 23:19:26 -07:00
|
|
|
bool doInterrupt = false;
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
result = WillDoNotify(aTransaction, &doInterrupt);
|
|
|
|
|
|
|
|
if (NS_FAILED(result)) {
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (doInterrupt) {
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2013-01-03 22:54:26 -08:00
|
|
|
result = BeginTransaction(aTransaction, nullptr);
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
if (NS_FAILED(result)) {
|
|
|
|
DidDoNotify(aTransaction, result);
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
2013-01-03 22:54:26 -08:00
|
|
|
result = EndTransaction(false);
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
nsresult result2 = DidDoNotify(aTransaction, result);
|
|
|
|
|
|
|
|
if (NS_SUCCEEDED(result))
|
|
|
|
result = result2;
|
|
|
|
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
nsTransactionManager::UndoTransaction()
|
|
|
|
{
|
|
|
|
nsresult result = NS_OK;
|
|
|
|
|
|
|
|
// It is illegal to call UndoTransaction() while the transaction manager is
|
|
|
|
// executing a transaction's DoTransaction() method! If this happens,
|
|
|
|
// the UndoTransaction() request is ignored, and we return NS_ERROR_FAILURE.
|
|
|
|
|
2012-03-02 12:08:40 -08:00
|
|
|
nsRefPtr<nsTransactionItem> tx = mDoStack.Peek();
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
if (tx) {
|
|
|
|
return NS_ERROR_FAILURE;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Peek at the top of the undo stack. Don't remove the transaction
|
|
|
|
// until it has successfully completed.
|
2012-03-02 12:08:40 -08:00
|
|
|
tx = mUndoStack.Peek();
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
// Bail if there's nothing on the stack.
|
|
|
|
if (!tx) {
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2012-06-19 06:23:36 -07:00
|
|
|
nsCOMPtr<nsITransaction> t = tx->GetTransaction();
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2011-09-28 23:19:26 -07:00
|
|
|
bool doInterrupt = false;
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
result = WillUndoNotify(t, &doInterrupt);
|
|
|
|
|
|
|
|
if (NS_FAILED(result)) {
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (doInterrupt) {
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
result = tx->UndoTransaction(this);
|
|
|
|
|
|
|
|
if (NS_SUCCEEDED(result)) {
|
2012-03-02 12:08:40 -08:00
|
|
|
tx = mUndoStack.Pop();
|
|
|
|
mRedoStack.Push(tx);
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
nsresult result2 = DidUndoNotify(t, result);
|
|
|
|
|
|
|
|
if (NS_SUCCEEDED(result))
|
|
|
|
result = result2;
|
|
|
|
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
nsTransactionManager::RedoTransaction()
|
|
|
|
{
|
|
|
|
nsresult result = NS_OK;
|
|
|
|
|
|
|
|
// It is illegal to call RedoTransaction() while the transaction manager is
|
|
|
|
// executing a transaction's DoTransaction() method! If this happens,
|
|
|
|
// the RedoTransaction() request is ignored, and we return NS_ERROR_FAILURE.
|
|
|
|
|
2012-03-02 12:08:40 -08:00
|
|
|
nsRefPtr<nsTransactionItem> tx = mDoStack.Peek();
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
if (tx) {
|
|
|
|
return NS_ERROR_FAILURE;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Peek at the top of the redo stack. Don't remove the transaction
|
|
|
|
// until it has successfully completed.
|
2012-03-02 12:08:40 -08:00
|
|
|
tx = mRedoStack.Peek();
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
// Bail if there's nothing on the stack.
|
|
|
|
if (!tx) {
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2012-06-19 06:23:36 -07:00
|
|
|
nsCOMPtr<nsITransaction> t = tx->GetTransaction();
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2011-09-28 23:19:26 -07:00
|
|
|
bool doInterrupt = false;
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
result = WillRedoNotify(t, &doInterrupt);
|
|
|
|
|
|
|
|
if (NS_FAILED(result)) {
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (doInterrupt) {
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
result = tx->RedoTransaction(this);
|
|
|
|
|
|
|
|
if (NS_SUCCEEDED(result)) {
|
2012-03-02 12:08:40 -08:00
|
|
|
tx = mRedoStack.Pop();
|
|
|
|
mUndoStack.Push(tx);
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
nsresult result2 = DidRedoNotify(t, result);
|
|
|
|
|
|
|
|
if (NS_SUCCEEDED(result))
|
|
|
|
result = result2;
|
|
|
|
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
nsTransactionManager::Clear()
|
|
|
|
{
|
|
|
|
nsresult result;
|
|
|
|
|
|
|
|
result = ClearRedoStack();
|
|
|
|
|
|
|
|
if (NS_FAILED(result)) {
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
|
|
|
result = ClearUndoStack();
|
|
|
|
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
2013-01-03 22:54:26 -08:00
|
|
|
nsTransactionManager::BeginBatch(nsISupports* aData)
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
|
|
|
nsresult result;
|
|
|
|
|
|
|
|
// We can batch independent transactions together by simply pushing
|
|
|
|
// a dummy transaction item on the do stack. This dummy transaction item
|
|
|
|
// will be popped off the do stack, and then pushed on the undo stack
|
|
|
|
// in EndBatch().
|
|
|
|
|
2011-09-28 23:19:26 -07:00
|
|
|
bool doInterrupt = false;
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
result = WillBeginBatchNotify(&doInterrupt);
|
|
|
|
|
|
|
|
if (NS_FAILED(result)) {
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (doInterrupt) {
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2013-01-03 22:54:26 -08:00
|
|
|
result = BeginTransaction(0, aData);
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
nsresult result2 = DidBeginBatchNotify(result);
|
|
|
|
|
|
|
|
if (NS_SUCCEEDED(result))
|
|
|
|
result = result2;
|
|
|
|
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
2013-01-03 22:54:26 -08:00
|
|
|
nsTransactionManager::EndBatch(bool aAllowEmpty)
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
2008-12-10 08:46:36 -08:00
|
|
|
nsCOMPtr<nsITransaction> ti;
|
2007-03-22 10:30:00 -07:00
|
|
|
nsresult result;
|
|
|
|
|
|
|
|
// XXX: Need to add some mechanism to detect the case where the transaction
|
|
|
|
// at the top of the do stack isn't the dummy transaction, so we can
|
|
|
|
// throw an error!! This can happen if someone calls EndBatch() within
|
|
|
|
// the DoTransaction() method of a transaction.
|
|
|
|
//
|
|
|
|
// For now, we can detect this case by checking the value of the
|
|
|
|
// dummy transaction's mTransaction field. If it is our dummy
|
2013-04-02 17:13:10 -07:00
|
|
|
// transaction, it should be nullptr. This may not be true in the
|
2007-03-22 10:30:00 -07:00
|
|
|
// future when we allow users to execute a transaction when beginning
|
|
|
|
// a batch!!!!
|
|
|
|
|
2012-03-02 12:08:40 -08:00
|
|
|
nsRefPtr<nsTransactionItem> tx = mDoStack.Peek();
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2012-06-19 06:23:36 -07:00
|
|
|
if (tx) {
|
|
|
|
ti = tx->GetTransaction();
|
|
|
|
}
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
if (!tx || ti) {
|
|
|
|
return NS_ERROR_FAILURE;
|
|
|
|
}
|
|
|
|
|
2011-09-28 23:19:26 -07:00
|
|
|
bool doInterrupt = false;
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
result = WillEndBatchNotify(&doInterrupt);
|
|
|
|
|
|
|
|
if (NS_FAILED(result)) {
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (doInterrupt) {
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2013-01-03 22:54:26 -08:00
|
|
|
result = EndTransaction(aAllowEmpty);
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
nsresult result2 = DidEndBatchNotify(result);
|
|
|
|
|
|
|
|
if (NS_SUCCEEDED(result))
|
|
|
|
result = result2;
|
|
|
|
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
2012-08-22 08:56:38 -07:00
|
|
|
nsTransactionManager::GetNumberOfUndoItems(int32_t *aNumItems)
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
2012-03-02 12:08:40 -08:00
|
|
|
*aNumItems = mUndoStack.GetSize();
|
|
|
|
return NS_OK;
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
2012-08-22 08:56:38 -07:00
|
|
|
nsTransactionManager::GetNumberOfRedoItems(int32_t *aNumItems)
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
2012-03-02 12:08:40 -08:00
|
|
|
*aNumItems = mRedoStack.GetSize();
|
|
|
|
return NS_OK;
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
2012-08-22 08:56:38 -07:00
|
|
|
nsTransactionManager::GetMaxTransactionCount(int32_t *aMaxCount)
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
2010-06-17 13:40:48 -07:00
|
|
|
NS_ENSURE_TRUE(aMaxCount, NS_ERROR_NULL_POINTER);
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
*aMaxCount = mMaxTransactionCount;
|
|
|
|
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
2012-08-22 08:56:38 -07:00
|
|
|
nsTransactionManager::SetMaxTransactionCount(int32_t aMaxCount)
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
2012-08-22 08:56:38 -07:00
|
|
|
int32_t numUndoItems = 0, numRedoItems = 0, total = 0;
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
// It is illegal to call SetMaxTransactionCount() while the transaction
|
|
|
|
// manager is executing a transaction's DoTransaction() method because
|
|
|
|
// the undo and redo stacks might get pruned! If this happens, the
|
|
|
|
// SetMaxTransactionCount() request is ignored, and we return
|
|
|
|
// NS_ERROR_FAILURE.
|
|
|
|
|
2012-03-02 12:08:40 -08:00
|
|
|
nsRefPtr<nsTransactionItem> tx = mDoStack.Peek();
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
if (tx) {
|
|
|
|
return NS_ERROR_FAILURE;
|
|
|
|
}
|
|
|
|
|
|
|
|
// If aMaxCount is less than zero, the user wants unlimited
|
|
|
|
// levels of undo! No need to prune the undo or redo stacks!
|
|
|
|
|
|
|
|
if (aMaxCount < 0) {
|
|
|
|
mMaxTransactionCount = -1;
|
2012-03-02 12:08:40 -08:00
|
|
|
return NS_OK;
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
2012-03-02 12:08:40 -08:00
|
|
|
numUndoItems = mUndoStack.GetSize();
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2012-03-02 12:08:40 -08:00
|
|
|
numRedoItems = mRedoStack.GetSize();
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
total = numUndoItems + numRedoItems;
|
|
|
|
|
|
|
|
// If aMaxCount is greater than the number of transactions that currently
|
|
|
|
// exist on the undo and redo stack, there is no need to prune the
|
|
|
|
// undo or redo stacks!
|
|
|
|
|
|
|
|
if (aMaxCount > total ) {
|
|
|
|
mMaxTransactionCount = aMaxCount;
|
2012-03-02 12:08:40 -08:00
|
|
|
return NS_OK;
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
// Try getting rid of some transactions on the undo stack! Start at
|
|
|
|
// the bottom of the stack and pop towards the top.
|
|
|
|
|
|
|
|
while (numUndoItems > 0 && (numRedoItems + numUndoItems) > aMaxCount) {
|
2012-03-02 12:08:40 -08:00
|
|
|
tx = mUndoStack.PopBottom();
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2012-03-02 12:08:40 -08:00
|
|
|
if (!tx) {
|
|
|
|
return NS_ERROR_FAILURE;
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
--numUndoItems;
|
|
|
|
}
|
|
|
|
|
|
|
|
// If necessary, get rid of some transactions on the redo stack! Start at
|
|
|
|
// the bottom of the stack and pop towards the top.
|
|
|
|
|
|
|
|
while (numRedoItems > 0 && (numRedoItems + numUndoItems) > aMaxCount) {
|
2012-03-02 12:08:40 -08:00
|
|
|
tx = mRedoStack.PopBottom();
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2012-03-02 12:08:40 -08:00
|
|
|
if (!tx) {
|
|
|
|
return NS_ERROR_FAILURE;
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
--numRedoItems;
|
|
|
|
}
|
|
|
|
|
|
|
|
mMaxTransactionCount = aMaxCount;
|
|
|
|
|
2012-03-02 12:08:40 -08:00
|
|
|
return NS_OK;
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
nsTransactionManager::PeekUndoStack(nsITransaction **aTransaction)
|
|
|
|
{
|
2012-06-19 06:23:36 -07:00
|
|
|
MOZ_ASSERT(aTransaction);
|
2014-03-15 12:00:15 -07:00
|
|
|
*aTransaction = PeekUndoStack().take();
|
2012-06-19 06:23:36 -07:00
|
|
|
return NS_OK;
|
|
|
|
}
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2012-06-19 06:23:36 -07:00
|
|
|
already_AddRefed<nsITransaction>
|
|
|
|
nsTransactionManager::PeekUndoStack()
|
|
|
|
{
|
2012-03-02 12:08:40 -08:00
|
|
|
nsRefPtr<nsTransactionItem> tx = mUndoStack.Peek();
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2012-03-02 12:08:40 -08:00
|
|
|
if (!tx) {
|
2012-07-30 07:20:58 -07:00
|
|
|
return nullptr;
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
2012-06-19 06:23:36 -07:00
|
|
|
return tx->GetTransaction();
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
2012-06-19 06:23:36 -07:00
|
|
|
nsTransactionManager::PeekRedoStack(nsITransaction** aTransaction)
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
2012-06-19 06:23:36 -07:00
|
|
|
MOZ_ASSERT(aTransaction);
|
2014-03-15 12:00:15 -07:00
|
|
|
*aTransaction = PeekRedoStack().take();
|
2012-06-19 06:23:36 -07:00
|
|
|
return NS_OK;
|
|
|
|
}
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2012-06-19 06:23:36 -07:00
|
|
|
already_AddRefed<nsITransaction>
|
|
|
|
nsTransactionManager::PeekRedoStack()
|
|
|
|
{
|
2012-03-02 12:08:40 -08:00
|
|
|
nsRefPtr<nsTransactionItem> tx = mRedoStack.Peek();
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2012-03-02 12:08:40 -08:00
|
|
|
if (!tx) {
|
2012-07-30 07:20:58 -07:00
|
|
|
return nullptr;
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
2012-06-19 06:23:36 -07:00
|
|
|
return tx->GetTransaction();
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
nsTransactionManager::GetUndoList(nsITransactionList **aTransactionList)
|
|
|
|
{
|
2010-06-17 13:40:48 -07:00
|
|
|
NS_ENSURE_TRUE(aTransactionList, NS_ERROR_NULL_POINTER);
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
*aTransactionList = (nsITransactionList *)new nsTransactionList(this, &mUndoStack);
|
|
|
|
|
|
|
|
NS_IF_ADDREF(*aTransactionList);
|
|
|
|
|
|
|
|
return (! *aTransactionList) ? NS_ERROR_OUT_OF_MEMORY : NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
nsTransactionManager::GetRedoList(nsITransactionList **aTransactionList)
|
|
|
|
{
|
2010-06-17 13:40:48 -07:00
|
|
|
NS_ENSURE_TRUE(aTransactionList, NS_ERROR_NULL_POINTER);
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
*aTransactionList = (nsITransactionList *)new nsTransactionList(this, &mRedoStack);
|
|
|
|
|
|
|
|
NS_IF_ADDREF(*aTransactionList);
|
|
|
|
|
|
|
|
return (! *aTransactionList) ? NS_ERROR_OUT_OF_MEMORY : NS_OK;
|
|
|
|
}
|
|
|
|
|
2013-01-03 22:54:26 -08:00
|
|
|
nsresult
|
|
|
|
nsTransactionManager::BatchTopUndo()
|
|
|
|
{
|
|
|
|
if (mUndoStack.GetSize() < 2) {
|
|
|
|
// Not enough transactions to merge into one batch.
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
nsRefPtr<nsTransactionItem> lastUndo;
|
|
|
|
nsRefPtr<nsTransactionItem> previousUndo;
|
|
|
|
|
|
|
|
lastUndo = mUndoStack.Pop();
|
|
|
|
MOZ_ASSERT(lastUndo, "There should be at least two transactions.");
|
|
|
|
|
|
|
|
previousUndo = mUndoStack.Peek();
|
|
|
|
MOZ_ASSERT(previousUndo, "There should be at least two transactions.");
|
|
|
|
|
|
|
|
nsresult result = previousUndo->AddChild(lastUndo);
|
|
|
|
|
|
|
|
// Transfer data from the transactions that is going to be
|
|
|
|
// merged to the transaction that it is being merged with.
|
|
|
|
nsCOMArray<nsISupports>& lastData = lastUndo->GetData();
|
|
|
|
nsCOMArray<nsISupports>& previousData = previousUndo->GetData();
|
|
|
|
NS_ENSURE_TRUE(previousData.AppendObjects(lastData), NS_ERROR_UNEXPECTED);
|
|
|
|
lastData.Clear();
|
|
|
|
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
|
|
|
nsresult
|
|
|
|
nsTransactionManager::RemoveTopUndo()
|
|
|
|
{
|
|
|
|
nsRefPtr<nsTransactionItem> lastUndo;
|
|
|
|
|
|
|
|
lastUndo = mUndoStack.Peek();
|
|
|
|
if (!lastUndo) {
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
lastUndo = mUndoStack.Pop();
|
|
|
|
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
NS_IMETHODIMP
|
|
|
|
nsTransactionManager::AddListener(nsITransactionListener *aListener)
|
|
|
|
{
|
2010-06-17 13:40:48 -07:00
|
|
|
NS_ENSURE_TRUE(aListener, NS_ERROR_NULL_POINTER);
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2012-01-01 14:35:11 -08:00
|
|
|
return mListeners.AppendObject(aListener) ? NS_OK : NS_ERROR_FAILURE;
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
nsTransactionManager::RemoveListener(nsITransactionListener *aListener)
|
|
|
|
{
|
2010-06-17 13:40:48 -07:00
|
|
|
NS_ENSURE_TRUE(aListener, NS_ERROR_NULL_POINTER);
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2012-01-01 14:35:11 -08:00
|
|
|
return mListeners.RemoveObject(aListener) ? NS_OK : NS_ERROR_FAILURE;
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
2013-01-03 22:54:26 -08:00
|
|
|
NS_IMETHODIMP
|
2007-03-22 10:30:00 -07:00
|
|
|
nsTransactionManager::ClearUndoStack()
|
|
|
|
{
|
2012-03-02 12:08:40 -08:00
|
|
|
mUndoStack.Clear();
|
|
|
|
return NS_OK;
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
2013-01-03 22:54:26 -08:00
|
|
|
NS_IMETHODIMP
|
2007-03-22 10:30:00 -07:00
|
|
|
nsTransactionManager::ClearRedoStack()
|
|
|
|
{
|
2012-03-02 12:08:40 -08:00
|
|
|
mRedoStack.Clear();
|
|
|
|
return NS_OK;
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
nsresult
|
2011-09-28 23:19:26 -07:00
|
|
|
nsTransactionManager::WillDoNotify(nsITransaction *aTransaction, bool *aInterrupt)
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
|
|
|
nsresult result = NS_OK;
|
2012-08-22 08:56:38 -07:00
|
|
|
for (int32_t i = 0, lcount = mListeners.Count(); i < lcount; i++)
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
2009-04-24 15:45:34 -07:00
|
|
|
nsITransactionListener *listener = mListeners[i];
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2010-06-17 13:40:48 -07:00
|
|
|
NS_ENSURE_TRUE(listener, NS_ERROR_FAILURE);
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
result = listener->WillDo(this, aTransaction, aInterrupt);
|
|
|
|
|
|
|
|
if (NS_FAILED(result) || *aInterrupt)
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
|
|
|
nsresult
|
|
|
|
nsTransactionManager::DidDoNotify(nsITransaction *aTransaction, nsresult aDoResult)
|
|
|
|
{
|
|
|
|
nsresult result = NS_OK;
|
2012-08-22 08:56:38 -07:00
|
|
|
for (int32_t i = 0, lcount = mListeners.Count(); i < lcount; i++)
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
2009-04-24 15:45:34 -07:00
|
|
|
nsITransactionListener *listener = mListeners[i];
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2010-06-17 13:40:48 -07:00
|
|
|
NS_ENSURE_TRUE(listener, NS_ERROR_FAILURE);
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
result = listener->DidDo(this, aTransaction, aDoResult);
|
|
|
|
|
|
|
|
if (NS_FAILED(result))
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
|
|
|
nsresult
|
2011-09-28 23:19:26 -07:00
|
|
|
nsTransactionManager::WillUndoNotify(nsITransaction *aTransaction, bool *aInterrupt)
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
|
|
|
nsresult result = NS_OK;
|
2012-08-22 08:56:38 -07:00
|
|
|
for (int32_t i = 0, lcount = mListeners.Count(); i < lcount; i++)
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
2009-04-24 15:45:34 -07:00
|
|
|
nsITransactionListener *listener = mListeners[i];
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2010-06-17 13:40:48 -07:00
|
|
|
NS_ENSURE_TRUE(listener, NS_ERROR_FAILURE);
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
result = listener->WillUndo(this, aTransaction, aInterrupt);
|
|
|
|
|
|
|
|
if (NS_FAILED(result) || *aInterrupt)
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
|
|
|
nsresult
|
|
|
|
nsTransactionManager::DidUndoNotify(nsITransaction *aTransaction, nsresult aUndoResult)
|
|
|
|
{
|
|
|
|
nsresult result = NS_OK;
|
2012-08-22 08:56:38 -07:00
|
|
|
for (int32_t i = 0, lcount = mListeners.Count(); i < lcount; i++)
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
2009-04-24 15:45:34 -07:00
|
|
|
nsITransactionListener *listener = mListeners[i];
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2010-06-17 13:40:48 -07:00
|
|
|
NS_ENSURE_TRUE(listener, NS_ERROR_FAILURE);
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
result = listener->DidUndo(this, aTransaction, aUndoResult);
|
|
|
|
|
|
|
|
if (NS_FAILED(result))
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
|
|
|
nsresult
|
2011-09-28 23:19:26 -07:00
|
|
|
nsTransactionManager::WillRedoNotify(nsITransaction *aTransaction, bool *aInterrupt)
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
|
|
|
nsresult result = NS_OK;
|
2012-08-22 08:56:38 -07:00
|
|
|
for (int32_t i = 0, lcount = mListeners.Count(); i < lcount; i++)
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
2009-04-24 15:45:34 -07:00
|
|
|
nsITransactionListener *listener = mListeners[i];
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2010-06-17 13:40:48 -07:00
|
|
|
NS_ENSURE_TRUE(listener, NS_ERROR_FAILURE);
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
result = listener->WillRedo(this, aTransaction, aInterrupt);
|
|
|
|
|
|
|
|
if (NS_FAILED(result) || *aInterrupt)
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
|
|
|
nsresult
|
|
|
|
nsTransactionManager::DidRedoNotify(nsITransaction *aTransaction, nsresult aRedoResult)
|
|
|
|
{
|
|
|
|
nsresult result = NS_OK;
|
2012-08-22 08:56:38 -07:00
|
|
|
for (int32_t i = 0, lcount = mListeners.Count(); i < lcount; i++)
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
2009-04-24 15:45:34 -07:00
|
|
|
nsITransactionListener *listener = mListeners[i];
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2010-06-17 13:40:48 -07:00
|
|
|
NS_ENSURE_TRUE(listener, NS_ERROR_FAILURE);
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
result = listener->DidRedo(this, aTransaction, aRedoResult);
|
|
|
|
|
|
|
|
if (NS_FAILED(result))
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
|
|
|
nsresult
|
2011-09-28 23:19:26 -07:00
|
|
|
nsTransactionManager::WillBeginBatchNotify(bool *aInterrupt)
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
|
|
|
nsresult result = NS_OK;
|
2012-08-22 08:56:38 -07:00
|
|
|
for (int32_t i = 0, lcount = mListeners.Count(); i < lcount; i++)
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
2009-04-24 15:45:34 -07:00
|
|
|
nsITransactionListener *listener = mListeners[i];
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2010-06-17 13:40:48 -07:00
|
|
|
NS_ENSURE_TRUE(listener, NS_ERROR_FAILURE);
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
result = listener->WillBeginBatch(this, aInterrupt);
|
|
|
|
|
|
|
|
if (NS_FAILED(result) || *aInterrupt)
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
|
|
|
nsresult
|
|
|
|
nsTransactionManager::DidBeginBatchNotify(nsresult aResult)
|
|
|
|
{
|
|
|
|
nsresult result = NS_OK;
|
2012-08-22 08:56:38 -07:00
|
|
|
for (int32_t i = 0, lcount = mListeners.Count(); i < lcount; i++)
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
2009-04-24 15:45:34 -07:00
|
|
|
nsITransactionListener *listener = mListeners[i];
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2010-06-17 13:40:48 -07:00
|
|
|
NS_ENSURE_TRUE(listener, NS_ERROR_FAILURE);
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
result = listener->DidBeginBatch(this, aResult);
|
|
|
|
|
|
|
|
if (NS_FAILED(result))
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
|
|
|
nsresult
|
2011-09-28 23:19:26 -07:00
|
|
|
nsTransactionManager::WillEndBatchNotify(bool *aInterrupt)
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
|
|
|
nsresult result = NS_OK;
|
2012-08-22 08:56:38 -07:00
|
|
|
for (int32_t i = 0, lcount = mListeners.Count(); i < lcount; i++)
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
2009-04-24 15:45:34 -07:00
|
|
|
nsITransactionListener *listener = mListeners[i];
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2010-06-17 13:40:48 -07:00
|
|
|
NS_ENSURE_TRUE(listener, NS_ERROR_FAILURE);
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
result = listener->WillEndBatch(this, aInterrupt);
|
|
|
|
|
|
|
|
if (NS_FAILED(result) || *aInterrupt)
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
|
|
|
nsresult
|
|
|
|
nsTransactionManager::DidEndBatchNotify(nsresult aResult)
|
|
|
|
{
|
|
|
|
nsresult result = NS_OK;
|
2012-08-22 08:56:38 -07:00
|
|
|
for (int32_t i = 0, lcount = mListeners.Count(); i < lcount; i++)
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
2009-04-24 15:45:34 -07:00
|
|
|
nsITransactionListener *listener = mListeners[i];
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2010-06-17 13:40:48 -07:00
|
|
|
NS_ENSURE_TRUE(listener, NS_ERROR_FAILURE);
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
result = listener->DidEndBatch(this, aResult);
|
|
|
|
|
|
|
|
if (NS_FAILED(result))
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
|
|
|
nsresult
|
2011-09-28 23:19:26 -07:00
|
|
|
nsTransactionManager::WillMergeNotify(nsITransaction *aTop, nsITransaction *aTransaction, bool *aInterrupt)
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
|
|
|
nsresult result = NS_OK;
|
2012-08-22 08:56:38 -07:00
|
|
|
for (int32_t i = 0, lcount = mListeners.Count(); i < lcount; i++)
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
2009-04-24 15:45:34 -07:00
|
|
|
nsITransactionListener *listener = mListeners[i];
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2010-06-17 13:40:48 -07:00
|
|
|
NS_ENSURE_TRUE(listener, NS_ERROR_FAILURE);
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
result = listener->WillMerge(this, aTop, aTransaction, aInterrupt);
|
|
|
|
|
|
|
|
if (NS_FAILED(result) || *aInterrupt)
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
|
|
|
nsresult
|
|
|
|
nsTransactionManager::DidMergeNotify(nsITransaction *aTop,
|
|
|
|
nsITransaction *aTransaction,
|
2011-09-28 23:19:26 -07:00
|
|
|
bool aDidMerge,
|
2007-03-22 10:30:00 -07:00
|
|
|
nsresult aMergeResult)
|
|
|
|
{
|
|
|
|
nsresult result = NS_OK;
|
2012-08-22 08:56:38 -07:00
|
|
|
for (int32_t i = 0, lcount = mListeners.Count(); i < lcount; i++)
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
2009-04-24 15:45:34 -07:00
|
|
|
nsITransactionListener *listener = mListeners[i];
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2010-06-17 13:40:48 -07:00
|
|
|
NS_ENSURE_TRUE(listener, NS_ERROR_FAILURE);
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
result = listener->DidMerge(this, aTop, aTransaction, aDidMerge, aMergeResult);
|
|
|
|
|
|
|
|
if (NS_FAILED(result))
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
|
|
|
nsresult
|
2013-01-03 22:54:26 -08:00
|
|
|
nsTransactionManager::BeginTransaction(nsITransaction *aTransaction,
|
|
|
|
nsISupports *aData)
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
|
|
|
nsresult result = NS_OK;
|
|
|
|
|
|
|
|
// XXX: POSSIBLE OPTIMIZATION
|
|
|
|
// We could use a factory that pre-allocates/recycles transaction items.
|
2008-12-10 08:46:36 -08:00
|
|
|
nsRefPtr<nsTransactionItem> tx = new nsTransactionItem(aTransaction);
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2013-01-03 22:54:26 -08:00
|
|
|
if (aData) {
|
|
|
|
nsCOMArray<nsISupports>& data = tx->GetData();
|
|
|
|
data.AppendObject(aData);
|
|
|
|
}
|
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
if (!tx) {
|
|
|
|
return NS_ERROR_OUT_OF_MEMORY;
|
|
|
|
}
|
|
|
|
|
2012-03-02 12:08:40 -08:00
|
|
|
mDoStack.Push(tx);
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
result = tx->DoTransaction();
|
|
|
|
|
|
|
|
if (NS_FAILED(result)) {
|
2012-03-02 12:08:40 -08:00
|
|
|
tx = mDoStack.Pop();
|
2007-03-22 10:30:00 -07:00
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
nsresult
|
2013-01-03 22:54:26 -08:00
|
|
|
nsTransactionManager::EndTransaction(bool aAllowEmpty)
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
|
|
|
nsresult result = NS_OK;
|
|
|
|
|
2012-03-02 12:08:40 -08:00
|
|
|
nsRefPtr<nsTransactionItem> tx = mDoStack.Pop();
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2012-03-02 12:08:40 -08:00
|
|
|
if (!tx)
|
|
|
|
return NS_ERROR_FAILURE;
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2012-06-19 06:23:36 -07:00
|
|
|
nsCOMPtr<nsITransaction> tint = tx->GetTransaction();
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2013-01-03 22:54:26 -08:00
|
|
|
if (!tint && !aAllowEmpty) {
|
2012-08-22 08:56:38 -07:00
|
|
|
int32_t nc = 0;
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
// If we get here, the transaction must be a dummy batch transaction
|
|
|
|
// created by BeginBatch(). If it contains no children, get rid of it!
|
|
|
|
|
|
|
|
tx->GetNumberOfChildren(&nc);
|
|
|
|
|
|
|
|
if (!nc) {
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// Check if the transaction is transient. If it is, there's nothing
|
|
|
|
// more to do, just return.
|
|
|
|
|
2011-09-28 23:19:26 -07:00
|
|
|
bool isTransient = false;
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
if (tint)
|
|
|
|
result = tint->GetIsTransient(&isTransient);
|
|
|
|
|
|
|
|
if (NS_FAILED(result) || isTransient || !mMaxTransactionCount) {
|
|
|
|
// XXX: Should we be clearing the redo stack if the transaction
|
|
|
|
// is transient and there is nothing on the do stack?
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Check if there is a transaction on the do stack. If there is,
|
|
|
|
// the current transaction is a "sub" transaction, and should
|
|
|
|
// be added to the transaction at the top of the do stack.
|
|
|
|
|
2012-03-02 12:08:40 -08:00
|
|
|
nsRefPtr<nsTransactionItem> top = mDoStack.Peek();
|
2007-03-22 10:30:00 -07:00
|
|
|
if (top) {
|
|
|
|
result = top->AddChild(tx);
|
|
|
|
|
|
|
|
// XXX: What do we do if this fails?
|
|
|
|
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
|
|
|
// The transaction succeeded, so clear the redo stack.
|
|
|
|
|
|
|
|
result = ClearRedoStack();
|
|
|
|
|
|
|
|
if (NS_FAILED(result)) {
|
|
|
|
// XXX: What do we do if this fails?
|
|
|
|
}
|
|
|
|
|
|
|
|
// Check if we can coalesce this transaction with the one at the top
|
|
|
|
// of the undo stack.
|
|
|
|
|
2012-03-02 12:08:40 -08:00
|
|
|
top = mUndoStack.Peek();
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
if (tint && top) {
|
2011-09-28 23:19:26 -07:00
|
|
|
bool didMerge = false;
|
2012-06-19 06:23:36 -07:00
|
|
|
nsCOMPtr<nsITransaction> topTransaction = top->GetTransaction();
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
if (topTransaction) {
|
|
|
|
|
2011-09-28 23:19:26 -07:00
|
|
|
bool doInterrupt = false;
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
result = WillMergeNotify(topTransaction, tint, &doInterrupt);
|
|
|
|
|
2010-06-17 13:44:35 -07:00
|
|
|
NS_ENSURE_SUCCESS(result, result);
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
if (!doInterrupt) {
|
|
|
|
result = topTransaction->Merge(tint, &didMerge);
|
|
|
|
|
|
|
|
nsresult result2 = DidMergeNotify(topTransaction, tint, didMerge, result);
|
|
|
|
|
|
|
|
if (NS_SUCCEEDED(result))
|
|
|
|
result = result2;
|
|
|
|
|
|
|
|
if (NS_FAILED(result)) {
|
|
|
|
// XXX: What do we do if this fails?
|
|
|
|
}
|
|
|
|
|
|
|
|
if (didMerge) {
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// Check to see if we've hit the max level of undo. If so,
|
|
|
|
// pop the bottom transaction off the undo stack and release it!
|
|
|
|
|
2012-08-22 08:56:38 -07:00
|
|
|
int32_t sz = mUndoStack.GetSize();
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
if (mMaxTransactionCount > 0 && sz >= mMaxTransactionCount) {
|
2012-03-02 12:08:40 -08:00
|
|
|
nsRefPtr<nsTransactionItem> overflow = mUndoStack.PopBottom();
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
// Push the transaction on the undo stack:
|
|
|
|
|
2012-03-02 12:08:40 -08:00
|
|
|
mUndoStack.Push(tx);
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2012-03-02 12:08:40 -08:00
|
|
|
return NS_OK;
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|