/[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 683 - (hide annotations) (download)
Mon Jun 17 08:33:06 2013 UTC (7 years, 10 months ago) by william
File size: 5275 byte(s)

1 william 674 using System;
2     using System.Collections.Generic;
3     using System.ComponentModel;
4     using System.Data;
5     using System.Drawing;
6     using System.Linq;
7     using System.Text;
8     using System.Windows.Forms;
9     using WeifenLuo.WinFormsUI.Docking;
10 william 676 using System.IO;
11 william 674
12     namespace RomCheater.PluginFramework.Core
13     {
14     public partial class ScratchPad : DockContent
15     {
16 william 683
17     private UserControlPlugin plugin;
18     public ScratchPad(UserControlPlugin plugin)
19 william 674 {
20 william 683 this.plugin = plugin;
21     InitializeComponent();
22     this.PerformPreInit();
23 william 674 }
24 william 676
25    
26 william 678 private void PerformPreInit()
27 william 676 {
28     txtScratchPad.Font = new System.Drawing.Font(txtScratchPad.Font, FontStyle.Italic);
29     txtScratchPad.ForeColor = SystemColors.GrayText;
30     StringBuilder builder = new StringBuilder();
31     txtScratchPad.Clear();
32    
33 william 678 builder.AppendFormat(System.Environment.NewLine);
34 william 676 builder.AppendFormat("\tThis is a scratchpad");
35 william 678 builder.AppendFormat(System.Environment.NewLine);
36 william 676 builder.AppendFormat("\tYou can type anything in here, and save it for later or load an existing file.");
37    
38     txtScratchPad.AppendText(builder.ToString());
39     }
40    
41 william 678
42     private void PerformSaveOperation()
43     {
44     }
45    
46 william 676 private void mnuItemSave_Click(object sender, EventArgs e)
47     {
48 william 678 PerformPostInit();
49 william 676 DialogResult result = ScracthPadSaver.ShowDialog();
50     if (result != DialogResult.OK) { return; }
51 william 678 using (FileStream fs = new FileStream(ScracthPadSaver.FileName, FileMode.OpenOrCreate, FileAccess.Write, FileShare.Read))
52 william 676 {
53     using (StreamWriter sw = new StreamWriter(fs))
54     {
55     sw.Write(txtScratchPad.Text);
56     sw.Flush();
57     sw.Close();
58     }
59     }
60     }
61    
62     private void mnuItemOpen_Click(object sender, EventArgs e)
63     {
64 william 678 PerformPostInit();
65 william 676 DialogResult result = ScracthPadLoader.ShowDialog();
66     if (result != DialogResult.OK) { return; }
67     txtScratchPad.Clear();
68    
69     using (FileStream fs = new FileStream(ScracthPadLoader.FileName, FileMode.Open, FileAccess.Read, FileShare.Read))
70     {
71     using (StreamReader sr = new StreamReader(fs))
72     {
73     txtScratchPad.AppendText(sr.ReadToEnd());
74     }
75     }
76     }
77    
78    
79    
80     private bool InitDone = false;
81 william 678
82     private void PerformPostInit()
83 william 676 {
84     if (!InitDone)
85     {
86     txtScratchPad.Clear();
87     txtScratchPad.Font = new System.Drawing.Font(txtScratchPad.Font, FontStyle.Regular);
88     txtScratchPad.ForeColor = Color.Black;
89     InitDone = true;
90 william 678 }
91 william 676 }
92 william 678 private void txtScratchPad_MouseDown(object sender, MouseEventArgs e)
93     {
94     PerformPostInit();
95     }
96 william 676
97     private void txtScratchPad_KeyDown(object sender, KeyEventArgs e)
98     {
99 william 678 PerformPostInit();
100     }
101    
102     private void mnuItemUndo_Click(object sender, EventArgs e)
103     {
104     PerformPostInit();
105     txtScratchPad.Focus();
106     SendKeys.Send("^Z");
107     }
108    
109     private void mnuItemRedo_Click(object sender, EventArgs e)
110     {
111     PerformPostInit();
112     txtScratchPad.Focus();
113     SendKeys.Send("^Y");
114     }
115    
116     private void mnuItemClear_Click(object sender, EventArgs e)
117     {
118     txtScratchPad.Clear();
119     }
120    
121     private void mnuItemCopy_Click(object sender, EventArgs e)
122     {
123     PerformPostInit();
124     string text = txtScratchPad.Text;
125     text = text.Replace("\n", System.Environment.NewLine);
126     Clipboard.SetText(text);
127     }
128    
129     private void mnuItemPaste_Click(object sender, EventArgs e)
130     {
131     PerformPostInit();
132     string text = Clipboard.GetText();
133     txtScratchPad.Text = text;
134     }
135    
136     private void ScratchPad_FormClosing(object sender, FormClosingEventArgs e)
137     {
138     if (txtScratchPad.Text != string.Empty)
139 william 676 {
140 william 678 DialogResult result = MessageBox.Show("Would you like to save the ScratchPad data before Closing?", "", MessageBoxButtons.YesNoCancel, MessageBoxIcon.Question, MessageBoxDefaultButton.Button1);
141     if (result == DialogResult.Cancel)
142     {
143     e.Cancel = true;
144     return;
145     }
146     if (result == DialogResult.Yes)
147     {
148     mnuItemSave.PerformClick();
149     }
150     }
151 william 676 }
152 william 678
153     private void ScratchPad_Deactivate<T>(object sender, T e) where T: EventArgs
154     {
155     try
156     {
157     FormClosingEventArgs args = (e as FormClosingEventArgs);
158     ScratchPad_FormClosing(sender, args);
159     }
160     catch { }
161     }
162 william 674 }
163     }

  ViewVC Help
Powered by ViewVC 1.1.22