/[RomCheater]/trunk/RomCheater.ScratchPad/ScratchPad.cs
ViewVC logotype

Diff of /trunk/RomCheater.ScratchPad/ScratchPad.cs

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

--- trunk/RomCheater.ScratchPad/ScratchPad.cs	2013/06/20 20:25:55	762
+++ trunk/RomCheater.ScratchPad/ScratchPad.cs	2013/06/20 21:34:48	769
@@ -29,15 +29,14 @@
 {
     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,179 +75,37 @@
         }
 
 
-        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();                
             }
+
         }
 
         private void ScratchPad_Deactivate<T>(object sender, T e) where T: EventArgs
@@ -261,27 +118,36 @@
             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);
+            docuemntList.Add(t);
+            this.tb.TabPages.Add(t.DocumentTab);
+        }
+
+        //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");
+        //    }
+        //}
     }
 }

 

  ViewVC Help
Powered by ViewVC 1.1.22