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

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

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

--- trunk/RomCheater.PluginFramework/Core/ScratchPad.cs	2013/06/17 06:53:33	677
+++ trunk/RomCheater.PluginFramework/Core/ScratchPad.cs	2013/06/17 07:01:41	678
@@ -16,30 +16,36 @@
         public ScratchPad()
         {
             InitializeComponent();
-            InitScratchPadText();
+            PerformPreInit();
         }
 
 
-        private void InitScratchPadText()
+        private void PerformPreInit()
         {
             txtScratchPad.Font = new System.Drawing.Font(txtScratchPad.Font, FontStyle.Italic);
             txtScratchPad.ForeColor = SystemColors.GrayText;
             StringBuilder builder = new StringBuilder();
             txtScratchPad.Clear();
 
-            builder.AppendLine();
+            builder.AppendFormat(System.Environment.NewLine);
             builder.AppendFormat("\tThis is a scratchpad");
-            builder.AppendLine();
+            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; }
-            using (FileStream fs = new FileStream(ScracthPadLoader.FileName, FileMode.OpenOrCreate, FileAccess.Write, FileShare.Read))
+            using (FileStream fs = new FileStream(ScracthPadSaver.FileName, FileMode.OpenOrCreate, FileAccess.Write, FileShare.Read))
             {
                 using (StreamWriter sw = new StreamWriter(fs))
                 {
@@ -52,6 +58,7 @@
 
         private void mnuItemOpen_Click(object sender, EventArgs e)
         {
+            PerformPostInit();
             DialogResult result = ScracthPadLoader.ShowDialog();
             if (result != DialogResult.OK) { return; }
             txtScratchPad.Clear();
@@ -68,8 +75,8 @@
 
 
         private bool InitDone = false;
-        
-        private void txtScratchPad_MouseDown(object sender, MouseEventArgs e)
+
+        private void PerformPostInit()
         {
             if (!InitDone)
             {
@@ -77,18 +84,77 @@
                 txtScratchPad.Font = new System.Drawing.Font(txtScratchPad.Font, FontStyle.Regular);
                 txtScratchPad.ForeColor = Color.Black;
                 InitDone = true;
-            }   
+            }  
+        }
+        private void txtScratchPad_MouseDown(object sender, MouseEventArgs e)
+        {
+            PerformPostInit();
         }
 
         private void txtScratchPad_KeyDown(object sender, KeyEventArgs e)
         {
-            if (!InitDone)
+            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)
             {
-                txtScratchPad.Clear();
-                txtScratchPad.Font = new System.Drawing.Font(txtScratchPad.Font, FontStyle.Regular);
-                txtScratchPad.ForeColor = Color.Black;
-                InitDone = true;
-            }  
+                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();
+                }
+            }
+        }
+
+        private void ScratchPad_Deactivate<T>(object sender, T e) where T: EventArgs
+        {
+            try
+            {
+                FormClosingEventArgs args = (e as FormClosingEventArgs);
+                ScratchPad_FormClosing(sender, args);
+            }
+            catch { }
         }
     }
 }

 

  ViewVC Help
Powered by ViewVC 1.1.22