// Copyright (c) AlphaSierraPapa for the SharpDevelop Team (for details please see \doc\copyright.txt) // This code is distributed under the GNU LGPL (for details please see \doc\license.txt) using Tango.Scripting.Editors.Utils; using System; using System.Collections.Generic; using System.Diagnostics; using System.Linq; namespace Tango.Scripting.Editors.Document { /// /// Creates/Deletes lines when text is inserted/removed. /// sealed class LineManager { #region Constructor readonly TextDocument document; readonly DocumentLineTree documentLineTree; /// /// A copy of the line trackers. We need a copy so that line trackers may remove themselves /// while being notified (used e.g. by WeakLineTracker) /// ILineTracker[] lineTrackers; internal void UpdateListOfLineTrackers() { this.lineTrackers = document.LineTrackers.ToArray(); } public LineManager(DocumentLineTree documentLineTree, TextDocument document) { this.document = document; this.documentLineTree = documentLineTree; UpdateListOfLineTrackers(); Rebuild(); } #endregion #region Change events /* HashSet deletedLines = new HashSet(); readonly HashSet changedLines = new HashSet(); HashSet deletedOrChangedLines = new HashSet(); /// /// Gets the list of lines deleted since the last RetrieveChangedLines() call. /// The returned list is unsorted. /// public ICollection RetrieveDeletedLines() { var r = deletedLines; deletedLines = new HashSet(); return r; } /// /// Gets the list of lines changed since the last RetrieveChangedLines() call. /// The returned list is sorted by line number and does not contain deleted lines. /// public List RetrieveChangedLines() { var list = (from line in changedLines where !line.IsDeleted let number = line.LineNumber orderby number select line).ToList(); changedLines.Clear(); return list; } /// /// Gets the list of lines changed since the last RetrieveDeletedOrChangedLines() call. /// The returned list is not sorted. /// public ICollection RetrieveDeletedOrChangedLines() { var r = deletedOrChangedLines; deletedOrChangedLines = new HashSet(); return r; } */ #endregion #region Rebuild public void Rebuild() { // keep the first document line DocumentLine ls = documentLineTree.GetByNumber(1); SimpleSegment ds = NewLineFinder.NextNewLine(document, 0); List lines = new List(); int lastDelimiterEnd = 0; while (ds != SimpleSegment.Invalid) { ls.TotalLength = ds.Offset + ds.Length - lastDelimiterEnd; ls.DelimiterLength = ds.Length; lastDelimiterEnd = ds.Offset + ds.Length; lines.Add(ls); ls = new DocumentLine(document); ds = NewLineFinder.NextNewLine(document, lastDelimiterEnd); } ls.ResetLine(); ls.TotalLength = document.TextLength - lastDelimiterEnd; lines.Add(ls); documentLineTree.RebuildTree(lines); foreach (ILineTracker lineTracker in lineTrackers) lineTracker.RebuildDocument(); } #endregion #region Remove public void Remove(int offset, int length) { Debug.Assert(length >= 0); if (length == 0) return; DocumentLine startLine = documentLineTree.GetByOffset(offset); int startLineOffset = startLine.Offset; Debug.Assert(offset < startLineOffset + startLine.TotalLength); if (offset > startLineOffset + startLine.Length) { Debug.Assert(startLine.DelimiterLength == 2); // we are deleting starting in the middle of a delimiter // remove last delimiter part SetLineLength(startLine, startLine.TotalLength - 1); // remove remaining text Remove(offset, length - 1); return; } if (offset + length < startLineOffset + startLine.TotalLength) { // just removing a part of this line //startLine.RemovedLinePart(ref deferredEventList, offset - startLineOffset, length); SetLineLength(startLine, startLine.TotalLength - length); return; } // merge startLine with another line because startLine's delimiter was deleted // possibly remove lines in between if multip
<controls:MetroWindow x:Class="Tango.Scripting.IDE.UI.MainWindow"
        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
        xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
        xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
        xmlns:controls="http://metro.mahapps.com/winfx/xaml/controls"
        xmlns:local="clr-namespace:Tango.Scripting.IDE.UI"
        xmlns:ide="clr-namespace:Tango.Scripting.IDE;assembly=Tango.Scripting.IDE"
        mc:Ignorable="d"
        Title="MainWindow" Height="720" Width="1280" d:DataContext="{d:DesignInstance Type=local:MainWindowVM, IsDesignTimeCreatable=False}" TitlebarHeight="40" TitleCaps="False" BorderBrush="Gray" BorderThickness="1" WindowStartupLocation="CenterScreen">
    <Grid>
        <ide:ScriptIDEView2 DataContext="{Binding IdeVM}" />
    </Grid>
</controls:MetroWindow>