@@ -1178,7 +1178,6 @@ void LibraryTreeModel::createNonExistingLibraryTreeItem(LibraryTreeItem *pLibrar
11781178 OMCProxy *pOMCProxy = mpLibraryWidget->getMainWindow ()->getOMCProxy ();
11791179 pLibraryTreeItem->setClassInformation (pOMCProxy->getClassInformation (pLibraryTreeItem->getNameStructure ()));
11801180 pLibraryTreeItem->setIsSaved (isSaved);
1181- pLibraryTreeItem->setSystemLibrary (pParentLibraryTreeItem == mpRootLibraryTreeItem ? true : pParentLibraryTreeItem->isSystemLibrary ());
11821181 pLibraryTreeItem->setIsProtected (pOMCProxy->isProtectedClass (pParentLibraryTreeItem->getNameStructure (), pLibraryTreeItem->getName ()));
11831182 if (pParentLibraryTreeItem->isDocumentationClass ()) {
11841183 pLibraryTreeItem->setIsDocumentationClass (true );
@@ -2550,76 +2549,89 @@ void LibraryWidget::openLibraryTreeItem(QString nameStructure)
25502549bool LibraryWidget::saveModelicaLibraryTreeItem (LibraryTreeItem *pLibraryTreeItem)
25512550{
25522551 bool result = false ;
2553- if (pLibraryTreeItem->isTopLevel () && pLibraryTreeItem->getChildren ().size () == 0 ) {
2554- /*
2555- A root model with no sub models.
2556- If it is a package then check whether save contents type. Otherwise simply save it to file.
2557- */
2558- if (pLibraryTreeItem->getRestriction () == StringHandler::Package && pLibraryTreeItem->getSaveContentsType () == LibraryTreeItem::SaveInOneFile) {
2559- result = saveLibraryTreeItemOneFileHelper (pLibraryTreeItem);
2560- } else if (pLibraryTreeItem->getRestriction () == StringHandler::Package && pLibraryTreeItem->getSaveContentsType () == LibraryTreeItem::SaveFolderStructure) {
2561- result = saveLibraryTreeItemFolderHelper (pLibraryTreeItem);
2562- } else {
2563- result = saveLibraryTreeItemHelper (pLibraryTreeItem);
2564- }
2565- if (result) {
2566- getMainWindow ()->addRecentFile (pLibraryTreeItem->getFileName (), Helper::utf8);
2567- /* We need to load the file again so that the line number information for model_info.xml is correct.
2568- * Update to AST (makes source info WRONG), saving it (source info STILL WRONG), reload it (and omc knows the new lines)
2569- * In order to get rid of it save API should update omc with new line information.
2570- */
2571- mpMainWindow->getOMCProxy ()->loadFile (pLibraryTreeItem->getFileName ());
2572- }
2573- } else if (pLibraryTreeItem->isTopLevel () && pLibraryTreeItem->getChildren ().size () > 0 ) {
2574- /* A root model with sub models.
2575- * If its a new model then its fileName is <interactive> then check its mSaveContentsType.
2576- * If mSaveContentsType is LibraryTreeItem::SaveInOneFile then we save all sub models in one file
2552+ LibraryTreeItem *pParentLibraryTreeItem = mpLibraryTreeModel->getContainingParentLibraryTreeItem (pLibraryTreeItem);
2553+ result = saveLibraryTreeItemHelper (pParentLibraryTreeItem);
2554+ if (result && !pLibraryTreeItem->isTopLevel ()) {
2555+ setChildLibraryTreeItemsSaved (pParentLibraryTreeItem);
2556+ }
2557+ if (result) {
2558+ getMainWindow ()->addRecentFile (pLibraryTreeItem->getFileName (), Helper::utf8);
2559+ /* We need to load the file again so that the line number information for model_info.xml is correct.
2560+ * Update to AST (makes source info WRONG), saving it (source info STILL WRONG), reload it (and omc knows the new lines)
2561+ * In order to get rid of it save API should update omc with new line information.
25772562 */
2578- if (pLibraryTreeItem->getFileName ().isEmpty () && pLibraryTreeItem->getSaveContentsType () == LibraryTreeItem::SaveInOneFile) {
2579- result = saveLibraryTreeItemOneFileHelper (pLibraryTreeItem);
2580- } else if (pLibraryTreeItem->getFileName ().isEmpty () && pLibraryTreeItem->getSaveContentsType () == LibraryTreeItem::SaveFolderStructure) {
2581- /* A root model with sub models.
2582- * If its a new model then its fileName is <interactive> then check its mSaveContentsType.
2583- * If mSaveContentsType is LibraryTreeItem::SaveFolderStructure then we save sub models in folder structure
2584- */
2585- result = saveLibraryTreeItemFolderHelper (pLibraryTreeItem);
2586- } else {
2587- result = saveLibraryTreeItemOneFileOrFolderHelper (pLibraryTreeItem);
2588- }
2589- if (result) {
2590- getMainWindow ()->addRecentFile (pLibraryTreeItem->getFileName (), Helper::utf8);
2591- /* We need to load the file again so that the line number information for model_info.xml is correct.
2592- * Update to AST (makes source info WRONG), saving it (source info STILL WRONG), reload it (and omc knows the new lines)
2593- * In order to get rid of it save API should update omc with new line information.
2594- */
2595- mpMainWindow->getOMCProxy ()->loadFile (pLibraryTreeItem->getFileName ());
2596- }
2597- } else if (!pLibraryTreeItem->isTopLevel ()) {
2598- /* A sub model contained inside some other model.
2599- * Find its root model.
2600- * If the root model fileName is <interactive> then check its mSaveContentsType.
2601- * If mSaveContentsType is LibraryTreeItem::SaveInOneFile then we save all sub models in one file.
2602- */
2603- pLibraryTreeItem = mpLibraryTreeModel->findLibraryTreeItem (StringHandler::getFirstWordBeforeDot (pLibraryTreeItem->getNameStructure ()));
2604- if (pLibraryTreeItem->getFileName ().isEmpty () && pLibraryTreeItem->getSaveContentsType () == LibraryTreeItem::SaveInOneFile) {
2605- result = saveLibraryTreeItemOneFileHelper (pLibraryTreeItem);
2606- }
2607- /* If mSaveContentsType is LibraryTreeItem::SaveFolderStructure then we save sub models in folder structure
2608- */
2609- else if (pLibraryTreeItem->getFileName ().isEmpty () && pLibraryTreeItem->getSaveContentsType () == LibraryTreeItem::SaveFolderStructure) {
2610- result = saveLibraryTreeItemFolderHelper (pLibraryTreeItem);
2611- } else {
2612- result = saveLibraryTreeItemOneFileOrFolderHelper (pLibraryTreeItem);
2613- }
2614- if (result) {
2615- getMainWindow ()->addRecentFile (pLibraryTreeItem->getFileName (), Helper::utf8);
2616- /* We need to load the file again so that the line number information for model_info.xml is correct.
2617- * Update to AST (makes source info WRONG), saving it (source info STILL WRONG), reload it (and omc knows the new lines)
2618- * In order to get rid of it save API should update omc with new line information.
2619- */
2620- mpMainWindow->getOMCProxy ()->loadFile (pLibraryTreeItem->getFileName ());
2621- }
2622- }
2563+ // mpMainWindow->getOMCProxy()->loadFile(pLibraryTreeItem->getFileName());
2564+ }
2565+ // if (pLibraryTreeItem->isTopLevel() && pLibraryTreeItem->getChildren().size() == 0) {
2566+ // /*
2567+ // A root model with no sub models.
2568+ // If it is a package then check whether save contents type. Otherwise simply save it to file.
2569+ // */
2570+ // if (pLibraryTreeItem->getRestriction() == StringHandler::Package && pLibraryTreeItem->getSaveContentsType() == LibraryTreeItem::SaveInOneFile) {
2571+ // result = saveLibraryTreeItemOneFileHelper(pLibraryTreeItem);
2572+ // } else if (pLibraryTreeItem->getRestriction() == StringHandler::Package && pLibraryTreeItem->getSaveContentsType() == LibraryTreeItem::SaveFolderStructure) {
2573+ // result = saveLibraryTreeItemFolderHelper(pLibraryTreeItem);
2574+ // } else {
2575+ // result = saveLibraryTreeItemHelper(pLibraryTreeItem);
2576+ // }
2577+ // if (result) {
2578+ // getMainWindow()->addRecentFile(pLibraryTreeItem->getFileName(), Helper::utf8);
2579+ // /* We need to load the file again so that the line number information for model_info.xml is correct.
2580+ // * Update to AST (makes source info WRONG), saving it (source info STILL WRONG), reload it (and omc knows the new lines)
2581+ // * In order to get rid of it save API should update omc with new line information.
2582+ // */
2583+ // mpMainWindow->getOMCProxy()->loadFile(pLibraryTreeItem->getFileName());
2584+ // }
2585+ // } else if (pLibraryTreeItem->isTopLevel() && pLibraryTreeItem->getChildren().size() > 0) {
2586+ // /* A root model with sub models.
2587+ // * If its a new model then its fileName is <interactive> then check its mSaveContentsType.
2588+ // * If mSaveContentsType is LibraryTreeItem::SaveInOneFile then we save all sub models in one file
2589+ // */
2590+ // if (pLibraryTreeItem->getFileName().isEmpty() && pLibraryTreeItem->getSaveContentsType() == LibraryTreeItem::SaveInOneFile) {
2591+ // result = saveLibraryTreeItemOneFileHelper(pLibraryTreeItem);
2592+ // } else if (pLibraryTreeItem->getFileName().isEmpty() && pLibraryTreeItem->getSaveContentsType() == LibraryTreeItem::SaveFolderStructure) {
2593+ // /* A root model with sub models.
2594+ // * If its a new model then its fileName is <interactive> then check its mSaveContentsType.
2595+ // * If mSaveContentsType is LibraryTreeItem::SaveFolderStructure then we save sub models in folder structure
2596+ // */
2597+ // result = saveLibraryTreeItemFolderHelper(pLibraryTreeItem);
2598+ // } else {
2599+ // result = saveLibraryTreeItemOneFileOrFolderHelper(pLibraryTreeItem);
2600+ // }
2601+ // if (result) {
2602+ // getMainWindow()->addRecentFile(pLibraryTreeItem->getFileName(), Helper::utf8);
2603+ // /* We need to load the file again so that the line number information for model_info.xml is correct.
2604+ // * Update to AST (makes source info WRONG), saving it (source info STILL WRONG), reload it (and omc knows the new lines)
2605+ // * In order to get rid of it save API should update omc with new line information.
2606+ // */
2607+ // mpMainWindow->getOMCProxy()->loadFile(pLibraryTreeItem->getFileName());
2608+ // }
2609+ // } else if (!pLibraryTreeItem->isTopLevel()) {
2610+ // /* A sub model contained inside some other model.
2611+ // * Find its root model.
2612+ // * If the root model fileName is <interactive> then check its mSaveContentsType.
2613+ // * If mSaveContentsType is LibraryTreeItem::SaveInOneFile then we save all sub models in one file.
2614+ // */
2615+ // pLibraryTreeItem = mpLibraryTreeModel->findLibraryTreeItem(StringHandler::getFirstWordBeforeDot(pLibraryTreeItem->getNameStructure()));
2616+ // if (pLibraryTreeItem->getFileName().isEmpty() && pLibraryTreeItem->getSaveContentsType() == LibraryTreeItem::SaveInOneFile) {
2617+ // result = saveLibraryTreeItemOneFileHelper(pLibraryTreeItem);
2618+ // }
2619+ // /* If mSaveContentsType is LibraryTreeItem::SaveFolderStructure then we save sub models in folder structure
2620+ // */
2621+ // else if (pLibraryTreeItem->getFileName().isEmpty() && pLibraryTreeItem->getSaveContentsType() == LibraryTreeItem::SaveFolderStructure) {
2622+ // result = saveLibraryTreeItemFolderHelper(pLibraryTreeItem);
2623+ // } else {
2624+ // result = saveLibraryTreeItemOneFileOrFolderHelper(pLibraryTreeItem);
2625+ // }
2626+ // if (result) {
2627+ // getMainWindow()->addRecentFile(pLibraryTreeItem->getFileName(), Helper::utf8);
2628+ // /* We need to load the file again so that the line number information for model_info.xml is correct.
2629+ // * Update to AST (makes source info WRONG), saving it (source info STILL WRONG), reload it (and omc knows the new lines)
2630+ // * In order to get rid of it save API should update omc with new line information.
2631+ // */
2632+ // mpMainWindow->getOMCProxy()->loadFile(pLibraryTreeItem->getFileName());
2633+ // }
2634+ // }
26232635 return result;
26242636}
26252637
@@ -2776,6 +2788,7 @@ bool LibraryWidget::saveLibraryTreeItemHelper(LibraryTreeItem *pLibraryTreeItem)
27762788 pLibraryTreeItem->getModelWidget ()->setWindowTitle (pLibraryTreeItem->getNameStructure ());
27772789 pLibraryTreeItem->getModelWidget ()->setModelFilePathLabel (fileName);
27782790 }
2791+ mpLibraryTreeModel->updateLibraryTreeItem (pLibraryTreeItem);
27792792 } else {
27802793 QMessageBox::information (this , Helper::applicationName + " - " + Helper::error, GUIMessages::getMessage (GUIMessages::ERROR_OCCURRED)
27812794 .arg (GUIMessages::getMessage (GUIMessages::UNABLE_TO_SAVE_FILE).arg (file.errorString ())), Helper::ok);
@@ -2784,6 +2797,28 @@ bool LibraryWidget::saveLibraryTreeItemHelper(LibraryTreeItem *pLibraryTreeItem)
27842797 return true ;
27852798}
27862799
2800+ /* !
2801+ * \brief LibraryWidget::setChildLibraryTreeItemsSaved
2802+ * Marks the child LibraryTreeItems saved.
2803+ * \param pLibraryTreeItem
2804+ */
2805+ void LibraryWidget::setChildLibraryTreeItemsSaved (LibraryTreeItem *pLibraryTreeItem)
2806+ {
2807+ for (int i = 0 ; i < pLibraryTreeItem->getChildren ().size (); i++) {
2808+ LibraryTreeItem *pChildLibraryTreeItem = pLibraryTreeItem->child (i);
2809+ pChildLibraryTreeItem->setIsSaved (true );
2810+ pChildLibraryTreeItem->setFileName (pLibraryTreeItem->getFileName ());
2811+ if (pChildLibraryTreeItem->getModelWidget ()) {
2812+ pChildLibraryTreeItem->getModelWidget ()->setWindowTitle (pChildLibraryTreeItem->getNameStructure ());
2813+ pChildLibraryTreeItem->getModelWidget ()->setModelFilePathLabel (pLibraryTreeItem->getFileName ());
2814+ }
2815+ mpLibraryTreeModel->updateLibraryTreeItem (pChildLibraryTreeItem);
2816+ if (pChildLibraryTreeItem->getSaveContentsType () == LibraryTreeItem::SaveInOneFile) {
2817+ setChildLibraryTreeItemsSaved (pChildLibraryTreeItem);
2818+ }
2819+ }
2820+ }
2821+
27872822/* !
27882823 * \brief LibraryWidget::saveLibraryTreeItemOneFileHelper
27892824 * Helper function for saving a LibraryTreeItem.
0 commit comments