2 * wxCreaDevManagerNewProjectDialog.cpp
4 * Created on: 2/11/2012
8 #include "wxCreaDevManagerNewProjectDialog.h"
10 #include "wx/richtext/richtextctrl.h"
12 #include "creaDevManagerIds.h"
14 #include "ControlCreaDevManagerProject.h"
16 #include "wxCreaDevManagerMainFrame.h"
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)
24 wxCreaDevManagerNewProjectDialog::wxCreaDevManagerNewProjectDialog(
26 ControlCreaDevManagerMain* controller,
28 const wxString& caption,
29 const wxPoint& position,
34 this->Controller = controller;
35 wxCreaDevManagerNewProjectDialog::Create(parent, id, caption, position, size, style);
38 wxCreaDevManagerNewProjectDialog::~wxCreaDevManagerNewProjectDialog()
42 bool wxCreaDevManagerNewProjectDialog::Create(
45 const wxString& caption,
46 const wxPoint& position,
51 wxDialog::Create(parent, id, caption, position, size, style);
53 this->CreateControls();
58 void wxCreaDevManagerNewProjectDialog::CreateControls()
60 wxBoxSizer* v_sizer1 = new wxBoxSizer(wxVERTICAL);
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);
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);
69 wxFlexGridSizer* formItems = new wxFlexGridSizer(4,2,9,15);
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)"));
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));
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);
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);
96 formItems->AddGrowableCol(1,1);
97 formItems->AddGrowableRow(3,1);
99 v_sizer1->Add(formItems, 1, wxEXPAND | wxALL, 15);
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);
105 v_sizer1->Add(h_sizer2, 0, wxALIGN_RIGHT | wxRIGHT | wxBOTTOM | wxALIGN_CENTER_VERTICAL, 30);
108 v_sizer1->SetSizeHints(this);
111 void wxCreaDevManagerNewProjectDialog::OnCreateProject(wxCommandEvent& event)
115 if(ready && this->projectName->GetValue() == wxString(""))
117 wxMessageBox(wxString("The project name cannot be empty"),_T("Error"),wxOK | wxICON_ERROR);
120 if(ready && this->projectLocation->GetLabel() == wxString(""))
122 wxMessageBox(wxString("The project location cannot be empty"),_T("Error"),wxOK | wxICON_ERROR);
125 if(ready && this->packageAuthor->GetValue() == wxString(""))
127 wxMessageBox(wxString("The project's author cannot be empty"),_T("Error"),wxOK | wxICON_ERROR);
131 std::cout << ready << std::endl;
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())))
135 this->Controller->OpenProject(crea::wx2std(this->projectLocation->GetLabel()) + "/" + crea::wx2std(this->projectName->GetValue()));
137 this->DestroyChildren();
139 wxBoxSizer* v_sizer1 = new wxBoxSizer(wxVERTICAL);
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);
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);
147 v_sizer1->Add(new wxButton(this, ID_BUTTON_CANCEL, wxString("Close")), 0, wxALL, 5);
150 v_sizer1->SetSizeHints(this);
160 void wxCreaDevManagerNewProjectDialog::OnCancel(wxCommandEvent& event)
166 void wxCreaDevManagerNewProjectDialog::OnChooseLocation(wxCommandEvent& event)
168 wxDirDialog* dialog = new wxDirDialog(this, "Choose the location of the new project");
170 this->projectLocation->SetLabel(dialog->GetPath());