private void AddRefreshElements(DomElement startElement, DomElement endElement) { DomContentElement ce = myContainer.ContentElement; DomElementList res = this.OwnerList.RefreshElements; if (res.Contains(startElement) == false) { res.Add(startElement); } DomContentLine startLine = null; while (startElement != null) { // 可能存在元素不显示在文档中,例如处于图形模式下的XTextShapeInputFieldElement中, // 内容就不显示,在此向上查询显示出来的内容。 if (ce.PrivateContent.Contains(startElement)) { startLine = startElement.OwnerLine; if (res.Contains(startElement) == false) { res.Add(startElement); } break; } startElement = startElement.Parent; }//while if (res.Contains(endElement) == false) { res.Add(endElement); } DomContentLine endLine = null; while (endElement != null) { if (ce.PrivateContent.Contains(endElement)) { endLine = endElement.OwnerLine; if (res.Contains(endElement) == false) { res.Add(endElement); } break; } endElement = endElement.Parent; }//while ce.SetLinesInvalidateState( startLine, endLine); }
private void btnOK_Click(object sender, EventArgs e) { if (this.SourceEventArgs != null && this.SourceEventArgs.Element is DomImageElement) { DomDocument document = this.SourceEventArgs.Document; DomImageElement element = (DomImageElement)this.SourceEventArgs.Element; element.OwnerDocument = document; bool logUndo = this.SourceEventArgs.LogUndo && document.CanLogUndo; bool modified = false; string txt = txtID.Text.Trim(); if (txt.Length == 0) { txt = null; } if (txt != element.ID) { if (logUndo) { document.UndoList.AddProperty("ID", element.ID, txt, element); } element.ID = txt; modified = true; } txt = txtTitle.Text.Trim(); if (txt.Length == 0) { txt = null; } if (txt != element.Title) { if (logUndo) { document.UndoList.AddProperty("Title", element.Title, txt, element); } element.Title = txt; modified = true; } txt = txtAlt.Text.Trim(); if (txt.Length == 0) { txt = null; } if (txt != element.Alt) { if (logUndo) { document.UndoList.AddProperty("Alt", element.Alt, txt, element); } element.Alt = txt; modified = true; } txt = txtSource.Text.Trim(); if (txt.Length == 0) { txt = null; } if (txt != element.Source) { if (logUndo) { document.UndoList.AddProperty("Source", element.Source, txt, element); } element.Source = txt; modified = true; element.UpdateImageContent(); } if (chkKeepWidthHeightRate.Checked != element.KeepWidthHeightRate) { if (logUndo) { document.UndoList.AddProperty( "KeepWidthHeightRate", element.KeepWidthHeightRate, chkKeepWidthHeightRate.Checked, element); } element.KeepWidthHeightRate = chkKeepWidthHeightRate.Checked; modified = true; } if (chkSaveContentInFile.Checked != element.SaveContentInFile) { if (logUndo) { document.UndoList.AddProperty( "SaveContentInFile", element.SaveContentInFile, chkSaveContentInFile.Checked, element); } element.SaveContentInFile = chkSaveContentInFile.Checked; modified = true; } if (picImage.Tag != element.Image) { XImageValue img = (XImageValue)picImage.Tag; if (img == null) { img = new XImageValue(); } if (img.HasContent) { if (logUndo) { document.UndoList.AddProperty( "Image", element.Image, img, element); } element.Image = img; modified = true; } } if (modified) { SizeF oldSize = new SizeF(element.Width, element.Height); element.UpdateSize(); SizeF newSize = new SizeF(element.Width, element.Height); if (logUndo) { document.UndoList.AddProperty("Width", oldSize.Width, element.Width, element); document.UndoList.AddProperty("Height", oldSize.Height, element.Height, element); } } if (this.SourceEventArgs.Method == ElementEditMethod.Edit) { if (modified) { element.UpdateContentVersion(); DomContentElement ce = element.ContentElement; ce.SetLinesInvalidateState( element.OwnerLine, element.OwnerLine); ce.UpdateContentElements(true); element.SizeInvalid = true; ce.RefreshPrivateContent(element.ViewIndex); ContentChangedEventArgs args = new ContentChangedEventArgs(); args.Document = element.OwnerDocument; args.Element = element; args.LoadingDocument = false; element.Parent.RaiseBubbleOnContentChanged(args); } } else { this.DialogResult = System.Windows.Forms.DialogResult.OK; } this.Close(); } }
/// <summary> /// 撤销操作 /// </summary> public override void Undo(DCSoft.CSharpWriter.Undo.XUndoEventArgs args) { if (myContainer != null) { DomContentElement ce = myContainer.ContentElement; args.Parameters["ContentElement"] = ce; if (_OldElements != null && _NewElements == null) { // 光删除,撤销操作就是恢复数据 myContainer.Elements.InsertRange(intIndex, _OldElements); foreach (DomElement element in _OldElements) { DomElement e2 = GetContentElement(element); if (e2 != null && e2.OwnerLine != null) { e2.OwnerLine.InvalidateState = true; } element.OwnerLine = null; element.Parent = myContainer; } myContainer.UpdateContentVersion(); AddRefreshElements( _OldElements.FirstContentElement, _OldElements.LastContentElement); } else if (_OldElements == null && _NewElements != null) { // 光插入,撤销操作就是删除数据 int index = ce.PrivateContent.IndexOf(_NewElements.FirstContentElement); int startIndex = index; foreach (DomElement element in _NewElements) { startIndex = Math.Min(startIndex, element.FirstContentElement.ViewIndex); myContainer.Elements.Remove(element); myContainer.OwnerDocument.HighlightManager.Remove(element); DomElement fce = GetContentElement(element.FirstContentElement); DomElement ece = GetContentElement(element.LastContentElement); ce.SetLinesInvalidateState( fce == null ? null : fce.OwnerLine, ece == null ? null : ece.OwnerLine); if (element.OwnerLine != null) { element.OwnerLine.InvalidateState = true; element.OwnerLine = null; } } myContainer.UpdateContentVersion(); this.OwnerList.AddContentRefreshInfo(ce, startIndex); } else if (_OldElements != null && _NewElements != null) { // 替换,撤销操作就是删除新数据并恢复旧数据 int index = ce.PrivateContent.IndexOf(_NewElements.FirstContentElement); int startIndex = index; foreach (DomElement element in _NewElements) { startIndex = Math.Min(startIndex, element.FirstContentElement.ViewIndex); myContainer.Elements.Remove(element); myContainer.OwnerDocument.HighlightManager.Remove(element); DomElement fce = GetContentElement(element.FirstContentElement); DomElement ece = GetContentElement(element.LastContentElement); ce.SetLinesInvalidateState( fce == null ? null : fce.OwnerLine, ece == null ? null : ece.OwnerLine); //ce.SetLinesInvalidateState( // element.FirstContentElement.OwnerLine, // element.LastContentElement.OwnerLine); element.OwnerLine = null; } this.OwnerList.AddContentRefreshInfo(ce, startIndex); myContainer.Elements.InsertRange(intIndex, _OldElements); foreach (DomElement element in _OldElements) { if (element.OwnerLine != null) { element.OwnerLine.InvalidateState = true; element.OwnerLine = null; } element.Parent = myContainer; } myContainer.UpdateContentVersion(); this.OwnerList.RefreshElements.Add( GetContentElement( _OldElements.FirstContentElement)); this.OwnerList.RefreshElements.Add( GetContentElement( _OldElements.LastContentElement)); } if (this.OwnerList.ContentChangedContainer.Contains(myContainer) == false) { this.OwnerList.ContentChangedContainer.Add(myContainer); } } }