Implement Save, Save As in editor.
git-svn-id: svn://10.0.0.236/trunk@30665 18797224-902f-48f8-a5cc-f745e15eee43
This commit is contained in:
parent
eea6214816
commit
ebe41203f5
@ -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();
|
||||
|
||||
@ -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();
|
||||
|
||||
@ -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<nsIDOMDocument> doc;
|
||||
rv = GetDocument(getter_AddRefs(doc));
|
||||
if (NS_FAILED(rv) || !doc)
|
||||
return rv;
|
||||
|
||||
nsCOMPtr<nsIDiskDocument> 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<nsIFileWidget> 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();
|
||||
|
||||
@ -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();
|
||||
|
||||
@ -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();
|
||||
|
||||
@ -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();
|
||||
|
||||
@ -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;
|
||||
|
||||
@ -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?
|
||||
|
||||
@ -19,7 +19,7 @@
|
||||
|
||||
<window id="main-window" xmlns:html="http://www.w3.org/TR/REC-html40"
|
||||
xmlns="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul"
|
||||
onload="Startup()" title="Editor">
|
||||
onload="Startup()" onunload="Shutdown()" title="Editor">
|
||||
|
||||
<html:script language="JavaScript" src="chrome://editor/content/EditorCommands.js">
|
||||
</html:script>
|
||||
@ -29,13 +29,16 @@
|
||||
<menubar>
|
||||
<menu name="File">
|
||||
<menuitem name=".New" onclick=""/>
|
||||
<menuitem name=".Change Icons" onclick=""/>
|
||||
<menuitem name=".Open..." onclick=""/>
|
||||
<menuitem name=".Close" onclick="EditorClose()"/>
|
||||
<separator />
|
||||
<menuitem name=".Print Setup" onclick=""/>
|
||||
<menuitem name="Save" onclick="EditorSave()"/>
|
||||
<menuitem name="Save As..." onclick="EditorSaveAs()"/>
|
||||
<separator />
|
||||
<menuitem name=".Print Setup..." onclick=""/>
|
||||
<menuitem name="Print Preview" onclick="EditorPrintPreview()"/>
|
||||
<menuitem name=".Print" onclick=""/>
|
||||
<menuitem name=".Print..." onclick=""/>
|
||||
<separator />
|
||||
<menuitem name=".Close" onclick=""/>
|
||||
<menuitem name="Quit" onclick="EditorExit()"/>
|
||||
</menu>
|
||||
|
||||
|
||||
@ -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) {
|
||||
|
||||
@ -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();
|
||||
|
||||
@ -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);
|
||||
|
||||
@ -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<nsITextEditor> textEditor = do_QueryInterface(mEditor);
|
||||
if (textEditor)
|
||||
err = textEditor->Save();
|
||||
}
|
||||
break;
|
||||
case eHTMLTextEditorType:
|
||||
{
|
||||
nsCOMPtr<nsIHTMLEditor> 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<nsITextEditor> textEditor = do_QueryInterface(mEditor);
|
||||
if (textEditor)
|
||||
err = textEditor->SaveAs(PR_FALSE);
|
||||
}
|
||||
break;
|
||||
case eHTMLTextEditorType:
|
||||
{
|
||||
nsCOMPtr<nsIHTMLEditor> 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
|
||||
|
||||
@ -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();
|
||||
|
||||
@ -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},
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user