]> Creatis software - crea.git/blob - appli/creaNewProject/creaNewProject.cpp
Don't create empty MakeFileLists.txt when NewPackage
[crea.git] / appli / creaNewProject / creaNewProject.cpp
1 #include <creaWx.h>
2 #include <wx/dirdlg.h>
3 #include <stdlib.h> // for getenv
4
5 class myApp : public wxApp
6 {
7 public:
8   bool OnInit( );
9   int  OnExit() { return true; }
10 };
11
12 IMPLEMENT_APP(myApp);
13 CREA_WXMAIN_WITH_CONSOLE
14
15 bool myApp::OnInit( )
16 {
17   wxApp::OnInit();
18 #ifdef __WXGTK__
19   //See http://www.wxwindows.org/faqgtk.htm#locale
20   setlocale(LC_NUMERIC, "C");
21 #endif
22    wxInitAllImageHandlers();
23
24    wxString dir = wxDirSelector(_T("Select directory in which to create the project"), _T(""), wxDD_DEFAULT_STYLE | wxDD_DIR_MUST_EXIST );
25
26    if (dir.IsEmpty()) return false;
27
28    wxString name = wxGetTextFromUser(_T("Enter project name"),
29                                      _T("creaNewProject"),
30                                      _T("New"));
31    if (name.IsEmpty()) return false;
32
33 char * install_Dir = getenv("bbtk_DIR");
34 std::string execGUICreateNewPackage(install_Dir);
35 execGUICreateNewPackage = "bbi " + execGUICreateNewPackage;
36   
37 #if(_WIN32)
38         std::string command("creaNewProject.bat ");
39         std::string command1("creaSed.exe ");
40         std::string command2("del ");
41         
42         command  += "\"" + crea::wx2std(dir) + "\" \"" + crea::wx2std(name) + "\"";
43         command1 += "\"" + crea::wx2std(dir)+"\\"+crea::wx2std(name)+"\\CMakeLists.txt.in\" " + "NameOfTheProject " + crea::wx2std(name) + "> \"" + crea::wx2std(dir)+"\\"+crea::wx2std(name)+"\\CMakeLists.txt\"";
44         command2 += "\"" + crea::wx2std(dir)+"\\"+crea::wx2std(name)+"\\CMakeLists.txt.in\"";
45         if ( ! system ( command.c_str() ) )
46         {
47                 system ( command1.c_str() );
48                 system ( command2.c_str() );
49                 wxMessageBox(_T("Done !"),_T("creaNewProject"),
50                                 wxOK | wxICON_INFORMATION);
51                 // Create a Package at the same time.   JPR
52                 execGUICreateNewPackage += "\..\..\..\share\bbtk\bbs\toolsbbtk\appli\GUICreatePackage.bbs";
53                 system(execGUICreateNewPackage.c_str());
54         }
55         else 
56         {
57                 wxString err(_T("An error occured while running '"));
58                 err +=  crea::std2wx(command) + _T("'");
59                 wxMessageBox(err,_T("creaNewProject"),wxOK | wxICON_ERROR);      
60         }
61 #else
62         std::string command("creaNewProject.sh ");
63         command += "\"" + crea::wx2std(dir) + "\"" +" " + crea::wx2std(name);
64         if ( ! system ( command.c_str() ) )
65         {
66                 wxMessageBox(_T("Done !"),_T("creaNewProject"),
67                                         wxOK | wxICON_INFORMATION);
68                 // Create a Package at the same time.   JPR
69                 execGUICreateNewPackage += "/../../../share/bbtk/bbs/toolsbbtk/appli/GUICreatePackage.bbs";
70                 system(execGUICreateNewPackage.c_str());
71
72         }
73         else 
74         {
75                 wxString err(_T("An error occured while running '"));
76                 err +=  crea::std2wx(command) + _T("'");
77                 wxMessageBox(err,_T("creaNewProject"),wxOK | wxICON_ERROR);      
78         }
79         
80 #endif
81
82
83
84    return false;
85 }
86