// This performs the paste. Returns false when paste was cancelled. private static void DoPasteSelection(PasteOptions options) { // Check if possible to copy/paste if (General.Editing.Mode.Attributes.AllowCopyPaste) { bool havepastedata = Clipboard.ContainsData(CLIPBOARD_DATA_FORMAT); //mxd bool havedb2pastedata = Clipboard.ContainsData(CLIPBOARD_DATA_FORMAT_DB2); //mxd // Anything to paste? if (havepastedata || havedb2pastedata) { // Cancel volatile mode General.Editing.DisengageVolatileMode(); // Let the plugins know if (General.Plugins.OnPasteBegin(options)) { // Ask the editing mode to prepare selection for pasting. if (General.Editing.Mode.OnPasteBegin(options.Copy())) { // Create undo General.MainWindow.DisplayStatus(StatusType.Action, "Pasted selected elements."); General.Map.UndoRedo.CreateUndo("Paste"); // Mark all current geometry General.Map.Map.ClearAllMarks(true); // Read from clipboard if (havepastedata) { using (Stream memstream = (Stream)Clipboard.GetData(CLIPBOARD_DATA_FORMAT)) { // Rewind before use memstream.Seek(0, SeekOrigin.Begin); // Read data stream ClipboardStreamReader reader = new ClipboardStreamReader(); //mxd General.Map.Map.BeginAddRemove(); bool success = reader.Read(General.Map.Map, memstream); General.Map.Map.EndAddRemove(); if (!success) //mxd { General.Map.UndoRedo.WithdrawUndo(); // This will also mess with the marks... General.Map.Map.ClearAllMarks(true); // So re-mark all current geometry... } } } // mxd. DB2/DB64 interop else if (havedb2pastedata) { using (Stream memstream = (Stream)Clipboard.GetData(CLIPBOARD_DATA_FORMAT_DB2)) { // Read data stream UniversalStreamReader reader = new UniversalStreamReader(new Dictionary <MapElementType, Dictionary <string, UniversalType> >()); reader.StrictChecking = false; General.Map.Map.BeginAddRemove(); reader.Read(General.Map.Map, memstream); General.Map.Map.EndAddRemove(); } } else { throw new NotImplementedException("Unknown clipboard data format!"); } // The new geometry is not marked, so invert the marks to get it marked General.Map.Map.InvertAllMarks(); // Check if anything was pasted List <Thing> things = General.Map.Map.GetMarkedThings(true); //mxd int totalpasted = things.Count; totalpasted += General.Map.Map.GetMarkedVertices(true).Count; totalpasted += General.Map.Map.GetMarkedLinedefs(true).Count; totalpasted += General.Map.Map.GetMarkedSidedefs(true).Count; totalpasted += General.Map.Map.GetMarkedSectors(true).Count; if (totalpasted > 0) { // Convert UDMF fields back to flags and activations, if needed if (!(General.Map.FormatInterface is UniversalMapSetIO)) { General.Map.Map.TranslateFromUDMF(); } // Modify tags and actions if preferred if (options.ChangeTags == PasteOptions.TAGS_REMOVE) { Tools.RemoveMarkedTags(); } if (options.ChangeTags == PasteOptions.TAGS_RENUMBER) { Tools.RenumberMarkedTags(); } if (options.RemoveActions) { Tools.RemoveMarkedActions(); } foreach (Thing t in things) { t.UpdateConfiguration(); //mxd } General.Map.ThingsFilter.Update(); General.Editing.Mode.OnPasteEnd(options.Copy()); General.Plugins.OnPasteEnd(options); } } } } else { // Nothing useful on the clipboard // [ZZ] don't beep if 3D mode is currently engaged. the 3D mode allows you to copy/paste non-geometry stuff. // note that this is a hack and probably needs to be fixed properly by making it beep elsewhere so that the current active mode can decide this. if (!(General.Editing.Mode is VisualMode)) { General.MessageBeep(MessageBeepType.Warning); } } } else { // Paste not allowed General.MessageBeep(MessageBeepType.Warning); } }
// This performs the paste. Returns false when paste was cancelled. private static void DoPasteSelection(PasteOptions options) { // Check if possible to copy/paste if (General.Editing.Mode.Attributes.AllowCopyPaste) { // Anything to paste? if (Clipboard.ContainsData(CLIPBOARD_DATA_FORMAT)) { // Cancel volatile mode General.Editing.DisengageVolatileMode(); // Let the plugins know if (General.Plugins.OnPasteBegin(options)) { // Ask the editing mode to prepare selection for pasting. if (General.Editing.Mode.OnPasteBegin(options.Copy())) { // Create undo General.MainWindow.DisplayStatus(StatusType.Action, "Pasted selected elements."); General.Map.UndoRedo.CreateUndo("Paste"); // Mark all current geometry General.Map.Map.ClearAllMarks(true); // Read from clipboard using (Stream memstream = (Stream)Clipboard.GetData(CLIPBOARD_DATA_FORMAT)) { // Rewind before use memstream.Seek(0, SeekOrigin.Begin); // Read data stream ClipboardStreamReader reader = new ClipboardStreamReader(); //mxd General.Map.Map.BeginAddRemove(); bool success = reader.Read(General.Map.Map, memstream); General.Map.Map.EndAddRemove(); if (!success) //mxd { General.Map.UndoRedo.WithdrawUndo(); // This will also mess with the marks... General.Map.Map.ClearAllMarks(true); // So re-mark all current geometry... } } // The new geometry is not marked, so invert the marks to get it marked General.Map.Map.InvertAllMarks(); // Check if anything was pasted List <Thing> things = General.Map.Map.GetMarkedThings(true); //mxd int totalpasted = things.Count; totalpasted += General.Map.Map.GetMarkedVertices(true).Count; totalpasted += General.Map.Map.GetMarkedLinedefs(true).Count; totalpasted += General.Map.Map.GetMarkedSidedefs(true).Count; totalpasted += General.Map.Map.GetMarkedSectors(true).Count; if (totalpasted > 0) { // Convert UDMF fields back to flags and activations, if needed if (!(General.Map.FormatInterface is UniversalMapSetIO)) { General.Map.Map.TranslateFromUDMF(); } // Modify tags and actions if preferred if (options.ChangeTags == PasteOptions.TAGS_REMOVE) { Tools.RemoveMarkedTags(); } if (options.ChangeTags == PasteOptions.TAGS_RENUMBER) { Tools.RenumberMarkedTags(); } if (options.RemoveActions) { Tools.RemoveMarkedActions(); } foreach (Thing t in things) { t.UpdateConfiguration(); //mxd } General.Map.ThingsFilter.Update(); General.Editing.Mode.OnPasteEnd(options.Copy()); General.Plugins.OnPasteEnd(options); } } } } else { // Nothing usefull on the clipboard General.MessageBeep(MessageBeepType.Warning); } } else { // Paste not allowed General.MessageBeep(MessageBeepType.Warning); } }