support for removing attributes

This commit is contained in:
buster%netscape.com 1999-01-07 01:02:16 +00:00
Родитель e8b01f3e65
Коммит 8dc326f5c0
6 изменённых файлов: 159 добавлений и 21 удалений

Просмотреть файл

@ -23,13 +23,16 @@
ChangeAttributeTxn::ChangeAttributeTxn(nsEditor *aEditor,
nsIDOMElement *aElement,
const nsString& aAttribute,
const nsString& aValue)
const nsString& aValue,
PRBool aRemoveAttribute)
: EditTxn(aEditor)
{
mElement = aElement;
mAttribute = aAttribute;
mValue = aValue;
mRemoveAttribute = aRemoveAttribute;
mAttributeWasSet=PR_FALSE;
mUndoValue="";
}
nsresult ChangeAttributeTxn::Do(void)
@ -40,13 +43,22 @@ nsresult ChangeAttributeTxn::Do(void)
char valueAsCString[stringlen+1];
mAttribute.ToCString(attributeAsCString, stringlen);
mAttributeWasSet;
mEditor->GetAttributeValue(mElement, mAttribute, mUndoValue, mAttributeWasSet);
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
if (mAttributeWasSet)
mUndoValue.ToCString(valueAsCString, stringlen);
// now set the attribute to the new value
return mEditor->SetAttribute(mElement, mAttribute, mValue);
if (PR_FALSE==mRemoveAttribute)
result = mEditor->SetAttribute(mElement, mAttribute, mValue);
else
result = mEditor->RemoveAttribute(mElement, mAttribute);
return result;
}
nsresult ChangeAttributeTxn::Undo(void)
@ -66,7 +78,14 @@ nsresult ChangeAttributeTxn::Undo(void)
nsresult ChangeAttributeTxn::Redo(void)
{
return mEditor->SetAttribute(mElement, mAttribute, mValue);
nsresult result;
if (PR_FALSE==mRemoveAttribute)
result = mEditor->SetAttribute(mElement, mAttribute, mValue);
else
result = mEditor->RemoveAttribute(mElement, mAttribute);
return result;
}
nsresult ChangeAttributeTxn::GetIsTransient(PRBool *aIsTransient)
@ -89,13 +108,25 @@ nsresult ChangeAttributeTxn::Write(nsIOutputStream *aOutputStream)
nsresult ChangeAttributeTxn::GetUndoString(nsString **aString)
{
if (nsnull!=aString)
*aString=nsnull;
{
if (PR_FALSE==mRemoveAttribute)
**aString="Change Attribute: ";
else
**aString="Remove Attribute: ";
**aString += mAttribute;
}
return NS_OK;
}
nsresult ChangeAttributeTxn::GetRedoString(nsString **aString)
{
if (nsnull!=aString)
*aString=nsnull;
{
if (PR_FALSE==mRemoveAttribute)
**aString="Change Attribute: ";
else
**aString="Add Attribute: ";
**aString += mAttribute;
}
return NS_OK;
}

Просмотреть файл

@ -25,6 +25,7 @@ class nsIDOMElement;
/**
* A transaction that changes an attribute of a content node.
* This transaction covers add, remove, and change attribute.
*/
class ChangeAttributeTxn : public EditTxn
{
@ -33,7 +34,8 @@ public:
ChangeAttributeTxn(nsEditor *aEditor,
nsIDOMElement *aElement,
const nsString& aAttribute,
const nsString& aValue);
const nsString& aValue,
PRBool aRemoveAttribute);
virtual nsresult Do(void);
@ -52,11 +54,24 @@ public:
virtual nsresult GetRedoString(nsString **aString);
protected:
/** the element to operate upon */
nsIDOMElement *mElement;
/** the attribute to change */
nsString mAttribute;
/** the value to set the attribute to (ignored if mRemoveAttribute==PR_TRUE) */
nsString mValue;
/** the value to set the attribute to for undo */
nsString mUndoValue;
/** PR_TRUE if the mAttribute was set on mElement at the time of execution */
PRBool mAttributeWasSet;
/** PR_TRUE if the operation is to remove mAttribute from mElement */
PRBool mRemoveAttribute;
};
#endif

