/[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 05:41:23	674
+++ trunk/RomCheater.PluginFramework/Core/ScratchPad.cs	2013/06/17 07:01:41	678
@@ -7,6 +7,7 @@
 using System.Text;
 using System.Windows.Forms;
 using WeifenLuo.WinFormsUI.Docking;
+using System.IO;
 
 namespace RomCheater.PluginFramework.Core
 {
@@ -15,6 +16,145 @@
         public ScratchPad()
         {
             InitializeComponent();
+            PerformPreInit();
+        }
+
+
+        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; }
+            using (FileStream fs = new FileStream(ScracthPadSaver.FileName, FileMode.OpenOrCreate, FileAccess.Write, FileShare.Read))
+            {
+                using (StreamWriter sw = new StreamWriter(fs))
+                {
+                    sw.Write(txtScratchPad.Text);
+                    sw.Flush();
+                    sw.Close();
+                }
+            }
+        }
+
+        private void mnuItemOpen_Click(object sender, EventArgs e)
+        {
+            PerformPostInit();
+            DialogResult result = ScracthPadLoader.ShowDialog();
+            if (result != DialogResult.OK) { return; }
+            txtScratchPad.Clear();
+
+            using (FileStream fs = new FileStream(ScracthPadLoader.FileName, FileMode.Open, FileAccess.Read, FileShare.Read))
+            {
+                using (StreamReader sr = new StreamReader(fs))
+                {
+                    txtScratchPad.AppendText(sr.ReadToEnd());
+                }
+            }
+        }
+
+
+
+        private bool InitDone = false;
+
+        private void PerformPostInit()
+        {
+            if (!InitDone)
+            {
+                txtScratchPad.Clear();
+                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)
+        {
+            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)
+            {
+                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