OSDN Git Service

[denncoCreator] Implemented cell code manager dialog. The implementation is incomplet...
authortkawata <tkawata@users.sourceforge.jp>
Sat, 3 Nov 2012 16:05:33 +0000 (01:05 +0900)
committertkawata <tkawata@users.sourceforge.jp>
Sat, 3 Nov 2012 16:05:33 +0000 (01:05 +0900)
21 files changed:
Source/codeeditor/dccellscriptseditorpagewidget.cpp
Source/codeeditor/dccellscriptseditorpagewidget.h
Source/codeeditor/dccellscriptseditortabwidget.cpp
Source/codeeditor/dccellscriptseditortabwidget.h
Source/codeeditor/dccellscriptseditorwindow.cpp
Source/codeeditor/dccellscriptseditorwindow.h
Source/dccontainer.cpp
Source/dccontainer.h
Source/denncoCreator.pro
Source/dialog/dcaddcellcodeclassdialog.cpp
Source/dialog/dcaddcellcodeclassdialog.h
Source/dialog/dcaddcelldialog.cpp
Source/dialog/dcassigncellcodeclassdialog.cpp
Source/dialog/dcmanagecellcodedialog.cpp [new file with mode: 0644]
Source/dialog/dcmanagecellcodedialog.h [new file with mode: 0644]
Source/dialog/dcrenamecelldialog.cpp
Source/mainwindow.cpp
Source/mainwindow.h
Source/treeview/dctreeviewwidget.cpp
Source/visualizer/dcglvisualizerwidget.cpp
Source/visualizer/toolwindow/dctoolwindowcelleditor.cpp

index ecd9b46..0357882 100644 (file)
@@ -95,6 +95,7 @@ void DCCellScriptsEditorPageWidget::assignedCellCodeChanged()
         d_splitter->widget(1)->show();
         d_splitter->setStretchFactor(0,1);
         d_splitter->setStretchFactor(1,4);
+        d_cellCodeScriptEditor->setFocus();
     }
     else
     {
@@ -160,8 +161,6 @@ bool DCCellScriptsEditorPageWidget::loadScriptsFormFile()
         d_cellCodeScriptEditor->setReadOnly(false);
         d_cellCodeScriptEditor->document()->setModified(false);
         d_splitter->widget(1)->show();
-        d_splitter->setStretchFactor(0,1);
-        d_splitter->setStretchFactor(1,4);
     }
     else
     {
@@ -307,3 +306,18 @@ bool DCCellScriptsEditorPageWidget::saveCellCodeScriptToFilePrivate(DCCellCode *
     }
     return false;
 }
+
+void DCCellScriptsEditorPageWidget::focusCustomScript()
+{
+    d_splitter->setStretchFactor(0,1);
+    d_splitter->setStretchFactor(1,4);
+    d_customScriptEditor->setFocus();
+}
+
+void DCCellScriptsEditorPageWidget::focusCellCodeScript()
+{
+    d_splitter->setStretchFactor(0,1);
+    d_splitter->setStretchFactor(1,4);
+    d_cellCodeScriptEditor->setFocus();
+
+}
index da6f8f3..d5e458a 100644 (file)
@@ -54,6 +54,9 @@ public:
     bool            saveCustomScriptOnlyToFile(bool saveModifiedOnly);
     bool            saveCellCodeScriptOnlyToFile(bool saveModifiedOnly);
 
+    void            focusCustomScript();
+    void            focusCellCodeScript();
+
 signals:
     void editingCellDestroyed(DCCell *cell);
     void cellScriptsModifiedStatusChanged(QWidget *self, bool modified);
index c6a4c14..54cc057 100644 (file)
@@ -193,8 +193,9 @@ void DCCellScriptsEditorTabWidget::setCurrentTabReadOnly(bool readOnly)
     }
 }
 
