public void Initialize(IDocument document) { if (changeList != null && changeList.Any()) { return; } this.document = document; this.textDocument = (TextDocument)document.GetService(typeof(TextDocument)); this.changeList = new CompressingTreeList <LineChangeInfo>((x, y) => x.Equals(y)); Stream baseFileStream = GetBaseVersion(); // TODO : update baseDocument on VCS actions if (baseFileStream != null) { // ReadAll() is taking care of closing the stream baseDocument = DocumentUtilitites.LoadReadOnlyDocumentFromBuffer(new StringTextBuffer(ReadAll(baseFileStream))); } else { if (baseDocument == null) { // if the file is not under subversion, the document is the opened document var doc = new TextDocument(textDocument.Text); baseDocument = new AvalonEditDocumentAdapter(doc, null); } } SetupInitialFileState(false); this.textDocument.LineTrackers.Add(this); this.textDocument.UndoStack.PropertyChanged += UndoStackPropertyChanged; }
public void Initialize(IDocument document, FileName fileName) { if (this.document == null) { this.document = document; this.textDocument = (TextDocument)document.GetService(typeof(TextDocument)); this.changeList = new CompressingTreeList <LineChangeInfo>((x, y) => x.Equals(y)); } InitializeBaseDocument(fileName); if (watcher != null) { watcher.Dispose(); } if (usedProvider != null) { watcher = usedProvider.WatchBaseVersionChanges(fileName, HandleBaseVersionChanges); } SetupInitialFileState(fileName != currentFileName); currentFileName = fileName; if (!this.textDocument.LineTrackers.Contains(this)) { this.textDocument.LineTrackers.Add(this); this.textDocument.UndoStack.PropertyChanged += UndoStackPropertyChanged; } }
public void SetBaseDocument(IReadonlyTextDocument document) { var curLineStates = lineStates; if (curLineStates != null) { try { foreach (var node in curLineStates.tree) { if (node.value.state == TextDocument.LineState.Dirty) { node.value = LineChangeInfo.Changed; } } } catch (Exception e) { LoggingService.LogError("error while DiffTracker.SetBaseDocument", e); Reset(); } } else { lineStates = new CompressingTreeList <LineChangeInfo>((x, y) => x.Equals(y)); lineStates.InsertRange(0, document.LineCount + 1, LineChangeInfo.Unchanged); trackDocument.TextChanged += TrackDocument_TextChanged; } }
public void Initialize(IDocument document) { if (changeList != null && changeList.Any()) return; this.document = document; this.textDocument = (TextDocument)document.GetService(typeof(TextDocument)); this.changeList = new CompressingTreeList<LineChangeInfo>((x, y) => x.Equals(y)); Stream baseFileStream = GetBaseVersion(); // TODO : update baseDocument on VCS actions if (baseFileStream != null) { // ReadAll() is taking care of closing the stream baseDocument = DocumentUtilitites.LoadReadOnlyDocumentFromBuffer(new StringTextBuffer(ReadAll(baseFileStream))); } else { if (baseDocument == null) { // if the file is not under subversion, the document is the opened document var doc = new TextDocument(textDocument.Text); baseDocument = new AvalonEditDocumentAdapter(doc, null); } } SetupInitialFileState(false); this.textDocument.LineTrackers.Add(this); this.textDocument.UndoStack.PropertyChanged += UndoStackPropertyChanged; }
public void Initialize(IDocument document) { if (this.document == null) { this.document = document; this.textDocument = (TextDocument)document.GetService(typeof(TextDocument)); this.changeList = new CompressingTreeList<LineChangeInfo>((x, y) => x.Equals(y)); } var fileName = ((ITextEditor)document.GetService(typeof(ITextEditor))).FileName; InitializeBaseDocument(); if (watcher != null) watcher.Dispose(); if (usedProvider != null) watcher = usedProvider.WatchBaseVersionChanges(fileName, HandleBaseVersionChanges); SetupInitialFileState(fileName != currentFileName); currentFileName = fileName; if (!this.textDocument.LineTrackers.Contains(this)) { this.textDocument.LineTrackers.Add(this); this.textDocument.UndoStack.PropertyChanged += UndoStackPropertyChanged; } }
public void CheckAdd10BillionElements() { const int billion = 1000000000; CompressingTreeList<string> list = new CompressingTreeList<string>(string.Equals); list.InsertRange(0, billion, "A"); list.InsertRange(1, billion, "B"); Assert.AreEqual(2 * billion, list.Count); Assert.Throws<OverflowException>(delegate { list.InsertRange(2, billion, "C"); }); }
public void AddRepeated() { CompressingTreeList<int> list = new CompressingTreeList<int>((a, b) => a == b); list.Add(42); list.Add(42); list.Add(42); list.Insert(0, 42); list.Insert(1, 42); Assert.AreEqual(new[] { 42, 42, 42, 42, 42 }, list.ToArray()); }
public void RemoveAtStart() { CompressingTreeList<int> list = new CompressingTreeList<int>((a, b) => a == b); for (int i = 1; i <= 3; i++) { list.InsertRange(list.Count, 2, i); } Assert.AreEqual(new[] { 1, 1, 2, 2, 3, 3 }, list.ToArray()); list.RemoveRange(0, 1); Assert.AreEqual(new[] { 1, 2, 2, 3, 3 }, list.ToArray()); }
public void EmptyTreeList() { CompressingTreeList<string> list = new CompressingTreeList<string>(string.Equals); Assert.AreEqual(0, list.Count); foreach (string v in list) { Assert.Fail(); } string[] arr = new string[0]; list.CopyTo(arr, 0); }
public void AddRepeated() { CompressingTreeList <int> list = new CompressingTreeList <int>((a, b) => a == b); list.Add(42); list.Add(42); list.Add(42); list.Insert(0, 42); list.Insert(1, 42); Assert.AreEqual(new[] { 42, 42, 42, 42, 42 }, list.ToArray()); }
public void EmptyTreeList() { CompressingTreeList <string> list = new CompressingTreeList <string>(string.Equals); Assert.AreEqual(0, list.Count); foreach (string v in list) { Assert.Fail(); } string[] arr = new string[0]; list.CopyTo(arr, 0); }
public void RemoveAtStart2() { CompressingTreeList <int> list = new CompressingTreeList <int>((a, b) => a == b); for (int i = 1; i <= 3; i++) { list.InsertRange(list.Count, 2, i); } Assert.AreEqual(new[] { 1, 1, 2, 2, 3, 3 }, list.ToArray()); list.RemoveRange(0, 3); Assert.AreEqual(new[] { 2, 3, 3 }, list.ToArray()); }
public void CheckAdd10BillionElements() { const int billion = 1000000000; CompressingTreeList<string> list = new CompressingTreeList<string>(string.Equals); list.InsertRange(0, billion, "A"); list.InsertRange(1, billion, "B"); Assert.AreEqual(2 * billion, list.Count); try { list.InsertRange(2, billion, "C"); Assert.Fail("Expected OverflowException"); } catch (OverflowException) { // expected } }
public void CheckAdd10BillionElements() { const int billion = 1000000000; CompressingTreeList <string> list = new CompressingTreeList <string>(string.Equals); list.InsertRange(0, billion, "A"); list.InsertRange(1, billion, "B"); Assert.AreEqual(2 * billion, list.Count); try { list.InsertRange(2, billion, "C"); Assert.Fail("Expected OverflowException"); } catch (OverflowException) { // expected } }
public void SetBaseDocument(IReadonlyTextDocument document) { if (lineStates != null) { foreach (var node in lineStates.tree) { if (node.value.state == Mono.TextEditor.TextDocument.LineState.Dirty) { node.value.state = Mono.TextEditor.TextDocument.LineState.Changed; } } } else { lineStates = new CompressingTreeList <LineChangeInfo>((x, y) => x.Equals(y)); lineStates.InsertRange(0, document.LineCount + 1, new LineChangeInfo(Mono.TextEditor.TextDocument.LineState.Unchanged)); trackDocument.TextChanging += TrackDocument_TextChanging; trackDocument.TextChanged += TrackDocument_TextChanged; } }
public void Initialize(IDocument document) { if (changeList != null && changeList.Any()) return; this.document = document; this.textDocument = (TextDocument)document.GetService(typeof(TextDocument)); this.changeList = new CompressingTreeList<LineChangeInfo>((x, y) => x.Equals(y)); InitializeBaseDocument(); if (usedProvider != null) { string fileName = ((ITextEditor)document.GetService(typeof(ITextEditor))).FileName; watcher = usedProvider.WatchBaseVersionChanges(fileName, HandleBaseVersionChanges); } SetupInitialFileState(false); this.textDocument.LineTrackers.Add(this); this.textDocument.UndoStack.PropertyChanged += UndoStackPropertyChanged; }
public void SetBaseDocument (TextDocument document) { if (lineStates != null) { foreach (var node in lineStates.tree) { if (node.value.state == Mono.TextEditor.TextDocument.LineState.Dirty) node.value.state = Mono.TextEditor.TextDocument.LineState.Changed; } } else { lineStates = new CompressingTreeList<LineChangeInfo>((x, y) => x.Equals(y)); lineStates.InsertRange(0, document.LineCount + 1, new LineChangeInfo (Mono.TextEditor.TextDocument.LineState.Unchanged)); trackDocument.Splitter.LineChanged += HandleLineChanged; trackDocument.Splitter.LineInserted += HandleLineInserted; trackDocument.Splitter.LineRemoved += HandleLineRemoved; } }
public void Transform() { CompressingTreeList<int> list = new CompressingTreeList<int>((a, b) => a == b); list.AddRange(new[] { 0, 1, 1, 0 }); int calls = 0; list.Transform(i => { calls++; return i + 1; }); Assert.AreEqual(3, calls); Assert.AreEqual(new[] { 1, 2, 2, 1 }, list.ToArray()); }
public void TransformRange() { CompressingTreeList<int> list = new CompressingTreeList<int>((a, b) => a == b); list.AddRange(new[] { 0, 1, 1, 1, 0, 0 }); list.TransformRange(2, 3, i => 0); Assert.AreEqual(new[] { 0, 1, 0, 0, 0, 0 }, list.ToArray()); }
public void Reset() { lineStates = new CompressingTreeList <LineChangeInfo>((x, y) => x.Equals(y)); lineStates.InsertRange(0, trackDocument.LineCount + 1, new LineChangeInfo(Mono.TextEditor.TextDocument.LineState.Unchanged)); }
public ChangeWatcher() { this.ChangeList = new((x, y) => x.Equals(y)); }
public void Reset () { lineStates = new CompressingTreeList<LineChangeInfo>((x, y) => x.Equals(y)); lineStates.InsertRange(0, trackDocument.LineCount + 1, new LineChangeInfo (Mono.TextEditor.TextDocument.LineState.Unchanged)); }