/[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 686 - (hide 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 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 684 }
49 william 686 void plugin_OnPEDataUpdated(PEViewerDataUpdatedEventArgs e)
50 william 684 {
51     logger.Warn.WriteLine("plugin_OnPEDataUpdated::has not been implemented!");
52     }
53 william 686 void plugin_OnSelectedConfigChanged(ConfigChangedEventArgs e)
54 william 684 {
55     logger.Warn.WriteLine("plugin_OnSelectedConfigChanged::has not been implemented!");
56     }
57 william 686 void plugin_OnSelectedProcessChanged(ProcessChangedEventArgs e)
58 william 684 {
59     logger.Warn.WriteLine("plugin_OnSelectedProcessChanged::has not been implemented!");
60     }
61    
62    
63 william 678 private void PerformPreInit()
64 william 676 {
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 william 678 builder.AppendFormat(System.Environment.NewLine);
71 william 676 builder.AppendFormat("\tThis is a scratchpad");
72 william 678 builder.AppendFormat(System.Environment.NewLine);
73 william 676 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 william 678
79     private void PerformSaveOperation()
80     {
81     }
82    
83 william 676 private void mnuItemSave_Click(object sender, EventArgs e)
84     {
85 william 678 PerformPostInit();
86 william 676 DialogResult result = ScracthPadSaver.ShowDialog();
87     if (result != DialogResult.OK) { return; }
88 william 678 using (FileStream fs = new FileStream(ScracthPadSaver.FileName, FileMode.OpenOrCreate, FileAccess.Write, FileShare.Read))
89 william 676 {
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 william 678 PerformPostInit();
102 william 676 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 william 678
119     private void PerformPostInit()
120 william 676 {
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 william 678 }
128 william 676 }
129 william 678 private void txtScratchPad_MouseDown(object sender, MouseEventArgs e)
130     {
131     PerformPostInit();
132     }
133 william 676
134     private void txtScratchPad_KeyDown(object sender, KeyEventArgs e)
135     {
136 william 678 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 william 676 {
177 william 678 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 william 676 }
189 william 678
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 william 674 }
200     }

  ViewVC Help
Powered by ViewVC 1.1.22