From 311bdcc514f85386f3bbbef9ff6a88bf69fd930f Mon Sep 17 00:00:00 2001 From: Daniel Gonzalez Date: Fri, 28 Dec 2012 17:53:57 +0100 Subject: [PATCH] Feature #1711 CreaDevManager application implementation -Fixed bug with refresh where all elements were being recreated. -Black box creation implemented --- lib/creaDevManagerLib/modelCDMAppli.cpp | 7 +- lib/creaDevManagerLib/modelCDMApplication.cpp | 7 +- lib/creaDevManagerLib/modelCDMBlackBox.cpp | 2 + .../modelCDMCMakeListsFile.cpp | 2 + lib/creaDevManagerLib/modelCDMFile.cpp | 2 + lib/creaDevManagerLib/modelCDMFolder.cpp | 15 +- lib/creaDevManagerLib/modelCDMLib.cpp | 7 +- lib/creaDevManagerLib/modelCDMLibrary.cpp | 13 +- lib/creaDevManagerLib/modelCDMPackage.cpp | 13 +- lib/creaDevManagerLib/modelCDMPackage.h | 3 +- lib/creaDevManagerLib/modelCDMPackageSrc.cpp | 143 +++++++++++++++++- lib/creaDevManagerLib/modelCDMPackageSrc.h | 1 + lib/creaDevManagerLib/modelCDMProject.cpp | 13 +- lib/creaDevManagerLib/wxCDMMainFrame.cpp | 1 + .../wxCDMPackageDescriptionPanel.cpp | 43 +++++- 15 files changed, 236 insertions(+), 36 deletions(-) diff --git a/lib/creaDevManagerLib/modelCDMAppli.cpp b/lib/creaDevManagerLib/modelCDMAppli.cpp index d15bc4f..c92932a 100644 --- a/lib/creaDevManagerLib/modelCDMAppli.cpp +++ b/lib/creaDevManagerLib/modelCDMAppli.cpp @@ -48,6 +48,7 @@ modelCDMAppli::modelCDMAppli() modelCDMAppli::modelCDMAppli(const std::string& path, const std::string& name, const int& level) { + std::cout << "creating appli\n"; this->type = wxDIR_DIRS; this->name = name; this->level = level; @@ -97,6 +98,7 @@ modelCDMAppli::modelCDMAppli(const std::string& path, const std::string& name, c } this->SortChildren(); + std::sort(this->applications.begin(), this->applications.end(), CompareNodeItem); } modelCDMAppli::~modelCDMAppli() @@ -176,7 +178,7 @@ const bool modelCDMAppli::Refresh(std::string*& result) std::string applicationName = stdfileName; //check if they already exist bool found = false; - for (int i = 0;!found && i < this->applications.size(); i++) + for (int i = 0; !found && i < this->applications.size(); i++) { if (this->applications[i]->GetName() == applicationName) { @@ -222,7 +224,7 @@ const bool modelCDMAppli::Refresh(std::string*& result) else { bool found = false; - for (int i = 0; i children.size(); i++) + for (int i = 0; !found && i < this->children.size(); i++) { if (this->children[i]->GetName() == stdfileName) { @@ -264,5 +266,6 @@ const bool modelCDMAppli::Refresh(std::string*& result) } } this->SortChildren(); + std::sort(this->applications.begin(), this->applications.end(), CompareNodeItem); return true; } diff --git a/lib/creaDevManagerLib/modelCDMApplication.cpp b/lib/creaDevManagerLib/modelCDMApplication.cpp index e8af2cf..5777044 100644 --- a/lib/creaDevManagerLib/modelCDMApplication.cpp +++ b/lib/creaDevManagerLib/modelCDMApplication.cpp @@ -47,6 +47,7 @@ modelCDMApplication::modelCDMApplication() modelCDMApplication::modelCDMApplication(const std::string& path, const std::string& name, const int& level) { + std::cout << "creating application: " + path + "\n"; //folder name this->name = name; //path @@ -129,6 +130,7 @@ modelCDMApplication::modelCDMApplication(const std::string& path, const std::str } } this->SortChildren(); + std::sort(this->folders.begin(), this->folders.end(), CompareNodeItem); } modelCDMApplication::~modelCDMApplication() @@ -204,6 +206,7 @@ modelCDMFolder* modelCDMApplication::CreateFolder(const std::string& name, std:: const bool modelCDMApplication::Refresh(std::string*& result) { + std::cout << "refreshing application: " << this->executableName << std::endl; //set attributes this->type = wxDIR_DIRS; @@ -257,7 +260,7 @@ const bool modelCDMApplication::Refresh(std::string*& result) std::string applicationName = stdfileName; //check if they already exist bool found = false; - for (int i = 0;!found && i < this->folders.size(); i++) + for (int i = 0; !found && i < this->folders.size(); i++) { if (this->folders[i]->GetName() == applicationName) { @@ -303,7 +306,7 @@ const bool modelCDMApplication::Refresh(std::string*& result) else { bool found = false; - for (int i = 0; i children.size(); i++) + for (int i = 0; !found && i < this->children.size(); i++) { if (this->children[i]->GetName() == stdfileName) { diff --git a/lib/creaDevManagerLib/modelCDMBlackBox.cpp b/lib/creaDevManagerLib/modelCDMBlackBox.cpp index 4d83492..daec9d4 100644 --- a/lib/creaDevManagerLib/modelCDMBlackBox.cpp +++ b/lib/creaDevManagerLib/modelCDMBlackBox.cpp @@ -49,6 +49,7 @@ modelCDMBlackBox::modelCDMBlackBox() modelCDMBlackBox::modelCDMBlackBox(const std::string& path, const std::string& name, const int& level) { + std::cout << "creating black box: " + name + " in " + path + "\n"; this->name = name; this->path = path; this->level = level; @@ -332,6 +333,7 @@ modelCDMFile* modelCDMBlackBox::GetSourceFile() const const bool modelCDMBlackBox::Refresh(std::string*& result) { + std::cout << "refreshing black box: " << this->nameBlackBox << std::endl; std::string pathHeader = path + CDMUtilities::SLASH + "bb" + this->name + ".h"; std::ifstream confFile; diff --git a/lib/creaDevManagerLib/modelCDMCMakeListsFile.cpp b/lib/creaDevManagerLib/modelCDMCMakeListsFile.cpp index dfbb999..72b1cdf 100644 --- a/lib/creaDevManagerLib/modelCDMCMakeListsFile.cpp +++ b/lib/creaDevManagerLib/modelCDMCMakeListsFile.cpp @@ -47,6 +47,7 @@ modelCDMCMakeListsFile::modelCDMCMakeListsFile() modelCDMCMakeListsFile::modelCDMCMakeListsFile(const std::string& path, const std::string& name, const int& level) { + std::cout << "creating cmakelist file: " + path + "\n"; this->children.clear(); this->level = level; this->type = wxDIR_FILES; @@ -77,6 +78,7 @@ bool modelCDMCMakeListsFile::OpenFile(std::string*& result) const bool modelCDMCMakeListsFile::Refresh(std::string*& result) { + //std::cout << "refreshing cmakelists" << std::endl; std::ifstream in((this->path).c_str()); if(!in.is_open()) { diff --git a/lib/creaDevManagerLib/modelCDMFile.cpp b/lib/creaDevManagerLib/modelCDMFile.cpp index 039de47..3f92ffe 100644 --- a/lib/creaDevManagerLib/modelCDMFile.cpp +++ b/lib/creaDevManagerLib/modelCDMFile.cpp @@ -46,6 +46,7 @@ modelCDMFile::modelCDMFile() modelCDMFile::modelCDMFile(const std::string& path, const std::string& name, const int& level) { + std::cout << "creating file: " + path + "\n"; this->children.clear(); this->level = level; this->name = name; @@ -76,6 +77,7 @@ bool modelCDMFile::OpenFile(std::string*& result, const std::string& command) const bool modelCDMFile::Refresh(std::string*& result) { + //std::cout << "refreshing file " << this->name << std::endl; std::ifstream in((this->path).c_str()); if(!in.is_open()) { diff --git a/lib/creaDevManagerLib/modelCDMFolder.cpp b/lib/creaDevManagerLib/modelCDMFolder.cpp index c1ef911..3365c09 100644 --- a/lib/creaDevManagerLib/modelCDMFolder.cpp +++ b/lib/creaDevManagerLib/modelCDMFolder.cpp @@ -49,6 +49,7 @@ modelCDMFolder::modelCDMFolder() modelCDMFolder::modelCDMFolder(const std::string& path, const std::string& name, const int& level) { + std::cout << "creating folder: " + path + "\n"; //set attributes this->children.clear(); this->level = level; @@ -70,7 +71,9 @@ modelCDMFolder::modelCDMFolder(const std::string& path, const std::string& name, std::string stdfileName = crea::wx2std(fileName); //if is an unknown folder, create folder - this->children.push_back(new modelCDMFolder(pathFixed + CDMUtilities::SLASH + stdfileName, stdfileName, this->level + 1)); + modelCDMFolder* folder = new modelCDMFolder(pathFixed + CDMUtilities::SLASH + stdfileName, stdfileName, this->level + 1); + this->children.push_back(folder); + this->folders.push_back(folder); cont = dir.GetNext(&fileName); } @@ -96,6 +99,7 @@ modelCDMFolder::modelCDMFolder(const std::string& path, const std::string& name, } this->SortChildren(); + std::sort(this->folders.begin(), this->folders.end(), CompareNodeItem); } modelCDMFolder::~modelCDMFolder() @@ -147,6 +151,7 @@ bool modelCDMFolder::OpenCMakeListsFile(std::string*& result) const bool modelCDMFolder::Refresh(std::string*& result) { + //std::cout << "refreshing folder " << this->name << std::endl; //set attributes this->type = wxDIR_DIRS; @@ -163,12 +168,11 @@ const bool modelCDMFolder::Refresh(std::string*& result) while (cont) { std::string stdfileName = crea::wx2std(fileName); - std::string folderName = stdfileName; //check if they already exist bool found = false; - for (int i = 0;!found && i < this->folders.size(); i++) + for (int i = 0; !found && i < this->folders.size(); i++) { - if (this->folders[i]->GetName() == folderName) + if (this->folders[i]->GetName() == stdfileName) { found = true; int pos = std::find(this->children.begin(), this->children.end(), this->folders[i]) - this->children.begin(); @@ -213,7 +217,7 @@ const bool modelCDMFolder::Refresh(std::string*& result) else { bool found = false; - for (int i = 0; i children.size(); i++) + for (int i = 0;!found && i < this->children.size(); i++) { if (this->children[i]->GetName() == stdfileName) { @@ -255,6 +259,7 @@ const bool modelCDMFolder::Refresh(std::string*& result) } } this->SortChildren(); + std::sort(this->folders.begin(), this->folders.end(), CompareNodeItem); return true; } diff --git a/lib/creaDevManagerLib/modelCDMLib.cpp b/lib/creaDevManagerLib/modelCDMLib.cpp index 416c1ff..8ebd9ae 100644 --- a/lib/creaDevManagerLib/modelCDMLib.cpp +++ b/lib/creaDevManagerLib/modelCDMLib.cpp @@ -47,6 +47,7 @@ modelCDMLib::modelCDMLib() modelCDMLib::modelCDMLib(const std::string& path, const std::string& name, const int& level) { + std::cout << "creating lib\n"; this->type = wxDIR_DIRS; this->name = name; this->level = level; @@ -97,6 +98,7 @@ modelCDMLib::modelCDMLib(const std::string& path, const std::string& name, const } } this->SortChildren(); + std::sort(this->libraries.begin(), this->libraries.end(), CompareNodeItem); } modelCDMLib::~modelCDMLib() @@ -178,7 +180,7 @@ const bool modelCDMLib::Refresh(std::string*& result) std::string libraryName = stdfileName; //check if they already exist bool found = false; - for (int i = 0;!found && i < this->libraries.size(); i++) + for (int i = 0; !found && i < this->libraries.size(); i++) { if (this->libraries[i]->GetName() == libraryName) { @@ -224,7 +226,7 @@ const bool modelCDMLib::Refresh(std::string*& result) else { bool found = false; - for (int i = 0; i children.size(); i++) + for (int i = 0; !found && i < this->children.size(); i++) { if (this->children[i]->GetName() == stdfileName) { @@ -266,5 +268,6 @@ const bool modelCDMLib::Refresh(std::string*& result) } } this->SortChildren(); + std::sort(this->libraries.begin(), this->libraries.end(), CompareNodeItem); return true; } diff --git a/lib/creaDevManagerLib/modelCDMLibrary.cpp b/lib/creaDevManagerLib/modelCDMLibrary.cpp index e16eeae..1964e88 100644 --- a/lib/creaDevManagerLib/modelCDMLibrary.cpp +++ b/lib/creaDevManagerLib/modelCDMLibrary.cpp @@ -47,6 +47,7 @@ modelCDMLibrary::modelCDMLibrary() modelCDMLibrary::modelCDMLibrary(const std::string& path, const std::string& name, const int& level) { + std::cout << "creating library: " + path + "\n"; //folder name this->name = name; //path @@ -131,6 +132,7 @@ modelCDMLibrary::modelCDMLibrary(const std::string& path, const std::string& nam } } this->SortChildren(); + std::sort(this->folders.begin(), this->folders.end(), CompareNodeItem); } modelCDMLibrary::~modelCDMLibrary() @@ -206,6 +208,7 @@ modelCDMFolder* modelCDMLibrary::CreateFolder(const std::string& name, std::stri const bool modelCDMLibrary::Refresh(std::string*& result) { + std::cout << "refreshing library: " << this->nameLibrary << std::endl; //set attributes this->type = wxDIR_DIRS; @@ -256,12 +259,11 @@ const bool modelCDMLibrary::Refresh(std::string*& result) while (cont) { std::string stdfileName = crea::wx2std(fileName); - std::string folderName = stdfileName; //check if they already exist bool found = false; - for (int i = 0;!found && i < this->folders.size(); i++) + for (int i = 0; !found && i < this->folders.size(); i++) { - if (this->folders[i]->GetName() == folderName) + if (this->folders[i]->GetName() == stdfileName) { found = true; int pos = std::find(this->children.begin(), this->children.end(), this->folders[i]) - this->children.begin(); @@ -301,11 +303,11 @@ const bool modelCDMLibrary::Refresh(std::string*& result) return false; } } - //if is an unknown file, create file + //if is an unknown file, check if exist in children else { bool found = false; - for (int i = 0; i children.size(); i++) + for (int i = 0; !found && i < this->children.size(); i++) { if (this->children[i]->GetName() == stdfileName) { @@ -347,5 +349,6 @@ const bool modelCDMLibrary::Refresh(std::string*& result) } } this->SortChildren(); + std::sort(this->folders.begin(), this->folders.end(), CompareNodeItem); return true; } diff --git a/lib/creaDevManagerLib/modelCDMPackage.cpp b/lib/creaDevManagerLib/modelCDMPackage.cpp index a2ee6c8..cd24c04 100644 --- a/lib/creaDevManagerLib/modelCDMPackage.cpp +++ b/lib/creaDevManagerLib/modelCDMPackage.cpp @@ -48,6 +48,7 @@ modelCDMPackage::modelCDMPackage() modelCDMPackage::modelCDMPackage(const std::string& path, const std::string& name, const int& level) { + std::cout << "creating package: " + path + "\n"; this->type = wxDIR_DIRS; this->name = name; //Get Package Name @@ -351,22 +352,22 @@ bool modelCDMPackage::SetDescription(const std::string& description, std::string } modelCDMBlackBox* modelCDMPackage::CreateBlackBox( + std::string*& result, const std::string& name, const std::string& type, const std::string& format, + const std::string& categories, const std::string& authors, const std::string& authorsEmail, - const std::string& categories, const std::string& description ) { - //TODO: implement method - return NULL; + return this->src->CreateBlackBox(result,name, this->namePackage, type,format,categories,authors,authorsEmail,description); } const bool modelCDMPackage::Refresh(std::string*& result) { - std::cout << "refreshing package" << std::endl; + std::cout << "refreshing package " << this->namePackage << std::endl; this->type = wxDIR_DIRS; //Get Package Name @@ -481,7 +482,7 @@ const bool modelCDMPackage::Refresh(std::string*& result) //check if folder already exist bool found = false; - for (int i = 0;!found && i < this->children.size(); i++) + for (int i = 0; !found && i < this->children.size(); i++) { if (this->children[i]->GetName() == stdfileName) { @@ -526,7 +527,7 @@ const bool modelCDMPackage::Refresh(std::string*& result) else { bool found = false; - for (int i = 0; i children.size(); i++) + for (int i = 0; !found && i < this->children.size(); i++) { if (this->children[i]->GetName() == stdfileName) { diff --git a/lib/creaDevManagerLib/modelCDMPackage.h b/lib/creaDevManagerLib/modelCDMPackage.h index 3745fb2..67e6957 100644 --- a/lib/creaDevManagerLib/modelCDMPackage.h +++ b/lib/creaDevManagerLib/modelCDMPackage.h @@ -62,12 +62,13 @@ public: modelCDMBlackBox* CreateBlackBox( + std::string*& result, const std::string& name, const std::string& type = "std", const std::string& format = "C++", + const std::string& categories = "empty", const std::string& authors = "unknown", const std::string& authorsEmail = "", - const std::string& categories = "empty", const std::string& description = "no description" ); virtual const bool Refresh(std::string*& result); diff --git a/lib/creaDevManagerLib/modelCDMPackageSrc.cpp b/lib/creaDevManagerLib/modelCDMPackageSrc.cpp index 16e7e59..06d0c09 100644 --- a/lib/creaDevManagerLib/modelCDMPackageSrc.cpp +++ b/lib/creaDevManagerLib/modelCDMPackageSrc.cpp @@ -49,6 +49,7 @@ modelCDMPackageSrc::modelCDMPackageSrc() modelCDMPackageSrc::modelCDMPackageSrc(const std::string& path, const std::string& name, const int& level) { + std::cout << "creating package src: " + path + "\n"; //set attributes this->children.clear(); this->level = level; @@ -109,6 +110,7 @@ modelCDMPackageSrc::modelCDMPackageSrc(const std::string& path, const std::strin } this->SortChildren(); + std::sort(this->blackBoxes.begin(), this->blackBoxes.end(), CompareNodeItem); } modelCDMPackageSrc::~modelCDMPackageSrc() @@ -130,21 +132,151 @@ const std::vector& modelCDMPackageSrc::GetBlackBoxes() const } modelCDMBlackBox* modelCDMPackageSrc::CreateBlackBox( + std::string*& result, const std::string& name, const std::string& package, const std::string& type, const std::string& format, + const std::string& categories, const std::string& authors, const std::string& authorsEmail, - const std::string& categories, const std::string& description) { - //TODO: implement method - return NULL; + //parse name + std::vector words; + CDMUtilities::splitter::split(words, name, " \n\",/\\", CDMUtilities::splitter::no_empties); + std::string bbName; + for (int i = 0; i < words.size(); i++) + { + bbName += words[i]; + } + + //parse categories + CDMUtilities::splitter::split(words, categories, " \n\",/\\", CDMUtilities::splitter::no_empties); + std::string bbCategories; + if(words.size() > 0) + { + bbCategories = words[0]; + for (int i = 1; i < words.size(); i++) + { + bbCategories += "," + words[i]; + } + } + if(bbCategories == "") + bbCategories = "empty"; + + //parse authors + CDMUtilities::splitter::split(words, authors, "\n\",/\\", CDMUtilities::splitter::no_empties); + std::string bbAuthors; + if(words.size() > 0) + { + bbAuthors = words[0]; + for (int i = 1; i < words.size(); i++) + { + bbAuthors += "," + words[i]; + } + } + if(bbAuthors == "") + bbAuthors = "Unknown"; + + //parse description + CDMUtilities::splitter::split(words, authorsEmail, " \n\"/\\", CDMUtilities::splitter::no_empties); + std::string bbDescription; + if(words.size() > 0) + { + bbDescription = words[0]; + for (int i = 1; i < words.size(); i++) + { + bbDescription += "," + words[i]; + } + bbDescription += " - "; + } + CDMUtilities::splitter::split(words, description, "\n\"/\\", CDMUtilities::splitter::no_empties); + if(words.size() > 0) + { + bbDescription += words[0]; + for (int i = 1; i < words.size(); i++) + { + bbDescription += words[i]; + } + } + + if(bbDescription == "") + bbDescription = "No Description."; + + + //create command + std::string command = "bbCreateBlackBox"; + command += " \"" + this->path + "\""; + command += " \"" + package + "\""; + command += " \"" + bbName + "\""; + command += " \"" + type + "\""; + command += " \"" + format + "\""; + command += " \"" + bbAuthors + "\""; + command += " \"" + bbDescription + "\""; + command += " \"" + bbCategories + "\""; + + //excecute command + if(system(command.c_str())) + { + result = new std::string("Error executing command '" + command + "'"); + return NULL; + } + + //if command succeed + + //create header + //create source + modelCDMFile* header = NULL; + modelCDMFile* source = NULL; + wxDir dir(crea::std2wx(path)); + if (dir.IsOpened()) + { + wxString fileName; + bool cont = dir.GetFirst(&fileName, crea::std2wx("bb"+package+bbName+".h"), wxDIR_FILES); + if (cont) + { + std::string stdfileName = crea::wx2std(fileName); + header = new modelCDMFile(this->path + stdfileName, stdfileName, this->level+1); + } + cont = dir.GetFirst(&fileName, crea::std2wx("bb"+package+bbName+".cxx"), wxDIR_FILES); + if (cont) + { + std::string stdfileName = crea::wx2std(fileName); + source = new modelCDMFile(this->path + stdfileName, stdfileName, this->level+1); + } + } + //if source and header exist + if (header != NULL && source != NULL) + { + //create black box + modelCDMBlackBox* blackBox = new modelCDMBlackBox(this->path, package+bbName); + + //associate header and source + blackBox->SetHeaderFile(header); + blackBox->SetSourceFile(source); + + this->children.push_back(header); + this->children.push_back(source); + + this->blackBoxes.push_back(blackBox); + + //sort children + std::sort(this->blackBoxes.begin(), this->blackBoxes.end(), CompareNodeItem); + this->SortChildren(); + + return blackBox; + } + else + { + result = new std::string("The header and source files were not found. Black box not created."); + return NULL; + } } const bool modelCDMPackageSrc::Refresh(std::string*& result) { + std::cout << "refreshing package src" << std::endl; //set attributes this->type = wxDIR_DIRS; @@ -164,7 +296,7 @@ const bool modelCDMPackageSrc::Refresh(std::string*& result) std::string folderName = stdfileName; //check if they already exist bool found = false; - for (int i = 0;!found && i < this->children.size(); i++) + for (int i = 0; !found && i < this->children.size(); i++) { if (this->children[i]->GetName() == folderName) { @@ -207,7 +339,7 @@ const bool modelCDMPackageSrc::Refresh(std::string*& result) else { bool found = false; - for (int i = 0; i children.size(); i++) + for (int i = 0; !found && i < this->children.size(); i++) { if (this->children[i]->GetName() == stdfileName) { @@ -275,5 +407,6 @@ const bool modelCDMPackageSrc::Refresh(std::string*& result) } } this->SortChildren(); + std::sort(this->blackBoxes.begin(), this->blackBoxes.end(), CompareNodeItem); return true; } diff --git a/lib/creaDevManagerLib/modelCDMPackageSrc.h b/lib/creaDevManagerLib/modelCDMPackageSrc.h index d94afbd..bb799c3 100644 --- a/lib/creaDevManagerLib/modelCDMPackageSrc.h +++ b/lib/creaDevManagerLib/modelCDMPackageSrc.h @@ -51,6 +51,7 @@ public: const std::vector& GetBlackBoxes() const; modelCDMBlackBox* CreateBlackBox( + std::string*& result, const std::string& name, const std::string& package, const std::string& type = "std", diff --git a/lib/creaDevManagerLib/modelCDMProject.cpp b/lib/creaDevManagerLib/modelCDMProject.cpp index 8206a75..c844798 100644 --- a/lib/creaDevManagerLib/modelCDMProject.cpp +++ b/lib/creaDevManagerLib/modelCDMProject.cpp @@ -59,6 +59,7 @@ modelCDMProject::modelCDMProject( const std::string& buildPath ) { + std::cout << "creating project: " + name + " in " + path + "\n"; this->path = CDMUtilities::fixPath(path); //open makelists file std::string pathFixed(CDMUtilities::fixPath(path)); @@ -202,6 +203,7 @@ modelCDMProject::modelCDMProject( } this->SortChildren(); + std::sort(this->packages.begin(), this->packages.end(), CompareNodeItem); } @@ -545,11 +547,10 @@ const bool modelCDMProject::Refresh(std::string*& result) //if package , create package else if(stdfileName.size() > 9 && stdfileName.substr(0,5) == "bbtk_" && stdfileName.substr(stdfileName.size()-4,4) == "_PKG") { - std::string packageName = stdfileName.substr(5, stdfileName.size()-9); bool found = false; - for (int i = 0;!found && i < this->packages.size(); i++) + for (int i = 0; !found && i < this->packages.size(); i++) { - if (this->packages[i]->GetName() == packageName) + if (this->packages[i]->GetName() == stdfileName) { found = true; int pos = std::find(this->children.begin(), this->children.end(), this->packages[i]) - this->children.begin(); @@ -561,7 +562,7 @@ const bool modelCDMProject::Refresh(std::string*& result) } if(!found) { - modelCDMPackage* package = new modelCDMPackage(this->path + CDMUtilities::SLASH + stdfileName, stdfileName,this->level + 1); + modelCDMPackage* package = new modelCDMPackage(this->path + CDMUtilities::SLASH + stdfileName, stdfileName, this->level + 1); this->packages.push_back(package); this->children.push_back(package); } @@ -617,7 +618,7 @@ const bool modelCDMProject::Refresh(std::string*& result) else { bool found = false; - for (int i = 0; i children.size(); i++) + for (int i = 0; !found && i < this->children.size(); i++) { if (this->children[i]->GetName() == stdfileName) { @@ -658,7 +659,9 @@ const bool modelCDMProject::Refresh(std::string*& result) i--; } } + this->SortChildren(); + std::sort(this->packages.begin(), this->packages.end(), CompareNodeItem); return true; } diff --git a/lib/creaDevManagerLib/wxCDMMainFrame.cpp b/lib/creaDevManagerLib/wxCDMMainFrame.cpp index ed3b6de..7f5fc3a 100755 --- a/lib/creaDevManagerLib/wxCDMMainFrame.cpp +++ b/lib/creaDevManagerLib/wxCDMMainFrame.cpp @@ -899,6 +899,7 @@ void wxCDMMainFrame::OnCreationComplete(wxCommandEvent& event) } else if(event.GetString() == wxT("blackbox")) { + this->tree_Projects->SelectItem(this->model->GetProject()->GetId(), false); modelCDMBlackBox* bb = (modelCDMBlackBox*)event.GetClientData(); description = new wxCDMBlackBoxDescriptionPanel( this, diff --git a/lib/creaDevManagerLib/wxCDMPackageDescriptionPanel.cpp b/lib/creaDevManagerLib/wxCDMPackageDescriptionPanel.cpp index 4411c9e..00858bd 100644 --- a/lib/creaDevManagerLib/wxCDMPackageDescriptionPanel.cpp +++ b/lib/creaDevManagerLib/wxCDMPackageDescriptionPanel.cpp @@ -39,6 +39,7 @@ #include "creaDevManagerIds.h" #include "images/PkIcon64.xpm" +#include "wxCDMNewBlackBoxDialog.h" #include #include "CDMUtilities.h" @@ -325,9 +326,45 @@ void wxCDMPackageDescriptionPanel::OnLnkBlackBoxSelect(wxHyperlinkEvent& event) void wxCDMPackageDescriptionPanel::OnBtnCreateBlackBox(wxCommandEvent& event) { - //TODO: implement method - std::cerr << "Event OnBtnCreateBlackBox not implemented" << std::endl; - event.Skip(); + + wxCDMNewBlackBoxDialog* dialog = new wxCDMNewBlackBoxDialog(this); + long userResponse; + userResponse = dialog->ShowModal(); + + if(userResponse == wxID_FORWARD) + { + std::string* result; + //create black box + modelCDMIProjectTreeNode* blackBox = this->package->CreateBlackBox( + result, + crea::wx2std(dialog->GetBlackBoxName()), + crea::wx2std(dialog->GetBlackBoxType()), + crea::wx2std(dialog->GetBlackBoxFormat()), + crea::wx2std(dialog->GetBlackBoxCategories()), + crea::wx2std(dialog->GetBlackBoxAuthor()), + crea::wx2std(dialog->GetBlackBoxAuthorEmail()), + crea::wx2std(dialog->GetBlackBoxDescription()) + ); + //check black box created + if(blackBox == NULL) + { + wxMessageBox(crea::std2wx(*result),_T("New Black Box - Error!"),wxOK | wxICON_ERROR); + return; + } + wxMessageBox(crea::std2wx("Black box successfully created."),_T("New Black Box - Success!"),wxOK | wxICON_INFORMATION); + + //refreshing tree and description + //send event instead of calling parent to avoid crashing + + ((wxCDMMainFrame*)this->GetParent())->RefreshProject(); + + wxCommandEvent* newEvent = new wxCommandEvent(wxEVT_DISPLAY_CHANGED); + newEvent->SetId(1); + newEvent->SetInt(blackBox->GetId()); + newEvent->SetString(wxT("blackbox")); + newEvent->SetClientData(blackBox); + wxPostEvent(this->GetParent(), *newEvent); + } } void wxCDMPackageDescriptionPanel::OnBtnEditCMakeLists(wxCommandEvent& event) -- 2.45.1