public virtual bool AktionPasteFromClipboard(UndoSnapshotSetzenOptionen undoSnapshotSetzen) { if (!this.AktionenMoeglich) { return(false); } string text = ""; try { XMLCursorPos startPos; if (Clipboard.ContainsText(TextDataFormat.Text)) { if (this.IstRootNodeSelektiert) { return(this.AktionRootNodeDurchClipboardInhaltErsetzen(undoSnapshotSetzen)); } if (this.IstEtwasSelektiert) { if (this.AktionDelete(UndoSnapshotSetzenOptionen.nein)) { startPos = this._cursor.StartPos; goto IL_008a; } return(false); } startPos = this.CursorOptimiert.StartPos; goto IL_008a; } return(false); IL_008a: if (undoSnapshotSetzen == UndoSnapshotSetzenOptionen.ja) { this._undoHandler.SnapshotSetzen(ResReader.Reader.GetString("AktionEinfuegen"), this._cursor); } text = Clipboard.GetText(TextDataFormat.Text); text = text.Replace("\r\n", " "); text = text.Replace("\n\r", " "); text = text.Replace("\r", " "); text = text.Replace("\n", " "); text = text.Replace("\t", " "); string xmlFragment = string.Format("<paste>{0}</paste>", text); XmlTextReader xmlTextReader = new XmlTextReader(xmlFragment, XmlNodeType.Element, null); xmlTextReader.MoveToContent(); XmlNode xmlNode = this._rootNode.OwnerDocument.ReadNode(xmlTextReader); XMLCursorPos xMLCursorPos = startPos.Clone(); foreach (XmlNode childNode in xmlNode.ChildNodes) { if (childNode is XmlText) { XmlNode xmlNode3 = null; xMLCursorPos.TextEinfuegen(childNode.Clone().Value, this.Regelwerk, out xmlNode3); if (xmlNode3 != null) { xMLCursorPos.InsertXMLNode(xmlNode3.Clone(), this.Regelwerk, true); } } else { xMLCursorPos.InsertXMLNode(childNode.Clone(), this.Regelwerk, true); } } XMLCursorPositionen posAmNode = this._cursor.EndPos.PosAmNode; if (posAmNode == XMLCursorPositionen.CursorVorDemNode || posAmNode == XMLCursorPositionen.CursorInnerhalbDesTextNodes) { this._cursor.BeideCursorPosSetzen(xMLCursorPos.AktNode, xMLCursorPos.PosAmNode, xMLCursorPos.PosImTextnode); } else { this._cursor.BeideCursorPosSetzen(xMLCursorPos.AktNode, XMLCursorPositionen.CursorHinterDemNode); } return(true); } catch (Exception ex) { Debugger.GlobalDebugger.Protokolliere(string.Format("AktionPasteFromClipboard:Fehler für Einfügetext '{0}':{1}", text, ex.Message), Debugger.ProtokollTypen.Fehlermeldung); return(false); } }
public virtual bool AktionPasteFromClipboard( XMLEditor.UndoSnapshotSetzenOptionen undoSnapshotSetzen) { if (!this.AktionenMoeglich) { return(false); } string str = ""; try { if (!Clipboard.ContainsText(TextDataFormat.Text)) { return(false); } if (this.IstRootNodeSelektiert) { return(this.AktionRootNodeDurchClipboardInhaltErsetzen(undoSnapshotSetzen)); } XMLCursorPos startPos; if (this.IstEtwasSelektiert) { if (!this.AktionDelete(XMLEditor.UndoSnapshotSetzenOptionen.nein)) { return(false); } startPos = this._cursor.StartPos; } else { startPos = this.CursorOptimiert.StartPos; } if (undoSnapshotSetzen == XMLEditor.UndoSnapshotSetzenOptionen.ja) { this._undoHandler.SnapshotSetzen(de.springwald.xml.ResReader.Reader.GetString("AktionEinfuegen"), this._cursor); } str = Clipboard.GetText(TextDataFormat.Text); str = str.Replace("\r\n", " "); str = str.Replace("\n\r", " "); str = str.Replace("\r", " "); str = str.Replace("\n", " "); str = str.Replace("\t", " "); XmlTextReader xmlTextReader = new XmlTextReader(string.Format("<paste>{0}</paste>", (object)str), XmlNodeType.Element, (XmlParserContext)null); int content = (int)xmlTextReader.MoveToContent(); XmlNode xmlNode = this._rootNode.OwnerDocument.ReadNode((XmlReader)xmlTextReader); XMLCursorPos xmlCursorPos = startPos.Clone(); foreach (XmlNode childNode in xmlNode.ChildNodes) { if (childNode is XmlText) { XmlNode ersatzNode = (XmlNode)null; xmlCursorPos.TextEinfuegen(childNode.Clone().Value, this.Regelwerk, out ersatzNode); if (ersatzNode != null) { xmlCursorPos.InsertXMLNode(ersatzNode.Clone(), this.Regelwerk, true); } } else { xmlCursorPos.InsertXMLNode(childNode.Clone(), this.Regelwerk, true); } } switch (this._cursor.EndPos.PosAmNode) { case XMLCursorPositionen.CursorVorDemNode: case XMLCursorPositionen.CursorInnerhalbDesTextNodes: this._cursor.BeideCursorPosSetzen(xmlCursorPos.AktNode, xmlCursorPos.PosAmNode, xmlCursorPos.PosImTextnode); break; default: this._cursor.BeideCursorPosSetzen(xmlCursorPos.AktNode, XMLCursorPositionen.CursorHinterDemNode); break; } return(true); } catch (Exception ex) { Debugger.GlobalDebugger.Protokolliere(string.Format("AktionPasteFromClipboard:Fehler für Einfügetext '{0}':{1}", (object)str, (object)ex.Message), Debugger.ProtokollTypen.Fehlermeldung); return(false); } }