// This performs the copy. Returns false when copy was cancelled. private bool DoCopySelection(string desc) { // Check if possible to copy/paste if (General.Editing.Mode.Attributes.AllowCopyPaste) { // Let the plugins know if (General.Plugins.OnCopyBegin()) { // Ask the editing mode to prepare selection for copying. // The edit mode should mark all vertices, lines and sectors // that need to be copied. if (General.Editing.Mode.OnCopyBegin()) { General.MainWindow.DisplayStatus(StatusType.Action, desc); // Copy the marked geometry // This links sidedefs that are not linked to a marked sector to a virtual sector MapSet copyset = General.Map.Map.CloneMarked(); // Convert flags and activations to UDMF fields, if needed if (!(General.Map.FormatInterface is UniversalMapSetIO)) { copyset.TranslateToUDMF(); } // Write data to stream MemoryStream memstream = new MemoryStream(); UniversalStreamWriter writer = new UniversalStreamWriter(); writer.RememberCustomTypes = false; writer.Write(copyset, memstream, null); // Set on clipboard Clipboard.SetData(CLIPBOARD_DATA_FORMAT, memstream); // Done memstream.Dispose(); General.Editing.Mode.OnCopyEnd(); General.Plugins.OnCopyEnd(); return(true); } } } else { // Copy not allowed General.MessageBeep(MessageBeepType.Warning); } // Aborted return(false); }
// This makes a prefab of the selection. Returns null when cancelled. internal MemoryStream MakePrefab() { // Let the plugins know if (General.Plugins.OnCopyBegin()) { // Ask the editing mode to prepare selection for copying. // The edit mode should mark all vertices, lines and sectors // that need to be copied. if (General.Editing.Mode.OnCopyBegin()) { // Copy the marked geometry // This links sidedefs that are not linked to a marked sector to a virtual sector MapSet copyset = General.Map.Map.CloneMarked(); // Convert flags and activations to UDMF fields, if needed if (!(General.Map.FormatInterface is UniversalMapSetIO)) { copyset.TranslateToUDMF(); } // Write data to stream MemoryStream memstream = new MemoryStream(); UniversalStreamWriter writer = new UniversalStreamWriter(); writer.RememberCustomTypes = false; writer.Write(copyset, memstream, null); // Compress the stream MemoryStream compressed = new MemoryStream((int)memstream.Length); memstream.Seek(0, SeekOrigin.Begin); BZip2.Compress(memstream, compressed, 900000); // Done memstream.Dispose(); General.Editing.Mode.OnCopyEnd(); General.Plugins.OnCopyEnd(); return(compressed); } } // Aborted return(null); }