root/trunk/NewProjectDlg.cpp

Revision 5, 9.9 kB (checked in by qbert, 6 years ago)

Initial ( and last :( ) commit

Line 
1 // NewProjectDlg.cpp : implementation file
2 //
3
4 #include "stdafx.h"
5 #include "Elephant.h"
6 #include "NewProjectDlg.h"
7
8 #ifdef _DEBUG
9 #define new DEBUG_NEW
10 #undef THIS_FILE
11 static char THIS_FILE[] = __FILE__;
12 #endif
13
14 /////////////////////////////////////////////////////////////////////////////
15 // CNewProjectDlg dialog
16
17
18 CNewProjectDlg::CNewProjectDlg(CWnd* pParent /*=NULL*/)
19     : CXTResizeDialog(CNewProjectDlg::IDD, pParent)
20 {
21     //{{AFX_DATA_INIT(CNewProjectDlg)
22     m_csLocation = _T(Globals::settings->baseSettings->GetCache("m_projectLocation").c_str());
23     m_csProjectDescription = _T("");
24     m_csProjectName = _T("");   
25     m_csFiles = _T("");
26     m_createProjectFolder = TRUE;
27     m_strProjectDir = _T(Globals::settings->baseSettings->GetCache("m_projectLocation").c_str());
28     m_projectTypeCriteria = _T("[ Not Supplied ] Project Type");   
29     m_projectNameCriteria = _T("[ Not Supplied] Project Name");
30     m_criteriaStr = _T("Criteria");
31     //}}AFX_DATA_INIT
32
33
34
35     if ( m_strProjectDir != "" ) m_projectLocationCriteria = _T("[ Supplied ] Project Location");
36     else m_projectLocationCriteria = _T("[ Not Supplied ] Project Location");
37    
38        
39 }
40
41
42 void CNewProjectDlg::DoDataExchange(CDataExchange* pDX)
43 {
44     CXTResizeDialog::DoDataExchange(pDX);
45     //{{AFX_DATA_MAP(CNewProjectDlg)
46     DDX_Control(pDX, IDC_STATIC21, m_criteriaTitle);
47     DDX_Control(pDX, IDC_STATIC5, m_properties);
48     DDX_Control(pDX, IDC_STATIC6, m_static6);
49     DDX_Control(pDX, IDC_EDIT5, m_filesEdit);
50     DDX_Control(pDX, IDC_STATIC4, m_st2);
51     DDX_Control(pDX, IDC_STATIC3, m_s2);
52     DDX_Control(pDX, IDC_STATIC2, m_s1);
53     DDX_Control(pDX, IDC_TREE1, m_options);
54     DDX_Control(pDX, IDC_BUTTON9, m_ok);
55     DDX_Control(pDX, IDC_BUTTON6, m_cancel);
56     DDX_Control(pDX, IDC_BUTTON1, m_browse);
57     DDX_Control(pDX, IDC_EDIT1, m_projectDescription);
58     DDX_Control(pDX, IDC_EDIT7, m_projectLocation);
59     DDX_Control(pDX, IDC_EDIT2, m_projectName);
60     DDX_Text(pDX, IDC_EDIT7, m_csLocation);
61     DDX_Text(pDX, IDC_EDIT1, m_csProjectDescription);
62     DDX_Text(pDX, IDC_EDIT2, m_csProjectName); 
63     DDX_Text(pDX, IDC_EDIT5, m_csFiles);
64     DDX_Check(pDX, IDC_CHECK3, m_createProjectFolder);
65     DDX_Text(pDX, IDC_STATIC7, m_strProjectDir);
66     DDX_Text(pDX, IDC_STATIC9, m_projectTypeCriteria);
67     DDX_Text(pDX, IDC_STATIC8, m_projectLocationCriteria);
68     DDX_Text(pDX, IDC_STATIC10, m_projectNameCriteria);
69     DDX_Text(pDX, IDC_STATIC21, m_criteriaStr);
70     //}}AFX_DATA_MAP
71 }
72
73
74 BEGIN_MESSAGE_MAP(CNewProjectDlg, CXTResizeDialog)
75     //{{AFX_MSG_MAP(CNewProjectDlg)
76     ON_BN_CLICKED(IDC_BUTTON9, OnBrowse)
77     ON_WM_DESTROY()
78     ON_NOTIFY(TVN_SELCHANGED, IDC_TREE1, OnProjectTreeChange)
79     ON_BN_CLICKED(IDC_BUTTON1, OnOk)
80     ON_EN_CHANGE(IDC_EDIT2, OnProjectNameChange)
81     ON_BN_CLICKED(IDC_BUTTON6, OnCancel)
82     ON_BN_CLICKED(IDC_CHECK3, OnProjectNameChange)
83     ON_EN_CHANGE(IDC_EDIT7, OnProjectNameChange)
84    
85     //}}AFX_MSG_MAP
86 END_MESSAGE_MAP()
87
88 /////////////////////////////////////////////////////////////////////////////
89 // CNewProjectDlg message handlers
90
91 BOOL CNewProjectDlg::OnInitDialog()
92 {
93     CXTResizeDialog::OnInitDialog();
94    
95
96     SetupButton(&m_browse);
97     SetupButton(&m_cancel);
98     SetupButton(&m_ok);
99
100 //  SetupTitle(&m_st1);
101     SetupTitle(&m_st2);
102     SetupTitle(&m_static6);
103     SetupTitle(&m_properties);
104     SetupTitle(&m_criteriaTitle);
105 //  SetupTitle(&m_st3 );
106
107     if ( !m_imageList.Create( 16, 16, ILC_COLOR24 | ILC_MASK, 16, 16 ) )
108     {
109         TRACE("Failed to create image list.\n");
110         return -1;
111     }
112     else TRACE("Succeeded creating image list");
113    
114     m_bitmap.LoadBitmap( IDB_BITMAP3 );
115     m_imageList.Add( &m_bitmap, RGB( 0x00,0xff,0x00 ) );
116    
117     m_options.SetImageList(&m_imageList, TVSIL_NORMAL );
118    
119     InitTree();
120     //m_projectLocation.SetText(); 
121     m_projectName.SetText("Project Name");
122
123     // resizing
124     {
125         SetResize(IDC_BUTTON9,SZ_BOTTOM_RIGHT,SZ_BOTTOM_RIGHT);
126         SetResize(IDC_BUTTON6,SZ_BOTTOM_RIGHT,SZ_BOTTOM_RIGHT);
127         SetResize(IDC_BUTTON1,SZ_BOTTOM_RIGHT,SZ_BOTTOM_RIGHT);
128
129         SetResize(IDC_EDIT1,SZ_TOP_RIGHT,SZ_BOTTOM_RIGHT);
130        
131        
132         SetResize(IDC_STATIC1,SZ_TOP_RIGHT,SZ_TOP_RIGHT);
133         SetResize(IDC_STATIC4,SZ_TOP_RIGHT,SZ_TOP_RIGHT);
134        
135
136         SetResize(IDC_STATIC6,SZ_BOTTOM_RIGHT,SZ_BOTTOM_RIGHT);
137         SetResize(IDC_EDIT5,SZ_BOTTOM_RIGHT,SZ_BOTTOM_RIGHT);
138        
139        
140
141         //SetResize(IDC_IMAGE,SZ_TOP_RIGHT,SZ_TOP_RIGHT);
142        
143        
144         SetResize(IDC_STATIC3,SZ_BOTTOM_LEFT,SZ_BOTTOM_LEFT);
145         SetResize(IDC_STATIC5,SZ_BOTTOM_LEFT,SZ_BOTTOM_LEFT);
146         SetResize(IDC_STATIC21,SZ_BOTTOM_LEFT,SZ_BOTTOM_LEFT);
147         SetResize(IDC_STATIC2,SZ_BOTTOM_LEFT,SZ_BOTTOM_LEFT);
148         SetResize(IDC_STATIC7,SZ_BOTTOM_LEFT,SZ_BOTTOM_LEFT);
149
150         //SetResize(IDC_CHECK3,SZ_BOTTOM_LEFT,SZ_BOTTOM_LEFT);
151         //SetResize(IDC_STATIC11,SZ_TOP_RIGHT,SZ_TOP_RIGHT);
152
153
154         SetResize(IDC_RADIO1,SZ_BOTTOM_LEFT,SZ_BOTTOM_LEFT);
155         SetResize(IDC_RADIO2,SZ_BOTTOM_LEFT,SZ_BOTTOM_LEFT);
156
157         SetResize(IDC_EDIT7 ,SZ_BOTTOM_LEFT,SZ_BOTTOM_RIGHT);
158         SetResize(IDC_EDIT2 ,SZ_BOTTOM_LEFT,SZ_BOTTOM_RIGHT);
159
160         //SetResize(IDC_STATIC11 ,SZ_BOTTOM_LEFT,SZ_BOTTOM_RIGHT);
161         SetResize(IDC_STATIC8 ,SZ_BOTTOM_LEFT,SZ_BOTTOM_RIGHT);
162         SetResize(IDC_STATIC9 ,SZ_BOTTOM_LEFT,SZ_BOTTOM_RIGHT);
163         SetResize(IDC_STATIC10,SZ_BOTTOM_LEFT,SZ_BOTTOM_RIGHT);
164        
165        
166        
167
168
169         SetResize(IDC_TREE1,SZ_TOP_LEFT,SZ_BOTTOM_RIGHT);
170            
171         LoadPlacement("CNewProjectDlg");    // TODO: Add your message handler code here
172     }
173
174
175     SetIcon(AfxGetApp()->LoadIcon(IDR_ELEPHANT) ,true);
176
177
178     return TRUE;  // return TRUE unless you set the focus to a control
179                   // EXCEPTION: OCX Property Pages should return FALSE
180 }
181
182 void CNewProjectDlg::OnBrowse()
183 {
184     UpdateData();
185 string dir;
186 if ( GetDirFromCDirDialog(dir,"") ) {
187         m_csLocation = dir.c_str();
188 UpdateData(FALSE);
189 }
190
191    
192 }
193
194 void CNewProjectDlg::OnDestroy()
195 {
196     CXTResizeDialog::OnDestroy();
197    
198 SavePlacement("CNewProjectDlg");    // TODO: Add your message handler code here
199    
200 }
201
202 void CNewProjectDlg::OnProjectTreeChange(NMHDR* pNMHDR, LRESULT* pResult)
203 {
204     UpdateData();
205     NM_TREEVIEW* pNMTreeView = (NM_TREEVIEW*)pNMHDR;
206     // TODO: Add your control notification handler code here
207     CString sel = m_options.GetItemText(pNMTreeView->itemNew.hItem);
208     m_csProjectDescription = DescriptionForProject(sel.GetBuffer(0) ).c_str();
209     m_csFiles = FilesForProject( sel.GetBuffer(0)).c_str();
210
211     if ( m_csProjectDescription != "Project Description" )
212     {
213         m_projectTypeCriteria = "[ Supplied ] Project Type";
214        
215     }
216     else
217     {
218
219         m_projectTypeCriteria = "[ Not Supplied ] Project Type";
220
221     }
222
223
224     UpdateData(FALSE);
225     *pResult = 0;
226 }
227
228 void CNewProjectDlg::OnCancel()
229 {
230     EndDialog(0);   
231 }
232
233 void CNewProjectDlg::OnOk()
234 {
235     UpdateData();
236
237
238     //|| m_csProjectName == "" || GetSelTreeCtrlItem(&m_options) == "" || m_csProjectName == m_projectName.GetText().c_str() )
239     if ( m_csLocation == "" )
240     {
241         ElephantMessageBox("Can you please enter a project location?",this);
242         m_projectLocation.SetFocus();
243         return ;
244
245     }
246     else if ( m_csProjectName == "" || m_csProjectName == m_projectName.GetText().c_str()  )
247     {
248
249         ElephantMessageBox("Can you please enter a name for your project?",this);
250         m_projectName.SetFocus();
251         return;
252
253     }
254     else if ( GetSelTreeCtrlItem(&m_options) == ""  )
255     {
256
257         ElephantMessageBox("Can you please select a project type?",this);
258         m_options.SetFocus();
259         return;
260
261
262     }
263
264
265     else {
266         string path = m_csLocation.GetBuffer(0);
267         if ( path.length())
268         {
269             if ( path[path.length() - 1 ] == '\\' )
270                 path = path.substr(0,path.length() - 1);
271
272             //if ( path == "C:" ) path = "C:\\";
273
274             //AfxMessageBox(path.c_str());
275         }
276
277         if ( path.length() <= 2)
278         {
279             ElephantMessageBox("Can you please select a folder to put this project into ?",this);
280             return;
281         }
282        
283         string createPath = path;
284        
285         if ( m_createProjectFolder )
286         {
287
288             createPath += "\\" ;
289             m_csProjectName.Replace(" ","_");
290             createPath += m_csProjectName.GetBuffer(0);
291         }
292        
293        
294         if ( ! CreateDirRecursive(createPath.c_str()) )
295         {
296
297             ElephantMessageBox("Sorry I could not create directory [ " + createPath + " ].  Please check the permissions , going to bail out without creating the project.",this);
298             return;
299
300
301         }
302            
303
304         path = createPath;
305        
306
307
308         CString _name = m_csProjectName;
309         _name.Replace(" ","_");
310         string name = _name.GetBuffer(0);
311         //path += "\\" + name;
312        
313         ProjectSpecs p;
314         try
315         {
316             p = GetProjectSpecs();
317         }
318         catch ( ... ) // must select a project
319         {
320
321             ElephantMessageBox("Could you please select a valid project type?",this);
322             return;
323
324         }
325         //AfxMessageBox(path.c_str() );
326         //AfxMessageBox(name.c_str());
327         ProjectSettings *project = new ProjectSettings(path,name);
328         ProjectError err =  project->CreateProject(p, 0);
329        
330         switch ( err )
331         {
332         case COULDNT_COPY_FILES :
333             ElephantMessageBox("Sorry I couldn't copy the project files.  Elephant will not overwrite files with the same name in the existing directory, but it could also be a permissions problem.",this);
334             return;
335         default:
336             break;
337
338         }
339        
340         try {
341
342        
343         Globals::SetProject(project);
344         }
345         catch ( ... )
346         {
347             ElephantMessageBox("Damn ... Fatal error setting up the project.  Bailing out.",this);
348         }
349         //AfxMessageBox("here");
350        
351
352
353
354         EndDialog(0);
355     }
356 }
357
358
359 void CNewProjectDlg::OnProjectNameChange()
360 {
361 UpdateData();
362
363
364
365     if ( m_createProjectFolder )
366     {
367        
368         CString temp = m_csLocation + "\\" + m_csProjectName + "\\" + m_csProjectName ;
369         temp.Replace(" ","_");
370         m_strProjectDir = "[ " + temp + ".dprj ]";
371        
372
373     }
374
375     else
376     {
377
378
379         CString temp = m_csLocation + "\\" + m_csProjectName;
380         temp.Replace(" ","_");
381         m_strProjectDir = "[" + temp + ".dprj ]";
382        
383
384     }
385
386
387     if ( m_csProjectName != "" && m_csProjectName != "Project Name")
388     {
389         m_projectNameCriteria = "[ Supplied ] Project Name";
390     }
391     else m_projectNameCriteria = "[ Not Supplied ] Project Name";
392
393     if ( m_csLocation != "")
394     {
395         m_projectLocationCriteria = "[ Supplied ] Project Location";
396     }
397     else m_projectLocationCriteria = "[ Not Supplied ] Project Location";
398
399    
400
401     UpdateData(FALSE);
402
403
404
405 }
Note: See TracBrowser for help on using the browser.