void Workspace::RenameProject(QString projectName) { Project * project = FindProject(projectName); if (project == NULL) { return; } GetUserString * user = new GetUserString(); QString newName = user->GetNewName(projectName, false); if (newName == "") { return; } newName = QFileInfo(newName).baseName(); QString newPath = QFileInfo(newName).baseName(); QString oldPath = config.workspace + "/" + projectName; if (QDir().rename(oldPath, config.workspace + "/" + newPath) == false) { ErrorMessage("Error while renaming the project!\n"); return; } oldPath = config.workspace + "/" + newPath + "/" + projectName + ".mmproj"; newPath = config.workspace + "/" + newPath + "/" + newName + ".mmproj"; if (QFile(oldPath).rename(newPath) == false) { ErrorMessage("Error while renaming the project definiton file. You'll need to do that manually.\n\nYou won't be able to load this project while this is not fixed"); } project->name = newName; SetCurrentProject(newName); modified = true; }
void Workspace::RemoveProject(QString projectName) { Project * project = FindProject(projectName); if (project == NULL) { return; } if (GetUserConfirmation("Confirm deleting this whole project?\n\n" + projectName) == false) { return; } QString path = config.workspace + "/" + projectName; QDir(path).removeRecursively(); if (QDir(path).exists()) { ErrorMessage("Could not remove the project files. Please delete them manually."); return; } for (int i=0; i < projects.size(); i++) { if (projects.at(i).name == projectName) { projects.erase(projects.begin() + i); break; } } if (projects.size() > 0) { SetCurrentProject(projects.at(0).name); } modified = true; }
void ProjectManager::ProccessFileOpenRequests() { if (!m_requestedProjectFileNameToOpen.empty()) { SetCurrentProject(m_requestedProjectFileNameToOpen.c_str()); SetCurrentFile(m_requestedProjectFileNameToOpen.c_str()); SaveLastDir(Platform::GetFileDirectory(m_requestedProjectFileNameToOpen.c_str()).c_str()); } m_requestedProjectFileNameToOpen.clear(); }
bool ProjectManager::Open() { char filter[] = "Ethanon Project files (*.ethproj)\0*.ethproj\0\0"; char path[512], file[512]; string sLastDir = ReadLastDir(); if (OpenForm(filter, "", path, file, sLastDir.c_str())) { SetCurrentProject(path); SetCurrentFile(path); SaveLastDir(ETHGlobal::GetPathName(path, true).c_str()); } return true; }
bool Workspace::Open(QString workPath) { QDir dir; dir.setPath(workPath); projects.clear(); if (dir.exists() == false) { return false; } config.workspace = workPath; bool ok = true; dir.setFilter(QDir::Dirs | QDir::Hidden | QDir::NoSymLinks); QFileInfoList list = dir.entryInfoList(); for (int i = 0; i < list.size(); ++i) { QFileInfo fileInfo = list.at(i); QString projectName = fileInfo.fileName(); if ((projectName == ".") || (projectName == "..")) { continue; } if (projectName.contains(".ignore") == false) { QString projectPath = QDir::cleanPath(config.workspace + QDir::separator()); Project proj; if (proj.Load(projectPath, projectName)) { projects.push_back(proj); } else { msg.Add("Could not load project '" + projectPath + "/" + projectName + "'", mtError); //ok = false; } } } //currentProject = ""; //if (projects.size() > 0) { //SetCurrentProject(projects.at(0).name); //} if (GetCurrentProject() == NULL) { if (projects.size() > 0) { SetCurrentProject(projects.at(0).name); } } return ok; }
bool Workspace::AddProject(QString name, QString importSketch) { QString path = config.workspace; // Force renaming the project name if another project with the same name already exists int aux = 0; QString auxName = name; bool ok = true; do { ok = QDir().mkdir(path + "/" + auxName); if (ok == false) { aux++; auxName = name + "_" + QString::number(aux); } } while ((ok == false) && (aux < 50)); if (aux >= 50) { return false; } name = auxName; path = path + "/" + name; QDir().mkdir(path + "/source"); Project project; project.name = name; if (importSketch == "") { CopyFileToProject(qApp->applicationDirPath() + "/templates/main.cpp", project.name + ".cpp", &project); //CopyFileToProject(qApp->applicationDirPath() + "/templates/main.h", "main.h", &project); CopyFileToProject(qApp->applicationDirPath() + "/templates/mariamole_auto_generated.h", "mariamole_auto_generated.h", &project); } else { if (ImportSketch(&project, importSketch) == false) { return false; } } projects.push_back(project); modified = true; if (ok) { SetCurrentProject(project.name); } return true; }
bool ProjectManager::SaveAs() { FILE_FORM_FILTER filter(GS_L("Ethanon Project files (*.ethproj)"), GS_L("ethproj")); char path[___OUTPUT_LENGTH], file[___OUTPUT_LENGTH]; std::string sLastDir = ReadLastDir(); if (SaveForm(filter, sLastDir.c_str(), path, file)) { std::string sOut; AddExtension(path, ".ethproj", sOut); std::ofstream ofs(sOut.c_str()); if (ofs.is_open()) { ofs << "Ethanon Engine project file"; ofs.close(); } SetCurrentFile(sOut.c_str()); SetCurrentProject(sOut.c_str()); SaveLastDir(Platform::GetFileDirectory(sOut.c_str()).c_str()); PrepareProjectDir(); } return true; }
bool ProjectManager::SaveAs() { char filter[] = "Ethanon Project files (*.ethproj)\0*.ethproj\0\0"; char path[___OUTPUT_LENGTH], file[___OUTPUT_LENGTH]; string sLastDir = ReadLastDir(); if (SaveForm(filter, "", path, file, sLastDir.c_str())) { string sOut; AddExtension(path, ".ethproj", sOut); std::ofstream ofs(sOut.c_str()); if (ofs.is_open()) { ofs << "Ethanon Engine project file"; ofs.close(); } SetCurrentFile(sOut.c_str()); SetCurrentProject(sOut.c_str()); SaveLastDir(ETHGlobal::GetPathName(sOut.c_str(), true).c_str()); PrepareProjectDir(); } return true; }