/// <summary> /// 在编辑器中删除整个对象 /// </summary> /// <param name="logUndo">是否记录撤销操作信息</param> public bool EditorDelete(bool logUndo) { if (this is DomDocumentContentElement) { return(false); } DomContainerElement container = this.Parent; int index = container.Elements.IndexOf(this); DomDocument document = this.OwnerDocument; if (logUndo) { document.BeginLogUndo(); } int result = document.ReplaceElements(new ReplaceElementsArgs( container, index, 1, null, logUndo, true, true)); if (logUndo) { document.EndLogUndo(); } return(result != 0); }
/// <summary> /// 根据内容创建一个新的文档对象,而且不包含已经被逻辑删除的内容. /// </summary> /// <returns>创建的文档对象</returns> public DomDocument CreateDocument() { DomDocument document = ( DomDocument )this.Document.Clone(false); DomDocument sourceDocument = this.Document; DomContainerElement body = document.Body; // 寻找所有内容共同的文档容器元素 DomElementList parents1 = WriterUtils.GetParentList(this.ContentElements.FirstElement); DomElementList parents2 = WriterUtils.GetParentList(this.ContentElements.LastElement); foreach (DomContainerElement parent in parents1) { if (parents2.Contains(parent)) { DomContentElement ce = parent.ContentElement; CloneElements(parent, ref body); break; } } //CloneElements(this.DocumentContent, ref body ); // 删除用户操作历史记录信息 foreach (DocumentContentStyle style in document.ContentStyles.Styles) { style.CreatorIndex = -1; style.DeleterIndex = -1; } document.UserHistories.Clear(); // 删除没有引用的样式 document.DeleteUselessStyle(); document.EditorControl = null; document.DocumentControler = null; document.HighlightManager = null; document.EditorCurrentStyle = null; document.HoverElement = null; if (document.UndoList != null) { document.EndLogUndo(); document.UndoList.Clear(); } document.FixDomState(); return(document); }