From: Daniel Gonzalez Date: Tue, 16 Apr 2013 13:22:11 +0000 (+0200) Subject: Feature #1711 CreaDevManager application implementation X-Git-Url: https://git.creatis.insa-lyon.fr/pubgit/?a=commitdiff_plain;h=5a424b13e6083c6d64db181e5c4b3022e56193e7;p=crea.git Feature #1711 CreaDevManager application implementation Feature: Now shows recently opened projects. --- diff --git a/lib/creaDevManagerLib/creaDevManagerIds.h b/lib/creaDevManagerLib/creaDevManagerIds.h index b8526d0..bdd9a15 100644 --- a/lib/creaDevManagerLib/creaDevManagerIds.h +++ b/lib/creaDevManagerLib/creaDevManagerIds.h @@ -122,4 +122,10 @@ #define ID_BUTTON_CHECK_PROJECT 10341 +#define ID_MENU_OPEN_RECENT1 10342 +#define ID_MENU_OPEN_RECENT2 10343 +#define ID_MENU_OPEN_RECENT3 10344 +#define ID_MENU_OPEN_RECENT4 10345 +#define ID_MENU_OPEN_RECENT5 10346 + #endif /* CREADEVMANAGERIDS_H_ */ diff --git a/lib/creaDevManagerLib/wxCDMMainFrame.cpp b/lib/creaDevManagerLib/wxCDMMainFrame.cpp index 019c0ac..eb0a2d4 100755 --- a/lib/creaDevManagerLib/wxCDMMainFrame.cpp +++ b/lib/creaDevManagerLib/wxCDMMainFrame.cpp @@ -63,8 +63,14 @@ BEGIN_EVENT_TABLE(wxCDMMainFrame, wxFrame) +EVT_MENU_OPEN(wxCDMMainFrame::OnMenuBarOpen) EVT_MENU(ID_MENU_NEW_PROJECT, wxCDMMainFrame::OnMenuNewProject) EVT_MENU(ID_MENU_OPEN_PROJECT, wxCDMMainFrame::OnMenuOpenProject) +EVT_MENU(ID_MENU_OPEN_RECENT1, wxCDMMainFrame::OnMenuOpenRecent) +EVT_MENU(ID_MENU_OPEN_RECENT2, wxCDMMainFrame::OnMenuOpenRecent) +EVT_MENU(ID_MENU_OPEN_RECENT3, wxCDMMainFrame::OnMenuOpenRecent) +EVT_MENU(ID_MENU_OPEN_RECENT4, wxCDMMainFrame::OnMenuOpenRecent) +EVT_MENU(ID_MENU_OPEN_RECENT5, wxCDMMainFrame::OnMenuOpenRecent) EVT_MENU(ID_MENU_CLOSE_PROJECT, wxCDMMainFrame::OnMenuCloseProject) EVT_MENU(ID_MENU_EXPORT_HIERARCHY, wxCDMMainFrame::OnMenuExportHierarchy) EVT_MENU(ID_MENU_EXIT, wxCDMMainFrame::OnMenuExit) @@ -172,10 +178,40 @@ void wxCDMMainFrame::CreateMenus() { wxMenuBar* menuBar = new wxMenuBar; + //Recently opened projects + menu_Recent = new wxMenu(); + wxConfigBase* pConfig = wxConfigBase::Get(); + std::string rp = crea::wx2std(pConfig->Read(wxT("RECENT1"), wxT(""))); + if(rp != "") + { + menu_Recent->Append(ID_MENU_OPEN_RECENT1, crea::std2wx(rp)); + rp = crea::wx2std(pConfig->Read(wxT("RECENT2"), wxT(""))); + if(rp != "") + { + menu_Recent->Append(ID_MENU_OPEN_RECENT2, crea::std2wx(rp)); + rp = crea::wx2std(pConfig->Read(wxT("RECENT3"), wxT(""))); + if(rp != "") + { + menu_Recent->Append(ID_MENU_OPEN_RECENT3, crea::std2wx(rp)); + rp = crea::wx2std(pConfig->Read(wxT("RECENT4"), wxT(""))); + if(rp != "") + { + menu_Recent->Append(ID_MENU_OPEN_RECENT4, crea::std2wx(rp)); + rp = crea::wx2std(pConfig->Read(wxT("RECENT5"), wxT(""))); + if(rp != "") + { + menu_Recent->Append(ID_MENU_OPEN_RECENT5, crea::std2wx(rp)); + } + } + } + } + } + //FileMenu menu_File = new wxMenu(); menu_File->Append(ID_MENU_NEW_PROJECT, wxT("&New Project...")); menu_File->Append(ID_MENU_OPEN_PROJECT, wxT("&Open Project...")); + menu_File->AppendSubMenu(menu_Recent,wxT("Open &Recent"),wxT("Open a recently opened project.")); menu_File->AppendSeparator(); menu_File->Append(ID_MENU_CLOSE_PROJECT, wxT("&Close Project")); menu_File->AppendSeparator(); @@ -254,6 +290,43 @@ void wxCDMMainFrame::CreateControls() } //Event Handlers + +void wxCDMMainFrame::OnMenuBarOpen(wxMenuEvent& event) +{ + //clean recent menu + int tam = menu_Recent->GetMenuItemCount(); + for (int i = 0; i < tam; ++i) { + menu_Recent->Delete(menu_Recent->FindItemByPosition(0)); + } + //populate recent menu + wxConfigBase* pConfig = wxConfigBase::Get(); + std::string rp = crea::wx2std(pConfig->Read(wxT("RECENT1"), wxT(""))); + if(rp != "") + { + menu_Recent->Append(ID_MENU_OPEN_RECENT1, crea::std2wx(rp)); + rp = crea::wx2std(pConfig->Read(wxT("RECENT2"), wxT(""))); + if(rp != "") + { + menu_Recent->Append(ID_MENU_OPEN_RECENT2, crea::std2wx(rp)); + rp = crea::wx2std(pConfig->Read(wxT("RECENT3"), wxT(""))); + if(rp != "") + { + menu_Recent->Append(ID_MENU_OPEN_RECENT3, crea::std2wx(rp)); + rp = crea::wx2std(pConfig->Read(wxT("RECENT4"), wxT(""))); + if(rp != "") + { + menu_Recent->Append(ID_MENU_OPEN_RECENT4, crea::std2wx(rp)); + rp = crea::wx2std(pConfig->Read(wxT("RECENT5"), wxT(""))); + if(rp != "") + { + menu_Recent->Append(ID_MENU_OPEN_RECENT5, crea::std2wx(rp)); + } + } + } + } + } +} + //File menu void wxCDMMainFrame::OnMenuNewProject(wxCommandEvent& event) { @@ -265,7 +338,7 @@ void wxCDMMainFrame::OnMenuNewProject(wxCommandEvent& event) if(userResponse == wxID_FORWARD) { - //create project + //close open project if(this->model->GetProject() != NULL) { if(!this->model->CloseProject(result)) @@ -275,6 +348,7 @@ void wxCDMMainFrame::OnMenuNewProject(wxCommandEvent& event) event.Skip(); return; } + if(this->panel_Properties != NULL) { auiManager.DetachPane(this->panel_Properties); @@ -288,7 +362,7 @@ void wxCDMMainFrame::OnMenuNewProject(wxCommandEvent& event) } - + //create project if(!this->model->CreateProject( crea::wx2std(dialog->GetProjectName()), crea::wx2std(dialog->GetProjectLocation()), @@ -303,6 +377,18 @@ void wxCDMMainFrame::OnMenuNewProject(wxCommandEvent& event) return; } + //update recently open projects + wxConfigBase* pConfig = wxConfigBase::Get(); + if(pConfig->Read(wxT("RECENT1"),wxT("")) != crea::std2wx(this->model->GetProject()->GetPath())) + { + pConfig->Write(wxT("RECENT5"), pConfig->Read(wxT("RECENT4"),wxT(""))); + pConfig->Write(wxT("RECENT4"), pConfig->Read(wxT("RECENT3"),wxT(""))); + pConfig->Write(wxT("RECENT3"), pConfig->Read(wxT("RECENT2"),wxT(""))); + pConfig->Write(wxT("RECENT2"), pConfig->Read(wxT("RECENT1"),wxT(""))); + pConfig->Write(wxT("RECENT1"), crea::std2wx(this->model->GetProject()->GetPath())); + } + + //show project actions panel if(this->panel_ProjectActions != NULL) { @@ -332,6 +418,104 @@ void wxCDMMainFrame::OnMenuNewProject(wxCommandEvent& event) //wxMessageBox(wxT("ProjectSelected") ,_T("New Project - Success!"),wxOK | wxICON_ERROR); } } +void wxCDMMainFrame::OnMenuOpenRecent(wxCommandEvent& event) +{ + std::string* result; + + //((wxMenuItem*)(event.GetEventObject()))->GetItemLabel(); + + std::string path = ""; + wxConfigBase* pConfig = wxConfigBase::Get(); + if(event.GetId() == ID_MENU_OPEN_RECENT1) + path = crea::wx2std (pConfig->Read(wxT("RECENT1"),wxT(""))); + else if(event.GetId() == ID_MENU_OPEN_RECENT2) + path = crea::wx2std (pConfig->Read(wxT("RECENT2"),wxT(""))); + else if(event.GetId() == ID_MENU_OPEN_RECENT3) + path = crea::wx2std (pConfig->Read(wxT("RECENT3"),wxT(""))); + else if(event.GetId() == ID_MENU_OPEN_RECENT4) + path = crea::wx2std (pConfig->Read(wxT("RECENT4"),wxT(""))); + else if(event.GetId() == ID_MENU_OPEN_RECENT5) + path = crea::wx2std (pConfig->Read(wxT("RECENT5"),wxT(""))); + + std::cout << "Selection to open: " << path << std::endl; + std::cout.flush(); + + + //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; + } + + if(this->panel_Properties != NULL) + { + auiManager.DetachPane(this->panel_Properties); + this->panel_Properties->Hide(); + } + if(this->panel_ProjectActions != NULL) + { + auiManager.DetachPane(this->panel_ProjectActions); + this->panel_ProjectActions->Hide(); + } + } + + 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; + }; + + //update recently open projects + if(pConfig->Read(wxT("RECENT1"),wxT("")) != crea::std2wx(this->model->GetProject()->GetPath())) + { + pConfig->Write(wxT("RECENT5"), pConfig->Read(wxT("RECENT4"),wxT(""))); + pConfig->Write(wxT("RECENT4"), pConfig->Read(wxT("RECENT3"),wxT(""))); + pConfig->Write(wxT("RECENT3"), pConfig->Read(wxT("RECENT2"),wxT(""))); + pConfig->Write(wxT("RECENT2"), pConfig->Read(wxT("RECENT1"),wxT(""))); + pConfig->Write(wxT("RECENT1"), crea::std2wx(this->model->GetProject()->GetPath())); + } + + std::cout << "building ui" << std::endl; + + //populate tree control + tree_Projects->BuildTree(this->model->GetModelElements(), this->model->GetProject()); + tree_Projects->Unselect(); + this->actualTreeItem.Unset(); + tree_Projects->SelectItem(this->model->GetProject()->GetId().GetWxId(), true); + + + //change project's actions panel + if(this->panel_ProjectActions!= NULL) + { + auiManager.DetachPane(this->panel_ProjectActions); + this->panel_ProjectActions->Destroy(); + this->panel_ProjectActions = NULL; + } + panel_ProjectActions = new wxCDMProjectActionsPanel( + this, + this->model->GetProject(), + ID_WINDOW_PROJ_ACTIONS, + wxT("Project Actions Panel"), + wxDefaultPosition, + wxSize(800,200), + 0 + ); + panel_ProjectActions->SetMinSize(wxSize(500, 100)); + + + auiManager.AddPane(panel_ProjectActions, wxAuiPaneInfo().Bottom().MinSize(800,50).Name(wxT("panel_ProjectActions")).Caption(wxT("General Project Actions")).BestSize(800,70).CloseButton(false)); + + auiManager.Update(); + +} void wxCDMMainFrame::OnMenuOpenProject(wxCommandEvent& event) { std::string* result; @@ -359,6 +543,7 @@ void wxCDMMainFrame::OnMenuOpenProject(wxCommandEvent& event) event.Skip(); return; } + if(this->panel_Properties != NULL) { auiManager.DetachPane(this->panel_Properties); @@ -379,6 +564,17 @@ void wxCDMMainFrame::OnMenuOpenProject(wxCommandEvent& event) return; }; + //update recently open projects + wxConfigBase* pConfig = wxConfigBase::Get(); + if(pConfig->Read(wxT("RECENT1"),wxT("")) != crea::std2wx(this->model->GetProject()->GetPath())) + { + pConfig->Write(wxT("RECENT5"), pConfig->Read(wxT("RECENT4"),wxT(""))); + pConfig->Write(wxT("RECENT4"), pConfig->Read(wxT("RECENT3"),wxT(""))); + pConfig->Write(wxT("RECENT3"), pConfig->Read(wxT("RECENT2"),wxT(""))); + pConfig->Write(wxT("RECENT2"), pConfig->Read(wxT("RECENT1"),wxT(""))); + pConfig->Write(wxT("RECENT1"), crea::std2wx(this->model->GetProject()->GetPath())); + } + std::cout << "building ui" << std::endl; //populate tree control diff --git a/lib/creaDevManagerLib/wxCDMMainFrame.h b/lib/creaDevManagerLib/wxCDMMainFrame.h index b5180f1..3cacf8a 100755 --- a/lib/creaDevManagerLib/wxCDMMainFrame.h +++ b/lib/creaDevManagerLib/wxCDMMainFrame.h @@ -125,6 +125,10 @@ protected: private: //Menus + /** + * Recently opened projects menu + */ + wxMenu* menu_Recent; /** * File menu */ @@ -177,6 +181,13 @@ private: //events protected: + + /** + * Starts when the menu bar is opened. + * @param event The event object that triggers the handler. + */ + void OnMenuBarOpen(wxMenuEvent& event); + //File /** * New project handler. Launches a new project dialog and creates a project model if the project is correctly created. @@ -188,6 +199,11 @@ protected: * @param event The event object that triggers the handler. */ void OnMenuOpenProject(wxCommandEvent& event); + /** + * Open recent project handler. Creates a project model if the project is correctly opened given its path. + * @param event The event object that triggers the handler. + */ + void OnMenuOpenRecent(wxCommandEvent& event); /** * Close project handler. Remove the project from the model and restarts the user interface. * @param event The event object that triggers the handler.