-
Notifications
You must be signed in to change notification settings - Fork 9
Expand file tree
/
Copy pathImportDialog.cs
More file actions
290 lines (257 loc) · 9.64 KB
/
ImportDialog.cs
File metadata and controls
290 lines (257 loc) · 9.64 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
using System;
using System.Collections.Generic;
using System.IO;
using System.Windows.Forms;
namespace SlbViewer
{
public partial class ImportDialog : Form
{
public List<string> SelectedFiles { get; private set; } = new List<string>();
public bool CreateNewLibrary { get; private set; }
public string NewLibraryPath { get; private set; } = "";
private ListBox listFiles;
private Button btnAddFiles;
private Button btnRemove;
private Button btnClear;
private RadioButton rbAddToExisting;
private RadioButton rbCreateNew;
private TextBox txtNewLibPath;
private Button btnBrowseNewLib;
private Button btnOK;
private Button btnCancel;
private Label lblFiles;
private Label lblMode;
private Label lblCount;
private string currentSlbPath = "";
public ImportDialog(string currentLibraryPath)
{
currentSlbPath = currentLibraryPath;
InitializeComponent();
InitializeControls();
}
private void InitializeComponent()
{
this.Text = "导入幻灯片";
this.Size = new System.Drawing.Size(600, 500);
this.FormBorderStyle = FormBorderStyle.FixedDialog;
this.MaximizeBox = false;
this.MinimizeBox = false;
this.StartPosition = FormStartPosition.CenterParent;
// 文件列表标签
lblFiles = new Label
{
Text = "要导入的文件 (SLD/图像):",
Location = new System.Drawing.Point(20, 20),
Size = new System.Drawing.Size(200, 20)
};
// 文件列表
listFiles = new ListBox
{
Location = new System.Drawing.Point(20, 45),
Size = new System.Drawing.Size(450, 200),
SelectionMode = SelectionMode.MultiExtended
};
// 添加文件按钮
btnAddFiles = new Button
{
Text = "添加文件...",
Location = new System.Drawing.Point(480, 45),
Size = new System.Drawing.Size(100, 30)
};
btnAddFiles.Click += BtnAddFiles_Click;
// 移除按钮
btnRemove = new Button
{
Text = "移除选中",
Location = new System.Drawing.Point(480, 85),
Size = new System.Drawing.Size(100, 30)
};
btnRemove.Click += BtnRemove_Click;
// 清空按钮
btnClear = new Button
{
Text = "清空列表",
Location = new System.Drawing.Point(480, 125),
Size = new System.Drawing.Size(100, 30)
};
btnClear.Click += BtnClear_Click;
// 文件计数标签
lblCount = new Label
{
Text = "文件数: 0",
Location = new System.Drawing.Point(20, 250),
Size = new System.Drawing.Size(200, 20)
};
// 导入模式标签
lblMode = new Label
{
Text = "导入模式:",
Location = new System.Drawing.Point(20, 285),
Size = new System.Drawing.Size(100, 20)
};
// 添加到现有库选项
rbAddToExisting = new RadioButton
{
Text = "添加到当前库",
Location = new System.Drawing.Point(20, 310),
Size = new System.Drawing.Size(200, 25),
Checked = true
};
rbAddToExisting.CheckedChanged += RbMode_CheckedChanged;
// 创建新库选项
rbCreateNew = new RadioButton
{
Text = "创建新库",
Location = new System.Drawing.Point(20, 340),
Size = new System.Drawing.Size(120, 25)
};
rbCreateNew.CheckedChanged += RbMode_CheckedChanged;
// 新库路径输入框
txtNewLibPath = new TextBox
{
Location = new System.Drawing.Point(140, 340),
Size = new System.Drawing.Size(330, 25),
Enabled = false
};
// 浏览新库路径按钮
btnBrowseNewLib = new Button
{
Text = "浏览...",
Location = new System.Drawing.Point(480, 338),
Size = new System.Drawing.Size(100, 30),
Enabled = false
};
btnBrowseNewLib.Click += BtnBrowseNewLib_Click;
// 确定按钮
btnOK = new Button
{
Text = "导入",
Location = new System.Drawing.Point(380, 410),
Size = new System.Drawing.Size(90, 35),
DialogResult = DialogResult.OK
};
btnOK.Click += BtnOK_Click;
// 取消按钮
btnCancel = new Button
{
Text = "取消",
Location = new System.Drawing.Point(480, 410),
Size = new System.Drawing.Size(90, 35),
DialogResult = DialogResult.Cancel
};
// 添加控件
this.Controls.AddRange(new Control[] {
lblFiles, listFiles,
btnAddFiles, btnRemove, btnClear, lblCount,
lblMode, rbAddToExisting, rbCreateNew,
txtNewLibPath, btnBrowseNewLib,
btnOK, btnCancel
});
this.AcceptButton = btnOK;
this.CancelButton = btnCancel;
}
private void InitializeControls()
{
// 如果没有当前库,强制创建新库
if (string.IsNullOrEmpty(currentSlbPath))
{
rbCreateNew.Checked = true;
rbAddToExisting.Enabled = false;
}
}
private void BtnAddFiles_Click(object? sender, EventArgs e)
{
using (OpenFileDialog openDialog = new OpenFileDialog())
{
openDialog.Filter = "支持的文件|*.sld;*.bmp;*.png;*.jpg;*.jpeg;*.gif|" +
"AutoCAD 幻灯片 (*.sld)|*.sld|" +
"图像文件 (*.bmp;*.png;*.jpg)|*.bmp;*.png;*.jpg;*.jpeg;*.gif|" +
"所有文件 (*.*)|*.*";
openDialog.Title = "选择 SLD 文件或图像文件";
openDialog.Multiselect = true;
if (openDialog.ShowDialog() == DialogResult.OK)
{
foreach (string file in openDialog.FileNames)
{
if (!listFiles.Items.Contains(file))
{
listFiles.Items.Add(file);
}
}
UpdateFileCount();
}
}
}
private void BtnRemove_Click(object? sender, EventArgs e)
{
if (listFiles.SelectedItems.Count > 0)
{
// 从后往前删除,避免索引变化
for (int i = listFiles.SelectedIndices.Count - 1; i >= 0; i--)
{
listFiles.Items.RemoveAt(listFiles.SelectedIndices[i]);
}
UpdateFileCount();
}
}
private void BtnClear_Click(object? sender, EventArgs e)
{
listFiles.Items.Clear();
UpdateFileCount();
}
private void RbMode_CheckedChanged(object? sender, EventArgs e)
{
bool isCreateNew = rbCreateNew.Checked;
txtNewLibPath.Enabled = isCreateNew;
btnBrowseNewLib.Enabled = isCreateNew;
}
private void BtnBrowseNewLib_Click(object? sender, EventArgs e)
{
using (SaveFileDialog saveDialog = new SaveFileDialog())
{
saveDialog.Filter = "AutoCAD 幻灯片库 (*.slb)|*.slb";
saveDialog.Title = "创建新的幻灯片库";
saveDialog.FileName = "NewLibrary.slb";
if (saveDialog.ShowDialog() == DialogResult.OK)
{
txtNewLibPath.Text = saveDialog.FileName;
}
}
}
private void BtnOK_Click(object? sender, EventArgs e)
{
// 检查是否有文件
if (listFiles.Items.Count == 0)
{
MessageBox.Show("请先添加要导入的 SLD 文件", "提示",
MessageBoxButtons.OK, MessageBoxIcon.Information);
this.DialogResult = DialogResult.None;
return;
}
// 收集文件路径
SelectedFiles.Clear();
foreach (var item in listFiles.Items)
{
SelectedFiles.Add(item.ToString() ?? "");
}
// 确定导入模式
CreateNewLibrary = rbCreateNew.Checked;
if (CreateNewLibrary)
{
// 检查新库路径
if (string.IsNullOrWhiteSpace(txtNewLibPath.Text))
{
MessageBox.Show("请指定新库文件的保存路径", "提示",
MessageBoxButtons.OK, MessageBoxIcon.Information);
this.DialogResult = DialogResult.None;
return;
}
NewLibraryPath = txtNewLibPath.Text;
}
}
private void UpdateFileCount()
{
lblCount.Text = $"文件数: {listFiles.Items.Count}";
}
}
}