OSDN Git Service

[denncoCreator] Some code refactoring to implement the feature to support external...
authortkawata <tkawata@users.sourceforge.jp>
Sat, 1 Dec 2012 05:17:25 +0000 (14:17 +0900)
committertkawata <tkawata@users.sourceforge.jp>
Sat, 1 Dec 2012 05:17:25 +0000 (14:17 +0900)
Source/codeeditor/dccellscriptseditorpagewidget.cpp
Source/dccell.cpp
Source/dccell.h
Source/dccellcode.cpp
Source/dccellcode.h
Source/dccontainer.cpp
Source/dccontainer.h
Source/utils/dcskeltoncreatorutil.cpp
Source/utils/dcutil.cpp

index 0357882..31e7e23 100644 (file)
@@ -73,6 +73,7 @@ DCCellScriptsEditorPageWidget::DCCellScriptsEditorPageWidget(DCCell *targetCell,
 
 DCCellScriptsEditorPageWidget::~DCCellScriptsEditorPageWidget()
 {
+    disconnect(d_cell, 0, this, 0);
     this->disconnect();
 }
 
index 9e4cc7a..fff7e6c 100644 (file)
@@ -192,6 +192,16 @@ void DCCell::getViewVCrossPoint(float dx, float dy, float *outX, float *outY) co
     //TODO
 }
 
+QString DCCell::getWorkFilePathForCustomScript() const
+{
+    DCContainer *container = dynamic_cast<DCContainer*>(getContainer());
+    if (container)
+    {
+        return container->getWorkFilePathForCustomScript(this);
+    }
+    return "";
+}
+
 void DCCell::setViewPageX(float x)
 {
     d_vComponent->setPageX(x);
index 216ee61..25fa565 100644 (file)
@@ -91,6 +91,7 @@ public:
     float               getViewHeight() const;
     void                getViewHCrossPoint(float dx, float dz, float *outX, float *outZ) const;
     void                getViewVCrossPoint(float dx, float dy, float *outX, float *outY) const;
+    QString             getWorkFilePathForCustomScript() const;
 
     void                setViewPageX(float x);
     void                setViewPageY(float y);
index 7a1cfaa..fac6c73 100644 (file)
@@ -36,6 +36,16 @@ QString DCCellCode::getOwnScript() const
     return d_container->readCellCodeScriptFromFile(this);
 }
 
