Add paste/insert as quotation into editor app cores to be accessible from JS.

This commit is contained in:
akkana%netscape.com 1999-05-28 00:46:34 +00:00
Родитель 721d89cf51
Коммит ee4632cddb
14 изменённых файлов: 377 добавлений и 13 удалений

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

@ -421,7 +421,7 @@ NS_IMETHODIMP nsHTMLEditor::PasteAsQuotation()
return PasteAsCitedQuotation(citation);
}
NS_IMETHODIMP nsHTMLEditor::PasteAsCitedQuotation(nsString& aCitation)
NS_IMETHODIMP nsHTMLEditor::PasteAsCitedQuotation(const nsString& aCitation)
{
printf("nsHTMLEditor::PasteAsQuotation\n");
@ -474,7 +474,7 @@ NS_IMETHODIMP nsHTMLEditor::InsertAsQuotation(const nsString& aQuotedText)
}
NS_IMETHODIMP nsHTMLEditor::InsertAsCitedQuotation(const nsString& aQuotedText,
nsString& aCitation)
const nsString& aCitation)
{
printf("nsHTMLEditor::InsertAsQuotation\n");

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

@ -95,9 +95,10 @@ public:
NS_IMETHOD Copy();
NS_IMETHOD Paste();
NS_IMETHOD PasteAsQuotation();
NS_IMETHOD PasteAsCitedQuotation(nsString& aCitation);
NS_IMETHOD PasteAsCitedQuotation(const nsString& aCitation);
NS_IMETHOD InsertAsQuotation(const nsString& aQuotedText);
NS_IMETHOD InsertAsCitedQuotation(const nsString& aQuotedText, nsString& aCitation);
NS_IMETHOD InsertAsCitedQuotation(const nsString& aQuotedText,
const nsString& aCitation);
// Input/Output
NS_IMETHOD InsertHTML(const nsString& aInputString);

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

@ -421,7 +421,7 @@ NS_IMETHODIMP nsHTMLEditor::PasteAsQuotation()
return PasteAsCitedQuotation(citation);
}
NS_IMETHODIMP nsHTMLEditor::PasteAsCitedQuotation(nsString& aCitation)
NS_IMETHODIMP nsHTMLEditor::PasteAsCitedQuotation(const nsString& aCitation)
{
printf("nsHTMLEditor::PasteAsQuotation\n");
@ -474,7 +474,7 @@ NS_IMETHODIMP nsHTMLEditor::InsertAsQuotation(const nsString& aQuotedText)
}
NS_IMETHODIMP nsHTMLEditor::InsertAsCitedQuotation(const nsString& aQuotedText,
nsString& aCitation)
const nsString& aCitation)
{
printf("nsHTMLEditor::InsertAsQuotation\n");

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

@ -95,9 +95,10 @@ public:
NS_IMETHOD Copy();
NS_IMETHOD Paste();
NS_IMETHOD PasteAsQuotation();
NS_IMETHOD PasteAsCitedQuotation(nsString& aCitation);
NS_IMETHOD PasteAsCitedQuotation(const nsString& aCitation);
NS_IMETHOD InsertAsQuotation(const nsString& aQuotedText);
NS_IMETHOD InsertAsCitedQuotation(const nsString& aQuotedText, nsString& aCitation);
NS_IMETHOD InsertAsCitedQuotation(const nsString& aQuotedText,
const nsString& aCitation);
// Input/Output
NS_IMETHOD InsertHTML(const nsString& aInputString);

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

@ -91,9 +91,9 @@ public:
NS_IMETHOD Copy()=0;
NS_IMETHOD Paste()=0;
NS_IMETHOD PasteAsQuotation()=0;
NS_IMETHOD PasteAsCitedQuotation(nsString& aCitation)=0;
NS_IMETHOD PasteAsCitedQuotation(const nsString& aCitation)=0;
NS_IMETHOD InsertAsQuotation(const nsString& aQuotedText)=0;
NS_IMETHOD InsertAsCitedQuotation(const nsString& aQuotedText, nsString& aCitation)=0;
NS_IMETHOD InsertAsCitedQuotation(const nsString& aQuotedText, const nsString& aCitation)=0;
NS_IMETHOD InsertHTML(const nsString &aInputString)=0;

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

@ -51,6 +51,7 @@
<menuitem name="Cut" onclick="EditorCut()"/>
<menuitem name="Copy" onclick="EditorCopy()"/>
<menuitem name="Paste" onclick="EditorPaste()"/>
<menuitem name="Paste as Quotation" onclick="EditorPasteAsQuotation()"/>
<menuitem name=".Clear" onclick=""/>
<separator />
<menuitem name="Select All" onclick="EditorSelectAll()"/>

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

@ -191,7 +191,6 @@ function EditorRedo()
function EditorCut()
{
if (appCore) {
dump("Cutting\n");
appCore.cut();
}
}
@ -199,7 +198,6 @@ function EditorCut()
function EditorCopy()
{
if (appCore) {
dump("Copying\n");
appCore.copy();
}
}
@ -207,11 +205,24 @@ function EditorCopy()
function EditorPaste()
{
if (appCore) {
dump("Pasting\n");
appCore.paste();
}
}
function EditorPasteAsQuotation()
{
if (appCore) {
appCore.pasteAsQuotation();
}
}
function EditorPasteAsQuotationCited(citeString)
{
if (appCore) {
appCore.pasteAsQuotationCited(CiteString);
}
}
function EditorSelectAll()
{
if (appCore) {

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

@ -51,6 +51,7 @@
<menuitem name="Cut" onclick="EditorCut()"/>
<menuitem name="Copy" onclick="EditorCopy()"/>
<menuitem name="Paste" onclick="EditorPaste()"/>
<menuitem name="Paste as Quotation" onclick="EditorPasteAsQuotation()"/>
<menuitem name=".Clear" onclick=""/>
<separator />
<menuitem name="Select All" onclick="EditorSelectAll()"/>

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

@ -51,6 +51,7 @@
<menuitem name="Cut" onclick="EditorCut()"/>
<menuitem name="Copy" onclick="EditorCopy()"/>
<menuitem name="Paste" onclick="EditorPaste()"/>
<menuitem name="Paste as Quotation" onclick="EditorPasteAsQuotation()"/>
<menuitem name=".Clear" onclick=""/>
<separator />
<menuitem name="Select All" onclick="EditorSelectAll()"/>

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

@ -42,6 +42,11 @@ interface EditorAppCore : BaseAppCore
void cut();
void copy();
void paste();
void pasteAsQuotation();
void pasteAsCitedQuotation(in DOMString cite);
void insertAsQuotation(in DOMString quotedText);
void insertAsCitedQuotation(in DOMString quotedText, in DOMString cite);
void selectAll();

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

@ -93,6 +93,14 @@ public:
NS_IMETHOD Paste()=0;
NS_IMETHOD PasteAsQuotation()=0;
NS_IMETHOD PasteAsCitedQuotation(const nsString& aCite)=0;
NS_IMETHOD InsertAsQuotation(const nsString& aQuotedText)=0;
NS_IMETHOD InsertAsCitedQuotation(const nsString& aQuotedText, const nsString& aCite)=0;
NS_IMETHOD SelectAll()=0;
NS_IMETHOD Find()=0;
@ -186,6 +194,10 @@ public:
NS_IMETHOD Cut(); \
NS_IMETHOD Copy(); \
NS_IMETHOD Paste(); \
NS_IMETHOD PasteAsQuotation(); \
NS_IMETHOD PasteAsCitedQuotation(const nsString& aCite); \
NS_IMETHOD InsertAsQuotation(const nsString& aQuotedText); \
NS_IMETHOD InsertAsCitedQuotation(const nsString& aQuotedText, const nsString& aCite); \
NS_IMETHOD SelectAll(); \
NS_IMETHOD Find(); \
NS_IMETHOD FindNext(); \
@ -249,6 +261,10 @@ public:
NS_IMETHOD Cut() { return _to Cut(); } \
NS_IMETHOD Copy() { return _to Copy(); } \
NS_IMETHOD Paste() { return _to Paste(); } \
NS_IMETHOD PasteAsQuotation() { return _to PasteAsQuotation(); } \
NS_IMETHOD PasteAsCitedQuotation(const nsString& aCite) { return _to PasteAsCitedQuotation(aCite); } \
NS_IMETHOD InsertAsQuotation(const nsString& aQuotedText) { return _to InsertAsQuotation(aQuotedText); } \
NS_IMETHOD InsertAsCitedQuotation(const nsString& aQuotedText, const nsString& aCite) { return _to InsertAsCitedQuotation(aQuotedText, aCite); } \
NS_IMETHOD SelectAll() { return _to SelectAll(); } \
NS_IMETHOD Find() { return _to Find(); } \
NS_IMETHOD FindNext() { return _to FindNext(); } \

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

@ -1097,6 +1097,119 @@ nsEditorAppCore::Paste()
return err;
}
NS_IMETHODIMP
nsEditorAppCore::PasteAsQuotation()
{
nsresult err = NS_NOINTERFACE;
switch (mEditorType)
{
case ePlainTextEditorType:
{
nsCOMPtr<nsITextEditor> textEditor = do_QueryInterface(mEditor);
if (textEditor)
err = textEditor->PasteAsQuotation();
}
break;
case eHTMLTextEditorType:
{
nsCOMPtr<nsIHTMLEditor> htmlEditor = do_QueryInterface(mEditor);
if (htmlEditor)
err = htmlEditor->PasteAsQuotation();
}
break;
default:
err = NS_ERROR_NOT_IMPLEMENTED;
}
return err;
}
NS_IMETHODIMP
nsEditorAppCore::PasteAsCitedQuotation(const nsString& aCiteString)
{
nsresult err = NS_NOINTERFACE;
switch (mEditorType)
{
case ePlainTextEditorType:
{
nsCOMPtr<nsITextEditor> textEditor = do_QueryInterface(mEditor);
if (textEditor)
err = textEditor->PasteAsQuotation();
}
break;
case eHTMLTextEditorType:
{
nsCOMPtr<nsIHTMLEditor> htmlEditor = do_QueryInterface(mEditor);
if (htmlEditor)
err = htmlEditor->PasteAsCitedQuotation(aCiteString);
}
break;
default:
err = NS_ERROR_NOT_IMPLEMENTED;
}
return err;
}
NS_IMETHODIMP
nsEditorAppCore::InsertAsQuotation(const nsString& aQuotedText)
{
nsresult err = NS_NOINTERFACE;
switch (mEditorType)
{
case ePlainTextEditorType:
{
nsCOMPtr<nsITextEditor> textEditor = do_QueryInterface(mEditor);
if (textEditor)
err = textEditor->InsertAsQuotation(aQuotedText);
}
break;
case eHTMLTextEditorType:
{
nsCOMPtr<nsIHTMLEditor> htmlEditor = do_QueryInterface(mEditor);
if (htmlEditor)
err = htmlEditor->InsertAsQuotation(aQuotedText);
}
break;
default:
err = NS_ERROR_NOT_IMPLEMENTED;
}
return err;
}
NS_IMETHODIMP
nsEditorAppCore::InsertAsCitedQuotation(const nsString& aQuotedText,
const nsString& aCiteString)
{
nsresult err = NS_NOINTERFACE;
switch (mEditorType)
{
case ePlainTextEditorType:
{
nsCOMPtr<nsITextEditor> textEditor = do_QueryInterface(mEditor);
if (textEditor)
err = textEditor->InsertAsQuotation(aQuotedText);
}
break;
case eHTMLTextEditorType:
{
nsCOMPtr<nsIHTMLEditor> htmlEditor = do_QueryInterface(mEditor);
if (htmlEditor)
err = htmlEditor->InsertAsCitedQuotation(aQuotedText, aCiteString);
}
break;
default:
err = NS_ERROR_NOT_IMPLEMENTED;
}
return err;
}
NS_IMETHODIMP
nsEditorAppCore::SelectAll()
{

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

@ -129,8 +129,14 @@ class nsEditorAppCore : public nsBaseAppCore,
NS_IMETHOD Cut();
NS_IMETHOD Copy();
NS_IMETHOD Paste();
NS_IMETHOD PasteAsQuotation();
NS_IMETHOD PasteAsCitedQuotation(const nsString& aCiteString);
NS_IMETHOD SelectAll();
NS_IMETHOD InsertAsQuotation(const nsString& aquotedText);
NS_IMETHOD InsertAsCitedQuotation(const nsString& aquotedText,
const nsString& aCiteString);
NS_IMETHOD InsertText(const nsString& textToInsert);
NS_IMETHOD Find();
NS_IMETHOD FindNext();

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

@ -1355,6 +1355,210 @@ EditorAppCorePaste(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval
}
//
// Native method PasteAsQuotation
//
PR_STATIC_CALLBACK(JSBool)
EditorAppCorePasteAsQuotation(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval)
{
nsIDOMEditorAppCore *nativeThis = (nsIDOMEditorAppCore*)JS_GetPrivate(cx, obj);
JSBool rBool = JS_FALSE;
*rval = JSVAL_NULL;
nsIScriptContext *scriptCX = (nsIScriptContext *)JS_GetContextPrivate(cx);
nsIScriptSecurityManager *secMan;
if (NS_OK == scriptCX->GetSecurityManager(&secMan)) {
PRBool ok;
secMan->CheckScriptAccess(scriptCX, obj, "editorappcore.pasteasquotation", &ok);
if (!ok) {
//Need to throw error here
return JS_FALSE;
}
NS_RELEASE(secMan);
}
else {
return JS_FALSE;
}
// If there's no private data, this must be the prototype, so ignore
if (nsnull == nativeThis) {
return JS_TRUE;
}
if (argc >= 0) {
if (NS_OK != nativeThis->PasteAsQuotation()) {
return JS_FALSE;
}
*rval = JSVAL_VOID;
}
else {
JS_ReportError(cx, "Function pasteAsQuotation requires 0 parameters");
return JS_FALSE;
}
return JS_TRUE;
}
//
// Native method PasteAsCitedQuotation
//
PR_STATIC_CALLBACK(JSBool)
EditorAppCorePasteAsCitedQuotation(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval)
{
nsIDOMEditorAppCore *nativeThis = (nsIDOMEditorAppCore*)JS_GetPrivate(cx, obj);
JSBool rBool = JS_FALSE;
nsAutoString b0;
*rval = JSVAL_NULL;
nsIScriptContext *scriptCX = (nsIScriptContext *)JS_GetContextPrivate(cx);
nsIScriptSecurityManager *secMan;
if (NS_OK == scriptCX->GetSecurityManager(&secMan)) {
PRBool ok;
secMan->CheckScriptAccess(scriptCX, obj, "editorappcore.pasteascitedquotation", &ok);
if (!ok) {
//Need to throw error here
return JS_FALSE;
}
NS_RELEASE(secMan);
}
else {
return JS_FALSE;
}
// If there's no private data, this must be the prototype, so ignore
if (nsnull == nativeThis) {
return JS_TRUE;
}
if (argc >= 1) {
nsJSUtils::nsConvertJSValToString(b0, cx, argv[0]);
if (NS_OK != nativeThis->PasteAsCitedQuotation(b0)) {
return JS_FALSE;
}
*rval = JSVAL_VOID;
}
else {
JS_ReportError(cx, "Function pasteAsCitedQuotation requires 1 parameters");
return JS_FALSE;
}
return JS_TRUE;
}
//
// Native method InsertAsQuotation
//
PR_STATIC_CALLBACK(JSBool)
EditorAppCoreInsertAsQuotation(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval)
{
nsIDOMEditorAppCore *nativeThis = (nsIDOMEditorAppCore*)JS_GetPrivate(cx, obj);
JSBool rBool = JS_FALSE;
nsAutoString b0;
*rval = JSVAL_NULL;
nsIScriptContext *scriptCX = (nsIScriptContext *)JS_GetContextPrivate(cx);
nsIScriptSecurityManager *secMan;
if (NS_OK == scriptCX->GetSecurityManager(&secMan)) {
PRBool ok;
secMan->CheckScriptAccess(scriptCX, obj, "editorappcore.insertasquotation", &ok);
if (!ok) {
//Need to throw error here
return JS_FALSE;
}
NS_RELEASE(secMan);
}
else {
return JS_FALSE;
}
// If there's no private data, this must be the prototype, so ignore
if (nsnull == nativeThis) {
return JS_TRUE;
}
if (argc >= 1) {
nsJSUtils::nsConvertJSValToString(b0, cx, argv[0]);
if (NS_OK != nativeThis->InsertAsQuotation(b0)) {
return JS_FALSE;
}
*rval = JSVAL_VOID;
}
else {
JS_ReportError(cx, "Function insertAsQuotation requires 1 parameters");
return JS_FALSE;
}
return JS_TRUE;
}
//
// Native method InsertAsCitedQuotation
//
PR_STATIC_CALLBACK(JSBool)
EditorAppCoreInsertAsCitedQuotation(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval)
{
nsIDOMEditorAppCore *nativeThis = (nsIDOMEditorAppCore*)JS_GetPrivate(cx, obj);
JSBool rBool = JS_FALSE;
nsAutoString b0;
nsAutoString b1;
*rval = JSVAL_NULL;
nsIScriptContext *scriptCX = (nsIScriptContext *)JS_GetContextPrivate(cx);
nsIScriptSecurityManager *secMan;
if (NS_OK == scriptCX->GetSecurityManager(&secMan)) {
PRBool ok;
secMan->CheckScriptAccess(scriptCX, obj, "editorappcore.insertascitedquotation", &ok);
if (!ok) {
//Need to throw error here
return JS_FALSE;
}
NS_RELEASE(secMan);
}
else {
return JS_FALSE;
}
// If there's no private data, this must be the prototype, so ignore
if (nsnull == nativeThis) {
return JS_TRUE;
}
if (argc >= 2) {
nsJSUtils::nsConvertJSValToString(b0, cx, argv[0]);
nsJSUtils::nsConvertJSValToString(b1, cx, argv[1]);
if (NS_OK != nativeThis->InsertAsCitedQuotation(b0, b1)) {
return JS_FALSE;
}
*rval = JSVAL_VOID;
}
else {
JS_ReportError(cx, "Function insertAsCitedQuotation requires 2 parameters");
return JS_FALSE;
}
return JS_TRUE;
}
//
// Native method SelectAll
//
@ -3019,6 +3223,10 @@ static JSFunctionSpec EditorAppCoreMethods[] =
{"cut", EditorAppCoreCut, 0},
{"copy", EditorAppCoreCopy, 0},
{"paste", EditorAppCorePaste, 0},
{"pasteAsQuotation", EditorAppCorePasteAsQuotation, 0},
{"pasteAsCitedQuotation", EditorAppCorePasteAsCitedQuotation, 1},
{"insertAsQuotation", EditorAppCoreInsertAsQuotation, 1},
{"insertAsCitedQuotation", EditorAppCoreInsertAsCitedQuotation, 2},
{"selectAll", EditorAppCoreSelectAll, 0},
{"find", EditorAppCoreFind, 0},
{"findNext", EditorAppCoreFindNext, 0},