From 462beec4495a0b979f6840b067848bce4ea41003 Mon Sep 17 00:00:00 2001 From: "cmanske%netscape.com" Date: Tue, 6 Aug 2002 19:16:03 +0000 Subject: [PATCH] Moved text properties utility methods as part of image border bug 142093, r=brade, sr=dveditz. Editor.js also has fix for wrong 'Find' component causing missing menuitems, b=142093, r=akkana, sr=alecf --- editor/ui/composer/content/editor.js | 45 +---------- editor/ui/composer/content/editorUtilities.js | 76 ++++++++++++++++++- 2 files changed, 77 insertions(+), 44 deletions(-) diff --git a/editor/ui/composer/content/editor.js b/editor/ui/composer/content/editor.js index 4f6123db52a1..30c463615594 100644 --- a/editor/ui/composer/content/editor.js +++ b/editor/ui/composer/content/editor.js @@ -709,48 +709,6 @@ function updateCharsetPopupMenu(menuPopup) // --------------------------- Text style --------------------------- -var gAtomService; -function GetAtomService() -{ - gAtomService = Components.classes["@mozilla.org/atom-service;1"].getService(Components.interfaces.nsIAtomService); -} - -function EditorGetTextProperty(property, attribute, value, firstHas, anyHas, allHas) -{ - if (!gIsHTMLEditor) return; - try { - if (!gAtomService) GetAtomService(); - var propAtom = gAtomService.getAtom(property); - gEditor.getInlineProperty(propAtom, attribute, value, - firstHas, anyHas, allHas); - } - catch(e) {} -} - -function EditorSetTextProperty(property, attribute, value) -{ - if (!gIsHTMLEditor) return; - try { - if (!gAtomService) GetAtomService(); - var propAtom = gAtomService.getAtom(property); - gEditor.setInlineProperty(propAtom, attribute, value); - gContentWindow.focus(); - } - catch(e) {} -} - -function EditorRemoveTextProperty(property, attribute) -{ - if (!gIsHTMLEditor) return; - try { - if (!gAtomService) GetAtomService(); - var propAtom = gAtomService.getAtom(property); - gEditor.removeInlineProperty(propAtom, attribute); - gContentWindow.focus(); - } - catch(e) {} -} - function onParagraphFormatChange(paraMenuList, commandID) { if (!paraMenuList) @@ -2475,7 +2433,8 @@ function IsSpellCheckerInstalled() //----------------------------------------------------------------------------------- function IsFindInstalled() { - return "@mozilla.org/appshell/component/find;1" in Components.classes; + return "@mozilla.org/embedcomp/rangefind;1" in Components.classes + && "@mozilla.org/find/find_service;1" in Components.classes; } //----------------------------------------------------------------------------------- diff --git a/editor/ui/composer/content/editorUtilities.js b/editor/ui/composer/content/editorUtilities.js index 3496d769157b..dfcd1c2823c4 100644 --- a/editor/ui/composer/content/editorUtilities.js +++ b/editor/ui/composer/content/editorUtilities.js @@ -176,10 +176,84 @@ function ConvertToCDATAString(string) function GetSelectionAsText() { - return editorShell.GetContentsAs("text/plain", 1); // OutputSelectionOnly + try { + return GetCurrentEditor().outputToString("text/plain", 1); // OutputSelectionOnly + } catch (e) {} + + return ""; } +/************* General editing command utilities ***************/ + +function GetCurrentEditor() +{ + // Get the actual active editor + //XXX Temporarily use a global until new embedding access is finished + if ("gEditor" in window) + return gEditor; + + // For dialogs: Search up parent chain to find top window with editor + var editor = null; + var parentWindow = window.opener; + try { + while ("GetCurrentEditor" in parentWindow) + { + editor = parentWindow.GetCurrentEditor(); + if (editor) + return editor; + + parentWindow = parentWindow.opener; + } + } catch (e) {} + + return null; +} + +var gAtomService; +function GetAtomService() +{ + gAtomService = Components.classes["@mozilla.org/atom-service;1"].getService(Components.interfaces.nsIAtomService); +} + +function EditorGetTextProperty(property, attribute, value, firstHas, anyHas, allHas) +{ + try { + if (!gAtomService) GetAtomService(); + var propAtom = gAtomService.getAtom(property); + + GetCurrentEditor().getInlineProperty(propAtom, attribute, value, + firstHas, anyHas, allHas); + } + catch(e) {} +} + +function EditorSetTextProperty(property, attribute, value) +{ + try { + if (!gAtomService) GetAtomService(); + var propAtom = gAtomService.getAtom(property); + + GetCurrentEditor().setInlineProperty(propAtom, attribute, value); + if ("gContentWindow" in window) + window.gContentWindow.focus(); + } + catch(e) {} +} + +function EditorRemoveTextProperty(property, attribute) +{ + try { + if (!gAtomService) GetAtomService(); + var propAtom = gAtomService.getAtom(property); + + GetCurrentEditor().removeInlineProperty(propAtom, attribute); + if ("gContentWindow" in window) + window.gContentWindow.focus(); + } + catch(e) {} +} + /************* Element enbabling/disabling ***************/ // this function takes an elementID and a flag