diff --git a/Irony.WinForms/035.Irony.WinForms.2010.csproj b/Irony.WinForms/035.Irony.WinForms.2010.csproj index c6ea0b2..d86d562 100644 --- a/Irony.WinForms/035.Irony.WinForms.2010.csproj +++ b/Irony.WinForms/035.Irony.WinForms.2010.csproj @@ -32,6 +32,9 @@ prompt 4 + + + @@ -45,6 +48,12 @@ + + UserControl + + + ConsoleTextBox.cs + Form @@ -120,12 +129,19 @@ + + {321A7F5D-00C2-4095-9970-075CDEE8C139} + 015.Irony.Interpreter.2010 + {D81F5C91-D7DB-46E5-BC99-49488FB6814C} 010.Irony.2010 + + ConsoleTextBox.cs + fmShowException.cs diff --git a/Irony.WinForms/ConsoleTextBox.Designer.cs b/Irony.WinForms/ConsoleTextBox.Designer.cs new file mode 100644 index 0000000..70a6184 --- /dev/null +++ b/Irony.WinForms/ConsoleTextBox.Designer.cs @@ -0,0 +1,38 @@ +namespace Irony.WinForms { + partial class ConsoleTextBox { + /// + /// Required designer variable. + /// + private System.ComponentModel.IContainer components = null; + + /// + /// Clean up any resources being used. + /// + /// true if managed resources should be disposed; otherwise, false. + protected override void Dispose(bool disposing) { + if (disposing && (components != null)) { + components.Dispose(); + } + base.Dispose(disposing); + } + + #region Component Designer generated code + + /// + /// Required method for Designer support - do not modify + /// the contents of this method with the code editor. + /// + private void InitializeComponent() { + this.SuspendLayout(); + // + // ConsoleTextBox + // + this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F); + this.Name = "ConsoleTextBox"; + this.ResumeLayout(false); + + } + + #endregion + } +} diff --git a/Irony.WinForms/ConsoleTextBox.cs b/Irony.WinForms/ConsoleTextBox.cs new file mode 100644 index 0000000..b8300f6 --- /dev/null +++ b/Irony.WinForms/ConsoleTextBox.cs @@ -0,0 +1,86 @@ +using System; +using System.ComponentModel; +using System.Drawing; +using System.Windows.Forms; +using Irony.Interpreter; +using Irony.Parsing; + +namespace Irony.WinForms { + using FastColoredTextBox = FastColoredTextBoxNS.FastColoredTextBox; + using FctbConsoleTextBox = FastColoredTextBoxNS.ConsoleTextBox; + + /// + /// TextBox with for console emulation. + /// + [ToolboxItem(true)] + public partial class ConsoleTextBox : IronyTextBoxBase, IConsoleAdaptor { + /// + /// Initializes a new instance of the class. + /// + public ConsoleTextBox() { + InitializeComponent(); + } + + protected override FastColoredTextBox CreateFastColoredTextBox() { + var textBox = new FctbConsoleTextBox { + BackColor = Color.Black, + IndentBackColor = Color.Black, + PaddingBackColor = Color.Black, + LineNumberColor = Color.Gold, + ForeColor = Color.White, + CaretColor = Color.White, + PreferredLineWidth = 80, + WordWrap = true, + WordWrapMode = FastColoredTextBoxNS.WordWrapMode.CharWrapPreferredWidth + }; + + return textBox; + } + + private FctbConsoleTextBox Console { + get { return (FctbConsoleTextBox)FastColoredTextBox; } + } + + [Browsable(false), DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] + public override string Text { + get { return base.Text; } + set { base.Text = value; } + } + + [Browsable(false), DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] + public bool Canceled { + get; + set; + } + + public void Write(string text) { + if (!InvokeRequired) { + Console.WriteLine(text); + return; + } + Invoke(new Action(Console.WriteLine), text); + } + + public void WriteLine(string text) { + Write(text + Environment.NewLine); + } + + public void SetTextStyle(ConsoleTextStyle style) { + Console.ForeColor = style == ConsoleTextStyle.Normal ? Color.White : Color.Red; + } + + public int Read() { + return 0; + } + + public string ReadLine() { + if (!InvokeRequired) + return Console.ReadLine(); + return Invoke(new Func(Console.ReadLine)) as string; + } + + public void SetTitle(string title) { + throw new NotImplementedException(); + } + } +} diff --git a/Irony.WinForms/ConsoleTextBox.resx b/Irony.WinForms/ConsoleTextBox.resx new file mode 100644 index 0000000..29dcb1b --- /dev/null +++ b/Irony.WinForms/ConsoleTextBox.resx @@ -0,0 +1,120 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + text/microsoft-resx + + + 2.0 + + + System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + \ No newline at end of file diff --git a/Irony.WinForms/FastColoredTextBox/FastColoredTextBox.cs b/Irony.WinForms/FastColoredTextBox/FastColoredTextBox.cs index 5d7f4a5..0f45eeb 100644 --- a/Irony.WinForms/FastColoredTextBox/FastColoredTextBox.cs +++ b/Irony.WinForms/FastColoredTextBox/FastColoredTextBox.cs @@ -8,7 +8,7 @@ // // Email: pavel_torgashov@mail.ru. // -// Copyright (C) Pavel Torgashov, 2011-2012. +// Copyright (C) Pavel Torgashov, 2011-2012. //#define debug @@ -26,7 +26,6 @@ using System.Windows.Forms; using System.Windows.Forms.Design; using Timer = System.Windows.Forms.Timer; -using System.Drawing.Text; namespace FastColoredTextBoxNS { @@ -60,6 +59,7 @@ public class FastColoredTextBox : UserControl private bool handledChar; private bool highlightFoldingIndicator; private Color indentBackColor; + private Color paddingBackColor; private bool isChanged; private Language language; private Keys lastModifiers; @@ -91,8 +91,10 @@ public class FastColoredTextBox : UserControl private Range updatingRange; private bool wordWrap; private int wordWrapLinesCount; + private int maxLineLength = 0; private WordWrapMode wordWrapMode = WordWrapMode.WordWrapControlWidth; private Color selectionColor; + private Brush backBrush; /// /// Constructor @@ -152,6 +154,9 @@ public FastColoredTextBox() AcceptsReturn = true; caretVisible = true; CaretColor = Color.Black; + Paddings = new Padding(0, 0, 0, 0); + PaddingBackColor = Color.Transparent; + DisabledColor = Color.FromArgb(100, 180, 180, 180); // base.AutoScroll = true; timer.Tick += timer_Tick; @@ -164,8 +169,6 @@ public FastColoredTextBox() } } - private int TopIndent { get; set; } - /// /// Indicates if tab characters are accepted as input /// @@ -376,6 +379,28 @@ public Color IndentBackColor } } + /// + /// Background color of padding area + /// + [DefaultValue(typeof (Color), "Transparent")] + [Description("Background color of padding area")] + public Color PaddingBackColor + { + get { return paddingBackColor; } + set + { + paddingBackColor = value; + Invalidate(); + } + } + + /// + /// Color of disabled component + /// + [DefaultValue(typeof(Color), "100;180;180;180")] + [Description("Color of disabled component")] + public Color DisabledColor { get;set;} + /// /// Color of caret /// @@ -398,11 +423,33 @@ public Color ServiceLinesColor } } + /// + /// Padings of text area + /// + [Browsable(true)] + [Description("Paddings of text area.")] + public Padding Paddings { get; set; } + + //hide parent padding + [Browsable(false)] + public new Padding Padding { + get { throw new NotImplementedException(); } + set { throw new NotImplementedException(); } + } + + //hide RTL + [Browsable(false)] + public new bool RightToLeft + { + get { throw new NotImplementedException(); } + set { throw new NotImplementedException(); } + } + /// /// Color of folding area indicator /// [DefaultValue(typeof (Color), "Green")] - [Description("Color of folding area indicator")] + [Description("Color of folding area indicator.")] public Color FoldingIndicatorColor { get { return foldingIndicatorColor; } @@ -439,7 +486,7 @@ public bool HighlightFoldingIndicator /// Left padding in pixels /// [DefaultValue(0)] - [Description("Left padding in pixels")] + [Description("Width of left service area (in pixels)")] public int LeftPadding { get { return leftPadding; } @@ -647,7 +694,9 @@ public Language Language [Browsable(true)] [DefaultValue(null)] [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.")] + [Description( + "XML file with description of syntax highlighting. This property works only with Language == Language.Custom." + )] public string DescriptionFile { get { return descriptionFile; } @@ -803,6 +852,7 @@ public Range Selection /// /// Background color. + /// It is used if BackBrush is null. /// [DefaultValue(typeof (Color), "White")] [Description("Background color.")] @@ -812,6 +862,19 @@ public override Color BackColor set { base.BackColor = value; } } + /// + /// Background brush. + /// If Null then BackColor is used. + /// + [Browsable(false)] + public Brush BackBrush + { + get { return backBrush; } + set { backBrush = value; + Invalidate(); + } + } + [Browsable(true)] [DefaultValue(true)] [Description("Scollbars visibility.")] @@ -995,13 +1058,6 @@ public IList Lines get { return lines.Lines; } } - [Browsable(false)] - public new Padding Padding - { - get { return new Padding(0, 0, 0, 0); } - set { ; } - } - /// /// Gets colored text as HTML /// @@ -1232,8 +1288,8 @@ protected virtual void OnCharSizeChanged() public event EventHandler VisibleRangeChanged; /// - /// TextChangedDelayed event. - /// It occurs after insert, delete, clear, undo and redo operations. + /// TextChangedDelayed event. + /// It occurs after insert, delete, clear, undo and redo operations. /// This event occurs with a delay relative to TextChanged, and fires only once. /// [Browsable(true)] @@ -2060,31 +2116,32 @@ private void Recalc() else needRecalc = true; //calc max line length and count of wordWrapLines - int maxLineLength = 0; wordWrapLinesCount = 0; maxLineLength = RecalcMaxLineLength(); //adjust AutoScrollMinSize - int minWidth = LeftIndent + (maxLineLength)*CharWidth + 2; + int minWidth = LeftIndent + (maxLineLength)*CharWidth + 2 + Paddings.Left + Paddings.Right; if (wordWrap) switch (WordWrapMode) { case WordWrapMode.WordWrapControlWidth: case WordWrapMode.CharWrapControlWidth: + maxLineLength = Math.Min(maxLineLength, (ClientSize.Width - LeftIndent - Paddings.Left - Paddings.Right)/CharWidth); minWidth = 0; break; case WordWrapMode.WordWrapPreferredWidth: case WordWrapMode.CharWrapPreferredWidth: - minWidth = LeftIndent + PreferredLineWidth*CharWidth + 2; + maxLineLength = Math.Min(maxLineLength, PreferredLineWidth); + minWidth = LeftIndent + PreferredLineWidth * CharWidth + 2 + Paddings.Left + Paddings.Right; break; } - AutoScrollMinSize = new Size(minWidth, wordWrapLinesCount*CharHeight + TopIndent); + AutoScrollMinSize = new Size(minWidth, wordWrapLinesCount*CharHeight + Paddings.Top + Paddings.Bottom); #if debug sw.Stop(); Console.WriteLine("Recalc: " + sw.ElapsedMilliseconds); - #endif +#endif } private void RecalcScrollByOneLine(int iLine) @@ -2093,7 +2150,9 @@ private void RecalcScrollByOneLine(int iLine) return; int maxLineLength = lines[iLine].Count; - int minWidth = LeftIndent + (maxLineLength)*CharWidth + 2; + if (this.maxLineLength < maxLineLength && !WordWrap) + this.maxLineLength = maxLineLength; + int minWidth = LeftIndent + (maxLineLength) * CharWidth + 2 + Paddings.Left + Paddings.Right; if (AutoScrollMinSize.Width < minWidth) AutoScrollMinSize = new Size(minWidth, AutoScrollMinSize.Height); } @@ -2104,7 +2163,7 @@ private int RecalcMaxLineLength() TextSource lines = this.lines; int count = lines.Count; int charHeight = CharHeight; - int topIndent = TopIndent; + int topIndent = Paddings.Top; for (int i = 0; i < count; i++) { @@ -2130,7 +2189,7 @@ private int GetMaxLineWordWrapedWidth() return ClientSize.Width; case WordWrapMode.WordWrapPreferredWidth: case WordWrapMode.CharWrapPreferredWidth: - return LeftIndent + PreferredLineWidth*CharWidth + 2; + return LeftIndent + PreferredLineWidth * CharWidth + 2 + Paddings.Left + Paddings.Right; } return int.MaxValue; @@ -2144,10 +2203,10 @@ private void RecalcWordWrap(int fromLine, int toLine) switch (WordWrapMode) { case WordWrapMode.WordWrapControlWidth: - maxCharsPerLine = (ClientSize.Width - LeftIndent)/CharWidth; + maxCharsPerLine = (ClientSize.Width - LeftIndent - Paddings.Left - Paddings.Right)/CharWidth; break; case WordWrapMode.CharWrapControlWidth: - maxCharsPerLine = (ClientSize.Width - LeftIndent)/CharWidth; + maxCharsPerLine = (ClientSize.Width - LeftIndent - Paddings.Left - Paddings.Right) / CharWidth; charWrap = true; break; case WordWrapMode.WordWrapPreferredWidth: @@ -2208,12 +2267,15 @@ private void DoVisibleRectangle(Rectangle rect) if (!Multiline) v = 0; // + v = Math.Max(0, v); + h = Math.Max(0, h); + // try { - if (VerticalScroll.Visible) - VerticalScroll.Value = Math.Max(0, v); - if (HorizontalScroll.Visible) - HorizontalScroll.Value = Math.Max(0, h); + if (VerticalScroll.Visible || !ShowScrollBars) + VerticalScroll.Value = v; + if (HorizontalScroll.Visible || !ShowScrollBars) + HorizontalScroll.Value = h; } catch (ArgumentOutOfRangeException) { @@ -2315,6 +2377,13 @@ protected override void OnKeyDown(KeyEventArgs e) if (e.Modifiers == Keys.Control) ShowFindDialog(); break; + case Keys.F3: + if (e.Modifiers == Keys.None) + if (findForm == null || findForm.tbFind.Text == "") + ShowFindDialog(); + else + findForm.FindNext(); + break; case Keys.H: if (e.Modifiers == Keys.Control) ShowReplaceDialog(); @@ -2366,7 +2435,7 @@ protected override void OnKeyDown(KeyEventArgs e) if (ReadOnly) break; if (e.Modifiers == Keys.Alt) Undo(); - else + else if (e.Modifiers == Keys.None) { if (OnKeyPressing('\b')) //KeyPress event processed key @@ -2595,7 +2664,7 @@ protected override bool ProcessCmdKey(ref Message msg, Keys keyData) return true; } } - + return base.ProcessCmdKey(ref msg, keyData); }*/ @@ -2681,7 +2750,7 @@ private bool ProcessKeyPress(char c) InsertText(new String(' ', spaces)); } - else + else if ((lastModifiers & Keys.Shift) == 0) IncreaseIndent(); } @@ -2905,6 +2974,14 @@ protected override bool IsInputKey(Keys keyData) [DllImport("User32.dll")] private static extern bool HideCaret(IntPtr hWnd); + protected override void OnPaintBackground(PaintEventArgs e) + { + if (BackBrush == null) + base.OnPaintBackground(e); + else + e.Graphics.FillRectangle(BackBrush, ClientRectangle); + } + /// /// Draw control /// @@ -2923,8 +3000,25 @@ protected override void OnPaint(PaintEventArgs e) var servicePen = new Pen(ServiceLinesColor); Brush changedLineBrush = new SolidBrush(ChangedLineColor); Brush indentBrush = new SolidBrush(IndentBackColor); + Brush paddingBrush = new SolidBrush(PaddingBackColor); var currentLinePen = new Pen(CurrentLineColor); Brush currentLineBrush = new SolidBrush(Color.FromArgb(50, CurrentLineColor)); + //draw padding area + //top + e.Graphics.FillRectangle(paddingBrush, 0, -VerticalScroll.Value, ClientSize.Width, Math.Max(0, Paddings.Top - 1)); + //bottom + var bottomPaddingStartY = wordWrapLinesCount * charHeight + Paddings.Top; + e.Graphics.FillRectangle(paddingBrush, 0, bottomPaddingStartY - VerticalScroll.Value, ClientSize.Width, ClientSize.Height); + //right + var rightPaddingStartX = LeftIndent + maxLineLength * CharWidth + Paddings.Left + 1; + e.Graphics.FillRectangle(paddingBrush, rightPaddingStartX - HorizontalScroll.Value, 0, ClientSize.Width, ClientSize.Height); + //left + e.Graphics.FillRectangle(paddingBrush, LeftIndentLine, 0, LeftIndent - LeftIndentLine - 1, ClientSize.Height); + if (HorizontalScroll.Value <= Paddings.Left) + e.Graphics.FillRectangle(paddingBrush, LeftIndent - HorizontalScroll.Value - 2, 0, Math.Max(0, Paddings.Left - 1), ClientSize.Height); + + var leftTextIndent = Math.Max(LeftIndent, LeftIndent + Paddings.Left - HorizontalScroll.Value); + var textWidth = rightPaddingStartX - HorizontalScroll.Value - leftTextIndent; //draw indent area e.Graphics.FillRectangle(indentBrush, 0, 0, LeftIndentLine, ClientSize.Height); if (LeftIndent > minLeftIndent) @@ -2932,10 +3026,10 @@ protected override void OnPaint(PaintEventArgs e) //draw preferred line width if (PreferredLineWidth > 0) e.Graphics.DrawLine(servicePen, - new Point(LeftIndent + PreferredLineWidth*CharWidth - HorizontalScroll.Value, 0), - new Point(LeftIndent + PreferredLineWidth*CharWidth - HorizontalScroll.Value, Height)); + new Point(LeftIndent + Paddings.Left + PreferredLineWidth * CharWidth - HorizontalScroll.Value + 1, 0), + new Point(LeftIndent + Paddings.Left + PreferredLineWidth * CharWidth - HorizontalScroll.Value + 1, Height)); // - int firstChar = HorizontalScroll.Value/CharWidth; + int firstChar = (Math.Max(0, HorizontalScroll.Value - Paddings.Left))/CharWidth; int lastChar = (HorizontalScroll.Value + ClientSize.Width)/CharWidth; //draw chars for (int iLine = YtoLineIndex(VerticalScroll.Value); iLine < lines.Count; iLine++) @@ -2957,14 +3051,14 @@ protected override void OnPaint(PaintEventArgs e) if (lineInfo.VisibleState == VisibleState.Visible) if (line.BackgroundBrush != null) e.Graphics.FillRectangle(line.BackgroundBrush, - new Rectangle(LeftIndent, y, Width, + new Rectangle(leftTextIndent, y, textWidth, CharHeight*lineInfo.WordWrapStringsCount)); //draw current line background if (CurrentLineColor != Color.Transparent && iLine == Selection.Start.iLine) if (Selection.Start == Selection.End) - e.Graphics.FillRectangle(currentLineBrush, new Rectangle(LeftIndent, y, Width, CharHeight)); + e.Graphics.FillRectangle(currentLineBrush, new Rectangle(leftTextIndent, y, textWidth, CharHeight)); else - e.Graphics.DrawLine(currentLinePen, LeftIndent, y + CharHeight, Width, y + CharHeight); + e.Graphics.DrawLine(currentLinePen, leftTextIndent, y + CharHeight, leftTextIndent + textWidth, y + CharHeight); //draw changed line marker if (ChangedLineColor != Color.Transparent && line.IsChanged) e.Graphics.FillRectangle(changedLineBrush, @@ -3001,7 +3095,7 @@ protected override void OnPaint(PaintEventArgs e) { y = lineInfo.startY + iWordWrapLine*CharHeight - VerticalScroll.Value; //draw chars - DrawLineChars(e, firstChar, lastChar, iLine, iWordWrapLine, y); + DrawLineChars(e, firstChar, lastChar, iLine, iWordWrapLine, LeftIndent + Paddings.Left - HorizontalScroll.Value, y); } } //draw brackets highlighting @@ -3050,6 +3144,11 @@ protected override void OnPaint(PaintEventArgs e) else HideCaret(Handle); + //draw disabled mask + if (!Enabled) + using (var brush = new SolidBrush(DisabledColor)) + e.Graphics.FillRectangle(brush, ClientRectangle); + //dispose resources lineNumberBrush.Dispose(); servicePen.Dispose(); @@ -3057,6 +3156,7 @@ protected override void OnPaint(PaintEventArgs e) indentBrush.Dispose(); currentLinePen.Dispose(); currentLineBrush.Dispose(); + paddingBrush.Dispose(); // #if debug Console.WriteLine("OnPaint: "+ sw.ElapsedMilliseconds); @@ -3086,14 +3186,14 @@ public virtual Color SelectionColor } } - private void DrawLineChars(PaintEventArgs e, int firstChar, int lastChar, int iLine, int iWordWrapLine, int y) + private void DrawLineChars(PaintEventArgs e, int firstChar, int lastChar, int iLine, int iWordWrapLine, int x, int y) { Line line = lines[iLine]; LineInfo lineInfo = lineInfos[iLine]; int from = lineInfo.GetWordWrapStringStartPosition(iWordWrapLine); int to = lineInfo.GetWordWrapStringFinishPosition(iWordWrapLine, line); - int startX = LeftIndent - HorizontalScroll.Value; + int startX = x; if (startX < LeftIndent) firstChar++; @@ -3289,7 +3389,7 @@ public Place PointToPlace(Point point) var sw = Stopwatch.StartNew(); #endif point.Offset(HorizontalScroll.Value, VerticalScroll.Value); - point.Offset(-LeftIndent, 0); + point.Offset(-LeftIndent - Paddings.Left, 0); int iLine = YtoLineIndex(point.Y); int y = 0; @@ -3323,7 +3423,7 @@ public Place PointToPlace(Point point) #if debug Console.WriteLine("PointToPlace: " + sw.ElapsedMilliseconds); - #endif +#endif return new Place(x, iLine); } @@ -3350,6 +3450,8 @@ public virtual void OnTextChanging(ref string text) var args = new TextChangingEventArgs {InsertingText = text}; TextChanging(this, args); text = args.InsertingText; + if (args.Cancel) + text = string.Empty; } } @@ -3464,7 +3566,7 @@ protected virtual void OnTextChanged(TextChangedEventArgs args) // #if debug Console.WriteLine("OnTextChanged: " + sw.ElapsedMilliseconds); - #endif +#endif OnVisibleRangeChanged(); } @@ -3496,7 +3598,7 @@ public virtual void OnSelectionChanged() #if debug Console.WriteLine("OnSelectionChanged: "+ sw.ElapsedMilliseconds); - #endif +#endif } //find folding markers for highlighting @@ -3628,7 +3730,7 @@ public Point PlaceToPoint(Place place) int x = (place.iChar - lineInfos[place.iLine].GetWordWrapStringStartPosition(iWordWrapIndex))*CharWidth; // y = y - VerticalScroll.Value; - x = LeftIndent + x - HorizontalScroll.Value; + x = LeftIndent + Paddings.Left + x - HorizontalScroll.Value; return new Point(x, y); } @@ -4212,15 +4314,15 @@ public virtual void OnSyntaxHighlight(TextChangedEventArgs args) #if debug Console.WriteLine("OnSyntaxHighlight: "+ sw.ElapsedMilliseconds); - #endif +#endif } private void InitializeComponent() { SuspendLayout(); - // + // // FastColoredTextBox - // + // Name = "FastColoredTextBox"; ResumeLayout(false); } @@ -4540,26 +4642,12 @@ public TextChangedEventArgs(Range changedRange) public class TextChangingEventArgs : EventArgs { public string InsertingText { get; set; } - public bool IsHandled { get; set; } - } - - public class TabChangingEventArgs : EventArgs - { - public TabChangingEventArgs(TabChangingReason reason) - { - Reason = reason; - } - - public TabChangingReason Reason { get; private set; } + /// + /// Set to true if you want to cancel text inserting + /// public bool Cancel { get; set; } } - public enum TabChangingReason - { - Programm, - User - } - public enum WordWrapMode { /// diff --git a/Irony.WinForms/FastColoredTextBox/FileTextSource.cs b/Irony.WinForms/FastColoredTextBox/FileTextSource.cs index e9bc999..cadd09d 100644 --- a/Irony.WinForms/FastColoredTextBox/FileTextSource.cs +++ b/Irony.WinForms/FastColoredTextBox/FileTextSource.cs @@ -78,7 +78,7 @@ public void OpenFile(string fileName, Encoding enc) fs = new FileStream(fileName, FileMode.Open); var length = fs.Length; //read signature - enc = DefineEncoding(enc); + enc = DefineEncoding(enc, fs); int shift = DefineShift(enc); //first line sourceFileLinePositions.Add((int)fs.Position); @@ -111,6 +111,11 @@ public void OpenFile(string fileName, Encoding enc) fileEncoding = enc; OnLineInserted(0, Count); + //load first lines for calc width of the text + var linesCount = Math.Min(lines.Count, CurrentTB.Height/CurrentTB.CharHeight); + for (int i = 0; i < linesCount; i++) + LoadLineFromSourceFile(i); + // NeedRecalc(new TextChangedEventArgs(0, 1)); } @@ -134,7 +139,7 @@ private int DefineShift(Encoding enc) return 0; } - private Encoding DefineEncoding(Encoding enc) + private static Encoding DefineEncoding(Encoding enc, FileStream fs) { int bytesPerSignature = 0; byte[] signature = new byte[4]; diff --git a/Irony.WinForms/FastColoredTextBox/FindForm.cs b/Irony.WinForms/FastColoredTextBox/FindForm.cs index e208978..bdca98d 100644 --- a/Irony.WinForms/FastColoredTextBox/FindForm.cs +++ b/Irony.WinForms/FastColoredTextBox/FindForm.cs @@ -28,7 +28,7 @@ private void btFindNext_Click(object sender, EventArgs e) FindNext(); } - private void FindNext() + public void FindNext() { try { diff --git a/Irony.WinForms/FastColoredTextBox/Style.cs b/Irony.WinForms/FastColoredTextBox/Style.cs index a0a766c..16bfc24 100644 --- a/Irony.WinForms/FastColoredTextBox/Style.cs +++ b/Irony.WinForms/FastColoredTextBox/Style.cs @@ -288,7 +288,7 @@ public override void Draw(Graphics gr, Point position, Range range) //get last char coordinates Point p = range.tb.PlaceToPoint(range.End); //draw small square under char - Rectangle rect = new Rectangle(p.X - 5, p.Y + range.tb.CharHeight - 3, 4, 3); + Rectangle rect = new Rectangle(p.X - 5, p.Y + range.tb.CharHeight - 2, 4, 3); gr.FillPath(Brushes.White, GetRoundedRectangle(rect, 1)); gr.DrawPath(borderPen, GetRoundedRectangle(rect, 1)); //add visual marker for handle mouse events diff --git a/Irony.WinForms/FastColoredTextBox/TextSource.cs b/Irony.WinForms/FastColoredTextBox/TextSource.cs index 7afdac6..802267d 100644 --- a/Irony.WinForms/FastColoredTextBox/TextSource.cs +++ b/Irony.WinForms/FastColoredTextBox/TextSource.cs @@ -282,6 +282,8 @@ internal void OnTextChanging(ref string text) var args = new TextChangingEventArgs() { InsertingText = text }; TextChanging(this, args); text = args.InsertingText; + if (args.Cancel) + text = string.Empty; }; }