using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Drawing; using System.Linq; using System.Text; using System.Windows.Forms; using WeifenLuo.WinFormsUI.Docking; using System.IO; namespace RomCheater.PluginFramework.Core { public partial class ScratchPad : DockContent { 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(object sender, T e) where T: EventArgs { try { FormClosingEventArgs args = (e as FormClosingEventArgs); ScratchPad_FormClosing(sender, args); } catch { } } } }