Skip to content

Commit

Permalink
Added IronyTextBox control, a wrapper for FCTB with Irony parser supp…
Browse files Browse the repository at this point in the history
…ort.
  • Loading branch information
yallie committed Mar 11, 2018
1 parent ed9627b commit 33164d3
Show file tree
Hide file tree
Showing 8 changed files with 488 additions and 4 deletions.
12 changes: 12 additions & 0 deletions Irony.WinForms/035.Irony.WinForms.2010.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@
<Reference Include="System.Xml" />
</ItemGroup>
<ItemGroup>
<Compile Include="BorderStyleEx.cs" />
<Compile Include="Exceptions\fmShowException.cs">
<SubType>Form</SubType>
</Compile>
Expand Down Expand Up @@ -96,7 +97,15 @@
<Compile Include="Highlighter\FastColoredTextBoxHighlighter.cs" />
<Compile Include="Highlighter\RichTextBoxHighlighter.cs" />
<Compile Include="Highlighter\WavyLineStyle.cs" />
<Compile Include="IronyTextBox.cs">
<SubType>UserControl</SubType>
</Compile>
<Compile Include="IronyTextBox.Designer.cs">
<DependentUpon>IronyTextBox.cs</DependentUpon>
</Compile>
<Compile Include="Properties\AssemblyInfo.cs" />
<Compile Include="Proxies\DuckTypingProxy.cs" />
<Compile Include="Proxies\TextBoxProxy.cs" />
</ItemGroup>
<ItemGroup>
<Content Include="Highlighter\AboutCodeHighlighter.txt" />
Expand All @@ -123,6 +132,9 @@
<EmbeddedResource Include="FastColoredTextBox\ReplaceForm.resx">
<DependentUpon>ReplaceForm.cs</DependentUpon>
</EmbeddedResource>
<EmbeddedResource Include="IronyTextBox.resx">
<DependentUpon>IronyTextBox.cs</DependentUpon>
</EmbeddedResource>
</ItemGroup>
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
<!-- To modify your build process, add your task inside one of the targets below and uncomment it.
Expand Down
29 changes: 29 additions & 0 deletions Irony.WinForms/BorderStyleEx.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace Irony.WinForms {
/// <summary>
/// Specifies the border style for the control.
/// </summary>
public enum BorderStyleEx {
/// <summary>
/// No border.
/// </summary>
None = BorderStyle.None,
/// <summary>
/// Single-line border.
/// </summary>
FixedSingle = BorderStyle.FixedSingle,
/// <summary>
/// A three-dimensional border.
/// </summary>
Fixed3D = BorderStyle.Fixed3D,
/// <summary>
/// A border supplied by system theme.
/// </summary>
VisualStyle = 100,
}
}
6 changes: 2 additions & 4 deletions Irony.WinForms/FastColoredTextBox/FastColoredTextBox.cs
Original file line number Diff line number Diff line change
Expand Up @@ -622,10 +622,8 @@ public Language Language
/// </summary>
[Browsable(true)]
[DefaultValue(null)]
[Editor("System.Design.FileNameEditor, System.Design", typeof (UITypeEditor))]
[Description(
"XML file with description of syntax highlighting. This property works only with Language == Language.Custom."
)]
[Editor("System.Windows.Forms.Design.FileNameEditor, System.Design, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a", typeof(UITypeEditor))]
[Description("XML file with description of syntax highlighting. This property works only with Language == Language.Custom.")]
public string DescriptionFile
{
get { return descriptionFile; }
Expand Down
55 changes: 55 additions & 0 deletions Irony.WinForms/IronyTextBox.Designer.cs

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

113 changes: 113 additions & 0 deletions Irony.WinForms/IronyTextBox.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,113 @@
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Drawing;
using System.Data;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Drawing.Design;
using System.Windows.Forms.VisualStyles;
using Irony.WinForms.Proxies;

namespace Irony.WinForms {
/// <summary>
/// TextBox with syntax highlighting support based on Irony toolkit.
/// </summary>
public partial class IronyTextBox : UserControl {
BorderStyleEx _borderStyleEx = BorderStyleEx.None;

/// <summary>
/// Initializes a new instance of the <see cref="IronyTextBox" /> class.
/// </summary>
public IronyTextBox() {
InitializeComponent();
TextBoxProxy = new Lazy<TextBox>(() => new TextBoxProxy(FastColoredTextBox).Instance);
BorderStyleEx = BorderStyleEx.VisualStyle;
}

/// <summary>
/// Gets or sets the TextBox proxy object.
/// </summary>
private Lazy<TextBox> TextBoxProxy { get; set; }

/// <summary>
/// Allows converting IronyTextBox into TextBox implicitly.
/// </summary>
/// <param name="ironyTextBox">The irony text box.</param>
public static implicit operator TextBox(IronyTextBox ironyTextBox) {
return ironyTextBox.TextBoxProxy.Value;
}

/// <summary>
/// Gets or sets the text associated with this <see cref="IronyTextBox"/>.
/// </summary>
[DefaultValue(null), Browsable(true), DesignerSerializationVisibility(DesignerSerializationVisibility.Visible), Localizable(true)]
[Editor("System.ComponentModel.Design.MultilineStringEditor, System.Design, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a", typeof(UITypeEditor))]
public override string Text {
get { return FastColoredTextBox.Text; }
set {
FastColoredTextBox.Text = value;
FastColoredTextBox.SelectionLength = 0;
FastColoredTextBox.SelectionStart = 0;
FastColoredTextBox.DoCaretVisible();
}
}

/// <summary>
/// Gets or sets the border style of the control.
/// </summary>
[DefaultValue(BorderStyleEx.VisualStyle), Browsable(true)]
public BorderStyleEx BorderStyleEx {
get { return _borderStyleEx; }
set {
if (_borderStyleEx != value) {
_borderStyleEx = value;
if (_borderStyleEx != BorderStyleEx.VisualStyle) {
BorderStyle = (BorderStyle)value;
Padding = new Padding(0);
} else {
BorderStyle = BorderStyle.None;
if (Application.RenderWithVisualStyles)
Padding = new Padding(1);
else
Padding = new Padding(2);
}
Invalidate();
}
}
}

/// <summary>
/// Hide the inherited BorderStyle property.
/// </summary>
[Browsable(false), DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
public new BorderStyle BorderStyle {
get { return base.BorderStyle; }
set { base.BorderStyle = value; }
}

/// <summary>
/// Hide the inherited Padding property.
/// </summary>
[Browsable(false), DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
public new Padding Padding {
get { return base.Padding; }
set { base.Padding = value; }
}

/// <summary>
/// Raises the <see cref="E:Paint" /> event.
/// </summary>
/// <param name="args">The <see cref="PaintEventArgs" /> instance containing the event data.</param>
protected override void OnPaint(PaintEventArgs args) {
base.OnPaint(args);
if (Application.RenderWithVisualStyles)
ControlPaint.DrawVisualStyleBorder(args.Graphics, new Rectangle(0, 0, Width - 1, Height - 1));
else {
ControlPaint.DrawBorder3D(args.Graphics, new Rectangle(0, 0, Width, Height), Border3DStyle.SunkenOuter);
ControlPaint.DrawBorder3D(args.Graphics, new Rectangle(1, 1, Width - 2, Height - 2), Border3DStyle.SunkenInner);
}
}
}
}
120 changes: 120 additions & 0 deletions Irony.WinForms/IronyTextBox.resx
Original file line number Diff line number Diff line change
@@ -0,0 +1,120 @@
<?xml version="1.0" encoding="utf-8"?>
<root>
<!--
Microsoft ResX Schema
Version 2.0
The primary goals of this format is to allow a simple XML format
that is mostly human readable. The generation and parsing of the
various data types are done through the TypeConverter classes
associated with the data types.
Example:
... ado.net/XML headers & schema ...
<resheader name="resmimetype">text/microsoft-resx</resheader>
<resheader name="version">2.0</resheader>
<resheader name="reader">System.Resources.ResXResourceReader, System.Windows.Forms, ...</resheader>
<resheader name="writer">System.Resources.ResXResourceWriter, System.Windows.Forms, ...</resheader>
<data name="Name1"><value>this is my long string</value><comment>this is a comment</comment></data>
<data name="Color1" type="System.Drawing.Color, System.Drawing">Blue</data>
<data name="Bitmap1" mimetype="application/x-microsoft.net.object.binary.base64">
<value>[base64 mime encoded serialized .NET Framework object]</value>
</data>
<data name="Icon1" type="System.Drawing.Icon, System.Drawing" mimetype="application/x-microsoft.net.object.bytearray.base64">
<value>[base64 mime encoded string representing a byte array form of the .NET Framework object]</value>
<comment>This is a comment</comment>
</data>
There are any number of "resheader" rows that contain simple
name/value pairs.
Each data row contains a name, and value. The row also contains a
type or mimetype. Type corresponds to a .NET class that support
text/value conversion through the TypeConverter architecture.
Classes that don't support this are serialized and stored with the
mimetype set.
The mimetype is used for serialized objects, and tells the
ResXResourceReader how to depersist the object. This is currently not
extensible. For a given mimetype the value must be set accordingly:
Note - application/x-microsoft.net.object.binary.base64 is the format
that the ResXResourceWriter will generate, however the reader can
read any of the formats listed below.
mimetype: application/x-microsoft.net.object.binary.base64
value : The object must be serialized with
: System.Runtime.Serialization.Formatters.Binary.BinaryFormatter
: and then encoded with base64 encoding.
mimetype: application/x-microsoft.net.object.soap.base64
value : The object must be serialized with
: System.Runtime.Serialization.Formatters.Soap.SoapFormatter
: and then encoded with base64 encoding.
mimetype: application/x-microsoft.net.object.bytearray.base64
value : The object must be serialized into a byte array
: using a System.ComponentModel.TypeConverter
: and then encoded with base64 encoding.
-->
<xsd:schema id="root" xmlns="" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:msdata="urn:schemas-microsoft-com:xml-msdata">
<xsd:import namespace="http://www.w3.org/XML/1998/namespace" />
<xsd:element name="root" msdata:IsDataSet="true">
<xsd:complexType>
<xsd:choice maxOccurs="unbounded">
<xsd:element name="metadata">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="value" type="xsd:string" minOccurs="0" />
</xsd:sequence>
<xsd:attribute name="name" use="required" type="xsd:string" />
<xsd:attribute name="type" type="xsd:string" />
<xsd:attribute name="mimetype" type="xsd:string" />
<xsd:attribute ref="xml:space" />
</xsd:complexType>
</xsd:element>
<xsd:element name="assembly">
<xsd:complexType>
<xsd:attribute name="alias" type="xsd:string" />
<xsd:attribute name="name" type="xsd:string" />
</xsd:complexType>
</xsd:element>
<xsd:element name="data">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
<xsd:element name="comment" type="xsd:string" minOccurs="0" msdata:Ordinal="2" />
</xsd:sequence>
<xsd:attribute name="name" type="xsd:string" use="required" msdata:Ordinal="1" />
<xsd:attribute name="type" type="xsd:string" msdata:Ordinal="3" />
<xsd:attribute name="mimetype" type="xsd:string" msdata:Ordinal="4" />
<xsd:attribute ref="xml:space" />
</xsd:complexType>
</xsd:element>
<xsd:element name="resheader">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
</xsd:sequence>
<xsd:attribute name="name" type="xsd:string" use="required" />
</xsd:complexType>
</xsd:element>
</xsd:choice>
</xsd:complexType>
</xsd:element>
</xsd:schema>
<resheader name="resmimetype">
<value>text/microsoft-resx</value>
</resheader>
<resheader name="version">
<value>2.0</value>
</resheader>
<resheader name="reader">
<value>System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
</resheader>
<resheader name="writer">
<value>System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
</resheader>
</root>
Loading

0 comments on commit 33164d3

Please sign in to comment.