100 |
100 |
101 def lastchild(self): |
101 def lastchild(self): |
102 raise NotImplementedError(b"method must be implemented by subclass") |
102 raise NotImplementedError(b"method must be implemented by subclass") |
103 |
103 |
104 def allchildren(self): |
104 def allchildren(self): |
105 b"Return a list of all of the direct children of this node" |
105 """Return a list of all of the direct children of this node""" |
106 raise NotImplementedError(b"method must be implemented by subclass") |
106 raise NotImplementedError(b"method must be implemented by subclass") |
107 |
107 |
108 def nextsibling(self): |
108 def nextsibling(self): |
109 """ |
109 """ |
110 Return the closest next item of the same type where there are no items |
110 Return the closest next item of the same type where there are no items |
262 so return None. |
262 so return None. |
263 """ |
263 """ |
264 return None |
264 return None |
265 |
265 |
266 def firstchild(self): |
266 def firstchild(self): |
267 b"return the first child of this item, if one exists. otherwise None." |
267 """return the first child of this item, if one exists. otherwise |
|
268 None.""" |
268 if len(self.hunks) > 0: |
269 if len(self.hunks) > 0: |
269 return self.hunks[0] |
270 return self.hunks[0] |
270 else: |
271 else: |
271 return None |
272 return None |
272 |
273 |
273 def lastchild(self): |
274 def lastchild(self): |
274 b"return the last child of this item, if one exists. otherwise None." |
275 """return the last child of this item, if one exists. otherwise |
|
276 None.""" |
275 if len(self.hunks) > 0: |
277 if len(self.hunks) > 0: |
276 return self.hunks[-1] |
278 return self.hunks[-1] |
277 else: |
279 else: |
278 return None |
280 return None |
279 |
281 |
280 def allchildren(self): |
282 def allchildren(self): |
281 b"return a list of all of the direct children of this node" |
283 """return a list of all of the direct children of this node""" |
282 return self.hunks |
284 return self.hunks |
283 |
285 |
284 def __getattr__(self, name): |
286 def __getattr__(self, name): |
285 return getattr(self.nonuiheader, name) |
287 return getattr(self.nonuiheader, name) |
286 |
288 |
287 |
289 |
288 class uihunkline(patchnode): |
290 class uihunkline(patchnode): |
289 b"represents a changed line in a hunk" |
291 """represents a changed line in a hunk""" |
290 |
292 |
291 def __init__(self, linetext, hunk): |
293 def __init__(self, linetext, hunk): |
292 self.linetext = linetext |
294 self.linetext = linetext |
293 self.applied = True |
295 self.applied = True |
294 # the parent hunk to which this line belongs |
296 # the parent hunk to which this line belongs |
317 return previousline |
319 return previousline |
318 else: |
320 else: |
319 return None |
321 return None |
320 |
322 |
321 def parentitem(self): |
323 def parentitem(self): |
322 b"return the parent to the current item" |
324 """return the parent to the current item""" |
323 return self.hunk |
325 return self.hunk |
324 |
326 |
325 def firstchild(self): |
327 def firstchild(self): |
326 b"return the first child of this item, if one exists. otherwise None." |
328 """return the first child of this item, if one exists. otherwise |
|
329 None.""" |
327 # hunk-lines don't have children |
330 # hunk-lines don't have children |
328 return None |
331 return None |
329 |
332 |
330 def lastchild(self): |
333 def lastchild(self): |
331 b"return the last child of this item, if one exists. otherwise None." |
334 """return the last child of this item, if one exists. otherwise |
|
335 None.""" |
332 # hunk-lines don't have children |
336 # hunk-lines don't have children |
333 return None |
337 return None |
334 |
338 |
335 |
339 |
336 class uihunk(patchnode): |
340 class uihunk(patchnode): |
370 return previoushunk |
374 return previoushunk |
371 else: |
375 else: |
372 return None |
376 return None |
373 |
377 |
374 def parentitem(self): |
378 def parentitem(self): |
375 b"return the parent to the current item" |
379 """return the parent to the current item""" |
376 return self.header |
380 return self.header |
377 |
381 |
378 def firstchild(self): |
382 def firstchild(self): |
379 b"return the first child of this item, if one exists. otherwise None." |
383 """return the first child of this item, if one exists. otherwise |
|
384 None.""" |
380 if len(self.changedlines) > 0: |
385 if len(self.changedlines) > 0: |
381 return self.changedlines[0] |
386 return self.changedlines[0] |
382 else: |
387 else: |
383 return None |
388 return None |
384 |
389 |
385 def lastchild(self): |
390 def lastchild(self): |
386 b"return the last child of this item, if one exists. otherwise None." |
391 """return the last child of this item, if one exists. otherwise |
|
392 None.""" |
387 if len(self.changedlines) > 0: |
393 if len(self.changedlines) > 0: |
388 return self.changedlines[-1] |
394 return self.changedlines[-1] |
389 else: |
395 else: |
390 return None |
396 return None |
391 |
397 |
392 def allchildren(self): |
398 def allchildren(self): |
393 b"return a list of all of the direct children of this node" |
399 """return a list of all of the direct children of this node""" |
394 return self.changedlines |
400 return self.changedlines |
395 |
401 |
396 def countchanges(self): |
402 def countchanges(self): |
397 """changedlines -> (n+,n-)""" |
403 """changedlines -> (n+,n-)""" |
398 add = len( |
404 add = len( |
851 currentitem = nextitem |
857 currentitem = nextitem |
852 |
858 |
853 self.currentselecteditem = currentitem |
859 self.currentselecteditem = currentitem |
854 |
860 |
855 def updatescroll(self): |
861 def updatescroll(self): |
856 b"scroll the screen to fully show the currently-selected" |
862 """scroll the screen to fully show the currently-selected""" |
857 selstart = self.selecteditemstartline |
863 selstart = self.selecteditemstartline |
858 selend = self.selecteditemendline |
864 selend = self.selecteditemendline |
859 |
865 |
860 padstart = self.firstlineofpadtoprint |
866 padstart = self.firstlineofpadtoprint |
861 padend = padstart + self.yscreensize - self.numstatuslines - 1 |
867 padend = padstart + self.yscreensize - self.numstatuslines - 1 |
869 elif selstart < padstartbuffered: |
875 elif selstart < padstartbuffered: |
870 # negative values scroll in pgup direction |
876 # negative values scroll in pgup direction |
871 self.scrolllines(selstart - padstartbuffered) |
877 self.scrolllines(selstart - padstartbuffered) |
872 |
878 |
873 def scrolllines(self, numlines): |
879 def scrolllines(self, numlines): |
874 b"scroll the screen up (down) by numlines when numlines >0 (<0)." |
880 """scroll the screen up (down) by numlines when numlines >0 (<0).""" |
875 self.firstlineofpadtoprint += numlines |
881 self.firstlineofpadtoprint += numlines |
876 if self.firstlineofpadtoprint < 0: |
882 if self.firstlineofpadtoprint < 0: |
877 self.firstlineofpadtoprint = 0 |
883 self.firstlineofpadtoprint = 0 |
878 if self.firstlineofpadtoprint > self.numpadlines - 1: |
884 if self.firstlineofpadtoprint > self.numpadlines - 1: |
879 self.firstlineofpadtoprint = self.numpadlines - 1 |
885 self.firstlineofpadtoprint = self.numpadlines - 1 |
971 item.hunk.header.partial = ( |
977 item.hunk.header.partial = ( |
972 someparentsiblingspartial or not allparentsiblingsapplied |
978 someparentsiblingspartial or not allparentsiblingsapplied |
973 ) |
979 ) |
974 |
980 |
975 def toggleall(self): |
981 def toggleall(self): |
976 b"toggle the applied flag of all items." |
982 """toggle the applied flag of all items.""" |
977 if self.waslasttoggleallapplied: # then unapply them this time |
983 if self.waslasttoggleallapplied: # then unapply them this time |
978 for item in self.headerlist: |
984 for item in self.headerlist: |
979 if item.applied: |
985 if item.applied: |
980 self.toggleapply(item) |
986 self.toggleapply(item) |
981 else: |
987 else: |
983 if not item.applied: |
989 if not item.applied: |
984 self.toggleapply(item) |
990 self.toggleapply(item) |
985 self.waslasttoggleallapplied = not self.waslasttoggleallapplied |
991 self.waslasttoggleallapplied = not self.waslasttoggleallapplied |
986 |
992 |
987 def toggleallbetween(self): |
993 def toggleallbetween(self): |
988 b"toggle applied on or off for all items in range [lastapplied,current]." |
994 """toggle applied on or off for all items in range [lastapplied, |
|
995 current]. """ |
989 if ( |
996 if ( |
990 not self.lastapplieditem |
997 not self.lastapplieditem |
991 or self.currentselecteditem == self.lastapplieditem |
998 or self.currentselecteditem == self.lastapplieditem |
992 ): |
999 ): |
993 # Treat this like a normal 'x'/' ' |
1000 # Treat this like a normal 'x'/' ' |
1024 if nextitem.applied != desiredstate: |
1031 if nextitem.applied != desiredstate: |
1025 self.toggleapply(item=nextitem) |
1032 self.toggleapply(item=nextitem) |
1026 nextitem = nextitem.nextitem() |
1033 nextitem = nextitem.nextitem() |
1027 |
1034 |
1028 def togglefolded(self, item=None, foldparent=False): |
1035 def togglefolded(self, item=None, foldparent=False): |
1029 b"toggle folded flag of specified item (defaults to currently selected)" |
1036 """toggle folded flag of specified item (defaults to currently |
|
1037 selected)""" |
1030 if item is None: |
1038 if item is None: |
1031 item = self.currentselecteditem |
1039 item = self.currentselecteditem |
1032 if foldparent or (isinstance(item, uiheader) and item.neverunfolded): |
1040 if foldparent or (isinstance(item, uiheader) and item.neverunfolded): |
1033 if not isinstance(item, uiheader): |
1041 if not isinstance(item, uiheader): |
1034 # we need to select the parent item in this case |
1042 # we need to select the parent item in this case |
1318 return outstr |
1326 return outstr |
1319 |
1327 |
1320 def printhunklinesbefore( |
1328 def printhunklinesbefore( |
1321 self, hunk, selected=False, towin=True, ignorefolding=False |
1329 self, hunk, selected=False, towin=True, ignorefolding=False |
1322 ): |
1330 ): |
1323 b"includes start/end line indicator" |
1331 """includes start/end line indicator""" |
1324 outstr = b"" |
1332 outstr = b"" |
1325 # where hunk is in list of siblings |
1333 # where hunk is in list of siblings |
1326 hunkindex = hunk.header.hunks.index(hunk) |
1334 hunkindex = hunk.header.hunks.index(hunk) |
1327 |
1335 |
1328 if hunkindex != 0: |
1336 if hunkindex != 0: |
1527 ) |
1535 ) |
1528 numlines = len(patchdisplaystring) // self.xscreensize |
1536 numlines = len(patchdisplaystring) // self.xscreensize |
1529 return numlines |
1537 return numlines |
1530 |
1538 |
1531 def sigwinchhandler(self, n, frame): |
1539 def sigwinchhandler(self, n, frame): |
1532 b"handle window resizing" |
1540 """handle window resizing""" |
1533 try: |
1541 try: |
1534 curses.endwin() |
1542 curses.endwin() |
1535 self.xscreensize, self.yscreensize = scmutil.termsize(self.ui) |
1543 self.xscreensize, self.yscreensize = scmutil.termsize(self.ui) |
1536 self.statuswin.resize(self.numstatuslines, self.xscreensize) |
1544 self.statuswin.resize(self.numstatuslines, self.xscreensize) |
1537 self.numpadlines = self.getnumlinesdisplayed(ignorefolding=True) + 1 |
1545 self.numpadlines = self.getnumlinesdisplayed(ignorefolding=True) + 1 |
1597 if textattrib in attrlist: |
1605 if textattrib in attrlist: |
1598 colorpair |= textattrib |
1606 colorpair |= textattrib |
1599 return colorpair |
1607 return colorpair |
1600 |
1608 |
1601 def initcolorpair(self, *args, **kwargs): |
1609 def initcolorpair(self, *args, **kwargs): |
1602 b"same as getcolorpair." |
1610 """same as getcolorpair.""" |
1603 self.getcolorpair(*args, **kwargs) |
1611 self.getcolorpair(*args, **kwargs) |
1604 |
1612 |
1605 def helpwindow(self): |
1613 def helpwindow(self): |
1606 b"print a help window to the screen. exit after any keypress." |
1614 """print a help window to the screen. exit after any keypress.""" |
1607 helptext = _( |
1615 helptext = _( |
1608 """ [press any key to return to the patch-display] |
1616 """ [press any key to return to the patch-display] |
1609 |
1617 |
1610 crecord allows you to interactively choose among the changes you have made, |
1618 crecord allows you to interactively choose among the changes you have made, |
1611 and confirm only those changes you select for further processing by the command |
1619 and confirm only those changes you select for further processing by the command |
1652 helpwin.getkey() |
1660 helpwin.getkey() |
1653 except curses.error: |
1661 except curses.error: |
1654 pass |
1662 pass |
1655 |
1663 |
1656 def commitMessageWindow(self): |
1664 def commitMessageWindow(self): |
1657 b"Create a temporary commit message editing window on the screen." |
1665 """Create a temporary commit message editing window on the screen.""" |
1658 |
1666 |
1659 curses.raw() |
1667 curses.raw() |
1660 curses.def_prog_mode() |
1668 curses.def_prog_mode() |
1661 curses.endwin() |
1669 curses.endwin() |
1662 self.commenttext = self.ui.edit(self.commenttext, self.ui.username()) |
1670 self.commenttext = self.ui.edit(self.commenttext, self.ui.username()) |
1702 |
1710 |
1703 self.currentselecteditem = currentitem |
1711 self.currentselecteditem = currentitem |
1704 self.recenterdisplayedarea() |
1712 self.recenterdisplayedarea() |
1705 |
1713 |
1706 def confirmationwindow(self, windowtext): |
1714 def confirmationwindow(self, windowtext): |
1707 b"display an informational window, then wait for and return a keypress." |
1715 """display an informational window, then wait for and return a |
|
1716 keypress.""" |
1708 |
1717 |
1709 confirmwin = curses.newwin(self.yscreensize, 0, 0, 0) |
1718 confirmwin = curses.newwin(self.yscreensize, 0, 0, 0) |
1710 try: |
1719 try: |
1711 lines = windowtext.split(b"\n") |
1720 lines = windowtext.split(b"\n") |
1712 for line in lines: |
1721 for line in lines: |