+QString DCCellCode::getWorkFilePathForCellCodeScript() const
+{
+    DCContainer *container = dynamic_cast<DCContainer*>(getContainer());
+    if (container)
+    {
+        return container->getWorkFilePathForCellCode(this);
+    }
+    return "";
+}
+
 bool DCCellCode::saveScript(const QString &script)
 {
     return d_container->saveClassScriptToWorkFile(this, script.toStdString());
index 9d7aca3..b70dfab 100644 (file)
@@ -56,11 +56,13 @@ public:
     virtual ~DCCellCode();
     virtual TKCellCodeInstance* createCellCodeInstance(TKCell *owner, const void *data) { return 0; }
 
-    bool                saveScript(const QString& script);
     DCVPageComponent*   getVComponent() const { return d_vComponent; }
     DCVCPage*           getPageBelonging() const;
     QString             getOwnScript() const;
     DCContainer*        getContainer() const { return d_container; }
+    QString             getWorkFilePathForCellCodeScript() const;
+
+    bool                saveScript(const QString& script);
 
     /**
       * Change the API type of this cell.
index e246888..7ff074b 100644 (file)
@@ -78,7 +78,7 @@ bool DCContainer::getIsModified() const
     }
 }
 
-bool DCContainer::isScriptableCell(DCCell *cell)
+bool DCContainer::isScriptableCell(DCCell *cell) const
 {
     bool    noScript = false;
 
@@ -354,12 +354,14 @@ bool DCContainer::removeCell(DCCell *cell)
 
 bool DCContainer::saveCustomScriptToWorkFile(const DCCell *cell, std::string customScript)
 {
-    QDir workdir(d_workDirCellRoot + QString::fromStdString(cell->getLocation()));
-    if (!workdir.exists())
+    QFile workfile(getWorkFilePathForCustomScript(cell));
+    QFileInfo fileInfo(workfile);
+    if (!fileInfo.absoluteDir().exists())
     {
-        workdir.mkpath(workdir.absolutePath());
+        QDir dir;
+        dir.mkpath(fileInfo.absolutePath());
     }
-    QFile workfile(workdir.absoluteFilePath(QString::fromStdString(cell->getName()) + ".js"));
+
     workfile.open(QIODevice::WriteOnly);
     QTextStream out(&workfile);
     out << QString::fromStdString(customScript);
@@ -370,18 +372,18 @@ bool DCContainer::saveCustomScriptToWorkFile(const DCCell *cell, std::string cus
 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);
 
     if (name.length() == 0)
         return false;
 
-    QDir workdir(d_workDirCellCodeRoot + path);
-    if (!workdir.exists())
+    QFile workfile(getWorkFilePathForCellCode(cellCode));
+    QFileInfo fileInfo(workfile);
+    if (!fileInfo.absoluteDir().exists())
     {
-        workdir.mkpath(workdir.absolutePath());
+        QDir dir;
+        dir.mkpath(fileInfo.absolutePath());
     }
-    QFile workfile(workdir.absoluteFilePath(name + ".js"));
     workfile.open(QIODevice::WriteOnly);
     QTextStream out(&workfile);
     out << QString::fromStdString(code);
@@ -391,7 +393,7 @@ bool DCContainer::saveClassScriptToWorkFile(const DCCellCode *cellCode, std::str
 
 QString DCContainer::readCustomScriptFromWorkFile(const DCCell *cell)
 {
-    QFile file(d_workDirCellRoot + QString::fromStdString(cell->getLocation()) + "/" + QString::fromStdString(cell->getName()) + ".js");
+    QFile file(getWorkFilePathForCustomScript(cell));
 
     if (!file.exists())
     {
@@ -409,13 +411,12 @@ QString DCContainer::readCustomScriptFromWorkFile(const DCCell *cell)
 QString DCContainer::readCellCodeScriptFromFile(const DCCellCode *cellCode)
 {
     QString qNamePath = QString::fromStdString(cellCode->getFQNName());
-    QString path = DCUtil::getContainerBasedPathFromFQNPath(qNamePath);
     QString name = DCUtil::getNameFromFQNPath(qNamePath);
 
     if (name.length() == 0)
         return false;
 
-    QFile file(d_workDirCellCodeRoot + path + "/" + name + ".js");
+    QFile file(getWorkFilePathForCellCode(cellCode));
     if (!file.exists())
     {
         return "";
@@ -450,8 +451,7 @@ bool DCContainer::renameCell(DCCell *cell, const QString &newName)
         return true;
 
     QString customScript = readCustomScriptFromWorkFile(cell);
-    QDir workDir(d_workDirCellRoot + QString::fromStdString(cell->getLocation()));
-    QFile workFileOld(workDir.absoluteFilePath(QString::fromStdString(cell->getName()) + ".js"));
+    QFile workFileOld(getWorkFilePathForCustomScript(cell));
 
     cell->changeName(newName);
     if (!saveCustomScriptToWorkFile(cell, customScript.toStdString()))
@@ -477,8 +477,7 @@ bool DCContainer::moveCell(DCCell *cell, const QString& pageNewContainerBasedPat
         return true;
 
     QString customScript = readCustomScriptFromWorkFile(cell);
-    QDir workDirOld(d_workDirCellRoot + QString::fromStdString(cell->getLocation()));
-    QFile workFileOld(workDirOld.absoluteFilePath(QString::fromStdString(cell->getName()) + ".js"));
+    QFile workFileOld(getWorkFilePathForCustomScript(cell));
 
     cell->changePath(pageNewContainerBasedPathName);
     if (!saveCustomScriptToWorkFile(cell, customScript.toStdString()))
@@ -503,7 +502,7 @@ bool DCContainer::renameCellCodeClass(DCCellCode *cellcode, const QString &newNa
     if (oldName == newName)
         return true;
 
-    QFile oldFile(d_workDirCellCodeRoot + oldPath + "/" + oldName + ".js");
+    QFile oldFile(getWorkFilePathForCellCode(cellcode));
     QString script = readCellCodeScriptFromFile(cellcode);
 
     cellcode->changeName(newName);
@@ -529,7 +528,7 @@ bool DCContainer::moveCellCodeClass(DCCellCode *cellcode, const QString& pageNew
     if (oldPath == pageNewContainerBasedPathName)
         return true;
 
-    QFile oldFile(d_workDirCellCodeRoot + oldPath + "/" + oldName + ".js");
+    QFile oldFile(getWorkFilePathForCellCode(cellcode));
     QString script = readCellCodeScriptFromFile(cellcode);
 
     cellcode->changePath(pageNewContainerBasedPathName);
@@ -653,3 +652,18 @@ bool DCContainer::getIsReceptorAvailable(const QString& type) const
     return false;
 }
 
+QString DCContainer::getWorkFilePathForCustomScript(const DCCell *cell) const
+{
+    QDir workdir(d_workDirCellRoot + QString::fromStdString(cell->getLocation()));
+    return workdir.absoluteFilePath(QString::fromStdString(cell->getName()) + ".js");
+}
+
+QString DCContainer::getWorkFilePathForCellCode(const DCCellCode *cellCode) const
+{
+    QString qNamePath = QString::fromStdString(cellCode->getFQNName());
+    QString path = DCUtil::getContainerBasedPathFromFQNPath(qNamePath);
+    QString name = DCUtil::getNameFromFQNPath(qNamePath);
+
+    QDir workdir(d_workDirCellCodeRoot + path);
+    return workdir.absoluteFilePath(name + ".js");
+}
index 4a2d6de..4e5f6b3 100644 (file)
@@ -51,7 +51,18 @@ public:
     DCContainer();
     virtual ~DCContainer();
 
-    bool getIsModified() const;
+    bool                    getIsModified() const;
+
+    DCContent*              getContent() const { return d_content; }
+    DCScene*                getScene() const { return d_scene; }
+    QList<DCVComponent*>    getSelectedCellObjects() const;
+    virtual float           getValue(std::string key) const { Q_UNUSED(key); return 0; }
+
+    TKCellCode*             getEmptyCellCodeClass() const { return mEmptyCellClass; }
+    bool                    isScriptableCell(DCCell *cell) const;
+
+    QString                 getWorkFilePathForCustomScript(const DCCell *cell) const;
+    QString                 getWorkFilePathForCellCode(const DCCellCode *cellcode) const;
 
     virtual TKCell*         addCell(std::string theLocation, std::string theName, std::string type, std::string customScript);
     virtual TKCell*         addCell(std::string theLocation, std::string theName, TKCellCode *cellCode, std::string customScript);
@@ -125,16 +136,6 @@ public:
 
     bool                    renameCellCodeClass(DCCellCode *cellcode, const QString& newName);
 
-    //
-    DCContent*              getContent() const { return d_content; }
-    DCScene*                getScene() const { return d_scene; }
-    QList<DCVComponent*>    getSelectedCellObjects() const;
-    virtual float           getValue(std::string key) const { Q_UNUSED(key); return 0; }
-
-    TKCellCode*             getEmptyCellCodeClass() const { return mEmptyCellClass; }
-    bool                    isScriptableCell(DCCell *cell);
-
-    //
     void                    setContent(DCContent *content);
 
     void                    unselectCellObjectAll();
@@ -156,7 +157,6 @@ public:
     QString                 readCustomScriptFromWorkFile(const DCCell *cell);
     QString                 readCellCodeScriptFromFile(const DCCellCode *cellcode);
 
-
     /***************************************************************************
      * Cell type rules
      **************************************************************************/
index 6b9df11..953c7d6 100644 (file)
@@ -107,7 +107,6 @@ bool DCSkeltonCreatorUtil::createNewContent(const QString &contentRootPath)
     {
         QMessageBox msgBox;
         msgBox.setText(tr("ERROR! Failed to create a directory"));
-        DCUtil::removeDirRecursive(contentRootPath);
         return false;
     }
 
@@ -122,7 +121,6 @@ bool DCSkeltonCreatorUtil::createNewContent(const QString &contentRootPath)
     {
         QMessageBox msgBox;
         msgBox.setText(tr("ERROR! Failed to create a directory"));
-        DCUtil::removeDirRecursive(contentRootPath);
         return false;
     }
 
index 99121a0..2a918a4 100644 (file)
@@ -26,6 +26,9 @@
 //static
 void DCUtil::removeDirRecursive(QString path)
 {
+    if (path.isEmpty() || path.length() == 0)
+        return;
+
     QDir  dir(path);
 
     QFileInfoList list = dir.entryInfoList(QDir::NoDot | QDir::NoDotDot | QDir::AllEntries);