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:
@@ -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) {
|
||||
|
||||
Reference in New Issue
Block a user