/// <summary> /// Closes the document /// </summary> public virtual void Close() { if (IsClosed) { return; } IsClosed = true; _textDocumentFactoryService.TextDocumentDisposed -= OnTextDocumentDisposed; DocumentClosing?.Invoke(this, null); if (EditorTree != null) { _editorTree.Dispose(); // this will also remove event handlers _editorTree = null; } if (DocumentClosing != null) { foreach (EventHandler <EventArgs> eh in DocumentClosing.GetInvocationList()) { Debug.Fail(String.Format(CultureInfo.CurrentCulture, "There are still listeners in the EditorDocument.OnDocumentClosing event list: {0}", eh.Target)); DocumentClosing -= eh; } } ServiceManager.RemoveService <REditorDocument>(TextBuffer); TextBuffer = null; }
/// <summary> /// Closes the document /// </summary> public void Close() { if (IsClosed) { return; } IsClosed = true; Closing?.Invoke(this, null); EditorTree?.Dispose(); // this will also remove event handlers EditorTree = null; if (Closing != null) { foreach (var eh in Closing.GetInvocationList()) { var closingHandler = eh as EventHandler <EventArgs>; if (closingHandler != null) { Debug.Fail(Invariant($"There are still listeners in the EditorDocument.OnDocumentClosing event list: {eh.Target}")); Closing -= closingHandler; } } } EditorBuffer?.Services?.RemoveService(this); EditorBuffer = null; }
public void ConstructionTest() { TextBufferMock textBuffer = new TextBufferMock(string.Empty, RContentTypeDefinition.ContentType); var tree = new EditorTree(textBuffer, _editorShell); using (var editorDocument = new EditorDocumentMock(tree)) { using (var ob = new ROutlineRegionBuilder(editorDocument, _editorShell)) { ob.EditorDocument.Should().NotBeNull(); ob.EditorTree.Should().NotBeNull(); editorDocument.DocumentClosing.GetInvocationList().Should().ContainSingle(); FieldInfo treeUpdateField = tree.GetType().GetField("UpdateCompleted", BindingFlags.Instance | BindingFlags.NonPublic); var d = (MulticastDelegate)treeUpdateField.GetValue(tree); d.GetInvocationList().Should().ContainSingle(); tree.Dispose(); editorDocument.DocumentClosing.Should().BeNull(); treeUpdateField.GetValue(tree).Should().BeNull(); } } }