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

# User Rev Content
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 674
26     namespace RomCheater.PluginFramework.Core
27     {
28     public partial class ScratchPad : DockContent
29     {
30 william 683
31     private UserControlPlugin plugin;
32     public ScratchPad(UserControlPlugin plugin)
33 william 674 {
34 william 683 this.plugin = plugin;
35 william 684 InitPluginFramework();
36 william 683 InitializeComponent();
37     this.PerformPreInit();
38 william 674 }
39 william 676
40    
41 william 684 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 william 678 private void PerformPreInit()
63 william 676 {
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 william 678 builder.AppendFormat(System.Environment.NewLine);
70 william 676 builder.AppendFormat("\tThis is a scratchpad");
71 william 678 builder.AppendFormat(System.Environment.NewLine);
72 william 676 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 william 678
78     private void PerformSaveOperation()
79     {
80     }
81    
82 william 676 private void mnuItemSave_Click(object sender, EventArgs e)
83     {
84 william 678 PerformPostInit();
85 william 676 DialogResult result = ScracthPadSaver.ShowDialog();
86     if (result != DialogResult.OK) { return; }
87 william 678 using (FileStream fs = new FileStream(ScracthPadSaver.FileName, FileMode.OpenOrCreate, FileAccess.Write, FileShare.Read))
88 william 676 {
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 william 678 PerformPostInit();
101 william 676 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 william 678
118     private void PerformPostInit()
119 william 676 {
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 william 678 }
127 william 676 }
128 william 678 private void txtScratchPad_MouseDown(object sender, MouseEventArgs e)
129     {
130     PerformPostInit();
131     }
132 william 676
133     private void txtScratchPad_KeyDown(object sender, KeyEventArgs e)
134     {
135 william 678 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 william 676 {
176 william 678 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 william 676 }
188 william 678
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 william 674 }
199     }