-void DCCellScriptsEditorTabWidget::openTab(DCCell *target)
+void DCCellScriptsEditorTabWidget::openTab(DCCell *target, bool focusInCellCodeScriptFirst)
 {
+    DCCellScriptsEditorPageWidget *targetWidget = NULL;
     int index = -1;
     for (int i = 0; i < count(); i++)
     {
@@ -204,6 +205,7 @@ void DCCellScriptsEditorTabWidget::openTab(DCCell *target)
             if (it.value() == target)
             {
                 index = i;
+                targetWidget = dynamic_cast<DCCellScriptsEditorPageWidget*>(it.key());
                 break;
             }
         }
@@ -215,12 +217,20 @@ void DCCellScriptsEditorTabWidget::openTab(DCCell *target)
     }
     else
     {
-        DCCellScriptsEditorPageWidget *widget = new DCCellScriptsEditorPageWidget(target, this);
-        d_targets.insert(widget, target);
-        setCurrentIndex(addTab(widget, QString::fromStdString(target->getName())));
-        connect(widget, SIGNAL(editingCellDestroyed(DCCell*)), this, SLOT(slotCellDestroyed(DCCell*)));
-        connect(widget, SIGNAL(cellScriptsModifiedStatusChanged(QWidget*, bool)), this, SLOT(slotTabPageContentModifiedStatusChanged(QWidget*, bool)));
-        connect(widget, SIGNAL(cellScriptsSaved(QWidget*)), this, SLOT(slotTabPageContentSaved(QWidget*)));
+        targetWidget = new DCCellScriptsEditorPageWidget(target, this);
+        d_targets.insert(targetWidget, target);
+        setCurrentIndex(addTab(targetWidget, QString::fromStdString(target->getName())));
+        connect(targetWidget, SIGNAL(editingCellDestroyed(DCCell*)), this, SLOT(slotCellDestroyed(DCCell*)));
+        connect(targetWidget, SIGNAL(cellScriptsModifiedStatusChanged(QWidget*, bool)), this, SLOT(slotTabPageContentModifiedStatusChanged(QWidget*, bool)));
+        connect(targetWidget, SIGNAL(cellScriptsSaved(QWidget*)), this, SLOT(slotTabPageContentSaved(QWidget*)));
+    }
+
+    if (targetWidget)
+    {
+        if (focusInCellCodeScriptFirst)
+            targetWidget->focusCellCodeScript();
+        else
+            targetWidget->focusCustomScript();
     }
 }
 
index 8d3f084..5356875 100644 (file)
@@ -46,7 +46,7 @@ public:
     DCCell* getCellForIndex(int i) const;
 
     void            setCurrentTabReadOnly(bool setReadOnly);
-    void            openTab(DCCell *editTarget);
+    void            openTab(DCCell *editTarget, bool focusInCellCodeScriptFirst);
     QSet<DCVCPage*> saveActiveTabContentToFile(bool saveModifiedOnly);
     QSet<DCVCPage*> saveContentToFile(int tabIndex, bool saveModifiedOnly);
     bool            saveCustomScriptOnlyToFile(int tabIndex, bool saveModifiedOnly);
index 1d51662..12720e7 100644 (file)
@@ -179,11 +179,11 @@ bool DCCellScriptsEditorWindow::getIsVisible()
 }
 
 //static
-bool DCCellScriptsEditorWindow::startEditing(DCCell *cell)
+bool DCCellScriptsEditorWindow::startEditing(DCCell *cell, bool focusInCellCodeScriptFirst)
 {
     if (s_instance)
     {
-        return s_instance->startEditingPrivate(cell);
+        return s_instance->startEditingPrivate(cell, focusInCellCodeScriptFirst);
     }
     return false;
 }
@@ -211,6 +211,16 @@ QSet<DCVCPage*> DCCellScriptsEditorWindow::saveScriptsAll(bool modifiedOnly)
 }
 
 //static
