Project/IdlCompilerOptionsDialog.py

branch
corba_options
changeset 6445
2b022e5ba54c
parent 6442
9d42b6c08a27
child 6466
dac80ad0de75
--- a/Project/IdlCompilerOptionsDialog.py	Sun Jul 29 12:53:57 2018 +0200
+++ b/Project/IdlCompilerOptionsDialog.py	Sun Jul 29 14:00:23 2018 +0200
@@ -17,6 +17,8 @@
 from E5Gui import E5PathPickerDialog
 from E5Gui.E5PathPicker import E5PathPickerModes
 
+from .IdlCompilerDefineNameDialog import IdlCompilerDefineNameDialog
+
 
 class IdlCompilerOptionsDialog(QDialog, Ui_IdlCompilerOptionsDialog):
     """
@@ -115,11 +117,7 @@
         @return flag indicating that the given directory is already included
         @rtype bool
         """
-        for row in range(self.idList.count()):
-            if self.idList.item(row).text() == directory:
-                return True
-        
-        return False
+        return len(self.idList.findItems(directory, Qt.MatchExactly)) > 0
     
     @pyqtSlot()
     def on_idList_itemSelectionChanged(self):
@@ -227,6 +225,37 @@
         
         self.dnList.sortItems(0, Qt.AscendingOrder)
     
+    def __generateDefinedNamesList(self):
+        """
+        Private method to prepare the list of 'Defined Names'.
+        
+        @return list of 'Defined Names'
+        @rtype list of str
+        """
+        definedNames = []
+        for row in range(self.dnList.topLevelItemCount()):
+            itm = self.dnList.topLevelItem(row)
+            name = itm.text(0).strip()
+            value = itm.text(1).strip()
+            if value:
+                definedNames.append("{0}={1}".format(name, value))
+            else:
+                definedNames.append(name)
+        
+        return definedNames
+    
+    def __definedNamesContain(self, name):
+        """
+        Private method to test, if the currently defined 'Defined Names'
+        contain a given one.
+        
+        @param name variable name to be tested
+        @type str
+        @return flag indicating that the given name is already included
+        @rtype bool
+        """
+        return len(self.dnList.findItems(name, Qt.MatchExactly, 0)) > 0
+    
     @pyqtSlot()
     def on_dnList_itemSelectionChanged(self):
         """
@@ -237,26 +266,51 @@
     @pyqtSlot()
     def on_dnAddButton_clicked(self):
         """
-        Slot documentation goes here.
+        Private slot to add a 'Define Name' entry.
         """
-        # TODO: not implemented yet
-        raise NotImplementedError
+        dlg = IdlCompilerDefineNameDialog(parent=self)
+        if dlg.exec_() == QDialog.Accepted:
+            name, value = dlg.getData()
+            if not self.__definedNamesContain(name):
+                QTreeWidgetItem(self.dnList, [name, value])
+        
+        self.dnList.sortItems(0, Qt.AscendingOrder)
     
     @pyqtSlot()
     def on_dnDeleteButton_clicked(self):
         """
-        Slot documentation goes here.
+        Private slot to delete the selected 'Define Name' entry.
         """
-        # TODO: not implemented yet
-        raise NotImplementedError
+        itm = self.dnList.selectedItems()[0]
+        index = self.dnList.indexOfTopLevelItem(itm)
+        self.dnList.takeTopLevelItem(index)
+        del itm
     
     @pyqtSlot()
     def on_dnEditButton_clicked(self):
         """
-        Slot documentation goes here.
+        Private slot to edit the selected 'Define Name' entry.
         """
-        # TODO: not implemented yet
-        raise NotImplementedError
+        itm = self.dnList.selectedItems()[0]
+        
+        dlg = IdlCompilerDefineNameDialog(
+            name=itm.text(0), value=itm.text(1), parent=self)
+        if dlg.exec_() == QDialog.Accepted:
+            name, value = dlg.getData()
+            if self.__definedNamesContain(name) and itm.text(0) != name:
+                # the entry exists already, delete the edited one
+                index = self.dnList.indexOfTopLevelItem(itm)
+                self.dnList.takeTopLevelItem(index)
+                del itm
+                
+                # change the named one
+                itm = self.dnList.findItems(name, Qt.MatchExactly, 0)[0]
+                itm.setText(1, value)
+            else:
+                itm.setText(0, name)
+                itm.setText(1, value)
+        
+        self.dnList.sortItems(0, Qt.AscendingOrder)
     
     #######################################################################
     ## Methods implementing the 'Undefine Name' option
@@ -292,11 +346,7 @@
         @return flag indicating that the given name is already included
         @rtype bool
         """
-        for row in range(self.unList.count()):
-            if self.unList.item(row).text() == name:
-                return True
-        
-        return False
+        return len(self.unList.findItems(name, Qt.MatchExactly)) > 0
     
     @pyqtSlot()
     def on_unList_itemSelectionChanged(self):
@@ -365,6 +415,6 @@
         """
         return (
             self.__generateIncludeDirectoriesList(),
-            [],
+            self.__generateDefinedNamesList(),
             self.__generateUndefinedNamesList(),
         )

eric ide

mercurial