/[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 678 - (hide annotations) (download)
Mon Jun 17 07:01:41 2013 UTC (7 years, 10 months ago) by william
File size: 5154 byte(s)
+ add OnActived/OnDeactivated support to notify all DockedContent that the form is closing

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

  ViewVC Help
Powered by ViewVC 1.1.22