From a5341f92a7e34f2352743a0ba76fffa2116d5c03 Mon Sep 17 00:00:00 2001 From: "jfrancis%netscape.com" Date: Mon, 6 Sep 1999 19:47:25 +0000 Subject: [PATCH] implementing RemoveList() - ie, list button now works as a toggle git-svn-id: svn://10.0.0.236/trunk@46125 18797224-902f-48f8-a5cc-f745e15eee43 --- mozilla/editor/base/nsEditorShell.cpp | 22 ++++++++ mozilla/editor/base/nsHTMLEditor.cpp | 56 ++++++++++++++----- mozilla/editor/base/nsHTMLEditor.h | 1 + mozilla/editor/base/nsTextEditRules.h | 1 + mozilla/editor/composer/src/nsEditorShell.cpp | 22 ++++++++ mozilla/editor/idl/nsIEditorShell.idl | 1 + .../editor/libeditor/html/nsHTMLEditor.cpp | 56 ++++++++++++++----- mozilla/editor/libeditor/html/nsHTMLEditor.h | 1 + .../editor/libeditor/text/nsTextEditRules.h | 1 + mozilla/editor/public/nsIHTMLEditor.h | 12 +++- .../ui/composer/content/EditorCommands.js | 24 +++++++- 11 files changed, 164 insertions(+), 33 deletions(-) diff --git a/mozilla/editor/base/nsEditorShell.cpp b/mozilla/editor/base/nsEditorShell.cpp index ba022d2378c..26b6c20d413 100644 --- a/mozilla/editor/base/nsEditorShell.cpp +++ b/mozilla/editor/base/nsEditorShell.cpp @@ -2065,6 +2065,28 @@ nsEditorShell::InsertList(const PRUnichar *listType) return err; } + +NS_IMETHODIMP +nsEditorShell::RemoveList(const PRUnichar *listType) +{ + nsresult err = NS_NOINTERFACE; + + nsAutoString aListType(listType); + + switch (mEditorType) + { + case eHTMLTextEditorType: + err = mEditor->RemoveList(aListType); + break; + + case ePlainTextEditorType: + default: + err = NS_ERROR_NOT_IMPLEMENTED; + } + + return err; +} + NS_IMETHODIMP nsEditorShell::Indent(const PRUnichar *indent) { diff --git a/mozilla/editor/base/nsHTMLEditor.cpp b/mozilla/editor/base/nsHTMLEditor.cpp index 65ec5b53b08..18bf69e0632 100644 --- a/mozilla/editor/base/nsHTMLEditor.cpp +++ b/mozilla/editor/base/nsHTMLEditor.cpp @@ -1618,6 +1618,34 @@ nsHTMLEditor::InsertList(const nsString& aListType) } +NS_IMETHODIMP +nsHTMLEditor::RemoveList(const nsString& aListType) +{ + nsresult res; + if (!mRules) { return NS_ERROR_NOT_INITIALIZED; } + + nsCOMPtr selection; + PRBool cancel= PR_FALSE; + + nsAutoEditBatch beginBatching(this); + + // pre-process + res = GetSelection(getter_AddRefs(selection)); + if (NS_FAILED(res)) return res; + if (!selection) return NS_ERROR_NULL_POINTER; + + nsTextRulesInfo ruleInfo(nsHTMLEditRules::kRemoveList); + if (aListType == "ol") ruleInfo.bOrdered = PR_TRUE; + else ruleInfo.bOrdered = PR_FALSE; + res = mRules->WillDoAction(selection, &ruleInfo, &cancel); + if (cancel || (NS_FAILED(res))) return res; + + // no default behavior for this yet. what would it mean? + + return res; +} + + NS_IMETHODIMP nsHTMLEditor::InsertBasicBlock(const nsString& aBlockType) { @@ -2977,18 +3005,18 @@ NS_IMETHODIMP nsHTMLEditor::OutputToString(nsString& aOutputString, const nsString& aFormatType, PRUint32 aFlags) { - PRBool cancel; - nsString resultString; - nsTextRulesInfo ruleInfo(nsTextEditRules::kOutputText); - ruleInfo.outString = &resultString; - nsresult rv = mRules->WillDoAction(nsnull, &ruleInfo, &cancel); - if (NS_FAILED(rv)) { return rv; } - if (PR_TRUE==cancel) - { // this case will get triggered by password fields - aOutputString = *(ruleInfo.outString); - } - else - { // default processing +// PRBool cancel; +// nsString resultString; +// nsTextRulesInfo ruleInfo(nsTextEditRules::kOutputText); +// ruleInfo.outString = &resultString; +// nsresult rv = mRules->WillDoAction(nsnull, &ruleInfo, &cancel); +// if (NS_FAILED(rv)) { return rv; } +// if (PR_TRUE==cancel) +// { // this case will get triggered by password fields +// aOutputString = *(ruleInfo.outString); +// } +// else +// { // default processing nsCOMPtr encoder; char* progid = (char *)nsAllocator::Alloc(strlen(NS_DOC_ENCODER_PROGID_BASE) + aFormatType.Length() + 1); if (! progid) @@ -2997,7 +3025,7 @@ NS_IMETHODIMP nsHTMLEditor::OutputToString(nsString& aOutputString, char* type = aFormatType.ToNewCString(); strcat(progid, type); nsCRT::free(type); - rv = nsComponentManager::CreateInstance(progid, + nsresult rv = nsComponentManager::CreateInstance(progid, nsnull, nsIDocumentEncoder::GetIID(), getter_AddRefs(encoder)); @@ -3047,7 +3075,7 @@ NS_IMETHODIMP nsHTMLEditor::OutputToString(nsString& aOutputString, } rv = encoder->EncodeToString(aOutputString); - } +// } return rv; } diff --git a/mozilla/editor/base/nsHTMLEditor.h b/mozilla/editor/base/nsHTMLEditor.h index 4f9e15a17c8..70a037019ed 100644 --- a/mozilla/editor/base/nsHTMLEditor.h +++ b/mozilla/editor/base/nsHTMLEditor.h @@ -96,6 +96,7 @@ public: NS_IMETHOD RemoveParent(const nsString &aParentTag); NS_IMETHOD InsertList(const nsString& aListType); + NS_IMETHOD RemoveList(const nsString& aListType); NS_IMETHOD InsertBasicBlock(const nsString& aBlockType); NS_IMETHOD Indent(const nsString& aIndent); NS_IMETHOD Align(const nsString& aAlign); diff --git a/mozilla/editor/base/nsTextEditRules.h b/mozilla/editor/base/nsTextEditRules.h index f989d2ddafa..fec23ca66e6 100644 --- a/mozilla/editor/base/nsTextEditRules.h +++ b/mozilla/editor/base/nsTextEditRules.h @@ -74,6 +74,7 @@ public: kOutdent = 3003, kAlign = 3004, kMakeBasicBlock = 3005, + kRemoveList = 3006, kInsertElement = 3008 }; diff --git a/mozilla/editor/composer/src/nsEditorShell.cpp b/mozilla/editor/composer/src/nsEditorShell.cpp index ba022d2378c..26b6c20d413 100644 --- a/mozilla/editor/composer/src/nsEditorShell.cpp +++ b/mozilla/editor/composer/src/nsEditorShell.cpp @@ -2065,6 +2065,28 @@ nsEditorShell::InsertList(const PRUnichar *listType) return err; } + +NS_IMETHODIMP +nsEditorShell::RemoveList(const PRUnichar *listType) +{ + nsresult err = NS_NOINTERFACE; + + nsAutoString aListType(listType); + + switch (mEditorType) + { + case eHTMLTextEditorType: + err = mEditor->RemoveList(aListType); + break; + + case ePlainTextEditorType: + default: + err = NS_ERROR_NOT_IMPLEMENTED; + } + + return err; +} + NS_IMETHODIMP nsEditorShell::Indent(const PRUnichar *indent) { diff --git a/mozilla/editor/idl/nsIEditorShell.idl b/mozilla/editor/idl/nsIEditorShell.idl index 670ffcb08df..0970b03fd5a 100644 --- a/mozilla/editor/idl/nsIEditorShell.idl +++ b/mozilla/editor/idl/nsIEditorShell.idl @@ -142,6 +142,7 @@ interface nsIEditorShell : nsISupports void InsertBreak(); void InsertList(in wstring listType); + void RemoveList(in wstring listType); void Indent(in wstring indent); void Align(in wstring align); diff --git a/mozilla/editor/libeditor/html/nsHTMLEditor.cpp b/mozilla/editor/libeditor/html/nsHTMLEditor.cpp index 65ec5b53b08..18bf69e0632 100644 --- a/mozilla/editor/libeditor/html/nsHTMLEditor.cpp +++ b/mozilla/editor/libeditor/html/nsHTMLEditor.cpp @@ -1618,6 +1618,34 @@ nsHTMLEditor::InsertList(const nsString& aListType) } +NS_IMETHODIMP +nsHTMLEditor::RemoveList(const nsString& aListType) +{ + nsresult res; + if (!mRules) { return NS_ERROR_NOT_INITIALIZED; } + + nsCOMPtr selection; + PRBool cancel= PR_FALSE; + + nsAutoEditBatch beginBatching(this); + + // pre-process + res = GetSelection(getter_AddRefs(selection)); + if (NS_FAILED(res)) return res; + if (!selection) return NS_ERROR_NULL_POINTER; + + nsTextRulesInfo ruleInfo(nsHTMLEditRules::kRemoveList); + if (aListType == "ol") ruleInfo.bOrdered = PR_TRUE; + else ruleInfo.bOrdered = PR_FALSE; + res = mRules->WillDoAction(selection, &ruleInfo, &cancel); + if (cancel || (NS_FAILED(res))) return res; + + // no default behavior for this yet. what would it mean? + + return res; +} + + NS_IMETHODIMP nsHTMLEditor::InsertBasicBlock(const nsString& aBlockType) { @@ -2977,18 +3005,18 @@ NS_IMETHODIMP nsHTMLEditor::OutputToString(nsString& aOutputString, const nsString& aFormatType, PRUint32 aFlags) { - PRBool cancel; - nsString resultString; - nsTextRulesInfo ruleInfo(nsTextEditRules::kOutputText); - ruleInfo.outString = &resultString; - nsresult rv = mRules->WillDoAction(nsnull, &ruleInfo, &cancel); - if (NS_FAILED(rv)) { return rv; } - if (PR_TRUE==cancel) - { // this case will get triggered by password fields - aOutputString = *(ruleInfo.outString); - } - else - { // default processing +// PRBool cancel; +// nsString resultString; +// nsTextRulesInfo ruleInfo(nsTextEditRules::kOutputText); +// ruleInfo.outString = &resultString; +// nsresult rv = mRules->WillDoAction(nsnull, &ruleInfo, &cancel); +// if (NS_FAILED(rv)) { return rv; } +// if (PR_TRUE==cancel) +// { // this case will get triggered by password fields +// aOutputString = *(ruleInfo.outString); +// } +// else +// { // default processing nsCOMPtr encoder; char* progid = (char *)nsAllocator::Alloc(strlen(NS_DOC_ENCODER_PROGID_BASE) + aFormatType.Length() + 1); if (! progid) @@ -2997,7 +3025,7 @@ NS_IMETHODIMP nsHTMLEditor::OutputToString(nsString& aOutputString, char* type = aFormatType.ToNewCString(); strcat(progid, type); nsCRT::free(type); - rv = nsComponentManager::CreateInstance(progid, + nsresult rv = nsComponentManager::CreateInstance(progid, nsnull, nsIDocumentEncoder::GetIID(), getter_AddRefs(encoder)); @@ -3047,7 +3075,7 @@ NS_IMETHODIMP nsHTMLEditor::OutputToString(nsString& aOutputString, } rv = encoder->EncodeToString(aOutputString); - } +// } return rv; } diff --git a/mozilla/editor/libeditor/html/nsHTMLEditor.h b/mozilla/editor/libeditor/html/nsHTMLEditor.h index 4f9e15a17c8..70a037019ed 100644 --- a/mozilla/editor/libeditor/html/nsHTMLEditor.h +++ b/mozilla/editor/libeditor/html/nsHTMLEditor.h @@ -96,6 +96,7 @@ public: NS_IMETHOD RemoveParent(const nsString &aParentTag); NS_IMETHOD InsertList(const nsString& aListType); + NS_IMETHOD RemoveList(const nsString& aListType); NS_IMETHOD InsertBasicBlock(const nsString& aBlockType); NS_IMETHOD Indent(const nsString& aIndent); NS_IMETHOD Align(const nsString& aAlign); diff --git a/mozilla/editor/libeditor/text/nsTextEditRules.h b/mozilla/editor/libeditor/text/nsTextEditRules.h index f989d2ddafa..fec23ca66e6 100644 --- a/mozilla/editor/libeditor/text/nsTextEditRules.h +++ b/mozilla/editor/libeditor/text/nsTextEditRules.h @@ -74,6 +74,7 @@ public: kOutdent = 3003, kAlign = 3004, kMakeBasicBlock = 3005, + kRemoveList = 3006, kInsertElement = 3008 }; diff --git a/mozilla/editor/public/nsIHTMLEditor.h b/mozilla/editor/public/nsIHTMLEditor.h index f5b873de61a..4ff4a74921a 100644 --- a/mozilla/editor/public/nsIHTMLEditor.h +++ b/mozilla/editor/public/nsIHTMLEditor.h @@ -48,7 +48,8 @@ public: eEditorPasswordBit, // text is not entered into content, only a representative character eEditorReadonlyBit, // editing events are disabled. Editor may still accept focus. eEditorDisabledBit, // all events are disabled (like scrolling). Editor will not accept focus. - eEditorFilterInputBit // text input is limited to certain character types, use mFilter + eEditorFilterInputBit, // text input is limited to certain character types, use mFilter + eEditorMailBit // use mail-compose editting rules // max 32 bits }; @@ -59,7 +60,8 @@ public: eEditorPasswordMask = (1 << eEditorPasswordBit), eEditorReadonlyMask = (1 << eEditorReadonlyBit), eEditorDisabledMask = (1 << eEditorDisabledBit), - eEditorFilterInputMask = (1 << eEditorFilterInputBit) + eEditorFilterInputMask = (1 << eEditorFilterInputBit), + eEditorMailMask = (1 << eEditorMailBit) }; @@ -244,6 +246,12 @@ public: */ NS_IMETHOD InsertList(const nsString& aListType)=0; + /** + * Document me! + * + */ + NS_IMETHOD RemoveList(const nsString& aListType)=0; + /** * Document me! * diff --git a/mozilla/editor/ui/composer/content/EditorCommands.js b/mozilla/editor/ui/composer/content/EditorCommands.js index ed726236803..e640ae113cc 100644 --- a/mozilla/editor/ui/composer/content/EditorCommands.js +++ b/mozilla/editor/ui/composer/content/EditorCommands.js @@ -726,9 +726,27 @@ function EditorDeleteTableCell() function EditorInsertList(listType) { - dump("Inserting list\n"); - editorShell.InsertList(listType); - contentWindow.focus(); + // check the observer node, + // which is the appropriate button + var theButton = document.getElementById(listType + "Button"); + dump("Toggling list " + listType + "\n"); + if (theButton) + { + var isOn = theButton.getAttribute("toggled"); + if (isOn == 1) + { + dump("Removing list \n"); + editorShell.RemoveList(listType); + } + else + editorShell.InsertList(listType); + + contentWindow.focus(); + } + else + { + dump("No button found for the " + listType + " style\n"); + } } function EditorAlign(align)