/[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 691 - (show annotations) (download)
Mon Jun 17 10:07:40 2013 UTC (7 years, 5 months ago) by william
File size: 7305 byte(s)
+ comment-out the not implemeted messages ...

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 RaisePluginFrameworkEvents();
49 }
50
51 bool EventsRaised = false;
52 private void RaisePluginFrameworkEvents()
53 {
54
55 if (this.plugin == null) { EventsRaised = true; return; }
56 if (!EventsRaised)
57 {
58 this.plugin.RaisePluginFrameworkEvents();
59 EventsRaised = true;
60 }
61 }
62
63 void plugin_OnPEDataUpdated(PEViewerDataUpdatedEventArgs e)
64 {
65 //logger.Warn.WriteLine("plugin_OnPEDataUpdated::has not been implemented!");
66 }
67 void plugin_OnSelectedConfigChanged(ConfigChangedEventArgs e)
68 {
69 //logger.Warn.WriteLine("plugin_OnSelectedConfigChanged::has not been implemented!");
70 }
71 void plugin_OnSelectedProcessChanged(ProcessChangedEventArgs e)
72 {
73 //logger.Warn.WriteLine("plugin_OnSelectedProcessChanged::has not been implemented!");
74 }
75
76
77 private void PerformPreInit()
78 {
79 txtScratchPad.Font = new System.Drawing.Font(txtScratchPad.Font, FontStyle.Italic);
80 txtScratchPad.ForeColor = SystemColors.GrayText;
81 StringBuilder builder = new StringBuilder();
82 txtScratchPad.Clear();
83
84 builder.AppendFormat(System.Environment.NewLine);
85 builder.AppendFormat("\tThis is a scratchpad");
86 builder.AppendFormat(System.Environment.NewLine);
87 builder.AppendFormat("\tYou can type anything in here, and save it for later or load an existing file.");
88
89 txtScratchPad.AppendText(builder.ToString());
90 }
91
92
93 private void PerformSaveOperation()
94 {
95 }
96
97 private void mnuItemSave_Click(object sender, EventArgs e)
98 {
99 PerformPostInit();
100 DialogResult result = ScracthPadSaver.ShowDialog();
101 if (result != DialogResult.OK) { return; }
102 using (FileStream fs = new FileStream(ScracthPadSaver.FileName, FileMode.OpenOrCreate, FileAccess.Write, FileShare.Read))
103 {
104 using (StreamWriter sw = new StreamWriter(fs))
105 {
106 sw.Write(txtScratchPad.Text);
107 sw.Flush();
108 sw.Close();
109 }
110 }
111 }
112
113 private void mnuItemOpen_Click(object sender, EventArgs e)
114 {
115 PerformPostInit();
116 DialogResult result = ScracthPadLoader.ShowDialog();
117 if (result != DialogResult.OK) { return; }
118 txtScratchPad.Clear();
119
120 using (FileStream fs = new FileStream(ScracthPadLoader.FileName, FileMode.Open, FileAccess.Read, FileShare.Read))
121 {
122 using (StreamReader sr = new StreamReader(fs))
123 {
124 txtScratchPad.AppendText(sr.ReadToEnd());
125 }
126 }
127 }
128
129
130
131 private bool InitDone = false;
132
133 private void PerformPostInit()
134 {
135 if (!InitDone)
136 {
137 txtScratchPad.Clear();
138 txtScratchPad.Font = new System.Drawing.Font(txtScratchPad.Font, FontStyle.Regular);
139 txtScratchPad.ForeColor = Color.Black;
140 InitDone = true;
141 }
142 }
143 private void txtScratchPad_MouseDown(object sender, MouseEventArgs e)
144 {
145 PerformPostInit();
146 }
147
148 private void txtScratchPad_KeyDown(object sender, KeyEventArgs e)
149 {
150 PerformPostInit();
151 }
152
153 private void mnuItemUndo_Click(object sender, EventArgs e)
154 {
155 PerformPostInit();
156 txtScratchPad.Focus();
157 SendKeys.Send("^Z");
158 }
159
160 private void mnuItemRedo_Click(object sender, EventArgs e)
161 {
162 PerformPostInit();
163 txtScratchPad.Focus();
164 SendKeys.Send("^Y");
165 }
166
167 private void mnuItemClear_Click(object sender, EventArgs e)
168 {
169 txtScratchPad.Clear();
170 }
171
172 private void mnuItemCopy_Click(object sender, EventArgs e)
173 {
174 PerformPostInit();
175 string text = txtScratchPad.Text;
176 text = text.Replace("\n", System.Environment.NewLine);
177 Clipboard.SetText(text);
178 }
179
180 private void mnuItemPaste_Click(object sender, EventArgs e)
181 {
182 PerformPostInit();
183 string text = Clipboard.GetText();
184 txtScratchPad.Text = text;
185 }
186
187 private void ScratchPad_FormClosing(object sender, FormClosingEventArgs e)
188 {
189 if (txtScratchPad.Text != string.Empty)
190 {
191 DialogResult result = MessageBox.Show("Would you like to save the ScratchPad data before Closing?", "", MessageBoxButtons.YesNoCancel, MessageBoxIcon.Question, MessageBoxDefaultButton.Button1);
192 if (result == DialogResult.Cancel)
193 {
194 e.Cancel = true;
195 return;
196 }
197 if (result == DialogResult.Yes)
198 {
199 mnuItemSave.PerformClick();
200 }
201 }
202 }
203
204 private void ScratchPad_Deactivate<T>(object sender, T e) where T: EventArgs
205 {
206 try
207 {
208 FormClosingEventArgs args = (e as FormClosingEventArgs);
209 ScratchPad_FormClosing(sender, args);
210 }
211 catch { }
212 }
213 }
214 }

  ViewVC Help
Powered by ViewVC 1.1.22