1999-01-06 20:30:13 +00:00
|
|
|
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*-
|
|
|
|
*
|
1999-11-06 03:43:54 +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
|
|
|
*
|
1999-11-06 03:43:54 +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.
|
|
|
|
*
|
|
|
|
* The Initial Developer of the Original Code is Netscape
|
1999-01-06 20:30:13 +00:00
|
|
|
* Communications Corporation. Portions created by Netscape are
|
1999-11-06 03:43:54 +00:00
|
|
|
* Copyright (C) 1998 Netscape Communications Corporation. All
|
|
|
|
* Rights Reserved.
|
|
|
|
*
|
|
|
|
* Contributor(s):
|
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-09-21 22:31:27 +00:00
|
|
|
SetTransactionDescriptionID( kTransactionID );
|
|
|
|
/* log description initialized in parent constructor */
|
1999-01-21 01:51:09 +00:00
|
|
|
}
|
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,
|
|
|
|
const nsString& aAttribute,
|
|
|
|
const nsString& aValue,
|
|
|
|
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
|
|
|
}
|
|
|
|
|
1999-03-02 05:30:53 +00:00
|
|
|
NS_IMETHODIMP ChangeAttributeTxn::Do(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
|
1999-01-07 01:02:16 +00:00
|
|
|
nsresult result = mEditor->GetAttributeValue(mElement, mAttribute, mUndoValue, mAttributeWasSet);
|
|
|
|
// 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
|
|
|
}
|
|
|
|
|
1999-03-02 05:30:53 +00:00
|
|
|
NS_IMETHODIMP ChangeAttributeTxn::Undo(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;
|
|
|
|
}
|
|
|
|
|
1999-03-02 05:30:53 +00:00
|
|
|
NS_IMETHODIMP ChangeAttributeTxn::Redo(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
|
|
|
}
|
|
|
|
|
1999-03-02 05:30:53 +00:00
|
|
|
NS_IMETHODIMP ChangeAttributeTxn::Merge(PRBool *aDidMerge, nsITransaction *aTransaction)
|
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;
|
|
|
|
}
|
|
|
|
|
1999-03-02 05:30:53 +00:00
|
|
|
NS_IMETHODIMP ChangeAttributeTxn::Write(nsIOutputStream *aOutputStream)
|
1999-01-06 20:30:13 +00:00
|
|
|
{
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
1999-05-27 20:50:52 +00:00
|
|
|
NS_IMETHODIMP ChangeAttributeTxn::GetUndoString(nsString *aString)
|
1999-01-06 20:30:13 +00:00
|
|
|
{
|
|
|
|
if (nsnull!=aString)
|
1999-01-07 01:02:16 +00:00
|
|
|
{
|
|
|
|
if (PR_FALSE==mRemoveAttribute)
|
2000-04-18 07:44:58 +00:00
|
|
|
aString->AssignWithConversion("Change Attribute: ");
|
1999-01-07 01:02:16 +00:00
|
|
|
else
|
2000-04-18 07:44:58 +00:00
|
|
|
aString->AssignWithConversion("Remove Attribute: ");
|
1999-05-27 20:50:52 +00:00
|
|
|
*aString += mAttribute;
|
1999-01-07 01:02:16 +00:00
|
|
|
}
|
1999-01-06 20:30:13 +00:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
1999-05-27 20:50:52 +00:00
|
|
|
NS_IMETHODIMP ChangeAttributeTxn::GetRedoString(nsString *aString)
|
1999-01-06 20:30:13 +00:00
|
|
|
{
|
|
|
|
if (nsnull!=aString)
|
1999-01-07 01:02:16 +00:00
|
|
|
{
|
|
|
|
if (PR_FALSE==mRemoveAttribute)
|
2000-04-18 07:44:58 +00:00
|
|
|
aString->AssignWithConversion("Change Attribute: ");
|
1999-01-07 01:02:16 +00:00
|
|
|
else
|
2000-04-18 07:44:58 +00:00
|
|
|
aString->AssignWithConversion("Add Attribute: ");
|
1999-05-27 20:50:52 +00:00
|
|
|
*aString += mAttribute;
|
1999-01-07 01:02:16 +00:00
|
|
|
}
|
1999-01-06 20:30:13 +00:00
|
|
|
return NS_OK;
|
|
|
|
}
|