//////////////////////////////////////////////////////////////////////////
        private void CopySelectedItems()
        {
            List<string> Types = new List<string>();
            List<string> Values = new List<string>();

            WDynBuffer Buf = new WDynBuffer(Game);
            foreach(WUIObject C in SelectedControls)
            {
                bool IsParentSelected = false;
                WUIObject Parent = C.Parent;
                while (Parent != null)
                {
                    if (Parent.EditorSelected)
                    {
                        IsParentSelected = true;
                        break;
                    }
                    Parent = Parent.Parent;
                }
                if (IsParentSelected) continue;

                Types.Add(C.GetType().AssemblyQualifiedName);

                Buf.Clear();
                C.SaveAsText(Buf);
                Values.Add(Buf.Text);
            }
            Buf.Dispose();

            if (Types.Count == 0)
            {
                SystemSounds.Asterisk.Play();
                return;
            }

            string[,] ClipData = new string[Types.Count, 2];
            for(int i=0; i<Types.Count; i++)
            {
                ClipData[i, 0] = Types[i];
                ClipData[i, 1] = Values[i];
            }
            Clipboard.SetData(ClipFormat, ClipData);
        }
        //////////////////////////////////////////////////////////////////////////
        public bool SaveDocument(bool SaveAs)
        {
            if (FileName == "") SaveAs = true;

            string NewFileName = FileName;

            if (SaveAs)
            {
                string Filter;
                if (InvBox != null || RespBox != null)
                    Filter = "Definiton files (*.def)|*.def";
                else
                    Filter = "Windows (*.window)|*.window";
                Filter += "|All files (*.*)|*.*";

                SaveFileDialog dlg = new SaveFileDialog();
                dlg.FileName = FileName;
                dlg.Filter = Filter;
                dlg.AddExtension = true;
                dlg.CheckPathExists = true;
                dlg.OverwritePrompt = true;
                dlg.RestoreDirectory = true;

                if (dlg.ShowDialog() != DialogResult.OK) return false;

                NewFileName = dlg.FileName;
            }

            DeleteEditorProps();

            WDynBuffer Buf = new WDynBuffer(Game);
            if (InvBox != null) InvBox.SaveAsText(Buf);
            else if (RespBox != null) RespBox.SaveAsText(Buf);
            else Window.SaveAsText(Buf);

            string RelProjectPath = WmeUtils.GetRelativePath(NewFileName, Path.GetDirectoryName(Game.ProjectFile) + "\\");

            string FileContent = "";
            FileContent += "; generated by WindowEdit\n\n";
            FileContent += "; $EDITOR_PROJECT_ROOT_DIR$ " + RelProjectPath + "\n\n";
            FileContent += Buf.Text;

            Buf.Dispose();

            try
            {
                using (StreamWriter sw = new StreamWriter(NewFileName, false, Encoding.Default))
                {
                    sw.WriteLine(FileContent);
                }

                FileName = NewFileName;
                IsDirty = false;

                return true;
            }
            catch(Exception e)
            {
                MessageBox.Show("Error saving file.\n\n" + e.Message, Form.ActiveForm.Text, MessageBoxButtons.OK, MessageBoxIcon.Error);
                return false;
            }
        }
        //////////////////////////////////////////////////////////////////////////
        private bool SaveFile(bool SaveAs)
        {
            if (Filename == "" || Filename == null)
            {
                SaveAs = true;
            }

            string NewFileName;

            if (SaveAs)
            {
                SaveFileDialog dlg = new SaveFileDialog();
                dlg.Filter           = "Tiles images (*.image)|*.image|All files (*.*)|*.*";
                dlg.AddExtension     = true;
                dlg.CheckPathExists  = true;
                dlg.OverwritePrompt  = true;
                dlg.RestoreDirectory = true;

                if (Filename != null && Filename != "")
                {
                    dlg.FileName = Game.MakeAbsolutePath(Filename);
                }

                if (dlg.ShowDialog() != DialogResult.OK)
                {
                    return(false);
                }

                NewFileName = dlg.FileName;
            }
            else
            {
                NewFileName = Game.MakeAbsolutePath(Filename);
            }


            WDynBuffer Buf = new WDynBuffer(Game);

            TiledImg.SaveAsText(Buf);

            string FileContent = "";

            FileContent += "; generated by WindowEdit\n\n";
            FileContent += Buf.Text;

            Buf.Dispose();

            try
            {
                using (StreamWriter sw = new StreamWriter(NewFileName, false, Encoding.Default))
                {
                    sw.WriteLine(FileContent);
                }

                Filename = Game.MakeRelativePath(NewFileName);
                IsDirty  = false;
                DisplayData();

                return(true);
            }
            catch (Exception e)
            {
                MessageBox.Show("Error saving file.\n\n" + e.Message, Form.ActiveForm.Text, MessageBoxButtons.OK, MessageBoxIcon.Error);
                return(false);
            }
        }
        //////////////////////////////////////////////////////////////////////////
        public override string GetCurrentStateForUndo()
        {
            WDynBuffer Buf = new WDynBuffer(Game);

            if (InvBox != null) InvBox.SaveAsText(Buf);
            else if (RespBox != null) RespBox.SaveAsText(Buf);
            else if (Window != null) Window.SaveAsText(Buf);
            else
            {
                Buf.Dispose();
                return null;
            }

            string Ret = Buf.Text;
            Buf.Dispose();

            return Ret;
        }
        //////////////////////////////////////////////////////////////////////////
        private bool SaveFile(bool SaveAs)
        {
            if (Filename == "" || Filename == null) SaveAs = true;

            string NewFileName;

            if (SaveAs)
            {
                SaveFileDialog dlg = new SaveFileDialog();
                dlg.Filter = "Tiles images (*.image)|*.image|All files (*.*)|*.*";
                dlg.AddExtension = true;
                dlg.CheckPathExists = true;
                dlg.OverwritePrompt = true;
                dlg.RestoreDirectory = true;

                if (Filename != null && Filename != "")
                    dlg.FileName = Game.MakeAbsolutePath(Filename);

                if (dlg.ShowDialog() != DialogResult.OK) return false;

                NewFileName = dlg.FileName;
            }
            else NewFileName = Game.MakeAbsolutePath(Filename);

            WDynBuffer Buf = new WDynBuffer(Game);
            TiledImg.SaveAsText(Buf);

            string FileContent = "";
            FileContent += "; generated by WindowEdit\n\n";
            FileContent += Buf.Text;

            Buf.Dispose();

            try
            {
                using (StreamWriter sw = new StreamWriter(NewFileName, false, Encoding.Default))
                {
                    sw.WriteLine(FileContent);
                }

                Filename = Game.MakeRelativePath(NewFileName);
                IsDirty = false;
                DisplayData();

                return true;
            }
            catch (Exception e)
            {
                MessageBox.Show("Error saving file.\n\n" + e.Message, Form.ActiveForm.Text, MessageBoxButtons.OK, MessageBoxIcon.Error);
                return false;
            }
        }