2008-09-16 13:43:47 +00:00
|
|
|
|
|
|
|
#region ================== Copyright (c) 2007 Pascal vd Heiden
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Copyright (c) 2007 Pascal vd Heiden, www.codeimp.com
|
|
|
|
* This program is released under GNU General Public License
|
|
|
|
*
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
|
|
|
#endregion
|
|
|
|
|
|
|
|
#region ================== Namespaces
|
|
|
|
|
|
|
|
using System;
|
|
|
|
using System.Collections;
|
|
|
|
using System.Collections.Generic;
|
|
|
|
using System.Globalization;
|
|
|
|
using System.Text;
|
|
|
|
using System.Windows.Forms;
|
|
|
|
using System.IO;
|
|
|
|
using System.Reflection;
|
|
|
|
using CodeImp.DoomBuilder.Windows;
|
|
|
|
using CodeImp.DoomBuilder.IO;
|
|
|
|
using CodeImp.DoomBuilder.Map;
|
|
|
|
using CodeImp.DoomBuilder.Rendering;
|
|
|
|
using System.Diagnostics;
|
|
|
|
using CodeImp.DoomBuilder.Actions;
|
|
|
|
|
|
|
|
#endregion
|
|
|
|
|
|
|
|
namespace CodeImp.DoomBuilder.Editing
|
|
|
|
{
|
|
|
|
public class CopyPasteManager
|
|
|
|
{
|
|
|
|
#region ================== Constants
|
|
|
|
|
2008-09-17 20:16:29 +00:00
|
|
|
private const string CLIPBOARD_DATA_FORMAT = "DOOM_BUILDER_GEOMETRY";
|
2008-09-17 19:21:45 +00:00
|
|
|
|
2008-09-16 13:43:47 +00:00
|
|
|
#endregion
|
|
|
|
|
|
|
|
#region ================== Variables
|
|
|
|
|
|
|
|
// Disposing
|
|
|
|
private bool isdisposed = false;
|
|
|
|
|
|
|
|
#endregion
|
|
|
|
|
|
|
|
#region ================== Properties
|
|
|
|
|
|
|
|
public bool IsDisposed { get { return isdisposed; } }
|
|
|
|
|
|
|
|
#endregion
|
|
|
|
|
|
|
|
#region ================== Constructor / Disposer
|
|
|
|
|
|
|
|
// Constructor
|
|
|
|
internal CopyPasteManager()
|
|
|
|
{
|
|
|
|
// Initialize
|
|
|
|
|
|
|
|
// Bind any methods
|
|
|
|
General.Actions.BindMethods(this);
|
|
|
|
|
|
|
|
// We have no destructor
|
|
|
|
GC.SuppressFinalize(this);
|
|
|
|
}
|
|
|
|
|
|
|
|
// Disposer
|
|
|
|
internal void Dispose()
|
|
|
|
{
|
|
|
|
// Not already disposed?
|
|
|
|
if(!isdisposed)
|
|
|
|
{
|
|
|
|
// Unbind any methods
|
|
|
|
General.Actions.UnbindMethods(this);
|
|
|
|
|
|
|
|
// Done
|
|
|
|
isdisposed = true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
#endregion
|
|
|
|
|
|
|
|
#region ================== Private Methods
|
|
|
|
|
2008-09-17 19:21:45 +00:00
|
|
|
// This performs the copy. Returns false when copy was cancelled.
|
|
|
|
private bool DoCopySelection()
|
|
|
|
{
|
2008-09-22 20:57:50 +00:00
|
|
|
// Let the plugins know
|
|
|
|
if(General.Plugins.OnPasteBegin())
|
2008-09-17 19:21:45 +00:00
|
|
|
{
|
2008-09-22 20:57:50 +00:00
|
|
|
// Ask the editing mode to prepare selection for copying.
|
|
|
|
// The edit mode should mark all vertices, lines and sectors
|
|
|
|
// that need to be copied.
|
2008-11-27 11:59:17 +00:00
|
|
|
if(General.Editing.Mode.OnCopyBegin())
|
2008-09-22 20:57:50 +00:00
|
|
|
{
|
2008-09-23 17:46:34 +00:00
|
|
|
// 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();
|
|
|
|
|
2008-09-22 20:57:50 +00:00
|
|
|
// Write data to stream
|
|
|
|
MemoryStream memstream = new MemoryStream();
|
|
|
|
UniversalStreamWriter writer = new UniversalStreamWriter();
|
|
|
|
writer.RememberCustomTypes = false;
|
2008-09-23 17:46:34 +00:00
|
|
|
writer.Write(copyset, memstream, null);
|
2008-09-22 20:57:50 +00:00
|
|
|
|
|
|
|
// Set on clipboard
|
|
|
|
Clipboard.SetData(CLIPBOARD_DATA_FORMAT, memstream);
|
|
|
|
|
|
|
|
// Done
|
|
|
|
memstream.Dispose();
|
2008-11-27 11:59:17 +00:00
|
|
|
General.Editing.Mode.OnCopyEnd();
|
2008-09-22 20:57:50 +00:00
|
|
|
General.Plugins.OnCopyEnd();
|
|
|
|
return true;
|
|
|
|
}
|
2008-09-17 19:21:45 +00:00
|
|
|
}
|
2008-09-22 20:57:50 +00:00
|
|
|
|
|
|
|
// Aborted
|
|
|
|
return false;
|
2008-09-17 19:21:45 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// This performs the paste. Returns false when paste was cancelled.
|
|
|
|
private bool DoPasteSelection()
|
|
|
|
{
|
2008-09-22 18:27:50 +00:00
|
|
|
// Anything to paste?
|
|
|
|
if(Clipboard.ContainsData(CLIPBOARD_DATA_FORMAT))
|
2008-09-17 19:21:45 +00:00
|
|
|
{
|
2008-09-23 10:04:10 +00:00
|
|
|
// Cancel volatile mode
|
|
|
|
General.DisengageVolatileMode();
|
|
|
|
|
2008-09-22 20:57:50 +00:00
|
|
|
// Let the plugins know
|
|
|
|
if(General.Plugins.OnPasteBegin())
|
2008-09-17 20:16:29 +00:00
|
|
|
{
|
2008-09-22 20:57:50 +00:00
|
|
|
// Ask the editing mode to prepare selection for pasting.
|
2008-11-27 11:59:17 +00:00
|
|
|
if(General.Editing.Mode.OnPasteBegin())
|
2008-09-22 20:57:50 +00:00
|
|
|
{
|
|
|
|
// Read from clipboard
|
|
|
|
Stream memstream = (Stream)Clipboard.GetData(CLIPBOARD_DATA_FORMAT);
|
|
|
|
memstream.Seek(0, SeekOrigin.Begin);
|
2008-09-22 18:27:50 +00:00
|
|
|
|
2008-09-22 20:57:50 +00:00
|
|
|
// Mark all current geometry
|
|
|
|
General.Map.Map.ClearAllMarks(true);
|
2008-09-22 18:27:50 +00:00
|
|
|
|
2008-09-22 20:57:50 +00:00
|
|
|
// Read data stream
|
|
|
|
UniversalStreamReader reader = new UniversalStreamReader();
|
2008-09-23 17:46:34 +00:00
|
|
|
reader.StrictChecking = false;
|
2008-09-22 20:57:50 +00:00
|
|
|
reader.Read(General.Map.Map, memstream);
|
2008-09-22 18:27:50 +00:00
|
|
|
|
2008-09-22 20:57:50 +00:00
|
|
|
// The new geometry is not marked, so invert the marks to get it marked
|
|
|
|
General.Map.Map.InvertAllMarks();
|
2008-09-22 18:27:50 +00:00
|
|
|
|
2008-09-22 20:57:50 +00:00
|
|
|
// Done
|
|
|
|
memstream.Dispose();
|
2008-11-27 11:59:17 +00:00
|
|
|
General.Editing.Mode.OnPasteEnd();
|
2008-09-22 20:57:50 +00:00
|
|
|
General.Plugins.OnPasteEnd();
|
|
|
|
return true;
|
|
|
|
}
|
2008-09-17 20:16:29 +00:00
|
|
|
}
|
2008-09-22 20:57:50 +00:00
|
|
|
|
|
|
|
// Aborted
|
|
|
|
return false;
|
2008-09-17 19:21:45 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2008-09-22 20:57:50 +00:00
|
|
|
// Nothing usefull on the clipboard
|
2008-09-17 19:21:45 +00:00
|
|
|
General.MessageBeep(MessageBeepType.Warning);
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2008-09-16 13:43:47 +00:00
|
|
|
#endregion
|
|
|
|
|
|
|
|
#region ================== Public Methods
|
|
|
|
|
|
|
|
// This copies the current selection
|
|
|
|
[BeginAction("copyselection")]
|
|
|
|
public void CopySelection()
|
|
|
|
{
|
2008-09-17 19:21:45 +00:00
|
|
|
DoCopySelection();
|
2008-09-16 13:43:47 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// This cuts the current selection
|
|
|
|
[BeginAction("cutselection")]
|
|
|
|
public void CutSelection()
|
|
|
|
{
|
|
|
|
// Copy selected geometry
|
2008-09-17 19:21:45 +00:00
|
|
|
if(DoCopySelection())
|
2008-09-16 13:43:47 +00:00
|
|
|
{
|
2008-09-17 19:21:45 +00:00
|
|
|
// Get the delete action and check if it's bound
|
|
|
|
Action deleteitem = General.Actions["builder_deleteitem"];
|
|
|
|
if(deleteitem.BeginBound)
|
|
|
|
{
|
|
|
|
// Perform delete action
|
|
|
|
deleteitem.Begin();
|
|
|
|
deleteitem.End();
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
// Action not bound
|
|
|
|
General.Interface.DisplayWarning("Cannot remove that in this mode.");
|
|
|
|
}
|
2008-09-16 13:43:47 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// This pastes what is on the clipboard and marks the new geometry
|
|
|
|
[BeginAction("pasteselection")]
|
|
|
|
public void PasteSelection()
|
|
|
|
{
|
2008-09-17 19:21:45 +00:00
|
|
|
DoPasteSelection();
|
2008-09-16 13:43:47 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
#endregion
|
|
|
|
}
|
|
|
|
}
|