Просмотреть файл

@ -23,13 +23,16 @@
ChangeAttributeTxn::ChangeAttributeTxn(nsEditor *aEditor,
nsIDOMElement *aElement,
const nsString& aAttribute,
const nsString& aValue)
const nsString& aValue,
PRBool aRemoveAttribute)
: EditTxn(aEditor)
{
mElement = aElement;
mAttribute = aAttribute;
mValue = aValue;
mRemoveAttribute = aRemoveAttribute;
mAttributeWasSet=PR_FALSE;
mUndoValue="";
}
nsresult ChangeAttributeTxn::Do(void)
@ -40,13 +43,22 @@ nsresult ChangeAttributeTxn::Do(void)
char valueAsCString[stringlen+1];
mAttribute.ToCString(attributeAsCString, stringlen);
mAttributeWasSet;
mEditor->GetAttributeValue(mElement, mAttribute, mUndoValue, mAttributeWasSet);
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
if (mAttributeWasSet)
mUndoValue.ToCString(valueAsCString, stringlen);
// now set the attribute to the new value
return mEditor->SetAttribute(mElement, mAttribute, mValue);
if (PR_FALSE==mRemoveAttribute)
result = mEditor->SetAttribute(mElement, mAttribute, mValue);
else
result = mEditor->RemoveAttribute(mElement, mAttribute);
return result;
}
nsresult ChangeAttributeTxn::Undo(void)
@ -66,7 +78,14 @@ nsresult ChangeAttributeTxn::Undo(void)
nsresult ChangeAttributeTxn::Redo(void)
{
return mEditor->SetAttribute(mElement, mAttribute, mValue);
nsresult result;
if (PR_FALSE==mRemoveAttribute)
result = mEditor->SetAttribute(mElement, mAttribute, mValue);
else
result = mEditor->RemoveAttribute(mElement, mAttribute);
return result;
}
nsresult ChangeAttributeTxn::GetIsTransient(PRBool *aIsTransient)
@ -89,13 +108,25 @@ nsresult ChangeAttributeTxn::Write(nsIOutputStream *aOutputStream)
nsresult ChangeAttributeTxn::GetUndoString(nsString **aString)
{
if (nsnull!=aString)
*aString=nsnull;
{
if (PR_FALSE==mRemoveAttribute)
**aString="Change Attribute: ";
else
**aString="Remove Attribute: ";
**aString += mAttribute;
}
return NS_OK;
}
nsresult ChangeAttributeTxn::GetRedoString(nsString **aString)
{
if (nsnull!=aString)
*aString=nsnull;
{
if (PR_FALSE==mRemoveAttribute)
**aString="Change Attribute: ";
else
**aString="Add Attribute: ";
**aString += mAttribute;
}
return NS_OK;
}

Просмотреть файл

@ -25,6 +25,7 @@ class nsIDOMElement;
/**
* A transaction that changes an attribute of a content node.
* This transaction covers add, remove, and change attribute.
*/
class ChangeAttributeTxn : public EditTxn
{
@ -33,7 +34,8 @@ public:
ChangeAttributeTxn(nsEditor *aEditor,
nsIDOMElement *aElement,
const nsString& aAttribute,
const nsString& aValue);
const nsString& aValue,
PRBool aRemoveAttribute);
virtual nsresult Do(void);
@ -52,11 +54,24 @@ public:
virtual nsresult GetRedoString(nsString **aString);
protected:
/** the element to operate upon */
nsIDOMElement *mElement;
/** the attribute to change */
nsString mAttribute;
/** the value to set the attribute to (ignored if mRemoveAttribute==PR_TRUE) */
nsString mValue;
/** the value to set the attribute to for undo */
nsString mUndoValue;
/** PR_TRUE if the mAttribute was set on mElement at the time of execution */
PRBool mAttributeWasSet;
/** PR_TRUE if the operation is to remove mAttribute from mElement */
PRBool mRemoveAttribute;
};
#endif

