Skip to content

Commit

Permalink
ticket:5666 Check component name against the list of keywords
Browse files Browse the repository at this point in the history
Use the default component name, if there is any, to find a new unique name.
  • Loading branch information
adeas31 committed Oct 21, 2019
1 parent 2705ebe commit 820af85
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 3 deletions.
12 changes: 10 additions & 2 deletions OMEdit/OMEdit/OMEditGUI/Modeling/ModelWidgetContainer.cpp
Expand Up @@ -354,8 +354,8 @@ bool GraphicsView::addComponent(QString className, QPointF position)
// get the model defaultComponentName
QString defaultName = pMainWindow->getOMCProxy()->getDefaultComponentName(pLibraryTreeItem->getNameStructure());
QString name;
if (!defaultName.isEmpty() && checkComponentName(defaultName)) {
name = defaultName;
if (!defaultName.isEmpty()) {
name = getUniqueComponentName(StringHandler::toCamelCase(defaultName));
} else {
name = getUniqueComponentName(StringHandler::toCamelCase(pLibraryTreeItem->getName()));
}
Expand Down Expand Up @@ -592,12 +592,20 @@ QString GraphicsView::getUniqueComponentName(QString componentName, int number)

/*!
* \brief GraphicsView::checkComponentName
* Checks the component name against the Modelica keywords as well.
* Checks if the component with the same name already exists or not.
* \param componentName
* \return
*/
bool GraphicsView::checkComponentName(QString componentName)
{
// if component name is any keyword of Modelica
if (mpModelWidget->getLibraryTreeItem()->getLibraryType() == LibraryTreeItem::Modelica) {
if (ModelicaHighlighter::getKeywords().contains(componentName)) {
return false;
}
}
// if component with same name exists
foreach (Component *pComponent, mComponentsList) {
if (pComponent->getName().compare(componentName, Qt::CaseSensitive) == 0) {
return false;
Expand Down
2 changes: 1 addition & 1 deletion OMEdit/OMEdit/OMEditGUI/Util/Helper.cpp
Expand Up @@ -717,7 +717,7 @@ QString GUIMessages::getMessage(int type)
case CHECK_MESSAGES_BROWSER:
return tr("Please check the Messages Browser for more error specific details.");
case SAME_COMPONENT_NAME:
return tr("A component with the name <b>%1</b> already exists. Please choose another name.");
return tr("A component with the name <b>%1</b> already exists or is a Modelica keyword. Please choose another name.");
case SAME_COMPONENT_CONNECT:
return tr("You cannot connect a component to itself.");
case NO_MODELICA_CLASS_OPEN:
Expand Down

0 comments on commit 820af85

Please sign in to comment.