Skip to content

Commit

Permalink
Fix #3380: Properly save the replaceable nested classes.
Browse files Browse the repository at this point in the history
  • Loading branch information
adeas31 committed Aug 5, 2015
1 parent 8a1191e commit c183a88
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 1 deletion.
11 changes: 10 additions & 1 deletion OMEdit/OMEditGUI/Modeling/LibraryTreeWidget.cpp
Expand Up @@ -1498,7 +1498,16 @@ bool LibraryTreeWidget::saveSubModelsFolderHelper(LibraryTreeNode *pLibraryTreeN
directory = directoryName;
mpMainWindow->getStatusBar()->showMessage(QString(tr("Saving")).append(" ").append(pChildLibraryTreeNode->getNameStructure()));
QString fileName = QString(directory).append("/").append(pChildLibraryTreeNode->getName()).append(".mo");
mpMainWindow->getOMCProxy()->setSourceFile(pChildLibraryTreeNode->getNameStructure(), fileName);
/* Ticket #3380
* Only create new file for nested classes if they are nested inside a package.
* If the nested class is replaceable then save it in the parent class.
*/
if ((pLibraryTreeNode->getClassInformation().restriction.toLower().compare("package") != 0) ||
mpMainWindow->getOMCProxy()->isReplaceable(pChildLibraryTreeNode->getParentName(), pChildLibraryTreeNode->getName())) {
mpMainWindow->getOMCProxy()->setSourceFile(pChildLibraryTreeNode->getNameStructure(), pLibraryTreeNode->getFileName());
} else {
mpMainWindow->getOMCProxy()->setSourceFile(pChildLibraryTreeNode->getNameStructure(), fileName);
}
if (mpMainWindow->getOMCProxy()->save(pChildLibraryTreeNode->getNameStructure())) {
pChildLibraryTreeNode->setIsSaved(true);
pChildLibraryTreeNode->setFileName(fileName);
Expand Down
13 changes: 13 additions & 0 deletions OMEdit/OMEditGUI/OMC/OMCProxy.cpp
Expand Up @@ -944,6 +944,19 @@ bool OMCProxy::isPartial(QString className)
return mpOMCInterface->isPartial(className);
}

/*!
* \brief OMCProxy::isReplaceable
* Returns true if the className is replaceable in parentClassName.
* \param parentClassName
* \param className
* \return
*/
bool OMCProxy::isReplaceable(QString parentClassName, QString className)
{
sendCommand("isReplaceable(" + parentClassName + ", \"" + className + "\")");
return StringHandler::unparseBool(getResult());
}

/*!
Gets the class type.
\param className - is the name of the class to check.
Expand Down
1 change: 1 addition & 0 deletions OMEdit/OMEditGUI/OMC/OMCProxy.h
Expand Up @@ -121,6 +121,7 @@ class OMCProxy : public QObject
bool isWhat(StringHandler::ModelicaClasses type, QString className);
bool isProtectedClass(QString className, QString nestedClassName);
bool isPartial(QString className);
bool isReplaceable(QString parentClassName, QString className);
StringHandler::ModelicaClasses getClassRestriction(QString className);
QString getParameterValue(QString className, QString parameter);
QStringList getComponentModifierNames(QString className, QString name);
Expand Down

0 comments on commit c183a88

Please sign in to comment.