16 |
|
public ScratchPad() |
17 |
|
{ |
18 |
|
InitializeComponent(); |
19 |
< |
InitScratchPadText(); |
19 |
> |
PerformPreInit(); |
20 |
|
} |
21 |
|
|
22 |
|
|
23 |
< |
private void InitScratchPadText() |
23 |
> |
private void PerformPreInit() |
24 |
|
{ |
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 |
< |
builder.AppendLine(); |
30 |
> |
builder.AppendFormat(System.Environment.NewLine); |
31 |
|
builder.AppendFormat("\tThis is a scratchpad"); |
32 |
< |
builder.AppendLine(); |
32 |
> |
builder.AppendFormat(System.Environment.NewLine); |
33 |
|
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 |
+ |
|
39 |
+ |
private void PerformSaveOperation() |
40 |
+ |
{ |
41 |
+ |
} |
42 |
+ |
|
43 |
|
private void mnuItemSave_Click(object sender, EventArgs e) |
44 |
|
{ |
45 |
+ |
PerformPostInit(); |
46 |
|
DialogResult result = ScracthPadSaver.ShowDialog(); |
47 |
|
if (result != DialogResult.OK) { return; } |
48 |
< |
using (FileStream fs = new FileStream(ScracthPadLoader.FileName, FileMode.OpenOrCreate, FileAccess.Write, FileShare.Read)) |
48 |
> |
using (FileStream fs = new FileStream(ScracthPadSaver.FileName, FileMode.OpenOrCreate, FileAccess.Write, FileShare.Read)) |
49 |
|
{ |
50 |
|
using (StreamWriter sw = new StreamWriter(fs)) |
51 |
|
{ |
58 |
|
|
59 |
|
private void mnuItemOpen_Click(object sender, EventArgs e) |
60 |
|
{ |
61 |
+ |
PerformPostInit(); |
62 |
|
DialogResult result = ScracthPadLoader.ShowDialog(); |
63 |
|
if (result != DialogResult.OK) { return; } |
64 |
|
txtScratchPad.Clear(); |
75 |
|
|
76 |
|
|
77 |
|
private bool InitDone = false; |
78 |
< |
|
79 |
< |
private void txtScratchPad_MouseDown(object sender, MouseEventArgs e) |
78 |
> |
|
79 |
> |
private void PerformPostInit() |
80 |
|
{ |
81 |
|
if (!InitDone) |
82 |
|
{ |
84 |
|
txtScratchPad.Font = new System.Drawing.Font(txtScratchPad.Font, FontStyle.Regular); |
85 |
|
txtScratchPad.ForeColor = Color.Black; |
86 |
|
InitDone = true; |
87 |
< |
} |
87 |
> |
} |
88 |
> |
} |
89 |
> |
private void txtScratchPad_MouseDown(object sender, MouseEventArgs e) |
90 |
> |
{ |
91 |
> |
PerformPostInit(); |
92 |
|
} |
93 |
|
|
94 |
|
private void txtScratchPad_KeyDown(object sender, KeyEventArgs e) |
95 |
|
{ |
96 |
< |
if (!InitDone) |
96 |
> |
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 |
|
{ |
137 |
< |
txtScratchPad.Clear(); |
138 |
< |
txtScratchPad.Font = new System.Drawing.Font(txtScratchPad.Font, FontStyle.Regular); |
139 |
< |
txtScratchPad.ForeColor = Color.Black; |
140 |
< |
InitDone = true; |
141 |
< |
} |
137 |
> |
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 |
> |
} |
149 |
> |
|
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 |
|
} |
160 |
|
} |