1999-01-06 23:30:13 +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 "ChangeAttributeTxn.h"
|
1999-01-12 01:47:23 +03:00
|
|
|
#include "nsIDOMElement.h"
|
1999-02-12 20:18:58 +03:00
|
|
|
#include "nsEditor.h"
|
1999-01-21 04:51:09 +03:00
|
|
|
|
|
|
|
ChangeAttributeTxn::ChangeAttributeTxn()
|
|
|
|
: EditTxn()
|
|
|
|
{
|
|
|
|
}
|
1999-01-06 23:30:13 +03:00
|
|
|
|
1999-03-06 00:05:35 +03:00
|
|
|
ChangeAttributeTxn::~ChangeAttributeTxn()
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
1999-03-02 08:30:53 +03:00
|
|
|
NS_IMETHODIMP ChangeAttributeTxn::Init(nsIEditor *aEditor,
|
1999-04-16 22:29:12 +04:00
|
|
|
nsIDOMElement *aElement,
|
|
|
|
const nsString& aAttribute,
|
|
|
|
const nsString& aValue,
|
|
|
|
PRBool aRemoveAttribute)
|
1999-01-06 23:30:13 +03:00
|
|
|
{
|
1999-01-21 04:51:09 +03:00
|
|
|
if (nsnull!=aEditor && nsnull!=aElement)
|
|
|
|
{
|
1999-02-19 14:30:31 +03:00
|
|
|
mEditor = do_QueryInterface(aEditor);
|
|
|
|
mElement = do_QueryInterface(aElement);
|
1999-01-21 04:51:09 +03:00
|
|
|
mAttribute = aAttribute;
|
|
|
|
mValue = aValue;
|
|
|
|
mRemoveAttribute = aRemoveAttribute;
|
|
|
|
mAttributeWasSet=PR_FALSE;
|
|
|
|
mUndoValue="";
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
return NS_ERROR_NULL_POINTER;
|
1999-01-06 23:30:13 +03:00
|
|
|
}
|
|
|
|
|
1999-03-02 08:30:53 +03:00
|
|
|
NS_IMETHODIMP ChangeAttributeTxn::Do(void)
|
1999-01-06 23:30:13 +03:00
|
|
|
{
|
|
|
|
// need to get the current value of the attribute and save it, and set mAttributeWasSet
|
|
|
|
const int stringlen=100;
|
|
|
|
char attributeAsCString[stringlen+1];
|
|
|
|
char valueAsCString[stringlen+1];
|
|
|
|
mAttribute.ToCString(attributeAsCString, stringlen);
|
|
|
|
mAttributeWasSet;
|
1999-01-07 04:02:16 +03:00
|
|
|
nsresult result = mEditor->GetAttributeValue(mElement, mAttribute, mUndoValue, mAttributeWasSet);
|
|
|
|
// XXX: hack until attribute-was-set code is implemented
|
|
|
|
if (PR_FALSE==mUndoValue.Equals(""))
|
|
|
|
mAttributeWasSet=PR_TRUE;
|
|
|
|
// XXX: end hack
|
1999-01-06 23:30:13 +03:00
|
|
|
|
|
|
|
if (mAttributeWasSet)
|
|
|
|
mUndoValue.ToCString(valueAsCString, stringlen);
|
|
|
|
|
|
|
|
// now set the attribute to the new value
|
1999-01-07 04:02:16 +03:00
|
|
|
if (PR_FALSE==mRemoveAttribute)
|
1999-01-12 21:20:58 +03:00
|
|
|
result = mElement->SetAttribute(mAttribute, mValue);
|
1999-01-07 04:02:16 +03:00
|
|
|
else
|
1999-01-12 01:47:23 +03:00
|
|
|
result = mElement->RemoveAttribute(mAttribute);
|
1999-01-07 04:02:16 +03:00
|
|
|
|
|
|
|
return result;
|
1999-01-06 23:30:13 +03:00
|
|
|
}
|
|
|
|
|
1999-03-02 08:30:53 +03:00
|
|
|
NS_IMETHODIMP ChangeAttributeTxn::Undo(void)
|
1999-01-06 23:30:13 +03:00
|
|
|
{
|
|
|
|
nsresult result=NS_OK;
|
|
|
|
if (PR_TRUE==mAttributeWasSet)
|
1999-01-12 21:20:58 +03:00
|
|
|
result = mElement->SetAttribute(mAttribute, mUndoValue);
|
1999-01-06 23:30:13 +03:00
|
|
|
else
|
1999-01-12 01:47:23 +03:00
|
|
|
result = mElement->RemoveAttribute(mAttribute);
|
1999-01-06 23:30:13 +03:00
|
|
|
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
1999-03-02 08:30:53 +03:00
|
|
|
NS_IMETHODIMP ChangeAttributeTxn::Redo(void)
|
1999-01-06 23:30:13 +03:00
|
|
|
{
|
1999-01-07 04:02:16 +03:00
|
|
|
nsresult result;
|
|
|
|
|
|
|
|
if (PR_FALSE==mRemoveAttribute)
|
1999-01-12 21:20:58 +03:00
|
|
|
result = mElement->SetAttribute(mAttribute, mValue);
|
1999-01-07 04:02:16 +03:00
|
|
|
else
|
1999-01-12 01:47:23 +03:00
|
|
|
result = mElement->RemoveAttribute(mAttribute);
|
1999-01-07 04:02:16 +03:00
|
|
|
|
|
|
|
return result;
|
1999-01-06 23:30:13 +03:00
|
|
|
}
|
|
|
|
|
1999-03-02 08:30:53 +03:00
|
|
|
NS_IMETHODIMP ChangeAttributeTxn::Merge(PRBool *aDidMerge, nsITransaction *aTransaction)
|
1999-01-06 23:30:13 +03:00
|
|
|
{
|
1999-01-14 21:02:45 +03:00
|
|
|
if (nsnull!=aDidMerge)
|
|
|
|
*aDidMerge=PR_FALSE;
|
1999-01-06 23:30:13 +03:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
1999-03-02 08:30:53 +03:00
|
|
|
NS_IMETHODIMP ChangeAttributeTxn::Write(nsIOutputStream *aOutputStream)
|
1999-01-06 23:30:13 +03:00
|
|
|
{
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
1999-03-02 08:30:53 +03:00
|
|
|
NS_IMETHODIMP ChangeAttributeTxn::GetUndoString(nsString **aString)
|
1999-01-06 23:30:13 +03:00
|
|
|
{
|
|
|
|
if (nsnull!=aString)
|
1999-01-07 04:02:16 +03:00
|
|
|
{
|
|
|
|
if (PR_FALSE==mRemoveAttribute)
|
|
|
|
**aString="Change Attribute: ";
|
|
|
|
else
|
|
|
|
**aString="Remove Attribute: ";
|
|
|
|
**aString += mAttribute;
|
|
|
|
}
|
1999-01-06 23:30:13 +03:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
1999-03-02 08:30:53 +03:00
|
|
|
NS_IMETHODIMP ChangeAttributeTxn::GetRedoString(nsString **aString)
|
1999-01-06 23:30:13 +03:00
|
|
|
{
|
|
|
|
if (nsnull!=aString)
|
1999-01-07 04:02:16 +03:00
|
|
|
{
|
|
|
|
if (PR_FALSE==mRemoveAttribute)
|
|
|
|
**aString="Change Attribute: ";
|
|
|
|
else
|
|
|
|
**aString="Add Attribute: ";
|
|
|
|
**aString += mAttribute;
|
|
|
|
}
|
1999-01-06 23:30:13 +03:00
|
|
|
return NS_OK;
|
|
|
|
}
|