Skip to content

Commit

Permalink
ticket:4357 Don't allow spaces in component name.
Browse files Browse the repository at this point in the history
  • Loading branch information
adeas31 committed Mar 27, 2017
1 parent a4c9d93 commit ebd8f5e
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 12 deletions.
9 changes: 8 additions & 1 deletion OMEdit/OMEditGUI/Modeling/ModelicaClassDialog.cpp
Expand Up @@ -1840,12 +1840,19 @@ ComponentNameDialog::ComponentNameDialog(QString name, GraphicsView *pGraphicsVi
*/
void ComponentNameDialog::updateComponentName()
{
// check name
// check if name is empty
if (mpNameTextBox->text().isEmpty()) {
QMessageBox::critical(this, QString("%1 - %2").arg(Helper::applicationName).arg(Helper::error), GUIMessages::getMessage(
GUIMessages::ENTER_NAME).arg(Helper::item), Helper::ok);
return;
}
// check for spaces
if (StringHandler::containsSpace(mpNameTextBox->text())) {
QMessageBox::critical(MainWindow::instance(), QString("%1 - %2").arg(Helper::applicationName).arg(Helper::information),
tr("A component name should not have spaces. Please choose another name."), Helper::ok);
return;
}
// check for existing component name
if (!mpGraphicsView->checkComponentName(mpNameTextBox->text())) {
QMessageBox::information(MainWindow::instance(), QString("%1 - %2").arg(Helper::applicationName).arg(Helper::information),
GUIMessages::getMessage(GUIMessages::SAME_COMPONENT_NAME).arg(mpNameTextBox->text()), Helper::ok);
Expand Down
25 changes: 15 additions & 10 deletions OMEdit/OMEditGUI/OMC/OMCProxy.cpp
Expand Up @@ -1717,10 +1717,11 @@ QString OMCProxy::getDefaultComponentPrefixes(QString className)
bool OMCProxy::addComponent(QString name, QString className, QString componentName, QString placementAnnotation)
{
sendCommand("addComponent(" + name + ", " + className + "," + componentName + "," + placementAnnotation + ")");
if (StringHandler::unparseBool(getResult()))
if (StringHandler::unparseBool(getResult())) {
return true;
else
} else {
return false;
}
}

/*!
Expand All @@ -1732,10 +1733,11 @@ bool OMCProxy::addComponent(QString name, QString className, QString componentNa
bool OMCProxy::deleteComponent(QString name, QString componentName)
{
sendCommand("deleteComponent(" + name + "," + componentName + ")");
if (StringHandler::unparseBool(getResult()))
if (StringHandler::unparseBool(getResult())) {
return true;
else
} else {
return false;
}
}

/*!
Expand All @@ -1750,10 +1752,11 @@ bool OMCProxy::deleteComponent(QString name, QString componentName)
bool OMCProxy::renameComponent(QString className, QString oldName, QString newName)
{
sendCommand("renameComponent(" + className + "," + oldName + "," + newName + ")");
if (getResult().toLower().contains("error"))
if (getResult().toLower().contains("error")) {
return false;
else
} else {
return true;
}
}

/*!
Expand All @@ -1767,10 +1770,11 @@ bool OMCProxy::renameComponent(QString className, QString oldName, QString newNa
bool OMCProxy::updateComponent(QString name, QString className, QString componentName, QString placementAnnotation)
{
sendCommand("updateComponent(" + name + "," + className + "," + componentName + "," + placementAnnotation + ")");
if (StringHandler::unparseBool(getResult()))
if (StringHandler::unparseBool(getResult())) {
return true;
else
} else {
return false;
}
}

/*!
Expand All @@ -1784,10 +1788,11 @@ bool OMCProxy::updateComponent(QString name, QString className, QString componen
bool OMCProxy::renameComponentInClass(QString className, QString oldName, QString newName)
{
sendCommand("renameComponentInClass(" + className + "," + oldName + "," + newName + ")");
if (getResult().toLower().contains("error"))
if (getResult().toLower().contains("error")) {
return false;
else
} else {
return true;
}
}

/*!
Expand Down
2 changes: 1 addition & 1 deletion OMEdit/OMEditGUI/Util/Helper.cpp
Expand Up @@ -594,7 +594,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. 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 ebd8f5e

Please sign in to comment.