Explorar o código

added objects renaming capability

Arkady Trestman %!s(int64=16) %!d(string=hai) anos
pai
achega
d71ea75038
Modificáronse 1 ficheiros con 20 adicións e 1 borrados
  1. 20 1
      direct/src/leveleditor/ObjectPaletteBase.py

+ 20 - 1
direct/src/leveleditor/ObjectPaletteBase.py

@@ -86,9 +86,28 @@ class ObjectPaletteBase:
         try:
         try:
             item = self.data[name]
             item = self.data[name]
         except:
         except:
-            return None;
+            return None
         return item
         return item
 
 
+    def rename(self, oldName, newName):
+        #import pdb;set_trace()
+        if oldName == newName:
+           return False
+        if newName == "":
+           return False
+        try:
+            for key in self.dataStruct.keys():
+                if self.dataStruct[key] == oldName:
+                   self.dataStruct[key] = newName
+
+            self.dataStruct[newName] = self.dataStruct.pop(oldName)
+            item = self.data.pop(oldName)
+            item.name = newName
+            self.data[newName] = item
+        except:
+            return False
+        return True
+
     def populate(self):
     def populate(self):
         # You should implement this in subclass
         # You should implement this in subclass
         raise NotImplementedError('populate() must be implemented in ObjectPalette.py')
         raise NotImplementedError('populate() must be implemented in ObjectPalette.py')