From 70a983becf3cfed3224b8746f8098753a84aede2 Mon Sep 17 00:00:00 2001 From: tkawata Date: Sat, 3 Nov 2012 09:52:02 +0900 Subject: [PATCH] [denncoCreator] reworked the code editor. Its now opened on a separate window. Fixed some compile error issues on Mac too. --- .../codeeditor/dccellscriptseditorpagewidget.cpp | 303 +++++++++++++ Source/codeeditor/dccellscriptseditorpagewidget.h | 68 +++ Source/codeeditor/dccellscriptseditortabwidget.cpp | 288 +++++++++++++ Source/codeeditor/dccellscriptseditortabwidget.h | 75 ++++ Source/codeeditor/dccellscriptseditorwindow.cpp | 467 +++++++++++++++++++++ Source/codeeditor/dccellscriptseditorwindow.h | 97 +++++ Source/codeeditor/dccodehighlighter.cpp | 6 +- Source/command/dceditcommands.cpp | 39 +- Source/command/dceditcommands.h | 23 - Source/dccell.cpp | 2 +- Source/dccell.h | 2 +- Source/dccellcode.cpp | 4 +- Source/dccellcode.h | 2 +- Source/dcconsole.cpp | 2 +- Source/dccontainer.h | 4 +- Source/dccontainersaver.cpp | 2 +- Source/dccreator.cpp | 47 ++- Source/dccreator.h | 7 +- Source/denncoCreator.pro | 14 +- Source/dialog/dcassigncellcodeclassdialog.cpp | 6 +- Source/dialog/dcassigncellcodeclassdialog.h | 2 +- Source/engine/layer1/platform/qt/QtTKConsole.cpp | 2 +- Source/mainwindow.cpp | 25 +- Source/mainwindow.h | 2 + Source/propertyeditor/dcpropertyeditor.cpp | 1 + Source/utils/dccommandutil.cpp | 12 - Source/utils/dccommandutil.h | 3 - Source/visualizer/component/dcvcaxon.h | 2 +- Source/visualizer/component/dcvcomponent.h | 4 +- .../visualizer/component/shape/dccuberenderer.cpp | 6 +- Source/visualizer/component/shape/dccuberenderer.h | 6 +- Source/visualizer/dceditmenudialog.cpp | 70 --- Source/visualizer/dceditmenudialog.h | 45 -- Source/visualizer/dcglvisualizerwidget.cpp | 89 +--- Source/visualizer/dcglvisualizerwidget.h | 6 - Source/visualizer/dcscene.cpp | 24 +- Source/visualizer/dcscene.h | 4 +- .../eventhandler/dcvlayoutmodehandler.cpp | 14 +- .../toolwindow/dctoolwindowcellcodeeditor.cpp | 447 -------------------- .../toolwindow/dctoolwindowcellcodeeditor.h | 94 ----- .../toolwindow/dctoolwindowcelleditor.cpp | 10 +- 41 files changed, 1408 insertions(+), 918 deletions(-) create mode 100644 Source/codeeditor/dccellscriptseditorpagewidget.cpp create mode 100644 Source/codeeditor/dccellscriptseditorpagewidget.h create mode 100644 Source/codeeditor/dccellscriptseditortabwidget.cpp create mode 100644 Source/codeeditor/dccellscriptseditortabwidget.h create mode 100644 Source/codeeditor/dccellscriptseditorwindow.cpp create mode 100644 Source/codeeditor/dccellscriptseditorwindow.h delete mode 100644 Source/visualizer/dceditmenudialog.cpp delete mode 100644 Source/visualizer/dceditmenudialog.h delete mode 100644 Source/visualizer/toolwindow/dctoolwindowcellcodeeditor.cpp delete mode 100644 Source/visualizer/toolwindow/dctoolwindowcellcodeeditor.h diff --git a/Source/codeeditor/dccellscriptseditorpagewidget.cpp b/Source/codeeditor/dccellscriptseditorpagewidget.cpp new file mode 100644 index 0000000..63e878d --- /dev/null +++ b/Source/codeeditor/dccellscriptseditorpagewidget.cpp @@ -0,0 +1,303 @@ +// 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 . + +// +// Created by tkawata on Nov-3, 2012. +// +#include "dccellscriptseditorpagewidget.h" + +#include +#include + +#include "dccreator.h" +#include "dccontainer.h" +#include "dccodeeditor.h" +#include "dccell.h" +#include "dccellcode.h" + +DCCellScriptsEditorPageWidget::DCCellScriptsEditorPageWidget(DCCell *targetCell, QWidget *parent) : + QWidget(parent), d_cell(targetCell), d_modified(false) +{ + if (d_cell->getIsCellCodeAssgined()) + { + d_cellCodeOrg = d_cell->getCellCode(); + } + else + { + d_cellCodeOrg = NULL; + } + + d_splitter = new QSplitter(Qt::Vertical, this); + + d_customScriptEditor = new DCCodeEditor(this); + d_cellCodeScriptEditor = new DCCodeEditor(this); + + QVBoxLayout *customScriptEditorLayout = new QVBoxLayout; + customScriptEditorLayout->addWidget(new QLabel(tr("custom script"))); + customScriptEditorLayout->addWidget(d_customScriptEditor); + QWidget *customScriptWidget = new QWidget; + customScriptWidget->setLayout(customScriptEditorLayout); + + QVBoxLayout *cellCodeScriptEditorLayout = new QVBoxLayout; + cellCodeScriptEditorLayout->addWidget(new QLabel(tr("cell code script"))); + cellCodeScriptEditorLayout->addWidget(d_cellCodeScriptEditor); + QWidget *cellCodeScriptWidget = new QWidget; + cellCodeScriptWidget->setLayout(cellCodeScriptEditorLayout); + + d_splitter->addWidget(customScriptWidget); + d_splitter->addWidget(cellCodeScriptWidget); + + QVBoxLayout *rootLayout = new QVBoxLayout; + rootLayout->setMargin(0); + rootLayout->addWidget(d_splitter); + + setLayout(rootLayout); + + loadScriptsFormFile(); + + connect(targetCell, SIGNAL(destroyed()), this, SLOT(cellDestroyed())); + connect(targetCell, SIGNAL(cellCodeChanged()), this, SLOT(assignedCellCodeChanged())); +} + +DCCellScriptsEditorPageWidget::~DCCellScriptsEditorPageWidget() +{ + this->disconnect(); +} + +//slot +void DCCellScriptsEditorPageWidget::cellDestroyed() +{ + emit editingCellDestroyed(d_cell); +} + +//slot +void DCCellScriptsEditorPageWidget::assignedCellCodeChanged() +{ + d_cellCodeScriptEditor->disconnect(this); + + if (d_cell->getIsCellCodeAssgined()) + { + DCCellCode *cellCode = d_cell->getCellCode(); + d_cellCodeScriptEditor->setPlainText(cellCode->getOwnScript()); + d_cellCodeScriptEditor->setReadOnly(false); + d_splitter->widget(1)->show(); + d_splitter->setStretchFactor(0,1); + d_splitter->setStretchFactor(1,4); + } + else + { + d_cellCodeScriptEditor->setPlainText(""); + d_cellCodeScriptEditor->setReadOnly(true); + d_splitter->widget(1)->hide(); + } + + if (d_modified != getIsModified()) + { + d_modified = getIsModified(); + emit cellScriptsModifiedStatusChanged(this,d_modified); + } + connect(d_cellCodeScriptEditor, SIGNAL(textChanged()), this, SLOT(cellCodeScriptChanged())); +} + +//slot +void DCCellScriptsEditorPageWidget::customScriptChanged() +{ + if (d_modified != d_customScriptEditor->document()->isModified()) + { + d_modified = getIsModified(); + emit cellScriptsModifiedStatusChanged(this, d_modified); + } +} + +//slot +void DCCellScriptsEditorPageWidget::cellCodeScriptChanged() +{ + if (d_modified != d_cellCodeScriptEditor->document()->isModified()) + { + d_modified = getIsModified(); + emit cellScriptsModifiedStatusChanged(this, d_modified); + } +} + +bool DCCellScriptsEditorPageWidget::getIsModified() const +{ + if (d_customScriptEditor->document()->isModified()) + return true; + + if (!d_cell->getIsCellCodeAssgined()) + { + return d_cellCodeOrg != NULL; + } + + if (d_cellCodeOrg != d_cell->getCellCode() || d_cellCodeScriptEditor->document()->isModified()) + return true; + + return false; +} + +bool DCCellScriptsEditorPageWidget::loadScriptsFormFile() +{ + d_customScriptEditor->disconnect(this); + d_cellCodeScriptEditor->disconnect(this); + + d_customScriptEditor->setPlainText(d_cell->getCustomScript()); + if (d_cell->getIsCellCodeAssgined()) + { + DCCellCode *cellCode = d_cell->getCellCode(); + d_cellCodeScriptEditor->setPlainText(cellCode->getOwnScript()); + 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 + { + d_cellCodeScriptEditor->setPlainText(""); + d_cellCodeScriptEditor->setReadOnly(true); + d_splitter->widget(1)->hide(); + } + + d_modified = false; + + connect(d_customScriptEditor, SIGNAL(textChanged()), this, SLOT(customScriptChanged())); + connect(d_cellCodeScriptEditor, SIGNAL(textChanged()), this, SLOT(cellCodeScriptChanged())); + + return true; +} + +QSet DCCellScriptsEditorPageWidget::saveScriptsToFile(bool saveModifiedOnly) +{ + bool save = false; + bool result = true; + + QSet modifiedPages; + + if (!saveModifiedOnly || d_customScriptEditor->document()->isModified()) + { + save = true; + result = saveCustomScriptToFilePrivate(); + if (result) + { + modifiedPages.insert(d_cell->getPageBelonging()); + } + } + + if (result) + { + if (d_cell->getIsCellCodeAssgined()) + { + if (!saveModifiedOnly || d_cellCodeScriptEditor->document()->isModified()) + { + DCCellCode *cellCode = d_cell->getCellCode(); + result = saveCellCodeScriptToFilePrivate(cellCode); + if (result) + { + modifiedPages.insert(cellCode->getPageBelonging()); + } + d_cellCodeOrg = cellCode; + } + } + else + { + d_cellCodeOrg = NULL; + } + } + + if (result) + { + d_modified = false; + emit cellScriptsSaved(this); + } + else + { + QMessageBox::warning(this, tr("Failed to save"), tr("The change couldn't be saved")); + } + return modifiedPages; +} + +bool DCCellScriptsEditorPageWidget::saveCustomScriptOnlyToFile(bool saveModifiedOnly) +{ + bool result = true; + bool saved = false; + if (!saveModifiedOnly || d_customScriptEditor->document()->isModified()) + { + saved = true; + result = saveCustomScriptToFilePrivate(); + } + + if (result) + { + if (saved) + { + d_modified = getIsModified(); + emit cellScriptsSaved(this); + } + } + else + { + QMessageBox::warning(this, tr("Failed to save"), tr("The change couldn't be saved")); + } + return result; +} + +bool DCCellScriptsEditorPageWidget::saveCellCodeScriptOnlyToFile(bool saveModifiedOnly) +{ + bool result = true; + bool saved = false; + DCCellCode *cellCode = NULL; + if (d_cell->getIsCellCodeAssgined()) + cellCode = d_cell->getCellCode(); + + if (cellCode && (!saveModifiedOnly || d_cellCodeScriptEditor->document()->isModified())) + { + saved = true; + result = saveCellCodeScriptToFilePrivate(cellCode); + } + + if (result) + { + if (saved) + { + d_modified = getIsModified(); + emit cellScriptsSaved(this); + } + } + else + { + QMessageBox::warning(this, tr("Failed to save"), tr("The change couldn't be saved")); + } + return result; +} + +bool DCCellScriptsEditorPageWidget::saveCustomScriptToFilePrivate() +{ + if (d_cell->saveCustomScript(d_customScriptEditor->toPlainText())) + { + d_customScriptEditor->document()->setModified(false); + return true; + } + return false; +} + +bool DCCellScriptsEditorPageWidget::saveCellCodeScriptToFilePrivate(DCCellCode *cellCode) +{ + if (cellCode->saveScript(d_cellCodeScriptEditor->toPlainText())) + { + d_cellCodeScriptEditor->document()->setModified(false); + return true; + } + return false; +} diff --git a/Source/codeeditor/dccellscriptseditorpagewidget.h b/Source/codeeditor/dccellscriptseditorpagewidget.h new file mode 100644 index 0000000..b451040 --- /dev/null +++ b/Source/codeeditor/dccellscriptseditorpagewidget.h @@ -0,0 +1,68 @@ +// 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 . + +// +// Created by tkawata on Nov-3, 2012. +// +#ifndef DCCELLCODEEDITORPAGEWIDGET_H +#define DCCELLCODEEDITORPAGEWIDGET_H + +#include +#include + +class DCCell; +class DCCellCode; +class DCCodeEditor; +class DCVCPage; + +class DCCellScriptsEditorPageWidget : public QWidget +{ + Q_OBJECT + + DCCell *d_cell; + DCCellCode *d_cellCodeOrg; + DCCodeEditor *d_customScriptEditor; + DCCodeEditor *d_cellCodeScriptEditor; + + QSplitter *d_splitter; + bool d_modified; + + bool saveCustomScriptToFilePrivate(); + bool saveCellCodeScriptToFilePrivate(DCCellCode *cellCode); + +public: + DCCellScriptsEditorPageWidget(DCCell *targetCell, QWidget *parent = 0); + virtual ~DCCellScriptsEditorPageWidget(); + + bool getIsModified() const; + + bool loadScriptsFormFile(); + QSet saveScriptsToFile(bool saveModifiedOnly); + bool saveCustomScriptOnlyToFile(bool saveModifiedOnly); + bool saveCellCodeScriptOnlyToFile(bool saveModifiedOnly); + +signals: + void editingCellDestroyed(DCCell *cell); + void cellScriptsModifiedStatusChanged(QWidget *self, bool modified); + void cellScriptsSaved(QWidget *self); + +private slots: + void assignedCellCodeChanged(); + void cellDestroyed(); + void customScriptChanged(); + void cellCodeScriptChanged(); +}; + +#endif // DCCELLCODEEDITORPAGEWIDGET_H diff --git a/Source/codeeditor/dccellscriptseditortabwidget.cpp b/Source/codeeditor/dccellscriptseditortabwidget.cpp new file mode 100644 index 0000000..bd7f02d --- /dev/null +++ b/Source/codeeditor/dccellscriptseditortabwidget.cpp @@ -0,0 +1,288 @@ +// 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 . + +// +// Created by tkawata on Nov-3, 2012. +// +#include "dccellscriptseditortabwidget.h" + +#include +#include +#include +#include + +#include "dccodeeditor.h" +#include "dccell.h" +#include "dccellscriptseditorpagewidget.h" +#include "dccellscriptseditorwindow.h" + +DCCellScriptsEditorTabWidget::DCCellScriptsEditorTabWidget(DCCellScriptsEditorWindow *parent) : + QTabWidget(parent), d_parent(parent) +{ + connect(this, SIGNAL(currentChanged(int)), this, SLOT(slotCurrentIndexChanged(int))); + connect(this, SIGNAL(tabCloseRequested(int)), this, SLOT(slotTabCloseRequested(int))); +} + + +DCCellScriptsEditorTabWidget::~DCCellScriptsEditorTabWidget() +{ + +} + +int DCCellScriptsEditorTabWidget::getIndexOf(const DCCell *cell) const +{ + int index = -1; + for (int i = 0; i < count(); i++) + { + QMap::const_iterator it = d_targets.find(widget(i)); + if (it != d_targets.end()) + { + if (it.value() == cell) + { + index = i; + break; + } + } + } + return index; +} + +bool DCCellScriptsEditorTabWidget::getIsModified(const DCCell *cell) const +{ + int index = getIndexOf(cell); + if (index == -1) + return false; + + return getIsModified(index); +} + +bool DCCellScriptsEditorTabWidget::getIsModified(int index) const +{ + DCCellScriptsEditorPageWidget *pageWidget = dynamic_cast(widget(index)); + return pageWidget->getIsModified(); +} + +DCCell* DCCellScriptsEditorTabWidget::getCurrentEditCell() const +{ + if (currentIndex() == -1) + return NULL; + + QMap::const_iterator it = d_targets.find(currentWidget()); + if (it != d_targets.end()) + { + return it.value(); + } + return NULL; +} + +DCCell* DCCellScriptsEditorTabWidget::getCellForIndex(int i) const +{ + if (count() < i) + return NULL; + + QMap::const_iterator it = d_targets.find(widget(i)); + if (it != d_targets.end()) + { + return it.value(); + } + return NULL; +} + +void DCCellScriptsEditorTabWidget::tabRemoved(int index) +{ + QMap removedTargets = d_targets; + + for (int i = 0; i < count(); i++) + { + removedTargets.take(widget(i)); + } + + QMap::iterator it = removedTargets.begin(); + while (it != removedTargets.end()) + { + emit editTabRemoved(it.value()); + d_targets.remove(it.key()); + it.key()->deleteLater(); + ++it; + } +} + +void DCCellScriptsEditorTabWidget::slotCurrentIndexChanged(int index) +{ + QMap::iterator it = d_targets.find(widget(index)); + if (it != d_targets.end()) + { + emit activeEditTabChanged(it.value()); + } +} + +void DCCellScriptsEditorTabWidget::slotCellDestroyed(DCCell *cell) +{ + removeTabForCell(cell); +} + +void DCCellScriptsEditorTabWidget::slotTabCloseRequested(int index) +{ + QMap::iterator it = d_targets.find(widget(index)); + if (it != d_targets.end()) + { + emit tabCloseRequested(it.value()); + } +} + +void DCCellScriptsEditorTabWidget::slotTabPageContentModifiedStatusChanged(QWidget *tabPage, bool modified) +{ + int index = indexOf(tabPage); + if (index == -1) + return; + + QMap::iterator it = d_targets.find(tabPage); + if (it != d_targets.end()) + { + QString tabTitle = QString::fromStdString(it.value()->getName()); + if (modified) + tabTitle.append(" * "); + setTabText(index, tabTitle); + emit editTabContentModifiedStatusChanged(it.value(), modified); + } +} + +void DCCellScriptsEditorTabWidget::slotTabPageContentChangedByExternal(QWidget *tabPage) +{ + //TODO + +} + +void DCCellScriptsEditorTabWidget::slotTabPageContentSaved(QWidget *tabPage) +{ + int index = indexOf(tabPage); + if (index == -1) + return; + + QMap::iterator it = d_targets.find(tabPage); + if (it != d_targets.end()) + { + QString tabTitle = QString::fromStdString(it.value()->getName()); + setTabText(index, tabTitle); + + emit editTabContentModifiedStatusChanged(it.value(), false); + } +} + +void DCCellScriptsEditorTabWidget::openTab(DCCell *target) +{ + int index = -1; + for (int i = 0; i < count(); i++) + { + QMap::iterator it = d_targets.find(widget(i)); + if (it != d_targets.end()) + { + if (it.value() == target) + { + index = i; + break; + } + } + } + + if (index >= 0) + { + setCurrentIndex(index); + } + 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*))); + } +} + + QSet DCCellScriptsEditorTabWidget::saveActiveTabContentToFile(bool saveModifiedOnly) +{ + QSet empty; + + if (currentIndex() == -1) + return empty; + + DCCellScriptsEditorPageWidget *pageWidget = dynamic_cast(currentWidget()); + if (pageWidget) + { + return pageWidget->saveScriptsToFile(saveModifiedOnly); + } + return empty; +} + +QSet DCCellScriptsEditorTabWidget::saveContentToFile(int tabIndex, bool saveModifiedOnly) +{ + QSet empty; + + if (count() < tabIndex) + return empty; + + DCCellScriptsEditorPageWidget *pageWidget = dynamic_cast(widget(tabIndex)); + if (pageWidget) + { + return pageWidget->saveScriptsToFile(saveModifiedOnly); + } + return empty; +} + +bool DCCellScriptsEditorTabWidget::saveCustomScriptOnlyToFile(int tabIndex, bool saveModifiedOnly) +{ + if (count() < tabIndex) + return false; + + DCCellScriptsEditorPageWidget *pageWidget = dynamic_cast(widget(tabIndex)); + if (pageWidget) + { + return pageWidget->saveCustomScriptOnlyToFile(saveModifiedOnly); + } + return false; + +} + +bool DCCellScriptsEditorTabWidget::saveCellCodeScriptOnlyToFile(int tabIndex, bool saveModifiedOnly) +{ + if (count() < tabIndex) + return false; + + DCCellScriptsEditorPageWidget *pageWidget = dynamic_cast(widget(tabIndex)); + if (pageWidget) + { + return pageWidget->saveCellCodeScriptOnlyToFile(saveModifiedOnly); + } + return false; + +} + +void DCCellScriptsEditorTabWidget::removeTabForCell(DCCell *cell) +{ + + int index = getIndexOf(cell); + + if (index >= 0) + { + removeTab(index); + } +} + +void DCCellScriptsEditorTabWidget::removeAllTab() +{ + while(count() > 0) + removeTab(0); +} diff --git a/Source/codeeditor/dccellscriptseditortabwidget.h b/Source/codeeditor/dccellscriptseditortabwidget.h new file mode 100644 index 0000000..39255d3 --- /dev/null +++ b/Source/codeeditor/dccellscriptseditortabwidget.h @@ -0,0 +1,75 @@ +// 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 . + +// +// Created by tkawata on Nov-3, 2012. +// +#ifndef DCCELLSCRIPTSEDITORTABWIDGET_H +#define DCCELLSCRIPTSEDITORTABWIDGET_H + +#include +#include + +class DCCell; +class DCCellCode; +class DCVCPage; +class DCCellScriptsEditorWindow; + +class DCCellScriptsEditorTabWidget : public QTabWidget +{ + Q_OBJECT + + DCCellScriptsEditorWindow *d_parent; + QMap d_targets; + + +public: + explicit DCCellScriptsEditorTabWidget(DCCellScriptsEditorWindow *parent); + virtual ~DCCellScriptsEditorTabWidget(); + + int getIndexOf(const DCCell *cell) const; + bool getIsModified(const DCCell *cell) const; + bool getIsModified(int index) const; + DCCell* getCurrentEditCell() const; + DCCell* getCellForIndex(int i) const; + +protected: + virtual void tabRemoved(int index); + +public: + void openTab(DCCell *editTarget); + QSet saveActiveTabContentToFile(bool saveModifiedOnly); + QSet saveContentToFile(int tabIndex, bool saveModifiedOnly); + bool saveCustomScriptOnlyToFile(int tabIndex, bool saveModifiedOnly); + bool saveCellCodeScriptOnlyToFile(int tabIndex, bool saveModifiedOnly); + void removeTabForCell(DCCell *cell); + void removeAllTab(); + +signals: + void activeEditTabChanged(DCCell *editTarget); + void editTabContentModifiedStatusChanged(DCCell *editTarget, bool modified); + void editTabRemoved(DCCell *editTarget); + void tabCloseRequested(DCCell *editTarget); + +private slots: + void slotCurrentIndexChanged(int index); + void slotTabCloseRequested(int index); + void slotCellDestroyed(DCCell *cell); + void slotTabPageContentSaved(QWidget *tabPage); + void slotTabPageContentModifiedStatusChanged(QWidget *tabPage, bool modified); + void slotTabPageContentChangedByExternal(QWidget *tabPage); +}; + +#endif // DCCELLSCRIPTSEDITORTABWIDGET_H diff --git a/Source/codeeditor/dccellscriptseditorwindow.cpp b/Source/codeeditor/dccellscriptseditorwindow.cpp new file mode 100644 index 0000000..1210a09 --- /dev/null +++ b/Source/codeeditor/dccellscriptseditorwindow.cpp @@ -0,0 +1,467 @@ +// 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 . + +// +// Created by tkawata on Nov-3, 2012. +// +#include "dccellscriptseditorwindow.h" + +#include +#include +#include +#include +#include + +#include "dccodeeditor.h" +#include "dccreator.h" +#include "dccell.h" +#include "dccellcode.h" +#include "dccellscriptseditortabwidget.h" +#include "mainwindow.h" +#include "utils/dcutil.h" +#include "dialog/dcassigncellcodeclassdialog.h" + +static DCCellScriptsEditorWindow *s_instance = NULL; + +DCCellScriptsEditorWindow::DCCellScriptsEditorWindow(DCCreator *creator, QWidget *parent) : + QDialog(parent), d_creator(creator) +{ + //code editor + d_tabWidget = new DCCellScriptsEditorTabWidget(this); + d_tabWidget->setTabsClosable(true); + + //tool + QWidget *toolWidget = new QWidget; + QSplitter *toolWidgetSplitter = new QSplitter(Qt::Vertical); + + //cell info tool + QWidget *cellInfoWidget = new QGroupBox(tr("Cell Information")); + QGridLayout *cellInfoLayout = new QGridLayout; + cellInfoLayout->addWidget(new QLabel(tr("Name:")),0,0); + cellInfoLayout->addWidget(new QLabel(tr("Path")), 1,0); + cellInfoLayout->addWidget(new QLabel(tr("Type")), 2,0); + + d_cellName = new QLineEdit(); + d_cellName->setReadOnly(true); + d_cellPath = new QLineEdit(); + d_cellPath->setReadOnly(true); + d_cellType = new QLineEdit(); + d_cellType->setReadOnly(true); + cellInfoLayout->addWidget(d_cellName, 0, 1); + cellInfoLayout->addWidget(d_cellPath, 1, 1); + cellInfoLayout->addWidget(d_cellType, 2, 1); + + cellInfoWidget->setLayout(cellInfoLayout); + + //cell code info tool + QWidget *cellCodeInfoWidget = new QWidget; + d_cellCodePanel = new QStackedLayout; + + QWidget *assignedCellCodeInfoWidget = new QGroupBox(tr("Cell Code Information")); + QGridLayout *cellCodeInfoLayout = new QGridLayout; + cellCodeInfoLayout->addWidget(new QLabel(tr("Name:")),0,0); + cellCodeInfoLayout->addWidget(new QLabel(tr("Path:")),1,0); + d_cellCodeName = new QLineEdit(); + d_cellCodeName->setReadOnly(true); + d_cellCodePath = new QLineEdit(); + d_cellCodePath->setReadOnly(true); + d_unassignCellCodeButton = new QPushButton(tr("Unassign cell code")); + cellCodeInfoLayout->addWidget(d_cellCodeName, 0,1); + cellCodeInfoLayout->addWidget(d_cellCodePath, 1,1); + cellCodeInfoLayout->addWidget(d_unassignCellCodeButton, 2,0,1,2); + assignedCellCodeInfoWidget->setLayout(cellCodeInfoLayout); + + QWidget *nonCellCodeInfoWidget = new QGroupBox(tr("Cell code - not assigned")); + QVBoxLayout *nonCellCodeInfoLayout = new QVBoxLayout; + QLabel *msg = new QLabel(tr("This cell don't have a assinged cell code")); + msg->setStyleSheet("color:red;"); + nonCellCodeInfoLayout->addWidget(msg); + d_assignCellCodeButton = new QPushButton(tr("Assign a cell code to this cell...")); + nonCellCodeInfoLayout->addWidget(d_assignCellCodeButton); + nonCellCodeInfoWidget->setLayout(nonCellCodeInfoLayout); + + cellCodeInfoWidget->setLayout(d_cellCodePanel); + d_cellCodePanel->addWidget(assignedCellCodeInfoWidget); + d_cellCodePanel->addWidget(nonCellCodeInfoWidget); + + toolWidgetSplitter->addWidget(cellInfoWidget); + toolWidgetSplitter->addWidget(cellCodeInfoWidget); + + QVBoxLayout *toolWidgetLayout = new QVBoxLayout; + toolWidgetLayout->addWidget(toolWidgetSplitter); + toolWidgetLayout->addStretch(1); + toolWidget->setLayout(toolWidgetLayout); + + //buttons + QHBoxLayout *buttonLayout = new QHBoxLayout; + d_saveButton = new QPushButton(tr("Save")); + d_closeButton = new QPushButton(tr("Close")); + buttonLayout->addStretch(); + buttonLayout->addWidget(d_saveButton); + buttonLayout->addWidget(d_closeButton); + + // put together + QSplitter *hsplitter = new QSplitter(Qt::Horizontal, this); + hsplitter->addWidget(d_tabWidget); + hsplitter->addWidget(toolWidget); + hsplitter->setStretchFactor(0,4); + hsplitter->setStretchFactor(1,1); + + QVBoxLayout *rootLayout = new QVBoxLayout; + rootLayout->addWidget(hsplitter); + rootLayout->addLayout(buttonLayout); + + setLayout(rootLayout); + + connect(d_creator, SIGNAL(sceneChanged(const void*,DCScene*)), this, SLOT(sceneChanged(const void*,DCScene*))); + connect(d_creator, SIGNAL(commandExecuted(const QUndoCommand*)), this, SLOT(creatorCommandExecuted(const QUndoCommand*))); + connect(d_tabWidget, SIGNAL(activeEditTabChanged(DCCell*)), this, SLOT(editTabChanged(DCCell*))); + connect(d_tabWidget, SIGNAL(editTabContentModifiedStatusChanged(DCCell*, bool)), this, SLOT(editTabContentModifiedStatusChanged(DCCell*, bool))); + connect(d_tabWidget, SIGNAL(editTabRemoved(DCCell*)), this, SLOT(editTabRemoved(DCCell*))); + connect(d_tabWidget, SIGNAL(tabCloseRequested(DCCell*)), this, SLOT(editTabCloseRequested(DCCell*))); + + connect(d_saveButton, SIGNAL(clicked()), this, SLOT(saveButtonClicked())); + connect(d_closeButton, SIGNAL(clicked()), this, SLOT(close())); + connect(d_assignCellCodeButton, SIGNAL(clicked()), this, SLOT(assignCellCode())); + connect(d_unassignCellCodeButton, SIGNAL(clicked()), this, SLOT(unassignCellCode())); + + QByteArray gdata = MainWindow::readSettingsForCellScriptsEditorGeometory(); + if (gdata.length() > 0) + restoreGeometry(gdata); +} + + +DCCellScriptsEditorWindow::~DCCellScriptsEditorWindow() +{ + +} + +//static +DCCellScriptsEditorWindow* DCCellScriptsEditorWindow::construct(DCCreator *creator) +{ + if (s_instance) + { + delete s_instance; + } + s_instance = new DCCellScriptsEditorWindow(creator); + return s_instance; +} + +//static +bool DCCellScriptsEditorWindow::getIsVisible() +{ + if (s_instance) + { + return s_instance->isVisible(); + } + return false; +} + +//static +bool DCCellScriptsEditorWindow::startEditing(DCCell *cell) +{ + if (s_instance) + { + return s_instance->startEditingPrivate(cell); + } + return false; +} + +//static +bool DCCellScriptsEditorWindow::saveScriptsBelongTo(DCVCPage *page, bool modifiedOnly) +{ + if (s_instance) + { + return s_instance->saveScriptsBelongToPrivate(page, modifiedOnly); + } + return false; +} + +//static +QSet DCCellScriptsEditorWindow::saveScriptsAll(bool modifiedOnly) +{ + QSet empty; + + if (s_instance) + { + return s_instance->saveScriptsAllPrivate(modifiedOnly); + } + return empty; +} + +//static +void DCCellScriptsEditorWindow::destroyEditor() +{ + if (s_instance) + { + delete s_instance; + s_instance = NULL; + } +} + + +void DCCellScriptsEditorWindow::closeEvent(QCloseEvent *event) +{ + if (maybeSave()) + { + if (isVisible()) + MainWindow::writeSettingsForCellScriptsEditorGeometory(saveGeometry()); + event->accept(); + } + else + { + event->ignore(); + } +} + + +bool DCCellScriptsEditorWindow::maybeSave() +{ + bool r = true; + for (int i = 0; r && i < d_tabWidget->count(); i++) + { + r = maybeSave(i); + } + + if (r) + { + d_tabWidget->removeAllTab(); + } + + return r; +} + +bool DCCellScriptsEditorWindow::maybeSave(DCCell *cell) +{ + int index = d_tabWidget->getIndexOf(cell); + if (index < 0) + return true; + + return maybeSave(index); +} + +bool DCCellScriptsEditorWindow::maybeSave(int index) +{ + bool r = true; + if (d_tabWidget->getIsModified(index)) + { + d_tabWidget->setCurrentIndex(index); + QMessageBox::StandardButton ret; + ret = QMessageBox::warning(this, tr("Cell scripts editor"), + tr("The cell scripts has been modified.\n" + "Do you want to save your changes?"), + QMessageBox::Save | QMessageBox::Discard | QMessageBox::Cancel); + if (ret == QMessageBox::Save) + { + QSet modifiedPages = d_tabWidget->saveContentToFile(index, true); + d_creator->savePage(modifiedPages, false); + } + else if (ret == QMessageBox::Cancel) + { + r = false; + } + } + return r; +} + +void DCCellScriptsEditorWindow::updateWindowState() +{ + QString windowTitle = ""; + + bool modified = false; + if (d_creator->getScene()) + { + DCCell *cell = d_tabWidget->getCurrentEditCell(); + if (cell) + { + windowTitle.append(QString::fromStdString(cell->getName())); + if (d_tabWidget->getIsModified(cell)) + { + windowTitle.append("*"); + modified = true; + } + windowTitle.append(" - "); + + d_cellName->setText(QString::fromStdString(cell->getName())); + d_cellPath->setText(QString::fromStdString(cell->getLocation())); + d_cellType->setText(cell->getType()); + if (cell->getIsCellCodeAssgined()) + { + d_cellCodePanel->setCurrentIndex(0); + DCCellCode *cellCode = cell->getCellCode(); + QString fqnName = QString::fromStdString(cellCode->getFQNName()); + d_cellCodeName->setText(DCUtil::getNameFromFQNPath(fqnName)); + d_cellCodePath->setText(DCUtil::getContainerBasedPathFromFQNPath(fqnName)); + } + else + { + d_cellCodePanel->setCurrentIndex(1); + d_cellCodeName->setText(""); + d_cellCodePath->setText(""); + } + } + } + windowTitle.append("Cell Scripts editor"); + setWindowTitle(windowTitle); + + if (modified) + { + d_saveButton->setEnabled(true); + d_saveButton->setDefault(true); + } + else + { + d_saveButton->setEnabled(false); + d_closeButton->setDefault(true); + } +} + +//slot +void DCCellScriptsEditorWindow::sceneChanged(const void *, DCScene *) +{ + close(); +} + +//slot +void DCCellScriptsEditorWindow::editTabChanged(DCCell*) +{ + updateWindowState(); +} + +//slot +void DCCellScriptsEditorWindow::editTabContentModifiedStatusChanged(DCCell *, bool) +{ + updateWindowState(); +} + +//slot +void DCCellScriptsEditorWindow::editTabRemoved(DCCell *cell) +{ + if (d_tabWidget->count() == 0) + { + close(); + } +} + +//slot +void DCCellScriptsEditorWindow::editTabCloseRequested(DCCell *editTarget) +{ + if (maybeSave(editTarget)) + { + d_tabWidget->removeTabForCell(editTarget); + } +} + +//slot +void DCCellScriptsEditorWindow::saveButtonClicked() +{ + QSet modifiedPages = d_tabWidget->saveActiveTabContentToFile(false); + d_creator->savePage(modifiedPages, false); +} + +//slot +void DCCellScriptsEditorWindow::assignCellCode() +{ + DCCell *cell = d_tabWidget->getCurrentEditCell(); + if (!cell) + return; + + DCAssignCellCodeClassDialog dialog(d_creator,this); + dialog.exec(); + DCCellCode *cellCode = dialog.getSelectedCellCodeClass(); + if (cellCode) + { + d_creator->doCommandAssignCellCodeClassToCell(this, cell , cellCode); + } +} + +//slot +void DCCellScriptsEditorWindow::unassignCellCode() +{ + DCCell *cell = d_tabWidget->getCurrentEditCell(); + if (!cell) + return; + + d_creator->doCommandUnassignCellCodeClassFromCell(this, cell); +} + +void DCCellScriptsEditorWindow::creatorCommandExecuted(const QUndoCommand *command) +{ + updateWindowState(); +} + +bool DCCellScriptsEditorWindow::startEditingPrivate(DCCell *cell) +{ + d_tabWidget->openTab(cell); + + if (!isVisible()) + { + QByteArray gdata = MainWindow::readSettingsForCellScriptsEditorGeometory(); + if (gdata.length() > 0) + restoreGeometry(gdata); + } + show(); + activateWindow(); + return true; +} + +bool DCCellScriptsEditorWindow::saveScriptsBelongToPrivate(DCVCPage *page, bool modifiedOnly) +{ + bool result; + for (int i = 0; i < d_tabWidget->count(); i++) + { + DCCell *cell = d_tabWidget->getCellForIndex(i); + DCCellCode *cellCode = NULL; + if (cell->getIsCellCodeAssgined()) + cellCode = cell->getCellCode(); + + if (page == cell->getPageBelonging()) + { + if (page == cellCode->getPageBelonging()) + { + if (d_tabWidget->saveContentToFile(i, modifiedOnly).count()) + { + result = false; + } + } + else + { + if (!d_tabWidget->saveCustomScriptOnlyToFile(i, modifiedOnly)) + { + result = false; + } + } + } + else if (cellCode && page == cellCode->getPageBelonging()) + { + if (!d_tabWidget->saveCellCodeScriptOnlyToFile(i, modifiedOnly)) + { + result = false; + } + } + } + + return result; +} + +QSet DCCellScriptsEditorWindow::saveScriptsAllPrivate(bool modifiedOnly) +{ + QSet modifiedPages; + for (int i = 0; i < d_tabWidget->count(); i++) + { + modifiedPages += d_tabWidget->saveContentToFile(i, modifiedOnly); + } + return modifiedPages; +} diff --git a/Source/codeeditor/dccellscriptseditorwindow.h b/Source/codeeditor/dccellscriptseditorwindow.h new file mode 100644 index 0000000..9ac0207 --- /dev/null +++ b/Source/codeeditor/dccellscriptseditorwindow.h @@ -0,0 +1,97 @@ +// 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 . + +// +// Created by tkawata on Nov-3, 2012. +// +#ifndef DCCELLSCRIPTSEDITORWINDOW_H +#define DCCELLSCRIPTSEDITORWINDOW_H + +#include +#include +#include +#include +#include +#include +#include +#include + +class DCCreator; +class DCScene; +class DCCell; +class DCCellCode; +class DCVCPage; +class DCCodeEditor; +class DCCellScriptsEditorTabWidget; + +class DCCellScriptsEditorWindow : public QDialog +{ + Q_OBJECT + + DCCreator *d_creator; + + DCCellScriptsEditorTabWidget *d_tabWidget; + DCCodeEditor *d_customScriptEditor; + DCCodeEditor *d_classCodeEditor; + + QPushButton *d_saveButton; + QPushButton *d_closeButton; + + QLineEdit *d_cellName; + QLineEdit *d_cellPath; + QLineEdit *d_cellType; + QLineEdit *d_cellCodeName; + QLineEdit *d_cellCodePath; + QPushButton *d_assignCellCodeButton; + QPushButton *d_unassignCellCodeButton; + QStackedLayout *d_cellCodePanel; + + bool maybeSave(); + bool maybeSave(DCCell *cell); + bool maybeSave(int index); + void updateWindowState(); + bool startEditingPrivate(DCCell *cell); + bool saveScriptsBelongToPrivate(DCVCPage *page, bool modifiedOnly); + QSet saveScriptsAllPrivate(bool modifiedOnly); + + DCCellScriptsEditorWindow(DCCreator *creator, QWidget *parent = 0); +public: + virtual ~DCCellScriptsEditorWindow(); + + static DCCellScriptsEditorWindow* construct(DCCreator *creator); + static bool getIsVisible(); + static bool startEditing(DCCell *cell); + static bool saveScriptsBelongTo(DCVCPage *page, bool modifiedOnly); + static QSet saveScriptsAll(bool modifiedOnly); + static void destroyEditor(); + + virtual void closeEvent(QCloseEvent *event); + + +signals: + +private slots: + void sceneChanged(const void *requester, DCScene *scene); + void editTabChanged(DCCell *cell); + void editTabContentModifiedStatusChanged(DCCell *cell, bool); + void editTabRemoved(DCCell *cell); + void editTabCloseRequested(DCCell *cell); + void saveButtonClicked(); + void creatorCommandExecuted(const QUndoCommand *command); + void assignCellCode(); + void unassignCellCode(); +}; + +#endif // DCCELLSCRIPTSEDITORWINDOW_H diff --git a/Source/codeeditor/dccodehighlighter.cpp b/Source/codeeditor/dccodehighlighter.cpp index 008c906..4e89121 100644 --- a/Source/codeeditor/dccodehighlighter.cpp +++ b/Source/codeeditor/dccodehighlighter.cpp @@ -65,7 +65,7 @@ DCCodeHighlighter::DCCodeHighlighter(QTextDocument *parent) : { HighlightingRule rule; - keywordFormat.setForeground(QColor(Qt::blue).lighter()); + keywordFormat.setForeground(QColor(Qt::blue)); keywordFormat.setFontWeight(QFont::Bold); QStringList keywordPatterns; keywordPatterns << "\\bthis.cell.axonValue\\b" << "\\bthis.cell.receptors\\b" @@ -90,13 +90,13 @@ DCCodeHighlighter::DCCodeHighlighter(QTextDocument *parent) : multiLineCommentFormat.setForeground(Qt::red); - quotationFormat.setForeground(QColor(Qt::green).lighter()); + quotationFormat.setForeground(QColor(Qt::green).darker()); rule.pattern = QRegExp("\".*\""); rule.format = quotationFormat; highlightingRules.append(rule); functionFormat.setFontItalic(true); - functionFormat.setForeground(QColor(Qt::blue).lighter(170)); + functionFormat.setForeground(QColor(Qt::blue)); rule.pattern = QRegExp("\\b[A-Za-z0-9_]+(?=\\()"); rule.format = functionFormat; highlightingRules.append(rule); diff --git a/Source/command/dceditcommands.cpp b/Source/command/dceditcommands.cpp index b069194..a9963da 100644 --- a/Source/command/dceditcommands.cpp +++ b/Source/command/dceditcommands.cpp @@ -186,43 +186,6 @@ void DCRemoveAxonTerminalCommand::undo() //TODO } - -DCStartCellCodeEditCommand::DCStartCellCodeEditCommand(const void *requester, DCCreator *creator, DCCell *ownerCell) - : DCCommand(requester, creator), d_cell(ownerCell) -{ - -} - -void DCStartCellCodeEditCommand::redo() -{ - bool r =getScene()->startCellCodeEdit(getRequester(), d_cell); - setCommandResult(r ? DCCommand::DCCOMMAND_SUCCEEDED : DCCommand::DCCOMMAND_FAILED); -} - -void DCStartCellCodeEditCommand::undo() -{ - -} - - -DCFinishCellCodeEditCommand::DCFinishCellCodeEditCommand(const void *requester, DCCreator *creator) - : DCCommand(requester, creator) -{ - -} - -void DCFinishCellCodeEditCommand::redo() -{ - bool r = getScene()->finishCellCodeEdit(getRequester()); - setCommandResult(r ? DCCommand::DCCOMMAND_SUCCEEDED : DCCommand::DCCOMMAND_FAILED); -} - -void DCFinishCellCodeEditCommand::undo() -{ - -} - - /*--------------------------------*/ DCAssignCellCodeClassToCellCommand::DCAssignCellCodeClassToCellCommand(const void *requester, DCCreator *creator, DCCell *cell, DCCellCode *cellCode) : DCCommand(requester, creator), d_cell(cell), d_cellCode(cellCode), d_prevClass(NULL) @@ -437,7 +400,7 @@ void DCChangeCellTypeCommand::redo() d_cell->saveCustomScript(""); } - if (d_cell->getIsCellCodeClassAssgined()) + if (d_cell->getIsCellCodeAssgined()) { //TODO } diff --git a/Source/command/dceditcommands.h b/Source/command/dceditcommands.h index 4d440e4..988a4d5 100644 --- a/Source/command/dceditcommands.h +++ b/Source/command/dceditcommands.h @@ -90,29 +90,6 @@ public: //------------------------------------------ -class DCStartCellCodeEditCommand : public DCCommand -{ - DCCell *d_cell; -public: - DCStartCellCodeEditCommand(const void *requester, DCCreator *creator, DCCell *ownerCell); - virtual ~DCStartCellCodeEditCommand() {} - void undo(); - void redo(); -}; - -//------------------------------------------ - -class DCFinishCellCodeEditCommand : public DCCommand -{ -public: - DCFinishCellCodeEditCommand(const void *requester, DCCreator *creator); - virtual ~DCFinishCellCodeEditCommand() {} - void undo(); - void redo(); -}; - -//------------------------------------------ - class DCAssignCellCodeClassToCellCommand : public DCCommand { DCCell *d_cell; diff --git a/Source/dccell.cpp b/Source/dccell.cpp index 1b7a8d4..4f44163 100644 --- a/Source/dccell.cpp +++ b/Source/dccell.cpp @@ -104,7 +104,7 @@ DCVCPage* DCCell::getPageBelonging() const return d_vComponent->getPageBelonging(); } -bool DCCell::getIsCellCodeClassAssgined() const +bool DCCell::getIsCellCodeAssgined() const { DCContainer *container = dynamic_cast(getContainer()); diff --git a/Source/dccell.h b/Source/dccell.h index 2e1e7d1..d495a59 100644 --- a/Source/dccell.h +++ b/Source/dccell.h @@ -79,7 +79,7 @@ public: DCVPageComponent * getVComponent() const { return d_vComponent; } DCVCPage* getPageBelonging() const; DCCellCode* getCellCode() const { return d_cellCode; } - bool getIsCellCodeClassAssgined() const; + bool getIsCellCodeAssgined() const; DCAxon* getAxon() const; std::string getReceptorName(DCReceptor *receptor) const; DCReceptor* getReceptor(const QString& receptorName); diff --git a/Source/dccellcode.cpp b/Source/dccellcode.cpp index 70cd81f..7a1cfaa 100644 --- a/Source/dccellcode.cpp +++ b/Source/dccellcode.cpp @@ -36,9 +36,9 @@ QString DCCellCode::getOwnScript() const return d_container->readCellCodeScriptFromFile(this); } -void DCCellCode::saveScript(const QString &script) +bool DCCellCode::saveScript(const QString &script) { - d_container->saveClassScriptToWorkFile(this, script.toStdString()); + return d_container->saveClassScriptToWorkFile(this, script.toStdString()); } DCVCPage* DCCellCode::getPageBelonging() const diff --git a/Source/dccellcode.h b/Source/dccellcode.h index 1b322f3..9d7aca3 100644 --- a/Source/dccellcode.h +++ b/Source/dccellcode.h @@ -56,7 +56,7 @@ public: virtual ~DCCellCode(); virtual TKCellCodeInstance* createCellCodeInstance(TKCell *owner, const void *data) { return 0; } - void saveScript(const QString& script); + bool saveScript(const QString& script); DCVPageComponent* getVComponent() const { return d_vComponent; } DCVCPage* getPageBelonging() const; QString getOwnScript() const; diff --git a/Source/dcconsole.cpp b/Source/dcconsole.cpp index a958b16..83b2f85 100644 --- a/Source/dcconsole.cpp +++ b/Source/dcconsole.cpp @@ -24,7 +24,7 @@ DCConsole::DCConsole() : d_size(100) void DCConsole::vprintf(TKLog::MessageType type, const char *fmt, va_list ap) { - (type); + Q_UNUSED(type); QString msg = QString().vsprintf(fmt,ap); d_queue.append(msg); diff --git a/Source/dccontainer.h b/Source/dccontainer.h index 3e0b9c8..a52e1e8 100644 --- a/Source/dccontainer.h +++ b/Source/dccontainer.h @@ -129,7 +129,7 @@ public: DCContent* getContent() const { return d_content; } DCScene* getScene() const { return d_scene; } QList getSelectedCellObjects() const; - virtual float getValue(std::string key) const { return 0; } + virtual float getValue(std::string key) const { Q_UNUSED(key); return 0; } TKCellCode* getEmptyCellCodeClass() const { return mEmptyCellClass; } bool isScriptableCell(DCCell *cell); @@ -139,7 +139,7 @@ public: void unselectCellObjectAll(); - virtual void setValue(std::string key, float value) {} + virtual void setValue(std::string key, float value) { Q_UNUSED(key); Q_UNUSED(value);} virtual void beganParsePage(const char *docRoot, const char *path); virtual void endedParsePage(const char *docRoot, const char *path); diff --git a/Source/dccontainersaver.cpp b/Source/dccontainersaver.cpp index abd72fa..8691b46 100644 --- a/Source/dccontainersaver.cpp +++ b/Source/dccontainersaver.cpp @@ -147,7 +147,7 @@ QDomDocument* constructDocumentForPage(DCContainer *conteinr, const DCVCPage *pa QDomElement aCellCodeTag = doc->createElement("a"); aCellCodeTag.setAttribute("parameter", "cellcode"); - if (cell->getIsCellCodeClassAssgined()) + if (cell->getIsCellCodeAssgined()) { aCellCodeTag.setAttribute("href", QString::fromStdString(cell->getCellCode()->getFQNName())); } diff --git a/Source/dccreator.cpp b/Source/dccreator.cpp index e1db5df..c5909e5 100644 --- a/Source/dccreator.cpp +++ b/Source/dccreator.cpp @@ -37,8 +37,7 @@ #include "utils/dcdialogutil.h" #include "utils/dccommandutil.h" #include "dialog/dcinputreceptornamedialog.h" - -#include "dctoolwindowcellcodeeditor.h" +#include "codeeditor/dccellscriptseditorwindow.h" #include #include @@ -48,7 +47,6 @@ DCCreator::DCCreator(QMainWindow *mainwindow) d_persMode(DC_PERSMODE_PAGEEDIT), d_contentRootPath("") { d_undoStack = new QUndoStack(this); - d_cellCodeEditor = new DCToolWindowCellCodeEditor(this); d_console = new DCConsole; TKLog::setDestination(d_console); @@ -56,6 +54,9 @@ DCCreator::DCCreator(QMainWindow *mainwindow) DCCreator::~DCCreator() { + emit sceneChanged(this, NULL); + d_scene = NULL; + if (d_vcontent) { delete d_vcontent; @@ -163,13 +164,7 @@ bool DCCreator::savePage(DCVCPage *page, bool showResultInMessageBox) bool r = false; if (d_scene && d_vcontent) { - if (d_scene->getEditMode() == DCScene::DCV_EDITMODE_CELLCODE) - { - if (d_scene->getEditCellCodeCell()->getPageBelonging() == page) - { - getCellCodeEditor()->saveScriptToFile(); - } - } + DCCellScriptsEditorWindow::saveScriptsBelongTo(page, true); r = d_vcontent->saveForPage(d_vcontent->getContentRootPath(), page); } if (showResultInMessageBox) @@ -188,13 +183,29 @@ bool DCCreator::savePage(DCVCPage *page, bool showResultInMessageBox) return r; } +bool DCCreator::savePage(const QSet &pages, bool showResultInMessageBox) +{ + bool r = true; + QSet::const_iterator i = pages.constBegin(); + while (i != pages.constEnd()) + { + if (!savePage(*i, showResultInMessageBox)) + { + r = false; + } + ++i; + } + return r; +} + bool DCCreator::saveAll(bool showResultInMessageBox) { bool r = false; - if (getCellCodeEditor()->getIsOnStage()) - getCellCodeEditor()->saveScriptToFile(); - + if (DCCellScriptsEditorWindow::getIsVisible()) + { + DCCellScriptsEditorWindow::saveScriptsAll(true); + } if (d_scene && d_vcontent) { @@ -462,16 +473,6 @@ void DCCreator::doCommandRemoveAxonTerminal(const void *requester, DCCell *recep } } -void DCCreator::doCommandStartEditCellCode(const void *requester, DCCell *cell) -{ - DCCommandUtil::postStartCellCodeEditCommand(requester, this, cell); -} - -void DCCreator::doCommandFinishEditCellCode(const void *requester) -{ - DCCommandUtil::postFinishCellCodeEditCommand(requester, this); -} - void DCCreator::doCommandAssignCellCodeClassToCell(const void *requester, DCCell *cell, DCCellCode *cellCode) { DCCommandUtil::postAssignCellCodeClassToCellCommand(requester, this, cell, cellCode); diff --git a/Source/dccreator.h b/Source/dccreator.h index 49f54ca..bfaf716 100644 --- a/Source/dccreator.h +++ b/Source/dccreator.h @@ -30,7 +30,6 @@ class DCScene; class DCVComponent; class DCContainer; class DCCommand; -class DCToolWindowCellCodeEditor; class DCConsole; #include @@ -52,8 +51,6 @@ private: QUndoStack *d_undoStack; DCConsole *d_console; - DCToolWindowCellCodeEditor *d_cellCodeEditor; - public: DCCreator(QMainWindow *mainwindow); virtual ~DCCreator(); @@ -63,7 +60,6 @@ public: QMainWindow* getMainWindow() const { return d_mainWindow; } DCScene* getScene() const { return d_scene; } DCPersMode getPersMode() const { return d_persMode; } - DCToolWindowCellCodeEditor* getCellCodeEditor() const { return d_cellCodeEditor; } virtual bool event(QEvent *event); @@ -72,6 +68,7 @@ public: bool loadContent(const QString &contentRoot); bool savePage(DCVCPage *page, bool showResultInMessageBox = false); + bool savePage(const QSet& pages, bool showResultInMessageBox = false); bool saveAll(bool showResultInMessageBox = false); void selectPage(const void *requester, DCVCPage *page, bool multipleSelection); @@ -104,8 +101,6 @@ public: void doCommandCancelAddAxonTerminal(const void *requester); void doCommandRemoveAxonTerminal(const void *requester, DCCell *axonCell, DCAxonTerminal *axonTerminal); void doCommandRemoveAxonTerminal(const void *requester, DCCell *receptorCell, const QString& receptorName); - void doCommandStartEditCellCode(const void *requester, DCCell *cell); - void doCommandFinishEditCellCode(const void *requester); void doCommandAssignCellCodeClassToCell(const void *requester, DCCell *cell, DCCellCode *cellCode); void doCommandUnassignCellCodeClassFromCell(const void *requester, DCCell *cell); diff --git a/Source/denncoCreator.pro b/Source/denncoCreator.pro index 1b22cde..33cb2ed 100644 --- a/Source/denncoCreator.pro +++ b/Source/denncoCreator.pro @@ -56,7 +56,6 @@ HEADERS = mainwindow.h \ visualizer/dcglwidget.h \ visualizer/toolwindow/dctoolwindowbase.h \ visualizer/toolwindow/dctoolwindowviewcontrol.h \ - visualizer/dceditmenudialog.h \ visualizer/component/dcvpagecomponent.h \ visualizer/component/dcvcaxonterminal.h \ visualizer/component/dcvceditmodecursor.h \ @@ -80,7 +79,6 @@ HEADERS = mainwindow.h \ visualizer/eventhandler/dcvlayoutmodehandler.h \ visualizer/toolwindow/dctoolwindowterminalfromaxoneditor.h \ visualizer/toolwindow/dctoolwindowterminalfromreceptoreditor.h \ - visualizer/toolwindow/dctoolwindowcellcodeeditor.h \ dialog/dcassigncellcodeclassdialog.h \ dialog/dcaddcellcodeclassdialog.h \ dialog/dcsinglecolumntableview.h \ @@ -96,7 +94,10 @@ HEADERS = mainwindow.h \ uieditor/dcuitexteditor.h \ dcconsole.h \ propertyeditor/dcpropertyeditor.h \ - dialog/dcinputnewcontentdirdialog.h + dialog/dcinputnewcontentdirdialog.h \ + codeeditor/dccellscriptseditorwindow.h \ + codeeditor/dccellscriptseditortabwidget.h \ + codeeditor/dccellscriptseditorpagewidget.h SOURCES = main.cpp \ mainwindow.cpp \ @@ -148,7 +149,6 @@ SOURCES = main.cpp \ visualizer/dcglwidget.cpp \ visualizer/toolwindow/dctoolwindowbase.cpp \ visualizer/toolwindow/dctoolwindowviewcontrol.cpp \ - visualizer/dceditmenudialog.cpp \ visualizer/component/dcvcaxonterminal.cpp \ visualizer/component/dcvceditmodecursor.cpp \ visualizer/component/dcvceditmodeterminal.cpp \ @@ -171,7 +171,6 @@ SOURCES = main.cpp \ visualizer/eventhandler/dcvlayoutmodehandler.cpp \ visualizer/toolwindow/dctoolwindowterminalfromaxoneditor.cpp \ visualizer/toolwindow/dctoolwindowterminalfromreceptoreditor.cpp \ - visualizer/toolwindow/dctoolwindowcellcodeeditor.cpp \ dialog/dcassigncellcodeclassdialog.cpp \ dialog/dcaddcellcodeclassdialog.cpp \ dialog/dcsinglecolumntableview.cpp \ @@ -187,7 +186,10 @@ SOURCES = main.cpp \ uieditor/dcuitexteditor.cpp \ dcconsole.cpp \ propertyeditor/dcpropertyeditor.cpp \ - dialog/dcinputnewcontentdirdialog.cpp + dialog/dcinputnewcontentdirdialog.cpp \ + codeeditor/dccellscriptseditorwindow.cpp \ + codeeditor/dccellscriptseditortabwidget.cpp \ + codeeditor/dccellscriptseditorpagewidget.cpp RESOURCES = denncoCreator.qrc diff --git a/Source/dialog/dcassigncellcodeclassdialog.cpp b/Source/dialog/dcassigncellcodeclassdialog.cpp index ab63b3c..27d95c6 100644 --- a/Source/dialog/dcassigncellcodeclassdialog.cpp +++ b/Source/dialog/dcassigncellcodeclassdialog.cpp @@ -18,6 +18,7 @@ // #include "dcassigncellcodeclassdialog.h" +#include "dccreator.h" #include "dccontainer.h" #include "DCCellCode.h" #include "utils/dcqtitemmodel.h" @@ -29,11 +30,12 @@ #include #include -DCAssignCellCodeClassDialog::DCAssignCellCodeClassDialog(DCContainer *container, DCCreator *creator, QWidget *parent) : - QDialog(parent), d_container(container), d_creator(creator), d_selectedCellCodeClassName("") +DCAssignCellCodeClassDialog::DCAssignCellCodeClassDialog(DCCreator *creator, QWidget *parent) : + QDialog(parent), d_creator(creator), d_selectedCellCodeClassName("") { setWindowTitle(tr("Assign cell code class")); + d_container = d_creator->getCurrentContainer(); d_table = new DCSingleColumnTableView(); QStringList headers; headers << "page # name"; diff --git a/Source/dialog/dcassigncellcodeclassdialog.h b/Source/dialog/dcassigncellcodeclassdialog.h index 5ee838f..34d7568 100644 --- a/Source/dialog/dcassigncellcodeclassdialog.h +++ b/Source/dialog/dcassigncellcodeclassdialog.h @@ -43,7 +43,7 @@ private: void updateClassList(); public: - DCAssignCellCodeClassDialog(DCContainer *container, DCCreator *creator, QWidget *parent = 0); + DCAssignCellCodeClassDialog(DCCreator *creator, QWidget *parent = 0); virtual ~DCAssignCellCodeClassDialog(); DCCellCode *getSelectedCellCodeClass() const; diff --git a/Source/engine/layer1/platform/qt/QtTKConsole.cpp b/Source/engine/layer1/platform/qt/QtTKConsole.cpp index 364af26..4fb02be 100644 --- a/Source/engine/layer1/platform/qt/QtTKConsole.cpp +++ b/Source/engine/layer1/platform/qt/QtTKConsole.cpp @@ -23,7 +23,7 @@ void TKConsole::vprintf(TKLog::MessageType type, const char *fmt, va_list ap) { - (type); + Q_UNUSED(type); QString msg = QString().vsprintf(fmt,ap); qDebug() << msg << endl; } diff --git a/Source/mainwindow.cpp b/Source/mainwindow.cpp index 3b96109..304aeb7 100644 --- a/Source/mainwindow.cpp +++ b/Source/mainwindow.cpp @@ -29,6 +29,7 @@ #include "utils/dcresources.h" #include "utils/dcskeltoncreatorutil.h" #include "dialog/dcinputnewcontentdirdialog.h" +#include "dccellscriptseditorwindow.h" #include #include @@ -36,11 +37,11 @@ #include #include -#ifdef Q_WS_WIN +#if defined(Q_WS_WIN) const QString DENNCO_ENGINE = "QtDennco.exe"; -#elif Q_WS_MACX - -#elif Q_OS_UNIX +#elif defined(Q_WS_MAC) + const QString DENNCO_ENGINE = "QtDennco"; +#elif defined(Q_OS_UNIX) #endif @@ -77,6 +78,8 @@ MainWindow::MainWindow(QWidget *parent) : d_treeViewWidget = new DCTreeViewWidget(this, d_creator); ui->treeViewDock->layout()->addWidget(d_treeViewWidget); + DCCellScriptsEditorWindow::construct(d_creator); + setCurrentContent(""); setUnifiedTitleAndToolBarOnMac(true); } @@ -371,6 +374,20 @@ void MainWindow::writeSettings() settings.setValue("contents", d_contentOpenHistory); } +//static +QByteArray MainWindow::readSettingsForCellScriptsEditorGeometory() +{ + QSettings settings("dennco project", "dennco creator"); + return settings.value("segeometory").toByteArray(); +} + +//static +void MainWindow::writeSettingsForCellScriptsEditorGeometory(const QByteArray &value) +{ + QSettings settings("dennco project", "dennco creator"); + settings.setValue("segeometory", value); +} + bool MainWindow::maybeSave() { if (d_creator->getCurrentContent()) diff --git a/Source/mainwindow.h b/Source/mainwindow.h index d7e842e..8c0172f 100644 --- a/Source/mainwindow.h +++ b/Source/mainwindow.h @@ -39,6 +39,8 @@ public: explicit MainWindow(QWidget *parent = 0); ~MainWindow(); + static QByteArray readSettingsForCellScriptsEditorGeometory(); + static void writeSettingsForCellScriptsEditorGeometory(const QByteArray &value); protected: void closeEvent(QCloseEvent *event); diff --git a/Source/propertyeditor/dcpropertyeditor.cpp b/Source/propertyeditor/dcpropertyeditor.cpp index 79f95b3..7c1d501 100644 --- a/Source/propertyeditor/dcpropertyeditor.cpp +++ b/Source/propertyeditor/dcpropertyeditor.cpp @@ -25,6 +25,7 @@ #include #include #include +#include static DCPropertyEditor *s_instance = NULL; diff --git a/Source/utils/dccommandutil.cpp b/Source/utils/dccommandutil.cpp index 0d0afdd..53e43d8 100644 --- a/Source/utils/dccommandutil.cpp +++ b/Source/utils/dccommandutil.cpp @@ -68,18 +68,6 @@ void DCCommandUtil::postRemoveAxonTerminalCommand(const void *requester, DCCreat } //static -void DCCommandUtil::postStartCellCodeEditCommand(const void *requester, DCCreator *creator, DCCell *ownerCell) -{ - postEvent(creator, new DCStartCellCodeEditCommand(requester, creator, ownerCell)); -} - -//static -void DCCommandUtil::postFinishCellCodeEditCommand(const void *requester, DCCreator *creator) -{ - postEvent(creator, new DCFinishCellCodeEditCommand(requester, creator)); -} - -//static void DCCommandUtil::postUndoRequestCommand(const void *requester, DCCreator *creator) { QEvent *event = new DCUndoEvent(); diff --git a/Source/utils/dccommandutil.h b/Source/utils/dccommandutil.h index 2050577..70d1c51 100644 --- a/Source/utils/dccommandutil.h +++ b/Source/utils/dccommandutil.h @@ -40,9 +40,6 @@ struct DCCommandUtil static void postRemoveAxonTerminalCommand(const void *requester, DCCreator *creator, DCCell *axonCell, DCAxonTerminal *axonTerminal); static void postRemoveAxonTerminalCommand(const void *requester, DCCreator *creator, DCCell *receptorCell, const QString& receptorName); - static void postStartCellCodeEditCommand(const void *requester, DCCreator *creator, DCCell *ownerCell); - static void postFinishCellCodeEditCommand(const void *requester, DCCreator *creator); - static void postUndoRequestCommand(const void *requester, DCCreator *creator); static void postAssignCellCodeClassToCellCommand(const void *requester, DCCreator *creator, DCCell *cell, DCCellCode *cellCode); diff --git a/Source/visualizer/component/dcvcaxon.h b/Source/visualizer/component/dcvcaxon.h index 0f7618b..00b082a 100644 --- a/Source/visualizer/component/dcvcaxon.h +++ b/Source/visualizer/component/dcvcaxon.h @@ -37,7 +37,7 @@ public: virtual ~DCVCAxon(); virtual DCVCPage * getPageBelonging() const; - virtual bool isResizingArea(float x, float y, float z) const { return false; } + virtual bool isResizingArea(float x, float y, float z) const { Q_UNUSED(x); Q_UNUSED(y); Q_UNUSED(z); return false; } virtual DCCell * getOwnerCell() const; diff --git a/Source/visualizer/component/dcvcomponent.h b/Source/visualizer/component/dcvcomponent.h index 074cec5..d63101a 100644 --- a/Source/visualizer/component/dcvcomponent.h +++ b/Source/visualizer/component/dcvcomponent.h @@ -59,9 +59,9 @@ public: virtual void drawChildren(bool isAnimationInterval) = 0; virtual void drawChildrenForSelection(QList *itemList) = 0; virtual void translate() = 0; - virtual void setVisible(DCVVisibility visibleSelf, DCVVisibility childrenAreVisible) { d_isVisible = visibleSelf; } + virtual void setVisible(DCVVisibility visibleSelf, DCVVisibility childrenAreVisible) { Q_UNUSED(childrenAreVisible); d_isVisible = visibleSelf; } virtual void setSelectable(bool selectable) { d_isSelectable = selectable; } - virtual void setSelected(bool selectedSelf, bool updateChildren) { d_isSelected = selectedSelf; } + virtual void setSelected(bool selectedSelf, bool updateChildren) { Q_UNUSED(updateChildren); d_isSelected = selectedSelf; } virtual void renderOwnShape(bool isAnimationInterval, bool renderAsWireframe) = 0; virtual bool startDrag(float x, float y, float z, bool isResizingDrag) = 0; diff --git a/Source/visualizer/component/shape/dccuberenderer.cpp b/Source/visualizer/component/shape/dccuberenderer.cpp index 453de3a..ff510ac 100644 --- a/Source/visualizer/component/shape/dccuberenderer.cpp +++ b/Source/visualizer/component/shape/dccuberenderer.cpp @@ -30,7 +30,11 @@ #include #include -#include +#if defined(Q_WS_WIN) + #include +#else + #include +#endif static const double PI = 3.14159265358979323846264338327950288419717; diff --git a/Source/visualizer/component/shape/dccuberenderer.h b/Source/visualizer/component/shape/dccuberenderer.h index 6e18ce9..4dca754 100644 --- a/Source/visualizer/component/shape/dccuberenderer.h +++ b/Source/visualizer/component/shape/dccuberenderer.h @@ -28,7 +28,11 @@ #define DCCUBERENDERER_H #include -#include +#if defined(Q_WS_WIN) + #include +#else + #include +#endif #include class DCCubeRenderer diff --git a/Source/visualizer/dceditmenudialog.cpp b/Source/visualizer/dceditmenudialog.cpp deleted file mode 100644 index 5fcd89e..0000000 --- a/Source/visualizer/dceditmenudialog.cpp +++ /dev/null @@ -1,70 +0,0 @@ -// 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 . - -// -// Created by tkawata on Sep-30, 2012. -// -#include "dceditmenudialog.h" - -#include - -DCEditMenuDialog::DCEditMenuDialog(QWidget *parent) : - QDialog(parent), isEditCellCode(false), isEditAxonTerminal(false), isEditReceptor(false), isEditCellAttribute(false) -{ - setLayout(new QVBoxLayout); - - setWindowFlags(Qt::Dialog); - - setWindowTitle("Edit a cell..."); - - QPushButton *b1 = new QPushButton("Edit cell code"); - QPushButton *b2 = new QPushButton("Add axon terminal"); - QPushButton *b3 = new QPushButton("Add receptor"); - QPushButton *b4 = new QPushButton("Edit cell attributes"); - - layout()->addWidget(b1); - layout()->addWidget(b2); - layout()->addWidget(b3); - layout()->addWidget(b4); - - connect(b1, SIGNAL(clicked()), this, SLOT(editCellCodeSelected())); - connect(b2, SIGNAL(clicked()), this, SLOT(editAxonTerminalSelected())); - connect(b3, SIGNAL(clicked()), this, SLOT(editReceptorSelected())); - connect(b4, SIGNAL(clicked()), this, SLOT(editCellAttributeSelected())); -} - -void DCEditMenuDialog::editCellCodeSelected() -{ - isEditCellCode = true; - close(); -} - -void DCEditMenuDialog::editAxonTerminalSelected() -{ - isEditAxonTerminal = true; - close(); -} - -void DCEditMenuDialog::editReceptorSelected() -{ - isEditReceptor = true; - close(); -} - -void DCEditMenuDialog::editCellAttributeSelected() -{ - isEditCellAttribute = true; - close(); -} diff --git a/Source/visualizer/dceditmenudialog.h b/Source/visualizer/dceditmenudialog.h deleted file mode 100644 index 7e08123..0000000 --- a/Source/visualizer/dceditmenudialog.h +++ /dev/null @@ -1,45 +0,0 @@ -// 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 . - -// -// Created by tkawata on Sep-30, 2012. -// -#ifndef DCEDITMENUDIALOG_H -#define DCEDITMENUDIALOG_H - -#include -#include - -class DCEditMenuDialog : public QDialog -{ - Q_OBJECT -public: - explicit DCEditMenuDialog(QWidget *parent = 0); - - bool isEditCellCode; - bool isEditAxonTerminal; - bool isEditReceptor; - bool isEditCellAttribute; - -signals: - -private slots: - void editCellCodeSelected(); - void editAxonTerminalSelected(); - void editReceptorSelected(); - void editCellAttributeSelected(); -}; - -#endif // DCEDITMENUDIALOG_H diff --git a/Source/visualizer/dcglvisualizerwidget.cpp b/Source/visualizer/dcglvisualizerwidget.cpp index 03092db..ee62153 100644 --- a/Source/visualizer/dcglvisualizerwidget.cpp +++ b/Source/visualizer/dcglvisualizerwidget.cpp @@ -36,18 +36,21 @@ #include "dctoolwindowcelleditor.h" #include "dctoolwindowterminalfromaxoneditor.h" #include "dctoolwindowterminalfromreceptoreditor.h" -#include "dctoolwindowcellcodeeditor.h" -#include "dceditmenudialog.h" #include "eventhandler/dcveventhandler.h" #include "utils/dcveventhandlerutil.h" +#include "codeeditor/dccellscriptseditorwindow.h" #include #include #include #include #include -#include +#if defined(Q_WS_WIN) + #include +#else + #include +#endif #include #ifndef GL_MULTISAMPLE @@ -452,13 +455,6 @@ void DCUIGraphicsScene::sceneChanged(const void *requester, DCScene *scene) removeToolWindow(toolWindow); } - if (d_creator->getCellCodeEditor()->getIsOnStage()) - { - removeToolWindow(d_creator->getCellCodeEditor()); - } - - d_creator->getCellCodeEditor()->resetData(); - DCScene::unlockScene(); updateView(false); } @@ -524,8 +520,6 @@ void DCUIGraphicsScene::sceneSelectedCellChanged(const void* requester, const DC case DCScene::DCV_EDITMODE_TERMINAL_FROM_RECEPTOR: break; - case DCScene::DCV_EDITMODE_CELLCODE: - break; } d_requestRedraw = true; @@ -551,7 +545,6 @@ void DCUIGraphicsScene::sceneEditModeChanged(const void *requester, const DCScen case DCScene::DCV_EDITMODE_LAYOUT: closeTerminalFromAxonToolWindow(); closeTerminalFromReceptorToolWindow(); - closeCellCodeEditorToolWindow(); showCellEditorToolWindows(); d_eventHandler = DCVEventHandlerUtil::createLayoutModeHandler(this, d_creator, d_scene); break; @@ -559,7 +552,6 @@ void DCUIGraphicsScene::sceneEditModeChanged(const void *requester, const DCScen case DCScene::DCV_EDITMODE_TERMINAL_FROM_AXON: closeAllCellEditorToolWindows(); closeTerminalFromReceptorToolWindow(); - closeCellCodeEditorToolWindow(); showTerminalFromAxonToolWindow(); d_eventHandler = DCVEventHandlerUtil::createTerminalFromAxonModeHandler(this, d_creator, d_scene, scene->getEditAxon(), scene->getTerminalEditCursor()); break; @@ -567,17 +559,10 @@ void DCUIGraphicsScene::sceneEditModeChanged(const void *requester, const DCScen case DCScene::DCV_EDITMODE_TERMINAL_FROM_RECEPTOR: closeAllCellEditorToolWindows(); closeTerminalFromAxonToolWindow(); - closeCellCodeEditorToolWindow(); showTerminalFromReceptorToolWindow(); d_eventHandler = DCVEventHandlerUtil::createTerminalFromReceptorModeHandler(this, d_creator, d_scene, scene->getEditReceptor(), scene->getTerminalEditCursor()); break; - case DCScene::DCV_EDITMODE_CELLCODE: - closeAllCellEditorToolWindows(); - closeTerminalFromAxonToolWindow(); - closeTerminalFromReceptorToolWindow(); - showCellCodeEditorToolWindow(); - break; } requestRedraw(false); } @@ -597,9 +582,6 @@ void DCUIGraphicsScene::sceneTerminalEditPageBelongingChanged(DCVCPage *page) updateTerminalFromReceptorToolWindow(); break; - case DCScene::DCV_EDITMODE_CELLCODE: - updateCellCodeEditorToolWindow(); - break; } d_requestRedraw = true; @@ -620,8 +602,6 @@ void DCUIGraphicsScene::sceneTerminalEditDropTargetChanged(DCVComponent *dropTar updateTerminalFromReceptorToolWindow(); break; - case DCScene::DCV_EDITMODE_CELLCODE: - updateCellCodeEditorToolWindow(); } d_requestRedraw = true; @@ -655,31 +635,6 @@ void DCUIGraphicsScene::setupCamera() glTranslatef(0, - d_scene->getCenterBrowsModeY(), 0); } -void DCUIGraphicsScene::showEditMenu(DCCell *editCell) -{ - if (editCell == NULL) - return; - - DCEditMenuDialog dialog; - dialog.exec(); - if (dialog.isEditCellCode) - { - d_creator->doCommandStartEditCellCode(this, editCell); - } - else if (dialog.isEditAxonTerminal) - { - d_creator->doCommandStartAddAxonTerminalFromAxon(this, editCell); - } - else if (dialog.isEditReceptor) - { - d_creator->doCommandStartAddAxonTerminalFromReceptor(this, editCell); - } - else if (dialog.isEditCellAttribute) - { - //TODO - } -} - void DCUIGraphicsScene::updateView(bool isAnimationInterval) { DCScene::lockScene(); @@ -1070,7 +1025,7 @@ void DCUIGraphicsScene::menuActionEditCellCode() cell = list.at(i)->getOwnerCell(); } } - d_creator->doCommandStartEditCellCode(this, cell); + DCCellScriptsEditorWindow::startEditing(cell); } void DCUIGraphicsScene::menuActionFinishEditMode() @@ -1119,8 +1074,6 @@ void DCUIGraphicsScene::creatorCommandExecuted() case DCScene::DCV_EDITMODE_TERMINAL_FROM_RECEPTOR: break; - case DCScene::DCV_EDITMODE_CELLCODE: - break; } d_requestRedraw = true; @@ -1274,31 +1227,3 @@ void DCUIGraphicsScene::closeTerminalFromReceptorToolWindow() removeToolWindow(d_terminalFromReceptorToolWindow); } } - -void DCUIGraphicsScene::showCellCodeEditorToolWindow() -{ - updateCellCodeEditorToolWindow(); - removeToolWindow(d_viewControlTool); - addToolWindow(d_creator->getCellCodeEditor()); -} - -void DCUIGraphicsScene::updateCellCodeEditorToolWindow() -{ - if (d_creator->getCellCodeEditor()) - { - DCCell *cell = d_scene->getEditCellCodeCell(); - d_creator->getCellCodeEditor()->setData(d_scene->getContainer(), cell->getCellCode(),cell ); - } -} - -void DCUIGraphicsScene::closeCellCodeEditorToolWindow() -{ - if (d_creator->getCellCodeEditor()->getIsOnStage()) - { - removeToolWindow(d_creator->getCellCodeEditor()); - } - - if (!d_viewControlTool->getIsOnStage()) - addToolWindow(d_viewControlTool); -} - diff --git a/Source/visualizer/dcglvisualizerwidget.h b/Source/visualizer/dcglvisualizerwidget.h index bfaa204..4a7aad9 100644 --- a/Source/visualizer/dcglvisualizerwidget.h +++ b/Source/visualizer/dcglvisualizerwidget.h @@ -35,7 +35,6 @@ class DCToolWindowViewControl; class DCToolWindowCellEditor; class DCToolWindowTerminalFromAxon; class DCToolWindowTerminalFromReceptor; -class DCToolWindowCellCodeEditor; class DCGLVisualizerWidget : public QGraphicsView { @@ -112,10 +111,6 @@ private: void updateTerminalFromReceptorToolWindow(); void closeTerminalFromReceptorToolWindow(); - void showCellCodeEditorToolWindow(); - void updateCellCodeEditorToolWindow(); - void closeCellCodeEditorToolWindow(); - DCCreator *d_creator; DCScene *d_scene; DCVEventHandler *d_eventHandler; @@ -153,7 +148,6 @@ public: void requestRedraw(bool immediate = false); DCVComponent* getObjectAt(int viewX, int viewY, DCVComponent *priorityObject = NULL); bool toObjectCoordinateXZ(float viewX, float viewY, DCVComponent *object, float *pLocalX, float *pLocalZ); - void showEditMenu(DCCell *editCell); void addToolWindow(DCToolWindowBase *window, int x = 10, int y = 10, DCGraphicsProxyWidget::DCSticky sticky = DCGraphicsProxyWidget::DC_STICKYWIDGET_LEFT); void removeToolWindow(DCToolWindowBase *window); diff --git a/Source/visualizer/dcscene.cpp b/Source/visualizer/dcscene.cpp index d249466..b30af5c 100644 --- a/Source/visualizer/dcscene.cpp +++ b/Source/visualizer/dcscene.cpp @@ -418,7 +418,7 @@ void DCScene::updateVisiblity() //selected pages : x <= s //non-selected pages: x <= n - if (d_veMode == DCV_EDITMODE_LAYOUT || d_veMode == DCV_EDITMODE_CELLCODE) + if (d_veMode == DCV_EDITMODE_LAYOUT) { switch(d_vpMode) { @@ -811,17 +811,6 @@ bool DCScene::startTerminalEditForReceptor(const void *requester, DCReceptor *ow return true; } -bool DCScene::startCellCodeEdit(const void *requester, DCCell *cell) -{ - d_veMode = DCV_EDITMODE_CELLCODE; - - d_editCellCodeCell = cell; - updateVisiblity(); - emit viewEditModeChanged(requester); - - return true; -} - bool DCScene::finishTerminalEdit(const void *requester) { d_veMode = DCV_EDITMODE_LAYOUT; @@ -832,17 +821,6 @@ bool DCScene::finishTerminalEdit(const void *requester) return true; } -bool DCScene::finishCellCodeEdit(const void *requester) -{ - d_veMode = DCV_EDITMODE_LAYOUT; - - updateVisiblity(); - emit viewEditModeChanged(requester); - - return true; -} - - void DCScene::setNavModeSelectedPageAlpha(const void *requester, float alpha) { d_navigationModeSelectedPageAlpha = alpha; diff --git a/Source/visualizer/dcscene.h b/Source/visualizer/dcscene.h index 3395d93..e047539 100644 --- a/Source/visualizer/dcscene.h +++ b/Source/visualizer/dcscene.h @@ -41,7 +41,7 @@ class DCScene : public QObject public: enum DCVPersMode { DCV_PERSMODE_NAVIGATION, DCV_PERSMODE_PAGEEDIT }; - enum DCVEditMode { DCV_EDITMODE_LAYOUT, DCV_EDITMODE_TERMINAL_FROM_AXON, DCV_EDITMODE_TERMINAL_FROM_RECEPTOR, DCV_EDITMODE_CELLCODE }; + enum DCVEditMode { DCV_EDITMODE_LAYOUT, DCV_EDITMODE_TERMINAL_FROM_AXON, DCV_EDITMODE_TERMINAL_FROM_RECEPTOR}; private: DCContainer *d_owner; @@ -184,9 +184,7 @@ public: bool changePersMode(const void *requester, DCVPersMode mode); bool startTerminalEditForAxon(const void *requester, DCAxon *ownerAxon); bool startTerminalEditForReceptor(const void *requester, DCReceptor *ownerReceptor); - bool startCellCodeEdit(const void *requester, DCCell *cell); bool finishTerminalEdit(const void *requester); - bool finishCellCodeEdit(const void *requester); bool loadSceneAll(); bool loadSceneForPage(DCVCPage *page); diff --git a/Source/visualizer/eventhandler/dcvlayoutmodehandler.cpp b/Source/visualizer/eventhandler/dcvlayoutmodehandler.cpp index b97c09e..3385c08 100644 --- a/Source/visualizer/eventhandler/dcvlayoutmodehandler.cpp +++ b/Source/visualizer/eventhandler/dcvlayoutmodehandler.cpp @@ -32,6 +32,7 @@ #include "dialog/dcaddcelldialog.h" #include "dialog/dcinputnewpagenamedialog.h" #include "dialog/dcrenamecelldialog.h" +#include "codeeditor/dccellscriptseditorwindow.h" #include #include @@ -153,7 +154,7 @@ void DCVLayoutModeHandler::mouseDoubleClickEvent(QGraphicsSceneMouseEvent *event } else { - getView()->showEditMenu(d_draggedObject.ref()->getOwnerCell()); + DCCellScriptsEditorWindow::startEditing(d_draggedObject.ref()->getOwnerCell()); } } } @@ -338,7 +339,7 @@ void DCVLayoutModeHandler::keyPressEvent(QKeyEvent *event) case DCScene::DCV_PERSMODE_PAGEEDIT: if (getScene()->getSelectedCellObjects().length() == 1) { - getView()->showEditMenu(getScene()->getSelectedCellObjects().at(0)->getOwnerCell()); + DCCellScriptsEditorWindow::startEditing(getScene()->getSelectedCellObjects().at(0)->getOwnerCell()); } break; @@ -496,12 +497,9 @@ void DCVLayoutModeHandler::showContextMenu(const QPoint &pos) { bool r = true; QList pages = getScene()->getSelectedPages(); - for (int i = 0; i < pages.length(); i++) + if (!getController()->savePage(pages.toSet())) { - if (!getController()->savePage(pages.at(i))) - { - r = false; - } + r = false; } QMessageBox msgBox; if (r) @@ -524,7 +522,7 @@ void DCVLayoutModeHandler::showContextMenu(const QPoint &pos) { if (selectedCell) { - getController()->doCommandStartEditCellCode(this, selectedCell); + DCCellScriptsEditorWindow::startEditing(selectedCell); } } else if (selectedItem == actionAddCell) diff --git a/Source/visualizer/toolwindow/dctoolwindowcellcodeeditor.cpp b/Source/visualizer/toolwindow/dctoolwindowcellcodeeditor.cpp deleted file mode 100644 index e2a3799..0000000 --- a/Source/visualizer/toolwindow/dctoolwindowcellcodeeditor.cpp +++ /dev/null @@ -1,447 +0,0 @@ -// 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 . - -// -// Created by tkawata on Sep-30, 2012. -// -#include "dctoolwindowcellcodeeditor.h" - -#include "dccodeeditor.h" -#include "dccontainer.h" -#include "dccell.h" -#include "dcaxon.h" -#include "dcaxonterminal.h" -#include "dcreceptor.h" -#include "dccellcode.h" -#include "dccreator.h" -#include "dceditablelabel.h" -#include "dceditabletreeview.h" -#include "dccellcodetypecombobox.h" -#include "dccelltypecombobox.h" -#include "utils/dcqtitemmodel.h" -#include "dialog/dcassigncellcodeclassdialog.h" - -#include -#include -#include -#include - - -DCToolWindowCellCodeEditor::DCToolWindowCellCodeEditor(DCCreator *creator) : - DCToolWindowBase("CELL CODE:", creator), d_mode(CELLCLASS_EDIT_MODE), d_container(NULL), d_cellCodeClass(NULL), d_ownerCell(NULL) -{ - setWindowOpacity(0.95); - d_editor = new DCCodeEditor; - - QHBoxLayout *layout = new QHBoxLayout; - layout->addWidget(d_editor); - - QVBoxLayout *toolLayout = new QVBoxLayout; - d_uiClassGroupBox = new QGroupBox(tr("Class")); - - QGridLayout *cellclassGroupBoxLayoutInnder1 = new QGridLayout; - - cellclassGroupBoxLayoutInnder1->addWidget(new QLabel(tr("name")), 0,0); - cellclassGroupBoxLayoutInnder1->addWidget(new QLabel(tr("type")), 1,0); - - d_uiClassName = new DCEditableLabel(this, ""); - d_uiClassType = new DCCellCodeTypeComboBox(creator, this); - d_uiClassUnsetButton = new QPushButton(tr("Unset class")); - cellclassGroupBoxLayoutInnder1->addWidget(d_uiClassName, 0,1); - cellclassGroupBoxLayoutInnder1->addWidget(d_uiClassType, 1,1); - cellclassGroupBoxLayoutInnder1->addWidget(d_uiClassUnsetButton, 2,0,1,2); - - QVBoxLayout *cellclassGroupBoxLayoutInnder2 = new QVBoxLayout; - d_uiClassAssignButton = new QPushButton(tr("Assign a class")); - cellclassGroupBoxLayoutInnder2->addWidget(new QLabel(tr("No Cell Code class is assinged."))); - cellclassGroupBoxLayoutInnder2->addWidget(d_uiClassAssignButton); - - QWidget *uiCellCode1 = new QWidget(d_uiClassGroupBox); - QWidget *uiCellCode2 = new QWidget(d_uiClassGroupBox); - uiCellCode1->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Minimum); - uiCellCode2->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Minimum); - uiCellCode1->setLayout(cellclassGroupBoxLayoutInnder1); - uiCellCode2->setLayout(cellclassGroupBoxLayoutInnder2); - QVBoxLayout *cellclassGroupBoxLayoutOuter = new QVBoxLayout; - cellclassGroupBoxLayoutOuter->addWidget(uiCellCode1); - cellclassGroupBoxLayoutOuter->addWidget(uiCellCode2); - - d_uiClassGroupBox->setLayout(cellclassGroupBoxLayoutOuter); - d_uiClassGroupBox->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Minimum); - toolLayout->addWidget(d_uiClassGroupBox); - - d_uiCellGroupBox = new QGroupBox(tr("Cell")); - QGridLayout *cellGroupBoxLayout = new QGridLayout; - cellGroupBoxLayout->addWidget(new QLabel(tr("name")), 0,0); - cellGroupBoxLayout->addWidget(new QLabel(tr("path")), 1,0); - cellGroupBoxLayout->addWidget(new QLabel(tr("type")), 2,0); - - d_uiCellName = new DCEditableLabel(this, ""); - d_uiCellPath = new DCEditableLabel(this, ""); - d_uiCellType = new DCCellTypeComboBox(creator, this); - d_uiSwitchEditorButton = new QPushButton(tr("Open custom script")); - cellGroupBoxLayout->addWidget(d_uiCellName, 0,1); - cellGroupBoxLayout->addWidget(d_uiCellPath, 1,1); - cellGroupBoxLayout->addWidget(d_uiCellType, 2,1); - - d_receptors = new DCEditableTreeView(this); - d_receptors->setHeaderHidden(true); - d_receptors->setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOff); - - d_axonTerminals = new DCEditableTreeView(this); - d_axonTerminals->setHeaderHidden(true); - d_axonTerminals->setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOff); - - - d_receptorItemModel = new DCQtItemModel(QStringList("name")); - d_axonTerminalItemModel = new DCQtItemModel(QStringList("name")); - - d_receptors->setModel(d_receptorItemModel); - d_axonTerminals->setModel(d_axonTerminalItemModel); - - cellGroupBoxLayout->addWidget(d_receptors, 3,0,1,2); - cellGroupBoxLayout->addWidget(d_axonTerminals, 4, 0, 1, 2); - cellGroupBoxLayout->addWidget(d_uiSwitchEditorButton, 5, 0,1,2); - - d_uiCellGroupBox->setLayout(cellGroupBoxLayout); - - toolLayout->addWidget(d_uiCellGroupBox); - - toolLayout->addItem(new QSpacerItem(10,10, QSizePolicy::Minimum, QSizePolicy::Expanding)); - - layout->addLayout(toolLayout); - - d_uiCloseButton = new QPushButton("Close"); - - QHBoxLayout *buttonLayout = new QHBoxLayout; - buttonLayout->addItem(new QSpacerItem(10,10, QSizePolicy::Expanding)); - buttonLayout->addWidget(d_uiCloseButton); - - contentLayout()->addLayout(layout); - contentLayout()->addLayout(buttonLayout); - - connect(d_uiCloseButton, SIGNAL(clicked()), this, SLOT(finishEditing())); - connect(d_uiSwitchEditorButton, SIGNAL(clicked()), this, SLOT(switchEditor())); - connect(d_uiClassUnsetButton, SIGNAL(clicked()), this, SLOT(unsetCellCodeButtonClicked())); - connect(d_uiClassAssignButton, SIGNAL(clicked()), this, SLOT(assignCellCodeButtonClicked())); - connect(getController(), SIGNAL(commandExecuted(const QUndoCommand*)), this, SLOT(commandExecuted(const QUndoCommand*))); -} - -DCToolWindowCellCodeEditor::~DCToolWindowCellCodeEditor() -{ - d_receptors->disconnect(this); - d_axonTerminals->disconnect(this); - getController()->disconnect(this); - - if (d_receptorItemModel) - d_receptorItemModel->deleteLater(); - - if (d_axonTerminalItemModel) - d_axonTerminalItemModel->deleteLater(); -} - -void DCToolWindowCellCodeEditor::setData(DCContainer *container, DCCellCode *cellCodeClass, DCCell *ownerCell) -{ - if (d_ownerCell && d_ownerCell != ownerCell) - { - d_ownerCell->disconnect(this); - } - if (ownerCell) - connect(ownerCell, SIGNAL(cellCodeChanged()), this, SLOT(classForCellChanged())); - - d_container = container; - d_cellCodeClass = cellCodeClass; - d_ownerCell = ownerCell; - - d_uiClassType->setEditingCellCode(cellCodeClass); - d_uiCellType->setEditingCell(ownerCell); - updateInformation(); - - showClassScript(); -} - -void DCToolWindowCellCodeEditor::setData(DCContainer *container, DCCell *ownerCell) -{ - if (d_ownerCell && d_ownerCell != ownerCell) - { - d_ownerCell->disconnect(this); - } - if (ownerCell) - connect(ownerCell, SIGNAL(cellCodeChanged()), this, SLOT(classForCellChanged())); - - d_container = container; - d_ownerCell = ownerCell; - - if (ownerCell) - { - d_cellCodeClass = ownerCell->getCellCode(); - } - - d_uiClassType->setEditingCellCode(d_cellCodeClass); - d_uiCellType->setEditingCell(d_ownerCell); - updateInformation(); - - showCustomScript(); -} - -void DCToolWindowCellCodeEditor::resetData() -{ - d_mode = CELLCLASS_EDIT_MODE; - d_container = NULL; - d_cellCodeClass = NULL; - d_ownerCell = NULL; -} - -void DCToolWindowCellCodeEditor::showClassScript() -{ - d_mode = CELLCLASS_EDIT_MODE; - d_uiClassGroupBox->setVisible(true); - d_uiSwitchEditorButton->setText(tr("Switch to Custom Script")); - if (d_ownerCell->getIsCellCodeClassAssgined() && d_container) - { - d_editor->setPlainText(d_cellCodeClass->getOwnScript()); - d_editor->setReadOnly(false); - } - else - { - d_editor->setPlainText(""); - d_editor->setReadOnly(true); - } -} - -void DCToolWindowCellCodeEditor::showCustomScript() -{ - d_mode = CUSTOMSCRIPT_EDIT_MODE; - d_uiClassGroupBox->setVisible(false); - d_uiSwitchEditorButton->setText(tr("Switch to Cell Code")); - if (d_ownerCell) - { - d_editor->setPlainText(d_ownerCell->getCustomScript()); - d_editor->setReadOnly(false); - } - else - { - d_editor->setPlainText(""); - d_editor->setReadOnly(true); - } -} - -void DCToolWindowCellCodeEditor::updateInformation() -{ - d_receptorItemModel->removeAllItems(); - d_axonTerminalItemModel->removeAllItems(); - - //update cell information - if (d_ownerCell) - { - d_uiCellName->setText(QString::fromStdString(d_ownerCell->getName())); - d_uiCellPath->setText(QString::fromStdString(d_ownerCell->getLocation())); - d_uiCellType->updateSelection(); - d_uiCellType->setEnabled(!d_ownerCell->getIsCellCodeClassAssgined()); - - d_receptorItemModel->insertString("receptors"); - d_receptorItemModel->setReadOnly(0,true); - - d_axonTerminalItemModel->insertString("axonTerminals"); - d_axonTerminalItemModel->setReadOnly(0,true); - - const TKReceptorMap *receptors = d_ownerCell->getReceptors(); - TKReceptorMap::const_iterator it = receptors->begin(); - QModelIndex rroot = d_receptorItemModel->index(0,0); - int i = 0; - while( it != receptors->end()) - { - QString receptorName = QString::fromStdString((*it).first); - d_receptorItemModel->insertString(receptorName,rroot); - ++it; - ++i; - } - - QModelIndex aroot = d_axonTerminalItemModel->index(0,0); - DCAxon *axon = d_ownerCell->getAxon(); - int acnt = axon->getNumberOfTerminals(); - for (int i = 0; i < acnt; i++) - { - DCReceptor *targetReceptor = NULL; - DCCell *targetCell = NULL; - DCAxonTerminal *tarminal = axon->getTerminalAt(i); - if (tarminal) - { - targetReceptor = tarminal->getTarget(); - if (targetReceptor) - { - targetCell = targetReceptor->getOwnerCell(); - } - } - QString axonTerminalName; - - if (targetCell) - { - QTextStream(&axonTerminalName) - << QString::fromStdString(targetCell->getLocation()) - << "/" - << QString::fromStdString(targetCell->getName()) - << "#" - << QString::fromStdString(targetCell->getReceptorName(targetReceptor)); - } - else - { - axonTerminalName = "-"; - } - - d_axonTerminalItemModel->insertString(axonTerminalName,aroot); - } - d_receptors->expandAll(); - d_axonTerminals->expandAll(); - } - else - { - d_uiCellName->setText(""); - d_uiCellPath->setText(""); - d_uiCellType->updateSelection(); - } - - //update cell code information - if (d_cellCodeClass) - { - d_uiClassName->setText(QString::fromStdString(d_cellCodeClass->getFQNName())); - d_uiClassType->updateSelection(); - } - else - { - d_uiClassName->setText(""); - d_uiClassType->updateSelection(); - } - - - // update title and tool visibility - QString titleString = ""; - if (d_ownerCell) - { - titleString.append("CELL : "); - titleString.append(QString::fromStdString(d_ownerCell->getName())); - titleString.append(" "); - - d_uiCellGroupBox->setVisible(true); - if (d_container->isScriptableCell(d_ownerCell)) - { - if (d_ownerCell->getIsCellCodeClassAssgined()) - { - titleString.append("CELL CODE : "); - titleString.append(QString::fromStdString(d_cellCodeClass->getFQNName())); - titleString.append(" ("); - titleString.append(QString::fromStdString(d_cellCodeClass->getCellAPIName())); - titleString.append(")"); - d_uiClassGroupBox->setVisible(true); - d_uiClassGroupBox->layout()->itemAt(0)->widget()->setVisible(true); - d_uiClassGroupBox->layout()->itemAt(1)->widget()->setVisible(false); - d_uiClassGroupBox->adjustSize(); - } - else - { - d_uiClassGroupBox->setVisible(true); - d_uiClassGroupBox->layout()->itemAt(0)->widget()->setVisible(false); - d_uiClassGroupBox->layout()->itemAt(1)->widget()->setVisible(true); - d_uiClassGroupBox->adjustSize(); - } - } - else - { - d_uiClassGroupBox->setVisible(false); - d_uiClassGroupBox->layout()->itemAt(0)->widget()->setVisible(false); - d_uiClassGroupBox->layout()->itemAt(1)->widget()->setVisible(false); - } - } - else - { - titleString.append("CELL CODE : "); - titleString.append(QString::fromStdString(d_cellCodeClass->getFQNName())); - titleString.append(" ("); - titleString.append(QString::fromStdString(d_cellCodeClass->getCellAPIName())); - titleString.append(")"); - d_uiCellGroupBox->setVisible(false); - d_uiClassGroupBox->setVisible(true); - d_uiClassGroupBox->layout()->itemAt(0)->widget()->setVisible(true); - d_uiClassGroupBox->layout()->itemAt(1)->widget()->setVisible(false); - d_uiClassGroupBox->adjustSize(); - } - setButtonedWindowTitle(titleString); - -} - - -void DCToolWindowCellCodeEditor::switchEditor() -{ - saveScriptToFile(); - if (d_mode == CELLCLASS_EDIT_MODE) - { - showCustomScript(); - } - else - { - showClassScript(); - } -} - -void DCToolWindowCellCodeEditor::saveScriptToFile() -{ - switch(d_mode) - { - case CELLCLASS_EDIT_MODE: - if (d_cellCodeClass) - d_cellCodeClass->saveScript(d_editor->toPlainText()); - break; - - case CUSTOMSCRIPT_EDIT_MODE: - if (d_ownerCell) - d_ownerCell->saveCustomScript(d_editor->toPlainText()); - break; - - } - -} - -void DCToolWindowCellCodeEditor::finishEditing() -{ - saveScriptToFile(); - getController()->doCommandFinishEditCellCode(this); -} - -void DCToolWindowCellCodeEditor::unsetCellCodeButtonClicked() -{ - getController()->doCommandUnassignCellCodeClassFromCell(this, d_ownerCell); -} - -void DCToolWindowCellCodeEditor::assignCellCodeButtonClicked() -{ - DCAssignCellCodeClassDialog dialog(d_container, getController()); - dialog.exec(); - DCCellCode *cellCode = dialog.getSelectedCellCodeClass(); - if (cellCode) - { - getController()->doCommandAssignCellCodeClassToCell(this, d_ownerCell, cellCode); - } -} - -void DCToolWindowCellCodeEditor::classForCellChanged() -{ - setData(d_container, d_ownerCell->getCellCode(), d_ownerCell); -} - -void DCToolWindowCellCodeEditor::commandExecuted(const QUndoCommand *executedCommand) -{ - if (getIsOnStage()) - updateInformation(); -} diff --git a/Source/visualizer/toolwindow/dctoolwindowcellcodeeditor.h b/Source/visualizer/toolwindow/dctoolwindowcellcodeeditor.h deleted file mode 100644 index 556a99d..0000000 --- a/Source/visualizer/toolwindow/dctoolwindowcellcodeeditor.h +++ /dev/null @@ -1,94 +0,0 @@ -// 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 . - -// -// Created by tkawata on Sep-30, 2012. -// -#ifndef DCTOOLWINDOWCELLCODEEDITOR_H -#define DCTOOLWINDOWCELLCODEEDITOR_H - -#include "dctoolwindowbase.h" - -class DCCodeEditor; -class DCCell; -class DCCellCode; -class DCContainer; - -class DCEditableLabel; -class DCEditableTreeView; -class DCQtItemModel; -class DCCellCodeTypeComboBox; -class DCCellTypeComboBox; - -class DCToolWindowCellCodeEditor : public DCToolWindowBase -{ - Q_OBJECT -private: - enum DCScriptEditMode { CELLCLASS_EDIT_MODE, CUSTOMSCRIPT_EDIT_MODE }; - - DCScriptEditMode d_mode; - DCContainer *d_container; - DCCodeEditor *d_editor; - DCCellCode *d_cellCodeClass; - DCCell *d_ownerCell; - - QGroupBox *d_uiClassGroupBox; - DCEditableLabel *d_uiClassName; - DCCellCodeTypeComboBox *d_uiClassType; - QPushButton *d_uiClassUnsetButton; - QPushButton *d_uiClassAssignButton; - - QGroupBox *d_uiCellGroupBox; - DCEditableLabel *d_uiCellName; - DCEditableLabel *d_uiCellPath; - DCCellTypeComboBox *d_uiCellType; - DCEditableTreeView *d_receptors; - DCQtItemModel *d_receptorItemModel; - DCEditableTreeView *d_axonTerminals; - DCQtItemModel *d_axonTerminalItemModel; - QPushButton *d_uiSwitchEditorButton; - - QPushButton *d_uiCloseButton; - - void updateInformation(); - void showClassScript(); - void showCustomScript(); - -public: - DCToolWindowCellCodeEditor(DCCreator *creator); - virtual ~DCToolWindowCellCodeEditor(); - - virtual int getPosPriority() const { return 1; } - - void setData(DCContainer *container, DCCellCode *cellCodeClass, DCCell *ownerCell = NULL); - void setData(DCContainer *container, DCCell *ownerCell); - void resetData(); - -signals: - -public slots: - void finishEditing(); - void saveScriptToFile(); - void switchEditor(); - -private slots: - void unsetCellCodeButtonClicked(); - void assignCellCodeButtonClicked(); - void classForCellChanged(); - void commandExecuted(const QUndoCommand *executedCommand); - -}; - -#endif // DCTOOLWINDOWCELLCODEEDITOR_H diff --git a/Source/visualizer/toolwindow/dctoolwindowcelleditor.cpp b/Source/visualizer/toolwindow/dctoolwindowcelleditor.cpp index e095a96..bebd98f 100644 --- a/Source/visualizer/toolwindow/dctoolwindowcelleditor.cpp +++ b/Source/visualizer/toolwindow/dctoolwindowcelleditor.cpp @@ -31,6 +31,7 @@ #include "utils/dcresources.h" #include "utils/dcqtitemmodel.h" #include "utils/dcutil.h" +#include "codeeditor/dccellscriptseditorwindow.h" #include #include @@ -350,7 +351,7 @@ void DCToolWindowCellEditor::updateView() { if (container->getIsScriptable(d_cell->getType())) { - if (d_cell->getIsCellCodeClassAssgined()) + if (d_cell->getIsCellCodeAssgined()) { d_classButton->setText(QString::fromStdString(d_cell->getCellCode()->getFQNName())); } @@ -372,7 +373,7 @@ void DCToolWindowCellEditor::updateView() } d_comboType->updateSelection(); - d_comboType->setEnabled(!d_cell->getIsCellCodeClassAssgined()); + d_comboType->setEnabled(!d_cell->getIsCellCodeAssgined()); d_textPage->setText(QString::fromStdString(d_cell->getLocation())); @@ -563,7 +564,8 @@ void DCToolWindowCellEditor::slotCellCodeEditButtonPressed() { if (d_cell) { - getController()->doCommandStartEditCellCode(this, d_cell); + //TODO + DCCellScriptsEditorWindow::startEditing(d_cell); } } @@ -571,7 +573,7 @@ void DCToolWindowCellEditor::slotCustomScriptEditButtonPressed() { if (d_cell) { - getController()->doCommandStartEditCellCode(this, d_cell); + DCCellScriptsEditorWindow::startEditing(d_cell); } } -- 2.11.0