ViewVC Help
View File | Revision Log | Show Annotations | Download File | View Changeset | Root Listing
root/RomCheater/trunk/RomCheater.PluginFramework/Core/ScratchPad.cs
Revision: 684
Committed: Mon Jun 17 08:52:54 2013 UTC (10 years, 5 months ago) by william
File size: 7083 byte(s)
Log Message:

File Contents

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