Add LICENSE
[pygdb.git] / BreakpointsFrame.py
index 3093fbbe18c047c2e44361dfa75a8d4c560732df..8450699eb4c5e970cd73837bf4ffba2ec177f436 100644 (file)
@@ -22,6 +22,8 @@ class BreakpointsFrame (StatusFrame.StatusFrame):
                StatusFrame.StatusFrame.__init__(self, debugger)
                self.set_label("Breakpoints")
 
+               debugger.gotActiveCallback += [self.updateValues]
+
                vbox = gtk.VBox(False, 5)
                self.add(vbox)
 
@@ -49,6 +51,7 @@ class BreakpointsFrame (StatusFrame.StatusFrame):
                self.tv = gtk.TreeView(self.model)
                self.tv.set_rules_hint(True)
                self.tv.get_selection().set_mode(gtk.SELECTION_MULTIPLE)
+               self.tv.get_selection().connect("changed", self.selChanged)
 
                self.__addColumns(self.tv)      
                sw.add(self.tv)
@@ -85,46 +88,20 @@ class BreakpointsFrame (StatusFrame.StatusFrame):
                tv.append_column(col)
 
 
+       def selChanged(self, sel):
+               model, paths = sel.get_selected_rows()
 
-       def addBtnClicked(self, btn):
-
-               if not self.debugger.isActive():
-                       return
-
-
-               bpspec = self.bpEntry.get_text()
-               bpspec = bpspec.strip()
-               rx = re.compile("^[\w\._\-]+:\d+(\s+if\s+\S+.*)?$")
-
-               #Check if format is correct
-               if not rx.search(bpspec):
-                       dialog = gtk.MessageDialog(None, \
-                               gtk.DIALOG_MODAL | gtk.DIALOG_DESTROY_WITH_PARENT, \
-                               gtk.MESSAGE_ERROR, gtk.BUTTONS_OK, \
-                               "Invalid format!") 
-                       dialog.run()
-                       dialog.destroy()
-                       return
-
-
-               ifsplit = string.split(bpspec, "if")
-
-               if len(ifsplit)>1:
-                       cond = ifsplit[1].strip()
-               else:
-                       cond = None
-
-               pos = ifsplit[0].strip()        
-               [file,lineno] = string.split(pos, ":")
+               if len(paths) > 0:
+                       path = paths[0]
+                       iter = model.get_iter(path)
+                       bpspec, = model.get(iter, 1)
+                       self.bpEntry.set_text(bpspec)
 
-               self.addBreakpoint(file, lineno, cond)
-       
 
 
        def addBreakpoint(self, file, lineno, cond=None):
 
                no = self.debugger.setBreakpoint(file, lineno, cond)
-
                if no!=None:
                        self.addBreakpointToList(no, file, lineno, cond)
                else:
@@ -139,24 +116,78 @@ class BreakpointsFrame (StatusFrame.StatusFrame):
        def applyConfiguration(self, conf):
                for b in conf.breakpoints:
                        self.addBreakpoint(b["file"], b["lineno"], b["cond"])
+               self.updateValues(None, None)
 
        def fillConfiguration(self, conf):
                iter = self.model.get_iter_first()
                while iter != None:
                        spec, = self.model.get(iter, 1)
-                       conf.parseBreak(spec)
+
+                       #Replacing file by absolute path
+                       file = string.split(spec, ":")[0]
+                       file = self.debugger.toAbsPath(file)
+                       postfile = string.join( string.split(spec,":")[1:], ":")
+
+                       conf.parseBreak(file + ":" + postfile )
                        iter = self.model.iter_next(iter)
 
 
 
        def addBreakpointToList(self, no, file, lineno, cond=None):
-               iter = self.model.append()
-               self.model.set(iter, 0, no)
 
                if cond==None:
-                       self.model.set(iter, 1, "%s:%s" % (str(file), str(lineno)))
+                       expr =  "%s:%s" % (str(file), str(lineno))
+               else:
+                       expr = "%s:%s if %s" % (str(file), str(lineno), str(cond))
+
+               iter = self.model.get_iter_first()
+               while iter != None:
+                       newiter = self.model.iter_next(iter)
+                       #Found a expression which is the same --> remove the breakpoint
+                       if (expr,) == self.model.get(iter,1):
+                               self.debugger.delBreakpoint(no)
+                               return
+                       iter = newiter
+       
+               #Add the entry to the breakpoint list
+               iter = self.model.append()
+               self.model.set(iter, 0, no)     
+               self.model.set(iter, 1, expr)
+
+
+       def addBtnClicked(self, btn):
+
+               if not self.debugger.isActive():
+                       return
+
+
+               bpspec = self.bpEntry.get_text()
+               bpspec = bpspec.strip()
+               rx = re.compile("^[\w/\._\-]+:\d+(\s+if\s+\S+.*)?$")
+
+               #Check if format is correct
+               if not rx.search(bpspec):
+                       dialog = gtk.MessageDialog(None, \
+                               gtk.DIALOG_MODAL | gtk.DIALOG_DESTROY_WITH_PARENT, \
+                               gtk.MESSAGE_ERROR, gtk.BUTTONS_OK, \
+                               "Invalid format!") 
+                       dialog.run()
+                       dialog.destroy()
+                       return
+
+
+               ifsplit = string.split(bpspec, " if ")
+
+               if len(ifsplit)>1:
+                       cond = ifsplit[1].strip()
                else:
-                       self.model.set(iter, 1, "%s:%s if %s" % (str(file), str(lineno), str(cond)))
+                       cond = None
+
+               pos = ifsplit[0].strip()        
+               [file,lineno] = string.split(pos, ":")
+
+               self.addBreakpoint(file, lineno, cond)
+
 
 
 
@@ -168,7 +199,7 @@ class BreakpointsFrame (StatusFrame.StatusFrame):
                selection = self.tv.get_selection()
                model, paths = selection.get_selected_rows()
 
-               for path in paths:
+               for path in reversed(paths):
                        iter = model.get_iter(path)
                        bpno, = self.model.get(iter, 0)
                        self.debugger.delBreakpoint(bpno)
@@ -180,10 +211,10 @@ class BreakpointsFrame (StatusFrame.StatusFrame):
                if not self.debugger.isActive():
                        return
 
-               self.updateValues(None)
+               self.updateValues(None, None)
 
 
-       def updateValues(self, pos):
+       def updateValues(self, status, param):
                
                bpnts = self.debugger.getBreakpoints()