Show More
@@ -111,17 +111,12 b' class patchnode(object):' | |||||
111 | def parentitem(self): |
|
111 | def parentitem(self): | |
112 | raise NotImplementedError("method must be implemented by subclass") |
|
112 | raise NotImplementedError("method must be implemented by subclass") | |
113 |
|
113 | |||
114 |
def nextitem(self, |
|
114 | def nextitem(self, skipfolded=True): | |
115 | """ |
|
115 | """ | |
116 | If constrainLevel == True, return the closest next item |
|
116 | Try to return the next item closest to this item, regardless of item's | |
117 | of the same type where there are no items of different types between |
|
117 | type (header, hunk, or hunkline). | |
118 | the current item and this closest item. |
|
|||
119 |
|
118 | |||
120 | If constrainLevel == False, then try to return the next item |
|
119 | If skipfolded == True, and the current item is folded, then the child | |
121 | closest to this item, regardless of item's type (header, hunk, or |
|
|||
122 | HunkLine). |
|
|||
123 |
|
||||
124 | If skipFolded == True, and the current item is folded, then the child |
|
|||
125 | items that are hidden due to folding will be skipped when determining |
|
120 | items that are hidden due to folding will be skipped when determining | |
126 | the next item. |
|
121 | the next item. | |
127 |
|
122 | |||
@@ -131,9 +126,7 b' class patchnode(object):' | |||||
131 | itemfolded = self.folded |
|
126 | itemfolded = self.folded | |
132 | except AttributeError: |
|
127 | except AttributeError: | |
133 | itemfolded = False |
|
128 | itemfolded = False | |
134 | if constrainlevel: |
|
129 | if skipfolded and itemfolded: | |
135 | return self.nextsibling() |
|
|||
136 | elif skipfolded and itemfolded: |
|
|||
137 | nextitem = self.nextsibling() |
|
130 | nextitem = self.nextsibling() | |
138 | if nextitem is None: |
|
131 | if nextitem is None: | |
139 | try: |
|
132 | try: | |
@@ -164,39 +157,31 b' class patchnode(object):' | |||||
164 | except AttributeError: # parent and/or grandparent was None |
|
157 | except AttributeError: # parent and/or grandparent was None | |
165 | return None |
|
158 | return None | |
166 |
|
159 | |||
167 |
def previtem(self |
|
160 | def previtem(self): | |
168 | """ |
|
161 | """ | |
169 | If constrainLevel == True, return the closest previous item |
|
162 | Try to return the previous item closest to this item, regardless of | |
170 | of the same type where there are no items of different types between |
|
163 | item's type (header, hunk, or hunkline). | |
171 | the current item and this closest item. |
|
|||
172 |
|
||||
173 | If constrainLevel == False, then try to return the previous item |
|
|||
174 | closest to this item, regardless of item's type (header, hunk, or |
|
|||
175 | HunkLine). |
|
|||
176 |
|
164 | |||
177 | If it is not possible to get the previous item, return None. |
|
165 | If it is not possible to get the previous item, return None. | |
178 | """ |
|
166 | """ | |
179 | if constrainlevel: |
|
167 | # try previous sibling's last child's last child, | |
180 | return self.prevsibling() |
|
168 | # else try previous sibling's last child, else try previous sibling | |
181 | else: |
|
169 | prevsibling = self.prevsibling() | |
182 | # try previous sibling's last child's last child, |
|
170 | if prevsibling is not None: | |
183 |
|
|
171 | prevsiblinglastchild = prevsibling.lastchild() | |
184 | prevsibling = self.prevsibling() |
|
172 | if ((prevsiblinglastchild is not None) and | |
185 |
|
|
173 | not prevsibling.folded): | |
186 |
prevsiblingl |
|
174 | prevsiblinglclc = prevsiblinglastchild.lastchild() | |
187 |
if ((prevsiblingl |
|
175 | if ((prevsiblinglclc is not None) and | |
188 | not prevsibling.folded): |
|
176 | not prevsiblinglastchild.folded): | |
189 |
prevsiblinglclc |
|
177 | return prevsiblinglclc | |
190 | if ((prevsiblinglclc is not None) and |
|
|||
191 | not prevsiblinglastchild.folded): |
|
|||
192 | return prevsiblinglclc |
|
|||
193 | else: |
|
|||
194 | return prevsiblinglastchild |
|
|||
195 | else: |
|
178 | else: | |
196 | return prevsibling |
|
179 | return prevsiblinglastchild | |
|
180 | else: | |||
|
181 | return prevsibling | |||
197 |
|
182 | |||
198 |
|
|
183 | # try parent (or None) | |
199 |
|
|
184 | return self.parentitem() | |
200 |
|
185 | |||
201 | class patch(patchnode, list): # todo: rename patchroot |
|
186 | class patch(patchnode, list): # todo: rename patchroot | |
202 | """ |
|
187 | """ | |
@@ -603,7 +588,7 b' class curseschunkselector(object):' | |||||
603 | """ |
|
588 | """ | |
604 | currentitem = self.currentselecteditem |
|
589 | currentitem = self.currentselecteditem | |
605 |
|
590 | |||
606 |
nextitem = currentitem.previtem( |
|
591 | nextitem = currentitem.previtem() | |
607 |
|
592 | |||
608 | if nextitem is None: |
|
593 | if nextitem is None: | |
609 | # if no parent item (i.e. currentitem is the first header), then |
|
594 | # if no parent item (i.e. currentitem is the first header), then | |
@@ -619,8 +604,8 b' class curseschunkselector(object):' | |||||
619 | parent-item of the currently selected item. |
|
604 | parent-item of the currently selected item. | |
620 | """ |
|
605 | """ | |
621 | currentitem = self.currentselecteditem |
|
606 | currentitem = self.currentselecteditem | |
622 |
nextitem = currentitem.prev |
|
607 | nextitem = currentitem.prevsibling() | |
623 |
# if there's no previous |
|
608 | # if there's no previous sibling, try choosing the parent | |
624 | if nextitem is None: |
|
609 | if nextitem is None: | |
625 | nextitem = currentitem.parentitem() |
|
610 | nextitem = currentitem.parentitem() | |
626 | if nextitem is None: |
|
611 | if nextitem is None: | |
@@ -641,7 +626,7 b' class curseschunkselector(object):' | |||||
641 | #self.startprintline += 1 #debug |
|
626 | #self.startprintline += 1 #debug | |
642 | currentitem = self.currentselecteditem |
|
627 | currentitem = self.currentselecteditem | |
643 |
|
628 | |||
644 |
nextitem = currentitem.nextitem( |
|
629 | nextitem = currentitem.nextitem() | |
645 | # if there's no next item, keep the selection as-is |
|
630 | # if there's no next item, keep the selection as-is | |
646 | if nextitem is None: |
|
631 | if nextitem is None: | |
647 | nextitem = currentitem |
|
632 | nextitem = currentitem | |
@@ -655,17 +640,16 b' class curseschunkselector(object):' | |||||
655 | same level as the parent item of the currently selected item. |
|
640 | same level as the parent item of the currently selected item. | |
656 | """ |
|
641 | """ | |
657 | currentitem = self.currentselecteditem |
|
642 | currentitem = self.currentselecteditem | |
658 |
nextitem = currentitem.next |
|
643 | nextitem = currentitem.nextsibling() | |
659 |
# if there's no next |
|
644 | # if there's no next sibling, try choosing the parent's nextsibling | |
660 | # nextitem. |
|
|||
661 | if nextitem is None: |
|
645 | if nextitem is None: | |
662 | try: |
|
646 | try: | |
663 |
nextitem = currentitem.parentitem().next |
|
647 | nextitem = currentitem.parentitem().nextsibling() | |
664 | except AttributeError: |
|
648 | except AttributeError: | |
665 |
# parentitem returned None, so next |
|
649 | # parentitem returned None, so nextsibling() can't be called | |
666 | nextitem = None |
|
650 | nextitem = None | |
667 | if nextitem is None: |
|
651 | if nextitem is None: | |
668 |
# if no next |
|
652 | # if parent has no next sibling, then no change... | |
669 | nextitem = currentitem |
|
653 | nextitem = currentitem | |
670 |
|
654 | |||
671 | self.currentselecteditem = nextitem |
|
655 | self.currentselecteditem = nextitem |
General Comments 0
You need to be logged in to leave comments.
Login now