Fixed list command problems: bug 41735, r=brade

This commit is contained in:
cmanske%netscape.com 2000-06-16 14:21:46 +00:00
Родитель 3a3f5cf275
Коммит c073210b68
8 изменённых файлов: 108 добавлений и 44 удалений

Просмотреть файл

@ -409,7 +409,8 @@ nsListCommand::GetCurrentState(nsIEditorShell *aEditorShell, const char* aTagNam
nsresult rv = aEditorShell->GetListState(&bMixed, &tagStr);
if (NS_FAILED(rv)) return rv;
outInList = (0 == nsCRT::strcmp(tagStr, aTagName));
// Need to use mTagName????
outInList = (0 == nsCRT::strcmp(tagStr, mTagName));
if (tagStr) nsCRT::free(tagStr);
@ -421,10 +422,10 @@ nsresult
nsListCommand::ToggleState(nsIEditorShell *aEditorShell, const char* aTagName)
{
PRBool inList;
nsresult rv = GetCurrentState(aEditorShell, aTagName, inList);
// Need to use mTagName????
nsresult rv = GetCurrentState(aEditorShell, mTagName, inList);
if (NS_FAILED(rv)) return rv;
nsAutoString listType; listType.AssignWithConversion(aTagName);
nsAutoString listType; listType.AssignWithConversion(mTagName);
if (inList)
rv = aEditorShell->RemoveList(listType.GetUnicode());
@ -454,7 +455,7 @@ nsListItemCommand::GetCurrentState(nsIEditorShell *aEditorShell, const char* aTa
nsresult rv = aEditorShell->GetListItemState(&bMixed, &tagStr);
if (NS_FAILED(rv)) return rv;
outInList = (0 == nsCRT::strcmp(tagStr, aTagName));
outInList = (0 == nsCRT::strcmp(tagStr, mTagName));
if (tagStr) nsCRT::free(tagStr);
@ -472,7 +473,8 @@ nsListItemCommand::ToggleState(nsIEditorShell *aEditorShell, const char* aTagNam
if (!htmlEditor) return NS_ERROR_NOT_INITIALIZED;
PRBool inList;
nsresult rv = GetCurrentState(aEditorShell, aTagName, inList);
// Need to use mTagName????
nsresult rv = GetCurrentState(aEditorShell, mTagName, inList);
if (NS_FAILED(rv)) return rv;
if (inList)
@ -494,7 +496,7 @@ nsListItemCommand::ToggleState(nsIEditorShell *aEditorShell, const char* aTagNam
}
else
{
nsAutoString itemType; itemType.AssignWithConversion(aTagName);
nsAutoString itemType; itemType.AssignWithConversion(mTagName);
// Set to the requested paragraph type
//XXX Note: This actually doesn't work for "LI",
// but we currently don't use this for non DL lists anyway.
@ -506,6 +508,43 @@ nsListItemCommand::ToggleState(nsIEditorShell *aEditorShell, const char* aTagNam
}
#ifdef XP_MAC
#pragma mark -
#endif
NS_IMETHODIMP
nsRemoveListCommand::IsCommandEnabled(const PRUnichar *aCommand, nsISupports * refCon, PRBool *outCmdEnabled)
{
nsCOMPtr<nsIEditorShell> editorShell = do_QueryInterface(refCon);
*outCmdEnabled = PR_FALSE;
if (editorShell)
{
// It is enabled if we are in any list type
PRBool bMixed;
PRUnichar *tagStr;
nsresult rv = editorShell->GetListState(&bMixed, &tagStr);
if (NS_FAILED(rv)) return rv;
*outCmdEnabled = (*tagStr != nsnull);
}
return NS_OK;
}
NS_IMETHODIMP
nsRemoveListCommand::DoCommand(const PRUnichar *aCommand, nsISupports * refCon)
{
nsCOMPtr<nsIEditorShell> editorShell = do_QueryInterface(refCon);
nsresult rv = NS_OK;
if (editorShell)
// This removes any list type
rv = editorShell->RemoveList(nsnull);
return rv;
}
#ifdef XP_MAC
#pragma mark -
#endif

Просмотреть файл

@ -223,6 +223,7 @@ NS_DECL_COMPOSER_COMMAND(nsIndentCommand)
NS_DECL_COMPOSER_COMMAND(nsOutdentCommand)
NS_DECL_COMPOSER_COMMAND(nsAlignCommand)
NS_DECL_COMPOSER_COMMAND(nsRemoveListCommand)
NS_DECL_COMPOSER_COMMAND(nsRemoveStylesCommand)
NS_DECL_COMPOSER_COMMAND(nsIncreaseFontSizeCommand)
NS_DECL_COMPOSER_COMMAND(nsDecreaseFontSizeCommand)

Просмотреть файл

@ -324,10 +324,11 @@ nsresult nsComposerController::RegisterComposerCommands(nsIControllerCommandMana
NS_REGISTER_STYLE_COMMAND(nsStyleUpdatingCommand, "cmd_var", "var");
// lists
NS_REGISTER_STYLE_COMMAND(nsListCommand, "cmd_ol", "ol");
NS_REGISTER_STYLE_COMMAND(nsListCommand, "cmd_ul", "ul");
NS_REGISTER_STYLE_COMMAND(nsListCommand, "cmd_ol", "ol");
NS_REGISTER_STYLE_COMMAND(nsListCommand, "cmd_ul", "ul");
NS_REGISTER_STYLE_COMMAND(nsListItemCommand, "cmd_dt", "dt");
NS_REGISTER_STYLE_COMMAND(nsListItemCommand, "cmd_dd", "dd");
NS_REGISTER_ONE_COMMAND(nsRemoveListCommand, "cmd_removeList");
// format stuff
NS_REGISTER_ONE_COMMAND(nsParagraphStateCommand, "cmd_paragraphState");

Просмотреть файл

@ -3367,24 +3367,15 @@ nsEditorShell::RemoveList(const PRUnichar *listType)
{
nsresult err = NS_NOINTERFACE;
nsAutoString aListType(listType);
switch (mEditorType)
{
case eHTMLTextEditorType:
if (aListType.IsEmpty())
{
err = mEditor->RemoveList(NS_ConvertASCIItoUCS2("ol"));
if(NS_SUCCEEDED(err))
{
err = mEditor->RemoveList(NS_ConvertASCIItoUCS2("ul"));
if(NS_SUCCEEDED(err))
err = mEditor->RemoveList(NS_ConvertASCIItoUCS2("dl"));
}
}
else
err = mEditor->RemoveList(aListType);
{
nsAutoString aListType(listType);
err = mEditor->RemoveList(aListType);
break;
}
case ePlainTextEditorType:
default:

Просмотреть файл

@ -409,7 +409,8 @@ nsListCommand::GetCurrentState(nsIEditorShell *aEditorShell, const char* aTagNam
nsresult rv = aEditorShell->GetListState(&bMixed, &tagStr);
if (NS_FAILED(rv)) return rv;
outInList = (0 == nsCRT::strcmp(tagStr, aTagName));
// Need to use mTagName????
outInList = (0 == nsCRT::strcmp(tagStr, mTagName));
if (tagStr) nsCRT::free(tagStr);
@ -421,10 +422,10 @@ nsresult
nsListCommand::ToggleState(nsIEditorShell *aEditorShell, const char* aTagName)
{
PRBool inList;
nsresult rv = GetCurrentState(aEditorShell, aTagName, inList);
// Need to use mTagName????
nsresult rv = GetCurrentState(aEditorShell, mTagName, inList);
if (NS_FAILED(rv)) return rv;
nsAutoString listType; listType.AssignWithConversion(aTagName);
nsAutoString listType; listType.AssignWithConversion(mTagName);
if (inList)
rv = aEditorShell->RemoveList(listType.GetUnicode());
@ -454,7 +455,7 @@ nsListItemCommand::GetCurrentState(nsIEditorShell *aEditorShell, const char* aTa
nsresult rv = aEditorShell->GetListItemState(&bMixed, &tagStr);
if (NS_FAILED(rv)) return rv;
outInList = (0 == nsCRT::strcmp(tagStr, aTagName));
outInList = (0 == nsCRT::strcmp(tagStr, mTagName));
if (tagStr) nsCRT::free(tagStr);
@ -472,7 +473,8 @@ nsListItemCommand::ToggleState(nsIEditorShell *aEditorShell, const char* aTagNam
if (!htmlEditor) return NS_ERROR_NOT_INITIALIZED;
PRBool inList;
nsresult rv = GetCurrentState(aEditorShell, aTagName, inList);
// Need to use mTagName????
nsresult rv = GetCurrentState(aEditorShell, mTagName, inList);
if (NS_FAILED(rv)) return rv;
if (inList)
@ -494,7 +496,7 @@ nsListItemCommand::ToggleState(nsIEditorShell *aEditorShell, const char* aTagNam
}
else
{
nsAutoString itemType; itemType.AssignWithConversion(aTagName);
nsAutoString itemType; itemType.AssignWithConversion(mTagName);
// Set to the requested paragraph type
//XXX Note: This actually doesn't work for "LI",
// but we currently don't use this for non DL lists anyway.
@ -506,6 +508,43 @@ nsListItemCommand::ToggleState(nsIEditorShell *aEditorShell, const char* aTagNam
}
#ifdef XP_MAC
#pragma mark -
#endif
NS_IMETHODIMP
nsRemoveListCommand::IsCommandEnabled(const PRUnichar *aCommand, nsISupports * refCon, PRBool *outCmdEnabled)
{
nsCOMPtr<nsIEditorShell> editorShell = do_QueryInterface(refCon);
*outCmdEnabled = PR_FALSE;
if (editorShell)
{
// It is enabled if we are in any list type
PRBool bMixed;
PRUnichar *tagStr;
nsresult rv = editorShell->GetListState(&bMixed, &tagStr);
if (NS_FAILED(rv)) return rv;
*outCmdEnabled = (*tagStr != nsnull);
}
return NS_OK;
}
NS_IMETHODIMP
nsRemoveListCommand::DoCommand(const PRUnichar *aCommand, nsISupports * refCon)
{
nsCOMPtr<nsIEditorShell> editorShell = do_QueryInterface(refCon);
nsresult rv = NS_OK;
if (editorShell)
// This removes any list type
rv = editorShell->RemoveList(nsnull);
return rv;
}
#ifdef XP_MAC
#pragma mark -
#endif

Просмотреть файл

@ -223,6 +223,7 @@ NS_DECL_COMPOSER_COMMAND(nsIndentCommand)
NS_DECL_COMPOSER_COMMAND(nsOutdentCommand)
NS_DECL_COMPOSER_COMMAND(nsAlignCommand)
NS_DECL_COMPOSER_COMMAND(nsRemoveListCommand)
NS_DECL_COMPOSER_COMMAND(nsRemoveStylesCommand)
NS_DECL_COMPOSER_COMMAND(nsIncreaseFontSizeCommand)
NS_DECL_COMPOSER_COMMAND(nsDecreaseFontSizeCommand)

Просмотреть файл

@ -3367,24 +3367,15 @@ nsEditorShell::RemoveList(const PRUnichar *listType)
{
nsresult err = NS_NOINTERFACE;
nsAutoString aListType(listType);
switch (mEditorType)
{
case eHTMLTextEditorType:
if (aListType.IsEmpty())
{
err = mEditor->RemoveList(NS_ConvertASCIItoUCS2("ol"));
if(NS_SUCCEEDED(err))
{
err = mEditor->RemoveList(NS_ConvertASCIItoUCS2("ul"));
if(NS_SUCCEEDED(err))
err = mEditor->RemoveList(NS_ConvertASCIItoUCS2("dl"));
}
}
else
err = mEditor->RemoveList(aListType);
{
nsAutoString aListType(listType);
err = mEditor->RemoveList(aListType);
break;
}
case ePlainTextEditorType:
default:

Просмотреть файл

@ -324,10 +324,11 @@ nsresult nsComposerController::RegisterComposerCommands(nsIControllerCommandMana
NS_REGISTER_STYLE_COMMAND(nsStyleUpdatingCommand, "cmd_var", "var");
// lists
NS_REGISTER_STYLE_COMMAND(nsListCommand, "cmd_ol", "ol");
NS_REGISTER_STYLE_COMMAND(nsListCommand, "cmd_ul", "ul");
NS_REGISTER_STYLE_COMMAND(nsListCommand, "cmd_ol", "ol");
NS_REGISTER_STYLE_COMMAND(nsListCommand, "cmd_ul", "ul");
NS_REGISTER_STYLE_COMMAND(nsListItemCommand, "cmd_dt", "dt");
NS_REGISTER_STYLE_COMMAND(nsListItemCommand, "cmd_dd", "dd");
NS_REGISTER_ONE_COMMAND(nsRemoveListCommand, "cmd_removeList");
// format stuff
NS_REGISTER_ONE_COMMAND(nsParagraphStateCommand, "cmd_paragraphState");