Title: [commits] (alecf) [9520] table code cleanup - consolidate the code that maps table row selection into a set of selection ranges into one function (RowRangeToIndexRange) and clean up code to use it
Hi Alecf:

It looks like your recent revision 9520 broke the functional test TestDeleteCollection

John

-------- Original Message --------
Return-Path: <[EMAIL PROTECTED]>
X-Original-To: [EMAIL PROTECTED]
Delivered-To: [EMAIL PROTECTED]
Received: from leilani.osafoundation.org (leilani.osafoundation.org [127.0.0.1]) by leilani.osafoundation.org (Postfix) with ESMTP id 3B2FE7F6B8; Wed, 15 Feb 2006 08:16:14 -0800 (PST)
X-Original-To: [email protected]
Delivered-To: [email protected]
Received: from laweleka.osafoundation.org (laweleka.osafoundation.org [204.152.186.98]) by leilani.osafoundation.org (Postfix) with ESMTP id DBBBD7F6B8 for <[email protected]>; Wed, 15 Feb 2006 08:16:12 -0800 (PST)
Received: from localhost (localhost [127.0.0.1]) by laweleka.osafoundation.org (Postfix) with ESMTP id CC30E1422A9 for <[email protected]>; Wed, 15 Feb 2006 08:16:12 -0800 (PST)
Received: from laweleka.osafoundation.org ([127.0.0.1]) by localhost (laweleka.osafoundation.org [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id 26372-03 for <[email protected]>; Wed, 15 Feb 2006 08:16:12 -0800 (PST)
Received: from tutu.osafoundation.org (tutu.osafoundation.org [204.152.186.96]) by laweleka.osafoundation.org (Postfix) with ESMTP id 948D81422A8 for <[email protected]>; Wed, 15 Feb 2006 08:16:12 -0800 (PST)
Received: by tutu.osafoundation.org (Postfix, from userid 575) id 7E78AF100D; Wed, 15 Feb 2006 08:16:12 -0800 (PST)
MIME-Version: 1.0
To: [email protected]
Subject: [commits] (alecf) [9520] table code cleanup - consolidate the code that maps table row selection into a set of selection ranges into one function (RowRangeToIndexRange) and clean up code to use it
X-Mailer: SVN::Notify 2.46: http://search.cpan.org/dist/SVN-Notify/
Message-Id: <[EMAIL PROTECTED]>
Date: Wed, 15 Feb 2006 08:16:12 -0800 (PST)
X-Virus-Scanned: by amavisd-new and clamav at osafoundation.org
X-Spam-Status: No, hits=1.4 tagged_above=-50.0 required=4.0 tests=AWL, HTML_40_50, HTML_MESSAGE, MIME_HTML_ONLY, NO_REAL_NAME
X-Spam-Level: *
From: [email protected]
X-BeenThere: [email protected]
X-Mailman-Version: 2.1.5
Precedence: list
Reply-To: [email protected]
List-Id: OSAF Chandler Checkins <commits.osafoundation.org>
List-Unsubscribe: <http://lists.osafoundation.org/mailman/listinfo/commits>, <mailto:[EMAIL PROTECTED]>
List-Archive: <http://lists.osafoundation.org/pipermail/commits>
List-Post: <mailto:[email protected]>
List-Help: <mailto:[EMAIL PROTECTED]>
List-Subscribe: <http://lists.osafoundation.org/mailman/listinfo/commits>, <mailto:[EMAIL PROTECTED]>
Content-Type: multipart/mixed; boundary="===============0412368944=="
Mime-version: 1.0
Sender: [EMAIL PROTECTED]
Errors-To: [EMAIL PROTECTED]


[commits] (alecf) [9520] table code cleanup - consolidate the code that maps table row selection into a set of selection ranges into one function (RowRangeToIndexRange) and clean up code to use it
Revision
9520
Author
alecf
Date
2006-02-15 08:16:10 -0800 (Wed, 15 Feb 2006)

Log Message

table code cleanup - consolidate the code that maps table row selection into a set of selection ranges into one function (RowRangeToIndexRange) and clean up code to use it

Modified Paths

Diff

Modified: trunk/chandler/parcels/osaf/framework/blocks/Table.py (9519 => 9520)

--- trunk/chandler/parcels/osaf/framework/blocks/Table.py	2006-02-15 06:19:26 UTC (rev 9519)
+++ trunk/chandler/parcels/osaf/framework/blocks/Table.py	2006-02-15 16:16:10 UTC (rev 9520)
@@ -199,39 +199,20 @@
             # changes to the selection
             blockItem.stopNotificationDirt()
             try:
-                # Extact the ranges from the grid using the top left
-                # block of the selection and thr bottom right block of
-                # the selection. Then assign the selected ranges to
-                # the content's selection
+                # map row ranges to index ranges 
                 contents = self.blockItem.contents
                 contents.setSelectionRanges ([])
-                topLeftList = self.GetSelectionBlockTopLeft()
-                bottomRightList = self.GetSelectionBlockBottomRight()
-                for ((topLeftRow, topLeftColumn),
-                     (bottomRightRow, bottomRightColumn)) in zip(topLeftList,
-                                                                 bottomRightList):
-                    indexStart = self.RowToIndex(topLeftRow)
-                    indexEnd = self.RowToIndex(bottomRightRow)
+                firstItemIndex = -1
+                for indexStart, indexEnd in self.SelectedIndexRanges():
 
-                    # this is the ugly case where the user "selects" a
-                    # section. It would be nice to avoid this case
-                    # alltogether by making table sections
-                    # un-selectable.
-                    if -1 not in (indexStart, indexEnd):
-                        contents.addSelectionRange ((indexStart, indexEnd))
-               
-                topLeftList.sort()
+                    # We'll need the first selected index later..
+                    if firstItemIndex == -1 or firstItemIndex > indexStart:
+                        firstItemIndex = indexStart
+                        
+                    contents.addSelectionRange ((indexStart, indexEnd))
                 item = None
-                try:
-                    (row, column) = topLeftList [0]
-                except IndexError:
-                    pass
-                else:
-                    itemIndex = self.RowToIndex(row)
-                    if itemIndex != -1:
-                        item = blockItem.contents [itemIndex]
-                    else:
-                        blockItem.PostSelectItems([])
+                if firstItemIndex != -1:
+                    item = blockItem.contents[firstItemIndex]
     
                 if item is not blockItem.selectedItemToView:
                     blockItem.selectedItemToView = item
@@ -448,6 +429,37 @@
         self.blockItem.postEventByName("SelectItemsBroadcast",
                                        {'items':[item]})
 
+    def SelectedIndexRanges(self):
+        """
+        Uses RowRangeToIndexRange to convert the selected rows to
+        selected indexes
+        """
+        # filter out columns from grid selection
+        topLeftList = self.GetSelectionBlockTopLeft()
+        bottomRightList = self.GetSelectionBlockBottomRight()
+        selectedRows = ((row1, row2) for ((row1, col1), (row2, col2)) in
+                zip(topLeftList, bottomRightList))
+        
+        return self.RowRangeToIndexRange(selectedRows)
+
+    def RowRangeToIndexRange(self, rowRanges):
+        """
+        Given a list of row ranges, [(a,b), (c,d), ...], generate
+        corresponding index ranges [(w,x), (y, z),..]
+        """
+        
+        for (topRow, bottomRow) in rowRanges:
+            indexStart = self.RowToIndex(topRow)
+            indexEnd = self.RowToIndex(bottomRow)
+
+            # this is the ugly case where the user "selects" a
+            # section. It would be nice to avoid this case
+            # alltogether by making table sections
+            # un-selectable.
+            if -1 not in (indexStart, indexEnd):
+                yield (indexStart, indexEnd)
+        
+
     def DeleteSelection (self, DeleteItemCallback=None, *args, **kwargs):
         def DefaultCallback(item, collection=self.blockItem.contents):
             collection.remove(item)
@@ -463,14 +475,10 @@
         """
         self.ClearSelection()
         
+        selectionRanges = []
         # build up a list of selection ranges [[tl1, br1], [tl2, br2]]
-        selectionRanges = []
-        for topLeftRow,topLeftColumn in topLeftList:
-            for bottomRightRow,bottomRightColumn in bottomRightList:
-                indexStart = self.RowToIndex(topLeftRow)
-                indexEnd = self.RowToIndex(bottomRightRow)
-                if -1 not in (indexStart, indexEnd):
-                    selectionRanges.append ([indexStart, indexEnd])
+        for indexStart, indexEnd in self.SelectedIndexRanges():
+            selectionRanges.append ([indexStart, indexEnd])
         selectionRanges.sort(reverse=True)
 
         # now delete rows - since we reverse sorted, the



_______________________________________________
Commits mailing list
[email protected]
http://lists.osafoundation.org/mailman/listinfo/commits

_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _

Open Source Applications Foundation "Dev" mailing list
http://lists.osafoundation.org/mailman/listinfo/dev

Reply via email to