using System;
using System.IO;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;

namespace Editor
{
    public partial class NewSceneDialog : Form
    {
        public NewSceneDialog()
        {
            InitializeComponent();
        }

        private void NewSceneDialog_Load(object sender, EventArgs e)
        {

        }

        private void btnOk_Click(object sender, EventArgs e)
        {
            // Check that we have a valid file name for the scene.
            // If we don't have any valid file name don't do anything!

            if (File.Exists(fileNameTextBox.Text))
            {
                DirectoryInfo dInf = Directory.GetParent(fileNameTextBox.Text);

                if (dInf.Exists)
                {
                    DialogResult = DialogResult.OK;
                }
            }
            else
            {
                MessageBox.Show("Please enter a valid file name!");
            }
        }

        private void fileNameTextBox_TextChanged(object sender, EventArgs e)
        {

        }

        private void browseBtn_Click(object sender, EventArgs e)
        {
            SaveFileDialog dlg = new SaveFileDialog();

            // Set the properties on dlg so the user is 
            // prompted to create the file if it doesn't exist 
            // or overwrite the file if it does exist.
            dlg.CreatePrompt = true;
            dlg.OverwritePrompt = true;

            // Set the file name to myText.txt, set the type filter
            // to text files, and set the initial directory to drive C.
            dlg.FileName = "myScene";
            dlg.DefaultExt = "xml";
            dlg.Filter = "Scene files (*.xml)|*.xml";

            // Call ShowDialog and check for a return value of DialogResult.OK,
            // which indicates that the file was saved. 
            DialogResult result = dlg.ShowDialog();
            System.IO.Stream fileStream;

            if (result == DialogResult.OK)

            // Open the file, copy the contents of memoryStream to fileStream,
            // and close fileStream. Set the memoryStream.Position value to 0 to 
            // copy the entire stream. 
            {
                fileStream = dlg.OpenFile();
                StreamWriter sw = new StreamWriter(fileStream);
                sw.Write("Empty. File was created but no scene information was ever persisted here!"); 
                fileStream.Close();

                fileNameTextBox.Text = dlg.FileName;
            }

        }

        private void BtnCancel_Click(object sender, EventArgs e)
        {
            DialogResult = DialogResult.Cancel;
        }
    }
}