2001-09-26 02:53:13 +04:00
|
|
|
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
|
|
|
/* ***** BEGIN LICENSE BLOCK *****
|
2004-04-18 18:21:17 +04:00
|
|
|
* Version: MPL 1.1/GPL 2.0/LGPL 2.1
|
1999-08-19 17:19:10 +04:00
|
|
|
*
|
2004-04-18 18:21:17 +04: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 17:19:10 +04:00
|
|
|
*
|
2001-09-26 02:53:13 +04: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 17:19:10 +04:00
|
|
|
*
|
1999-11-06 06:43:54 +03:00
|
|
|
* The Original Code is mozilla.org code.
|
|
|
|
*
|
2004-04-18 18:21:17 +04:00
|
|
|
* The Initial Developer of the Original Code is
|
2001-09-26 02:53:13 +04:00
|
|
|
* Netscape Communications Corporation.
|
|
|
|
* Portions created by the Initial Developer are Copyright (C) 1998
|
|
|
|
* the Initial Developer. All Rights Reserved.
|
1999-11-06 06:43:54 +03:00
|
|
|
*
|
2001-09-26 02:53:13 +04:00
|
|
|
* Contributor(s):
|
2000-01-11 23:49:15 +03:00
|
|
|
* Pierre Phaneuf <pp@ludusdesign.com>
|
2001-09-26 02:53:13 +04:00
|
|
|
*
|
|
|
|
* Alternatively, the contents of this file may be used under the terms of
|
2004-04-18 18:21:17 +04: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-26 02:53:13 +04: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 18:21:17 +04:00
|
|
|
* use your version of this file under the terms of the MPL, indicate your
|
2001-09-26 02:53:13 +04: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 18:21:17 +04:00
|
|
|
* the terms of any one of the MPL, the GPL or the LGPL.
|
2001-09-26 02:53:13 +04:00
|
|
|
*
|
|
|
|
* ***** END LICENSE BLOCK ***** */
|
1999-08-19 17:19:10 +04:00
|
|
|
|
|
|
|
#include <stdio.h>
|
|
|
|
#include "nsHTMLEditorLog.h"
|
|
|
|
#include "nsEditorTxnLog.h"
|
2001-03-09 17:23:59 +03:00
|
|
|
#include "nsPIEditorTransaction.h"
|
1999-08-19 17:19:10 +04: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) {
|
2010-07-05 13:42:18 +04:00
|
|
|
delete this;
|
1999-08-19 17:19:10 +04:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
return mRefCnt;
|
|
|
|
}
|
|
|
|
|
|
|
|
#else
|
|
|
|
|
|
|
|
NS_IMPL_ADDREF(nsEditorTxnLog)
|
|
|
|
NS_IMPL_RELEASE(nsEditorTxnLog)
|
|
|
|
|
|
|
|
#endif
|
|
|
|
|
2003-06-27 18:19:40 +04:00
|
|
|
NS_IMPL_QUERY_INTERFACE1(nsEditorTxnLog, nsITransactionListener)
|
1999-08-19 17:19:10 +04:00
|
|
|
|
|
|
|
NS_IMETHODIMP
|
2011-09-29 10:19:26 +04:00
|
|
|
nsEditorTxnLog::WillDo(nsITransactionManager *aTxMgr, nsITransaction *aTransaction, bool *aInterrupt)
|
1999-08-19 17:19:10 +04:00
|
|
|
{
|
|
|
|
LOCK_LOG(this);
|
|
|
|
|
|
|
|
PrintIndent(mIndentLevel++);
|
|
|
|
Write("WillDo: ");
|
2001-10-16 07:53:44 +04:00
|
|
|
WriteTransaction(aTransaction);
|
1999-08-19 17:19:10 +04: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 07:53:44 +04:00
|
|
|
WriteTransaction(aTransaction);
|
1999-08-19 17:19:10 +04:00
|
|
|
Write("(");
|
2002-11-18 18:43:19 +03:00
|
|
|
WriteInt(aDoResult);
|
1999-08-19 17:19:10 +04:00
|
|
|
Write(")\n");
|
|
|
|
Flush();
|
|
|
|
|
|
|
|
UNLOCK_LOG(this);
|
|
|
|
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
2011-09-29 10:19:26 +04:00
|
|
|
nsEditorTxnLog::WillUndo(nsITransactionManager *aTxMgr, nsITransaction *aTransaction, bool *aInterrupt)
|
1999-08-19 17:19:10 +04:00
|
|
|
{
|
|
|
|
LOCK_LOG(this);
|
|
|
|
|
|
|
|
PrintIndent(mIndentLevel++);
|
|
|
|
|
|
|
|
if (aTransaction)
|
|
|
|
{
|
|
|
|
Write("WillUndo: ");
|
2001-10-16 07:53:44 +04:00
|
|
|
WriteTransaction(aTransaction);
|
1999-08-19 17:19:10 +04: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 07:53:44 +04:00
|
|
|
WriteTransaction(aTransaction);
|
1999-08-19 17:19:10 +04:00
|
|
|
Write("(");
|
2002-11-18 18:43:19 +03:00
|
|
|
WriteInt(aUndoResult);
|
1999-08-19 17:19:10 +04:00
|
|
|
Write(")\n");
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
Write("EndUndoBatch (");
|
2002-11-18 18:43:19 +03:00
|
|
|
WriteInt(aUndoResult);
|
1999-08-19 17:19:10 +04:00
|
|
|
Write(")\n");
|
|
|
|
}
|
|
|
|
|
|
|
|
Flush();
|
|
|
|
|
|
|
|
UNLOCK_LOG(this);
|
|
|
|
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
2011-09-29 10:19:26 +04:00
|
|
|
nsEditorTxnLog::WillRedo(nsITransactionManager *aTxMgr, nsITransaction *aTransaction, bool *aInterrupt)
|
1999-08-19 17:19:10 +04:00
|
|
|
{
|
|
|
|
LOCK_LOG(this);
|
|
|
|
|
|
|
|
PrintIndent(mIndentLevel++);
|
|
|
|
|
|
|
|
if (aTransaction)
|
|
|
|
{
|
|
|
|
Write("WillRedo: ");
|
2001-10-16 07:53:44 +04:00
|
|
|
WriteTransaction(aTransaction);
|
1999-08-19 17:19:10 +04: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 07:53:44 +04:00
|
|
|
WriteTransaction(aTransaction);
|
1999-08-19 17:19:10 +04:00
|
|
|
Write(" (");
|
2002-11-18 18:43:19 +03:00
|
|
|
WriteInt(aRedoResult);
|
1999-08-19 17:19:10 +04:00
|
|
|
Write(")\n");
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
Write("DidRedoBatch (");
|
2002-11-18 18:43:19 +03:00
|
|
|
WriteInt(aRedoResult);
|
1999-08-19 17:19:10 +04:00
|
|
|
Write(")\n");
|
|
|
|
}
|
|
|
|
|
|
|
|
Flush();
|
|
|
|
|
|
|
|
UNLOCK_LOG(this);
|
|
|
|
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
2011-09-29 10:19:26 +04:00
|
|
|
nsEditorTxnLog::WillBeginBatch(nsITransactionManager *aTxMgr, bool *aInterrupt)
|
1999-08-19 17:19:10 +04:00
|
|
|
{
|
|
|
|
LOCK_LOG(this);
|
|
|
|
|
|
|
|
PrintIndent(mIndentLevel);
|
|
|
|
Write("WillBeginBatch: ");
|
2002-11-18 18:43:19 +03:00
|
|
|
WriteInt(mBatchCount);
|
1999-08-19 17:19:10 +04: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 18:43:19 +03:00
|
|
|
WriteInt(mBatchCount++);
|
1999-08-19 17:19:10 +04:00
|
|
|
Write(" (");
|
2002-11-18 18:43:19 +03:00
|
|
|
WriteInt(aResult);
|
1999-08-19 17:19:10 +04:00
|
|
|
Write(")\n");
|
|
|
|
Flush();
|
|
|
|
|
|
|
|
UNLOCK_LOG(this);
|
|
|
|
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
2011-09-29 10:19:26 +04:00
|
|
|
nsEditorTxnLog::WillEndBatch(nsITransactionManager *aTxMgr, bool *aInterrupt)
|
1999-08-19 17:19:10 +04:00
|
|
|
{
|
|
|
|
LOCK_LOG(this);
|
|
|
|
|
|
|
|
PrintIndent(--mIndentLevel);
|
|
|
|
Write("WillEndBatch: ");
|
2002-11-18 18:43:19 +03:00
|
|
|
WriteInt(--mBatchCount);
|
1999-08-19 17:19:10 +04: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 18:43:19 +03:00
|
|
|
WriteInt(mBatchCount);
|
1999-08-19 17:19:10 +04:00
|
|
|
Write(" (");
|
2002-11-18 18:43:19 +03:00
|
|
|
WriteInt(aResult);
|
1999-08-19 17:19:10 +04:00
|
|
|
Write(")\n");
|
|
|
|
Flush();
|
|
|
|
|
|
|
|
UNLOCK_LOG(this);
|
|
|
|
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
2011-09-29 10:19:26 +04:00
|
|
|
nsEditorTxnLog::WillMerge(nsITransactionManager *aTxMgr, nsITransaction *aTopTransaction, nsITransaction *aTransaction, bool *aInterrupt)
|
1999-08-19 17:19:10 +04:00
|
|
|
{
|
|
|
|
LOCK_LOG(this);
|
|
|
|
|
|
|
|
PrintIndent(mIndentLevel);
|
|
|
|
Write("WillMerge: ");
|
2001-10-16 07:53:44 +04:00
|
|
|
WriteTransaction(aTopTransaction);
|
1999-08-19 17:19:10 +04:00
|
|
|
Write(" <-- ");
|
2001-10-16 07:53:44 +04:00
|
|
|
WriteTransaction(aTransaction);
|
1999-08-19 17:19:10 +04:00
|
|
|
Write("\n");
|
|
|
|
Flush();
|
|
|
|
|
|
|
|
UNLOCK_LOG(this);
|
|
|
|
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
2011-09-29 10:19:26 +04:00
|
|
|
nsEditorTxnLog::DidMerge(nsITransactionManager *aTxMgr, nsITransaction *aTopTransaction, nsITransaction *aTransaction, bool aDidMerge, nsresult aMergeResult)
|
1999-08-19 17:19:10 +04:00
|
|
|
{
|
|
|
|
LOCK_LOG(this);
|
|
|
|
|
|
|
|
PrintIndent(mIndentLevel);
|
|
|
|
Write("DidMerge: ");
|
2001-10-16 07:53:44 +04:00
|
|
|
WriteTransaction(aTopTransaction);
|
1999-08-19 17:19:10 +04:00
|
|
|
Write(" <-- ");
|
2001-10-16 07:53:44 +04:00
|
|
|
WriteTransaction(aTransaction);
|
1999-08-19 17:19:10 +04:00
|
|
|
Write(" (");
|
|
|
|
Write(aDidMerge ? "TRUE" : "FALSE");
|
|
|
|
Write(", ");
|
2002-11-18 18:43:19 +03:00
|
|
|
WriteInt(aMergeResult);
|
1999-08-19 17:19:10 +04:00
|
|
|
Write(")\n");
|
|
|
|
Flush();
|
|
|
|
|
|
|
|
UNLOCK_LOG(this);
|
|
|
|
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2001-10-16 07:53:44 +04:00
|
|
|
nsresult
|
|
|
|
nsEditorTxnLog::WriteTransaction(nsITransaction *aTransaction)
|
1999-08-19 17:19:10 +04:00
|
|
|
{
|
2000-04-18 11:44:58 +04:00
|
|
|
nsString str;
|
1999-08-19 17:19:10 +04:00
|
|
|
|
2001-03-09 17:23:59 +03:00
|
|
|
nsCOMPtr<nsPIEditorTransaction> txn = do_QueryInterface(aTransaction);
|
2001-10-16 07:53:44 +04:00
|
|
|
if (txn) {
|
|
|
|
txn->GetTxnDescription(str);
|
|
|
|
if (str.IsEmpty())
|
2004-06-17 04:13:25 +04:00
|
|
|
str.AssignLiteral("<NULL>");
|
2001-10-16 07:53:44 +04:00
|
|
|
}
|
2001-03-09 17:23:59 +03:00
|
|
|
|
2006-02-03 17:18:39 +03:00
|
|
|
return Write(NS_LossyConvertUTF16toASCII(str).get());
|
1999-08-19 17:19:10 +04: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)
|
|
|
|
{
|
2010-06-18 00:40:48 +04:00
|
|
|
NS_ENSURE_TRUE(aBuffer, NS_ERROR_NULL_POINTER);
|
1999-08-19 17:19:10 +04:00
|
|
|
|
|
|
|
if (mEditorLog)
|
|
|
|
mEditorLog->Write(aBuffer);
|
|
|
|
else
|
2002-11-18 18:43:19 +03:00
|
|
|
{
|
|
|
|
PRInt32 len = strlen(aBuffer);
|
|
|
|
if (len > 0)
|
|
|
|
fwrite(aBuffer, 1, len, stdout);
|
|
|
|
}
|
1999-08-19 17:19:10 +04:00
|
|
|
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
nsresult
|
2002-11-18 18:43:19 +03:00
|
|
|
nsEditorTxnLog::WriteInt(PRInt32 aInt)
|
1999-08-19 17:19:10 +04:00
|
|
|
{
|
|
|
|
if (mEditorLog)
|
2002-11-18 18:43:19 +03:00
|
|
|
mEditorLog->WriteInt(aInt);
|
1999-08-19 17:19:10 +04:00
|
|
|
else
|
2002-11-18 18:43:19 +03:00
|
|
|
printf("%d", aInt);
|
1999-08-19 17:19:10 +04: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;
|
|
|
|
}
|