📄 freetextboxeditor.cs
字号:
namespace CommunityServer.FreeTextBoxWrapper
{
using Aylar.Highlight;
using CommunityServer;
using CommunityServer.Components;
using CommunityServer.Configuration;
using CommunityServer.Controls;
using FreeTextBoxControls;
using FreeTextBoxControls.Support;
using System;
using System.Collections;
using System.Drawing;
using System.Text;
using System.Text.RegularExpressions;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Xml;
public class FreeTextBoxEditor : FreeTextBox, ITextEditor
{
public FreeTextBoxEditor()
{
this._styleName = null;
base.ImageGalleryPath = "~/images";
}
protected void AddItems(Toolbar tb, bool sep, params ToolbarItem[] items)
{
if (sep)
{
tb.Items.Add(new ToolbarSeparator());
}
foreach (ToolbarItem item1 in items)
{
tb.Items.Add(item1);
}
}
protected Toolbar CommunityServerToolbar()
{
Toolbar toolbar1 = null;
toolbar1 = new Toolbar();
if (!this.showToolbarGeneral)
{
toolbar1.Items.Add(new WordClean());
}
if (!this.useLanguageToolbar)
{
toolbar1.Items.Add(new InsertCode());
}
if (this.allowObjectTags)
{
toolbar1.Items.Add(new InsertFlash());
toolbar1.Items.Add(new InsertMedia());
toolbar1.Items.Add(new InsertReal());
}
toolbar1.Items.Add(new ContentSelectorButton(this.ClientID));
if (CSContext.Current.SiteSettings.EnableEmoticons && CSContext.Current.User.Profile.EnableEmoticons)
{
if (!this.useOldSmilies)
{
toolbar1.Items.Add(new InsertEmoticons());
return toolbar1;
}
toolbar1.Items.Add(new InsertSmileyDropDownList());
}
return toolbar1;
}
public void Configure()
{
if (base.Height.IsEmpty)
{
base.Height = Unit.Pixel(400);
}
if (base.Width.IsEmpty)
{
base.Width = Unit.Pixel(400);
}
base.ButtonImagesLocation = ResourceLocation.ExternalFile;
base.ToolbarImagesLocation = ResourceLocation.ExternalFile;
base.JavaScriptLocation = ResourceLocation.ExternalFile;
base.BreakMode = BreakMode.Paragraph;
base.AutoGenerateToolbarsFromString = false;
base.GutterBackColor = Color.Transparent;
base.BackColor = Color.Transparent;
base.ToolbarBackColor = Color.Transparent;
base.FormatHtmlTagsToXhtml = false;
base.SupportFolder = "~" + CSConfiguration.GetConfig().FilesPath + "FreeTextBox3/";
string text1 = CSContext.Current.User.Profile.Language;
if (text1 == "")
{
text1 = CSConfiguration.GetConfig().DefaultLanguage;
}
base.Language = text1;
base.DesignModeCss = Globals.GetSiteUrls().Home + "FreeTextBox3/ftb.css";
if (base.EnableSsl)
{
base.SslUrl = Globals.GetSiteUrls().Home + "FreeTextBox3/blank.htm";
}
base.ImageGalleryUrl = Globals.GetSiteUrls().Home + "FreeTextBox3/ftb.imagegallery.aspx?rif={1}&cif={0}";
base.ImageGalleryUrl = base.ImageGalleryUrl.Replace("{1}", base.ImageGalleryPath);
this.CreateToolBars();
}
protected virtual void CreateToolBars()
{
base.Toolbars.Clear();
base.Toolbars.Add(this.LayoutToolbar());
base.Toolbars.Add(this.EditToolBar());
base.Toolbars.Add(this.FormatingToolBar());
base.Toolbars.Add(this.ParagraphToolBar());
if (this.showToolbarTables)
{
base.Toolbars.Add(this.TablesToolBar());
}
if (this.showToolbarGeneral)
{
base.Toolbars.Add(this.GeneralToolbar());
}
if (this.useLanguageToolbar)
{
base.Toolbars.Add(this.DeveloperEnchancedToolbar());
}
base.Toolbars.Add(this.CommunityServerToolbar());
}
protected Toolbar DeveloperEnchancedToolbar()
{
Toolbar toolbar1 = new Toolbar();
XmlDocument document1 = new XmlDocument();
try
{
XmlNodeList list1 = Global.GetConfiguration(string.Empty).SelectNodes("//definition");
ToolbarItem[] itemArray1 = new ToolbarItem[list1.Count];
long num1 = 0;
foreach (XmlNode node1 in list1)
{
string text1 = node1.Attributes["name"].Value.ToLower();
text1 = "button_" + Regex.Replace(text1, @"\W", "", RegexOptions.IgnoreCase);
ToolbarButton button1 = new ToolbarButton(node1.Attributes["name"].Value + " code", null, text1);
button1.ScriptBlock = "this.ftb.SurroundHtml('[code language=\"" + node1.Attributes["name"].Value + "\"]','[/code]');";
num1++;
itemArray1.SetValue(button1, num1);
}
this.AddItems(toolbar1, false, itemArray1);
}
catch
{
ToolbarItem[] itemArray2 = new ToolbarItem[5];
ToolbarButton button2 = new ToolbarButton("ASP/ASP.NET", null, "button_aspaspnet");
button2.ScriptBlock = "this.ftb.SurroundHtml('[code language=\"ASP/ASP.NET\"]','[/code]');";
itemArray2.SetValue(button2, 0);
button2 = new ToolbarButton("C#", null, "button_c");
button2.ScriptBlock = "this.ftb.SurroundHtml('[code language=\"C#\"]','[/code]');";
itemArray2.SetValue(button2, 1);
button2 = new ToolbarButton("JScript", null, "button_jscript");
button2.ScriptBlock = "this.ftb.SurroundHtml('[code language=\"JScript\"]','[/code]');";
itemArray2.SetValue(button2, 2);
button2 = new ToolbarButton("T-SQL", null, "button_tsql");
button2.ScriptBlock = "this.ftb.SurroundHtml('[code language=\"T-SQL\"]','[/code]');";
itemArray2.SetValue(button2, 3);
button2 = new ToolbarButton("VB.NET", null, "button_vbnet");
button2.ScriptBlock = "this.ftb.SurroundHtml('[code language=\"VB.NET\"]','[/code]');";
itemArray2.SetValue(button2, 4);
this.AddItems(toolbar1, false, itemArray2);
}
return toolbar1;
}
protected Toolbar DeveloperToolbar()
{
Toolbar toolbar1 = new Toolbar();
ToolbarItem[] itemArray1 = new ToolbarItem[] { new ASPButton(), new CSharpButton(), new JavaScriptButton(), new TSQLButton(), new VBButton() };
this.AddItems(toolbar1, false, itemArray1);
return toolbar1;
}
protected Toolbar EditToolBar()
{
Toolbar toolbar1 = new Toolbar();
if (this.toolbarEdit != null)
{
string[] textArray1 = this.toolbarEdit.Replace(" ", "").Replace(";", ",;,").Replace(",,", ",").ToLower().Split(new char[] { ',' });
for (int num1 = 0; num1 < textArray1.Length; num1++)
{
toolbar1.Items.Add(ToolbarGenerator.ToolbarItemFromString(textArray1[num1]));
}
return toolbar1;
}
ToolbarItem[] itemArray1 = new ToolbarItem[] { new Cut(), new Copy(), new Paste(), new Delete() };
this.AddItems(toolbar1, false, itemArray1);
itemArray1 = new ToolbarItem[] { new Undo(), new Redo(), new Print() };
this.AddItems(toolbar1, true, itemArray1);
return toolbar1;
}
protected Toolbar FormatingToolBar()
{
Toolbar toolbar1 = new Toolbar();
if (this.toolbarFormating != null)
{
string[] textArray1 = this.toolbarFormating.Replace(" ", "").Replace(";", ",;,").Replace(",,", ",").ToLower().Split(new char[] { ',' });
for (int num1 = 0; num1 < textArray1.Length; num1++)
{
toolbar1.Items.Add(ToolbarGenerator.ToolbarItemFromString(textArray1[num1]));
}
return toolbar1;
}
ToolbarItem[] itemArray1 = new ToolbarItem[] { new Bold(), new Italic(), new Underline(), new StrikeThrough(), new SuperScript(), new SubScript(), new RemoveFormat() };
this.AddItems(toolbar1, false, itemArray1);
return toolbar1;
}
protected Toolbar GeneralToolbar()
{
Toolbar toolbar1 = new Toolbar();
if (this.toolbarGeneral != null)
{
string[] textArray1 = this.toolbarGeneral.Replace(" ", "").Replace(";", ",;,").Replace(",,", ",").ToLower().Split(new char[] { ',' });
for (int num1 = 0; num1 < textArray1.Length; num1++)
{
toolbar1.Items.Add(ToolbarGenerator.ToolbarItemFromString(textArray1[num1]));
}
return toolbar1;
}
ToolbarItem[] itemArray1 = new ToolbarItem[] { new InsertRule(), new InsertDate(), new InsertTime() };
this.AddItems(toolbar1, false, itemArray1);
itemArray1 = new ToolbarItem[] { new SymbolsMenu(), new InsertFlash(), new InsertMedia(), new InsertReal(), new SelectAll(), new WordClean() };
this.AddItems(toolbar1, true, itemArray1);
return toolbar1;
}
protected Toolbar LayoutToolbar()
{
Toolbar toolbar1 = new Toolbar();
if (this.toolbarLayout != null)
{
string[] textArray1 = this.toolbarLayout.Replace(" ", "").Replace(";", ",;,").Replace(",,", ",").ToLower().Split(new char[] { ',' });
for (int num1 = 0; num1 < textArray1.Length; num1++)
{
toolbar1.Items.Add(ToolbarGenerator.ToolbarItemFromString(textArray1[num1]));
}
return toolbar1;
}
ToolbarItem[] itemArray1 = new ToolbarItem[] { new ParagraphMenu(), new FontFacesMenu(), new FontSizesMenu(), new FontForeColorsMenu(), new FontBackColorsMenu() };
this.AddItems(toolbar1, false, itemArray1);
return toolbar1;
}
protected override void OnPreRender(EventArgs e)
{
this.Configure();
base.OnPreRender(e);
this.Page.ClientScript.RegisterClientScriptBlock(this.Page.GetType(), "FTB_ClientText", this.RenderClientTextScript());
}
protected Toolbar ParagraphToolBar()
{
Toolbar toolbar1 = new Toolbar();
if (this.toolbarParagraph != null)
{
string[] textArray1 = this.toolbarParagraph.Replace(" ", "").Replace(";", ",;,").Replace(",,", ",").ToLower().Split(new char[] { ',' });
for (int num1 = 0; num1 < textArray1.Length; num1++)
{
toolbar1.Items.Add(ToolbarGenerator.ToolbarItemFromString(textArray1[num1]));
}
return toolbar1;
}
ToolbarItem[] itemArray1 = new ToolbarItem[] { new JustifyLeft(), new JustifyRight(), new JustifyCenter(), new JustifyFull() };
this.AddItems(toolbar1, false, itemArray1);
itemArray1 = new ToolbarItem[] { new FreeTextBoxControls.BulletedList(), new NumberedList(), new Indent(), new Outdent() };
this.AddItems(toolbar1, true, itemArray1);
itemArray1 = new ToolbarItem[] { new CreateLink(), new Unlink(), new InsertImage() };
this.AddItems(toolbar1, true, itemArray1);
return toolbar1;
}
protected string RenderClientTextScript()
{
StringBuilder builder1 = new StringBuilder();
builder1.Append("<script type=\"text/javascript\" src=\"" + base.SupportFolder + "FTB-Extensions.js\"></script>\r\n");
builder1.AppendFormat("<script type=\"text/javascript\">{0}", Environment.NewLine);
builder1.AppendFormat("\tfunction FTBClientText() {{{0}", Environment.NewLine);
builder1.AppendFormat("\t\treturn FTB_API['{0}'].GetHtml();{1}", this.ClientID, Environment.NewLine);
builder1.AppendFormat("\t}}{0}", Environment.NewLine);
builder1.Append("</script>");
return builder1.ToString();
}
protected override void RenderRichEditor(HtmlTextWriter writer)
{
base.RenderRichEditor(writer);
writer.WriteLine("<iframe frameborder=\"0\" id=\"" + this.ClientID + "_Popup\" src=\"" + (base.EnableSsl ? base.SslUrl.ToString() : "about:blank") + "\" style=\"Z-INDEX: -1; VISIBILITY: hidden; POSITION: absolute; \"></iframe>");
}
protected override void RenderTabStyles(HtmlTextWriter writer)
{
writer.WriteLine("\r\n\t\t\t." + this.ClientID + "_StartTabOn {\r\n\t\t\t\tdisplay: none;\r\n\t\t\t}\r\n\t\t\t." + this.ClientID + "_StartTabOff {\r\n\t\t\t}\r\n\t\t\t." + this.ClientID + "_TabOffRight {\r\n\t\t\t\tfont: 8pt MS Sans Serif;\r\n\t\t\t\tpadding: 1px 5px;\r\n\t\t\t\tborder: 0px;\r\n\t\t\t\tbackground-color: #fff;\r\n\t\t\t\tcursor: hand;\r\n\t\t\t}\r\n\t\t\t." + this.ClientID + "_TabOffRight:hover {\r\n\t\t\t\tborder: solid 1px #666666;\r\n\t\t\t}\r\n\t\t\t." + this.ClientID + "_TabOffLeft {\r\n\t\t\t\tfont: 8pt MS Sans Serif;\r\n\t\t\t\tpadding: 1px 5px;\r\n\t\t\t\tborder: 0px;\r\n\t\t\t\tbackground-color: #fff;\r\n\t\t\t\tcursor: hand;\r\n\t\t\t}\r\n\t\t\t." + this.ClientID + "_EndTab {\r\n\t\t\t\tfont: 10pt MS Sans Serif;\r\n\t\t\t\twidth: 100%;\r\n\t\t\t\tpadding: 1px;\r\n\t\t\t\tborder: 0px;\r\n\t\t\t}\r\n\t\t\t." + this.ClientID + "_TabOn {\r\n\t\t\t\tfont: 8pt MS Sans Serif;\r\n\t\t\t\tpadding: 1px 5px;\r\n\t\t\t\tborder: solid 1px #666666;\r\n\t\t\t\tbackground-color: #E5E5E5;\r\n\t\t\t\tcursor: default;\r\n\t\t\t}\r\n\t\t\t." + this.ClientID + "_AncestorArea {\r\n\t\t\t\t" + (!base.ShowTagPath ? "display:none;" : "") + "\r\n\t\t\t\tmargin-left: 4px;\r\n\t\t\t}\r\n\t\t\t." + this.ClientID + "_AncestorArea a {\r\n\t\t\t\tpadding: 1px;\r\n\t\t\t\tmargin-left: 2px;\r\n\t\t\t\tmargin-right: 2px;\r\n\t\t\t\tborder: 1px solid #808080;\t\r\n\t\t\t\tcolor: #000;\r\n\t\t\t\tfont-family: arial;\r\n\t\t\t\tfont-size: 11px;\r\n\t\t\t}\r\n\t\t\t." + this.ClientID + "_AncestorArea a:link, ." + this.ClientID + "_AncestorArea a:visited, ." + this.ClientID + "_AncestorArea a:active {\r\n\t\t\t\tbackground-color: transparent;\r\n\t\t\t\ttext-decoration: none;\r\n\t\t\t}\r\n\t\t\t." + this.ClientID + "_AncestorArea a:hover {\r\n\t\t\t\ttext-decoration: none;\r\n\t\t\t\tbackground-color: #316AC5;\r\n\t\t\t\tborder: 1px solid #fff;\r\n\t\t\t\tcolor:#fff;\r\n\t\t\t}\r\n\t\t\t");
}
protected Toolbar SmiliesToolbar()
{
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -