-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathCDlgInput.cpp
More file actions
385 lines (359 loc) · 11.7 KB
/
CDlgInput.cpp
File metadata and controls
385 lines (359 loc) · 11.7 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
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
// CDlgInput.cpp: 구현 파일
//
#include "pch.h"
#include "BatchNamer.h"
#include "CDlgInput.h"
#include "afxdialogex.h"
#include "EtcFunctions.h"
// CDlgInput 대화 상자
IMPLEMENT_DYNAMIC(CDlgInput, CDialogEx)
CDlgInput::CDlgInput(CWnd* pParent /*=nullptr*/)
: CDialogEx(IDD_INPUT, pParent)
{
m_nCB = 0;
m_nCommand = 0;
}
CDlgInput::~CDlgInput()
{
}
void CDlgInput::DoDataExchange(CDataExchange* pDX)
{
CDialogEx::DoDataExchange(pDX);
//{{AFX_DATA_MAP(CDlgInput)
DDX_Control(pDX, IDC_CB_INPUT, m_cb);
//}}AFX_DATA_MAP
}
BEGIN_MESSAGE_MAP(CDlgInput, CDialogEx)
//{{AFX_MSG_MAP(CDlgInput)
ON_CBN_SELCHANGE(IDC_CB_INPUT, OnSelchangeCbInput)
//}}AFX_MSG_MAP
END_MESSAGE_MAP()
// CDlgInput 메시지 처리기
BOOL CDlgInput::OnInitDialog()
{
CDialogEx::OnInitDialog();
SetWindowText(m_strTitle);
if (m_aInput.GetSize() > 0)
{
int nItem;
for (int i = 0; i < m_aInput.GetSize(); i++)
{
InputItem& item = m_aInput[i];
nItem = m_cb.AddString(item.m_strItemName);
m_cb.SetItemData(nItem, (DWORD_PTR)&item);
}
m_cb.SetCurSel(m_nCB);
OnSelchangeCbInput();
}
else return FALSE;
if (m_strReturn1.IsEmpty() == FALSE) SetDlgItemText(IDC_EDIT_1, m_strReturn1);
if (m_strReturn2.IsEmpty() == FALSE) SetDlgItemText(IDC_EDIT_2, m_strReturn2);
return TRUE; // return TRUE unless you set the focus to a control
// EXCEPTION: OCX Property Pages should return FALSE
}
void CDlgInput::SetInputItem(InputItem* pItem)
{
BOOL bShow1 = !(pItem->m_strLabel1.IsEmpty());
BOOL bShow2 = !(pItem->m_strLabel2.IsEmpty());
SetDlgItemText(IDC_STATIC_1, pItem->m_strLabel1);
SetDlgItemText(IDC_STATIC_2, pItem->m_strLabel2);
GetDlgItem(IDC_STATIC_1)->ShowWindow(bShow1 ? SW_SHOW : SW_HIDE);
GetDlgItem(IDC_EDIT_1)->ShowWindow(bShow1 ? SW_SHOW : SW_HIDE);
GetDlgItem(IDC_STATIC_2)->ShowWindow(bShow2 ? SW_SHOW : SW_HIDE);
GetDlgItem(IDC_EDIT_2)->ShowWindow(bShow2 ? SW_SHOW : SW_HIDE);
HWND h1 = GetDlgItem(IDC_EDIT_1)->GetSafeHwnd();
HWND h2 = GetDlgItem(IDC_EDIT_2)->GetSafeHwnd();
SetWindowLong(h1, GWL_STYLE, pItem->m_bIsNumber1
? (GetWindowLong(h1, GWL_STYLE) | ES_NUMBER) : (GetWindowLong(h1, GWL_STYLE) & ~ES_NUMBER));
SetWindowLong(h2, GWL_STYLE, pItem->m_bIsNumber2
? (GetWindowLong(h2, GWL_STYLE) | ES_NUMBER) : (GetWindowLong(h2, GWL_STYLE) & ~ES_NUMBER));
SetDlgItemText(IDC_EDIT_1, L"");
SetDlgItemText(IDC_EDIT_2, L"");
}
BOOL CheckInvalidCharForFile(CString str)
{
if (str.Find(_T('\\')) != -1) return TRUE;
if (str.Find(_T('\"')) != -1) return TRUE;
if (str.Find(_T('/')) != -1) return TRUE;
if (str.Find(_T('|')) != -1) return TRUE;
if (str.Find(_T('<')) != -1) return TRUE;
if (str.Find(_T('>')) != -1) return TRUE;
if (str.Find(_T(':')) != -1) return TRUE;
if (str.Find(_T('?')) != -1) return TRUE;
if (str.Find(_T('*')) != -1) return TRUE;
return FALSE;
}
void CDlgInput::OnOK()
{
if (GetDlgItem(IDC_EDIT_1)->IsWindowVisible()) GetDlgItemText(IDC_EDIT_1, m_strReturn1);
else m_strReturn1.Empty();
if (GetDlgItem(IDC_EDIT_2)->IsWindowVisible()) GetDlgItemText(IDC_EDIT_2, m_strReturn2);
else m_strReturn2.Empty();
//파일 이름에 맞지 않는 글자(\, /, | ,<. >, :, ", ?, *) 를 미리 체크
if (CheckInvalidCharForFile(m_strReturn1) || CheckInvalidCharForFile(m_strReturn2))
{
//APP()->ShowMsg(IDSTR(IDS_INVALID_CHAR), IDSTR(IDS_MSG_ERROR));
AfxMessageBox(IDSTR(IDS_INVALID_CHAR));
return;
}
m_nCB = m_cb.GetCurSel();
CDialogEx::OnOK();
}
void CDlgInput::OnCancel()
{
// TODO: Add extra cleanup here
CDialogEx::OnCancel();
}
void CDlgInput::InitValue(int nSubCommand, CString str1, CString str2)
{
if (nSubCommand != 0)
{
for (int i = 0; i < m_aInput.GetSize(); i++)
{
if (m_aInput[i].m_nSubCommand == nSubCommand)
{
m_nCB = i;
break;
}
}
}
m_strReturn1 = str1;
m_strReturn2 = str2;
}
void CDlgInput::AddOption(InputItem* pItem)
{
if (pItem == NULL) return;
m_aInput.Add(*pItem);
}
void CDlgInput::OnSelchangeCbInput()
{
int nSel = m_cb.GetCurSel();
if (nSel < 0 || nSel >= m_aInput.GetSize()) return;
InputItem* pItem = (InputItem*)m_cb.GetItemData(nSel);
SetInputItem(pItem);
}
int CDlgInput::GetSubCommand()
{
return m_aInput[m_nCB].m_nSubCommand;
}
void CDlgInput::InitInputByCommand(int nCommand)
{
m_nCommand = nCommand;
m_strTitle = IDSTR(nCommand);
InputItem item;
switch (nCommand)
{
case IDS_TB_01: //Replace
item.m_strItemName = IDSTR(IDS_REPLACESTRING);
item.m_nSubCommand = IDS_REPLACESTRING;
item.m_strLabel1 = IDSTR(IDS_REPLACEOLD);
item.m_strLabel2 = IDSTR(IDS_REPLACENEW);
m_aInput.Add(item);
break;
case IDS_TB_02: //Add Front
case IDS_TB_03: //Add End
item.m_strItemName = IDSTR(IDS_ADDSTRING);
item.m_nSubCommand = IDS_ADDSTRING;
item.m_strLabel1 = IDSTR(IDS_STRINGTOADD);
m_aInput.Add(item);
item.Clear();
item.m_strItemName = IDSTR(IDS_ADDPARENT);
item.m_nSubCommand = IDS_ADDPARENT;
item.m_strLabel1 = IDSTR(IDS_ADDPREFIX);
item.m_strLabel2 = IDSTR(IDS_ADDSUFFIX);
m_aInput.Add(item);
item.Clear();
item.m_strItemName = IDSTR(IDS_ADDDATECREATE);
item.m_nSubCommand = IDS_ADDDATECREATE;
item.m_strLabel1 = IDSTR(IDS_ADDPREFIX);
item.m_strLabel2 = IDSTR(IDS_ADDSUFFIX);
m_aInput.Add(item);
item.Clear();
item.m_strItemName = IDSTR(IDS_ADDDATEMODIFY);
item.m_nSubCommand = IDS_ADDDATEMODIFY;
item.m_strLabel1 = IDSTR(IDS_ADDPREFIX);
item.m_strLabel2 = IDSTR(IDS_ADDSUFFIX);
m_aInput.Add(item);
item.Clear();
item.m_strItemName = IDSTR(IDS_ADDTIMECREATE);
item.m_nSubCommand = IDS_ADDTIMECREATE;
item.m_strLabel1 = IDSTR(IDS_ADDPREFIX);
item.m_strLabel2 = IDSTR(IDS_ADDSUFFIX);
m_aInput.Add(item);
item.Clear();
item.m_strItemName = IDSTR(IDS_ADDTIMEMODIFY);
item.m_nSubCommand = IDS_ADDTIMEMODIFY;
item.m_strLabel1 = IDSTR(IDS_ADDPREFIX);
item.m_strLabel2 = IDSTR(IDS_ADDSUFFIX);
m_aInput.Add(item);
break;
case IDS_TB_05:
item.m_strItemName = IDSTR(IDS_DELPOS_FRONT);
item.m_nSubCommand = IDS_DELPOS_FRONT;
item.m_bIsNumber1 = TRUE;
item.m_bIsNumber2 = TRUE;
item.m_strLabel1 = IDSTR(IDS_POS_1);
item.m_strLabel2 = IDSTR(IDS_POS_2);
m_aInput.Add(item);
item.Clear();
item.m_strItemName = IDSTR(IDS_DELPOS_REAR);
item.m_nSubCommand = IDS_DELPOS_REAR;
item.m_bIsNumber1 = TRUE;
item.m_strLabel1 = IDSTR(IDS_POS_1_REAR);
m_aInput.Add(item);
item.Clear();
item.m_strItemName = IDSTR(IDS_REMOVEBYBRACKET); //_T("지정된 문자로 묶인 부분을 삭제합니다.")
item.m_nSubCommand = IDS_REMOVEBYBRACKET;
item.m_strLabel1 = IDSTR(IDS_BRACKET1); // _T("시작문자")
item.m_strLabel2 = IDSTR(IDS_BRACKET2); // _T("끝문자")
m_aInput.Add(item);
break;
case IDS_TB_08:
item.m_strItemName = IDSTR(IDS_DIGITBACK); //"맨 뒤쪽 숫자의 앞에 0을 추가해서 자릿수를 맞춥니다."
item.m_nSubCommand = IDS_DIGITBACK;
item.m_bIsNumber1 = TRUE;
item.m_strLabel1 = IDSTR(IDS_DIGITCOUNT); //_T("자릿수")
m_aInput.Add(item);
item.Clear();
item.m_strItemName = IDSTR(IDS_DIGITFRONT); //"맨 앞쪽 숫자의 앞에 0을 추가해서 자릿수를 맞춥니다."
item.m_nSubCommand = IDS_DIGITFRONT;
item.m_bIsNumber1 = TRUE;
item.m_strLabel1 = IDSTR(IDS_DIGITCOUNT); //_T("자릿수")
m_aInput.Add(item);
break;
case IDS_TB_09:
item.m_strItemName = IDSTR(IDS_ADDNUM_ALL_BACK); //"모든 이름 뒤에 목록 순서대로 번호를 붙입니다."
item.m_nSubCommand = IDS_ADDNUM_ALL_BACK;
item.m_bIsNumber1 = TRUE;
item.m_strLabel1 = IDSTR(IDS_DIGITCOUNT); //_T("자릿수")
item.m_bIsNumber2 = TRUE;
item.m_strLabel2 = IDSTR(IDS_STARTNUMBER); //_T("시작값")
m_aInput.Add(item);
item.Clear();
item.m_strItemName = IDSTR(IDS_ADDNUM_ALL_FRONT); //"모든 이름 앞에 목록 순서대로 번호를 붙입니다."
item.m_nSubCommand = IDS_ADDNUM_ALL_FRONT;
item.m_bIsNumber1 = TRUE;
item.m_strLabel1 = IDSTR(IDS_DIGITCOUNT); //_T("자릿수")
item.m_bIsNumber2 = TRUE;
item.m_strLabel2 = IDSTR(IDS_STARTNUMBER); //_T("시작값")
m_aInput.Add(item);
item.Clear();
item.m_strItemName = IDSTR(IDS_ADDNUM_BYFOLDER_BACK); //"폴더별로 이름 뒤에 목록 순서대로 번호를 붙입니다."
item.m_nSubCommand = IDS_ADDNUM_BYFOLDER_BACK;
item.m_bIsNumber1 = TRUE;
item.m_strLabel1 = IDSTR(IDS_DIGITCOUNT); //_T("자릿수")
item.m_bIsNumber2 = TRUE;
item.m_strLabel2 = IDSTR(IDS_STARTNUMBER); //_T("시작값")
m_aInput.Add(item);
item.Clear();
item.m_strItemName = IDSTR(IDS_ADDNUM_BYFOLDER_FRONT); //"폴더별로 이름 앞에 목록 순서대로 번호를 붙입니다."
item.m_nSubCommand = IDS_ADDNUM_BYFOLDER_FRONT;
item.m_bIsNumber1 = TRUE;
item.m_strLabel1 = IDSTR(IDS_DIGITCOUNT); //_T("자릿수")
item.m_bIsNumber2 = TRUE;
item.m_strLabel2 = IDSTR(IDS_STARTNUMBER); //_T("시작값")
m_aInput.Add(item);
break;
case IDS_TB_13: // Manual Change
item.m_strItemName = IDSTR(IDS_MANUAL_CHANGE);
item.m_nSubCommand = IDS_MANUAL_CHANGE;
item.m_strLabel1 = IDSTR(IDS_COL_NEWNAME);
m_aInput.Add(item);
break;
case IDS_TB_18: // Add Extension
item.m_strItemName = IDSTR(IDS_EXT_APPEND); //"확장자를 추가합니다."
item.m_nSubCommand = IDS_EXT_APPEND;
item.m_strLabel1 = IDSTR(IDS_EXT_TOADD); //_T("추가할 확장자")
m_aInput.Add(item);
break;
case IDS_TB_19: // Replac Extension
item.m_strItemName = IDSTR(IDS_EXT_REPLACE); //"확장자를 변경합니다."
item.m_nSubCommand = IDS_EXT_REPLACE;
item.m_strLabel1 = IDSTR(IDS_EXT_OLD); //_T("원래 확장자")
item.m_strLabel2 = IDSTR(IDS_EXT_NEW); //_T("바뀔 확장자")
m_aInput.Add(item);
break;
case IDS_PRESET_NAME:
item.m_strItemName = IDSTR(IDS_PRESET_NAME_DESC);
item.m_nSubCommand = IDS_PRESET_NAME_DESC;
item.m_strLabel1 = IDSTR(IDS_PRESET_NAME); //_T("원래 확장자")
m_aInput.Add(item);
break;
}
}
BOOL CDlgInput::VerifyReturnValue()
{
int nCommand = m_nCommand;
int nSubCommand = GetSubCommand();
switch (nCommand)
{
case IDS_TB_01: //Replace
if (m_strReturn1.IsEmpty()) return FALSE;
break;
case IDS_TB_02: //Add Front
case IDS_TB_03: //Add End
if (nSubCommand == IDS_ADDSTRING) { if (m_strReturn1.IsEmpty()) return FALSE;}
break;
case IDS_TB_05:
if (nSubCommand == IDS_DELPOS_FRONT || nSubCommand == IDS_DELPOS_REAR)
{
int nStart = _ttoi(m_strReturn1);
int nEnd = _ttoi(m_strReturn2);
if (nStart == 0 && nEnd == 0) return FALSE;
if (nEnd > 0 && nStart > nEnd)
{
AfxMessageBox(IDSTR(IDS_MSG_INVALIDPOS));
return FALSE;
}
}
else if (nSubCommand == IDS_REMOVEBYBRACKET)
{
if (m_strReturn1.IsEmpty() || m_strReturn2.IsEmpty())
{
AfxMessageBox(IDSTR(IDS_MSG_BRACKETINVALID)); //_T("시작/끝 문자가 정확하게 지정되지 않았습니다.")
return FALSE;
}
if (m_strReturn1.GetLength() > 1 || m_strReturn2.GetLength() > 1)
{
AfxMessageBox(IDSTR(IDS_MSG_BRACKETLEN)); //(_T("구분자 길이가 한 글자가 아닙니다."));
return FALSE;
}
}
break;
case IDS_TB_08:
if (nSubCommand == IDS_DIGITBACK || nSubCommand == IDS_DIGITFRONT)
{
int nDigit = _ttoi(m_strReturn1);
if (nDigit < 0 || nDigit > 10)
{
AfxMessageBox(IDSTR(IDS_MSG_INVALIDDIGIT)); //_T("자릿수 입력이 잘못되었습니다."));
return FALSE;
}
}
break;
case IDS_TB_09:
if (nSubCommand == IDS_ADDNUM_ALL_BACK || nSubCommand == IDS_ADDNUM_ALL_FRONT ||
nSubCommand == IDS_ADDNUM_BYFOLDER_BACK || nSubCommand == IDS_ADDNUM_BYFOLDER_FRONT )
{
int nDigit = _ttoi(m_strReturn1);
if (nDigit < 0 || nDigit > 10)
{
AfxMessageBox(IDSTR(IDS_MSG_INVALIDDIGIT));
return FALSE;
}
}
break;
case IDS_TB_13: // Manual Change
break;
case IDS_TB_18: // Add Extension
if (m_strReturn1.IsEmpty()) return FALSE;
break;
case IDS_TB_19: // Replace Extension
if (m_strReturn2.IsEmpty()) return FALSE;
break;
case IDS_PRESET_NAME: // Add Extension
if (m_strReturn1.IsEmpty()) return FALSE;
break;
}
return TRUE;
}