OSDN Git Service

[denncoCreator] small refactoring to remove a redundant code.
authortkawata <tkawata@users.sourceforge.jp>
Mon, 11 Feb 2013 03:12:47 +0000 (12:12 +0900)
committertkawata <tkawata@users.sourceforge.jp>
Mon, 11 Feb 2013 03:12:47 +0000 (12:12 +0900)
Source/codeeditor/dccellscriptseditorwindow.cpp
Source/dccontainer.cpp
Source/dccontainer.h

index 74225b9..5defd27 100644 (file)
@@ -318,7 +318,7 @@ void DCCellScriptsEditorWindow::updateWindowState()
             d_cellType->setText(cell->getType());
             DCContainer *container = d_creator->getCurrentContainer();
 
-            if (container->isScriptableCell(cell))
+            if (container->getIsScriptableCell(cell))
             {
                 d_tabWidget->setCurrentTabReadOnly(false);
                 if (cell->getIsCellCodeAssgined())
index 402f54d..9152c1c 100644 (file)
@@ -79,41 +79,9 @@ bool DCContainer::getIsModified() const
     }
 }
 
-bool DCContainer::isScriptableCell(DCCell *cell) const
+bool DCContainer::getIsScriptableCell(const DCCell *cell) const
 {
-    bool    noScript = false;
-
-    std::string type = cell->getType().toStdString();
-
-    if (type == CELLTYPE_JSBASIC || type.length() == 0)
-    {
-        noScript = false;
-    }
-    else if (type == CELLTYPE_IN)
-    {
-        noScript = true;
-    }
-    else if (type == CELLTYPE_OUT)
-    {
-        noScript = true;
-    }
-    else if (type == CELLTYPE_BASICSTORAGE)
-    {
-        noScript = false;
-    }
-    else if (type == CELLTYPE_PLUGIN_IN)
-    {
-        noScript = true;
-    }
-    else if (type == CELLTYPE_PLUGIN_OUT)
-    {
-        noScript = true;
-    }
-    else
-    {
-        Q_ASSERT(0);
-    }
-    return !noScript;
+    return getIsScriptable(cell->getType());
 }
 
 void DCContainer::setContent(DCContent *content)
@@ -199,8 +167,8 @@ TKCell*  DCContainer::addCell(std::string theLocation, std::string theName, TKCe
     QMutexLocker lock(d_scene->getSceneLock());
 
     DCCell *cell = dynamic_cast<DCCell*>(TKContainer::addCell(theLocation, theName, cellCode, customScript));
-
-    saveCustomScriptToWorkFile(cell, customScript);
+    if (cell)
+        saveCustomScriptToWorkFile(cell, customScript);
 
     return cell;
 }
@@ -210,8 +178,8 @@ TKCellCode* DCContainer::addCellCode(std::string theName, std::string theAPIType
     QMutexLocker lock(d_scene->getSceneLock());
 
     DCCellCode *cellCode = dynamic_cast<DCCellCode*>(TKContainer::addCellCode(theName, theAPIType, code));
-
-    saveClassScriptToWorkFile(cellCode, code);
+    if (cellCode)
+        saveClassScriptToWorkFile(cellCode, code);
 
     return cellCode;
 }
@@ -626,6 +594,11 @@ bool DCContainer::getIsScriptable(const QString& type) const
 {
     std::string t = type.toStdString();
 
+    if (t.length() == 0)
+    {
+        return true;
+    }
+
     if (t == TKContainer::CELLTYPE_JSBASIC)
     {
         return true;
index e4cced3..b4151f2 100644 (file)
@@ -59,7 +59,7 @@ public:
     virtual float           getValue(std::string key) const { Q_UNUSED(key); return 0; }
 
     TKCellCode*             getEmptyCellCodeClass() const { return mEmptyCellClass; }
-    bool                    isScriptableCell(DCCell *cell) const;
+    bool                    getIsScriptableCell(const DCCell *cell) const;
 
     QString                 getWorkFilePathForCustomScript(const DCCell *cell) const;
     QString                 getWorkFilePathForCellCode(const DCCellCode *cellcode) const;