OSDN Git Service

[denncoCreator] fixed a bug. Scripts were not moved properly when a cell was moved...
authortkawata <tkawata@users.sourceforge.jp>
Mon, 26 Nov 2012 16:32:53 +0000 (01:32 +0900)
committertkawata <tkawata@users.sourceforge.jp>
Mon, 26 Nov 2012 16:32:53 +0000 (01:32 +0900)
Source/dccontainer.cpp
Source/dccontainer.h
Source/denncoCreator.pro

index 443973d..e246888 100644 (file)
@@ -266,8 +266,8 @@ TKCellCode* DCContainer::cellCodeFactory(std::string name, std::string cellapi,
 
 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());
@@ -352,9 +352,9 @@ bool DCContainer::removeCell(DCCell *cell)
     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());
@@ -367,13 +367,16 @@ bool DCContainer::saveCustomScriptToWorkFile(DCCell *cell, std::string customScr
     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());
@@ -388,7 +391,7 @@ bool DCContainer::saveClassScriptToWorkFile(DCCellCode *cellCode, std::string co
 
 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())
     {
@@ -409,7 +412,10 @@ QString DCContainer::readCellCodeScriptFromFile(const DCCellCode *cellCode)
     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 "";
@@ -437,10 +443,24 @@ QString DCContainer::containerBasedPathToSysFilePath(const QString &containerBas
 
 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));
@@ -450,12 +470,24 @@ bool DCContainer::renameCell(DCCell *cell, const QString &newName)
 
 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));
@@ -464,8 +496,25 @@ bool DCContainer::moveCell(DCCell *cell, const QString& pageNewContainerBasedPat
 
 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;
@@ -473,11 +522,24 @@ bool DCContainer::renameCellCodeClass(DCCellCode *cellcode, const QString &newNa
 
 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));
 
index 156b88f..4a2d6de 100644 (file)
@@ -147,8 +147,8 @@ public:
     void                    beganBuildContainer();
     void                    endedBuildContainer();
 
-    bool                    saveCustomScriptToWorkFile(DCCell *cell, std::string customScript);
-    bool                    saveClassScriptToWorkFile(DCCellCode *cellCode, std::string code);
+    bool                    saveCustomScriptToWorkFile(const DCCell *cell, std::string customScript);
+    bool                    saveClassScriptToWorkFile(const DCCellCode *cellCode, std::string code);
 
     QString                 sysFilePathToContainerBasedPath(const QString& sysFilePath);
     QString                 containerBasedPathToSysFilePath(const QString& containerBasedPath);
index 61c580e..032eddb 100644 (file)
@@ -98,7 +98,8 @@ HEADERS       = mainwindow.h \
     codeeditor/dccellscriptseditorwindow.h \
     codeeditor/dccellscriptseditortabwidget.h \
     codeeditor/dccellscriptseditorpagewidget.h \
-    dialog/dcmanagecellcodedialog.h
+    dialog/dcmanagecellcodedialog.h \
+    engine/versioninfo.h
 
 SOURCES       = main.cpp \
                 mainwindow.cpp \