+bool DCCellScriptsEditorWindow::closeEditor()
+{
+    if (s_instance && s_instance->isVisible())
+    {
+        return s_instance->close();
+    }
+    return true;
+}
+
+//static
 void DCCellScriptsEditorWindow::destroyEditor()
 {
     if (s_instance)
@@ -424,9 +434,9 @@ void DCCellScriptsEditorWindow::creatorCommandExecuted(const QUndoCommand *comma
     updateWindowState();
 }
 
-bool DCCellScriptsEditorWindow::startEditingPrivate(DCCell *cell)
+bool DCCellScriptsEditorWindow::startEditingPrivate(DCCell *cell, bool focusInCellCodeScriptFirst)
 {
-    d_tabWidget->openTab(cell);
+    d_tabWidget->openTab(cell, focusInCellCodeScriptFirst);
 
     if (!isVisible())
     {
index 9ac0207..6a26bda 100644 (file)
@@ -62,7 +62,7 @@ class DCCellScriptsEditorWindow : public QDialog
     bool maybeSave(DCCell *cell);
     bool maybeSave(int index);
     void updateWindowState();
-    bool startEditingPrivate(DCCell *cell);
+    bool startEditingPrivate(DCCell *cell, bool focusInCellCodeScriptFirst);
     bool saveScriptsBelongToPrivate(DCVCPage *page, bool modifiedOnly);
     QSet<DCVCPage*> saveScriptsAllPrivate(bool modifiedOnly);
 
@@ -72,9 +72,10 @@ public:
 
     static DCCellScriptsEditorWindow* construct(DCCreator *creator);
     static bool getIsVisible();
-    static bool startEditing(DCCell *cell);
+    static bool startEditing(DCCell *cell, bool focusInCellCodeScriptFirst = true);
     static bool saveScriptsBelongTo(DCVCPage *page, bool modifiedOnly);
     static QSet<DCVCPage*> saveScriptsAll(bool modifiedOnly);
+    static bool closeEditor();
     static void destroyEditor();
 
     virtual void closeEvent(QCloseEvent *event);
index 8a55426..d3de997 100644 (file)
@@ -532,6 +532,16 @@ QList<QString> DCContainer::getAvailableCellTypes() const
     return list;
 }
 
+QList<QString> DCContainer::getAvailableScriptableCellTypes() const
+{
+    QList<QString> list;
+
+    list.append(QString::fromStdString(TKContainer::CELLTYPE_JSBASIC));
+    list.append(QString::fromStdString(TKContainer::CELLTYPE_BASICSTORAGE));
+
+    return list;
+}
+
 bool DCContainer::getIsScriptable(const QString& type) const
 {
     std::string t = type.toStdString();
index a52e1e8..6a68d43 100644 (file)
@@ -167,6 +167,8 @@ public:
      */
     QList<QString>          getAvailableCellTypes() const;
 
+    QList<QString>          getAvailableScriptableCellTypes() const;
+
     /**
      * @brief check if given cell type can have script
      * @param type
index 33cb2ed..f80e279 100644 (file)
@@ -97,7 +97,8 @@ HEADERS       = mainwindow.h \
     dialog/dcinputnewcontentdirdialog.h \
     codeeditor/dccellscriptseditorwindow.h \
     codeeditor/dccellscriptseditortabwidget.h \
-    codeeditor/dccellscriptseditorpagewidget.h
+    codeeditor/dccellscriptseditorpagewidget.h \
+    dialog/dcmanagecellcodedialog.h
 
 SOURCES       = main.cpp \
                 mainwindow.cpp \
@@ -189,7 +190,8 @@ SOURCES       = main.cpp \
     dialog/dcinputnewcontentdirdialog.cpp \
     codeeditor/dccellscriptseditorwindow.cpp \
     codeeditor/dccellscriptseditortabwidget.cpp \
-    codeeditor/dccellscriptseditorpagewidget.cpp
+    codeeditor/dccellscriptseditorpagewidget.cpp \
+    dialog/dcmanagecellcodedialog.cpp
 
 RESOURCES     = denncoCreator.qrc
 
index 1148a04..532b8db 100644 (file)
 #include <QTableView>
 #include <QHeaderView>
 
-DCAddCellCodeClassDialog::DCAddCellCodeClassDialog(DCContainer *container, DCCreator *creator, const QString& path, QWidget *parent) :
-    QDialog(parent), d_container(container), d_creator(creator)
+DCAddCellCodeClassDialog::DCAddCellCodeClassDialog(DCCreator *creator, const QString& path, QWidget *parent) :
+    QDialog(parent), d_creator(creator)
 {
-    setWindowTitle(tr("Add class"));
+    d_container = d_creator->getCurrentContainer();
+
+    setWindowTitle(tr("Add cell code"));
 
     d_textField = new QLineEdit;
 
@@ -44,9 +46,9 @@ DCAddCellCodeClassDialog::DCAddCellCodeClassDialog(DCContainer *container, DCCre
     d_tableModel->setReadOnly(0,true);
 
     d_comboBox = new QComboBox;
-    d_comboBox->addItems(QStringList(d_container->getAvailableCellTypes()));
+    d_comboBox->addItems(QStringList(d_container->getAvailableScriptableCellTypes()));
 
-    DCScene *scene = container->getScene();
+    DCScene *scene = d_container->getScene();
     const QMap<QString,DCVCPage*> *pages = scene->getPages();
     QMapIterator<QString, DCVCPage*> i(*pages);
     int row = 0;
@@ -102,6 +104,8 @@ DCAddCellCodeClassDialog::DCAddCellCodeClassDialog(DCContainer *container, DCCre
 
 DCAddCellCodeClassDialog::~DCAddCellCodeClassDialog()
 {
+    if (d_tableModel)
+        d_tableModel->deleteLater();
 }
 
 
index adfbca4..16cca4c 100644 (file)
@@ -50,7 +50,7 @@ private:
     bool            checkInput();
 
 public:
-    DCAddCellCodeClassDialog(DCContainer *container, DCCreator *creator, const QString& path, QWidget *parent = 0);
+    DCAddCellCodeClassDialog(DCCreator *creator, const QString& path, QWidget *parent = 0);
     virtual ~DCAddCellCodeClassDialog();
 
     QString getAddedCellCodeClassName() const;
index 32e8591..04db055 100644 (file)
 
 DCAddCellDialog::~DCAddCellDialog()
 {
-
+    if (d_tableModel)
+        d_tableModel->deleteLater();
 }
 
 bool DCAddCellDialog::checkInput()
index 27d95c6..f7881d3 100644 (file)
@@ -115,7 +115,7 @@ void DCAssignCellCodeClassDialog::cancelButtonClicked()
 
 void DCAssignCellCodeClassDialog::addNewClicked()
 {
-    DCAddCellCodeClassDialog dialog(d_container, d_creator, "");
+    DCAddCellCodeClassDialog dialog(d_creator, "");
     dialog.exec();
     updateClassList();
     QString classname = dialog.getAddedCellCodeClassName();
diff --git a/Source/dialog/dcmanagecellcodedialog.cpp b/Source/dialog/dcmanagecellcodedialog.cpp
new file mode 100644 (file)
index 0000000..b1a8f27
--- /dev/null
@@ -0,0 +1,299 @@
+//  Copyright (c) 2012 Dennco Project
+//
+// This program is free software: you can redistribute it and/or modify
+// it under the terms of the GNU General Public License as published by
+// the Free Software Foundation, either version 3 of the License, or
+// (at your option) any later version.
+//
+// This program is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+// GNU General Public License for more details.
+//
+// You should have received a copy of the GNU General Public License
+// along with this program.  If not, see <http://www.gnu.org/licenses/>.
+
+//
+//  Created by tkawata on Nov-4, 2012.
+//
+#include "dcmanagecellcodedialog.h"
+
+#include "dccontainer.h"
+#include "dccreator.h"
+#include "dcscene.h"
+#include "dccellcode.h"
+#include "dcvcpage.h"
+#include "command/dccommand.h"
+#include "utils/dcqtitemmodel.h"
+#include "utils/dcutil.h"
+#include "dcsinglecolumntableview.h"
+#include "dialog/dcaddcellcodeclassdialog.h"
+
+#include <QLineEdit>
+#include <QTableView>
+#include <QHeaderView>
+
+DCManageCellCodeDialog::DCManageCellCodeDialog(DCCreator *creator, DCCellCode* cellCode, QWidget *parent) :
+    QDialog(parent), d_creator(creator), d_cellCode(cellCode), d_reloading(false)
+{
+    setWindowTitle(tr("Manage Cell Code"));
+    d_container = d_creator->getCurrentContainer();
+
+    d_textField = new QLineEdit;
+    d_table = new DCSingleColumnTableView();
+    QStringList headers;
+    headers << "Cell code";
+    d_tableModel = new DCQtItemModel(headers);
+    d_tableModel->setReadOnly(0,true);
+    d_table->setModel(d_tableModel);
+
+    d_comboBox = new QComboBox;
+    d_comboBox->addItems(QStringList(d_container->getAvailableScriptableCellTypes()));
+
+    setLayout(new QVBoxLayout);
+    d_table->horizontalHeader()->setResizeMode(QHeaderView::Stretch);
+
+    d_addButton = new QPushButton(tr("Add"));
+    d_closeButton = new QPushButton(tr("Close"));
+    d_saveButton = new QPushButton(tr("Save"));
+    QHBoxLayout *buttonLayout = new QHBoxLayout;
+    buttonLayout->addWidget(d_addButton);
+    buttonLayout->addItem(new QSpacerItem(10,10, QSizePolicy::Expanding));
+    buttonLayout->addWidget(d_saveButton);
+    buttonLayout->addWidget(d_closeButton);
+    d_saveButton->setEnabled(false);
+    d_closeButton->setDefault(true);
+
+    QGridLayout *glayout = new QGridLayout;
+    glayout->addWidget(new QLabel(tr("name")),0,0);
+    glayout->addWidget(d_textField,0,1);
+    glayout->addWidget(new QLabel(tr("type")),1,0);
+    glayout->addWidget(d_comboBox);
+    ((QVBoxLayout*)layout())->addLayout(glayout);
+    layout()->addWidget(d_table);
+    d_statusText = new QLabel;
+    d_message = new QLabel;
+    d_message->setStyleSheet("color : red;");
+    layout()->addWidget(d_statusText);
+    layout()->addWidget(d_message);
+    ((QVBoxLayout*)layout())->addLayout(buttonLayout);
+
+    reloadViewData();
+
+    connect(d_textField, SIGNAL(textChanged(QString)), this, SLOT(textInputChanged(QString)));
+    connect(d_comboBox, SIGNAL(currentIndexChanged(int)), this, SLOT(comboBoxSelectionChanged()));
+    connect(d_addButton, SIGNAL(clicked()), this, SLOT(addButtonClicked()));
+    connect(d_saveButton, SIGNAL(clicked()), this, SLOT(saveButtonClicked()));
+    connect(d_closeButton, SIGNAL(clicked()), this, SLOT(close()));
+    connect(d_table,SIGNAL(selectionChangedSignal(QItemSelection,QItemSelection)), this, SLOT(listSelectionChanged(QItemSelection,QItemSelection)));
+    connect(d_creator, SIGNAL(commandExecuted(const QUndoCommand*)), this, SLOT(commandExecuted(const QUndoCommand*)));
+}
+
+DCManageCellCodeDialog::~DCManageCellCodeDialog()
+{
+    if (d_tableModel)
+        d_tableModel->deleteLater();
+}
+
+void DCManageCellCodeDialog::closeEvent(QCloseEvent *event)
+{
+    if (maybeSave())
+    {
+        event->accept();
+    }
+    else
+    {
+        event->ignore();
+    }
+}
+
+bool DCManageCellCodeDialog::maybeSave()
+{
+    if (!d_cellCode)
+        return true;
+
+    bool typeChanged = QString::fromStdString(d_cellCode->getCellAPIName()) != d_comboBox->currentText().trimmed();
+    bool nameChanged = DCUtil::getNameFromFQNPath(QString::fromStdString(d_cellCode->getFQNName())) != d_textField->text().trimmed();
+
+    bool r = true;
+
+    if (typeChanged || nameChanged)
+    {
+        QMessageBox::StandardButton ret;
+        ret = QMessageBox::warning(this, tr("Cell code manager"),
+            tr("The cell code has been modified.\n"
+            "Do you want to save your changes?"),
+            QMessageBox::Save | QMessageBox::Discard | QMessageBox::Cancel);
+        if (ret == QMessageBox::Save)
+        {
+            if (typeChanged)
+            {
+                d_creator->doCommandChangeCellCodeClassType(this, d_cellCode, d_comboBox->currentText().trimmed());
+            }
+            if (nameChanged)
+            {
+                //TODO
+                QMessageBox::warning(this, "Not implemented", "Sorry! Renaming cell code name is not implemented now..\nIt will be supported in the future..");
+                d_textField->setText(DCUtil::getNameFromFQNPath(QString::fromStdString(d_cellCode->getFQNName())));
+            }
+        }
+        else if (ret == QMessageBox::Cancel)
+        {
+            r = false;
+        }
+    }
+    return r;
+}
+
+bool DCManageCellCodeDialog::updateWindowStatus()
+{
+    d_message->setText("");
+    d_statusText->setText("");
+
+    if (!d_cellCode)
+        return true;
+
+    QString name = DCUtil::getNameFromFQNPath(QString::fromStdString(d_cellCode->getFQNName()));
+    bool modified = name != d_textField->text().trimmed();
+    if (!modified)
+        modified = QString::fromStdString(d_cellCode->getCellAPIName()) != d_comboBox->currentText().trimmed();
+
+    QString windowTitle = name;
+    if (modified)
+    {
+        windowTitle.append("*");
+        d_saveButton->setEnabled(true);
+        d_saveButton->setDefault(true);
+    }
+    else
+    {
+        d_saveButton->setEnabled(false);
+        d_closeButton->setEnabled(true);
+    }
+    windowTitle.append(" - Manage Cell Code");
+
+    setWindowTitle(windowTitle);
+
+    return modified;
+}
+
+void DCManageCellCodeDialog::textInputChanged(const QString &text)
+{
+    updateWindowStatus();
+}
+
+void DCManageCellCodeDialog::comboBoxSelectionChanged()
+{
+    updateWindowStatus();
+}
+
+void DCManageCellCodeDialog::saveButtonClicked()
+{
+    bool typeChanged = QString::fromStdString(d_cellCode->getCellAPIName()) != d_comboBox->currentText().trimmed();
+    bool nameChanged = DCUtil::getNameFromFQNPath(QString::fromStdString(d_cellCode->getFQNName())) != d_textField->text().trimmed();
+
+    if (typeChanged)
+    {
+        d_creator->doCommandChangeCellCodeClassType(this, d_cellCode, d_comboBox->currentText().trimmed());
+    }
+    if (nameChanged)
+    {
+        //TODO
+        QMessageBox::warning(this, "Not implemented", "Sorry! Renaming cell code name is not implemented now..\nIt will be supported in the future..");
+        d_textField->setText(DCUtil::getNameFromFQNPath(QString::fromStdString(d_cellCode->getFQNName())));
+    }
+}
+
+void DCManageCellCodeDialog::addButtonClicked()
+{
+    DCAddCellCodeClassDialog dialog(d_creator, "", this);
+    dialog.exec();
+}
+
+void DCManageCellCodeDialog::deleteButtonClicked()
+{
+    //TODO
+    QMessageBox::warning(this, "Not implemented", "Sorry! Delete cell code is not implemented now..\nIt will be supported in the future..");
+}
+
+
+void DCManageCellCodeDialog::listSelectionChanged(const QItemSelection &selected, const QItemSelection &deselected)
+{
+    if (d_reloading)
+        return;
+
+    DCCellCode *newCellCode = NULL;
+    if (selected.count()>0)
+    {
+        QString selectedPath = d_tableModel->data(selected.at(0).indexes().at(0), Qt::DisplayRole).toString();
+        newCellCode = dynamic_cast<DCCellCode*>(d_container->getCellCode(selectedPath.toStdString()));
+    }
+
+    if (newCellCode != d_cellCode)
+    {
+        if (maybeSave())
+        {
+            d_cellCode = newCellCode;
+            reloadViewData();
+            updateWindowStatus();
+        }
+        else
+        {
+            QItemSelectionModel s(d_tableModel);
+            s.select(deselected,QItemSelectionModel::Select);
+            d_table->setSelectionModel(&s);
+        }
+    }
+
+    updateWindowStatus();
+}
+
+void DCManageCellCodeDialog::commandExecuted(const QUndoCommand *executedCommand)
+{
+    reloadViewData();
+}
+
+void DCManageCellCodeDialog::reloadViewData()
+{
+    d_reloading = true;
+
+    const TKCellCodeMap* cellcodes = d_container->getCellCodes();
+    TKCellCode *emtpyCellCodeClass = d_container->getEmptyCellCodeClass();
+    int selection = -1;
+    int row = 0;
+    d_tableModel->removeAllItems();
+    for ( TKCellCodeMap::const_iterator it = cellcodes->begin(); it != cellcodes->end(); ++it ) {
+        if (it->second != emtpyCellCodeClass)
+        {
+            if (it->second == d_cellCode)
+            {
+                selection = row;
+            }
+            d_tableModel->insertString(QString::fromStdString(it->first));
+            row++;
+        }
+    }
+    d_table->setModel(d_tableModel);
+    if (selection >= 0)
+    {
+        d_table->selectRow(selection);
+    }
+
+    if (d_cellCode)
+    {
+        d_textField->setText(DCUtil::getNameFromFQNPath(QString::fromStdString(d_cellCode->getFQNName())));
+
+        QString type = QString::fromStdString(d_cellCode->getCellAPIName());
+        for (int i = 0; i < d_comboBox->count(); i++)
+        {
+            if (d_comboBox->itemText(i) == type)
+            {
+                d_comboBox->setCurrentIndex(i);
+                break;
+            }
+        }
+    }
+
+    updateWindowStatus();
+    d_reloading = false;
+}
diff --git a/Source/dialog/dcmanagecellcodedialog.h b/Source/dialog/dcmanagecellcodedialog.h
new file mode 100644 (file)
index 0000000..5b2b1c5
--- /dev/null
@@ -0,0 +1,77 @@
+//  Copyright (c) 2012 Dennco Project
+//
+// This program is free software: you can redistribute it and/or modify
+// it under the terms of the GNU General Public License as published by
+// the Free Software Foundation, either version 3 of the License, or
+// (at your option) any later version.
+//
+// This program is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+// GNU General Public License for more details.
+//
+// You should have received a copy of the GNU General Public License
+// along with this program.  If not, see <http://www.gnu.org/licenses/>.
+
+//
+//  Created by tkawata on Nov-4, 2012.
+//
+#ifndef DCMANAGECELLCODEDIALOG_H
+#define DCMANAGECELLCODEDIALOG_H
+
+#include <QDialog>
+#include <QTableView>
+#include <QComboBox>
+#include <QLabel>
+#include <QUndoCommand>
+
+class DCContainer;
+class DCCreator;
+class DCCellCode;
+class DCQtItemModel;
+class DCSingleColumnTableView;
+
+class DCManageCellCodeDialog : public QDialog
+{
+    Q_OBJECT
+
+    DCContainer                 *d_container;
+    DCCreator                   *d_creator;
+    DCSingleColumnTableView     *d_table;
+    DCQtItemModel               *d_tableModel;
+    QComboBox                   *d_comboBox;
+    QPushButton                 *d_addButton;
+    QPushButton                 *d_deleteButton;
+    QPushButton                 *d_saveButton;
+    QPushButton                 *d_closeButton;
+    DCCellCode                  *d_cellCode;
+    QLineEdit                   *d_textField;
+    QLabel                      *d_statusText;
+    QLabel                      *d_message;
+    bool                        d_reloading;
+
+    bool maybeSave();
+    bool updateWindowStatus();
+    void reloadViewData();
+
+public:
+    DCManageCellCodeDialog(DCCreator *creator, DCCellCode *cellCode, QWidget *parent = 0);
+    virtual ~DCManageCellCodeDialog();
+
+protected:
+    virtual void closeEvent(QCloseEvent *event);
+
+signals:
+    
+private slots:
+    void textInputChanged(const QString &text);
+    void addButtonClicked();
+    void deleteButtonClicked();
+    void saveButtonClicked();
+    void comboBoxSelectionChanged();
+    void listSelectionChanged(const QItemSelection &selected, const QItemSelection &deselected);
+    void commandExecuted(const QUndoCommand* executedCommand);
+    
+};
+
+#endif // DCMANAGECELLCODEDIALOG_H
index 1b54b75..030da62 100644 (file)
 
 DCRenameCellDialog::~DCRenameCellDialog()
 {
-
+    if (d_tableModel)
+        d_tableModel->deleteLater();
 }
 
 bool DCRenameCellDialog::checkInput()
index 304aeb7..d84d033 100644 (file)
@@ -29,6 +29,7 @@
 #include "utils/dcresources.h"
 #include "utils/dcskeltoncreatorutil.h"
 #include "dialog/dcinputnewcontentdirdialog.h"
+#include "dialog/dcmanagecellcodedialog.h"
 #include "dccellscriptseditorwindow.h"
 
 #include <QCloseEvent>
@@ -257,6 +258,9 @@ void MainWindow::createActions()
     exitAct->setStatusTip(tr("Exit the application"));
     connect(exitAct, SIGNAL(triggered()), this, SLOT(close()));
 
+    manageCellCodeAct = new QAction(tr("Manage Cell Code..."), this);
+    connect(manageCellCodeAct, SIGNAL(triggered()), this, SLOT(manageCellCode()));
+
     cutAct = new QAction(QIcon(":/images/cut.png"), tr("Cu&t"), this);
     cutAct->setShortcuts(QKeySequence::Cut);
     cutAct->setStatusTip(tr("Cut the current selection's contents to the "
@@ -306,6 +310,8 @@ void MainWindow::createMenus()
     fileMenu->addAction(exitAct);
 
     editMenu = menuBar()->addMenu(tr("&Edit"));
+    editMenu->addAction(manageCellCodeAct);
+    editMenu->addSeparator();
     editMenu->addAction(cutAct);
     editMenu->addAction(copyAct);
     editMenu->addAction(pasteAct);
@@ -392,6 +398,9 @@ bool MainWindow::maybeSave()
 {
     if (d_creator->getCurrentContent())
     {
+        if (!DCCellScriptsEditorWindow::closeEditor())
+            return false;
+
         if (d_creator->getCurrentContent()->getIsModified())
         {
             QMessageBox::StandardButton ret;
@@ -525,3 +534,12 @@ void MainWindow::playContent()
         socket->close();
     }
 }
+
+void MainWindow::manageCellCode()
+{
+    if (!d_creator)
+        return;
+
+    DCManageCellCodeDialog dialog(d_creator, NULL, this);
+    dialog.exec();
+}
index 8c0172f..73909dc 100644 (file)
@@ -59,6 +59,7 @@ private slots:
     void about();
     void documentWasModified();
     void playContent();
+    void manageCellCode();
 
 private:
     void createActions();
@@ -88,6 +89,7 @@ private:
     QAction *saveAct;
     QAction *saveAsAct;
     QAction *exitAct;
+    QAction *manageCellCodeAct;
     QAction *cutAct;
     QAction *copyAct;
     QAction *playAct;
index 9614df9..d775658 100644 (file)
@@ -429,7 +429,7 @@ void DCTreeViewWidget::doContextMenu(const QPoint &pos)
                 {
                     if (index.isValid())
                     {
-                        DCAddCellCodeClassDialog dialog(container, d_creator, containerBasedPath);
+                        DCAddCellCodeClassDialog dialog(d_creator, containerBasedPath);
                         dialog.exec();
                     }
                 }
index ee62153..d5b6c4e 100644 (file)
@@ -274,7 +274,7 @@ DCUIGraphicsScene::DCUIGraphicsScene(DCCreator *creator, QWidget *parent)
     connect(DCAnimationTimer::instance(), SIGNAL(goNextFrame()), this, SLOT(doAnimation()));
     connect(this, SIGNAL(sceneRectChanged(QRectF)), this, SLOT(resizeEvent(QRectF)));
     d_viewControlTool = new DCToolWindowViewControl(d_creator);
-
+    addToolWindow(d_viewControlTool);
 }
 
 DCUIGraphicsScene::~DCUIGraphicsScene()
index bebd98f..cd1e159 100644 (file)
@@ -562,10 +562,9 @@ void DCToolWindowCellEditor::slotAxonTerminalItemClicked(const QModelIndex &inde
 
 void DCToolWindowCellEditor::slotCellCodeEditButtonPressed()
 {
-    if (d_cell)
+    if (d_cell && d_cell->getCellCode())
     {
-        //TODO
-        DCCellScriptsEditorWindow::startEditing(d_cell);
+        DCCellScriptsEditorWindow::startEditing(d_cell, true);
     }
 }
 
@@ -573,7 +572,7 @@ void DCToolWindowCellEditor::slotCustomScriptEditButtonPressed()
 {
     if (d_cell)
     {
-        DCCellScriptsEditorWindow::startEditing(d_cell);
+        DCCellScriptsEditorWindow::startEditing(d_cell, false);
     }
 }