diff --git a/editor/base/nsEditor.cpp b/editor/base/nsEditor.cpp index 410888207c2d..b8c734ce1e24 100644 --- a/editor/base/nsEditor.cpp +++ b/editor/base/nsEditor.cpp @@ -155,6 +155,7 @@ nsEditor::nsEditor() , mDocDirtyState(-1) , mDoc(nsnull) , mPrefs(nsnull) +, mDocCharset("ISO-8859-1") #ifdef ENABLE_JS_EDITOR_LOG , mJSEditorLog(nsnull) , mJSTxnLog(nsnull) @@ -430,8 +431,7 @@ NS_IMETHODIMP nsEditor::SaveDocument(PRBool saveAs, PRBool saveCopy) } } - nsAutoString charsetStr(""); - rv = diskDoc->SaveFile(&docFileSpec, replacing, saveCopy, nsIDiskDocument::eSaveFileHTML, charsetStr); + rv = diskDoc->SaveFile(&docFileSpec, replacing, saveCopy, nsIDiskDocument::eSaveFileHTML, mDocCharset); if (NS_FAILED(rv)) { @@ -805,6 +805,24 @@ nsEditor::GetDocumentModified(PRBool *outDocModified) return NS_OK; } +NS_IMETHODIMP +nsEditor::GetDocumentCharacterSet(PRUnichar** characterSet) +{ + *characterSet = mDocCharset.ToNewUnicode(); + return NS_OK; +} + +NS_IMETHODIMP +nsEditor::SetDocumentCharacterSet(const PRUnichar* characterSet) +{ + if (characterSet!=NULL) { + mDocCharset = characterSet; + return NS_OK; + } + + return NS_ERROR_FAILURE; +} + /* NS_IMETHODIMP diff --git a/editor/base/nsEditor.h b/editor/base/nsEditor.h index f77c20e0511e..1bd8e48b70c9 100644 --- a/editor/base/nsEditor.h +++ b/editor/base/nsEditor.h @@ -134,6 +134,8 @@ public: NS_IMETHOD Save(); NS_IMETHOD SaveAs(PRBool aSavingCopy); NS_IMETHOD GetDocumentModified(PRBool *outDocModified); + NS_IMETHOD GetDocumentCharacterSet(PRUnichar** characterSet); + NS_IMETHOD SetDocumentCharacterSet(const PRUnichar* characterSet); // these are pure virtual in this base class NS_IMETHOD Cut() = 0; @@ -619,6 +621,9 @@ protected: // Services are not nsCOMPtr friendly nsIPref* mPrefs; + //Document 'SaveAs' charset + nsString mDocCharset; + #ifdef ENABLE_JS_EDITOR_LOG nsJSEditorLog *mJSEditorLog; nsJSTxnLog *mJSTxnLog; diff --git a/editor/base/nsEditorShell.cpp b/editor/base/nsEditorShell.cpp index 9ca61c98ce84..570169fb7bdb 100644 --- a/editor/base/nsEditorShell.cpp +++ b/editor/base/nsEditorShell.cpp @@ -1520,6 +1520,29 @@ nsEditorShell::FindNext() return DoFind(PR_TRUE); } +NS_IMETHODIMP +nsEditorShell::GetDocumentCharacterSet(PRUnichar** characterSet) +{ + nsCOMPtr editor = do_QueryInterface(mEditor); + + if (editor) + return editor->GetDocumentCharacterSet(characterSet); + + return NS_ERROR_FAILURE; +} + +NS_IMETHODIMP +nsEditorShell::SetDocumentCharacterSet(const PRUnichar* characterSet) +{ + nsCOMPtr editor = do_QueryInterface(mEditor); + + if (editor) + return editor->SetDocumentCharacterSet(characterSet); + + return NS_ERROR_FAILURE; + +} + NS_IMETHODIMP nsEditorShell::GetContentsAs(const PRUnichar *format, PRUint32 flags, PRUnichar **contentsAs) diff --git a/editor/base/nsEditorShell.h b/editor/base/nsEditorShell.h index 42c87834742a..fde6eec10b62 100644 --- a/editor/base/nsEditorShell.h +++ b/editor/base/nsEditorShell.h @@ -128,6 +128,10 @@ class nsEditorShell : public nsIEditorShell, NS_IMETHOD Find(); NS_IMETHOD FindNext(); + /* Charset Menu */ + NS_IMETHOD GetDocumentCharacterSet(PRUnichar **characterSet); + NS_IMETHOD SetDocumentCharacterSet(const PRUnichar *characterSet); + /* void InsertText (in wstring textToInsert); */ NS_IMETHOD InsertText(const PRUnichar *textToInsert); NS_IMETHOD InsertSource(const PRUnichar *sourceToInsert); diff --git a/editor/composer/src/nsEditorShell.cpp b/editor/composer/src/nsEditorShell.cpp index 9ca61c98ce84..570169fb7bdb 100644 --- a/editor/composer/src/nsEditorShell.cpp +++ b/editor/composer/src/nsEditorShell.cpp @@ -1520,6 +1520,29 @@ nsEditorShell::FindNext() return DoFind(PR_TRUE); } +NS_IMETHODIMP +nsEditorShell::GetDocumentCharacterSet(PRUnichar** characterSet) +{ + nsCOMPtr editor = do_QueryInterface(mEditor); + + if (editor) + return editor->GetDocumentCharacterSet(characterSet); + + return NS_ERROR_FAILURE; +} + +NS_IMETHODIMP +nsEditorShell::SetDocumentCharacterSet(const PRUnichar* characterSet) +{ + nsCOMPtr editor = do_QueryInterface(mEditor); + + if (editor) + return editor->SetDocumentCharacterSet(characterSet); + + return NS_ERROR_FAILURE; + +} + NS_IMETHODIMP nsEditorShell::GetContentsAs(const PRUnichar *format, PRUint32 flags, PRUnichar **contentsAs) diff --git a/editor/composer/src/nsEditorShell.h b/editor/composer/src/nsEditorShell.h index 42c87834742a..fde6eec10b62 100644 --- a/editor/composer/src/nsEditorShell.h +++ b/editor/composer/src/nsEditorShell.h @@ -128,6 +128,10 @@ class nsEditorShell : public nsIEditorShell, NS_IMETHOD Find(); NS_IMETHOD FindNext(); + /* Charset Menu */ + NS_IMETHOD GetDocumentCharacterSet(PRUnichar **characterSet); + NS_IMETHOD SetDocumentCharacterSet(const PRUnichar *characterSet); + /* void InsertText (in wstring textToInsert); */ NS_IMETHOD InsertText(const PRUnichar *textToInsert); NS_IMETHOD InsertSource(const PRUnichar *sourceToInsert); diff --git a/editor/idl/nsIEditorShell.idl b/editor/idl/nsIEditorShell.idl index 65ee64f74066..97b381c77a46 100644 --- a/editor/idl/nsIEditorShell.idl +++ b/editor/idl/nsIEditorShell.idl @@ -100,6 +100,10 @@ interface nsIEditorShell : nsISupports void Find(); void FindNext(); + + /* Charset Menu */ + wstring GetDocumentCharacterSet(); + void SetDocumentCharacterSet(in wstring characterSet); /* Structure change */ void InsertText(in wstring textToInsert); diff --git a/editor/libeditor/base/nsEditor.cpp b/editor/libeditor/base/nsEditor.cpp index 410888207c2d..b8c734ce1e24 100644 --- a/editor/libeditor/base/nsEditor.cpp +++ b/editor/libeditor/base/nsEditor.cpp @@ -155,6 +155,7 @@ nsEditor::nsEditor() , mDocDirtyState(-1) , mDoc(nsnull) , mPrefs(nsnull) +, mDocCharset("ISO-8859-1") #ifdef ENABLE_JS_EDITOR_LOG , mJSEditorLog(nsnull) , mJSTxnLog(nsnull) @@ -430,8 +431,7 @@ NS_IMETHODIMP nsEditor::SaveDocument(PRBool saveAs, PRBool saveCopy) } } - nsAutoString charsetStr(""); - rv = diskDoc->SaveFile(&docFileSpec, replacing, saveCopy, nsIDiskDocument::eSaveFileHTML, charsetStr); + rv = diskDoc->SaveFile(&docFileSpec, replacing, saveCopy, nsIDiskDocument::eSaveFileHTML, mDocCharset); if (NS_FAILED(rv)) { @@ -805,6 +805,24 @@ nsEditor::GetDocumentModified(PRBool *outDocModified) return NS_OK; } +NS_IMETHODIMP +nsEditor::GetDocumentCharacterSet(PRUnichar** characterSet) +{ + *characterSet = mDocCharset.ToNewUnicode(); + return NS_OK; +} + +NS_IMETHODIMP +nsEditor::SetDocumentCharacterSet(const PRUnichar* characterSet) +{ + if (characterSet!=NULL) { + mDocCharset = characterSet; + return NS_OK; + } + + return NS_ERROR_FAILURE; +} + /* NS_IMETHODIMP diff --git a/editor/libeditor/base/nsEditor.h b/editor/libeditor/base/nsEditor.h index f77c20e0511e..1bd8e48b70c9 100644 --- a/editor/libeditor/base/nsEditor.h +++ b/editor/libeditor/base/nsEditor.h @@ -134,6 +134,8 @@ public: NS_IMETHOD Save(); NS_IMETHOD SaveAs(PRBool aSavingCopy); NS_IMETHOD GetDocumentModified(PRBool *outDocModified); + NS_IMETHOD GetDocumentCharacterSet(PRUnichar** characterSet); + NS_IMETHOD SetDocumentCharacterSet(const PRUnichar* characterSet); // these are pure virtual in this base class NS_IMETHOD Cut() = 0; @@ -619,6 +621,9 @@ protected: // Services are not nsCOMPtr friendly nsIPref* mPrefs; + //Document 'SaveAs' charset + nsString mDocCharset; + #ifdef ENABLE_JS_EDITOR_LOG nsJSEditorLog *mJSEditorLog; nsJSTxnLog *mJSTxnLog; diff --git a/editor/public/nsIEditor.h b/editor/public/nsIEditor.h index e7e49986798c..4ba536b541e7 100644 --- a/editor/public/nsIEditor.h +++ b/editor/public/nsIEditor.h @@ -125,7 +125,11 @@ public: /** Returns true if the document is modifed and needs saving */ NS_IMETHOD GetDocumentModified(PRBool *outDocModified)=0; + /** Returns the current 'Save' document character set */ + NS_IMETHOD GetDocumentCharacterSet(PRUnichar** characterSet)=0; + /** Sets the current 'Save' document character set */ + NS_IMETHOD SetDocumentCharacterSet(const PRUnichar* characterSet)=0; /* ------------ Transaction methods -------------- */ diff --git a/editor/ui/composer/content/EditorCommands.js b/editor/ui/composer/content/EditorCommands.js index 955737318cbe..8c01f277fd07 100644 --- a/editor/ui/composer/content/EditorCommands.js +++ b/editor/ui/composer/content/EditorCommands.js @@ -263,7 +263,7 @@ function EditorShowClipboard() function EditorSetDocumentCharacterSet(aCharset) { dump(aCharset); - editorShell.editorDocument.SetDocumentCharacterSet(aCharset); + editorShell.SetDocumentCharacterSet(aCharset); }