Browse Source

added label editing capability

Arkady Trestman 16 years ago
parent
commit
0cc987d0b7
1 changed files with 22 additions and 0 deletions
  1. 22 0
      direct/src/leveleditor/ProtoPaletteUI.py

+ 22 - 0
direct/src/leveleditor/ProtoPaletteUI.py

@@ -53,6 +53,8 @@ class ProtoPaletteUI(wx.Panel):
         self.rootName = "Proto Objects"
         self.rootName = "Proto Objects"
         self.root = self.tree.AddRoot(self.rootName)
         self.root = self.tree.AddRoot(self.rootName)
         self.addTreeNodes(self.root, self.palette.dataStruct)
         self.addTreeNodes(self.root, self.palette.dataStruct)
+        
+        self.editorTxt = "Proto Objects Editor"
 
 
         self.opAdd    = "Add Group"
         self.opAdd    = "Add Group"
         self.opDelete = "Delete Group"
         self.opDelete = "Delete Group"
@@ -81,6 +83,7 @@ class ProtoPaletteUI(wx.Panel):
 
 
         self.tree.Bind(wx.EVT_TREE_SEL_CHANGED, self.onSelected)
         self.tree.Bind(wx.EVT_TREE_SEL_CHANGED, self.onSelected)
         self.tree.Bind(wx.EVT_TREE_BEGIN_DRAG, self.onBeginDrag)
         self.tree.Bind(wx.EVT_TREE_BEGIN_DRAG, self.onBeginDrag)
+        self.tree.Bind(wx.EVT_TREE_END_LABEL_EDIT, self.OnEndLabelEdit)
         self.tree.Bind(wx.EVT_KILL_FOCUS , self.OnKillFocus)
         self.tree.Bind(wx.EVT_KILL_FOCUS , self.OnKillFocus)
 
 
         self.SetDropTarget(FileDrop(self.editor))
         self.SetDropTarget(FileDrop(self.editor))
@@ -146,6 +149,25 @@ class ProtoPaletteUI(wx.Panel):
             tds.SetData(tdo)
             tds.SetData(tdo)
             tds.DoDragDrop(True)
             tds.DoDragDrop(True)
 
 
+    def OnEndLabelEdit(self, event):
+        item = event.GetItem()
+        if item != self.tree.GetRootItem():
+            newLabel = event.GetLabel()
+            if self.traverse(self.tree.GetRootItem(), newLabel) is None:
+               oldLabel = self.tree.GetItemText(item)
+               if isinstance(self.editor.protoPalette.findItem(oldLabel), ObjectBase):
+                  event.Veto()
+                  wx.MessageBox("Only groups allowed to be renamed", self.editorTxt, wx.OK|wx.ICON_EXCLAMATION)
+               elif not self.editor.protoPalette.rename(oldLabel, newLabel):
+                  event.Veto()
+                  wx.MessageBox("Label '%s' is not allowed" % newLabel, self.editorTxt, wx.OK|wx.ICON_EXCLAMATION)
+            else:
+               event.Veto()
+               wx.MessageBox("There is already an item labled '%s'" % newLabel, self.editorTxt, wx.OK|wx.ICON_EXCLAMATION)
+        else:
+            event.Veto()
+            wx.MessageBox("'%s' renaming is not allowed" % self.rootName, self.editorTxt, wx.OK|wx.ICON_EXCLAMATION)
+
     def OnKillFocus(self, event):
     def OnKillFocus(self, event):
         print "Leaving protoUI window..."
         print "Leaving protoUI window..."
         self.SetDropTarget(FileDrop(self.editor))
         self.SetDropTarget(FileDrop(self.editor))