protected override void OnClosing(System.ComponentModel.CancelEventArgs e)
        {
            if (richTextBox1.Text == m_strLevelText)
            {
                return;
            }

            DialogResult dlgr = MessageBox.Show(this, "Save Changes?", "M", MessageBoxButtons.YesNoCancel,
                                                MessageBoxIcon.Question);

            switch (dlgr)
            {
            case DialogResult.Yes:
                int ichErrorPos;
                if (m_lvld.SetLevelText(richTextBox1.Text, out ichErrorPos))
                {
                    DialogResult = DialogResult.OK;
                }
                else
                {
                    richTextBox1.Select(ichErrorPos, 0);
                    e.Cancel = true;
                }
                break;

            case DialogResult.No:
                DialogResult = DialogResult.Cancel;
                break;

            case DialogResult.Cancel:
                e.Cancel = true;
                break;
            }
        }
示例#2
0
        public static void ImportText(string[] astr)
        {
            // Expand filespecs
            ArrayList alsFiles = new ArrayList();

            for (int n = 1; n < astr.Length; n++)
            {
                string strFileT = Path.GetFileName(astr[n]);
                string strDirT  = Path.GetDirectoryName(astr[n]);
                if (strDirT == "")
                {
                    strDirT = ".";
                }
                string[] astrFiles = Directory.GetFiles(strDirT, strFileT);
                alsFiles.AddRange(astrFiles);
            }

            Console.WriteLine("Importing text from {0} files", alsFiles.Count);

            // Attempt to process these text files/level docs

            foreach (string strTextFile in alsFiles)
            {
                string strFile = "." + Path.DirectorySeparatorChar + Path.GetFileName(strTextFile).Replace(".txt", ".ld");
                Console.Write("Writing " + strTextFile + " to " + strFile + "...");
                LevelDoc lvld = (LevelDoc)DocManager.OpenDocument(strFile);
                if (lvld == null)
                {
                    throw new Exception("Could not load level doc " + strFile);
                }

                StreamReader stmr = new StreamReader(strTextFile);
                string       str  = stmr.ReadToEnd();
                stmr.Close();
                str = str.Replace("\r\n", "\n");

                int ichErrorPos;
                if (!lvld.SetLevelText(str, out ichErrorPos))
                {
                    Console.WriteLine(" error at char " + ichErrorPos);
                }
                else
                {
                    lvld.Save();
                    Console.WriteLine(" saved");
                }
                lvld.Dispose();
            }
        }