Kiln » TortoiseHg » TortoiseHg
Clone URL:  
Pushed to one repository · View In Graph Contained in 2.0, 2.0.1, and 2.0.2

stable status: improve sort by status (sort in S, M, A, R, !, ?, C, I order) (refs #61)

This almost closes #61 but I think it does not because we would also need to
make this sort method the default.

Changeset 37bb954d6916

Parent 9f0afb1d2669

by Angel Ezquerra

Changes to one file · Browse files at 37bb954d6916 Showing diff from parent 9f0afb1d2669 Diff from another changeset...

 
612
613
614
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
615
616
617
 
 
 
 
 
 
 
 
 
 
618
619
620
 
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
@@ -612,9 +612,35 @@
    def sort(self, col, order):   self.layoutAboutToBeChanged.emit() + + def getStatusRank(value): + """Helper function used to sort items according to their hg status + + Statuses are ranked in the following order: + 'S','M','A','R','!','?','C','I' + """ + sortList = ('S','M','A','R','!','?','C','I') + + try: + rank = sortList.index(value) + except IndexError, e: + rank = len(shortList) + + return rank +   if col == COL_PATH:   c = self.checked   self.rows.sort(lambda x, y: cmp(c[x[col]], c[y[col]])) + elif col == COL_STATUS: + # We want to sort the list by status, and then, for files which have + # the same status, we want them to be sorted alphabetically (without + # taking into account the case) + # Since since Python 2.3 the sort function is guaranteed to be + # stable, we can do that by sorting in two passes (first sort by + # path and then by status) + self.rows.sort(lambda x, y: \ + cmp(x[COL_PATH].lower(), y[COL_PATH].lower())) + self.rows.sort(key=lambda x: getStatusRank(x[col]))   else:   self.rows.sort(lambda x, y: cmp(x[col], y[col]))   if order == Qt.DescendingOrder: