ViewVC Help
View File | Revision Log | Show Annotations | Download File | View Changeset | Root Listing
root/RomCheater/trunk/RomCheater.ScratchPad/ScratchPad.cs
(Generate patch)

Comparing trunk/RomCheater.ScratchPad/ScratchPad.cs (file contents):
Revision 762 by william, Thu Jun 20 20:25:55 2013 UTC vs.
Revision 774 by william, Thu Jun 20 22:33:04 2013 UTC

--- trunk/RomCheater.ScratchPad/ScratchPad.cs	2013/06/20 20:25:55	762
+++ trunk/RomCheater.ScratchPad/ScratchPad.cs	2013/06/20 22:33:04	774
@@ -28,16 +28,15 @@ using RomCheater.PluginFramework.Core;
 namespace RomCheater.ScratchPad
 {
     public partial class ScratchPad : DockContent
-    {
-
+    {        
+        List<ScratchPadDocument> docuemntList = new List<ScratchPadDocument>();
         private UserControlPlugin plugin;
         private bool PostInitDone = false;
         public ScratchPad(UserControlPlugin plugin)
         {
             this.plugin = plugin;
             InitPluginFramework();
-            InitializeComponent();            
-            this.PerformPreInit();
+            InitializeComponent();                        
         }
 
 
@@ -76,178 +75,34 @@ namespace RomCheater.ScratchPad
         }
 
 
-        private void PerformPreInit()
-        {
-            txtScratchPad.Font = new System.Drawing.Font(txtScratchPad.Font, FontStyle.Italic);
-            txtScratchPad.ForeColor = SystemColors.GrayText;
-            StringBuilder builder = new StringBuilder();
-            txtScratchPad.Clear();
-
-            builder.AppendFormat(System.Environment.NewLine);
-            builder.AppendFormat("\tThis is a scratchpad");
-            builder.AppendFormat(System.Environment.NewLine);
-            builder.AppendFormat("\tYou can type anything in here, and save it for later or load an existing file.");
-
-            txtScratchPad.AppendText(builder.ToString());
-        }
-
-
-        private void PerformSaveOperation()
-        {
-        }
-
-        private void mnuItemSave_Click(object sender, EventArgs e)
-        {
-            PerformPostInit();
-            DialogResult result = ScracthPadSaver.ShowDialog();
-            if (result != DialogResult.OK) { return; }
-            try
-            {
-                using (FileStream fs = new FileStream(ScracthPadSaver.FileName, FileMode.OpenOrCreate, FileAccess.Write, FileShare.Read))
-                {
-                    try
-                    {
-                        using (StreamWriter sw = new StreamWriter(fs))
-                        {
-                            string line = string.Empty;
-                            using (StringReader sr = new StringReader(txtScratchPad.Text))
-                            {
-                                while ((line = sr.ReadLine()) != null)
-                                {
-                                    sw.WriteLine(line);
-                                }
-                            }
-                            sw.Flush();
-                            sw.Close();
-                        }
-                    }
-                    catch (Exception ex)
-                    {
-                        logger.Error.WriteLine("Failed to save file: {0}", ScracthPadSaver.FileName);
-                        logger.VerboseError.WriteLine(ex.ToString());
-                        MessageBox.Show(string.Format("Failed to save: '{0}'", new FileInfo(ScracthPadSaver.FileName).Name), "", MessageBoxButtons.OK, MessageBoxIcon.Error);
-                        return;
-                    }
-                }
-                MessageBox.Show(string.Format("Successfully saved file: '{0}'", new FileInfo(ScracthPadSaver.FileName).Name), "", MessageBoxButtons.OK, MessageBoxIcon.Information);
-            }
-            catch (Exception ex)
-            {
-                logger.Error.WriteLine("Failed to save file: {0}", ScracthPadSaver.FileName);
-                logger.VerboseError.WriteLine(ex.ToString());
-                MessageBox.Show(string.Format("Failed to save: '{0}'", new FileInfo(ScracthPadSaver.FileName).Name), "", MessageBoxButtons.OK, MessageBoxIcon.Error);
-            }
-        }
-
-        private void mnuItemOpen_Click(object sender, EventArgs e)
-        {
-            PerformPostInit();
-            DialogResult result = ScracthPadLoader.ShowDialog();
-            if (result != DialogResult.OK) { return; }
-            txtScratchPad.Clear();
-
-            try
-            {
-                using (FileStream fs = new FileStream(ScracthPadLoader.FileName, FileMode.Open, FileAccess.Read, FileShare.Read))
-                {
-                    try
-                    {
-                        using (StreamReader sr = new StreamReader(fs))
-                        {
-                            txtScratchPad.AppendText(sr.ReadToEnd());
-                        }
-                    }
-                    catch (Exception ex)
-                    {
-                        logger.Error.WriteLine("Failed to open file: {0}", ScracthPadLoader.FileName);
-                        logger.VerboseError.WriteLine(ex.ToString());
-                        MessageBox.Show(string.Format("Failed to open: '{0}'", new FileInfo(ScracthPadLoader.FileName).Name), "", MessageBoxButtons.OK, MessageBoxIcon.Error);
-                        return;
-                    }
-                    //MessageBox.Show(string.Format("Successfully opened file: '{0}'", new FileInfo(ScracthPadLoader.FileName).Name), "", MessageBoxButtons.OK, MessageBoxIcon.Information);
-                }
-            }
-            catch (Exception ex)
-            {
-                logger.Error.WriteLine("Failed to open file: {0}", ScracthPadLoader.FileName);
-                logger.VerboseError.WriteLine(ex.ToString());
-                MessageBox.Show(string.Format("Failed to open: '{0}'", new FileInfo(ScracthPadLoader.FileName).Name), "", MessageBoxButtons.OK, MessageBoxIcon.Error);
-            }
-
-            txtScratchPad.SelectionStart = 0;
-            txtScratchPad.ScrollToCaret();
-
-        }
 
 
-        private void PerformPostInit()
-        {
-            if (!PostInitDone)
-            {
-                txtScratchPad.Clear();
-                txtScratchPad.Font = new System.Drawing.Font(txtScratchPad.Font, FontStyle.Regular);
-                txtScratchPad.ForeColor = Color.Black;
-                PostInitDone = true;
-            }  
-        }
-        private void txtScratchPad_MouseDown(object sender, MouseEventArgs e)
-        {
-            PerformPostInit();
-        }
 
-        private void txtScratchPad_KeyDown(object sender, KeyEventArgs e)
-        {
-            PerformPostInit();
-        }
 
-        private void mnuItemUndo_Click(object sender, EventArgs e)
-        {
-            PerformPostInit();
-            txtScratchPad.Focus();
-            SendKeys.Send("^Z");
-        }
 
-        private void mnuItemRedo_Click(object sender, EventArgs e)
-        {
-            PerformPostInit();
-            txtScratchPad.Focus();
-            SendKeys.Send("^Y");
-        }
 
-        private void mnuItemClear_Click(object sender, EventArgs e)
-        {
-            txtScratchPad.Clear();
-        }
 
-        private void mnuItemCopy_Click(object sender, EventArgs e)
-        {
-            PerformPostInit();
-            string text = txtScratchPad.Text;
-            text = text.Replace("\n", System.Environment.NewLine);
-            Clipboard.SetText(text);
-        }
 
-        private void mnuItemPaste_Click(object sender, EventArgs e)
-        {
-            PerformPostInit();
-            string text = Clipboard.GetText();
-            txtScratchPad.Text = text;
-        }
 
         private void ScratchPad_FormClosing(object sender, FormClosingEventArgs e)
         {
-            if (txtScratchPad.Text != string.Empty && PostInitDone)
+            //if (txtScratchPad.Text != string.Empty && PostInitDone)
+            //{
+            //    DialogResult result = MessageBox.Show("Would you like to save the ScratchPad data before Closing?", "", MessageBoxButtons.YesNoCancel, MessageBoxIcon.Question, MessageBoxDefaultButton.Button1);
+            //    if (result == DialogResult.Cancel)
+            //    {
+            //        e.Cancel = true;
+            //        return;
+            //    }
+            //    if (result == DialogResult.Yes)
+            //    {
+            //        mnuItemSave.PerformClick();
+            //    }
+            //}
+            for (int i = 0; i < docuemntList.Count; i++)
             {
-                DialogResult result = MessageBox.Show("Would you like to save the ScratchPad data before Closing?", "", MessageBoxButtons.YesNoCancel, MessageBoxIcon.Question, MessageBoxDefaultButton.Button1);
-                if (result == DialogResult.Cancel)
-                {
-                    e.Cancel = true;
-                    return;
-                }
-                if (result == DialogResult.Yes)
-                {
-                    mnuItemSave.PerformClick();
-                }
+                var Document = docuemntList[i];
+                Document.OnDocumentQuit();
             }
         }
 
@@ -261,27 +116,52 @@ namespace RomCheater.ScratchPad
             catch { }
         }
 
-        private void txtScratchPad_LinkClicked(object sender, LinkClickedEventArgs e)
+        private void mnuItemNew_Click(object sender, EventArgs e)
         {
-            //System.Diagnostics.Process.Start(e.LinkText);
-            if (this.plugin != null)
-            {
-                var p = this.plugin.WebBrowserInterface;
-                if (p != null)
-                {
-                    p.Navigate(e.LinkText);
-                }
-                else
-                {
-                    logger.Debug.WriteLine("Could not navigate to url: '{0}'", e.LinkText);
-                    logger.Debug.WriteLine("Could not obtain a handle to the WebBrowser Provider's Interface.");
-                }
-            }
-            else
-            {
-                logger.Debug.WriteLine("Could not navigate to url: '{0}'", e.LinkText);
-                logger.Debug.WriteLine("Loaded plugin is null");
-            }
-        }
+            // create new document
+            int tp_index = this.tb.TabPages.Count;
+            ScratchPadDocument t = new ScratchPadDocument(tp_index);
+            t.DocumentClosing += new BaseEventHandler<ControlClosingEventArgs<int>>(t_DocumentClosing);
+            docuemntList.Add(t);
+            this.tb.TabPages.Add(t.DocumentTab);
+        }
+
+        private void ScratchPad_Load(object sender, EventArgs e)
+        {
+            int tp_index = this.tb.TabPages.Count;
+            ScratchPadDocument t = new ScratchPadDocument(tp_index);
+            t.DocumentClosing += new BaseEventHandler<ControlClosingEventArgs<int>>(t_DocumentClosing);
+            docuemntList.Add(t);
+            this.tb.TabPages.Add(t.DocumentTab);
+        }
+
+        void t_DocumentClosing(ControlClosingEventArgs<int> e)
+        {
+                int index = e.Args;
+                this.docuemntList.RemoveAt(index);
+        }
+
+        //private void txtScratchPad_LinkClicked(object sender, LinkClickedEventArgs e)
+        //{
+        //    //System.Diagnostics.Process.Start(e.LinkText);
+        //    if (this.plugin != null)
+        //    {
+        //        var p = this.plugin.WebBrowserInterface;
+        //        if (p != null)
+        //        {
+        //            p.Navigate(e.LinkText);
+        //        }
+        //        else
+        //        {
+        //            logger.Debug.WriteLine("Could not navigate to url: '{0}'", e.LinkText);
+        //            logger.Debug.WriteLine("Could not obtain a handle to the WebBrowser Provider's Interface.");
+        //        }
+        //    }
+        //    else
+        //    {
+        //        logger.Debug.WriteLine("Could not navigate to url: '{0}'", e.LinkText);
+        //        logger.Debug.WriteLine("Loaded plugin is null");
+        //    }
+        //}
     }
 }