109 raise NotImplementedError("method must be implemented by subclass") |
109 raise NotImplementedError("method must be implemented by subclass") |
110 |
110 |
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, constrainlevel=True, skipfolded=True): |
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. |
118 |
119 |
119 If skipfolded == True, and the current item is folded, then the child |
120 If constrainLevel == False, then try to return the next item |
|
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 |
128 If it is not possible to get the next item, return None. |
123 If it is not possible to get the next item, return None. |
129 """ |
124 """ |
130 try: |
125 try: |
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: |
140 nextitem = self.parentitem().nextsibling() |
133 nextitem = self.parentitem().nextsibling() |
141 except AttributeError: |
134 except AttributeError: |
162 return self.parentitem().parentitem().nextsibling() |
155 return self.parentitem().parentitem().nextsibling() |
163 |
156 |
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, constrainlevel=True): |
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 # else try previous sibling's last child, else try previous sibling |
171 prevsiblinglastchild = prevsibling.lastchild() |
184 prevsibling = self.prevsibling() |
172 if ((prevsiblinglastchild is not None) and |
185 if prevsibling is not None: |
173 not prevsibling.folded): |
186 prevsiblinglastchild = prevsibling.lastchild() |
174 prevsiblinglclc = prevsiblinglastchild.lastchild() |
187 if ((prevsiblinglastchild is not None) and |
175 if ((prevsiblinglclc is not None) and |
188 not prevsibling.folded): |
176 not prevsiblinglastchild.folded): |
189 prevsiblinglclc = prevsiblinglastchild.lastchild() |
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 |
197 |
180 else: |
198 # try parent (or None) |
181 return prevsibling |
199 return self.parentitem() |
182 |
|
183 # try parent (or None) |
|
184 return self.parentitem() |
200 |
185 |
201 class patch(patchnode, list): # todo: rename patchroot |
186 class patch(patchnode, list): # todo: rename patchroot |
202 """ |
187 """ |
203 list of header objects representing the patch. |
188 list of header objects representing the patch. |
204 """ |
189 """ |
601 the first hunkline of a hunk is currently selected, then select the |
586 the first hunkline of a hunk is currently selected, then select the |
602 hunk itself. |
587 hunk itself. |
603 """ |
588 """ |
604 currentitem = self.currentselecteditem |
589 currentitem = self.currentselecteditem |
605 |
590 |
606 nextitem = currentitem.previtem(constrainlevel=False) |
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 |
610 # no change... |
595 # no change... |
611 nextitem = currentitem |
596 nextitem = currentitem |
617 select (if possible) the previous item on the same level as the |
602 select (if possible) the previous item on the same level as the |
618 currently selected item. otherwise, select (if possible) the |
603 currently selected item. otherwise, select (if possible) the |
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.previtem() |
607 nextitem = currentitem.prevsibling() |
623 # if there's no previous item on this level, try choosing the parent |
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: |
627 # if no parent item (i.e. currentitem is the first header), then |
612 # if no parent item (i.e. currentitem is the first header), then |
628 # no change... |
613 # no change... |
639 or if not, the next header if one exists. |
624 or if not, the next header if one exists. |
640 """ |
625 """ |
641 #self.startprintline += 1 #debug |
626 #self.startprintline += 1 #debug |
642 currentitem = self.currentselecteditem |
627 currentitem = self.currentselecteditem |
643 |
628 |
644 nextitem = currentitem.nextitem(constrainlevel=False) |
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 |
648 |
633 |
649 self.currentselecteditem = nextitem |
634 self.currentselecteditem = nextitem |
653 select (if possible) the next item on the same level as the currently |
638 select (if possible) the next item on the same level as the currently |
654 selected item. otherwise, select (if possible) the next item on the |
639 selected item. otherwise, select (if possible) the next item on the |
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.nextitem() |
643 nextitem = currentitem.nextsibling() |
659 # if there's no next item on this level, try choosing the parent's |
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().nextitem() |
647 nextitem = currentitem.parentitem().nextsibling() |
664 except AttributeError: |
648 except AttributeError: |
665 # parentitem returned None, so nextitem() can't be called |
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 item on parent-level, then no change... |
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 |
672 |
656 |
673 def rightarrowevent(self): |
657 def rightarrowevent(self): |