/// <summary> /// Converts the string to toolbar set. /// </summary> /// <param name="inputString">The input string.</param> /// <returns>Returns the ToolbarSet</returns> public static ToolbarSet ConvertStringToToolbarSet(string inputString) { inputString = inputString.Replace(" ", string.Empty).Replace("\"", "'"); var toolbarSet = new ToolbarSet(); // Import old toolbar set older then CKEditor 3.6 if (inputString.StartsWith("[")) { var groupId = 1; var matchOld = Regex.Match(inputString, @"\[(?<group>[^\]]*)\]"); while (matchOld.Success) { var group = matchOld.Groups["group"].Value.Replace("'", string.Empty).Replace(" ", string.Empty).Split(','); var toolBarGroup = new ToolbarGroup { items = new List<string>(), name = string.Format("Group{0}", groupId) }; foreach (string s in group) { toolBarGroup.items.Add(s); } toolbarSet.ToolbarGroups.Add(toolBarGroup); groupId++; matchOld = matchOld.NextMatch(); } } var match = Regex.Match(inputString, @"\{name:'(?<groupName>(.+?))',items:\[(?<group>[^\]]*)\]\}"); while (match.Success) { var group = match.Groups["group"].Value.Replace("'", string.Empty).Replace(" ", string.Empty).Split(','); var toolBarGroup = new ToolbarGroup { name = match.Groups["groupName"].Value }; foreach (var button in group) { toolBarGroup.items.Add(button); } toolbarSet.ToolbarGroups.Add(toolBarGroup); match = match.NextMatch(); } return toolbarSet; }
/// <summary> /// Gets the default toolbar. /// </summary> /// <param name="toolbarName">Name of the toolbar.</param> /// <returns>Gets the Default Toolbar Based on the toolbarName</returns> public static ToolbarSet GetDefaultToolbar(string toolbarName) { switch (toolbarName) { case "Basic": { var toolbarSetBasic = new ToolbarSet("Basic", 10); // Basic Toolbar var toolBarGroup = new ToolbarGroup { items = new List<string> { "Bold", "Italic", "-", "NumberedList", "BulletedList", "-", "Link", "Unlink", "Image", "Mathjax", "oembed", "-", "About" }, name = "basicset" }; toolbarSetBasic.ToolbarGroups.Add(toolBarGroup); return toolbarSetBasic; } case "Standard": { var toolbarSetStandard = new ToolbarSet("Standard", 15); // Standard Toolbar toolbarSetStandard.ToolbarGroups.Add( new ToolbarGroup { items = new List<string> { "Cut", "Copy", "Paste", "PasteText", "PasteFromWord", "-", "Undo", "Redo" }, name = "clipboard" }); toolbarSetStandard.ToolbarGroups.Add( new ToolbarGroup { items = new List<string> { "Link", "Unlink", "Anchor" }, name = "link" }); toolbarSetStandard.ToolbarGroups.Add( new ToolbarGroup { items = new List<string> { "Image", "Mathjax", "oembed", "HorizontalRule" }, name = "insert" }); toolbarSetStandard.ToolbarGroups.Add( new ToolbarGroup { items = new List<string> { "Maximize" }, name = "tools" }); toolbarSetStandard.ToolbarGroups.Add( new ToolbarGroup { items = new List<string> { "Source" }, name = "document" }); toolbarSetStandard.ToolbarGroups.Add( new ToolbarGroup { items = new List<string> { "/" }, name = "rowBreak", }); toolbarSetStandard.ToolbarGroups.Add( new ToolbarGroup { items = new List<string> { "Bold", "Italic", "Strike", "RemoveFormat" }, name = "basicstyles" }); toolbarSetStandard.ToolbarGroups.Add( new ToolbarGroup { items = new List<string> { "NumberedList", "BulletedList", "-", "Outdent", "Indent", "Blockquote" }, name = "paragraph" }); toolbarSetStandard.ToolbarGroups.Add( new ToolbarGroup { items = new List<string> { "Styles" }, name = "styles" }); toolbarSetStandard.ToolbarGroups.Add( new ToolbarGroup { items = new List<string> { "Format" }, name = "format" }); toolbarSetStandard.ToolbarGroups.Add( new ToolbarGroup { items = new List<string> { "About" }, name = "about" }); return toolbarSetStandard; } case "Full": { var toolbarSetFull = new ToolbarSet("Full", 20); // Full Toolbar toolbarSetFull.ToolbarGroups.Add( new ToolbarGroup { items = new List<string> { "Source", "-", "Preview", "Print", "-", "Templates" }, name = "document" }); toolbarSetFull.ToolbarGroups.Add( new ToolbarGroup { items = new List<string> { "Cut", "Copy", "Paste", "PasteText", "PasteFromWord", "-", "Undo", "Redo", }, name = "clipboard" }); toolbarSetFull.ToolbarGroups.Add( new ToolbarGroup { items = new List<string> { "Find", "Replace", "-", "SelectAll", "-", "SpellChecker", "Scayt" }, name = "editing" }); toolbarSetFull.ToolbarGroups.Add( new ToolbarGroup { items = new List<string> { "Maximize", "ShowBlocks", "-", "About" }, name = "tools" }); toolbarSetFull.ToolbarGroups.Add( new ToolbarGroup { items = new List<string> { "/" }, name = "rowBreak", }); toolbarSetFull.ToolbarGroups.Add( new ToolbarGroup { items = new List<string> { "NumberedList", "BulletedList", "-", "Outdent", "Indent", "Blockquote", "CreateDiv", "-", "JustifyLeft", "JustifyCenter", "JustifyRight", "JustifyBlock", "-", "BidiLtr", "BidiRtl" }, name = "paragraph" }); toolbarSetFull.ToolbarGroups.Add( new ToolbarGroup { items = new List<string> { "Link", "Unlink", "Anchor" }, name = "links" }); toolbarSetFull.ToolbarGroups.Add( new ToolbarGroup { items = new List<string> { "Image", "Mathjax", "oembed", "syntaxhighlight", "Table", "HorizontalRule", "Smiley", "SpecialChar", "PageBreak", "Iframe", }, name = "insert" }); toolbarSetFull.ToolbarGroups.Add( new ToolbarGroup { items = new List<string> { "/" }, name = "rowBreak", }); toolbarSetFull.ToolbarGroups.Add( new ToolbarGroup { items = new List<string> { "Bold", "Italic", "Underline", "Strike", "Subscript", "Superscript", "-", "RemoveFormat" }, name = "basicstyles" }); toolbarSetFull.ToolbarGroups.Add( new ToolbarGroup { items = new List<string> { "Styles", "Format", "Font", "FontSize" }, name = "styles" }); toolbarSetFull.ToolbarGroups.Add( new ToolbarGroup { items = new List<string> { "TextColor", "BGColor" }, name = "colors" }); return toolbarSetFull; } } return null; }