1999-01-14 21:02:45 +03:00
|
|
|
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*-
|
|
|
|
*
|
|
|
|
* The contents of this file are subject to the Netscape Public License
|
|
|
|
* Version 1.0 (the "NPL"); you may not use this file except in
|
|
|
|
* compliance with the NPL. You may obtain a copy of the NPL at
|
|
|
|
* http://www.mozilla.org/NPL/
|
|
|
|
*
|
|
|
|
* Software distributed under the NPL is distributed on an "AS IS" basis,
|
|
|
|
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the NPL
|
|
|
|
* for the specific language governing rights and limitations under the
|
|
|
|
* NPL.
|
|
|
|
*
|
|
|
|
* The Initial Developer of this code under the NPL is Netscape
|
|
|
|
* Communications Corporation. Portions created by Netscape are
|
|
|
|
* Copyright (C) 1998 Netscape Communications Corporation. All Rights
|
|
|
|
* Reserved.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include "DeleteElementTxn.h"
|
1999-01-21 04:51:09 +03:00
|
|
|
#ifdef NS_DEBUG
|
1999-01-14 21:02:45 +03:00
|
|
|
#include "nsIDOMElement.h"
|
1999-01-21 04:51:09 +03:00
|
|
|
#endif
|
|
|
|
|
1999-01-21 22:44:26 +03:00
|
|
|
#ifdef NS_DEBUG
|
|
|
|
static PRBool gNoisy = PR_FALSE;
|
|
|
|
#else
|
|
|
|
static const PRBool gNoisy = PR_FALSE;
|
|
|
|
#endif
|
|
|
|
|
1999-01-21 04:51:09 +03:00
|
|
|
|
|
|
|
DeleteElementTxn::DeleteElementTxn()
|
|
|
|
: EditTxn()
|
|
|
|
{
|
|
|
|
}
|
1999-01-14 21:02:45 +03:00
|
|
|
|
1999-02-15 21:25:30 +03:00
|
|
|
nsresult DeleteElementTxn::Init(nsIDOMNode *aElement)
|
1999-01-14 21:02:45 +03:00
|
|
|
{
|
1999-02-15 21:25:30 +03:00
|
|
|
if (nsnull!=aElement) {
|
1999-02-19 14:30:31 +03:00
|
|
|
mElement = do_QueryInterface(aElement);
|
1999-01-21 04:51:09 +03:00
|
|
|
}
|
1999-02-15 21:25:30 +03:00
|
|
|
else
|
1999-01-21 04:51:09 +03:00
|
|
|
return NS_ERROR_NULL_POINTER;
|
1999-02-15 21:25:30 +03:00
|
|
|
return NS_OK;
|
1999-01-14 21:02:45 +03:00
|
|
|
}
|
|
|
|
|
1999-01-21 04:51:09 +03:00
|
|
|
|
1999-01-14 21:02:45 +03:00
|
|
|
DeleteElementTxn::~DeleteElementTxn()
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
nsresult DeleteElementTxn::Do(void)
|
|
|
|
{
|
1999-02-15 21:25:30 +03:00
|
|
|
if (!mElement)
|
|
|
|
return NS_ERROR_NULL_POINTER;
|
|
|
|
|
|
|
|
nsresult result = mElement->GetParentNode(getter_AddRefs(mParent));
|
|
|
|
if (NS_FAILED(result)) {
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
if (!mParent) {
|
1999-01-14 21:02:45 +03:00
|
|
|
return NS_ERROR_NULL_POINTER;
|
1999-02-15 21:25:30 +03:00
|
|
|
}
|
|
|
|
|
1999-01-14 21:02:45 +03:00
|
|
|
#ifdef NS_DEBUG
|
1999-01-21 04:51:09 +03:00
|
|
|
// begin debug output
|
1999-02-17 04:59:56 +03:00
|
|
|
nsCOMPtr<nsIDOMElement> element;
|
|
|
|
element = do_QueryInterface(mElement, &result);
|
1999-01-21 04:51:09 +03:00
|
|
|
nsAutoString elementTag="text node";
|
|
|
|
if (element)
|
|
|
|
element->GetTagName(elementTag);
|
1999-02-17 04:59:56 +03:00
|
|
|
nsCOMPtr<nsIDOMElement> parentElement;
|
|
|
|
parentElement = do_QueryInterface(mParent, &result);
|
1999-01-21 04:51:09 +03:00
|
|
|
nsAutoString parentElementTag="text node";
|
|
|
|
if (parentElement)
|
|
|
|
parentElement->GetTagName(parentElementTag);
|
|
|
|
char *c, *p;
|
|
|
|
c = elementTag.ToNewCString();
|
|
|
|
p = parentElementTag.ToNewCString();
|
|
|
|
if (c&&p)
|
|
|
|
{
|
1999-01-21 22:44:26 +03:00
|
|
|
if (gNoisy)
|
|
|
|
printf("DeleteElementTxn: deleting child %s from parent %s\n", c, p);
|
1999-01-21 04:51:09 +03:00
|
|
|
delete [] c;
|
|
|
|
delete [] p;
|
|
|
|
}
|
|
|
|
// end debug output
|
1999-01-14 21:02:45 +03:00
|
|
|
#endif
|
|
|
|
|
|
|
|
// remember which child mElement was (by remembering which child was next)
|
1999-02-15 21:25:30 +03:00
|
|
|
result = mElement->GetNextSibling(getter_AddRefs(mRefNode)); // can return null mRefNode
|
1999-01-14 21:02:45 +03:00
|
|
|
|
|
|
|
nsCOMPtr<nsIDOMNode> resultNode;
|
|
|
|
result = mParent->RemoveChild(mElement, getter_AddRefs(resultNode));
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
|
|
|
nsresult DeleteElementTxn::Undo(void)
|
|
|
|
{
|
|
|
|
if (!mParent || !mElement)
|
|
|
|
return NS_ERROR_NULL_POINTER;
|
|
|
|
|
|
|
|
nsCOMPtr<nsIDOMNode> resultNode;
|
|
|
|
nsresult result = mParent->InsertBefore(mElement, mRefNode, getter_AddRefs(resultNode));
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
|
|
|
nsresult DeleteElementTxn::Redo(void)
|
|
|
|
{
|
|
|
|
if (!mParent || !mElement)
|
|
|
|
return NS_ERROR_NULL_POINTER;
|
|
|
|
|
|
|
|
nsCOMPtr<nsIDOMNode> resultNode;
|
|
|
|
nsresult result = mParent->RemoveChild(mElement, getter_AddRefs(resultNode));
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
|
|
|
nsresult DeleteElementTxn::Merge(PRBool *aDidMerge, nsITransaction *aTransaction)
|
|
|
|
{
|
|
|
|
if (nsnull!=aDidMerge)
|
|
|
|
*aDidMerge=PR_FALSE;
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
nsresult DeleteElementTxn::Write(nsIOutputStream *aOutputStream)
|
|
|
|
{
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
nsresult DeleteElementTxn::GetUndoString(nsString **aString)
|
|
|
|
{
|
|
|
|
if (nsnull!=aString)
|
|
|
|
{
|
|
|
|
**aString="Insert Element: ";
|
|
|
|
}
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
nsresult DeleteElementTxn::GetRedoString(nsString **aString)
|
|
|
|
{
|
|
|
|
if (nsnull!=aString)
|
|
|
|
{
|
|
|
|
**aString="Remove Element: ";
|
|
|
|
}
|
|
|
|
return NS_OK;
|
|
|
|
}
|