2001-09-25 22:53:13 +00:00
|
|
|
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
|
|
|
/* ***** BEGIN LICENSE BLOCK *****
|
2004-04-18 14:21:17 +00:00
|
|
|
* Version: MPL 1.1/GPL 2.0/LGPL 2.1
|
1999-08-19 13:19:10 +00:00
|
|
|
*
|
2004-04-18 14:21:17 +00:00
|
|
|
* The contents of this file are subject to the Mozilla Public License Version
|
|
|
|
* 1.1 (the "License"); you may not use this file except in compliance with
|
|
|
|
* the License. You may obtain a copy of the License at
|
|
|
|
* http://www.mozilla.org/MPL/
|
1999-08-19 13:19:10 +00:00
|
|
|
*
|
2001-09-25 22:53:13 +00:00
|
|
|
* Software distributed under the License is distributed on an "AS IS" basis,
|
|
|
|
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
|
|
|
|
* for the specific language governing rights and limitations under the
|
|
|
|
* License.
|
1999-08-19 13:19:10 +00:00
|
|
|
*
|
1999-11-06 03:43:54 +00:00
|
|
|
* The Original Code is mozilla.org code.
|
|
|
|
*
|
2004-04-18 14:21:17 +00:00
|
|
|
* The Initial Developer of the Original Code is
|
2001-09-25 22:53:13 +00:00
|
|
|
* Netscape Communications Corporation.
|
|
|
|
* Portions created by the Initial Developer are Copyright (C) 1998
|
|
|
|
* the Initial Developer. All Rights Reserved.
|
1999-11-06 03:43:54 +00:00
|
|
|
*
|
2001-09-25 22:53:13 +00:00
|
|
|
* Contributor(s):
|
2000-01-11 20:49:15 +00:00
|
|
|
* Pierre Phaneuf <pp@ludusdesign.com>
|
2001-09-25 22:53:13 +00:00
|
|
|
*
|
|
|
|
* Alternatively, the contents of this file may be used under the terms of
|
2004-04-18 14:21:17 +00:00
|
|
|
* either of the GNU General Public License Version 2 or later (the "GPL"),
|
|
|
|
* or the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
|
2001-09-25 22:53:13 +00:00
|
|
|
* in which case the provisions of the GPL or the LGPL are applicable instead
|
|
|
|
* of those above. If you wish to allow use of your version of this file only
|
|
|
|
* under the terms of either the GPL or the LGPL, and not to allow others to
|
2004-04-18 14:21:17 +00:00
|
|
|
* use your version of this file under the terms of the MPL, indicate your
|
2001-09-25 22:53:13 +00:00
|
|
|
* decision by deleting the provisions above and replace them with the notice
|
|
|
|
* and other provisions required by the GPL or the LGPL. If you do not delete
|
|
|
|
* the provisions above, a recipient may use your version of this file under
|
2004-04-18 14:21:17 +00:00
|
|
|
* the terms of any one of the MPL, the GPL or the LGPL.
|
2001-09-25 22:53:13 +00:00
|
|
|
*
|
|
|
|
* ***** END LICENSE BLOCK ***** */
|
1999-08-19 13:19:10 +00:00
|
|
|
|
|
|
|
#include <stdio.h>
|
|
|
|
#include "nsHTMLEditorLog.h"
|
|
|
|
#include "nsEditorTxnLog.h"
|
2001-03-09 14:23:59 +00:00
|
|
|
#include "nsPIEditorTransaction.h"
|
1999-08-19 13:19:10 +00:00
|
|
|
|
|
|
|
#define LOCK_LOG(doc)
|
|
|
|
#define UNLOCK_LOG(doc)
|
|
|
|
|
|
|
|
|
|
|
|
nsEditorTxnLog::nsEditorTxnLog(nsHTMLEditorLog *aEditorLog)
|
|
|
|
{
|
|
|
|
mRefCnt = 0;
|
|
|
|
mIndentLevel = 0;
|
|
|
|
mBatchCount = 0;
|
|
|
|
mEditorLog = aEditorLog;
|
|
|
|
}
|
|
|
|
|
|
|
|
nsEditorTxnLog::~nsEditorTxnLog()
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
// #define DEBUG_EDITOR_TXN_LOG_REFCNT 1
|
|
|
|
|
|
|
|
#ifdef DEBUG_EDITOR_TXN_LOG_REFCNT
|
|
|
|
|
|
|
|
nsrefcnt nsEditorTxnLog::AddRef(void)
|
|
|
|
{
|
|
|
|
return ++mRefCnt;
|
|
|
|
}
|
|
|
|
|
|
|
|
nsrefcnt nsEditorTxnLog::Release(void)
|
|
|
|
{
|
|
|
|
NS_PRECONDITION(0 != mRefCnt, "dup release");
|
|
|
|
if (--mRefCnt == 0) {
|
|
|
|
NS_DELETEXPCOM(this);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
return mRefCnt;
|
|
|
|
}
|
|
|
|
|
|
|
|
#else
|
|
|
|
|
|
|
|
NS_IMPL_ADDREF(nsEditorTxnLog)
|
|
|
|
NS_IMPL_RELEASE(nsEditorTxnLog)
|
|
|
|
|
|
|
|
#endif
|
|
|
|
|
2003-06-27 14:19:40 +00:00
|
|
|
NS_IMPL_QUERY_INTERFACE1(nsEditorTxnLog, nsITransactionListener)
|
1999-08-19 13:19:10 +00:00
|
|
|
|
|
|
|
NS_IMETHODIMP
|
1999-11-11 19:35:40 +00:00
|
|
|
nsEditorTxnLog::WillDo(nsITransactionManager *aTxMgr, nsITransaction *aTransaction, PRBool *aInterrupt)
|
1999-08-19 13:19:10 +00:00
|
|
|
{
|
|
|
|
LOCK_LOG(this);
|
|
|
|
|
|
|
|
PrintIndent(mIndentLevel++);
|
|
|
|
Write("WillDo: ");
|
2001-10-16 03:53:44 +00:00
|
|
|
WriteTransaction(aTransaction);
|
1999-08-19 13:19:10 +00:00
|
|
|
Write("\n");
|
|
|
|
Flush();
|
|
|
|
|
|
|
|
UNLOCK_LOG(this);
|
|
|
|
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
nsEditorTxnLog::DidDo(nsITransactionManager *aTxMgr, nsITransaction *aTransaction, nsresult aDoResult)
|
|
|
|
{
|
|
|
|
LOCK_LOG(this);
|
|
|
|
|
|
|
|
PrintIndent(--mIndentLevel);
|
|
|
|
Write("DidDo: ");
|
2001-10-16 03:53:44 +00:00
|
|
|
WriteTransaction(aTransaction);
|
1999-08-19 13:19:10 +00:00
|
|
|
Write("(");
|
2002-11-18 15:43:19 +00:00
|
|
|
WriteInt(aDoResult);
|
1999-08-19 13:19:10 +00:00
|
|
|
Write(")\n");
|
|
|
|
Flush();
|
|
|
|
|
|
|
|
UNLOCK_LOG(this);
|
|
|
|
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
1999-11-11 19:35:40 +00:00
|
|
|
nsEditorTxnLog::WillUndo(nsITransactionManager *aTxMgr, nsITransaction *aTransaction, PRBool *aInterrupt)
|
1999-08-19 13:19:10 +00:00
|
|
|
{
|
|
|
|
LOCK_LOG(this);
|
|
|
|
|
|
|
|
PrintIndent(mIndentLevel++);
|
|
|
|
|
|
|
|
if (aTransaction)
|
|
|
|
{
|
|
|
|
Write("WillUndo: ");
|
2001-10-16 03:53:44 +00:00
|
|
|
WriteTransaction(aTransaction);
|
1999-08-19 13:19:10 +00:00
|
|
|
Write("\n");
|
|
|
|
}
|
|
|
|
else
|
|
|
|
Write("WillUndoBatch\n");
|
|
|
|
|
|
|
|
Flush();
|
|
|
|
|
|
|
|
UNLOCK_LOG(this);
|
|
|
|
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
nsEditorTxnLog::DidUndo(nsITransactionManager *aTxMgr, nsITransaction *aTransaction, nsresult aUndoResult)
|
|
|
|
{
|
|
|
|
LOCK_LOG(this);
|
|
|
|
|
|
|
|
PrintIndent(--mIndentLevel);
|
|
|
|
|
|
|
|
if (aTransaction)
|
|
|
|
{
|
|
|
|
Write("DidUndo: ");
|
2001-10-16 03:53:44 +00:00
|
|
|
WriteTransaction(aTransaction);
|
1999-08-19 13:19:10 +00:00
|
|
|
Write("(");
|
2002-11-18 15:43:19 +00:00
|
|
|
WriteInt(aUndoResult);
|
1999-08-19 13:19:10 +00:00
|
|
|
Write(")\n");
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
Write("EndUndoBatch (");
|
2002-11-18 15:43:19 +00:00
|
|
|
WriteInt(aUndoResult);
|
1999-08-19 13:19:10 +00:00
|
|
|
Write(")\n");
|
|
|
|
}
|
|
|
|
|
|
|
|
Flush();
|
|
|
|
|
|
|
|
UNLOCK_LOG(this);
|
|
|
|
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
1999-11-11 19:35:40 +00:00
|
|
|
nsEditorTxnLog::WillRedo(nsITransactionManager *aTxMgr, nsITransaction *aTransaction, PRBool *aInterrupt)
|
1999-08-19 13:19:10 +00:00
|
|
|
{
|
|
|
|
LOCK_LOG(this);
|
|
|
|
|
|
|
|
PrintIndent(mIndentLevel++);
|
|
|
|
|
|
|
|
if (aTransaction)
|
|
|
|
{
|
|
|
|
Write("WillRedo: ");
|
2001-10-16 03:53:44 +00:00
|
|
|
WriteTransaction(aTransaction);
|
1999-08-19 13:19:10 +00:00
|
|
|
Write("\n");
|
|
|
|
}
|
|
|
|
else
|
|
|
|
Write("WillRedoBatch\n");
|
|
|
|
|
|
|
|
Flush();
|
|
|
|
|
|
|
|
UNLOCK_LOG(this);
|
|
|
|
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
nsEditorTxnLog::DidRedo(nsITransactionManager *aTxMgr, nsITransaction *aTransaction, nsresult aRedoResult)
|
|
|
|
{
|
|
|
|
LOCK_LOG(this);
|
|
|
|
|
|
|
|
PrintIndent(--mIndentLevel);
|
|
|
|
|
|
|
|
if (aTransaction)
|
|
|
|
{
|
|
|
|
Write("DidRedo: ");
|
2001-10-16 03:53:44 +00:00
|
|
|
WriteTransaction(aTransaction);
|
1999-08-19 13:19:10 +00:00
|
|
|
Write(" (");
|
2002-11-18 15:43:19 +00:00
|
|
|
WriteInt(aRedoResult);
|
1999-08-19 13:19:10 +00:00
|
|
|
Write(")\n");
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
Write("DidRedoBatch (");
|
2002-11-18 15:43:19 +00:00
|
|
|
WriteInt(aRedoResult);
|
1999-08-19 13:19:10 +00:00
|
|
|
Write(")\n");
|
|
|
|
}
|
|
|
|
|
|
|
|
Flush();
|
|
|
|
|
|
|
|
UNLOCK_LOG(this);
|
|
|
|
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
1999-11-11 19:35:40 +00:00
|
|
|
nsEditorTxnLog::WillBeginBatch(nsITransactionManager *aTxMgr, PRBool *aInterrupt)
|
1999-08-19 13:19:10 +00:00
|
|
|
{
|
|
|
|
LOCK_LOG(this);
|
|
|
|
|
|
|
|
PrintIndent(mIndentLevel);
|
|
|
|
Write("WillBeginBatch: ");
|
2002-11-18 15:43:19 +00:00
|
|
|
WriteInt(mBatchCount);
|
1999-08-19 13:19:10 +00:00
|
|
|
Write("\n");
|
|
|
|
Flush();
|
|
|
|
|
|
|
|
UNLOCK_LOG(this);
|
|
|
|
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
nsEditorTxnLog::DidBeginBatch(nsITransactionManager *aTxMgr, nsresult aResult)
|
|
|
|
{
|
|
|
|
LOCK_LOG(this);
|
|
|
|
|
|
|
|
PrintIndent(mIndentLevel++);
|
|
|
|
Write("DidBeginBatch: ");
|
2002-11-18 15:43:19 +00:00
|
|
|
WriteInt(mBatchCount++);
|
1999-08-19 13:19:10 +00:00
|
|
|
Write(" (");
|
2002-11-18 15:43:19 +00:00
|
|
|
WriteInt(aResult);
|
1999-08-19 13:19:10 +00:00
|
|
|
Write(")\n");
|
|
|
|
Flush();
|
|
|
|
|
|
|
|
UNLOCK_LOG(this);
|
|
|
|
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
1999-11-11 19:35:40 +00:00
|
|
|
nsEditorTxnLog::WillEndBatch(nsITransactionManager *aTxMgr, PRBool *aInterrupt)
|
1999-08-19 13:19:10 +00:00
|
|
|
{
|
|
|
|
LOCK_LOG(this);
|
|
|
|
|
|
|
|
PrintIndent(--mIndentLevel);
|
|
|
|
Write("WillEndBatch: ");
|
2002-11-18 15:43:19 +00:00
|
|
|
WriteInt(--mBatchCount);
|
1999-08-19 13:19:10 +00:00
|
|
|
Write("\n");
|
|
|
|
Flush();
|
|
|
|
|
|
|
|
UNLOCK_LOG(this);
|
|
|
|
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
nsEditorTxnLog::DidEndBatch(nsITransactionManager *aTxMgr, nsresult aResult)
|
|
|
|
{
|
|
|
|
LOCK_LOG(this);
|
|
|
|
|
|
|
|
PrintIndent(mIndentLevel);
|
|
|
|
Write("DidEndBatch: ");
|
2002-11-18 15:43:19 +00:00
|
|
|
WriteInt(mBatchCount);
|
1999-08-19 13:19:10 +00:00
|
|
|
Write(" (");
|
2002-11-18 15:43:19 +00:00
|
|
|
WriteInt(aResult);
|
1999-08-19 13:19:10 +00:00
|
|
|
Write(")\n");
|
|
|
|
Flush();
|
|
|
|
|
|
|
|
UNLOCK_LOG(this);
|
|
|
|
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
1999-11-11 19:35:40 +00:00
|
|
|
nsEditorTxnLog::WillMerge(nsITransactionManager *aTxMgr, nsITransaction *aTopTransaction, nsITransaction *aTransaction, PRBool *aInterrupt)
|
1999-08-19 13:19:10 +00:00
|
|
|
{
|
|
|
|
LOCK_LOG(this);
|
|
|
|
|
|
|
|
PrintIndent(mIndentLevel);
|
|
|
|
Write("WillMerge: ");
|
2001-10-16 03:53:44 +00:00
|
|
|
WriteTransaction(aTopTransaction);
|
1999-08-19 13:19:10 +00:00
|
|
|
Write(" <-- ");
|
2001-10-16 03:53:44 +00:00
|
|
|
WriteTransaction(aTransaction);
|
1999-08-19 13:19:10 +00:00
|
|
|
Write("\n");
|
|
|
|
Flush();
|
|
|
|
|
|
|
|
UNLOCK_LOG(this);
|
|
|
|
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
nsEditorTxnLog::DidMerge(nsITransactionManager *aTxMgr, nsITransaction *aTopTransaction, nsITransaction *aTransaction, PRBool aDidMerge, nsresult aMergeResult)
|
|
|
|
{
|
|
|
|
LOCK_LOG(this);
|
|
|
|
|
|
|
|
PrintIndent(mIndentLevel);
|
|
|
|
Write("DidMerge: ");
|
2001-10-16 03:53:44 +00:00
|
|
|
WriteTransaction(aTopTransaction);
|
1999-08-19 13:19:10 +00:00
|
|
|
Write(" <-- ");
|
2001-10-16 03:53:44 +00:00
|
|
|
WriteTransaction(aTransaction);
|
1999-08-19 13:19:10 +00:00
|
|
|
Write(" (");
|
|
|
|
Write(aDidMerge ? "TRUE" : "FALSE");
|
|
|
|
Write(", ");
|
2002-11-18 15:43:19 +00:00
|
|
|
WriteInt(aMergeResult);
|
1999-08-19 13:19:10 +00:00
|
|
|
Write(")\n");
|
|
|
|
Flush();
|
|
|
|
|
|
|
|
UNLOCK_LOG(this);
|
|
|
|
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2001-10-16 03:53:44 +00:00
|
|
|
nsresult
|
|
|
|
nsEditorTxnLog::WriteTransaction(nsITransaction *aTransaction)
|
1999-08-19 13:19:10 +00:00
|
|
|
{
|
2000-04-18 07:44:58 +00:00
|
|
|
nsString str;
|
1999-08-19 13:19:10 +00:00
|
|
|
|
2001-03-09 14:23:59 +00:00
|
|
|
nsCOMPtr<nsPIEditorTransaction> txn = do_QueryInterface(aTransaction);
|
2001-10-16 03:53:44 +00:00
|
|
|
if (txn) {
|
|
|
|
txn->GetTxnDescription(str);
|
|
|
|
if (str.IsEmpty())
|
2004-06-17 00:13:25 +00:00
|
|
|
str.AssignLiteral("<NULL>");
|
2001-10-16 03:53:44 +00:00
|
|
|
}
|
2001-03-09 14:23:59 +00:00
|
|
|
|
2006-02-03 14:18:39 +00:00
|
|
|
return Write(NS_LossyConvertUTF16toASCII(str).get());
|
1999-08-19 13:19:10 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
nsresult
|
|
|
|
nsEditorTxnLog::PrintIndent(PRInt32 aIndentLevel)
|
|
|
|
{
|
|
|
|
PRInt32 i;
|
|
|
|
|
|
|
|
Write(" // ");
|
|
|
|
|
|
|
|
for (i = 0; i < aIndentLevel; i++)
|
|
|
|
Write(" ");
|
|
|
|
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
nsresult
|
|
|
|
nsEditorTxnLog::Write(const char *aBuffer)
|
|
|
|
{
|
|
|
|
if (!aBuffer)
|
|
|
|
return NS_ERROR_NULL_POINTER;
|
|
|
|
|
|
|
|
if (mEditorLog)
|
|
|
|
mEditorLog->Write(aBuffer);
|
|
|
|
else
|
2002-11-18 15:43:19 +00:00
|
|
|
{
|
|
|
|
PRInt32 len = strlen(aBuffer);
|
|
|
|
if (len > 0)
|
|
|
|
fwrite(aBuffer, 1, len, stdout);
|
|
|
|
}
|
1999-08-19 13:19:10 +00:00
|
|
|
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
nsresult
|
2002-11-18 15:43:19 +00:00
|
|
|
nsEditorTxnLog::WriteInt(PRInt32 aInt)
|
1999-08-19 13:19:10 +00:00
|
|
|
{
|
|
|
|
if (mEditorLog)
|
2002-11-18 15:43:19 +00:00
|
|
|
mEditorLog->WriteInt(aInt);
|
1999-08-19 13:19:10 +00:00
|
|
|
else
|
2002-11-18 15:43:19 +00:00
|
|
|
printf("%d", aInt);
|
1999-08-19 13:19:10 +00:00
|
|
|
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
nsresult
|
|
|
|
nsEditorTxnLog::Flush()
|
|
|
|
{
|
|
|
|
nsresult result = NS_OK;
|
|
|
|
|
|
|
|
#ifdef SLOWS_THINGS_WAY_DOWN
|
|
|
|
|
|
|
|
if (mEditorLog)
|
|
|
|
result = mEditorLog->Flush();
|
|
|
|
else
|
|
|
|
fflush(stdout);
|
|
|
|
|
|
|
|
#endif // SLOWS_THINGS_WAY_DOWN
|
|
|
|
|
|
|
|
return result;
|
|
|
|
}
|