This repository was archived by the owner on Mar 3, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathConfigForm1.cs
More file actions
329 lines (290 loc) · 7.28 KB
/
ConfigForm1.cs
File metadata and controls
329 lines (290 loc) · 7.28 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
/*
* Erstellt mit SharpDevelop.
* Benutzer: rschmidt
* Datum: 11.08.2008
* Zeit: 13:23
*
* Sie können diese Vorlage unter Extras > Optionen > Codeerstellung > Standardheader ändern.
*/
using System;
using System.IO;
using System.Collections;
using System.Drawing;
using System.Windows.Forms;
using System.Xml;
using System.Xml.XPath;
using WLA;
namespace V_Learning_Aid
{
/// <summary>
/// Description of ConfigForm1.
/// </summary>
public partial class ConfigForm1 : Form
{
//public ArrayList items = new ArrayList();
public ItemsList newitems = new ItemsList();
/**
* Constructor
*/
public ConfigForm1()
{
// The InitializeComponent() call is required for Windows Forms designer support.
InitializeComponent();
LoadConfig();
// TODO: Add constructor code after the InitializeComponent() call.
}
/**
* Save config
*/
void SaveConfig ()
{
Settings.setString ("RepeatTimes", repeatTimes.Value.ToString ());
Settings.setString ("RepeatMode", repeatMode.SelectedIndex.ToString ());
if (File.Exists (textBox1.Text)) {
Settings.setString ("Filename", textBox1.Text);
} else {
Settings.setString ("Filename", "");
}
Settings.setString("dumpTooltips", dumpTooltips.Checked.ToString());
Settings.setString("intervalInt", intervalInt.Value.ToString());
Settings.setString("intervalUnit", intervalUnit.SelectedIndex.ToString());
Settings.setString("chanceInt", chanceInt.Value.ToString());
Settings.setString("speakingPauseInt", speakingPauseInt.Value.ToString());
Settings.setString("speakTooltip", speakTooltip.Checked.ToString());
Settings.setString("uniqItems", uniqItems.Checked.ToString());
Settings.setString("rndSeq", rndSeq.Checked.ToString());
Settings.setString("dumpTooltips", dumpTooltips.Checked.ToString());
LoadConfig();
}
/**
* Load config
*/
public void LoadConfig() {
repeatTimes.Value = 999;
repeatMode.SelectedIndex = 0;
textBox1.Text = Settings.getString("Filename", "");
if(textBox1.Text != "" && !File.Exists(textBox1.Text))
{
MessageBox.Show("File "+textBox1.Text+" not found.");
textBox1.Text = "";
openFileDialog1.FileName = "";
}
intervalInt.Value = Settings.getInt("intervalInt", 10);
intervalUnit.SelectedIndex = Settings.getInt("intervalUnit", 0);
chanceInt.Value = Settings.getInt("chanceInt", 100);
speakingPauseInt.Value = Settings.getInt("speakingPauseInt", 10);
speakTooltip.Checked = Settings.getBool("speakTooltip", false);
uniqItems.Checked = Settings.getBool("uniqItems", false);
rndSeq.Checked = Settings.getBool("rndSeq", true);
dumpTooltips.Checked = Settings.getBool("dumpTooltips", false);
// speakingPauseInt nach SpeakTooltip einstellen
SpeakToolTipChanged(this,new System.EventArgs());
RandomModeChanged(this,new System.EventArgs());
this.readFile(textBox1.Text);
// Shuffle
if(rndSeq.Checked && uniqItems.Checked)
{
newitems.Shuffle();
}
}
/**
* Traverse file
*/
void traverseFile(XmlNodeList elements, string question) {
string answer = "";
foreach (XmlElement element in elements) {
if(element.Name == "node") {
if(element.HasChildNodes) {
question = element.GetAttribute("TEXT");
traverseFile(element.ChildNodes,question);
} else {
answer += element.GetAttribute("TEXT")+" ";
}
}
}
if(question != "" && answer != "" && answer != " ") {
Item item = new Item();
item.Set(question,answer);
newitems.Add(item);
}
}
/**
* Read file
*/
void readFile(string filename) {
if(filename == "")
{
return;
}
if(!File.Exists(filename))
{
MessageBox.Show("File "+filename+" not found.");
textBox1.Text = "";
openFileDialog1.FileName = "";
return;
}
newitems.ytems.Clear();
try
{
XmlDocument mm = new XmlDocument();
mm.Load(filename);
traverseFile(mm.SelectNodes("//map/node"),"");
statusLabel.Text = newitems.ytems.Count.ToString()+" item(s) read.";
} catch (Exception ex) {
MessageBox.Show("Error: Could not read file. Original error: " + ex.Message);
textBox1.Text = "";
openFileDialog1.FileName = "";
return;
}
}
/**
* Form load
*/
void ConfigForm1Load(object sender, EventArgs e)
{
}
/**
* Single click
*/
void Button1Click(object sender, EventArgs e)
{
}
/**
* Open file dialog
*/
void OpenFileDialog1FileOk(object sender, System.ComponentModel.CancelEventArgs e)
{
}
/**
* Handler
*/
void Button3Click(object sender, EventArgs e)
{
}
/**
* Handler
*/
void GroupBox1Enter(object sender, EventArgs e)
{
}
/**
* Handler
*/
void Label1Click(object sender, EventArgs e)
{
}
/**
* Handler
*/
void Button2Click(object sender, EventArgs e)
{
}
/**
* Handler
*/
void SpeakToolTipChanged(object sender, EventArgs e)
{
speakingPauseInt.Enabled = speakTooltip.Checked;
dumpTooltips.Enabled = speakTooltip.Checked;
}
/**
* Handler
*/
void RandomModeChanged(object sender, EventArgs e)
{
uniqItems.Enabled = rndSeq.Checked;
if(!uniqItems.Enabled)
{
uniqItems.Checked = true;
}
}
/**
* Select file handler
*/
void SelectFile(object sender, EventArgs e)
{
Stream myStream = null;
OpenFileDialog openFileDialog1 = new OpenFileDialog();
openFileDialog1.InitialDirectory = "Desktop" ;
openFileDialog1.Filter = "All files (*.*)|*.*|mm files (*.mm)|*.mm";
openFileDialog1.FilterIndex = 2 ;
openFileDialog1.RestoreDirectory = true ;
if(openFileDialog1.ShowDialog() == DialogResult.OK)
{
try
{
if ((myStream = openFileDialog1.OpenFile()) != null)
{
using (myStream)
{
textBox1.Text = openFileDialog1.FileName;
}
}
}
catch (Exception ex)
{
MessageBox.Show("Error: Could not read file from disk. Original error: " + ex.Message);
}
}
}
/**
* File tab click
*/
void FileTabClick(object sender, EventArgs e)
{
}
/**
* Dialog OK button click
*/
void dlgOkBtnClick(object sender, EventArgs e)
{
Hide();
SaveConfig();
}
/**
* Dialog Cancel button click
*/
void dlgCancelBtnClick(object sender, EventArgs e)
{
Hide();
LoadConfig();
}
/**
* Interval boundary
*/
void intervalBoundary(object sender, EventArgs e)
{
int i = (int)intervalInt.Value;
int u = (int)intervalUnit.SelectedIndex;
switch(u)
{
case 0:
if(i < 30)
intervalInt.Value = 30;
break;
case 1:
i = i*60;
break;
case 2:
i = i*60*60;
break;
}
}
/**
* Repeat mode changed
*/
void repeatModeChanged(object sender, EventArgs e)
{
repeatTimes.Tag = "Test";
switch(repeatMode.SelectedIndex) {
case 1:
repeatTimes.Enabled = true;
break;
case 0:
default:
repeatTimes.Enabled = false;
break;
}
}
}
}