diff --git a/mozilla/editor/base/nsComposerCommands.cpp b/mozilla/editor/base/nsComposerCommands.cpp index fce5677c139..e1a64212519 100644 --- a/mozilla/editor/base/nsComposerCommands.cpp +++ b/mozilla/editor/base/nsComposerCommands.cpp @@ -129,7 +129,14 @@ nsBaseStateUpdatingCommand::IsCommandEnabled(const PRUnichar *aCommand, nsISuppo *outCmdEnabled = !sourceMode; // also udpate the command state - return UpdateCommandState(aCommand, refCon); + nsresult rv = UpdateCommandState(aCommand, refCon); + if (NS_FAILED(rv)) + { + *outCmdEnabled = PR_FALSE; + return NS_OK; + } + + return NS_OK; } @@ -454,6 +461,7 @@ nsListItemCommand::ToggleState(nsIEditorShell *aEditorShell, const char* aTagNam #ifdef XP_MAC #pragma mark - #endif + NS_IMETHODIMP nsRemoveListCommand::IsCommandEnabled(const PRUnichar *aCommand, nsISupports * refCon, PRBool *outCmdEnabled) { @@ -595,7 +603,13 @@ nsMultiStateCommand::IsCommandEnabled(const PRUnichar *aCommand, nsISupports * r } } - return UpdateCommandState(aCommand, refCon); + nsresult rv = UpdateCommandState(aCommand, refCon); + if (NS_FAILED(rv)) { + *outCmdEnabled = PR_FALSE; + return NS_OK; + } + + return NS_OK; } @@ -840,44 +854,62 @@ nsBackgroundColorStateCommand::SetState(nsIEditorShell *aEditorShell, nsString& #pragma mark - #endif -NS_IMETHODIMP -nsAlignCommand::IsCommandEnabled(const PRUnichar *aCommand, nsISupports * refCon, PRBool *outCmdEnabled) +nsAlignCommand::nsAlignCommand() +: nsMultiStateCommand() { - nsCOMPtr editorShell = do_QueryInterface(refCon); - *outCmdEnabled = PR_FALSE; - if (editorShell) +} + +nsresult +nsAlignCommand::GetCurrentState(nsIEditorShell *aEditorShell, nsString& outStateString, PRBool& outMixed) +{ + NS_ASSERTION(aEditorShell, "Need an editor shell here"); + + nsCOMPtr editor; + aEditorShell->GetEditor(getter_AddRefs(editor)); + nsCOMPtr htmlEditor = do_QueryInterface(editor); + if (!htmlEditor) return NS_ERROR_FAILURE; + + nsIHTMLEditor::EAlignment firstAlign; + nsresult rv = htmlEditor->GetAlignment(outMixed, firstAlign); + if (NS_FAILED(rv)) return rv; + switch (firstAlign) { - nsCOMPtr editor; - editorShell->GetEditor(getter_AddRefs(editor)); - if (editor) - { - *outCmdEnabled = PR_TRUE; - } + default: + case nsIHTMLEditor::eLeft: + outStateString.AssignWithConversion("left"); + break; + + case nsIHTMLEditor::eCenter: + outStateString.AssignWithConversion("center"); + break; + + case nsIHTMLEditor::eRight: + outStateString.AssignWithConversion("right"); + break; + + case nsIHTMLEditor::eJustify: + outStateString.AssignWithConversion("justify"); + break; } return NS_OK; } -NS_IMETHODIMP -nsAlignCommand::DoCommand(const PRUnichar *aCommand, nsISupports * refCon) +nsresult +nsAlignCommand::SetState(nsIEditorShell *aEditorShell, nsString& newState) { - nsCOMPtr editorShell = do_QueryInterface(refCon); - - nsresult rv = NS_OK; - if (editorShell) - { - // we have to grab the state attribute on our command node to find out - // what format to set the paragraph to - nsAutoString stateAttribute; - rv = GetCommandNodeState(aCommand, editorShell, stateAttribute); - if (NS_FAILED(rv)) return rv; - rv = editorShell->Align(stateAttribute.GetUnicode()); - } + NS_ASSERTION(aEditorShell, "Need an editor shell here"); - return rv; + nsCOMPtr editor; + aEditorShell->GetEditor(getter_AddRefs(editor)); + nsCOMPtr htmlEditor = do_QueryInterface(editor); + if (!htmlEditor) return NS_ERROR_FAILURE; + + return htmlEditor->Align(newState); } + #ifdef XP_MAC #pragma mark - #endif diff --git a/mozilla/editor/base/nsComposerCommands.h b/mozilla/editor/base/nsComposerCommands.h index 46bd44c0426..2c685b4c426 100644 --- a/mozilla/editor/base/nsComposerCommands.h +++ b/mozilla/editor/base/nsComposerCommands.h @@ -207,6 +207,17 @@ protected: virtual nsresult SetState(nsIEditorShell *aEditorShell, nsString& newState); }; +class nsAlignCommand : public nsMultiStateCommand +{ +public: + nsAlignCommand(); + +protected: + + virtual nsresult GetCurrentState(nsIEditorShell *aEditorShell, nsString& outStateString, PRBool& outMixed); + virtual nsresult SetState(nsIEditorShell *aEditorShell, nsString& newState); +}; + class nsBackgroundColorStateCommand : public nsMultiStateCommand { public: @@ -239,7 +250,6 @@ NS_DECL_COMPOSER_COMMAND(nsPasteQuotationCommand) 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) diff --git a/mozilla/editor/base/nsEditor.cpp b/mozilla/editor/base/nsEditor.cpp index 7d514870f1f..126b4693135 100644 --- a/mozilla/editor/base/nsEditor.cpp +++ b/mozilla/editor/base/nsEditor.cpp @@ -4120,6 +4120,8 @@ NS_IMETHODIMP nsEditor::IncDocModCount(PRInt32 inNumMods) NS_IMETHODIMP nsEditor::GetDocModCount(PRInt32 &outModCount) { if (!mDocWeak) return NS_ERROR_NOT_INITIALIZED; + + outModCount = 0; nsCOMPtr doc = do_QueryReferent(mDocWeak); if (!doc) return NS_ERROR_NOT_INITIALIZED; diff --git a/mozilla/editor/base/nsHTMLEditRules.cpp b/mozilla/editor/base/nsHTMLEditRules.cpp index b5380ea9648..07eff2f71b8 100644 --- a/mozilla/editor/base/nsHTMLEditRules.cpp +++ b/mozilla/editor/base/nsHTMLEditRules.cpp @@ -488,6 +488,7 @@ nsHTMLEditRules::GetAlignment(PRBool &aMixed, nsIHTMLEditor::EAlignment &aAlign) // this routine assumes that alignment is done ONLY via divs // default alignment is left + aMixed = PR_FALSE; aAlign = nsIHTMLEditor::eLeft; // get selection @@ -546,6 +547,8 @@ nsHTMLEditRules::GetAlignment(PRBool &aMixed, nsIHTMLEditor::EAlignment &aAlign) aAlign = nsIHTMLEditor::eCenter; else if (typeAttrVal.EqualsWithConversion("right")) aAlign = nsIHTMLEditor::eRight; + else if (typeAttrVal.EqualsWithConversion("justify")) + aAlign = nsIHTMLEditor::eJustify; else aAlign = nsIHTMLEditor::eLeft; return res; diff --git a/mozilla/editor/base/nsHTMLEditUtils.cpp b/mozilla/editor/base/nsHTMLEditUtils.cpp index 85532794557..f8f722b4b11 100644 --- a/mozilla/editor/base/nsHTMLEditUtils.cpp +++ b/mozilla/editor/base/nsHTMLEditUtils.cpp @@ -42,7 +42,6 @@ nsHTMLEditUtils::IsBody(nsIDOMNode *node) { nsAutoString tag; nsEditor::GetTagString(node,tag); - tag.ToLowerCase(); if (tag.EqualsWithConversion("body")) { return PR_TRUE; diff --git a/mozilla/editor/composer/src/nsComposerCommands.cpp b/mozilla/editor/composer/src/nsComposerCommands.cpp index fce5677c139..e1a64212519 100644 --- a/mozilla/editor/composer/src/nsComposerCommands.cpp +++ b/mozilla/editor/composer/src/nsComposerCommands.cpp @@ -129,7 +129,14 @@ nsBaseStateUpdatingCommand::IsCommandEnabled(const PRUnichar *aCommand, nsISuppo *outCmdEnabled = !sourceMode; // also udpate the command state - return UpdateCommandState(aCommand, refCon); + nsresult rv = UpdateCommandState(aCommand, refCon); + if (NS_FAILED(rv)) + { + *outCmdEnabled = PR_FALSE; + return NS_OK; + } + + return NS_OK; } @@ -454,6 +461,7 @@ nsListItemCommand::ToggleState(nsIEditorShell *aEditorShell, const char* aTagNam #ifdef XP_MAC #pragma mark - #endif + NS_IMETHODIMP nsRemoveListCommand::IsCommandEnabled(const PRUnichar *aCommand, nsISupports * refCon, PRBool *outCmdEnabled) { @@ -595,7 +603,13 @@ nsMultiStateCommand::IsCommandEnabled(const PRUnichar *aCommand, nsISupports * r } } - return UpdateCommandState(aCommand, refCon); + nsresult rv = UpdateCommandState(aCommand, refCon); + if (NS_FAILED(rv)) { + *outCmdEnabled = PR_FALSE; + return NS_OK; + } + + return NS_OK; } @@ -840,44 +854,62 @@ nsBackgroundColorStateCommand::SetState(nsIEditorShell *aEditorShell, nsString& #pragma mark - #endif -NS_IMETHODIMP -nsAlignCommand::IsCommandEnabled(const PRUnichar *aCommand, nsISupports * refCon, PRBool *outCmdEnabled) +nsAlignCommand::nsAlignCommand() +: nsMultiStateCommand() { - nsCOMPtr editorShell = do_QueryInterface(refCon); - *outCmdEnabled = PR_FALSE; - if (editorShell) +} + +nsresult +nsAlignCommand::GetCurrentState(nsIEditorShell *aEditorShell, nsString& outStateString, PRBool& outMixed) +{ + NS_ASSERTION(aEditorShell, "Need an editor shell here"); + + nsCOMPtr editor; + aEditorShell->GetEditor(getter_AddRefs(editor)); + nsCOMPtr htmlEditor = do_QueryInterface(editor); + if (!htmlEditor) return NS_ERROR_FAILURE; + + nsIHTMLEditor::EAlignment firstAlign; + nsresult rv = htmlEditor->GetAlignment(outMixed, firstAlign); + if (NS_FAILED(rv)) return rv; + switch (firstAlign) { - nsCOMPtr editor; - editorShell->GetEditor(getter_AddRefs(editor)); - if (editor) - { - *outCmdEnabled = PR_TRUE; - } + default: + case nsIHTMLEditor::eLeft: + outStateString.AssignWithConversion("left"); + break; + + case nsIHTMLEditor::eCenter: + outStateString.AssignWithConversion("center"); + break; + + case nsIHTMLEditor::eRight: + outStateString.AssignWithConversion("right"); + break; + + case nsIHTMLEditor::eJustify: + outStateString.AssignWithConversion("justify"); + break; } return NS_OK; } -NS_IMETHODIMP -nsAlignCommand::DoCommand(const PRUnichar *aCommand, nsISupports * refCon) +nsresult +nsAlignCommand::SetState(nsIEditorShell *aEditorShell, nsString& newState) { - nsCOMPtr editorShell = do_QueryInterface(refCon); - - nsresult rv = NS_OK; - if (editorShell) - { - // we have to grab the state attribute on our command node to find out - // what format to set the paragraph to - nsAutoString stateAttribute; - rv = GetCommandNodeState(aCommand, editorShell, stateAttribute); - if (NS_FAILED(rv)) return rv; - rv = editorShell->Align(stateAttribute.GetUnicode()); - } + NS_ASSERTION(aEditorShell, "Need an editor shell here"); - return rv; + nsCOMPtr editor; + aEditorShell->GetEditor(getter_AddRefs(editor)); + nsCOMPtr htmlEditor = do_QueryInterface(editor); + if (!htmlEditor) return NS_ERROR_FAILURE; + + return htmlEditor->Align(newState); } + #ifdef XP_MAC #pragma mark - #endif diff --git a/mozilla/editor/composer/src/nsComposerCommands.h b/mozilla/editor/composer/src/nsComposerCommands.h index 46bd44c0426..2c685b4c426 100644 --- a/mozilla/editor/composer/src/nsComposerCommands.h +++ b/mozilla/editor/composer/src/nsComposerCommands.h @@ -207,6 +207,17 @@ protected: virtual nsresult SetState(nsIEditorShell *aEditorShell, nsString& newState); }; +class nsAlignCommand : public nsMultiStateCommand +{ +public: + nsAlignCommand(); + +protected: + + virtual nsresult GetCurrentState(nsIEditorShell *aEditorShell, nsString& outStateString, PRBool& outMixed); + virtual nsresult SetState(nsIEditorShell *aEditorShell, nsString& newState); +}; + class nsBackgroundColorStateCommand : public nsMultiStateCommand { public: @@ -239,7 +250,6 @@ NS_DECL_COMPOSER_COMMAND(nsPasteQuotationCommand) 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) diff --git a/mozilla/editor/libeditor/base/nsEditor.cpp b/mozilla/editor/libeditor/base/nsEditor.cpp index 7d514870f1f..126b4693135 100644 --- a/mozilla/editor/libeditor/base/nsEditor.cpp +++ b/mozilla/editor/libeditor/base/nsEditor.cpp @@ -4120,6 +4120,8 @@ NS_IMETHODIMP nsEditor::IncDocModCount(PRInt32 inNumMods) NS_IMETHODIMP nsEditor::GetDocModCount(PRInt32 &outModCount) { if (!mDocWeak) return NS_ERROR_NOT_INITIALIZED; + + outModCount = 0; nsCOMPtr doc = do_QueryReferent(mDocWeak); if (!doc) return NS_ERROR_NOT_INITIALIZED; diff --git a/mozilla/editor/libeditor/html/nsHTMLEditRules.cpp b/mozilla/editor/libeditor/html/nsHTMLEditRules.cpp index b5380ea9648..07eff2f71b8 100644 --- a/mozilla/editor/libeditor/html/nsHTMLEditRules.cpp +++ b/mozilla/editor/libeditor/html/nsHTMLEditRules.cpp @@ -488,6 +488,7 @@ nsHTMLEditRules::GetAlignment(PRBool &aMixed, nsIHTMLEditor::EAlignment &aAlign) // this routine assumes that alignment is done ONLY via divs // default alignment is left + aMixed = PR_FALSE; aAlign = nsIHTMLEditor::eLeft; // get selection @@ -546,6 +547,8 @@ nsHTMLEditRules::GetAlignment(PRBool &aMixed, nsIHTMLEditor::EAlignment &aAlign) aAlign = nsIHTMLEditor::eCenter; else if (typeAttrVal.EqualsWithConversion("right")) aAlign = nsIHTMLEditor::eRight; + else if (typeAttrVal.EqualsWithConversion("justify")) + aAlign = nsIHTMLEditor::eJustify; else aAlign = nsIHTMLEditor::eLeft; return res; diff --git a/mozilla/editor/libeditor/html/nsHTMLEditUtils.cpp b/mozilla/editor/libeditor/html/nsHTMLEditUtils.cpp index 85532794557..f8f722b4b11 100644 --- a/mozilla/editor/libeditor/html/nsHTMLEditUtils.cpp +++ b/mozilla/editor/libeditor/html/nsHTMLEditUtils.cpp @@ -42,7 +42,6 @@ nsHTMLEditUtils::IsBody(nsIDOMNode *node) { nsAutoString tag; nsEditor::GetTagString(node,tag); - tag.ToLowerCase(); if (tag.EqualsWithConversion("body")) { return PR_TRUE; diff --git a/mozilla/editor/public/nsIHTMLEditor.h b/mozilla/editor/public/nsIHTMLEditor.h index f3a45771b97..d31f74c52fe 100644 --- a/mozilla/editor/public/nsIHTMLEditor.h +++ b/mozilla/editor/public/nsIHTMLEditor.h @@ -87,7 +87,8 @@ public: typedef enum { eLeft, eCenter, - eRight + eRight, + eJustify } EAlignment; /* ------------ Document info methods -------------- */ diff --git a/mozilla/editor/ui/composer/content/ComposerCommands.js b/mozilla/editor/ui/composer/content/ComposerCommands.js index 9381382eb6c..25347126916 100644 --- a/mozilla/editor/ui/composer/content/ComposerCommands.js +++ b/mozilla/editor/ui/composer/content/ComposerCommands.js @@ -774,13 +774,18 @@ var nsObjectPropertiesCommand = { isCommandEnabled: function(aCommand, dummy) { + var isEnabled = false; if (window.editorShell && window.editorShell.documentEditable) { + try { // Launch Object properties for appropriate selected element - return (GetSelectedElementOrParentCellOrLink() != null || - window.editorShell.GetSelectedElement("href") != null); + isEnabled = (GetSelectedElementOrParentCellOrLink() != null || + window.editorShell.GetSelectedElement("href") != null); + } catch(e) + { + } } - return false; + return isEnabled; }, doCommand: function(aCommand) { diff --git a/mozilla/editor/ui/composer/content/editor.js b/mozilla/editor/ui/composer/content/editor.js index 9a7d68e9f38..15f2d0407ad 100644 --- a/mozilla/editor/ui/composer/content/editor.js +++ b/mozilla/editor/ui/composer/content/editor.js @@ -1682,6 +1682,16 @@ function onButtonUpdate(button, commmandID) button.setAttribute("toggled", state); } +//-------------------------------------------------------------------- +function onStateButtonUpdate(button, commmandID, onState) +{ +// dump(" === onButtonUpdate called\n"); + var commandNode = document.getElementById(commmandID); + var state = commandNode.getAttribute("state"); + + button.setAttribute("toggled", (state == onState) ? "true" : "false"); +} + // --------------------------- Status calls --------------------------- function onStyleChange(theStyle) @@ -1724,20 +1734,6 @@ function onDirtyChange() } } -function onListFormatChange(listType) -{ - var theButton = document.getElementById(listType + "Button"); - if (theButton) - { - var isOn = theButton.getAttribute(listType); - if (isOn == "true") { - theButton.setAttribute("toggled", "true"); - } else { - theButton.setAttribute("toggled", "false"); - } - } -} - function getColorAndSetColorWell(ColorPickerID, ColorWellID) { var colorWell; diff --git a/mozilla/editor/ui/composer/content/editorOverlay.xul b/mozilla/editor/ui/composer/content/editorOverlay.xul index c3fb3ca8c52..a5099ba85a4 100644 --- a/mozilla/editor/ui/composer/content/editorOverlay.xul +++ b/mozilla/editor/ui/composer/content/editorOverlay.xul @@ -747,10 +747,18 @@ tooltip="aTooltip" tooltiptext="&AlignPopupButton.tooltip;"/> - + + +