/*! Saves the project in the specified path. The TfilePath fp must be an absolute path. The project is saved as a xml file.\n Uses TProjectManager and TOStream. \note Exceptions can be thrown. \see TProjectManager and TOStream. */ bool TProject::save(const TFilePath &projectPath) { assert(isAProjectPath(projectPath)); TProjectManager *pm = TProjectManager::instance(); m_name = pm->projectPathToProjectName(projectPath); m_path = getLatestVersionProjectPath(projectPath); TFilePath projectFolder = projectPath.getParentDir(); if (!TFileStatus(projectFolder).doesExist()) { try { TSystem::mkDir(projectFolder); } catch (...) { return false; } } TFilePath sceneFolder = decode(getFolder(TProject::Scenes)); TFilePath scenesDescPath = sceneFolder + "scenes.xml"; TFileStatus fs(projectPath); if (fs.doesExist() && !fs.isWritable()) { throw TSystemException( projectPath, "Cannot save the project settings. The file is read-only."); return false; } TFileStatus fs2(scenesDescPath); if (fs2.doesExist() && !fs2.isWritable()) { throw TSystemException( projectPath, "Cannot save the project settings. The scenes file is read-only."); return false; } TOStream os(m_path); os.openChild("project"); os.openChild("version"); os << 70 << 1; // Standard version signature: os.closeChild(); // <Major Toonz version number * 10>.<Major version // advancement> os.openChild("folders"); int i = 0; for (i = 0; i < getFolderCount(); i++) { TFilePath folderRelativePath = getFolder(i); if (folderRelativePath == TFilePath()) continue; std::map<std::string, string> attr; string folderName = getFolderName(i); attr["name"] = folderName; attr["path"] = ::to_string(folderRelativePath); // escape() if (getUseScenePath(folderName)) attr["useScenePath"] = "yes"; os.openCloseChild("folder", attr); } os.closeChild(); os.openChild("sceneProperties"); getSceneProperties().saveData(os); os.closeChild(); os.closeChild(); // crea (se necessario) le directory relative ai vari folder for (i = 0; i < getFolderCount(); i++) if (isConstantFolder(i)) { TFilePath fp = getFolder(i); if (fp == TFilePath()) continue; fp = decode(fp); // if(!fp.isAbsolute()) fp = projectFolder + fp; if (!TFileStatus(fp).doesExist()) { try { TSystem::mkDir(fp); } catch (...) { } } } /*-- +scenes だけでなく、全てのProject Folderにscenes.xmlを生成する --*/ std::vector<std::string> foldernames; pm->getFolderNames(foldernames); for (int f = 0; f < foldernames.size(); f++) { TFilePath folderpath = decode(getFolder(foldernames.at(f))); if (folderpath.isEmpty() || !isConstantFolder(f)) continue; TFilePath xmlPath = folderpath + "scenes.xml"; TFileStatus xmlfs(xmlPath); if (xmlfs.doesExist() && !xmlfs.isWritable()) continue; TFilePath relativeProjectFolder = makeRelative(folderpath, m_path.getParentDir()); TOStream os2(xmlPath); std::map<std::string, string> attr; attr["type"] = "projectFolder"; os2.openChild("parentProject", attr); os2 << relativeProjectFolder; os2.closeChild(); } // The project has been successfully saved. In case there are other // project files from older Toonz project versions, those files are // renamed so that older Toonz versions can no longer 'see' it. if (!isFolderUnderVersionControl(projectFolder)) hideOlderProjectFiles(projectFolder); return true; }
ProjectPopup::ProjectPopup(bool isModal) : Dialog(TApp::instance()->getMainWindow(), isModal, false, "Project") { TProjectManager *pm = TProjectManager::instance(); m_choosePrjLabel = new QLabel(tr("Project:"), this); m_chooseProjectCombo = new QComboBox(); m_prjNameLabel = new QLabel(tr("Project Name:"), this); m_nameFld = new LineEdit(); m_model = new ProjectDirModel; m_treeView = new DvDirTreeView(this); m_nameFld->setMaximumHeight(WidgetHeight); m_treeView->setModel(m_model); m_treeView->setStyleSheet("border:1px solid rgb(120,120,120);"); //----layout m_topLayout->setMargin(5); m_topLayout->setSpacing(10); { m_topLayout->addWidget(m_treeView, 0); QGridLayout *upperLayout = new QGridLayout(); upperLayout->setMargin(5); upperLayout->setHorizontalSpacing(5); upperLayout->setVerticalSpacing(10); { upperLayout->addWidget(m_choosePrjLabel, 0, 0, Qt::AlignRight | Qt::AlignVCenter); upperLayout->addWidget(m_chooseProjectCombo, 0, 1); upperLayout->addWidget(m_prjNameLabel, 1, 0, Qt::AlignRight | Qt::AlignVCenter); upperLayout->addWidget(m_nameFld, 1, 1); } upperLayout->setColumnStretch(0, 0); upperLayout->setColumnStretch(1, 1); std::vector<std::string> folderNames; pm->getFolderNames(folderNames); int i; for (i = 0; i < (int)folderNames.size(); i++) { std::string name = folderNames[i]; QString qName = QString::fromStdString(name); FileField *ff = new FileField(0, qName); m_folderFlds.append(qMakePair(name, ff)); upperLayout->addWidget(new QLabel("+" + qName, this), i + 2, 0, Qt::AlignRight | Qt::AlignVCenter); upperLayout->addWidget(ff, i + 2, 1); } struct { QString name; std::string folderName; } cbs[] = {{tr("Append $scenepath to +drawings"), TProject::Drawings}, {tr("Append $scenepath to +inputs"), TProject::Inputs}, {tr("Append $scenepath to +extras"), TProject::Extras}}; int currentRow = upperLayout->rowCount(); for (i = 0; i < tArrayCount(cbs); i++) { CheckBox *cb = new CheckBox(cbs[i].name); cb->setMaximumHeight(WidgetHeight); upperLayout->addWidget(cb, currentRow + i, 1); m_useScenePathCbs.append(qMakePair(cbs[i].folderName, cb)); } m_topLayout->addLayout(upperLayout); } pm->addListener(this); }