-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathDlgOptions.cpp
More file actions
357 lines (293 loc) · 9.27 KB
/
DlgOptions.cpp
File metadata and controls
357 lines (293 loc) · 9.27 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
/*
* International Chemical Identifier (InChI)
* Version 1
* Software version 1.07
* April 30, 2024
*
* The InChI library and programs are free software developed under the
* auspices of the International Union of Pure and Applied Chemistry (IUPAC).
* Originally developed at NIST.
* Modifications and additions by IUPAC and the InChI Trust.
* Some portions of code were developed/changed by external contributors
* (either contractor or volunteer) which are listed in the file
* 'External-contributors' included in this distribution.
*
* IUPAC/InChI-Trust Licence No.1.0 for the
* International Chemical Identifier (InChI)
* Copyright (C) IUPAC and InChI Trust
*
* This library is free software; you can redistribute it and/or modify it
* under the terms of the IUPAC/InChI Trust InChI Licence No.1.0,
* or any later version.
*
* Please note that this library is distributed WITHOUT ANY WARRANTIES
* whatsoever, whether expressed or implied.
* See the IUPAC/InChI-Trust InChI Licence No.1.0 for more details.
*
* You should have received a copy of the IUPAC/InChI Trust InChI
* Licence No. 1.0 with this library; if not, please e-mail:
*
* info@inchi-trust.org
*
*/
// DlgOptions.cpp : implementation file
//
#include "stdafx.h"
#include "io.h"
#include "wIChI.h"
#include "DlgOptions.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
/////////////////////////////////////////////////////////////////////////////
static BOOL HasTrailingSlash( const CString& str )
{
int iLength = str.GetLength() - 1;
if( str[iLength] == _T('\\') )
return TRUE;
return FALSE;
}
/////////////////////////////////////////////////////////////////////////////
static BOOL IsDirectory( CString& str )
{
//if it has a trailing slash...remove it...
if( HasTrailingSlash(str) )
str = str.Left(str.GetLength() - 1);
// If the last character in the string is a : then
// we are a root directory. CFile::GetStatus uses
// FindFirstFile to verify our existence, and fails
// on C:\ so we need to add some wildcards
if(str.Right(1) == _T(":"))
{
str += _T("\\*.*");
}
//Get the status of the file...return TRUE if a directory...
CFileStatus fs;
if( CFile::GetStatus( str, fs ) && (fs.m_attribute & CFile::directory))
{
// GetStatus returns FALSE if it can't find the file
// If it returns True, and it is a filename,
// go to that directory instead of returning false
return TRUE;
}
//otherwise return FALSE
return FALSE;
}
/////////////////////////////////////////////////////////////////////////////
void InchiBrowseFileEdit::OnBrowse()
{
CString str,strOrig;
//SECFileSystem fs;
if( m_dwDialogStyle & OFN_NOCHANGEDIR ) {
// strOrig = fs.GetCurrentDirectory();
GetCurrentDirectory( MAX_PATH, strOrig.GetBufferSetLength(MAX_PATH));
strOrig.ReleaseBuffer();
}
if (m_strInitialFile.IsEmpty()) {
// Edit control containing patname
//GetWindowText(str);
pWndParent->GetDlgItem(IDC_EDIT_INPUT_FILE)->GetWindowText(str);
} else {
str = m_strInitialFile; //they specified a file...assume valid...
}
//Lets use an instance of SECFileSystem to check the validity of the text
BOOL bClearStr = FALSE;
//if string is empty...do nothing
if( !str.IsEmpty() )
{
//check to see if it is a directory and not a file
if( IsDirectory(str) )
/*{
//never can be too careful
if( fs.DirectoryExists(str) )
{
fs.ChangeDirectory(str);
bClearStr = TRUE;
}
}*/
{
if ( 0 == _access(str,00) ) {
DWORD dw = GetFileAttributes(str);
if ( dw != INVALID_FILE_ATTRIBUTES ) {
if ( dw & FILE_ATTRIBUTE_DIRECTORY ) {
BOOL ret = SetCurrentDirectory(str);
if ( ret ) {
bClearStr = TRUE;
}
} else
if ( dw &(FILE_ATTRIBUTE_READONLY | FILE_ATTRIBUTE_ARCHIVE |
FILE_ATTRIBUTE_NORMAL) ) {
// it is a file
} else {
bClearStr = TRUE;
}
}
}
}
else //not a directory...
{
//if it is a file...we don't want to clear the string...
//but if it isn't a file and it isn't a directory..probably bogus...clear it
/*if( !fs.FileExists(str) )
bClearStr = TRUE;*/
if ( 0 == _access(str,00) ) {
DWORD dw = GetFileAttributes(str);
if ( dw == INVALID_FILE_ATTRIBUTES ) {
bClearStr = TRUE;
}
} else {
bClearStr = TRUE;
}
}
}
if( bClearStr )
str = _T("");
if ( str.IsEmpty() && !strOrig.IsEmpty() && IsDirectory(strOrig) ) {
str = strOrig + "\\"; // 2024-08-30 DCh
}
//CFileDialog Dialog(m_bOpenDialog, m_strExt, str, m_dwDialogStyle, m_strFilters, this);
/*Dialog.m_ofn.lpstrTitle = GetBrowseCaption();
if (Dialog.DoModal() == IDOK)
SetWindowText(Dialog.GetPathName());
if( m_dwDialogStyle & OFN_NOCHANGEDIR )
fs.ChangeDirectory(strOrig);*/
CString fileName = str;
BOOL ret = MyDoPromptFileName(fileName, AFX_IDS_OPENFILE/*nIDSTitle*/,
1 /*bOpenFileDialog*/, NULL);
if ( ret ) {
pWndParent->GetDlgItem(IDC_EDIT_INPUT_FILE)->SetWindowText(fileName);
if( m_dwDialogStyle & OFN_NOCHANGEDIR ) {
SetCurrentDirectory( strOrig);
}
}
}
/////////////////////////////////////////////////////////////////////////////
// DlgOptions dialog
/////////////////////////////////////////////////////////////////////////////
DlgOptions::DlgOptions(CWnd* pParent /*=NULL*/)
: CDialog(DlgOptions::IDD, pParent)
{
m_bMerge = FALSE;
//{{AFX_DATA_INIT(DlgOptions)
m_InputFile = _T("");
m_Header = _T("");
//}}AFX_DATA_INIT
}
/////////////////////////////////////////////////////////////////////////////
void DDV_EmptyString(CDataExchange* pDX, CString& Str, const CString& Message)
{
if( pDX->m_bSaveAndValidate && Str.IsEmpty())
{
::AfxMessageBox(Message);
pDX->Fail();
}
}
/////////////////////////////////////////////////////////////////////////////
void DlgOptions::DoDataExchange(CDataExchange* pDX)
{
CDialog::DoDataExchange(pDX);
//{{AFX_DATA_MAP(DlgOptions)
DDX_Text(pDX, IDC_EDIT_INPUT_FILE, m_InputFile);
DDV_EmptyString(pDX, m_InputFile, "Enter input file");
DDX_Text(pDX, IDC_EDIT_SDFID, m_Header);
//}}AFX_DATA_MAP
if( !pDX->m_bSaveAndValidate )
{
m_OldInputFile = m_InputFile;
}
else
{
if( m_OldInputFile.CompareNoCase(m_InputFile) != 0 )
{
m_bMerge = FALSE;
}
}
}
BEGIN_MESSAGE_MAP(DlgOptions, CDialog)
//{{AFX_MSG_MAP(DlgOptions)
ON_BN_CLICKED(IDC_BUTTON_ADV, OnButtonAdv)
//}}AFX_MSG_MAP
ON_BN_CLICKED(IDC_BUTTON2, &DlgOptions::OnBnClickedButton2)
ON_EN_CHANGE(IDC_EDIT_INPUT_FILE, &DlgOptions::OnEnChangeEditInputFile)
END_MESSAGE_MAP()
/////////////////////////////////////////////////////////////////////////////
// DlgOptions message handlers
/////////////////////////////////////////////////////////////////////////////
BOOL DlgOptions::OnInitDialog()
{
CDialog::OnInitDialog();
// TODO: Add extra initialization here
MYFTYPES mf[] = {
{"*.mol", "MolFile (*.mol)"},
{"*.sdf", "SDFile (*.sdf)"},
// {"*.cml", "CMLFile (*.cml)"},
{"*.*", "All Files (*.*)"},
};
int num_mf = sizeof(mf)/sizeof(mf[0]);
m_editFileInput.Initialize(IDC_EDIT_INPUT_FILE, this);
//m_editFileInput.SetFileFilters("MolFile (*.mol)|*.mol|SDFile (*.sdf)|*.sdf|All Files (*.*)|*.*||");
m_editFileInput.SetFileFilters(mf, num_mf);
m_editFileInput.ModifyDialogStyle(0,OFN_FILEMUSTEXIST|OFN_PATHMUSTEXIST);
return TRUE; // return TRUE unless you set the focus to a control
// EXCEPTION: OCX Property Pages should return FALSE
}
/////////////////////////////////////////////////////////////////////////////
void DlgOptions::OnButtonAdv()
{
// TODO: Add your control notification handler code here
m_Dlg.DoModal();
}
/////////////////////////////////////////////////////////////////////////////
void DlgOptions::GetOptions(CStringArray& Opt, int *Write2Disk ) const
{
CString str;
char ext[_MAX_EXT];
_splitpath( (LPCSTR)m_InputFile, NULL, NULL, NULL, ext );
_strupr(ext);
if( strcmp(ext,".CML") == 0 )
{
Opt.Add("/CML");
}
else
{
if( !m_Header.IsEmpty() )
{
str= "/SDF:";
str += m_Header;
Opt.Add(str);
}
else
Opt.Add("/MOL");
}
if( m_bMerge )
Opt.Add("/MERGE");
m_Dlg.GetOptions(Opt, Write2Disk );
}
void DlgOptions::OnBnClickedButton2()
{
// TODO: Add your control notification handler code here
m_editFileInput.OnBrowse();
}
void DlgOptions::OnEnChangeEditInputFile()
{
// TODO: Add your control notification handler code here
}
/********************************************************************************/
BOOL InchiBrowseFileEdit::MyDoPromptFileName(CString& fileName, UINT nIDSTitle,
BOOL bOpenFileDialog, CDocTemplate* pTemplate)
{
CFileDialog dlgFile(bOpenFileDialog);
CString title;
VERIFY(title.LoadString(nIDSTitle));
dlgFile.m_ofn.Flags |= lFlags;
dlgFile.m_ofn.lpstrFilter = m_strFilters;
dlgFile.m_ofn.hwndOwner = hWndParent;
dlgFile.m_ofn.lpstrTitle = title;
dlgFile.m_ofn.lpstrFile = fileName.GetBuffer(_MAX_PATH);
//m_pMyFileOpenDlg = &dlgFile;
BOOL bRet = (dlgFile.DoModal() == (IDOK ? TRUE : FALSE));
fileName.ReleaseBuffer();
return bRet;
}