Skip to content

Commit

Permalink
#3362 - Updated the question message according to context menu choice.
Browse files Browse the repository at this point in the history
  • Loading branch information
adeas31 committed Jun 26, 2015
1 parent 05fbbbb commit 2014834
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 13 deletions.
36 changes: 24 additions & 12 deletions OMEdit/OMEditGUI/Modeling/LibraryTreeWidget.cpp
Expand Up @@ -881,20 +881,29 @@ void LibraryTreeWidget::showProtectedClasses(bool enable)
}
}

/*!
* \brief LibraryTreeWidget::unloadClass
* Helper function for unloading/deleting the Modelica class.
* \param pLibraryTreeNode
* \param askQuestion
* \return
*/
bool LibraryTreeWidget::unloadClass(LibraryTreeNode *pLibraryTreeNode, bool askQuestion)
{
if (askQuestion)
{
if (askQuestion) {
QMessageBox *pMessageBox = new QMessageBox(mpMainWindow);
pMessageBox->setWindowTitle(QString(Helper::applicationName).append(" - ").append(Helper::question));
pMessageBox->setIcon(QMessageBox::Question);
pMessageBox->setAttribute(Qt::WA_DeleteOnClose);
pMessageBox->setText(GUIMessages::getMessage(GUIMessages::DELETE_CLASS_MSG).arg(pLibraryTreeNode->getNameStructure()));
if (pLibraryTreeNode->getParentName().isEmpty()) {
pMessageBox->setText(GUIMessages::getMessage(GUIMessages::UNLOAD_CLASS_MSG).arg(pLibraryTreeNode->getNameStructure()));
} else {
pMessageBox->setText(GUIMessages::getMessage(GUIMessages::DELETE_CLASS_MSG).arg(pLibraryTreeNode->getNameStructure()));
}
pMessageBox->setStandardButtons(QMessageBox::Yes | QMessageBox::No);
pMessageBox->setDefaultButton(QMessageBox::Yes);
int answer = pMessageBox->exec();
switch (answer)
{
switch (answer) {
case QMessageBox::Yes:
// Yes was clicked. Don't return.
break;
Expand All @@ -910,16 +919,13 @@ bool LibraryTreeWidget::unloadClass(LibraryTreeNode *pLibraryTreeNode, bool askQ
Delete the class in OMC.
If deleteClass is successfull remove the class from Library Browser and delete the corresponding ModelWidget.
*/
if (mpMainWindow->getOMCProxy()->deleteClass(pLibraryTreeNode->getNameStructure()))
{
if (mpMainWindow->getOMCProxy()->deleteClass(pLibraryTreeNode->getNameStructure())) {
/* remove the child nodes first */
unloadClassHelper(pLibraryTreeNode);
mpMainWindow->getOMCProxy()->removeCachedOMCCommand(pLibraryTreeNode->getNameStructure());
unloadLibraryTreeNodeAndModelWidget(pLibraryTreeNode);
return true;
}
else
{
} else {
QMessageBox::critical(mpMainWindow, QString(Helper::applicationName).append(" - ").append(Helper::error),
GUIMessages::getMessage(GUIMessages::ERROR_OCCURRED).arg(mpMainWindow->getOMCProxy()->getResult())
.append(tr("while deleting ") + pLibraryTreeNode->getNameStructure()), Helper::ok);
Expand Down Expand Up @@ -1767,14 +1773,20 @@ void LibraryTreeWidget::duplicateClass()
}
}

/*!
* \brief LibraryTreeWidget::unloadClass
* Unloads/Deletes the Modelica class.
*/
void LibraryTreeWidget::unloadClass()
{
QList<QTreeWidgetItem*> selectedItemsList = selectedItems();
if (selectedItemsList.isEmpty())
if (selectedItemsList.isEmpty()) {
return;
}
LibraryTreeNode *pLibraryTreeNode = dynamic_cast<LibraryTreeNode*>(selectedItemsList.at(0));
if (pLibraryTreeNode)
if (pLibraryTreeNode) {
unloadClass(pLibraryTreeNode);
}
}

void LibraryTreeWidget::unloadTextFile()
Expand Down
4 changes: 3 additions & 1 deletion OMEdit/OMEditGUI/Util/Helper.cpp
Expand Up @@ -563,8 +563,10 @@ QString GUIMessages::getMessage(int type)
return tr("The XML is generated at %1/%2.xml");
case FIGARO_GENERATED:
return tr("The FIGARO is generated.");
case DELETE_CLASS_MSG:
case UNLOAD_CLASS_MSG:
return tr("Are you sure you want to unload <b>%1</b>? Everything contained inside this class will also be unloaded.");
case DELETE_CLASS_MSG:
return tr("Are you sure you want to delete <b>%1</b>? Everything contained inside this class will also be deleted.");
case DELETE_TEXT_FILE_MSG:
return tr("Are you sure you want to unload <b>%1</b>?");
case WRONG_MODIFIER:
Expand Down
1 change: 1 addition & 0 deletions OMEdit/OMEditGUI/Util/Helper.h
Expand Up @@ -345,6 +345,7 @@ class GUIMessages : public QObject
FMU_GENERATED,
XML_GENERATED,
FIGARO_GENERATED,
UNLOAD_CLASS_MSG,
DELETE_CLASS_MSG,
DELETE_TEXT_FILE_MSG,
WRONG_MODIFIER,
Expand Down

0 comments on commit 2014834

Please sign in to comment.