Просмотреть файл

@ -23,13 +23,16 @@
ChangeAttributeTxn::ChangeAttributeTxn(nsEditor *aEditor,
nsIDOMElement *aElement,
const nsString& aAttribute,
const nsString& aValue)
const nsString& aValue,
PRBool aRemoveAttribute)
: EditTxn(aEditor)
{
mElement = aElement;
mAttribute = aAttribute;
mValue = aValue;
mRemoveAttribute = aRemoveAttribute;
mAttributeWasSet=PR_FALSE;
mUndoValue="";
}
nsresult ChangeAttributeTxn::Do(void)
@ -40,13 +43,22 @@ nsresult ChangeAttributeTxn::Do(void)
char valueAsCString[stringlen+1];
mAttribute.ToCString(attributeAsCString, stringlen);
mAttributeWasSet;
mEditor->GetAttributeValue(mElement, mAttribute, mUndoValue, mAttributeWasSet);
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
if (mAttributeWasSet)
mUndoValue.ToCString(valueAsCString, stringlen);
// now set the attribute to the new value
return mEditor->SetAttribute(mElement, mAttribute, mValue);
if (PR_FALSE==mRemoveAttribute)
result = mEditor->SetAttribute(mElement, mAttribute, mValue);
else
result = mEditor->RemoveAttribute(mElement, mAttribute);
return result;
}
nsresult ChangeAttributeTxn::Undo(void)
@ -66,7 +78,14 @@ nsresult ChangeAttributeTxn::Undo(void)
nsresult ChangeAttributeTxn::Redo(void)
{
return mEditor->SetAttribute(mElement, mAttribute, mValue);
nsresult result;
if (PR_FALSE==mRemoveAttribute)
result = mEditor->SetAttribute(mElement, mAttribute, mValue);
else
result = mEditor->RemoveAttribute(mElement, mAttribute);
return result;
}
nsresult ChangeAttributeTxn::GetIsTransient(PRBool *aIsTransient)
@ -89,13 +108,25 @@ nsresult ChangeAttributeTxn::Write(nsIOutputStream *aOutputStream)
nsresult ChangeAttributeTxn::GetUndoString(nsString **aString)
{
if (nsnull!=aString)
*aString=nsnull;
{
if (PR_FALSE==mRemoveAttribute)
**aString="Change Attribute: ";
else
**aString="Remove Attribute: ";
**aString += mAttribute;
}
return NS_OK;
}
nsresult ChangeAttributeTxn::GetRedoString(nsString **aString)
{
if (nsnull!=aString)
*aString=nsnull;
{
if (PR_FALSE==mRemoveAttribute)
**aString="Change Attribute: ";
else
**aString="Add Attribute: ";
**aString += mAttribute;
}
return NS_OK;
}

Просмотреть файл

@ -25,6 +25,7 @@ class nsIDOMElement;
/**
* A transaction that changes an attribute of a content node.
* This transaction covers add, remove, and change attribute.
*/
class ChangeAttributeTxn : public EditTxn
{
@ -33,7 +34,8 @@ public:
ChangeAttributeTxn(nsEditor *aEditor,
nsIDOMElement *aElement,
const nsString& aAttribute,
const nsString& aValue);
const nsString& aValue,
PRBool aRemoveAttribute);
virtual nsresult Do(void);
@ -52,11 +54,24 @@ public:
virtual nsresult GetRedoString(nsString **aString);
protected:
/** the element to operate upon */
nsIDOMElement *mElement;
/** the attribute to change */
nsString mAttribute;
/** the value to set the attribute to (ignored if mRemoveAttribute==PR_TRUE) */
nsString mValue;
/** the value to set the attribute to for undo */
nsString mUndoValue;
/** PR_TRUE if the mAttribute was set on mElement at the time of execution */
PRBool mAttributeWasSet;
/** PR_TRUE if the operation is to remove mAttribute from mElement */
PRBool mRemoveAttribute;
};
#endif