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
This commit is contained in:
jfrancis%netscape.com
1999-09-06 19:47:25 +00:00
parent 33cc588b93
commit a5341f92a7
11 changed files with 164 additions and 33 deletions

View File

@@ -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)
{

View File

@@ -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<nsIDOMSelection> 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<nsIDocumentEncoder> 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;
}

View File

@@ -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);

View File

@@ -74,6 +74,7 @@ public:
kOutdent = 3003,
kAlign = 3004,
kMakeBasicBlock = 3005,
kRemoveList = 3006,
kInsertElement = 3008
};

View File

@@ -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)
{

View File

@@ -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);

View File

@@ -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<nsIDOMSelection> 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<nsIDocumentEncoder> 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;
}

View File

@@ -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);

View File

@@ -74,6 +74,7 @@ public:
kOutdent = 3003,
kAlign = 3004,
kMakeBasicBlock = 3005,
kRemoveList = 3006,
kInsertElement = 3008
};

View File

@@ -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!
*

View File

@@ -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)