-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathForm1.cs
187 lines (167 loc) · 5.63 KB
/
Form1.cs
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
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using lrx;
namespace lrxw
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
importRadio.Tag = OperationMode.Import;
alignRadio.Tag = OperationMode.Align;
exportRadio.Tag = OperationMode.Export;
locResFormat.SelectedIndex = 0; // XXX
Application.Idle += Application_Idle;
}
private void ImpossibleCondition()
{
// XXX
}
private void Application_Idle(object sender, EventArgs e)
{
// Update per Mode UI components.
var key = Mode.ToString()[0]; // XXX
foreach (Control c in Controls)
{
var tag = c.Tag as string;
if (tag != null)
{
c.Enabled = tag.IndexOf(key) >= 0;
}
}
// Check whether all mandatory parameters are specified.
TextBox[] mandatory = null;
switch (Mode)
{
case OperationMode.Import:
mandatory = new[] { sourceLocRes, xliffPath, sourceLang, targetLang };
break;
case OperationMode.Align:
mandatory = new[] { sourceLocRes, targetLocRes, xliffPath, sourceLang, targetLang };
break;
case OperationMode.Export:
mandatory = new[] { targetLocRes, xliffPath };
break;
default:
ImpossibleCondition();
break;
}
runButton.Enabled = mandatory?.All(t => !string.IsNullOrWhiteSpace(t.Text)) == true;
}
private enum OperationMode
{
Import,
Align,
Export,
}
private OperationMode Mode = OperationMode.Import;
private void operation_CheckedChanged(object sender, EventArgs e)
{
var radio = sender as RadioButton;
if (radio?.Checked == true)
{
Mode = (OperationMode)radio.Tag;
}
}
private void sourceButton_Click(object sender, EventArgs e)
{
switch (Mode)
{
case OperationMode.Import:
case OperationMode.Align:
handleFileDialog(sourceOpenDialog, sourceLocRes);
break;
default:
ImpossibleCondition();
break;
}
}
private void targetButton_Click(object sender, EventArgs e)
{
switch (Mode)
{
case OperationMode.Align:
handleFileDialog(targetOpenDialog, targetLocRes);
break;
case OperationMode.Export:
handleFileDialog(targetSaveDialog, targetLocRes);
break;
default:
ImpossibleCondition();
break;
}
}
private void xliffButton_Click(object sender, EventArgs e)
{
switch (Mode)
{
case OperationMode.Import:
case OperationMode.Align:
handleFileDialog(xliffSaveDialog, xliffPath);
break;
case OperationMode.Export:
handleFileDialog(xliffOpenDialog, xliffPath);
break;
default:
ImpossibleCondition();
break;
}
}
private void handleFileDialog(FileDialog dialog, TextBox text)
{
dialog.FileName = text.Text;
if (dialog.ShowDialog(this) == DialogResult.OK)
{
text.Text = dialog.FileName;
}
}
private async void runButton_Click(object sender, EventArgs e)
{
var source_locres = sourceLocRes.Text;
var target_locres = targetLocRes.Text;
var xliff_path = xliffPath.Text;
var slang = sourceLang.Text;
var tlang = targetLang.Text;
LocResFormat format = LocResFormat.Auto;
switch (locResFormat.SelectedIndex)
{
case 0: format = LocResFormat.Auto; break;
case 1: format = LocResFormat.Old; break;
case 2: format = LocResFormat.New; break;
default:
ImpossibleCondition();
break;
}
UseWaitCursor = true;
Cursor.Current = Cursors.WaitCursor;
await Task.Run(() =>
{
switch (Mode)
{
case OperationMode.Import:
Converter.Import(source_locres, xliff_path, slang, tlang);
break;
case OperationMode.Align:
Converter.Align(source_locres, target_locres, xliff_path, slang, tlang);
break;
case OperationMode.Export:
Converter.Export(xliff_path, target_locres, format);
break;
default:
ImpossibleCondition();
break;
}
});
UseWaitCursor = false;
Cursor.Current = Cursors.Default;
}
}
}