2001-09-25 22:53:13 +00:00
|
|
|
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
|
|
|
/* ***** BEGIN LICENSE BLOCK *****
|
|
|
|
* Version: NPL 1.1/GPL 2.0/LGPL 2.1
|
1999-01-06 20:30:13 +00:00
|
|
|
*
|
2001-09-25 22:53:13 +00:00
|
|
|
* The contents of this file are subject to the Netscape 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/NPL/
|
1999-01-06 20:30:13 +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-01-06 20:30:13 +00:00
|
|
|
*
|
1999-11-06 03:43:54 +00:00
|
|
|
* The Original Code is mozilla.org code.
|
|
|
|
*
|
2001-09-25 22:53:13 +00:00
|
|
|
* The Initial Developer of the Original Code is
|
|
|
|
* 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):
|
|
|
|
*
|
|
|
|
*
|
|
|
|
* Alternatively, the contents of this file may be used under the terms of
|
|
|
|
* either 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"),
|
|
|
|
* 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
|
|
|
|
* use your version of this file under the terms of the NPL, indicate your
|
|
|
|
* 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
|
|
|
|
* the terms of any one of the NPL, the GPL or the LGPL.
|
|
|
|
*
|
|
|
|
* ***** END LICENSE BLOCK ***** */
|
1999-01-06 20:30:13 +00:00
|
|
|
|
|
|
|
#include "ChangeAttributeTxn.h"
|
1999-01-11 22:47:23 +00:00
|
|
|
#include "nsIDOMElement.h"
|
1999-02-12 17:18:58 +00:00
|
|
|
#include "nsEditor.h"
|
1999-01-21 01:51:09 +00:00
|
|
|
|
|
|
|
ChangeAttributeTxn::ChangeAttributeTxn()
|
|
|
|
: EditTxn()
|
|
|
|
{
|
|
|
|
}
|
1999-01-06 20:30:13 +00:00
|
|
|
|
1999-03-05 21:05:35 +00:00
|
|
|
ChangeAttributeTxn::~ChangeAttributeTxn()
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
1999-03-02 05:30:53 +00:00
|
|
|
NS_IMETHODIMP ChangeAttributeTxn::Init(nsIEditor *aEditor,
|
1999-04-16 18:29:12 +00:00
|
|
|
nsIDOMElement *aElement,
|
2001-04-07 00:45:26 +00:00
|
|
|
const nsAReadableString& aAttribute,
|
|
|
|
const nsAReadableString& aValue,
|
1999-04-16 18:29:12 +00:00
|
|
|
PRBool aRemoveAttribute)
|
1999-01-06 20:30:13 +00:00
|
|
|
{
|
1999-08-19 13:30:48 +00:00
|
|
|
NS_ASSERTION(aEditor && aElement, "bad arg");
|
|
|
|
if (!aEditor || !aElement) { return NS_ERROR_NULL_POINTER; }
|
|
|
|
|
|
|
|
mEditor = aEditor;
|
|
|
|
mElement = do_QueryInterface(aElement);
|
|
|
|
mAttribute = aAttribute;
|
|
|
|
mValue = aValue;
|
|
|
|
mRemoveAttribute = aRemoveAttribute;
|
|
|
|
mAttributeWasSet=PR_FALSE;
|
2000-04-18 07:44:58 +00:00
|
|
|
mUndoValue.SetLength(0);
|
1999-08-19 13:30:48 +00:00
|
|
|
return NS_OK;
|
1999-01-06 20:30:13 +00:00
|
|
|
}
|
|
|
|
|
2001-03-09 14:23:59 +00:00
|
|
|
NS_IMETHODIMP ChangeAttributeTxn::DoTransaction(void)
|
1999-01-06 20:30:13 +00:00
|
|
|
{
|
1999-08-19 13:30:48 +00:00
|
|
|
NS_ASSERTION(mEditor && mElement, "bad state");
|
|
|
|
if (!mEditor || !mElement) { return NS_ERROR_NOT_INITIALIZED; }
|
|
|
|
|
1999-01-06 20:30:13 +00:00
|
|
|
// need to get the current value of the attribute and save it, and set mAttributeWasSet
|
2001-04-07 00:45:26 +00:00
|
|
|
nsresult result = mEditor->GetAttributeValue(mElement, mAttribute, mUndoValue, &mAttributeWasSet);
|
1999-01-07 01:02:16 +00:00
|
|
|
// XXX: hack until attribute-was-set code is implemented
|
2000-04-18 07:44:58 +00:00
|
|
|
if (PR_FALSE==mUndoValue.IsEmpty())
|
1999-01-07 01:02:16 +00:00
|
|
|
mAttributeWasSet=PR_TRUE;
|
|
|
|
// XXX: end hack
|
1999-01-06 20:30:13 +00:00
|
|
|
|
|
|
|
// now set the attribute to the new value
|
1999-01-07 01:02:16 +00:00
|
|
|
if (PR_FALSE==mRemoveAttribute)
|
1999-01-12 18:20:58 +00:00
|
|
|
result = mElement->SetAttribute(mAttribute, mValue);
|
1999-01-07 01:02:16 +00:00
|
|
|
else
|
1999-01-11 22:47:23 +00:00
|
|
|
result = mElement->RemoveAttribute(mAttribute);
|
1999-01-07 01:02:16 +00:00
|
|
|
|
|
|
|
return result;
|
1999-01-06 20:30:13 +00:00
|
|
|
}
|
|
|
|
|
2001-03-09 14:23:59 +00:00
|
|
|
NS_IMETHODIMP ChangeAttributeTxn::UndoTransaction(void)
|
1999-01-06 20:30:13 +00:00
|
|
|
{
|
1999-08-19 13:30:48 +00:00
|
|
|
NS_ASSERTION(mEditor && mElement, "bad state");
|
|
|
|
if (!mEditor || !mElement) { return NS_ERROR_NOT_INITIALIZED; }
|
|
|
|
|
1999-01-06 20:30:13 +00:00
|
|
|
nsresult result=NS_OK;
|
|
|
|
if (PR_TRUE==mAttributeWasSet)
|
1999-01-12 18:20:58 +00:00
|
|
|
result = mElement->SetAttribute(mAttribute, mUndoValue);
|
1999-01-06 20:30:13 +00:00
|
|
|
else
|
1999-01-11 22:47:23 +00:00
|
|
|
result = mElement->RemoveAttribute(mAttribute);
|
1999-01-06 20:30:13 +00:00
|
|
|
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
2001-03-09 14:23:59 +00:00
|
|
|
NS_IMETHODIMP ChangeAttributeTxn::RedoTransaction(void)
|
1999-01-06 20:30:13 +00:00
|
|
|
{
|
1999-08-19 13:30:48 +00:00
|
|
|
NS_ASSERTION(mEditor && mElement, "bad state");
|
|
|
|
if (!mEditor || !mElement) { return NS_ERROR_NOT_INITIALIZED; }
|
|
|
|
|
1999-01-07 01:02:16 +00:00
|
|
|
nsresult result;
|
|
|
|
|
|
|
|
if (PR_FALSE==mRemoveAttribute)
|
1999-01-12 18:20:58 +00:00
|
|
|
result = mElement->SetAttribute(mAttribute, mValue);
|
1999-01-07 01:02:16 +00:00
|
|
|
else
|
1999-01-11 22:47:23 +00:00
|
|
|
result = mElement->RemoveAttribute(mAttribute);
|
1999-01-07 01:02:16 +00:00
|
|
|
|
|
|
|
return result;
|
1999-01-06 20:30:13 +00:00
|
|
|
}
|
|
|
|
|
2001-03-09 14:23:59 +00:00
|
|
|
NS_IMETHODIMP ChangeAttributeTxn::Merge(nsITransaction *aTransaction, PRBool *aDidMerge)
|
1999-01-06 20:30:13 +00:00
|
|
|
{
|
1999-01-14 18:02:45 +00:00
|
|
|
if (nsnull!=aDidMerge)
|
|
|
|
*aDidMerge=PR_FALSE;
|
1999-01-06 20:30:13 +00:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2001-03-09 14:23:59 +00:00
|
|
|
NS_IMETHODIMP ChangeAttributeTxn::GetTxnDescription(nsAWritableString& aString)
|
1999-01-06 20:30:13 +00:00
|
|
|
{
|
2001-03-09 14:23:59 +00:00
|
|
|
aString.Assign(NS_LITERAL_STRING("ChangeAttributeTxn: "));
|
1999-01-06 20:30:13 +00:00
|
|
|
|
2001-03-09 14:23:59 +00:00
|
|
|
if (PR_FALSE==mRemoveAttribute)
|
|
|
|
aString += NS_LITERAL_STRING("[mRemoveAttribute == false] ");
|
|
|
|
else
|
|
|
|
aString += NS_LITERAL_STRING("[mRemoveAttribute == true] ");
|
|
|
|
aString += mAttribute;
|
1999-01-06 20:30:13 +00:00
|
|
|
return NS_OK;
|
|
|
|
}
|