X-Git-Url: https://git.creatis.insa-lyon.fr/pubgit/?a=blobdiff_plain;f=lib%2FcreaDevManagerLib%2FwxCDMMainFrame.cpp;h=28d9a5d0e7860f3fe791adb9669577a4394a17eb;hb=58e994c7ddc088821aa0f583354216c6376405c8;hp=d60b3173dc21433c11ce50cb26bd9f6e56fec003;hpb=b10bc326c058168a64969db6c6a29b91a3136fb3;p=crea.git diff --git a/lib/creaDevManagerLib/wxCDMMainFrame.cpp b/lib/creaDevManagerLib/wxCDMMainFrame.cpp index d60b317..28d9a5d 100755 --- a/lib/creaDevManagerLib/wxCDMMainFrame.cpp +++ b/lib/creaDevManagerLib/wxCDMMainFrame.cpp @@ -31,10 +31,12 @@ #include #include +#include "wx/treectrl.h" #include "CDMUtilities.h" #include "creaDevManagerIds.h" #include "wxCDMMainDescriptionPanel.h" +#include "wxCDMProjectDescriptionPanel.h" #include "wxCDMProjectActionsPanel.h" #include "wxCDMNewProjectDialog.h" @@ -65,6 +67,7 @@ EVT_MENU(ID_MENU_ABOUT_CREADEVMANAGER, wxCDMMainFrame::OnMenuAboutCreaDevManager EVT_MENU(ID_MENU_ABOUT_CREATIS, wxCDMMainFrame::OnMenuAboutCreatis) EVT_BUTTON(ID_BUTTON_NEWPROJECT, wxCDMMainFrame::OnMenuNewProject) EVT_BUTTON(ID_BUTTON_OPENPROJECT, wxCDMMainFrame::OnMenuOpenProject) +EVT_TREE_SEL_CHANGED(ID_TREE_PROJECTS, wxCDMMainFrame::OnTreeSelectionChanged) END_EVENT_TABLE() wxCDMMainFrame::wxCDMMainFrame( @@ -187,79 +190,181 @@ void wxCDMMainFrame::CreateControls() - panel_ProjectActions = new wxCDMProjectActionsPanel( - this, - ID_WINDOW_PROJ_ACTIONS, - wxT("Project Actions Panel"), - wxDefaultPosition, - wxSize(600,200), - 0 - ); - panel_ProjectActions->SetMinSize(wxSize(500, 100)); + auiManager.AddPane(tree_Projects, wxLEFT, wxT("Projects Tree")); - auiManager.AddPane(panel_ProjectActions, wxBOTTOM, wxT("Project Actions")); auiManager.AddPane(panel_Properties, wxCENTER, wxT("Properties")); auiManager.Update(); auiManager.GetPane(tree_Projects).CloseButton(false).MaximizeButton(true); - auiManager.GetPane(panel_Properties).CloseButton(false); } //Event Handlers //File menu void wxCDMMainFrame::OnMenuNewProject(wxCommandEvent& event) { + std::string* result; + wxCDMNewProjectDialog* dialog = new wxCDMNewProjectDialog(this); long userResponse; userResponse = dialog->ShowModal(); if(userResponse == wxID_FORWARD) { - std::string* result; + //create project + if(this->model->GetProject() != NULL) + { + if(!this->model->CloseProject(result)) + { + std::cout << "error closing project: " << *result << std::endl; + wxMessageBox(crea::std2wx(*result),_T("New Project - Error!"),wxOK | wxICON_ERROR); + event.Skip(); + return; + } + } + if(!this->model->CreateProject( crea::wx2std(dialog->GetProjectName()), crea::wx2std(dialog->GetProjectLocation()), result, crea::wx2std(dialog->GetPackageAuthor()), crea::wx2std(dialog->GetPackageDescription()) - )) + )) { + std::cout << "error opening project: " << *result << std::endl; wxMessageBox(crea::std2wx(*result),_T("New Project - Error!"),wxOK | wxICON_ERROR); + event.Skip(); + return; } - wxMessageBox(_T("New Project created!"),_T("New Project - Success!"), wxOK | wxICON_INFORMATION); - //TODO: populate model - //TODO: populate tree control + //populate tree control + tree_Projects->BuildTree(this->model->GetProject()); + tree_Projects->SelectItem(this->model->GetProject()->GetId()); + + //change description panel + if(this->panel_Properties != NULL) + { + auiManager.DetachPane(this->panel_Properties); + this->panel_Properties->Destroy(); + } + + this->panel_Properties = new wxCDMProjectDescriptionPanel( + this, + this->model->GetProject(), + ID_WINDOW_PROPERTIES, + wxT("Description Panel"), + wxDefaultPosition, + wxSize(300, 400), + 0); + //show projectactions panel + if(this->panel_ProjectActions != NULL) + { + auiManager.DetachPane(this->panel_Properties); + this->panel_ProjectActions->Destroy(); + } + + panel_ProjectActions = new wxCDMProjectActionsPanel( + this, + ID_WINDOW_PROJ_ACTIONS, + wxT("Project Actions Panel"), + wxDefaultPosition, + wxSize(600,200), + 0 + ); + panel_ProjectActions->SetMinSize(wxSize(500, 100)); + + + auiManager.AddPane(panel_Properties, wxCENTER, wxT("Properties")); + auiManager.AddPane(panel_ProjectActions, wxBOTTOM, wxT("Project Actions")); - //tree_Projects->BuildTree(this->model->GetActiveProjects()); auiManager.Update(); + + wxMessageBox(_T("New Project created!"),_T("New Project - Success!"), wxOK | wxICON_INFORMATION); } event.Skip(); } void wxCDMMainFrame::OnMenuOpenProject(wxCommandEvent& event) { + std::string* result; + long style = wxDD_DEFAULT_STYLE | wxDD_DIR_MUST_EXIST; wxDirDialog* FD = new wxDirDialog(this, wxT("Select the project directory"), wxT(""), style); - long userResponse; - userResponse = FD->ShowModal(); + long userResponse = FD->ShowModal(); if(userResponse == wxID_OK) { - std::cout << "Selection to open: " << crea::wx2std (FD->GetPath()) << std::endl; std::string path = crea::wx2std (FD->GetPath()); + FD -> Destroy(); + FD = NULL; + + std::cout << "Selection to open: " << path << std::endl; + + + //populate model + if(this->model->GetProject() != NULL) + { + std::cout << "Project not null, closing it" << std::endl; + if(!this->model->CloseProject(result)) + { + std::cout << "error closing project: " << *result << std::endl; + wxMessageBox(crea::std2wx(result->c_str()),_T("New Project - Error!"),wxOK | wxICON_ERROR); + event.Skip(); + return; + } + } - std::string* result; if (!this->model->OpenProject(path, result)) { + std::cout << "error opening project: " << *result << std::endl; wxMessageBox( crea::std2wx(result->c_str()), wxT("Open Project - Error"), wxICON_ERROR); event.Skip(); + return; }; - //TODO: populate model - //TODO: populate tree control + std::cout << "building ui" << std::endl; + + + //populate tree control + tree_Projects->BuildTree(this->model->GetProject()); + tree_Projects->SelectItem(this->model->GetProject()->GetId()); + + //change description panel + if(this->panel_Properties != NULL) + { + auiManager.DetachPane(this->panel_Properties); + this->panel_Properties->Destroy(); + } + + this->panel_Properties = new wxCDMProjectDescriptionPanel( + this, + this->model->GetProject(), + ID_WINDOW_PROPERTIES, + wxT("Description Panel"), + wxDefaultPosition, + wxSize(300, 400), + 0 + ); + + //change project's actions panel + if(this->panel_ProjectActions!= NULL) + { + auiManager.DetachPane(this->panel_ProjectActions); + this->panel_ProjectActions->Destroy(); + } + panel_ProjectActions = new wxCDMProjectActionsPanel( + this, + ID_WINDOW_PROJ_ACTIONS, + wxT("Project Actions Panel"), + wxDefaultPosition, + wxSize(600,200), + 0 + ); + panel_ProjectActions->SetMinSize(wxSize(500, 100)); + + + auiManager.AddPane(panel_Properties, wxCENTER, wxT("Properties")); + auiManager.AddPane(panel_ProjectActions, wxBOTTOM, wxT("Project Actions")); - //((wxCreaDevManagerTreeCtrl*)tree_Projects)->BuildTree(controller->GetActiveProjects()); auiManager.Update(); } @@ -272,7 +377,37 @@ void wxCDMMainFrame::OnMenuOpenRecent(wxCommandEvent& event) } void wxCDMMainFrame::OnMenuCloseProject(wxCommandEvent& event) { - std::cerr << "Event OnMenuCloseProject not implemented" << std::endl; + std::string* result; + if(!this->model->CloseProject(result)) + { + std::cout << "error closing project: " << *result << std::endl; + wxMessageBox( crea::std2wx(result->c_str()), wxT("Close Project - Error"), wxICON_ERROR); + } + tree_Projects->BuildTree(this->model->GetProject()); + + if(this->panel_Properties != NULL) + { + auiManager.DetachPane(this->panel_Properties); + this->panel_Properties->Destroy(); + } + if(this->panel_ProjectActions != NULL) + { + auiManager.DetachPane(this->panel_ProjectActions); + this->panel_ProjectActions->Destroy(); + } + + this->panel_Properties = new wxCDMMainDescriptionPanel( + this, + ID_WINDOW_PROPERTIES, + wxT("Description Panel"), + wxDefaultPosition, + wxSize(300, 400), + 0 + ); + + auiManager.AddPane(panel_Properties, wxCENTER, wxT("Properties")); + + auiManager.Update(); event.Skip(); } void wxCDMMainFrame::OnMenuCloseAllProjects(wxCommandEvent& event) @@ -295,7 +430,12 @@ void wxCDMMainFrame::OnMenuExit(wxCommandEvent& event) //Edit Menu void wxCDMMainFrame::OnMenuRefreshProject(wxCommandEvent& event) { - std::cerr << "Event OnMenuRefreshProject not implemented" << std::endl; + std::string* result; + if(!model->RefreshProject(result)) + { + wxMessageBox( crea::std2wx(result->c_str()), wxT("Refresh Project - Error"), wxICON_ERROR); + } + //TODO: Show possible problems in CMakeLists files event.Skip(); } void wxCDMMainFrame::OnMenuMenuCut(wxCommandEvent& event) @@ -377,3 +517,9 @@ void wxCDMMainFrame::OnMenuAboutCreatis(wxCommandEvent& event) std::cerr << "Event OnMenuAboutCreatis not implemented" << std::endl; event.Skip(); } + +void wxCDMMainFrame::OnTreeSelectionChanged(wxTreeEvent& event) +{ + std::cerr << "Event OnTreeSelectionChange not implemented" << std::endl; + event.Skip(); +}