diff --git a/OMEdit/OMEditLIB/Modeling/LibraryTreeWidget.cpp b/OMEdit/OMEditLIB/Modeling/LibraryTreeWidget.cpp index c7be6cc9d12..90906985d9e 100644 --- a/OMEdit/OMEditLIB/Modeling/LibraryTreeWidget.cpp +++ b/OMEdit/OMEditLIB/Modeling/LibraryTreeWidget.cpp @@ -4690,14 +4690,13 @@ void LibraryWidget::saveAsLibraryTreeItem(LibraryTreeItem *pLibraryTreeItem) * \param pLibraryTreeItem * \return */ -bool LibraryWidget::saveTotalLibraryTreeItem(LibraryTreeItem *pLibraryTreeItem) +void LibraryWidget::saveTotalLibraryTreeItem(LibraryTreeItem *pLibraryTreeItem) { MainWindow::instance()->getStatusBar()->showMessage(tr("Saving %1").arg(pLibraryTreeItem->getNameStructure())); MainWindow::instance()->showProgressBar(); - bool result = saveTotalLibraryTreeItemHelper(pLibraryTreeItem); + saveTotalLibraryTreeItemHelper(pLibraryTreeItem); MainWindow::instance()->getStatusBar()->clearMessage(); MainWindow::instance()->hideProgressBar(); - return result; } /*! @@ -5211,24 +5210,13 @@ bool LibraryWidget::saveCompositeModelLibraryTreeItem(LibraryTreeItem *pLibraryT * \param pLibraryTreeItem * \return */ -bool LibraryWidget::saveTotalLibraryTreeItemHelper(LibraryTreeItem *pLibraryTreeItem) +void LibraryWidget::saveTotalLibraryTreeItemHelper(LibraryTreeItem *pLibraryTreeItem) { - bool result = false; /* if user has done some changes in the Modelica text view then save & validate it in the AST before saving it to file. */ - if (pLibraryTreeItem->getModelWidget() && !pLibraryTreeItem->getModelWidget()->validateText(&pLibraryTreeItem)) { - return false; + if (pLibraryTreeItem->getModelWidget() && pLibraryTreeItem->getModelWidget()->validateText(&pLibraryTreeItem)) { + SaveTotalFileDialog *pSaveTotalFileDialog = new SaveTotalFileDialog(pLibraryTreeItem); + pSaveTotalFileDialog->exec(); } - QString fileName; - QString name = QString("%1Total").arg(pLibraryTreeItem->getName()); - fileName = StringHandler::getSaveFileName(this, tr("%1 - Save %2 %3 as Total File").arg(Helper::applicationName) - .arg(pLibraryTreeItem->mClassInformation.restriction).arg(pLibraryTreeItem->getName()), NULL, - Helper::omFileTypes, NULL, "mo", &name); - if (fileName.isEmpty()) { // if user press ESC - return false; - } - // save the model through OMC - result = MainWindow::instance()->getOMCProxy()->saveTotalModel(fileName, pLibraryTreeItem->getNameStructure()); - return result; } /*! diff --git a/OMEdit/OMEditLIB/Modeling/LibraryTreeWidget.h b/OMEdit/OMEditLIB/Modeling/LibraryTreeWidget.h index f2ab8b394b3..a59153dbd9f 100644 --- a/OMEdit/OMEditLIB/Modeling/LibraryTreeWidget.h +++ b/OMEdit/OMEditLIB/Modeling/LibraryTreeWidget.h @@ -491,7 +491,7 @@ class LibraryWidget : public QWidget bool saveFile(QString fileName, QString contents); bool saveLibraryTreeItem(LibraryTreeItem *pLibraryTreeItem); void saveAsLibraryTreeItem(LibraryTreeItem *pLibraryTreeItem); - bool saveTotalLibraryTreeItem(LibraryTreeItem *pLibraryTreeItem); + void saveTotalLibraryTreeItem(LibraryTreeItem *pLibraryTreeItem); void openLibraryTreeItem(QString nameStructure); private: TreeSearchFilters *mpTreeSearchFilters; @@ -512,7 +512,7 @@ class LibraryWidget : public QWidget bool saveAsCompositeModelLibraryTreeItem(LibraryTreeItem *pLibraryTreeItem); bool saveAsOMSLibraryTreeItem(LibraryTreeItem *pLibraryTreeItem); bool saveCompositeModelLibraryTreeItem(LibraryTreeItem *pLibraryTreeItem, QString fileName); - bool saveTotalLibraryTreeItemHelper(LibraryTreeItem *pLibraryTreeItem); + void saveTotalLibraryTreeItemHelper(LibraryTreeItem *pLibraryTreeItem); public slots: void scrollToActiveLibraryTreeItem(); void searchClasses(); diff --git a/OMEdit/OMEditLIB/Modeling/ModelicaClassDialog.cpp b/OMEdit/OMEditLIB/Modeling/ModelicaClassDialog.cpp index 70bdaf6b9ed..642e1969db5 100644 --- a/OMEdit/OMEditLIB/Modeling/ModelicaClassDialog.cpp +++ b/OMEdit/OMEditLIB/Modeling/ModelicaClassDialog.cpp @@ -1253,6 +1253,64 @@ void RenameClassDialog::renameClass() } } +/*! + * \class SaveTotalFileDialog + * \brief Creates a dialog that shows the options for saveTotalModel. + */ +/*! + * \brief SaveTotalFileDialog::SaveTotalFileDialog + * \param pLibraryTreeItem + * \param pParent + */ +SaveTotalFileDialog::SaveTotalFileDialog(LibraryTreeItem *pLibraryTreeItem, QWidget *pParent) + : QDialog(pParent) +{ + mpLibraryTreeItem = pLibraryTreeItem; + setAttribute(Qt::WA_DeleteOnClose); + setWindowTitle(QString("%1 - Save %2 %3 as Total File").arg(Helper::applicationName, mpLibraryTreeItem->mClassInformation.restriction, mpLibraryTreeItem->getName())); + setMinimumWidth(400); + // checkboxes + mpObfuscateOutputCheckBox = new QCheckBox(tr("Obfuscate output")); + mpStripAnnotationsCheckBox = new QCheckBox(tr("Strip annotations")); + mpStripCommentsCheckBox = new QCheckBox(tr("Strip comments")); + // buttons + mpOkButton = new QPushButton(Helper::ok); + mpOkButton->setAutoDefault(true); + connect(mpOkButton, SIGNAL(clicked()), this, SLOT(saveTotalModel())); + mpCancelButton = new QPushButton(Helper::cancel); + mpCancelButton->setAutoDefault(false); + connect(mpCancelButton, SIGNAL(clicked()), this, SLOT(reject())); + mpButtonBox = new QDialogButtonBox(Qt::Horizontal); + mpButtonBox->addButton(mpOkButton, QDialogButtonBox::ActionRole); + mpButtonBox->addButton(mpCancelButton, QDialogButtonBox::ActionRole); + QGridLayout *pMainGridLayout = new QGridLayout; + pMainGridLayout->addWidget(mpObfuscateOutputCheckBox, 0, 0); + pMainGridLayout->addWidget(mpStripAnnotationsCheckBox, 1, 0); + pMainGridLayout->addWidget(mpStripCommentsCheckBox, 2, 0); + pMainGridLayout->addWidget(mpButtonBox, 3, 0, 1, 1, Qt::AlignRight); + setLayout(pMainGridLayout); +} + +/*! + * \brief SaveTotalFileDialog::saveTotalModel + * Saves the model as total file. + */ +void SaveTotalFileDialog::saveTotalModel() +{ + QString fileName; + QString name = QString("%1Total").arg(mpLibraryTreeItem->getName()); + fileName = StringHandler::getSaveFileName(this, tr("%1 - Save %2 %3 as Total File").arg(Helper::applicationName, mpLibraryTreeItem->mClassInformation.restriction, + mpLibraryTreeItem->getName()), NULL, Helper::omFileTypes, NULL, "mo", &name); + if (fileName.isEmpty()) { // if user press ESC + reject(); + } else { + // save the model through OMC + MainWindow::instance()->getOMCProxy()->saveTotalModel(fileName, mpLibraryTreeItem->getNameStructure(), mpStripAnnotationsCheckBox->isChecked(), + mpStripCommentsCheckBox->isChecked(), mpObfuscateOutputCheckBox->isChecked()); + accept(); + } +} + /*! * \class InformationDialog * \brief Creates a dialog that shows the users the result of OMCProxy::instantiateModel and OMCProxy::checkModel. diff --git a/OMEdit/OMEditLIB/Modeling/ModelicaClassDialog.h b/OMEdit/OMEditLIB/Modeling/ModelicaClassDialog.h index 7d9501c6a86..492a1c7df77 100644 --- a/OMEdit/OMEditLIB/Modeling/ModelicaClassDialog.h +++ b/OMEdit/OMEditLIB/Modeling/ModelicaClassDialog.h @@ -206,6 +206,23 @@ public slots: void renameClass(); }; +class SaveTotalFileDialog : public QDialog +{ + Q_OBJECT +public: + SaveTotalFileDialog(LibraryTreeItem *pLibraryTreeItem, QWidget *pParent = 0); +private: + LibraryTreeItem *mpLibraryTreeItem; + QCheckBox *mpObfuscateOutputCheckBox; + QCheckBox *mpStripAnnotationsCheckBox; + QCheckBox *mpStripCommentsCheckBox; + QPushButton *mpOkButton; + QPushButton *mpCancelButton; + QDialogButtonBox *mpButtonBox; +private slots: + void saveTotalModel(); +}; + class InformationDialog : public QWidget { public: diff --git a/OMEdit/OMEditLIB/OMC/OMCProxy.cpp b/OMEdit/OMEditLIB/OMC/OMCProxy.cpp index b87879d1161..9b05fe0257e 100644 --- a/OMEdit/OMEditLIB/OMC/OMCProxy.cpp +++ b/OMEdit/OMEditLIB/OMC/OMCProxy.cpp @@ -1838,14 +1838,15 @@ bool OMCProxy::saveModifiedModel(QString modelText) * Save class with all used classes to a file. * \param fileName - the file to save in. * \param className - the name of the class. + * \param stripAnnotations + * \param stripComments + * \param obfuscate * \return true on success. */ -bool OMCProxy::saveTotalModel(QString fileName, QString className) +bool OMCProxy::saveTotalModel(QString fileName, QString className, bool stripAnnotations, bool stripComments, bool obfuscate) { - bool result = mpOMCInterface->saveTotalModel(fileName, className, false, false, false); - if (!result) { - printMessagesStringInternal(); - } + bool result = mpOMCInterface->saveTotalModel(fileName, className, stripAnnotations, stripComments, obfuscate); + printMessagesStringInternal(); return result; } diff --git a/OMEdit/OMEditLIB/OMC/OMCProxy.h b/OMEdit/OMEditLIB/OMC/OMCProxy.h index 79faca57c67..f1ceacb330d 100644 --- a/OMEdit/OMEditLIB/OMC/OMCProxy.h +++ b/OMEdit/OMEditLIB/OMC/OMCProxy.h @@ -171,7 +171,7 @@ class OMCProxy : public QObject bool setSourceFile(QString className, QString path); bool save(QString className); bool saveModifiedModel(QString modelText); - bool saveTotalModel(QString fileName, QString className); + bool saveTotalModel(QString fileName, QString className, bool stripAnnotations, bool stripComments, bool obfuscate); QString list(QString className); QString listFile(QString className, bool nestedClasses = true); QString diffModelicaFileListings(const QString &before, const QString &after);