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

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

Parent Directory Parent Directory | Revision Log Revision Log


Revision 683 - (show annotations) (download)
Mon Jun 17 08:33:06 2013 UTC (7 years, 4 months ago) by william
File size: 5275 byte(s)

1 using System;
2 using System.Collections.Generic;
3 using System.ComponentModel;
4 using System.Data;
5 using System.Drawing;
6 using System.Linq;
7 using System.Text;
8 using System.Windows.Forms;
9 using WeifenLuo.WinFormsUI.Docking;
10 using System.IO;
11
12 namespace RomCheater.PluginFramework.Core
13 {
14 public partial class ScratchPad : DockContent
15 {
16
17 private UserControlPlugin plugin;
18 public ScratchPad(UserControlPlugin plugin)
19 {
20 this.plugin = plugin;
21 InitializeComponent();
22 this.PerformPreInit();
23 }
24
25
26 private void PerformPreInit()
27 {
28 txtScratchPad.Font = new System.Drawing.Font(txtScratchPad.Font, FontStyle.Italic);
29 txtScratchPad.ForeColor = SystemColors.GrayText;
30 StringBuilder builder = new StringBuilder();
31 txtScratchPad.Clear();
32
33 builder.AppendFormat(System.Environment.NewLine);
34 builder.AppendFormat("\tThis is a scratchpad");
35 builder.AppendFormat(System.Environment.NewLine);
36 builder.AppendFormat("\tYou can type anything in here, and save it for later or load an existing file.");
37
38 txtScratchPad.AppendText(builder.ToString());
39 }
40
41
42 private void PerformSaveOperation()
43 {
44 }
45
46 private void mnuItemSave_Click(object sender, EventArgs e)
47 {
48 PerformPostInit();
49 DialogResult result = ScracthPadSaver.ShowDialog();
50 if (result != DialogResult.OK) { return; }
51 using (FileStream fs = new FileStream(ScracthPadSaver.FileName, FileMode.OpenOrCreate, FileAccess.Write, FileShare.Read))
52 {
53 using (StreamWriter sw = new StreamWriter(fs))
54 {
55 sw.Write(txtScratchPad.Text);
56 sw.Flush();
57 sw.Close();
58 }
59 }
60 }
61
62 private void mnuItemOpen_Click(object sender, EventArgs e)
63 {
64 PerformPostInit();
65 DialogResult result = ScracthPadLoader.ShowDialog();
66 if (result != DialogResult.OK) { return; }
67 txtScratchPad.Clear();
68
69 using (FileStream fs = new FileStream(ScracthPadLoader.FileName, FileMode.Open, FileAccess.Read, FileShare.Read))
70 {
71 using (StreamReader sr = new StreamReader(fs))
72 {
73 txtScratchPad.AppendText(sr.ReadToEnd());
74 }
75 }
76 }
77
78
79
80 private bool InitDone = false;
81
82 private void PerformPostInit()
83 {
84 if (!InitDone)
85 {
86 txtScratchPad.Clear();
87 txtScratchPad.Font = new System.Drawing.Font(txtScratchPad.Font, FontStyle.Regular);
88 txtScratchPad.ForeColor = Color.Black;
89 InitDone = true;
90 }
91 }
92 private void txtScratchPad_MouseDown(object sender, MouseEventArgs e)
93 {
94 PerformPostInit();
95 }
96
97 private void txtScratchPad_KeyDown(object sender, KeyEventArgs e)
98 {
99 PerformPostInit();
100 }
101
102 private void mnuItemUndo_Click(object sender, EventArgs e)
103 {
104 PerformPostInit();
105 txtScratchPad.Focus();
106 SendKeys.Send("^Z");
107 }
108
109 private void mnuItemRedo_Click(object sender, EventArgs e)
110 {
111 PerformPostInit();
112 txtScratchPad.Focus();
113 SendKeys.Send("^Y");
114 }
115
116 private void mnuItemClear_Click(object sender, EventArgs e)
117 {
118 txtScratchPad.Clear();
119 }
120
121 private void mnuItemCopy_Click(object sender, EventArgs e)
122 {
123 PerformPostInit();
124 string text = txtScratchPad.Text;
125 text = text.Replace("\n", System.Environment.NewLine);
126 Clipboard.SetText(text);
127 }
128
129 private void mnuItemPaste_Click(object sender, EventArgs e)
130 {
131 PerformPostInit();
132 string text = Clipboard.GetText();
133 txtScratchPad.Text = text;
134 }
135
136 private void ScratchPad_FormClosing(object sender, FormClosingEventArgs e)
137 {
138 if (txtScratchPad.Text != string.Empty)
139 {
140 DialogResult result = MessageBox.Show("Would you like to save the ScratchPad data before Closing?", "", MessageBoxButtons.YesNoCancel, MessageBoxIcon.Question, MessageBoxDefaultButton.Button1);
141 if (result == DialogResult.Cancel)
142 {
143 e.Cancel = true;
144 return;
145 }
146 if (result == DialogResult.Yes)
147 {
148 mnuItemSave.PerformClick();
149 }
150 }
151 }
152
153 private void ScratchPad_Deactivate<T>(object sender, T e) where T: EventArgs
154 {
155 try
156 {
157 FormClosingEventArgs args = (e as FormClosingEventArgs);
158 ScratchPad_FormClosing(sender, args);
159 }
160 catch { }
161 }
162 }
163 }

  ViewVC Help
Powered by ViewVC 1.1.22