diff --git a/src/AddIns/BackendBindings/WixBinding/Project/Src/Gui/WixDocumentEditor.cs b/src/AddIns/BackendBindings/WixBinding/Project/Src/Gui/WixDocumentEditor.cs index e31d137ec9..8662453d86 100644 --- a/src/AddIns/BackendBindings/WixBinding/Project/Src/Gui/WixDocumentEditor.cs +++ b/src/AddIns/BackendBindings/WixBinding/Project/Src/Gui/WixDocumentEditor.cs @@ -36,9 +36,9 @@ namespace ICSharpCode.WixBinding ISegment segment = WixDocument.ConvertRegionToSegment(document, region); // Replace the original xml with the new xml and indent it. - int originalLineCount = document.LineSegmentCollection.Count; + int originalLineCount = document.TotalNumberOfLines; document.Replace(segment.Offset, segment.Length, xml); - int addedLineCount = document.LineSegmentCollection.Count - originalLineCount; + int addedLineCount = document.TotalNumberOfLines - originalLineCount; // Make sure the text inserted is visible. textAreaControl.ScrollTo(region.BeginLine); @@ -59,10 +59,10 @@ namespace ICSharpCode.WixBinding ISegment segment = document.GetLineSegment(line); // Insert the xml and indent it. - int originalLineCount = document.LineSegmentCollection.Count; + int originalLineCount = document.TotalNumberOfLines; int offset = segment.Offset + column; document.Insert(offset, xml); - int addedLineCount = document.LineSegmentCollection.Count - originalLineCount; + int addedLineCount = document.TotalNumberOfLines - originalLineCount; // Make sure the text inserted is visible. textAreaControl.ScrollTo(line); diff --git a/src/Libraries/ICSharpCode.TextEditor/Project/ICSharpCode.TextEditor.csproj b/src/Libraries/ICSharpCode.TextEditor/Project/ICSharpCode.TextEditor.csproj index b067093c9c..d838659d5f 100644 --- a/src/Libraries/ICSharpCode.TextEditor/Project/ICSharpCode.TextEditor.csproj +++ b/src/Libraries/ICSharpCode.TextEditor/Project/ICSharpCode.TextEditor.csproj @@ -84,8 +84,7 @@ - - + diff --git a/src/Libraries/ICSharpCode.TextEditor/Project/Src/Document/BookmarkManager/Bookmark.cs b/src/Libraries/ICSharpCode.TextEditor/Project/Src/Document/BookmarkManager/Bookmark.cs index a1ec5ba7e7..17aba3eeda 100644 --- a/src/Libraries/ICSharpCode.TextEditor/Project/Src/Document/BookmarkManager/Bookmark.cs +++ b/src/Libraries/ICSharpCode.TextEditor/Project/Src/Document/BookmarkManager/Bookmark.cs @@ -17,8 +17,9 @@ namespace ICSharpCode.TextEditor.Document public class Bookmark { IDocument document; - int lineNumber; - bool isEnabled = true; + LineSegment line; + int lineNumber; + bool isEnabled = true; public IDocument Document { get { @@ -26,7 +27,14 @@ namespace ICSharpCode.TextEditor.Document } set { if (document != value) { + if (line != null) { + lineNumber = line.LineNumber; + line = null; + } document = value; + if (document != null) { + line = document.GetLineSegment(Math.Min(lineNumber, document.TotalNumberOfLines-1)); + } OnDocumentChanged(EventArgs.Empty); } } @@ -66,29 +74,32 @@ namespace ICSharpCode.TextEditor.Document } } + /// + /// Gets the line the bookmark belongs to. + /// Is null if the bookmark is not connected to a document. + /// + public LineSegment Line { + get { return line; } + } + public int LineNumber { get { - return lineNumber; + if (line != null) + return line.LineNumber; + else + return lineNumber; } set { if (value < 0) throw new ArgumentOutOfRangeException("value", value, "line number must be >= 0"); - if (lineNumber != value) { + if (document == null) { lineNumber = value; - OnLineNumberChanged(EventArgs.Empty); + } else { + line = document.GetLineSegment(value); } } } - public event EventHandler LineNumberChanged; - - protected virtual void OnLineNumberChanged(EventArgs e) - { - if (LineNumberChanged != null) { - LineNumberChanged(this, e); - } - } - /// /// Gets if the bookmark can be toggled off using the 'set/unset bookmark' command. /// @@ -104,11 +115,9 @@ namespace ICSharpCode.TextEditor.Document public Bookmark(IDocument document, int lineNumber, bool isEnabled) { - if (lineNumber < 0) - throw new ArgumentOutOfRangeException("lineNumber", lineNumber, "line number must be >= 0"); this.document = document; - this.lineNumber = lineNumber; this.isEnabled = isEnabled; + this.LineNumber = lineNumber; } public virtual bool Click(SWF.Control parent, SWF.MouseEventArgs e) diff --git a/src/Libraries/ICSharpCode.TextEditor/Project/Src/Document/BookmarkManager/BookmarkManager.cs b/src/Libraries/ICSharpCode.TextEditor/Project/Src/Document/BookmarkManager/BookmarkManager.cs index 20f52b3e22..96db49e56c 100644 --- a/src/Libraries/ICSharpCode.TextEditor/Project/Src/Document/BookmarkManager/BookmarkManager.cs +++ b/src/Libraries/ICSharpCode.TextEditor/Project/Src/Document/BookmarkManager/BookmarkManager.cs @@ -41,10 +41,18 @@ namespace ICSharpCode.TextEditor.Document /// /// Creates a new instance of /// - public BookmarkManager(IDocument document, ILineManager lineTracker) + internal BookmarkManager(IDocument document, LineManager lineTracker) { this.document = document; - lineTracker.LineCountChanged += new LineManagerEventHandler(MoveIndices); + lineTracker.LineDeleted += delegate(object sender, LineEventArgs e) { + for (int i = 0; i < bookmark.Count; i++) { + Bookmark b = bookmark[i]; + if (b.Line == e.LineSegment) { + bookmark.RemoveAt(i--); + OnRemoved(new BookmarkEventArgs(b)); + } + } + }; } IBookmarkFactory factory; @@ -78,28 +86,24 @@ namespace ICSharpCode.TextEditor.Document if (mark.LineNumber == lineNr && mark.CanToggle && mark.GetType() == newMarkType) { bookmark.RemoveAt(i); OnRemoved(new BookmarkEventArgs(mark)); - OnChanged(EventArgs.Empty); return; } } bookmark.Add(newMark); OnAdded(new BookmarkEventArgs(newMark)); - OnChanged(EventArgs.Empty); } public void AddMark(Bookmark mark) { bookmark.Add(mark); OnAdded(new BookmarkEventArgs(mark)); - OnChanged(EventArgs.Empty); } public void RemoveMark(Bookmark mark) { bookmark.Remove(mark); OnRemoved(new BookmarkEventArgs(mark)); - OnChanged(EventArgs.Empty); } public void RemoveMarks(Predicate predicate) @@ -111,7 +115,6 @@ namespace ICSharpCode.TextEditor.Document OnRemoved(new BookmarkEventArgs(bm)); } } - OnChanged(EventArgs.Empty); } /// @@ -127,38 +130,6 @@ namespace ICSharpCode.TextEditor.Document return false; } - /// - /// This method moves all indices from index upward count lines - /// (useful for deletion/insertion of text) - /// - void MoveIndices(object sender,LineManagerEventArgs e) - { - bool changed = false; - for (int i = 0; i < bookmark.Count; ++i) { - Bookmark mark = bookmark[i]; - if (e.LinesMoved < 0 && mark.LineNumber == e.LineStart) { - bookmark.RemoveAt(i); - OnRemoved(new BookmarkEventArgs(mark)); - --i; - changed = true; - } else if (mark.LineNumber > e.LineStart) { - changed = true; - int newLine = mark.LineNumber + e.LinesMoved; - if (newLine >= 0) { - bookmark[i].LineNumber = newLine; - } else { - bookmark.RemoveAt(i); - OnRemoved(new BookmarkEventArgs(mark)); - --i; - } - } - } - - if (changed) { - OnChanged(EventArgs.Empty); - } - } - /// /// Clears all bookmark /// @@ -168,7 +139,6 @@ namespace ICSharpCode.TextEditor.Document OnRemoved(new BookmarkEventArgs(mark)); } bookmark.Clear(); - OnChanged(EventArgs.Empty); } /// @@ -264,14 +234,6 @@ namespace ICSharpCode.TextEditor.Document return prev; } - protected virtual void OnChanged(EventArgs e) - { - if (Changed != null) { - Changed(this, e); - } - } - - protected virtual void OnRemoved(BookmarkEventArgs e) { if (Removed != null) { @@ -279,7 +241,6 @@ namespace ICSharpCode.TextEditor.Document } } - protected virtual void OnAdded(BookmarkEventArgs e) { if (Added != null) { @@ -289,10 +250,5 @@ namespace ICSharpCode.TextEditor.Document public event BookmarkEventHandler Removed; public event BookmarkEventHandler Added; - - /// - /// Is fired after the bookmarks change - /// - public event EventHandler Changed; } } diff --git a/src/Libraries/ICSharpCode.TextEditor/Project/Src/Document/CustomLineManager/CustomLineManager.cs b/src/Libraries/ICSharpCode.TextEditor/Project/Src/Document/CustomLineManager/CustomLineManager.cs index d4f2774745..4841dbdff0 100644 --- a/src/Libraries/ICSharpCode.TextEditor/Project/Src/Document/CustomLineManager/CustomLineManager.cs +++ b/src/Libraries/ICSharpCode.TextEditor/Project/Src/Document/CustomLineManager/CustomLineManager.cs @@ -47,9 +47,9 @@ namespace ICSharpCode.TextEditor.Document /// /// Creates a new instance of /// - public CustomLineManager(ILineManager lineTracker) + internal CustomLineManager(LineManager lineTracker) { - lineTracker.LineCountChanged += new LineManagerEventHandler(MoveIndices); + lineTracker.LineCountChanged += MoveIndices; } /// @@ -178,7 +178,7 @@ namespace ICSharpCode.TextEditor.Document /// This method moves all indices from index upward count lines /// (useful for deletion/insertion of text) /// - void MoveIndices(object sender,LineManagerEventArgs e) + void MoveIndices(object sender, LineCountChangeEventArgs e) { bool changed = false; OnBeforeChanged(); diff --git a/src/Libraries/ICSharpCode.TextEditor/Project/Src/Document/DefaultDocument.cs b/src/Libraries/ICSharpCode.TextEditor/Project/Src/Document/DefaultDocument.cs index 475c7c9af5..ab75e3e83c 100644 --- a/src/Libraries/ICSharpCode.TextEditor/Project/Src/Document/DefaultDocument.cs +++ b/src/Libraries/ICSharpCode.TextEditor/Project/Src/Document/DefaultDocument.cs @@ -90,27 +90,41 @@ namespace ICSharpCode.TextEditor.Document /// /// The default implementation. /// - internal class DefaultDocument : IDocument + internal sealed class DefaultDocument : IDocument { bool readOnly = false; - ILineManager lineTrackingStrategy = null; - ICustomLineManager customLineManager = null; - BookmarkManager bookmarkManager = null; - ITextBufferStrategy textBufferStrategy = null; - IFormattingStrategy formattingStrategy = null; - FoldingManager foldingManager = null; - UndoStack undoStack = new UndoStack(); + LineManager lineTrackingStrategy; + ICustomLineManager customLineManager; + BookmarkManager bookmarkManager; + ITextBufferStrategy textBufferStrategy; + IFormattingStrategy formattingStrategy; + FoldingManager foldingManager; + UndoStack undoStack = new UndoStack(); ITextEditorProperties textEditorProperties = new DefaultTextEditorProperties(); - MarkerStrategy markerStrategy = null; + MarkerStrategy markerStrategy; + + public LineManager LineManager { + get { return lineTrackingStrategy; } + set { lineTrackingStrategy = value; } + } + + public event EventHandler LineLengthChanged { + add { lineTrackingStrategy.LineLengthChanged += value; } + remove { lineTrackingStrategy.LineLengthChanged -= value; } + } + public event EventHandler LineCountChanged { + add { lineTrackingStrategy.LineCountChanged += value; } + remove { lineTrackingStrategy.LineCountChanged -= value; } + } + public event EventHandler LineDeleted { + add { lineTrackingStrategy.LineDeleted += value; } + remove { lineTrackingStrategy.LineDeleted -= value; } + } public MarkerStrategy MarkerStrategy { - get { - return markerStrategy; - } - set { - markerStrategy = value; - } + get { return markerStrategy; } + set { markerStrategy = value; } } public ITextEditorProperties TextEditorProperties { @@ -143,15 +157,6 @@ namespace ICSharpCode.TextEditor.Document } } - public ILineManager LineManager { - get { - return lineTrackingStrategy; - } - set { - lineTrackingStrategy = value; - } - } - public ITextBufferStrategy TextBufferStrategy { get { return textBufferStrategy; @@ -390,14 +395,14 @@ namespace ICSharpCode.TextEditor.Document } } - protected void OnDocumentAboutToBeChanged(DocumentEventArgs e) + void OnDocumentAboutToBeChanged(DocumentEventArgs e) { if (DocumentAboutToBeChanged != null) { DocumentAboutToBeChanged(this, e); } } - protected void OnDocumentChanged(DocumentEventArgs e) + void OnDocumentChanged(DocumentEventArgs e) { if (DocumentChanged != null) { DocumentChanged(this, e); @@ -436,7 +441,7 @@ namespace ICSharpCode.TextEditor.Document } } - protected virtual void OnTextContentChanged(EventArgs e) + void OnTextContentChanged(EventArgs e) { if (TextContentChanged != null) { TextContentChanged(this, e); diff --git a/src/Libraries/ICSharpCode.TextEditor/Project/Src/Document/DocumentFactory.cs b/src/Libraries/ICSharpCode.TextEditor/Project/Src/Document/DocumentFactory.cs index 1e6fed0d15..9e7d0edd57 100644 --- a/src/Libraries/ICSharpCode.TextEditor/Project/Src/Document/DocumentFactory.cs +++ b/src/Libraries/ICSharpCode.TextEditor/Project/Src/Document/DocumentFactory.cs @@ -25,7 +25,7 @@ namespace ICSharpCode.TextEditor.Document DefaultDocument doc = new DefaultDocument(); doc.TextBufferStrategy = new GapTextBufferStrategy(); doc.FormattingStrategy = new DefaultFormattingStrategy(); - doc.LineManager = new DefaultLineManager(doc, null); + doc.LineManager = new LineManager(doc, null); doc.FoldingManager = new FoldingManager(doc, doc.LineManager); doc.FoldingManager.FoldingStrategy = null; //new ParserFoldingStrategy(); doc.MarkerStrategy = new MarkerStrategy(doc); diff --git a/src/Libraries/ICSharpCode.TextEditor/Project/Src/Document/FoldingStrategy/FoldingManager.cs b/src/Libraries/ICSharpCode.TextEditor/Project/Src/Document/FoldingStrategy/FoldingManager.cs index 9da48a6aaf..0c39aaf3bb 100644 --- a/src/Libraries/ICSharpCode.TextEditor/Project/Src/Document/FoldingStrategy/FoldingManager.cs +++ b/src/Libraries/ICSharpCode.TextEditor/Project/Src/Document/FoldingStrategy/FoldingManager.cs @@ -34,7 +34,7 @@ namespace ICSharpCode.TextEditor.Document } } - public FoldingManager(IDocument document, ILineManager lineTracker) + internal FoldingManager(IDocument document, LineManager lineTracker) { this.document = document; document.DocumentChanged += new DocumentEventHandler(DocumentChanged); diff --git a/src/Libraries/ICSharpCode.TextEditor/Project/Src/Document/IDocument.cs b/src/Libraries/ICSharpCode.TextEditor/Project/Src/Document/IDocument.cs index 93b4f3c095..e789ebf5c9 100644 --- a/src/Libraries/ICSharpCode.TextEditor/Project/Src/Document/IDocument.cs +++ b/src/Libraries/ICSharpCode.TextEditor/Project/Src/Document/IDocument.cs @@ -104,8 +104,7 @@ namespace ICSharpCode.TextEditor.Document } /// - /// The total number of lines, this may be != ArrayList.Count - /// if the last line ends with a delimiter. + /// The total number of lines in the document. /// int TotalNumberOfLines { get; @@ -189,6 +188,10 @@ namespace ICSharpCode.TextEditor.Document /// Get the next visible line below lineNumber /// int GetNextVisibleLineBelow(int lineNumber, int lineCount); + + event EventHandler LineLengthChanged; + event EventHandler LineCountChanged; + event EventHandler LineDeleted; #endregion #region ITextBufferStrategy interface diff --git a/src/Libraries/ICSharpCode.TextEditor/Project/Src/Document/LineManager/ILineManager.cs b/src/Libraries/ICSharpCode.TextEditor/Project/Src/Document/LineManager/ILineManager.cs deleted file mode 100644 index 7b5c3970f3..0000000000 --- a/src/Libraries/ICSharpCode.TextEditor/Project/Src/Document/LineManager/ILineManager.cs +++ /dev/null @@ -1,147 +0,0 @@ -// -// -// -// -// $Revision$ -// - -using System.Collections.Generic; - -namespace ICSharpCode.TextEditor.Document -{ - /// - /// The line tracker keeps track of all lines in a document. - /// - public interface ILineManager - { - /// - /// A collection of all line segments - /// - IList LineSegmentCollection { - get; - } - - /// - /// The total number of lines, this may be != ArrayList.Count - /// if the last line ends with a delimiter. - /// - int TotalNumberOfLines { - get; - } - - /// - /// The current attached to this line manager - /// - IHighlightingStrategy HighlightingStrategy { - get; - set; - } - - /// - /// Returns a valid line number for the given offset. - /// - /// - /// A offset which points to a character in the line which - /// line number is returned. - /// - /// - /// An int which value is the line number. - /// - /// If offset points not to a valid position - int GetLineNumberForOffset(int offset); - - /// - /// Returns a for the given offset. - /// - /// - /// A offset which points to a character in the line which - /// is returned. - /// - /// - /// A object. - /// - /// If offset points not to a valid position - LineSegment GetLineSegmentForOffset(int offset); - - /// - /// Returns a for the given line number. - /// This function should be used to get a line instead of getting the - /// line using the . - /// - /// - /// The line number which is requested. - /// - /// - /// A object. - /// - /// If offset points not to a valid position - LineSegment GetLineSegment(int lineNumber); - - /// - /// Used internally, do not call yourself. - /// - void Insert(int offset, string text); - - /// - /// Used internally, do not call yourself. - /// - void Remove(int offset, int length); - - /// - /// Used internally, do not call yourself. - /// - void Replace(int offset, int length, string text); - - /// - /// Sets the content of this line manager = break the text - /// into lines. - /// - void SetContent(string text); - - /// - /// Get the first logical line for a given visible line. - /// example : lineNumber == 100 foldings are in the linetracker - /// between 0..1 (2 folded, invisible lines) this method returns 102 - /// the 'logical' line number - /// - int GetFirstLogicalLine(int lineNumber); - - /// - /// Get the last logical line for a given visible line. - /// example : lineNumber == 100 foldings are in the linetracker - /// between 0..1 (2 folded, invisible lines) this method returns 102 - /// the 'logical' line number - /// - int GetLastLogicalLine(int lineNumber); - - /// - /// Get the visible line for a given logical line. - /// example : lineNumber == 100 foldings are in the linetracker - /// between 0..1 (2 folded, invisible lines) this method returns 98 - /// the 'visible' line number - /// - int GetVisibleLine(int lineNumber); - -// /// -// /// Get the visible column for a given logical line and logical column. -// /// -// int GetVisibleColumn(int logicalLine, int logicalColumn); - - /// - /// Get the next visible line after lineNumber - /// - int GetNextVisibleLineAbove(int lineNumber, int lineCount); - - /// - /// Get the next visible line below lineNumber - /// - int GetNextVisibleLineBelow(int lineNumber, int lineCount); - - /// - /// Is fired when lines are inserted or removed - /// - event LineManagerEventHandler LineCountChanged; - - event LineLengthEventHandler LineLengthChanged; - } -} diff --git a/src/Libraries/ICSharpCode.TextEditor/Project/Src/Document/LineManager/DefaultLineManager.cs b/src/Libraries/ICSharpCode.TextEditor/Project/Src/Document/LineManager/LineManager.cs similarity index 89% rename from src/Libraries/ICSharpCode.TextEditor/Project/Src/Document/LineManager/DefaultLineManager.cs rename to src/Libraries/ICSharpCode.TextEditor/Project/Src/Document/LineManager/LineManager.cs index 293f633422..f48b3c6550 100644 --- a/src/Libraries/ICSharpCode.TextEditor/Project/Src/Document/LineManager/DefaultLineManager.cs +++ b/src/Libraries/ICSharpCode.TextEditor/Project/Src/Document/LineManager/LineManager.cs @@ -11,7 +11,7 @@ using System.Diagnostics; namespace ICSharpCode.TextEditor.Document { - internal class DefaultLineManager : ILineManager + internal sealed class LineManager { LineSegmentTree lineCollection = new LineSegmentTree(); @@ -44,7 +44,7 @@ namespace ICSharpCode.TextEditor.Document } } - public DefaultLineManager(IDocument document, IHighlightingStrategy highlightingStrategy) + public LineManager(IDocument document, IHighlightingStrategy highlightingStrategy) { this.document = document; this.highlightingStrategy = highlightingStrategy; @@ -80,7 +80,7 @@ namespace ICSharpCode.TextEditor.Document // Console.WriteLine("Replace offset="+offset+" length="+length+" text.Length="+text.Length); int lineStart = GetLineNumberForOffset(offset); int oldNumberOfLines = this.TotalNumberOfLines; - RemoveInternal(offset, length); + List removedLines = RemoveInternal(offset, length); int numberOfLinesAfterRemoving = this.TotalNumberOfLines; if (!string.IsNullOrEmpty(text)) { InsertInternal(offset, text); @@ -92,15 +92,19 @@ namespace ICSharpCode.TextEditor.Document // Console.WriteLine("'" + document.TextContent + "'"); // #endif RunHighlighter(lineStart, 1 + Math.Max(0, this.TotalNumberOfLines - numberOfLinesAfterRemoving)); + if (removedLines != null) { + foreach (LineSegment ls in removedLines) + OnLineDeleted(new LineEventArgs(document, ls)); + } if (this.TotalNumberOfLines != oldNumberOfLines) { - OnLineCountChanged(new LineManagerEventArgs(document, lineStart, this.TotalNumberOfLines - oldNumberOfLines)); + OnLineCountChanged(new LineCountChangeEventArgs(document, lineStart, this.TotalNumberOfLines - oldNumberOfLines)); } } - void RemoveInternal(int offset, int length) + List RemoveInternal(int offset, int length) { Debug.Assert(length >= 0); - if (length == 0) return; + if (length == 0) return null; LineSegmentTree.Enumerator it = lineCollection.GetEnumeratorForOffset(offset); LineSegment startSegment = it.Current; int startSegmentOffset = startSegment.Offset; @@ -108,7 +112,7 @@ namespace ICSharpCode.TextEditor.Document // just removing a part of this line segment startSegment.RemovedLinePart(offset - startSegmentOffset, length); SetSegmentLength(startSegment, startSegment.TotalLength - length); - return; + return null; } // merge startSegment with another line segment because startSegment's delimiter was deleted // possibly remove lines in between if multiple delimiters were deleted @@ -122,7 +126,7 @@ namespace ICSharpCode.TextEditor.Document // special case: we are removing a part of the last line up to the // end of the document SetSegmentLength(startSegment, startSegment.TotalLength - length); - return; + return null; } int endSegmentOffset = endSegment.Offset; int charactersLeftInEndLine = endSegmentOffset + endSegment.TotalLength - (offset + length); @@ -132,13 +136,16 @@ namespace ICSharpCode.TextEditor.Document startSegment.DelimiterLength = endSegment.DelimiterLength; // remove all segments between startSegment (excl.) and endSegment (incl.) it.MoveNext(); + List removedLines = new List(); LineSegment segmentToRemove; do { segmentToRemove = it.Current; it.MoveNext(); lineCollection.RemoveSegment(segmentToRemove); + removedLines.Add(segmentToRemove); segmentToRemove.Deleted(); } while (segmentToRemove != endSegment); + return removedLines; } void InsertInternal(int offset, string text) @@ -181,7 +188,7 @@ namespace ICSharpCode.TextEditor.Document int delta = newTotalLength - segment.TotalLength; if (delta != 0) { lineCollection.SetSegmentLength(segment, newTotalLength); - OnLineLengthChanged(new LineLengthEventArgs(document, segment, delta)); + OnLineLengthChanged(new LineLengthChangeEventArgs(document, segment, delta)); } } @@ -298,13 +305,6 @@ namespace ICSharpCode.TextEditor.Document return Math.Max(0, curLineNumber); } - protected virtual void OnLineCountChanged(LineManagerEventArgs e) - { - if (LineCountChanged != null) { - LineCountChanged(this, e); - } - } - // use always the same DelimiterSegment object for the NextDelimiter DelimiterSegment delimiterSegment = new DelimiterSegment(); @@ -330,15 +330,30 @@ namespace ICSharpCode.TextEditor.Document return null; } - protected virtual void OnLineLengthChanged(LineLengthEventArgs e) + void OnLineCountChanged(LineCountChangeEventArgs e) + { + if (LineCountChanged != null) { + LineCountChanged(this, e); + } + } + + void OnLineLengthChanged(LineLengthChangeEventArgs e) { if (LineLengthChanged != null) { LineLengthChanged(this, e); } } - public event LineLengthEventHandler LineLengthChanged; - public event LineManagerEventHandler LineCountChanged; + void OnLineDeleted(LineEventArgs e) + { + if (LineDeleted != null) { + LineDeleted(this, e); + } + } + + public event EventHandler LineLengthChanged; + public event EventHandler LineCountChanged; + public event EventHandler LineDeleted; sealed class DelimiterSegment { diff --git a/src/Libraries/ICSharpCode.TextEditor/Project/Src/Document/LineManager/LineManagerEventArgs.cs b/src/Libraries/ICSharpCode.TextEditor/Project/Src/Document/LineManager/LineManagerEventArgs.cs index 2abc0a4856..dbe1909eb9 100644 --- a/src/Libraries/ICSharpCode.TextEditor/Project/Src/Document/LineManager/LineManagerEventArgs.cs +++ b/src/Libraries/ICSharpCode.TextEditor/Project/Src/Document/LineManager/LineManagerEventArgs.cs @@ -9,10 +9,7 @@ using System; namespace ICSharpCode.TextEditor.Document { - public delegate void LineManagerEventHandler(object sender, LineManagerEventArgs e); - public delegate void LineLengthEventHandler(object sender, LineLengthEventArgs e); - - public class LineManagerEventArgs : EventArgs + public class LineCountChangeEventArgs : EventArgs { IDocument document; int start; @@ -45,7 +42,7 @@ namespace ICSharpCode.TextEditor.Document } } - public LineManagerEventArgs(IDocument document, int lineStart, int linesMoved) + public LineCountChangeEventArgs(IDocument document, int lineStart, int linesMoved) { this.document = document; this.start = lineStart; @@ -53,11 +50,10 @@ namespace ICSharpCode.TextEditor.Document } } - public class LineLengthEventArgs : EventArgs + public class LineEventArgs : EventArgs { IDocument document; LineSegment lineSegment; - int lengthDelta; public IDocument Document { get { return document; } @@ -67,20 +63,35 @@ namespace ICSharpCode.TextEditor.Document get { return lineSegment; } } + public LineEventArgs(IDocument document, LineSegment lineSegment) + { + this.document = document; + this.lineSegment = lineSegment; + } + + public override string ToString() + { + return string.Format("[LineEventArgs Document={0} LineSegment={1}]", this.document, this.lineSegment); + } + } + + public class LineLengthChangeEventArgs : LineEventArgs + { + int lengthDelta; + public int LengthDelta { get { return lengthDelta; } } - public LineLengthEventArgs(IDocument document, LineSegment lineSegment, int moved) + public LineLengthChangeEventArgs(IDocument document, LineSegment lineSegment, int moved) + : base(document, lineSegment) { - this.document = document; - this.lineSegment = lineSegment; this.lengthDelta = moved; } public override string ToString() { - return string.Format("[LineLengthEventArgs Document={0} LineSegment={1} LengthDelta={2}]", this.document, this.lineSegment, this.lengthDelta); + return string.Format("[LineLengthEventArgs Document={0} LineSegment={1} LengthDelta={2}]", this.Document, this.LineSegment, this.lengthDelta); } } } diff --git a/src/Libraries/ICSharpCode.TextEditor/Project/Src/Document/LineManager/LineSegment.cs b/src/Libraries/ICSharpCode.TextEditor/Project/Src/Document/LineManager/LineSegment.cs index caa55067b6..f913a6b09c 100644 --- a/src/Libraries/ICSharpCode.TextEditor/Project/Src/Document/LineManager/LineSegment.cs +++ b/src/Libraries/ICSharpCode.TextEditor/Project/Src/Document/LineManager/LineSegment.cs @@ -106,7 +106,10 @@ namespace ICSharpCode.TextEditor.Document /// public override string ToString() { - return "[LineSegment: Offset = "+ Offset +", Length = " + Length + ", TotalLength = " + TotalLength + ", DelimiterLength = " + delimiterLength + "]"; + if (IsDeleted) + return "[LineSegment: (deleted) Length = " + Length + ", TotalLength = " + TotalLength + ", DelimiterLength = " + delimiterLength + "]"; + else + return "[LineSegment: LineNumber=" + LineNumber + ", Offset = "+ Offset +", Length = " + Length + ", TotalLength = " + TotalLength + ", DelimiterLength = " + delimiterLength + "]"; } #region Anchor management diff --git a/src/Main/Base/Project/Src/TextEditor/Bookmarks/Bookmark.cs b/src/Main/Base/Project/Src/TextEditor/Bookmarks/Bookmark.cs index c87c01cd7d..4527357c38 100644 --- a/src/Main/Base/Project/Src/TextEditor/Bookmarks/Bookmark.cs +++ b/src/Main/Base/Project/Src/TextEditor/Bookmarks/Bookmark.cs @@ -46,6 +46,14 @@ namespace ICSharpCode.SharpDevelop.Bookmarks } } + public event EventHandler LineNumberChanged; + + internal void RaiseLineNumberChanged() + { + if (LineNumberChanged != null) + LineNumberChanged(this, EventArgs.Empty); + } + bool isSaved = true; /// diff --git a/src/Main/Base/Project/Src/TextEditor/Bookmarks/Pad/Nodes/BookmarkNode.cs b/src/Main/Base/Project/Src/TextEditor/Bookmarks/Pad/Nodes/BookmarkNode.cs index 16788de31a..909a8b22d7 100644 --- a/src/Main/Base/Project/Src/TextEditor/Bookmarks/Pad/Nodes/BookmarkNode.cs +++ b/src/Main/Base/Project/Src/TextEditor/Bookmarks/Pad/Nodes/BookmarkNode.cs @@ -75,8 +75,8 @@ namespace ICSharpCode.SharpDevelop.Bookmarks { Graphics g = e.Graphics; int x = MeasureTextWidth(g, positionText, BoldMonospacedFont); - if (line != null) { - x += MeasureTextWidth(g, bookmark.Document.GetText(line).Replace("\t", " "), BoldMonospacedFont); + if (line != null && !line.IsDeleted) { + x += MeasureTextWidth(g, bookmark.Document.GetText(line).Replace("\t", " "), BoldMonospacedFont); } return x; } @@ -89,7 +89,7 @@ namespace ICSharpCode.SharpDevelop.Bookmarks spaceSize = g.MeasureString("-", RegularBigFont, new PointF(0, 0), StringFormat.GenericTypographic); - if (line != null) { + if (line != null && !line.IsDeleted) { DrawLine(g, line, e.Bounds.Y, x, e.State); } } diff --git a/src/Main/Base/Project/Src/TextEditor/Gui/Editor/SharpDevelopTextAreaControl.cs b/src/Main/Base/Project/Src/TextEditor/Gui/Editor/SharpDevelopTextAreaControl.cs index f1f5f08c4f..3762704ee0 100644 --- a/src/Main/Base/Project/Src/TextEditor/Gui/Editor/SharpDevelopTextAreaControl.cs +++ b/src/Main/Base/Project/Src/TextEditor/Gui/Editor/SharpDevelopTextAreaControl.cs @@ -58,6 +58,7 @@ namespace ICSharpCode.SharpDevelop.DefaultEditor.Gui.Editor Document.BookmarkManager.Factory = new Bookmarks.SDBookmarkFactory(Document.BookmarkManager); Document.BookmarkManager.Added += new BookmarkEventHandler(BookmarkAdded); Document.BookmarkManager.Removed += new BookmarkEventHandler(BookmarkRemoved); + Document.LineCountChanged += BookmarkLineCountChanged; GenerateEditActions(); TextEditorProperties = SharpDevelopTextEditorProperties.Instance; @@ -79,6 +80,18 @@ namespace ICSharpCode.SharpDevelop.DefaultEditor.Gui.Editor } } + void BookmarkLineCountChanged(object sender, LineCountChangeEventArgs e) + { + foreach (Bookmark b in Document.BookmarkManager.Marks) { + if (b.LineNumber >= e.LineStart) { + Bookmarks.SDBookmark sdb = b as Bookmarks.SDBookmark; + if (sdb != null) { + sdb.RaiseLineNumberChanged(); + } + } + } + } + protected override void InitializeTextAreaControl(TextAreaControl newControl) { base.InitializeTextAreaControl(newControl);