void DCContainer::beganParsePage(const char *docRoot, const char *path)
{
- QDir workCellDir(d_workDirCellRoot + "/" + QString::fromLocal8Bit(path));
- QDir workCellCodeDir(d_workDirCellCodeRoot + "/" + QString::fromLocal8Bit(path));
+ QDir workCellDir(d_workDirCellRoot + QString::fromLocal8Bit(path));
+ QDir workCellCodeDir(d_workDirCellCodeRoot + QString::fromLocal8Bit(path));
if (!workCellDir.exists())
{
workCellDir.mkpath(workCellDir.absolutePath());
return false;
}
-bool DCContainer::saveCustomScriptToWorkFile(DCCell *cell, std::string customScript)
+bool DCContainer::saveCustomScriptToWorkFile(const DCCell *cell, std::string customScript)
{
- QDir workdir(d_workDirCellRoot + "/" + QString::fromStdString(cell->getLocation()));
+ QDir workdir(d_workDirCellRoot + QString::fromStdString(cell->getLocation()));
if (!workdir.exists())
{
workdir.mkpath(workdir.absolutePath());
return true;
}
-bool DCContainer::saveClassScriptToWorkFile(DCCellCode *cellCode, std::string code)
+bool DCContainer::saveClassScriptToWorkFile(const DCCellCode *cellCode, std::string code)
{
QString qNamePath = QString::fromStdString(cellCode->getFQNName());
QString path = DCUtil::getContainerBasedPathFromFQNPath(qNamePath);
QString name = DCUtil::getNameFromFQNPath(qNamePath);
- QDir workdir(d_workDirCellCodeRoot + "/" + path);
+ if (name.length() == 0)
+ return false;
+
+ QDir workdir(d_workDirCellCodeRoot + path);
if (!workdir.exists())
{
workdir.mkpath(workdir.absolutePath());
QString DCContainer::readCustomScriptFromWorkFile(const DCCell *cell)
{
- QFile file(d_workDirCellRoot + "/" + QString::fromStdString(cell->getLocation()) + "/" + QString::fromStdString(cell->getName()) + ".js");
+ QFile file(d_workDirCellRoot + QString::fromStdString(cell->getLocation()) + "/" + QString::fromStdString(cell->getName()) + ".js");
if (!file.exists())
{
QString path = DCUtil::getContainerBasedPathFromFQNPath(qNamePath);
QString name = DCUtil::getNameFromFQNPath(qNamePath);
- QFile file(d_workDirCellCodeRoot + "/" + path + "/" + name + ".js");
+ if (name.length() == 0)
+ return false;
+
+ QFile file(d_workDirCellCodeRoot + path + "/" + name + ".js");
if (!file.exists())
{
return "";
bool DCContainer::renameCell(DCCell *cell, const QString &newName)
{
- QString fqnName = DCUtil::getFQNPath(cell->getLocation(), cell->getName());
- mCells.erase(fqnName.toStdString());
+ QString oldFqnName = DCUtil::getFQNPath(cell->getLocation(), cell->getName());
+ QString oldName = QString::fromStdString(cell->getName());
+
+ if (oldName == newName)
+ return true;
+
+ QString customScript = readCustomScriptFromWorkFile(cell);
+ QDir workDir(d_workDirCellRoot + QString::fromStdString(cell->getLocation()));
+ QFile workFileOld(workDir.absoluteFilePath(QString::fromStdString(cell->getName()) + ".js"));
cell->changeName(newName);
+ if (!saveCustomScriptToWorkFile(cell, customScript.toStdString()))
+ {
+ cell->changeName(oldName);
+ return false;
+ }
+ workFileOld.remove();
+ mCells.erase(oldFqnName.toStdString());
QString newFqnName = DCUtil::getFQNPath(cell->getLocation(), cell->getName());
std::pair<TKCellMap::iterator, bool> r = mCells.insert(TKCellMap::value_type(newFqnName.toStdString(), cell));
bool DCContainer::moveCell(DCCell *cell, const QString& pageNewContainerBasedPathName)
{
- QString fqnName = DCUtil::getFQNPath(cell->getLocation(), cell->getName());
+ QString oldFqnName = DCUtil::getFQNPath(cell->getLocation(), cell->getName());
+ QString oldContainerPath = QString::fromStdString(cell->getLocation());
+
+ if (oldContainerPath == pageNewContainerBasedPathName)
+ return true;
+
QString customScript = readCustomScriptFromWorkFile(cell);
- mCells.erase(fqnName.toStdString());
+ QDir workDirOld(d_workDirCellRoot + QString::fromStdString(cell->getLocation()));
+ QFile workFileOld(workDirOld.absoluteFilePath(QString::fromStdString(cell->getName()) + ".js"));
cell->changePath(pageNewContainerBasedPathName);
- saveCustomScriptToWorkFile(cell, customScript.toStdString());
+ if (!saveCustomScriptToWorkFile(cell, customScript.toStdString()))
+ {
+ cell->changePath(oldContainerPath);
+ return false;
+ }
+ workFileOld.remove();
+ mCells.erase(oldFqnName.toStdString());
QString newFqnName = DCUtil::getFQNPath(pageNewContainerBasedPathName.toStdString(), cell->getName());
std::pair<TKCellMap::iterator, bool> r = mCells.insert(TKCellMap::value_type(newFqnName.toStdString(), cell));
bool DCContainer::renameCellCodeClass(DCCellCode *cellcode, const QString &newName)
{
- mCellCodes.erase(cellcode->getFQNName());
+ QString oldFqnName = QString::fromStdString(cellcode->getFQNName());
+ QString oldPath = DCUtil::getContainerBasedPathFromFQNPath(oldFqnName);
+ QString oldName = DCUtil::getNameFromFQNPath(oldFqnName);
+
+ if (oldName == newName)
+ return true;
+
+ QFile oldFile(d_workDirCellCodeRoot + oldPath + "/" + oldName + ".js");
+ QString script = readCellCodeScriptFromFile(cellcode);
+
cellcode->changeName(newName);
+ if (!saveClassScriptToWorkFile(cellcode, script.toStdString()))
+ {
+ cellcode->changeName(oldName);
+ return false;
+ }
+ oldFile.remove();
+ mCellCodes.erase(oldFqnName.toStdString());
+
std::pair<TKCellCodeMap::iterator, bool> r = mCellCodes.insert(TKCellCodeMap::value_type(cellcode->getFQNName(), cellcode));
return r.second;
bool DCContainer::moveCellCodeClass(DCCellCode *cellcode, const QString& pageNewContainerBasedPathName)
{
+ QString oldFqnName = QString::fromStdString(cellcode->getFQNName());
+ QString oldPath = DCUtil::getContainerBasedPathFromFQNPath(oldFqnName);
+ QString oldName = DCUtil::getNameFromFQNPath(oldFqnName);
+
+ if (oldPath == pageNewContainerBasedPathName)
+ return true;
+
+ QFile oldFile(d_workDirCellCodeRoot + oldPath + "/" + oldName + ".js");
QString script = readCellCodeScriptFromFile(cellcode);
- mCellCodes.erase(cellcode->getFQNName());
cellcode->changePath(pageNewContainerBasedPathName);
- saveClassScriptToWorkFile(cellcode, script.toStdString());
+ if (!saveClassScriptToWorkFile(cellcode, script.toStdString()))
+ {
+ cellcode->changePath(oldPath);
+ return false;
+ }
+ oldFile.remove();
+ mCellCodes.erase(oldFqnName.toStdString());
std::pair<TKCellCodeMap::iterator, bool> r = mCellCodes.insert(TKCellCodeMap::value_type(cellcode->getFQNName(), cellcode));