From ebe41203f5c0e4f3abb3309b4b407dc5bbbd82d0 Mon Sep 17 00:00:00 2001 From: "sfraser%netscape.com" Date: Fri, 7 May 1999 05:02:35 +0000 Subject: [PATCH] Implement Save, Save As in editor. git-svn-id: svn://10.0.0.236/trunk@30665 18797224-902f-48f8-a5cc-f745e15eee43 --- mozilla/editor/base/nsHTMLEditor.cpp | 10 ++ mozilla/editor/base/nsHTMLEditor.h | 4 + mozilla/editor/base/nsTextEditor.cpp | 66 +++++++++++- mozilla/editor/base/nsTextEditor.h | 8 ++ .../editor/libeditor/html/nsHTMLEditor.cpp | 10 ++ mozilla/editor/libeditor/html/nsHTMLEditor.h | 4 + mozilla/editor/public/nsIHTMLEditor.h | 6 ++ mozilla/editor/public/nsITextEditor.h | 16 ++- .../ui/composer/content/EditorAppShell.xul | 13 ++- .../ui/composer/content/EditorCommands.js | 36 +++++++ mozilla/xpfe/AppCores/idl/EditorAppCore.idl | 7 +- .../AppCores/public/nsIDOMEditorAppCore.h | 72 +++++++------ mozilla/xpfe/AppCores/src/nsEditorAppCore.cpp | 67 +++++++++++- mozilla/xpfe/AppCores/src/nsEditorAppCore.h | 4 + .../xpfe/AppCores/src/nsJSEditorAppCore.cpp | 102 ++++++++++++++++++ 15 files changed, 385 insertions(+), 40 deletions(-) diff --git a/mozilla/editor/base/nsHTMLEditor.cpp b/mozilla/editor/base/nsHTMLEditor.cpp index 25b2ad384a6..795cacf459d 100644 --- a/mozilla/editor/base/nsHTMLEditor.cpp +++ b/mozilla/editor/base/nsHTMLEditor.cpp @@ -349,6 +349,16 @@ NS_IMETHODIMP nsHTMLEditor::ScrollIntoView(PRBool aScrollToBegin) return nsTextEditor::ScrollIntoView(aScrollToBegin); } +NS_IMETHODIMP nsHTMLEditor::Save() +{ + return nsTextEditor::Save(); +} + +NS_IMETHODIMP nsHTMLEditor::SaveAs(PRBool aSavingCopy) +{ + return nsTextEditor::SaveAs(aSavingCopy); +} + NS_IMETHODIMP nsHTMLEditor::Cut() { return nsTextEditor::Cut(); diff --git a/mozilla/editor/base/nsHTMLEditor.h b/mozilla/editor/base/nsHTMLEditor.h index ad4ea563d9c..4e8480edc7d 100644 --- a/mozilla/editor/base/nsHTMLEditor.h +++ b/mozilla/editor/base/nsHTMLEditor.h @@ -86,6 +86,10 @@ public: NS_IMETHOD ScrollDown(nsIAtom *aIncrement); NS_IMETHOD ScrollIntoView(PRBool aScrollToBegin); +// file handling + NS_IMETHOD Save(); + NS_IMETHOD SaveAs(PRBool aSavingCopy); + // cut, copy & paste NS_IMETHOD Cut(); NS_IMETHOD Copy(); diff --git a/mozilla/editor/base/nsTextEditor.cpp b/mozilla/editor/base/nsTextEditor.cpp index f5f9440f651..fd806d00fc3 100644 --- a/mozilla/editor/base/nsTextEditor.cpp +++ b/mozilla/editor/base/nsTextEditor.cpp @@ -29,7 +29,7 @@ #include "nsHTMLContentSinkStream.h" #include "nsHTMLToTXTSinkStream.h" #include "nsXIFDTD.h" - +#include "nsFileSpec.h" #include "nsIDOMDocument.h" #include "nsIDOMEventReceiver.h" @@ -42,6 +42,7 @@ #include "nsIDOMCharacterData.h" #include "nsIDOMElement.h" #include "nsIDOMTextListener.h" +#include "nsIDiskDocument.h" #include "nsEditorCID.h" #include "nsISupportsArray.h" #include "nsIEnumerator.h" @@ -60,6 +61,10 @@ #include "nsIFileStream.h" #include "nsIStringStream.h" +#include "nsIAppSHell.h" +#include "nsIToolkit.h" +#include "nsWidgetsCID.h" +#include "nsIFileWidget.h" class nsIFrame; @@ -945,6 +950,65 @@ NS_IMETHODIMP nsTextEditor::ScrollIntoView(PRBool aScrollToBegin) return nsEditor::ScrollIntoView(aScrollToBegin); } +static NS_DEFINE_IID(kCFileWidgetCID, NS_FILEWIDGET_CID); +static NS_DEFINE_IID(kIFileWidgetIID, NS_IFILEWIDGET_IID); + +NS_IMETHODIMP nsTextEditor::SaveDocument(PRBool saveAs, PRBool saveCopy) +{ + nsresult rv = NS_OK; + + // get the document + nsCOMPtr doc; + rv = GetDocument(getter_AddRefs(doc)); + if (NS_FAILED(rv) || !doc) + return rv; + + nsCOMPtr diskDoc = do_QueryInterface(doc); + if (!diskDoc) + return NS_ERROR_NO_INTERFACE; + + // find out if the doc already has a fileSpec associated with it. + nsFileSpec docFileSpec; + PRBool mustShowFileDialog = saveAs || (diskDoc->GetFileSpec(docFileSpec) == NS_ERROR_NOT_INITIALIZED); + PRBool replacing = !saveAs; + + if (mustShowFileDialog) + { + nsCOMPtr fileWidget; + rv = nsComponentManager::CreateInstance(kCFileWidgetCID, nsnull, kIFileWidgetIID, getter_AddRefs(fileWidget)); + if (NS_SUCCEEDED(rv) && fileWidget) + { + nsAutoString promptString("Save this document as:"); // XXX i18n, l10n + nsFileDlgResults dialogResult; + dialogResult = fileWidget->PutFile(nsnull, promptString, docFileSpec); + if (dialogResult == nsFileDlgResults_Cancel) + return NS_OK; + + replacing = (dialogResult == nsFileDlgResults_Replace); + } + } + + nsAutoString charsetStr("ISO-8859-1"); + rv = diskDoc->SaveFile(&docFileSpec, replacing, saveCopy, nsIDiskDocument::eSaveFileHTML, charsetStr); + + if (NS_FAILED(rv)) + { + // show some error dialog? + } + + return rv; +} + +NS_IMETHODIMP nsTextEditor::Save() +{ + return SaveDocument(PR_FALSE, PR_FALSE); +} + +NS_IMETHODIMP nsTextEditor::SaveAs(PRBool aSavingCopy) +{ + return SaveDocument(PR_TRUE, aSavingCopy); +} + NS_IMETHODIMP nsTextEditor::Cut() { return nsEditor::Cut(); diff --git a/mozilla/editor/base/nsTextEditor.h b/mozilla/editor/base/nsTextEditor.h index 743b684377e..884e3238d2b 100644 --- a/mozilla/editor/base/nsTextEditor.h +++ b/mozilla/editor/base/nsTextEditor.h @@ -89,6 +89,10 @@ public: NS_IMETHOD ScrollDown(nsIAtom *aIncrement); NS_IMETHOD ScrollIntoView(PRBool aScrollToBegin); +// file handling + NS_IMETHOD Save(); + NS_IMETHOD SaveAs(PRBool aSavingCopy); + // cut, copy & paste NS_IMETHOD Cut(); NS_IMETHOD Copy(); @@ -109,6 +113,10 @@ public: protected: +// file handling utils + + NS_IMETHOD SaveDocument(PRBool saveAs, PRBool saveCopy); + // rules initialization virtual void InitRules(); diff --git a/mozilla/editor/libeditor/html/nsHTMLEditor.cpp b/mozilla/editor/libeditor/html/nsHTMLEditor.cpp index 25b2ad384a6..795cacf459d 100644 --- a/mozilla/editor/libeditor/html/nsHTMLEditor.cpp +++ b/mozilla/editor/libeditor/html/nsHTMLEditor.cpp @@ -349,6 +349,16 @@ NS_IMETHODIMP nsHTMLEditor::ScrollIntoView(PRBool aScrollToBegin) return nsTextEditor::ScrollIntoView(aScrollToBegin); } +NS_IMETHODIMP nsHTMLEditor::Save() +{ + return nsTextEditor::Save(); +} + +NS_IMETHODIMP nsHTMLEditor::SaveAs(PRBool aSavingCopy) +{ + return nsTextEditor::SaveAs(aSavingCopy); +} + NS_IMETHODIMP nsHTMLEditor::Cut() { return nsTextEditor::Cut(); diff --git a/mozilla/editor/libeditor/html/nsHTMLEditor.h b/mozilla/editor/libeditor/html/nsHTMLEditor.h index ad4ea563d9c..4e8480edc7d 100644 --- a/mozilla/editor/libeditor/html/nsHTMLEditor.h +++ b/mozilla/editor/libeditor/html/nsHTMLEditor.h @@ -86,6 +86,10 @@ public: NS_IMETHOD ScrollDown(nsIAtom *aIncrement); NS_IMETHOD ScrollIntoView(PRBool aScrollToBegin); +// file handling + NS_IMETHOD Save(); + NS_IMETHOD SaveAs(PRBool aSavingCopy); + // cut, copy & paste NS_IMETHOD Cut(); NS_IMETHOD Copy(); diff --git a/mozilla/editor/public/nsIHTMLEditor.h b/mozilla/editor/public/nsIHTMLEditor.h index 7963d55301b..4668ffa0d42 100644 --- a/mozilla/editor/public/nsIHTMLEditor.h +++ b/mozilla/editor/public/nsIHTMLEditor.h @@ -44,6 +44,8 @@ class nsIHTMLEditor : public nsISupports{ public: static const nsIID& GetIID() { static nsIID iid = NS_IHTMLEDITOR_IID; return iid; } + typedef enum {eSaveFileText = 0, eSaveFileHTML = 1 } ESaveFileType; + /** Initialize the text editor * */ @@ -80,6 +82,10 @@ public: NS_IMETHOD ScrollUp(nsIAtom *aIncrement)=0; NS_IMETHOD ScrollDown(nsIAtom *aIncrement)=0; NS_IMETHOD ScrollIntoView(PRBool aScrollToBegin)=0; + + NS_IMETHOD Save()=0; + NS_IMETHOD SaveAs(PRBool aSavingCopy)=0; + NS_IMETHOD Cut()=0; NS_IMETHOD Copy()=0; NS_IMETHOD Paste()=0; diff --git a/mozilla/editor/public/nsITextEditor.h b/mozilla/editor/public/nsITextEditor.h index 52c6a914156..8cbed49db2d 100644 --- a/mozilla/editor/public/nsITextEditor.h +++ b/mozilla/editor/public/nsITextEditor.h @@ -42,11 +42,11 @@ class nsString; * a single line plain text editor is instantiated by using the SingleLinePlainTextGUIManager * to limit UI and the SingleLinePlainTextEditRules to filter input and output. */ -class nsITextEditor : public nsISupports{ +class nsITextEditor : public nsISupports { public: typedef enum {ePlainText=0, eRichText=1} TextType; typedef enum {eSingleLine=0, eMultipleLines=1, ePassword=2} EditorType; - + static const nsIID& GetIID() { static nsIID iid = NS_ITEXTEDITOR_IID; return iid; } /** Initialize the text editor @@ -229,6 +229,18 @@ public: /** select the entire contents of the document */ NS_IMETHOD SelectAll()=0; + /** Respond to the menu 'Save' command; this may put up save UI if the document + * hasn't been saved yet. + */ + NS_IMETHOD Save()=0; + + /** Respond to the menu 'Save As' command; this will put up save UI + * @param aSavingCopy true if we are saving off a copy of the document + * without changing the disk file associated with the doc. + * This would correspond to a 'Save Copy As' menu command. + */ + NS_IMETHOD SaveAs(PRBool aSavingCopy)=0; + /** cut the currently selected text, putting it into the OS clipboard * What if no text is selected? * What about mixed selections? diff --git a/mozilla/editor/ui/composer/content/EditorAppShell.xul b/mozilla/editor/ui/composer/content/EditorAppShell.xul index 8a9be208bdb..b4cb06d2ef2 100644 --- a/mozilla/editor/ui/composer/content/EditorAppShell.xul +++ b/mozilla/editor/ui/composer/content/EditorAppShell.xul @@ -19,7 +19,7 @@ + onload="Startup()" onunload="Shutdown()" title="Editor"> @@ -29,13 +29,16 @@ - + + - + + + + - + - diff --git a/mozilla/editor/ui/composer/content/EditorCommands.js b/mozilla/editor/ui/composer/content/EditorCommands.js index 3e59ad28e98..8fa987c6764 100644 --- a/mozilla/editor/ui/composer/content/EditorCommands.js +++ b/mozilla/editor/ui/composer/content/EditorCommands.js @@ -41,6 +41,42 @@ } } + + function EditorSave() + { + dump("In EditorSave...\n"); + + appCore = XPAppCoresManager.Find(editorName); + if (appCore) + { + appCore.save(); + } + } + + function EditorSaveAs() + { + dump("In EditorSave...\n"); + + appCore = XPAppCoresManager.Find(editorName); + if (appCore) + { + appCore.saveAs(); + } + } + + function EditorClose() + { + dump("In EditorClose...\n"); + + appCore = XPAppCoresManager.Find(editorName); + if (appCore) + { + + + + } + } + function EditorFind(firstTime) { if (toolkitCore && firstTime) { diff --git a/mozilla/xpfe/AppCores/idl/EditorAppCore.idl b/mozilla/xpfe/AppCores/idl/EditorAppCore.idl index 3ab12cd4379..08e28e59a5c 100755 --- a/mozilla/xpfe/AppCores/idl/EditorAppCore.idl +++ b/mozilla/xpfe/AppCores/idl/EditorAppCore.idl @@ -17,8 +17,13 @@ interface EditorAppCore : BaseAppCore void setTextProperty(in DOMString prop, in DOMString attr, in DOMString value); void removeTextProperty(in DOMString prop, in DOMString attr); void getTextProperty(in DOMString prop, in DOMString attr, in DOMString value, out DOMString firstHas, out DOMString anyHas, out DOMString allHas); - + void setParagraphFormat(in DOMString value); + + void save(); + void saveAs(); + + void closeWindow(); void undo(); void redo(); diff --git a/mozilla/xpfe/AppCores/public/nsIDOMEditorAppCore.h b/mozilla/xpfe/AppCores/public/nsIDOMEditorAppCore.h index 5ff1a737985..751f85e5f90 100755 --- a/mozilla/xpfe/AppCores/public/nsIDOMEditorAppCore.h +++ b/mozilla/xpfe/AppCores/public/nsIDOMEditorAppCore.h @@ -58,6 +58,12 @@ public: NS_IMETHOD SetParagraphFormat(const nsString& aValue)=0; + NS_IMETHOD Save()=0; + + NS_IMETHOD SaveAs()=0; + + NS_IMETHOD CloseWindow()=0; + NS_IMETHOD Undo()=0; NS_IMETHOD Redo()=0; @@ -111,6 +117,9 @@ public: NS_IMETHOD RemoveTextProperty(const nsString& aProp, const nsString& aAttr); \ NS_IMETHOD GetTextProperty(const nsString& aProp, const nsString& aAttr, const nsString& aValue, nsString& aFirstHas, nsString& aAnyHas, nsString& aAllHas); \ NS_IMETHOD SetParagraphFormat(const nsString& aValue); \ + NS_IMETHOD Save(); \ + NS_IMETHOD SaveAs(); \ + NS_IMETHOD CloseWindow(); \ NS_IMETHOD Undo(); \ NS_IMETHOD Redo(); \ NS_IMETHOD Cut(); \ @@ -135,36 +144,39 @@ public: #define NS_FORWARD_IDOMEDITORAPPCORE(_to) \ - NS_IMETHOD GetContentsAsText(nsString& aContentsAsText) { return _to##GetContentsAsText(aContentsAsText); } \ - NS_IMETHOD GetContentsAsHTML(nsString& aContentsAsHTML) { return _to##GetContentsAsHTML(aContentsAsHTML); } \ - NS_IMETHOD GetEditorDocument(nsIDOMDocument** aEditorDocument) { return _to##GetEditorDocument(aEditorDocument); } \ - NS_IMETHOD GetEditorSelection(nsIDOMSelection** aEditorSelection) { return _to##GetEditorSelection(aEditorSelection); } \ - NS_IMETHOD GetParagraphFormat(nsString& aParagraphFormat) { return _to##GetParagraphFormat(aParagraphFormat); } \ - NS_IMETHOD SetEditorType(const nsString& aEditorType) { return _to##SetEditorType(aEditorType); } \ - NS_IMETHOD SetTextProperty(const nsString& aProp, const nsString& aAttr, const nsString& aValue) { return _to##SetTextProperty(aProp, aAttr, aValue); } \ - NS_IMETHOD RemoveTextProperty(const nsString& aProp, const nsString& aAttr) { return _to##RemoveTextProperty(aProp, aAttr); } \ - NS_IMETHOD GetTextProperty(const nsString& aProp, const nsString& aAttr, const nsString& aValue, nsString& aFirstHas, nsString& aAnyHas, nsString& aAllHas) { return _to##GetTextProperty(aProp, aAttr, aValue, aFirstHas, aAnyHas, aAllHas); } \ - NS_IMETHOD SetParagraphFormat(const nsString& aValue) { return _to##SetParagraphFormat(aValue); } \ - NS_IMETHOD Undo() { return _to##Undo(); } \ - NS_IMETHOD Redo() { return _to##Redo(); } \ - NS_IMETHOD Cut() { return _to##Cut(); } \ - NS_IMETHOD Copy() { return _to##Copy(); } \ - NS_IMETHOD Paste() { return _to##Paste(); } \ - NS_IMETHOD SelectAll() { return _to##SelectAll(); } \ - NS_IMETHOD Find(const nsString& aSearchTerm, PRBool aMatchCase, PRBool aSearchDown) { return _to##Find(aSearchTerm, aMatchCase, aSearchDown); } \ - NS_IMETHOD BeginBatchChanges() { return _to##BeginBatchChanges(); } \ - NS_IMETHOD EndBatchChanges() { return _to##EndBatchChanges(); } \ - NS_IMETHOD ShowClipboard() { return _to##ShowClipboard(); } \ - NS_IMETHOD InsertText(const nsString& aTextToInsert) { return _to##InsertText(aTextToInsert); } \ - NS_IMETHOD InsertLink() { return _to##InsertLink(); } \ - NS_IMETHOD InsertImage() { return _to##InsertImage(); } \ - NS_IMETHOD GetSelectedElement(const nsString& aTagName, nsIDOMElement** aReturn) { return _to##GetSelectedElement(aTagName, aReturn); } \ - NS_IMETHOD CreateElementWithDefaults(const nsString& aTagName, nsIDOMElement** aReturn) { return _to##CreateElementWithDefaults(aTagName, aReturn); } \ - NS_IMETHOD InsertElement(nsIDOMElement* aElement, PRBool aDeleteSelection, nsIDOMElement** aReturn) { return _to##InsertElement(aElement, aDeleteSelection, aReturn); } \ - NS_IMETHOD Exit() { return _to##Exit(); } \ - NS_IMETHOD SetToolbarWindow(nsIDOMWindow* aWin) { return _to##SetToolbarWindow(aWin); } \ - NS_IMETHOD SetContentWindow(nsIDOMWindow* aWin) { return _to##SetContentWindow(aWin); } \ - NS_IMETHOD SetWebShellWindow(nsIDOMWindow* aWin) { return _to##SetWebShellWindow(aWin); } \ + NS_IMETHOD GetContentsAsText(nsString& aContentsAsText) { return _to GetContentsAsText(aContentsAsText); } \ + NS_IMETHOD GetContentsAsHTML(nsString& aContentsAsHTML) { return _to GetContentsAsHTML(aContentsAsHTML); } \ + NS_IMETHOD GetEditorDocument(nsIDOMDocument** aEditorDocument) { return _to GetEditorDocument(aEditorDocument); } \ + NS_IMETHOD GetEditorSelection(nsIDOMSelection** aEditorSelection) { return _to GetEditorSelection(aEditorSelection); } \ + NS_IMETHOD GetParagraphFormat(nsString& aParagraphFormat) { return _to GetParagraphFormat(aParagraphFormat); } \ + NS_IMETHOD SetEditorType(const nsString& aEditorType) { return _to SetEditorType(aEditorType); } \ + NS_IMETHOD SetTextProperty(const nsString& aProp, const nsString& aAttr, const nsString& aValue) { return _to SetTextProperty(aProp, aAttr, aValue); } \ + NS_IMETHOD RemoveTextProperty(const nsString& aProp, const nsString& aAttr) { return _to RemoveTextProperty(aProp, aAttr); } \ + NS_IMETHOD GetTextProperty(const nsString& aProp, const nsString& aAttr, const nsString& aValue, nsString& aFirstHas, nsString& aAnyHas, nsString& aAllHas) { return _to GetTextProperty(aProp, aAttr, aValue, aFirstHas, aAnyHas, aAllHas); } \ + NS_IMETHOD SetParagraphFormat(const nsString& aValue) { return _to SetParagraphFormat(aValue); } \ + NS_IMETHOD Save() { return _to Save(); } \ + NS_IMETHOD SaveAs() { return _to SaveAs(); } \ + NS_IMETHOD CloseWindow() { return _to CloseWindow(); } \ + NS_IMETHOD Undo() { return _to Undo(); } \ + NS_IMETHOD Redo() { return _to Redo(); } \ + NS_IMETHOD Cut() { return _to Cut(); } \ + NS_IMETHOD Copy() { return _to Copy(); } \ + NS_IMETHOD Paste() { return _to Paste(); } \ + NS_IMETHOD SelectAll() { return _to SelectAll(); } \ + NS_IMETHOD Find(const nsString& aSearchTerm, PRBool aMatchCase, PRBool aSearchDown) { return _to Find(aSearchTerm, aMatchCase, aSearchDown); } \ + NS_IMETHOD BeginBatchChanges() { return _to BeginBatchChanges(); } \ + NS_IMETHOD EndBatchChanges() { return _to EndBatchChanges(); } \ + NS_IMETHOD ShowClipboard() { return _to ShowClipboard(); } \ + NS_IMETHOD InsertText(const nsString& aTextToInsert) { return _to InsertText(aTextToInsert); } \ + NS_IMETHOD InsertLink() { return _to InsertLink(); } \ + NS_IMETHOD InsertImage() { return _to InsertImage(); } \ + NS_IMETHOD GetSelectedElement(const nsString& aTagName, nsIDOMElement** aReturn) { return _to GetSelectedElement(aTagName, aReturn); } \ + NS_IMETHOD CreateElementWithDefaults(const nsString& aTagName, nsIDOMElement** aReturn) { return _to CreateElementWithDefaults(aTagName, aReturn); } \ + NS_IMETHOD InsertElement(nsIDOMElement* aElement, PRBool aDeleteSelection, nsIDOMElement** aReturn) { return _to InsertElement(aElement, aDeleteSelection, aReturn); } \ + NS_IMETHOD Exit() { return _to Exit(); } \ + NS_IMETHOD SetToolbarWindow(nsIDOMWindow* aWin) { return _to SetToolbarWindow(aWin); } \ + NS_IMETHOD SetContentWindow(nsIDOMWindow* aWin) { return _to SetContentWindow(aWin); } \ + NS_IMETHOD SetWebShellWindow(nsIDOMWindow* aWin) { return _to SetWebShellWindow(aWin); } \ extern "C" NS_DOM nsresult NS_InitEditorAppCoreClass(nsIScriptContext *aContext, void **aPrototype); diff --git a/mozilla/xpfe/AppCores/src/nsEditorAppCore.cpp b/mozilla/xpfe/AppCores/src/nsEditorAppCore.cpp index 328a216e45f..5be9ff6bd6c 100755 --- a/mozilla/xpfe/AppCores/src/nsEditorAppCore.cpp +++ b/mozilla/xpfe/AppCores/src/nsEditorAppCore.cpp @@ -55,6 +55,8 @@ #include "nsEditorMode.h" #include "nsIDOMSelection.h" +#include "nsIFileWidget.h" + /////////////////////////////////////// // Editor Includes /////////////////////////////////////// @@ -228,6 +230,7 @@ nsEditorAppCore::Init(const nsString& aId) (nsISupports**)&appCoreManager); if (NS_OK == rv) { appCoreManager->Add((nsIDOMBaseAppCore *)(nsBaseAppCore *)this); + nsServiceManager::ReleaseService(kAppCoresManagerCID, appCoreManager); } return rv; } @@ -690,7 +693,69 @@ nsEditorAppCore::SetWebShellWindow(nsIDOMWindow* aWin) NS_IMETHODIMP nsEditorAppCore::NewWindow() { - return NS_OK; + return NS_ERROR_NOT_IMPLEMENTED; +} + +NS_IMETHODIMP +nsEditorAppCore::Save() +{ + nsresult err = NS_NOINTERFACE; + + switch (mEditorType) + { + case ePlainTextEditorType: + { + nsCOMPtr textEditor = do_QueryInterface(mEditor); + if (textEditor) + err = textEditor->Save(); + } + break; + case eHTMLTextEditorType: + { + nsCOMPtr htmlEditor = do_QueryInterface(mEditor); + if (htmlEditor) + err = htmlEditor->Save(); + } + break; + default: + err = NS_ERROR_NOT_IMPLEMENTED; + } + + return err; +} + +NS_IMETHODIMP +nsEditorAppCore::SaveAs() +{ + nsresult err = NS_NOINTERFACE; + + switch (mEditorType) + { + case ePlainTextEditorType: + { + nsCOMPtr textEditor = do_QueryInterface(mEditor); + if (textEditor) + err = textEditor->SaveAs(PR_FALSE); + } + break; + case eHTMLTextEditorType: + { + nsCOMPtr htmlEditor = do_QueryInterface(mEditor); + if (htmlEditor) + err = htmlEditor->SaveAs(PR_FALSE); + } + break; + default: + err = NS_ERROR_NOT_IMPLEMENTED; + } + + return err; +} + +NS_IMETHODIMP +nsEditorAppCore::CloseWindow() +{ + return NS_ERROR_NOT_IMPLEMENTED; } NS_IMETHODIMP diff --git a/mozilla/xpfe/AppCores/src/nsEditorAppCore.h b/mozilla/xpfe/AppCores/src/nsEditorAppCore.h index 679db3df169..32e2166b957 100755 --- a/mozilla/xpfe/AppCores/src/nsEditorAppCore.h +++ b/mozilla/xpfe/AppCores/src/nsEditorAppCore.h @@ -88,6 +88,10 @@ class nsEditorAppCore : public nsBaseAppCore, NS_IMETHOD GetEditorSelection(nsIDOMSelection** aEditorSelection); + NS_IMETHOD Save(); + NS_IMETHOD SaveAs(); + NS_IMETHOD CloseWindow(); + NS_IMETHOD Undo(); NS_IMETHOD Redo(); NS_IMETHOD Back(); diff --git a/mozilla/xpfe/AppCores/src/nsJSEditorAppCore.cpp b/mozilla/xpfe/AppCores/src/nsJSEditorAppCore.cpp index e4d1e8b791a..8531c80e851 100755 --- a/mozilla/xpfe/AppCores/src/nsJSEditorAppCore.cpp +++ b/mozilla/xpfe/AppCores/src/nsJSEditorAppCore.cpp @@ -409,6 +409,105 @@ EditorAppCoreSetParagraphFormat(JSContext *cx, JSObject *obj, uintN argc, jsval } +// +// Native method Save +// +PR_STATIC_CALLBACK(JSBool) +EditorAppCoreSave(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval) +{ + nsIDOMEditorAppCore *nativeThis = (nsIDOMEditorAppCore*)JS_GetPrivate(cx, obj); + JSBool rBool = JS_FALSE; + + *rval = JSVAL_NULL; + + // 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->Save()) { + return JS_FALSE; + } + + *rval = JSVAL_VOID; + } + else { + JS_ReportError(cx, "Function save requires 0 parameters"); + return JS_FALSE; + } + + return JS_TRUE; +} + + +// +// Native method SaveAs +// +PR_STATIC_CALLBACK(JSBool) +EditorAppCoreSaveAs(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval) +{ + nsIDOMEditorAppCore *nativeThis = (nsIDOMEditorAppCore*)JS_GetPrivate(cx, obj); + JSBool rBool = JS_FALSE; + + *rval = JSVAL_NULL; + + // 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->SaveAs()) { + return JS_FALSE; + } + + *rval = JSVAL_VOID; + } + else { + JS_ReportError(cx, "Function saveAs requires 0 parameters"); + return JS_FALSE; + } + + return JS_TRUE; +} + + +// +// Native method CloseWindow +// +PR_STATIC_CALLBACK(JSBool) +EditorAppCoreCloseWindow(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval) +{ + nsIDOMEditorAppCore *nativeThis = (nsIDOMEditorAppCore*)JS_GetPrivate(cx, obj); + JSBool rBool = JS_FALSE; + + *rval = JSVAL_NULL; + + // 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->CloseWindow()) { + return JS_FALSE; + } + + *rval = JSVAL_VOID; + } + else { + JS_ReportError(cx, "Function closeWindow requires 0 parameters"); + return JS_FALSE; + } + + return JS_TRUE; +} + + // // Native method Undo // @@ -1177,6 +1276,9 @@ static JSFunctionSpec EditorAppCoreMethods[] = {"removeTextProperty", EditorAppCoreRemoveTextProperty, 2}, {"getTextProperty", EditorAppCoreGetTextProperty, 6}, {"setParagraphFormat", EditorAppCoreSetParagraphFormat, 1}, + {"save", EditorAppCoreSave, 0}, + {"saveAs", EditorAppCoreSaveAs, 0}, + {"closeWindow", EditorAppCoreCloseWindow, 0}, {"undo", EditorAppCoreUndo, 0}, {"redo", EditorAppCoreRedo, 0}, {"cut", EditorAppCoreCut, 0},