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

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

Parent Directory Parent Directory | Revision Log Revision Log


Revision 689 - (hide annotations) (download)
Mon Jun 17 10:02:53 2013 UTC (7 years, 10 months ago) by william
File size: 7351 byte(s)
+ add support for plugin framework events to be fired, the first time
* Process change events would not fire, until another process was selected (ignoreing the already selected process at startup)
** same goes for the other events that rely on a process being passed in

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

  ViewVC Help
Powered by ViewVC 1.1.22