mirror of
https://github.com/mozilla/gecko-dev.git
synced 2024-10-10 20:05:49 +00:00
support for inserting text
This commit is contained in:
parent
8c25fcb097
commit
4435c98060
86
editor/base/InsertTextTxn.cpp
Normal file
86
editor/base/InsertTextTxn.cpp
Normal file
@ -0,0 +1,86 @@
|
||||
/* -*- 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 "InsertTextTxn.h"
|
||||
#include "editor.h"
|
||||
#include "nsIDOMCharacterData.h"
|
||||
|
||||
// note that aEditor is not refcounted
|
||||
InsertTextTxn::InsertTextTxn(nsEditor *aEditor,
|
||||
nsIDOMCharacterData *aElement,
|
||||
PRUint32 aOffset,
|
||||
const nsString& aStringToInsert)
|
||||
: EditTxn(aEditor)
|
||||
{
|
||||
mElement = aElement;
|
||||
mOffset = aOffset;
|
||||
mStringToInsert = aStringToInsert;
|
||||
}
|
||||
|
||||
nsresult InsertTextTxn::Do(void)
|
||||
{
|
||||
return (mElement->InsertData(mOffset, mStringToInsert));
|
||||
}
|
||||
|
||||
nsresult InsertTextTxn::Undo(void)
|
||||
{
|
||||
PRUint32 length = mStringToInsert.Length();
|
||||
return (mElement->DeleteData(mOffset, length));
|
||||
}
|
||||
|
||||
nsresult InsertTextTxn::Redo(void)
|
||||
{
|
||||
return Do();
|
||||
}
|
||||
|
||||
nsresult InsertTextTxn::GetIsTransient(PRBool *aIsTransient)
|
||||
{
|
||||
if (nsnull!=aIsTransient)
|
||||
*aIsTransient = PR_FALSE;
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
nsresult InsertTextTxn::Merge(PRBool *aDidMerge, nsITransaction *aTransaction)
|
||||
{
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
nsresult InsertTextTxn::Write(nsIOutputStream *aOutputStream)
|
||||
{
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
nsresult InsertTextTxn::GetUndoString(nsString **aString)
|
||||
{
|
||||
if (nsnull!=aString)
|
||||
{
|
||||
**aString="Remove Text: ";
|
||||
**aString += mStringToInsert;
|
||||
}
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
nsresult InsertTextTxn::GetRedoString(nsString **aString)
|
||||
{
|
||||
if (nsnull!=aString)
|
||||
{
|
||||
**aString="Insert Text: ";
|
||||
**aString += mStringToInsert;
|
||||
}
|
||||
return NS_OK;
|
||||
}
|
71
editor/base/InsertTextTxn.h
Normal file
71
editor/base/InsertTextTxn.h
Normal file
@ -0,0 +1,71 @@
|
||||
/* -*- 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.
|
||||
*/
|
||||
|
||||
#ifndef InsertTextTxn_h__
|
||||
#define InsertTextTxn_h__
|
||||
|
||||
#include "EditTxn.h"
|
||||
|
||||
class nsIDOMCharacterData;
|
||||
|
||||
/**
|
||||
* A transaction that changes an attribute of a content node.
|
||||
* This transaction covers add, remove, and change attribute.
|
||||
*/
|
||||
class InsertTextTxn : public EditTxn
|
||||
{
|
||||
public:
|
||||
|
||||
InsertTextTxn(nsEditor *aEditor,
|
||||
nsIDOMCharacterData *aElement,
|
||||
PRUint32 aOffset,
|
||||
const nsString& aStringToInsert);
|
||||
|
||||
virtual nsresult Do(void);
|
||||
|
||||
virtual nsresult Undo(void);
|
||||
|
||||
virtual nsresult Redo(void);
|
||||
|
||||
virtual nsresult GetIsTransient(PRBool *aIsTransient);
|
||||
|
||||
virtual nsresult Merge(PRBool *aDidMerge, nsITransaction *aTransaction);
|
||||
|
||||
virtual nsresult Write(nsIOutputStream *aOutputStream);
|
||||
|
||||
virtual nsresult GetUndoString(nsString **aString);
|
||||
|
||||
virtual nsresult GetRedoString(nsString **aString);
|
||||
|
||||
protected:
|
||||
|
||||
/** the text element to operate upon */
|
||||
nsIDOMCharacterData *mElement;
|
||||
|
||||
/** the offset into mElement where the insertion is to take place */
|
||||
PRUint32 mOffset;
|
||||
|
||||
/** the value to set the attribute to (ignored if mRemoveAttribute==PR_TRUE) */
|
||||
nsString mValue;
|
||||
|
||||
/** the text to insert into mElement at mOffset */
|
||||
nsString mStringToInsert;
|
||||
|
||||
};
|
||||
|
||||
#endif
|
@ -19,10 +19,14 @@
|
||||
#include "nsString.h"
|
||||
#include "editor.h"
|
||||
#include "ChangeAttributeTxn.h"
|
||||
#include "InsertTextTxn.h"
|
||||
#include "nsIDOMDocument.h"
|
||||
#include "nsIDOMElement.h"
|
||||
#include "nsIDOMCharacterData.h"
|
||||
|
||||
static NS_DEFINE_IID(kIDOMElementIID, NS_IDOMELEMENT_IID);
|
||||
static NS_DEFINE_IID(kIDOMCharacterDataIID, NS_IDOMCHARACTERDATA_IID);
|
||||
|
||||
|
||||
/*
|
||||
* nsEditorKeyListener implementation
|
||||
@ -129,15 +133,30 @@ nsEditorKeyListener::KeyDown(nsIDOMEvent* aKeyEvent)
|
||||
mEditor->Commit(ctrlKey);
|
||||
break;
|
||||
default:
|
||||
// XXX Replace with x-platform NS-virtkeycode transform.
|
||||
if (NS_OK == GetCharFromKeyCode(keyCode, isShift, & character)) {
|
||||
nsString* key = new nsString();
|
||||
*key += character;
|
||||
if (!isShift) {
|
||||
key->ToLowerCase();
|
||||
{
|
||||
// XXX Replace with x-platform NS-virtkeycode transform.
|
||||
if (NS_OK == GetCharFromKeyCode(keyCode, isShift, & character)) {
|
||||
nsString key;
|
||||
key += character;
|
||||
if (!isShift) {
|
||||
key.ToLowerCase();
|
||||
}
|
||||
|
||||
nsCOMPtr<nsIDOMNode> currentNode;
|
||||
nsCOMPtr<nsIDOMNode> textNode;
|
||||
nsCOMPtr<nsIDOMCharacterData> text;
|
||||
if (NS_SUCCEEDED(mEditor->GetCurrentNode(getter_AddRefs(currentNode))) &&
|
||||
NS_SUCCEEDED(mEditor->GetFirstTextNode(currentNode,getter_AddRefs(textNode))) &&
|
||||
NS_SUCCEEDED(textNode->QueryInterface(kIDOMCharacterDataIID, getter_AddRefs(text))))
|
||||
{
|
||||
// XXX: for now, just append the text
|
||||
PRUint32 offset;
|
||||
text->GetLength(&offset);
|
||||
InsertTextTxn *txn;
|
||||
txn = new InsertTextTxn(mEditor, text, offset, key);
|
||||
mEditor->ExecuteTransaction(txn);
|
||||
}
|
||||
}
|
||||
mEditor->InsertString(key);
|
||||
delete key;
|
||||
}
|
||||
break;
|
||||
}
|
||||
@ -213,7 +232,11 @@ nsEditorKeyListener::ProcessShortCutKeys(nsIDOMEvent* aKeyEvent, PRBool& aProces
|
||||
{
|
||||
if (NS_SUCCEEDED(currentNode->QueryInterface(kIDOMElementIID, getter_AddRefs(element))))
|
||||
{
|
||||
ChangeAttributeTxn *txn = new ChangeAttributeTxn(mEditor, element, attribute, value);
|
||||
ChangeAttributeTxn *txn;
|
||||
if (PR_TRUE==ctrlKey) // remove the attribute
|
||||
txn = new ChangeAttributeTxn(mEditor, element, attribute, value, PR_TRUE);
|
||||
else // change the attribute
|
||||
txn = new ChangeAttributeTxn(mEditor, element, attribute, value, PR_FALSE);
|
||||
mEditor->ExecuteTransaction(txn);
|
||||
}
|
||||
}
|
||||
@ -221,27 +244,6 @@ nsEditorKeyListener::ProcessShortCutKeys(nsIDOMEvent* aKeyEvent, PRBool& aProces
|
||||
aProcessed=PR_TRUE;
|
||||
break;
|
||||
|
||||
case nsIDOMEvent::VK_SPACE:
|
||||
{
|
||||
//XXX: should be from a factory
|
||||
//XXX: should manage the refcount of txn
|
||||
nsString attribute("height");
|
||||
nsString value("200");
|
||||
|
||||
nsString tableTag("TABLE");
|
||||
nsCOMPtr<nsIDOMNode> currentNode;
|
||||
nsCOMPtr<nsIDOMElement> element;
|
||||
if (NS_SUCCEEDED(mEditor->GetFirstNodeOfType(nsnull, tableTag, getter_AddRefs(currentNode))))
|
||||
{
|
||||
if (NS_SUCCEEDED(currentNode->QueryInterface(kIDOMElementIID, getter_AddRefs(element))))
|
||||
{
|
||||
ChangeAttributeTxn *txn = new ChangeAttributeTxn(mEditor, element, attribute, value);
|
||||
mEditor->ExecuteTransaction(txn);
|
||||
}
|
||||
}
|
||||
}
|
||||
aProcessed=PR_TRUE;
|
||||
break;
|
||||
}
|
||||
}
|
||||
return NS_OK;
|
||||
|
@ -26,6 +26,7 @@ CPPSRCS = \
|
||||
nsEditFactory.cpp \
|
||||
EditTxn.cpp \
|
||||
ChangeAttributeTxn.cpp \
|
||||
InsertTextTxn.cpp \
|
||||
$(NULL)
|
||||
|
||||
CPP_OBJS = \
|
||||
@ -34,6 +35,7 @@ CPP_OBJS = \
|
||||
.\$(OBJDIR)\editorInterfaces.obj \
|
||||
.\$(OBJDIR)\EditTxn.obj \
|
||||
.\$(OBJDIR)\ChangeAttributeTxn.obj \
|
||||
.\$(OBJDIR)\InsertTextTxn.obj \
|
||||
$(NULL)
|
||||
|
||||
MODULE=editor
|
||||
|
86
editor/core/InsertTextTxn.cpp
Normal file
86
editor/core/InsertTextTxn.cpp
Normal file
@ -0,0 +1,86 @@
|
||||
/* -*- 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 "InsertTextTxn.h"
|
||||
#include "editor.h"
|
||||
#include "nsIDOMCharacterData.h"
|
||||
|
||||
// note that aEditor is not refcounted
|
||||
InsertTextTxn::InsertTextTxn(nsEditor *aEditor,
|
||||
nsIDOMCharacterData *aElement,
|
||||
PRUint32 aOffset,
|
||||
const nsString& aStringToInsert)
|
||||
: EditTxn(aEditor)
|
||||
{
|
||||
mElement = aElement;
|
||||
mOffset = aOffset;
|
||||
mStringToInsert = aStringToInsert;
|
||||
}
|
||||
|
||||
nsresult InsertTextTxn::Do(void)
|
||||
{
|
||||
return (mElement->InsertData(mOffset, mStringToInsert));
|
||||
}
|
||||
|
||||
nsresult InsertTextTxn::Undo(void)
|
||||
{
|
||||
PRUint32 length = mStringToInsert.Length();
|
||||
return (mElement->DeleteData(mOffset, length));
|
||||
}
|
||||
|
||||
nsresult InsertTextTxn::Redo(void)
|
||||
{
|
||||
return Do();
|
||||
}
|
||||
|
||||
nsresult InsertTextTxn::GetIsTransient(PRBool *aIsTransient)
|
||||
{
|
||||
if (nsnull!=aIsTransient)
|
||||
*aIsTransient = PR_FALSE;
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
nsresult InsertTextTxn::Merge(PRBool *aDidMerge, nsITransaction *aTransaction)
|
||||
{
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
nsresult InsertTextTxn::Write(nsIOutputStream *aOutputStream)
|
||||
{
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
nsresult InsertTextTxn::GetUndoString(nsString **aString)
|
||||
{
|
||||
if (nsnull!=aString)
|
||||
{
|
||||
**aString="Remove Text: ";
|
||||
**aString += mStringToInsert;
|
||||
}
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
nsresult InsertTextTxn::GetRedoString(nsString **aString)
|
||||
{
|
||||
if (nsnull!=aString)
|
||||
{
|
||||
**aString="Insert Text: ";
|
||||
**aString += mStringToInsert;
|
||||
}
|
||||
return NS_OK;
|
||||
}
|
71
editor/core/InsertTextTxn.h
Normal file
71
editor/core/InsertTextTxn.h
Normal file
@ -0,0 +1,71 @@
|
||||
/* -*- 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.
|
||||
*/
|
||||
|
||||
#ifndef InsertTextTxn_h__
|
||||
#define InsertTextTxn_h__
|
||||
|
||||
#include "EditTxn.h"
|
||||
|
||||
class nsIDOMCharacterData;
|
||||
|
||||
/**
|
||||
* A transaction that changes an attribute of a content node.
|
||||
* This transaction covers add, remove, and change attribute.
|
||||
*/
|
||||
class InsertTextTxn : public EditTxn
|
||||
{
|
||||
public:
|
||||
|
||||
InsertTextTxn(nsEditor *aEditor,
|
||||
nsIDOMCharacterData *aElement,
|
||||
PRUint32 aOffset,
|
||||
const nsString& aStringToInsert);
|
||||
|
||||
virtual nsresult Do(void);
|
||||
|
||||
virtual nsresult Undo(void);
|
||||
|
||||
virtual nsresult Redo(void);
|
||||
|
||||
virtual nsresult GetIsTransient(PRBool *aIsTransient);
|
||||
|
||||
virtual nsresult Merge(PRBool *aDidMerge, nsITransaction *aTransaction);
|
||||
|
||||
virtual nsresult Write(nsIOutputStream *aOutputStream);
|
||||
|
||||
virtual nsresult GetUndoString(nsString **aString);
|
||||
|
||||
virtual nsresult GetRedoString(nsString **aString);
|
||||
|
||||
protected:
|
||||
|
||||
/** the text element to operate upon */
|
||||
nsIDOMCharacterData *mElement;
|
||||
|
||||
/** the offset into mElement where the insertion is to take place */
|
||||
PRUint32 mOffset;
|
||||
|
||||
/** the value to set the attribute to (ignored if mRemoveAttribute==PR_TRUE) */
|
||||
nsString mValue;
|
||||
|
||||
/** the text to insert into mElement at mOffset */
|
||||
nsString mStringToInsert;
|
||||
|
||||
};
|
||||
|
||||
#endif
|
@ -19,10 +19,14 @@
|
||||
#include "nsString.h"
|
||||
#include "editor.h"
|
||||
#include "ChangeAttributeTxn.h"
|
||||
#include "InsertTextTxn.h"
|
||||
#include "nsIDOMDocument.h"
|
||||
#include "nsIDOMElement.h"
|
||||
#include "nsIDOMCharacterData.h"
|
||||
|
||||
static NS_DEFINE_IID(kIDOMElementIID, NS_IDOMELEMENT_IID);
|
||||
static NS_DEFINE_IID(kIDOMCharacterDataIID, NS_IDOMCHARACTERDATA_IID);
|
||||
|
||||
|
||||
/*
|
||||
* nsEditorKeyListener implementation
|
||||
@ -129,15 +133,30 @@ nsEditorKeyListener::KeyDown(nsIDOMEvent* aKeyEvent)
|
||||
mEditor->Commit(ctrlKey);
|
||||
break;
|
||||
default:
|
||||
// XXX Replace with x-platform NS-virtkeycode transform.
|
||||
if (NS_OK == GetCharFromKeyCode(keyCode, isShift, & character)) {
|
||||
nsString* key = new nsString();
|
||||
*key += character;
|
||||
if (!isShift) {
|
||||
key->ToLowerCase();
|
||||
{
|
||||
// XXX Replace with x-platform NS-virtkeycode transform.
|
||||
if (NS_OK == GetCharFromKeyCode(keyCode, isShift, & character)) {
|
||||
nsString key;
|
||||
key += character;
|
||||
if (!isShift) {
|
||||
key.ToLowerCase();
|
||||
}
|
||||
|
||||
nsCOMPtr<nsIDOMNode> currentNode;
|
||||
nsCOMPtr<nsIDOMNode> textNode;
|
||||
nsCOMPtr<nsIDOMCharacterData> text;
|
||||
if (NS_SUCCEEDED(mEditor->GetCurrentNode(getter_AddRefs(currentNode))) &&
|
||||
NS_SUCCEEDED(mEditor->GetFirstTextNode(currentNode,getter_AddRefs(textNode))) &&
|
||||
NS_SUCCEEDED(textNode->QueryInterface(kIDOMCharacterDataIID, getter_AddRefs(text))))
|
||||
{
|
||||
// XXX: for now, just append the text
|
||||
PRUint32 offset;
|
||||
text->GetLength(&offset);
|
||||
InsertTextTxn *txn;
|
||||
txn = new InsertTextTxn(mEditor, text, offset, key);
|
||||
mEditor->ExecuteTransaction(txn);
|
||||
}
|
||||
}
|
||||
mEditor->InsertString(key);
|
||||
delete key;
|
||||
}
|
||||
break;
|
||||
}
|
||||
@ -213,7 +232,11 @@ nsEditorKeyListener::ProcessShortCutKeys(nsIDOMEvent* aKeyEvent, PRBool& aProces
|
||||
{
|
||||
if (NS_SUCCEEDED(currentNode->QueryInterface(kIDOMElementIID, getter_AddRefs(element))))
|
||||
{
|
||||
ChangeAttributeTxn *txn = new ChangeAttributeTxn(mEditor, element, attribute, value);
|
||||
ChangeAttributeTxn *txn;
|
||||
if (PR_TRUE==ctrlKey) // remove the attribute
|
||||
txn = new ChangeAttributeTxn(mEditor, element, attribute, value, PR_TRUE);
|
||||
else // change the attribute
|
||||
txn = new ChangeAttributeTxn(mEditor, element, attribute, value, PR_FALSE);
|
||||
mEditor->ExecuteTransaction(txn);
|
||||
}
|
||||
}
|
||||
@ -221,27 +244,6 @@ nsEditorKeyListener::ProcessShortCutKeys(nsIDOMEvent* aKeyEvent, PRBool& aProces
|
||||
aProcessed=PR_TRUE;
|
||||
break;
|
||||
|
||||
case nsIDOMEvent::VK_SPACE:
|
||||
{
|
||||
//XXX: should be from a factory
|
||||
//XXX: should manage the refcount of txn
|
||||
nsString attribute("height");
|
||||
nsString value("200");
|
||||
|
||||
nsString tableTag("TABLE");
|
||||
nsCOMPtr<nsIDOMNode> currentNode;
|
||||
nsCOMPtr<nsIDOMElement> element;
|
||||
if (NS_SUCCEEDED(mEditor->GetFirstNodeOfType(nsnull, tableTag, getter_AddRefs(currentNode))))
|
||||
{
|
||||
if (NS_SUCCEEDED(currentNode->QueryInterface(kIDOMElementIID, getter_AddRefs(element))))
|
||||
{
|
||||
ChangeAttributeTxn *txn = new ChangeAttributeTxn(mEditor, element, attribute, value);
|
||||
mEditor->ExecuteTransaction(txn);
|
||||
}
|
||||
}
|
||||
}
|
||||
aProcessed=PR_TRUE;
|
||||
break;
|
||||
}
|
||||
}
|
||||
return NS_OK;
|
||||
|
@ -26,6 +26,7 @@ CPPSRCS = \
|
||||
nsEditFactory.cpp \
|
||||
EditTxn.cpp \
|
||||
ChangeAttributeTxn.cpp \
|
||||
InsertTextTxn.cpp \
|
||||
$(NULL)
|
||||
|
||||
CPP_OBJS = \
|
||||
@ -34,6 +35,7 @@ CPP_OBJS = \
|
||||
.\$(OBJDIR)\editorInterfaces.obj \
|
||||
.\$(OBJDIR)\EditTxn.obj \
|
||||
.\$(OBJDIR)\ChangeAttributeTxn.obj \
|
||||
.\$(OBJDIR)\InsertTextTxn.obj \
|
||||
$(NULL)
|
||||
|
||||
MODULE=editor
|
||||
|
86
editor/libeditor/base/InsertTextTxn.cpp
Normal file
86
editor/libeditor/base/InsertTextTxn.cpp
Normal file
@ -0,0 +1,86 @@
|
||||
/* -*- 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 "InsertTextTxn.h"
|
||||
#include "editor.h"
|
||||
#include "nsIDOMCharacterData.h"
|
||||
|
||||
// note that aEditor is not refcounted
|
||||
InsertTextTxn::InsertTextTxn(nsEditor *aEditor,
|
||||
nsIDOMCharacterData *aElement,
|
||||
PRUint32 aOffset,
|
||||
const nsString& aStringToInsert)
|
||||
: EditTxn(aEditor)
|
||||
{
|
||||
mElement = aElement;
|
||||
mOffset = aOffset;
|
||||
mStringToInsert = aStringToInsert;
|
||||
}
|
||||
|
||||
nsresult InsertTextTxn::Do(void)
|
||||
{
|
||||
return (mElement->InsertData(mOffset, mStringToInsert));
|
||||
}
|
||||
|
||||
nsresult InsertTextTxn::Undo(void)
|
||||
{
|
||||
PRUint32 length = mStringToInsert.Length();
|
||||
return (mElement->DeleteData(mOffset, length));
|
||||
}
|
||||
|
||||
nsresult InsertTextTxn::Redo(void)
|
||||
{
|
||||
return Do();
|
||||
}
|
||||
|
||||
nsresult InsertTextTxn::GetIsTransient(PRBool *aIsTransient)
|
||||
{
|
||||
if (nsnull!=aIsTransient)
|
||||
*aIsTransient = PR_FALSE;
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
nsresult InsertTextTxn::Merge(PRBool *aDidMerge, nsITransaction *aTransaction)
|
||||
{
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
nsresult InsertTextTxn::Write(nsIOutputStream *aOutputStream)
|
||||
{
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
nsresult InsertTextTxn::GetUndoString(nsString **aString)
|
||||
{
|
||||
if (nsnull!=aString)
|
||||
{
|
||||
**aString="Remove Text: ";
|
||||
**aString += mStringToInsert;
|
||||
}
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
nsresult InsertTextTxn::GetRedoString(nsString **aString)
|
||||
{
|
||||
if (nsnull!=aString)
|
||||
{
|
||||
**aString="Insert Text: ";
|
||||
**aString += mStringToInsert;
|
||||
}
|
||||
return NS_OK;
|
||||
}
|
71
editor/libeditor/base/InsertTextTxn.h
Normal file
71
editor/libeditor/base/InsertTextTxn.h
Normal file
@ -0,0 +1,71 @@
|
||||
/* -*- 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.
|
||||
*/
|
||||
|
||||
#ifndef InsertTextTxn_h__
|
||||
#define InsertTextTxn_h__
|
||||
|
||||
#include "EditTxn.h"
|
||||
|
||||
class nsIDOMCharacterData;
|
||||
|
||||
/**
|
||||
* A transaction that changes an attribute of a content node.
|
||||
* This transaction covers add, remove, and change attribute.
|
||||
*/
|
||||
class InsertTextTxn : public EditTxn
|
||||
{
|
||||
public:
|
||||
|
||||
InsertTextTxn(nsEditor *aEditor,
|
||||
nsIDOMCharacterData *aElement,
|
||||
PRUint32 aOffset,
|
||||
const nsString& aStringToInsert);
|
||||
|
||||
virtual nsresult Do(void);
|
||||
|
||||
virtual nsresult Undo(void);
|
||||
|
||||
virtual nsresult Redo(void);
|
||||
|
||||
virtual nsresult GetIsTransient(PRBool *aIsTransient);
|
||||
|
||||
virtual nsresult Merge(PRBool *aDidMerge, nsITransaction *aTransaction);
|
||||
|
||||
virtual nsresult Write(nsIOutputStream *aOutputStream);
|
||||
|
||||
virtual nsresult GetUndoString(nsString **aString);
|
||||
|
||||
virtual nsresult GetRedoString(nsString **aString);
|
||||
|
||||
protected:
|
||||
|
||||
/** the text element to operate upon */
|
||||
nsIDOMCharacterData *mElement;
|
||||
|
||||
/** the offset into mElement where the insertion is to take place */
|
||||
PRUint32 mOffset;
|
||||
|
||||
/** the value to set the attribute to (ignored if mRemoveAttribute==PR_TRUE) */
|
||||
nsString mValue;
|
||||
|
||||
/** the text to insert into mElement at mOffset */
|
||||
nsString mStringToInsert;
|
||||
|
||||
};
|
||||
|
||||
#endif
|
Loading…
Reference in New Issue
Block a user