From 12b2f9c2431a24e2a1bb4a0f6d01863cfa33e5fa Mon Sep 17 00:00:00 2001 From: Alexey Yakovlev Date: Sat, 21 Apr 2012 23:26:34 +0400 Subject: [PATCH] Moved syntax highlighter from GrammarExplorer to a separate project. --- .../030.Irony.GrammarExplorer.2010.csproj | 22 +---- Irony.GrammarExplorer/Program.cs | 5 +- Irony.GrammarExplorer/fmGrammarExplorer.cs | 3 +- Irony.WinForms/035.Irony.WinForms.2010.csproj | 84 +++++++++++++++++++ .../Exceptions}/fmShowException.Designer.cs | 10 +-- .../Exceptions}/fmShowException.cs | 6 +- .../Exceptions}/fmShowException.resx | 0 .../Highlighter/AboutCodeHighlighter.txt | 0 .../Highlighter/EditorAdapter.cs | 3 +- .../Highlighter/EditorViewAdapter.cs | 2 +- .../FastColoredTextBoxHighlighter.cs | 2 +- .../Highlighter/RichTextBoxHighlighter.cs | 40 ++++----- .../Highlighter/WavyLineStyle.cs | 2 +- Irony.WinForms/Properties/AssemblyInfo.cs | 36 ++++++++ Irony_All.2010.sln | 14 ++++ 15 files changed, 176 insertions(+), 53 deletions(-) create mode 100644 Irony.WinForms/035.Irony.WinForms.2010.csproj rename {Irony.GrammarExplorer => Irony.WinForms/Exceptions}/fmShowException.Designer.cs (94%) rename {Irony.GrammarExplorer => Irony.WinForms/Exceptions}/fmShowException.cs (88%) rename {Irony.GrammarExplorer => Irony.WinForms/Exceptions}/fmShowException.resx (100%) rename {Irony.GrammarExplorer => Irony.WinForms}/Highlighter/AboutCodeHighlighter.txt (100%) rename {Irony.GrammarExplorer => Irony.WinForms}/Highlighter/EditorAdapter.cs (95%) rename {Irony.GrammarExplorer => Irony.WinForms}/Highlighter/EditorViewAdapter.cs (97%) rename {Irony.GrammarExplorer => Irony.WinForms}/Highlighter/FastColoredTextBoxHighlighter.cs (96%) rename {Irony.GrammarExplorer => Irony.WinForms}/Highlighter/RichTextBoxHighlighter.cs (88%) rename {Irony.GrammarExplorer => Irony.WinForms}/Highlighter/WavyLineStyle.cs (92%) create mode 100644 Irony.WinForms/Properties/AssemblyInfo.cs diff --git a/Irony.GrammarExplorer/030.Irony.GrammarExplorer.2010.csproj b/Irony.GrammarExplorer/030.Irony.GrammarExplorer.2010.csproj index af41c3c..26a6177 100644 --- a/Irony.GrammarExplorer/030.Irony.GrammarExplorer.2010.csproj +++ b/Irony.GrammarExplorer/030.Irony.GrammarExplorer.2010.csproj @@ -89,10 +89,6 @@ - - - - @@ -107,10 +103,6 @@ Resources.Designer.cs Designer - - Designer - fmShowException.cs - True Resources.resx @@ -126,22 +118,16 @@ Settings.settings True - - Form - - - fmShowException.cs - - - - - {321A7F5D-00C2-4095-9970-075CDEE8C139} 015.Irony.Interpreter.2010 + + {70D319F3-3C0C-4EB5-A271-58ED22FB3070} + 035.Irony.WinForms.2010 + {D81F5C91-D7DB-46E5-BC99-49488FB6814C} 010.Irony.2010 diff --git a/Irony.GrammarExplorer/Program.cs b/Irony.GrammarExplorer/Program.cs index 2231e4c..17fe545 100644 --- a/Irony.GrammarExplorer/Program.cs +++ b/Irony.GrammarExplorer/Program.cs @@ -3,8 +3,8 @@ * Copyright (c) Roman Ivantsov * This source code is subject to terms and conditions of the MIT License * for Irony. A copy of the license can be found in the License.txt file - * at the root of this distribution. - * By using this source code in any fashion, you are agreeing to be bound by the terms of the + * at the root of this distribution. + * By using this source code in any fashion, you are agreeing to be bound by the terms of the * MIT License. * You must not remove this notice from this software. * **********************************************************************************/ @@ -14,6 +14,7 @@ using System.Collections.Generic; using System.Windows.Forms; using System.Diagnostics; +using Irony.WinForms.Exceptions; namespace Irony.GrammarExplorer { class Program : MarshalByRefObject { diff --git a/Irony.GrammarExplorer/fmGrammarExplorer.cs b/Irony.GrammarExplorer/fmGrammarExplorer.cs index 66f9ef9..f314090 100644 --- a/Irony.GrammarExplorer/fmGrammarExplorer.cs +++ b/Irony.GrammarExplorer/fmGrammarExplorer.cs @@ -24,7 +24,8 @@ using Irony.Ast; using Irony.Parsing; using Irony.GrammarExplorer.Properties; -using Irony.GrammarExplorer.Highlighter; +using Irony.WinForms.Exceptions; +using Irony.WinForms.Highlighter; namespace Irony.GrammarExplorer { using ScriptException = Irony.Interpreter.ScriptException; //that's the only place we use stuff from Irony.Interpreter diff --git a/Irony.WinForms/035.Irony.WinForms.2010.csproj b/Irony.WinForms/035.Irony.WinForms.2010.csproj new file mode 100644 index 0000000..917adc7 --- /dev/null +++ b/Irony.WinForms/035.Irony.WinForms.2010.csproj @@ -0,0 +1,84 @@ + + + + Debug + AnyCPU + 8.0.30703 + 2.0 + {70D319F3-3C0C-4EB5-A271-58ED22FB3070} + Library + Properties + Irony.WinForms + Irony.WinForms + v4.0 + 512 + Client + + + true + full + false + bin\Debug\ + DEBUG;TRACE + prompt + 4 + + + pdbonly + true + bin\Release\ + TRACE + prompt + 4 + + + + ..\Libraries\FastColoredTextBox\FastColoredTextBox.dll + + + + + + + + + + + + + + Form + + + fmShowException.cs + + + + + + + + + + + + + + {D81F5C91-D7DB-46E5-BC99-49488FB6814C} + 010.Irony.2010 + + + + + fmShowException.cs + + + + + \ No newline at end of file diff --git a/Irony.GrammarExplorer/fmShowException.Designer.cs b/Irony.WinForms/Exceptions/fmShowException.Designer.cs similarity index 94% rename from Irony.GrammarExplorer/fmShowException.Designer.cs rename to Irony.WinForms/Exceptions/fmShowException.Designer.cs index 29b8b32..2882e4c 100644 --- a/Irony.GrammarExplorer/fmShowException.Designer.cs +++ b/Irony.WinForms/Exceptions/fmShowException.Designer.cs @@ -1,4 +1,4 @@ -namespace Irony.GrammarExplorer { +namespace Irony.WinForms.Exceptions { partial class fmShowException { /// /// Required designer variable. @@ -25,9 +25,9 @@ protected override void Dispose(bool disposing) { private void InitializeComponent() { this.txtException = new System.Windows.Forms.TextBox(); this.SuspendLayout(); - // + // // txtException - // + // this.txtException.AcceptsReturn = true; this.txtException.AcceptsTab = true; this.txtException.Dock = System.Windows.Forms.DockStyle.Fill; @@ -40,9 +40,9 @@ private void InitializeComponent() { this.txtException.ScrollBars = System.Windows.Forms.ScrollBars.Vertical; this.txtException.Size = new System.Drawing.Size(764, 334); this.txtException.TabIndex = 1; - // + // // fmShowException - // + // this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F); this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; this.ClientSize = new System.Drawing.Size(764, 334); diff --git a/Irony.GrammarExplorer/fmShowException.cs b/Irony.WinForms/Exceptions/fmShowException.cs similarity index 88% rename from Irony.GrammarExplorer/fmShowException.cs rename to Irony.WinForms/Exceptions/fmShowException.cs index f3d88a0..46f8158 100644 --- a/Irony.GrammarExplorer/fmShowException.cs +++ b/Irony.WinForms/Exceptions/fmShowException.cs @@ -3,8 +3,8 @@ * Copyright (c) Roman Ivantsov * This source code is subject to terms and conditions of the MIT License * for Irony. A copy of the license can be found in the License.txt file - * at the root of this distribution. - * By using this source code in any fashion, you are agreeing to be bound by the terms of the + * at the root of this distribution. + * By using this source code in any fashion, you are agreeing to be bound by the terms of the * MIT License. * You must not remove this notice from this software. * **********************************************************************************/ @@ -18,7 +18,7 @@ using System.Text; using System.Windows.Forms; -namespace Irony.GrammarExplorer { +namespace Irony.WinForms.Exceptions { public partial class fmShowException : Form { public fmShowException() { InitializeComponent(); diff --git a/Irony.GrammarExplorer/fmShowException.resx b/Irony.WinForms/Exceptions/fmShowException.resx similarity index 100% rename from Irony.GrammarExplorer/fmShowException.resx rename to Irony.WinForms/Exceptions/fmShowException.resx diff --git a/Irony.GrammarExplorer/Highlighter/AboutCodeHighlighter.txt b/Irony.WinForms/Highlighter/AboutCodeHighlighter.txt similarity index 100% rename from Irony.GrammarExplorer/Highlighter/AboutCodeHighlighter.txt rename to Irony.WinForms/Highlighter/AboutCodeHighlighter.txt diff --git a/Irony.GrammarExplorer/Highlighter/EditorAdapter.cs b/Irony.WinForms/Highlighter/EditorAdapter.cs similarity index 95% rename from Irony.GrammarExplorer/Highlighter/EditorAdapter.cs rename to Irony.WinForms/Highlighter/EditorAdapter.cs index 245beae..729051b 100644 --- a/Irony.GrammarExplorer/Highlighter/EditorAdapter.cs +++ b/Irony.WinForms/Highlighter/EditorAdapter.cs @@ -18,8 +18,9 @@ using System.Runtime.InteropServices; using System.Diagnostics; using Irony.Parsing; +using Irony.WinForms.Exceptions; -namespace Irony.GrammarExplorer { +namespace Irony.WinForms.Highlighter { public class EditorAdapter { Parser _parser; diff --git a/Irony.GrammarExplorer/Highlighter/EditorViewAdapter.cs b/Irony.WinForms/Highlighter/EditorViewAdapter.cs similarity index 97% rename from Irony.GrammarExplorer/Highlighter/EditorViewAdapter.cs rename to Irony.WinForms/Highlighter/EditorViewAdapter.cs index c49b8a2..55f1c14 100644 --- a/Irony.GrammarExplorer/Highlighter/EditorViewAdapter.cs +++ b/Irony.WinForms/Highlighter/EditorViewAdapter.cs @@ -17,7 +17,7 @@ using System.Threading; using Irony.Parsing; -namespace Irony.GrammarExplorer { +namespace Irony.WinForms.Highlighter { public delegate void ColorizeMethod(); public interface IUIThreadInvoker { void InvokeOnUIThread(ColorizeMethod colorize); diff --git a/Irony.GrammarExplorer/Highlighter/FastColoredTextBoxHighlighter.cs b/Irony.WinForms/Highlighter/FastColoredTextBoxHighlighter.cs similarity index 96% rename from Irony.GrammarExplorer/Highlighter/FastColoredTextBoxHighlighter.cs rename to Irony.WinForms/Highlighter/FastColoredTextBoxHighlighter.cs index 4bb963f..90847ef 100644 --- a/Irony.GrammarExplorer/Highlighter/FastColoredTextBoxHighlighter.cs +++ b/Irony.WinForms/Highlighter/FastColoredTextBoxHighlighter.cs @@ -29,7 +29,7 @@ using System.Diagnostics; using FastColoredTextBoxNS; -namespace Irony.GrammarExplorer.Highlighter { +namespace Irony.WinForms.Highlighter { /// /// Highlights text inside FastColoredTextBox control. diff --git a/Irony.GrammarExplorer/Highlighter/RichTextBoxHighlighter.cs b/Irony.WinForms/Highlighter/RichTextBoxHighlighter.cs similarity index 88% rename from Irony.GrammarExplorer/Highlighter/RichTextBoxHighlighter.cs rename to Irony.WinForms/Highlighter/RichTextBoxHighlighter.cs index 455a33a..dfb465a 100644 --- a/Irony.GrammarExplorer/Highlighter/RichTextBoxHighlighter.cs +++ b/Irony.WinForms/Highlighter/RichTextBoxHighlighter.cs @@ -3,8 +3,8 @@ * Copyright (c) Roman Ivantsov * This source code is subject to terms and conditions of the MIT License * for Irony. A copy of the license can be found in the License.txt file - * at the root of this distribution. - * By using this source code in any fashion, you are agreeing to be bound by the terms of the + * at the root of this distribution. + * By using this source code in any fashion, you are agreeing to be bound by the terms of the * MIT License. * You must not remove this notice from this software. * **********************************************************************************/ @@ -26,14 +26,14 @@ using Irony.Parsing; using System.Diagnostics; -namespace Irony.GrammarExplorer { +namespace Irony.WinForms.Highlighter { public class TokenColorTable : Dictionary { } public class RichTextBoxHighlighter : NativeWindow, IDisposable, IUIThreadInvoker { public RichTextBox TextBox; public readonly TokenColorTable TokenColors = new TokenColorTable(); - public readonly EditorAdapter Adapter; + public readonly EditorAdapter Adapter; public readonly EditorViewAdapter ViewAdapter; private IntPtr _savedEventMask = IntPtr.Zero; @@ -43,7 +43,7 @@ public class RichTextBoxHighlighter : NativeWindow, IDisposable, IUIThreadInvoke #region constructor, initialization and disposing public RichTextBoxHighlighter(RichTextBox textBox, LanguageData language) { TextBox = textBox; - Adapter = new EditorAdapter(language); + Adapter = new EditorAdapter(language); ViewAdapter = new EditorViewAdapter(Adapter, this); InitColorTable(); Connect(); @@ -77,7 +77,7 @@ private void Disconnect() { public void Dispose() { Adapter.Stop(); - _disposed = true; + _disposed = true; Disconnect(); this.ReleaseHandle(); GC.SuppressFinalize(this); @@ -88,7 +88,7 @@ private void InitColorTable() { TokenColors[TokenColor.Identifier] = Color.Black; TokenColors[TokenColor.Keyword] = Color.Blue; TokenColors[TokenColor.Number] = Color.DarkRed; - TokenColors[TokenColor.String] = Color.DarkSlateGray; + TokenColors[TokenColor.String] = Color.DarkSlateGray; TokenColors[TokenColor.Text] = Color.Black; } @@ -106,7 +106,7 @@ void TextBox_KeyDown(object sender, KeyEventArgs e) { void TextBox_TextChanged(object sender, EventArgs e) { //if we are here while colorizing, it means the "change" event is a result of our coloring action - if (_colorizing) return; + if (_colorizing) return; ViewAdapter.SetNewText(TextBox.Text); } void TextBox_ScrollResize(object sender, EventArgs e) { @@ -152,7 +152,7 @@ private void UpdateViewRange() { private int HScrollPos { get { //sometimes explodes with null reference exception - return GetScrollPos((int)TextBox.Handle, SB_HORZ); + return GetScrollPos((int)TextBox.Handle, SB_HORZ); } set { SetScrollPos((IntPtr)TextBox.Handle, SB_HORZ, value, true); @@ -162,7 +162,7 @@ private int HScrollPos { private int VScrollPos { get { - return GetScrollPos((int)TextBox.Handle, SB_VERT); + return GetScrollPos((int)TextBox.Handle, SB_VERT); } set { SetScrollPos((IntPtr)TextBox.Handle, SB_VERT, value, true); @@ -173,25 +173,25 @@ private int VScrollPos { #region Colorizing tokens public void LockTextBox() { - // Stop redrawing: + // Stop redrawing: SendMessage(TextBox.Handle, WM_SETREDRAW, 0, IntPtr.Zero ); - // Stop sending of events: + // Stop sending of events: _savedEventMask = SendMessage(TextBox.Handle, EM_GETEVENTMASK, 0, IntPtr.Zero); //SendMessage(TextBox.Handle, EM_SETEVENTMASK, 0, IntPtr.Zero); } public void UnlockTextBox() { - // turn on events + // turn on events SendMessage(TextBox.Handle, EM_SETEVENTMASK, 0, _savedEventMask); - // turn on redrawing + // turn on redrawing SendMessage(TextBox.Handle, WM_SETREDRAW, 1, IntPtr.Zero); } void Adapter_ColorizeTokens(object sender, ColorizeEventArgs args) { - if (_disposed) return; + if (_disposed) return; //Debug.WriteLine("Coloring " + args.Tokens.Count + " tokens."); _colorizing = true; - + int hscroll = HScrollPos; int vscroll = VScrollPos; int selstart = TextBox.SelectionStart; @@ -214,9 +214,9 @@ void Adapter_ColorizeTokens(object sender, ColorizeEventArgs args) { } private Color GetTokenColor(Token token) { - if (token.EditorInfo == null) return Color.Black; + if (token.EditorInfo == null) return Color.Black; //Right now we scan source, not parse; initially all keywords are recognized as Identifiers; then they are "backpatched" - // by parser when it detects that it is in fact keyword from Grammar. So now this backpatching does not happen, + // by parser when it detects that it is in fact keyword from Grammar. So now this backpatching does not happen, // so we have to detect keywords here var colorIndex = token.EditorInfo.Color; if (token.KeyTerm != null && token.KeyTerm.EditorInfo != null && token.KeyTerm.Flags.IsSet(TermFlags.IsKeyword)) { @@ -232,10 +232,10 @@ private Color GetTokenColor(Token token) { #region IUIThreadInvoker Members public void InvokeOnUIThread(ColorizeMethod colorize) { - TextBox.BeginInvoke(new MethodInvoker(colorize)); + TextBox.BeginInvoke(new MethodInvoker(colorize)); } #endregion }//class -}//namespace +}//namespace diff --git a/Irony.GrammarExplorer/Highlighter/WavyLineStyle.cs b/Irony.WinForms/Highlighter/WavyLineStyle.cs similarity index 92% rename from Irony.GrammarExplorer/Highlighter/WavyLineStyle.cs rename to Irony.WinForms/Highlighter/WavyLineStyle.cs index 377ad23..ac1f358 100644 --- a/Irony.GrammarExplorer/Highlighter/WavyLineStyle.cs +++ b/Irony.WinForms/Highlighter/WavyLineStyle.cs @@ -7,7 +7,7 @@ using System.Drawing; using FastColoredTextBoxNS; -namespace Irony.GrammarExplorer.Highlighter { +namespace Irony.WinForms.Highlighter { /// /// This style draws a wavy line below a given text range. /// diff --git a/Irony.WinForms/Properties/AssemblyInfo.cs b/Irony.WinForms/Properties/AssemblyInfo.cs new file mode 100644 index 0000000..d3f68f0 --- /dev/null +++ b/Irony.WinForms/Properties/AssemblyInfo.cs @@ -0,0 +1,36 @@ +using System.Reflection; +using System.Runtime.CompilerServices; +using System.Runtime.InteropServices; + +// General Information about an assembly is controlled through the following +// set of attributes. Change these attribute values to modify the information +// associated with an assembly. +[assembly: AssemblyTitle("Irony.WinForms")] +[assembly: AssemblyDescription("Windows.Forms controls for Irony.GrammarExplorer")] +[assembly: AssemblyConfiguration("")] +[assembly: AssemblyCompany("")] +[assembly: AssemblyProduct("Irony.WinForms")] +[assembly: AssemblyCopyright("Copyright © 2012 Alexey Yakovlev")] +[assembly: AssemblyTrademark("")] +[assembly: AssemblyCulture("")] + +// Setting ComVisible to false makes the types in this assembly not visible +// to COM components. If you need to access a type in this assembly from +// COM, set the ComVisible attribute to true on that type. +[assembly: ComVisible(false)] + +// The following GUID is for the ID of the typelib if this project is exposed to COM +[assembly: Guid("aa4077ba-1d75-4ff6-bfd2-78c837cf7c9f")] + +// Version information for an assembly consists of the following four values: +// +// Major Version +// Minor Version +// Build Number +// Revision +// +// You can specify all the values or you can default the Build and Revision Numbers +// by using the '*' as shown below: +// [assembly: AssemblyVersion("1.0.*")] +[assembly: AssemblyVersion("1.0.0.0")] +[assembly: AssemblyFileVersion("1.0.0.0")] diff --git a/Irony_All.2010.sln b/Irony_All.2010.sln index 190ab3f..63ec427 100644 --- a/Irony_All.2010.sln +++ b/Irony_All.2010.sln @@ -57,6 +57,8 @@ Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "101.IronySilverlight.2010", EndProject Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "015.Irony.Interpreter.2010", "Irony.Interpreter\015.Irony.Interpreter.2010.csproj", "{321A7F5D-00C2-4095-9970-075CDEE8C139}" EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "035.Irony.WinForms.2010", "Irony.WinForms\035.Irony.WinForms.2010.csproj", "{70D319F3-3C0C-4EB5-A271-58ED22FB3070}" +EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution Debug|Any CPU = Debug|Any CPU @@ -189,6 +191,18 @@ Global {321A7F5D-00C2-4095-9970-075CDEE8C139}.Silverlight Release|Any CPU.Build.0 = Release|Any CPU {321A7F5D-00C2-4095-9970-075CDEE8C139}.SpecSharp|Any CPU.ActiveCfg = Release|Any CPU {321A7F5D-00C2-4095-9970-075CDEE8C139}.SpecSharp|Any CPU.Build.0 = Release|Any CPU + {70D319F3-3C0C-4EB5-A271-58ED22FB3070}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {70D319F3-3C0C-4EB5-A271-58ED22FB3070}.Debug|Any CPU.Build.0 = Debug|Any CPU + {70D319F3-3C0C-4EB5-A271-58ED22FB3070}.FxCop|Any CPU.ActiveCfg = Release|Any CPU + {70D319F3-3C0C-4EB5-A271-58ED22FB3070}.FxCop|Any CPU.Build.0 = Release|Any CPU + {70D319F3-3C0C-4EB5-A271-58ED22FB3070}.Release|Any CPU.ActiveCfg = Release|Any CPU + {70D319F3-3C0C-4EB5-A271-58ED22FB3070}.Release|Any CPU.Build.0 = Release|Any CPU + {70D319F3-3C0C-4EB5-A271-58ED22FB3070}.Silverlight Debug|Any CPU.ActiveCfg = Debug|Any CPU + {70D319F3-3C0C-4EB5-A271-58ED22FB3070}.Silverlight Debug|Any CPU.Build.0 = Debug|Any CPU + {70D319F3-3C0C-4EB5-A271-58ED22FB3070}.Silverlight Release|Any CPU.ActiveCfg = Release|Any CPU + {70D319F3-3C0C-4EB5-A271-58ED22FB3070}.Silverlight Release|Any CPU.Build.0 = Release|Any CPU + {70D319F3-3C0C-4EB5-A271-58ED22FB3070}.SpecSharp|Any CPU.ActiveCfg = Release|Any CPU + {70D319F3-3C0C-4EB5-A271-58ED22FB3070}.SpecSharp|Any CPU.Build.0 = Release|Any CPU EndGlobalSection GlobalSection(SolutionProperties) = preSolution HideSolutionNode = FALSE