]> Creatis software - crea.git/blob - lib/creaDevManagerLib/wxCreaDevManagerNewProjectDialog.cpp
Feature #1711
[crea.git] / lib / creaDevManagerLib / wxCreaDevManagerNewProjectDialog.cpp
1 /*
2  * wxCreaDevManagerNewProjectDialog.cpp
3  *
4  *  Created on: 2/11/2012
5  *      Author: daniel
6  */
7
8 #include "wxCreaDevManagerNewProjectDialog.h"
9
10 #include "wx/richtext/richtextctrl.h"
11
12 #include "creaDevManagerIds.h"
13
14 #include "ControlCreaDevManagerProject.h"
15
16 #include "wxCreaDevManagerMainFrame.h"
17
18 BEGIN_EVENT_TABLE(wxCreaDevManagerNewProjectDialog, wxDialog)
19   EVT_BUTTON(ID_BUTTON_NEXT, wxCreaDevManagerNewProjectDialog::OnCreateProject)
20   EVT_BUTTON(ID_BUTTON_CANCEL, wxCreaDevManagerNewProjectDialog::OnCancel)
21   EVT_BUTTON(ID_BUTTON_CHOOSE, wxCreaDevManagerNewProjectDialog::OnChooseLocation)
22 END_EVENT_TABLE()
23
24 wxCreaDevManagerNewProjectDialog::wxCreaDevManagerNewProjectDialog(
25   wxWindow* parent,
26   ControlCreaDevManagerMain* controller,
27   wxWindowID id,
28   const wxString& caption,
29   const wxPoint& position,
30   const wxSize& size,
31   long style
32 )
33 {
34   this->Controller = controller;
35   wxCreaDevManagerNewProjectDialog::Create(parent, id, caption, position, size, style);
36 }
37
38 wxCreaDevManagerNewProjectDialog::~wxCreaDevManagerNewProjectDialog()
39 {
40 }
41
42 bool wxCreaDevManagerNewProjectDialog::Create(
43   wxWindow* parent,
44   wxWindowID id,
45   const wxString& caption,
46   const wxPoint& position,
47   const wxSize& size,
48   long style
49 )
50 {
51   wxDialog::Create(parent, id, caption, position, size, style);
52
53   this->CreateControls();
54
55   return TRUE;
56 }
57
58 void wxCreaDevManagerNewProjectDialog::CreateControls()
59 {
60   wxBoxSizer* v_sizer1 = new wxBoxSizer(wxVERTICAL);
61
62
63   wxStaticText* title = new wxStaticText(this, wxID_ANY, wxString("Create a new project"), wxDefaultPosition, wxDefaultSize, wxALIGN_LEFT);//new wxRichTextCtrl(this,wxID_ANY, wxString("Create a new project"), wxDefaultPosition, wxDefaultSize, wxRE_READONLY);
64   v_sizer1->Add(title, 0, wxALIGN_LEFT | wxALL | wxALIGN_CENTER_VERTICAL, 5);
65
66   wxStaticText* instruction = new wxStaticText(this, wxID_ANY, wxString("Please fill the following details."), wxDefaultPosition, wxDefaultSize, wxALIGN_LEFT);
67   v_sizer1->Add(instruction, 0, wxALIGN_LEFT | wxALL | wxALIGN_CENTER_VERTICAL, 5);
68
69   wxFlexGridSizer* formItems = new wxFlexGridSizer(4,2,9,15);
70
71   wxStaticText *stxtPrjLoc = new wxStaticText(this, -1, wxT("Project Location"));
72   wxStaticText *stxtPrjName = new wxStaticText(this, -1, wxT("Project Name"));
73   wxStaticText *stxtPrjAuth = new wxStaticText(this, -1, wxT("Default Package's Author (1 word)"));
74   wxStaticText *stxtPrjPkg = new wxStaticText(this, -1, wxT("Default Package's Description (HTML)"));
75
76   wxBoxSizer* h_sizer1 = new wxBoxSizer(wxHORIZONTAL);
77   wxButton *ddPrjLocBtn = new wxButton(this, ID_BUTTON_CHOOSE, wxString("Choose directory..."));
78   this->projectLocation = new wxStaticText(this, -1, wxString(""));
79   h_sizer1->Add(ddPrjLocBtn,0,wxALIGN_LEFT | wxLEFT | wxALIGN_CENTER_VERTICAL, 5);
80   h_sizer1->Add(this->projectLocation,0,wxALIGN_LEFT | wxLEFT | wxALIGN_CENTER_VERTICAL, 5);
81   h_sizer1->SetMinSize(wxSize(150, 20));
82
83   this->projectName = new wxTextCtrl(this, -1);
84   this->packageAuthor = new wxTextCtrl(this, -1);
85   this->packageDescription = new wxTextCtrl(this, -1, wxEmptyString, wxDefaultPosition, wxDefaultSize, wxTE_MULTILINE);
86
87   formItems->Add(stxtPrjLoc, 0, wxALIGN_CENTER_VERTICAL);
88   formItems->Add(h_sizer1, 1, wxEXPAND | wxALIGN_CENTER_VERTICAL);
89   formItems->Add(stxtPrjName, 0, wxALIGN_CENTER_VERTICAL);
90   formItems->Add(this->projectName, 1, wxEXPAND | wxALIGN_CENTER_VERTICAL);
91   formItems->Add(stxtPrjAuth, 0, wxALIGN_CENTER_VERTICAL);
92   formItems->Add(this->packageAuthor, 1, wxEXPAND | wxALIGN_CENTER_VERTICAL);
93   formItems->Add(stxtPrjPkg);
94   formItems->Add(this->packageDescription, 1, wxEXPAND);
95
96   formItems->AddGrowableCol(1,1);
97   formItems->AddGrowableRow(3,1);
98
99   v_sizer1->Add(formItems, 1, wxEXPAND | wxALL, 15);
100
101   wxBoxSizer* h_sizer2 = new wxBoxSizer(wxHORIZONTAL);
102   h_sizer2->Add(new wxButton(this, ID_BUTTON_NEXT, wxString("Create Project")), 0, wxALL | wxALIGN_CENTER_VERTICAL, 5);
103   h_sizer2->Add(new wxButton(this, ID_BUTTON_CANCEL, wxString("Cancel")), 0, wxALL | wxALIGN_CENTER_VERTICAL, 5);
104
105   v_sizer1->Add(h_sizer2, 0, wxALIGN_RIGHT | wxRIGHT | wxBOTTOM | wxALIGN_CENTER_VERTICAL, 30);
106
107   SetSizer(v_sizer1);
108   v_sizer1->SetSizeHints(this);
109 }
110
111 void wxCreaDevManagerNewProjectDialog::OnCreateProject(wxCommandEvent& event)
112 {
113   bool ready = true;
114
115   if(ready && this->projectName->GetValue() == wxString(""))
116   {
117     wxMessageBox(wxString("The project name cannot be empty"),_T("Error"),wxOK | wxICON_ERROR);
118     ready = false;
119   }
120   if(ready && this->projectLocation->GetLabel() == wxString(""))
121   {
122     wxMessageBox(wxString("The project location cannot be empty"),_T("Error"),wxOK | wxICON_ERROR);
123     ready = false;
124   }
125   if(ready && this->packageAuthor->GetValue() == wxString(""))
126   {
127     wxMessageBox(wxString("The project's author cannot be empty"),_T("Error"),wxOK | wxICON_ERROR);
128     ready = false;
129   }
130
131   std::cout << ready << std::endl;
132
133   if(ready && ControlCreaDevManagerProject::CreateProject(crea::wx2std(this->projectName->GetValue()), crea::wx2std(this->projectLocation->GetLabel()), crea::wx2std(this->packageAuthor->GetValue()), crea::wx2std(this->packageDescription->GetValue())))
134   {
135     this->Controller->OpenProject(crea::wx2std(this->projectLocation->GetLabel()) + "/" + crea::wx2std(this->projectName->GetValue()));
136
137     this->DestroyChildren();
138
139     wxBoxSizer* v_sizer1 = new wxBoxSizer(wxVERTICAL);
140
141     wxStaticText* title = new wxStaticText(this, wxID_ANY, wxString("Your project is ready!"), wxDefaultPosition, wxDefaultSize, wxALIGN_LEFT);//new wxRichTextCtrl(this,wxID_ANY, wxString("Create a new project"), wxDefaultPosition, wxDefaultSize, wxRE_READONLY);
142     v_sizer1->Add(title, 0, wxALL, 5);
143
144     wxStaticText* instruction = new wxStaticText(this, wxID_ANY, wxString("Please close this dialog to continue to the project."), wxDefaultPosition, wxDefaultSize, wxALIGN_LEFT);
145     v_sizer1->Add(instruction, 0, wxALL, 5);
146
147     v_sizer1->Add(new wxButton(this, ID_BUTTON_CANCEL, wxString("Close")), 0, wxALL, 5);
148
149     SetSizer(v_sizer1);
150     v_sizer1->SetSizeHints(this);
151   }else{
152       if(ready)
153         this->Close();
154   }
155
156
157   event.Skip();
158 }
159
160 void wxCreaDevManagerNewProjectDialog::OnCancel(wxCommandEvent& event)
161 {
162   this->Close();
163   event.Skip();
164 }
165
166 void wxCreaDevManagerNewProjectDialog::OnChooseLocation(wxCommandEvent& event)
167 {
168   wxDirDialog* dialog = new wxDirDialog(this, "Choose the location of the new project");
169   dialog->ShowModal();
170   this->projectLocation->SetLabel(dialog->GetPath());
171   this->Update();
172   event.Skip();
173 }