/[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 686 - (show annotations) (download)
Mon Jun 17 09:31:52 2013 UTC (7 years, 10 months ago) by william
File size: 6900 byte(s)
+ massive move of source files

1 #region Logging Defines
2 // include this any class or method that required logging, and comment-out what is not needed
3 #define LOGGING_ENABLED // this is only valid within the logger class
4 #region Enabled logging levels
5 #define LOGGING_ENABLE_INFO
6 #define LOGGING_ENABLE_WARN
7 #define LOGGING_ENABLE_DEBUG
8 #define LOGGING_ENABLE_VERBOSEDEBUG
9 #define LOGGING_ENABLE_ERROR
10 #define LOGGING_ENABLE_VERBOSEERROR
11 #define LOGGING_ENABLE_PROFILER
12 #endregion
13 #endregion
14 using System;
15 using System.Collections.Generic;
16 using System.ComponentModel;
17 using System.Data;
18 using System.Drawing;
19 using System.Linq;
20 using System.Text;
21 using System.Windows.Forms;
22 using WeifenLuo.WinFormsUI.Docking;
23 using System.IO;
24 using RomCheater.Logging;
25 using RomCheater.Core;
26
27 namespace RomCheater.PluginFramework.Core
28 {
29 public partial class ScratchPad : DockContent
30 {
31
32 private UserControlPlugin plugin;
33 public ScratchPad(UserControlPlugin plugin)
34 {
35 this.plugin = plugin;
36 InitPluginFramework();
37 InitializeComponent();
38 this.PerformPreInit();
39 }
40
41
42 private void InitPluginFramework()
43 {
44 if (this.plugin == null) { return; }
45 this.plugin.OnSelectedProcessChanged += new BaseEventHandler<ProcessChangedEventArgs>(plugin_OnSelectedProcessChanged);
46 this.plugin.OnSelectedConfigChanged += new BaseEventHandler<ConfigChangedEventArgs>(plugin_OnSelectedConfigChanged);
47 this.plugin.OnPEDataUpdated += new BaseEventHandler<PEViewerDataUpdatedEventArgs>(plugin_OnPEDataUpdated);
48 }
49 void plugin_OnPEDataUpdated(PEViewerDataUpdatedEventArgs e)
50 {
51 logger.Warn.WriteLine("plugin_OnPEDataUpdated::has not been implemented!");
52 }
53 void plugin_OnSelectedConfigChanged(ConfigChangedEventArgs e)
54 {
55 logger.Warn.WriteLine("plugin_OnSelectedConfigChanged::has not been implemented!");
56 }
57 void plugin_OnSelectedProcessChanged(ProcessChangedEventArgs e)
58 {
59 logger.Warn.WriteLine("plugin_OnSelectedProcessChanged::has not been implemented!");
60 }
61
62
63 private void PerformPreInit()
64 {
65 txtScratchPad.Font = new System.Drawing.Font(txtScratchPad.Font, FontStyle.Italic);
66 txtScratchPad.ForeColor = SystemColors.GrayText;
67 StringBuilder builder = new StringBuilder();
68 txtScratchPad.Clear();
69
70 builder.AppendFormat(System.Environment.NewLine);
71 builder.AppendFormat("\tThis is a scratchpad");
72 builder.AppendFormat(System.Environment.NewLine);
73 builder.AppendFormat("\tYou can type anything in here, and save it for later or load an existing file.");
74
75 txtScratchPad.AppendText(builder.ToString());
76 }
77
78
79 private void PerformSaveOperation()
80 {
81 }
82
83 private void mnuItemSave_Click(object sender, EventArgs e)
84 {
85 PerformPostInit();
86 DialogResult result = ScracthPadSaver.ShowDialog();
87 if (result != DialogResult.OK) { return; }
88 using (FileStream fs = new FileStream(ScracthPadSaver.FileName, FileMode.OpenOrCreate, FileAccess.Write, FileShare.Read))
89 {
90 using (StreamWriter sw = new StreamWriter(fs))
91 {
92 sw.Write(txtScratchPad.Text);
93 sw.Flush();
94 sw.Close();
95 }
96 }
97 }
98
99 private void mnuItemOpen_Click(object sender, EventArgs e)
100 {
101 PerformPostInit();
102 DialogResult result = ScracthPadLoader.ShowDialog();
103 if (result != DialogResult.OK) { return; }
104 txtScratchPad.Clear();
105
106 using (FileStream fs = new FileStream(ScracthPadLoader.FileName, FileMode.Open, FileAccess.Read, FileShare.Read))
107 {
108 using (StreamReader sr = new StreamReader(fs))
109 {
110 txtScratchPad.AppendText(sr.ReadToEnd());
111 }
112 }
113 }
114
115
116
117 private bool InitDone = false;
118
119 private void PerformPostInit()
120 {
121 if (!InitDone)
122 {
123 txtScratchPad.Clear();
124 txtScratchPad.Font = new System.Drawing.Font(txtScratchPad.Font, FontStyle.Regular);
125 txtScratchPad.ForeColor = Color.Black;
126 InitDone = true;
127 }
128 }
129 private void txtScratchPad_MouseDown(object sender, MouseEventArgs e)
130 {
131 PerformPostInit();
132 }
133
134 private void txtScratchPad_KeyDown(object sender, KeyEventArgs e)
135 {
136 PerformPostInit();
137 }
138
139 private void mnuItemUndo_Click(object sender, EventArgs e)
140 {
141 PerformPostInit();
142 txtScratchPad.Focus();
143 SendKeys.Send("^Z");
144 }
145
146 private void mnuItemRedo_Click(object sender, EventArgs e)
147 {
148 PerformPostInit();
149 txtScratchPad.Focus();
150 SendKeys.Send("^Y");
151 }
152
153 private void mnuItemClear_Click(object sender, EventArgs e)
154 {
155 txtScratchPad.Clear();
156 }
157
158 private void mnuItemCopy_Click(object sender, EventArgs e)
159 {
160 PerformPostInit();
161 string text = txtScratchPad.Text;
162 text = text.Replace("\n", System.Environment.NewLine);
163 Clipboard.SetText(text);
164 }
165
166 private void mnuItemPaste_Click(object sender, EventArgs e)
167 {
168 PerformPostInit();
169 string text = Clipboard.GetText();
170 txtScratchPad.Text = text;
171 }
172
173 private void ScratchPad_FormClosing(object sender, FormClosingEventArgs e)
174 {
175 if (txtScratchPad.Text != string.Empty)
176 {
177 DialogResult result = MessageBox.Show("Would you like to save the ScratchPad data before Closing?", "", MessageBoxButtons.YesNoCancel, MessageBoxIcon.Question, MessageBoxDefaultButton.Button1);
178 if (result == DialogResult.Cancel)
179 {
180 e.Cancel = true;
181 return;
182 }
183 if (result == DialogResult.Yes)
184 {
185 mnuItemSave.PerformClick();
186 }
187 }
188 }
189
190 private void ScratchPad_Deactivate<T>(object sender, T e) where T: EventArgs
191 {
192 try
193 {
194 FormClosingEventArgs args = (e as FormClosingEventArgs);
195 ScratchPad_FormClosing(sender, args);
196 }
197 catch { }
198 }
199 }
200 }

  ViewVC Help
Powered by ViewVC 1.1.22