Add also files, when selecting the modules in the project loading process
[bertos.git] / wizard / BEditingDialog.py
index 6ed7e621c3fab625c664c3666fb58e2709a3aae7..1b297d3879ce84d8015b984abb8f23c58954099b 100644 (file)
@@ -44,6 +44,7 @@ from BToolchainPage import BToolchainPage
 from BVersionPage import BVersionPage
 import qvariant_converter
 import BModulePage
+import bertos_utils
 
 class BEditingDialog(QDialog):
 
@@ -71,6 +72,7 @@ class BEditingDialog(QDialog):
         button_layout.addWidget(self.apply_button)
         layout.addLayout(button_layout)
         self.setLayout(layout)
+        self.setWindowTitle(self.tr("Edit \"%1\" project").arg(os.path.basename(self.module_page.projectInfo("PROJECT_PATH"))))
 
     def setupMenu(self):
         self.menu = QMenu(self.tr("Advanced options"))
@@ -89,7 +91,15 @@ class BEditingDialog(QDialog):
         dialog = QDialog()
         layout = QVBoxLayout()
         toolchain_page = BToolchainPage()
+       current_toolchain = toolchain_page.projectInfo("TOOLCHAIN")
         toolchain_page.reloadData()
+       # TODO: to be moved in BToolchainPage
+       for toolchain_row in range(toolchain_page.pageContent.toolchainList.count()):
+            toolchain = qvariant_converter.getStringDict(toolchain_page.pageContent.toolchainList.item(toolchain_row).data(Qt.UserRole))
+           if toolchain["path"] == current_toolchain["path"]:
+                toolchain_page.pageContent.toolchainList.setCurrentRow(toolchain_row)
+               toolchain_page.selectionChanged()
+               break
         layout.addWidget(toolchain_page)
         button_layout = QHBoxLayout()
         button_layout.addStretch()
@@ -101,7 +111,10 @@ class BEditingDialog(QDialog):
         layout.addLayout(button_layout)
         dialog.setLayout(layout)
         dialog.connect(ok_button, SIGNAL("clicked()"), dialog.accept)
-        dialog.exec_()
+        dialog.setWindowTitle(self.tr("Change toolchain"))
+        if dialog.exec_():
+            toolchain = qvariant_converter.getStringDict(toolchain_page.currentItem().data(Qt.UserRole))
+            toolchain_page.setProjectInfo("TOOLCHAIN", toolchain)
     
     def changeBertosVersion(self):
         dialog = QDialog()
@@ -119,7 +132,37 @@ class BEditingDialog(QDialog):
         layout.addLayout(button_layout)
         dialog.setLayout(layout)
         dialog.connect(ok_button, SIGNAL("clicked()"), dialog.accept)
-        dialog.exec_()
+        current_version = version_page.projectInfo("SOURCES_PATH")
+        dialog.setWindowTitle(self.tr("Change BeRTOS version"))
+        if dialog.exec_():
+            version = qvariant_converter.getString(version_page.currentItem().data(Qt.UserRole))
+            if version != current_version:
+                if QMessageBox.question(
+                    version_page,
+                    self.tr("BeRTOS version update"),
+                    self.tr("Changing the BeRTOS version will destroy all the modification done on the BeRTOS sources"),
+                    QMessageBox.Ok | QMessageBox.Cancel
+                ) == QMessageBox.Ok:
+                    version_page.setProjectInfo("SOURCES_PATH", version)
+                    version_page.setProjectInfo("OLD_SOURCES_PATH", current_version)
+                    enabled_modules = bertos_utils.enabledModules(version_page.project())
+                    old_configuration = version_page.projectInfo("CONFIGURATIONS")
+                    bertos_utils.loadSourceTree(version_page.project())
+                    bertos_utils.loadModuleData(version_page.project())
+                    new_configuration = version_page.projectInfo("CONFIGURATIONS")
+                    merged_configuration = {}
+                    for conf in new_configuration:
+                        if conf in old_configuration:
+                            configuration = bertos_utils.updateConfigurationValues(new_configuration[conf], old_configuration[conf])
+                        else:
+                            configuration = new_configuration[conf]
+                        merged_configuration[conf] = configuration
+                    version_page.setProjectInfo("CONFIGURATIONS", merged_configuration)
+                    bertos_utils.setEnabledModules(version_page.project(), enabled_modules)
+                    self.module_page.fillModuleTree()
+               else:
+                   # Rollback version to the previous selected one.
+                   version_page.setProjectInfo("SOURCES_PATH", current_version)
 
     def apply(self):
         createBertosProject(self.module_page.project(), edit=True)