comparison hgext/histedit.py @ 48214:1895027c5051

chistedit: remove some local variable and access state on self instead Now that we've replaced the state dict by a class, some of the local variables that just do `foo = self.foo` seem unnecessary. Differential Revision: https://phab.mercurial-scm.org/D11652
author Martin von Zweigbergk <martinvonz@google.com>
date Tue, 12 Oct 2021 14:28:51 -0700
parents 1302905b2d49
children d8cff8564f5a
comparison
equal deleted inserted replaced
48213:1302905b2d49 48214:1895027c5051
1254 } 1254 }
1255 1255
1256 def render_commit(self, win): 1256 def render_commit(self, win):
1257 """Renders the commit window that shows the log of the current selected 1257 """Renders the commit window that shows the log of the current selected
1258 commit""" 1258 commit"""
1259 pos = self.pos 1259 rule = self.rules[self.pos]
1260 rules = self.rules
1261 rule = rules[pos]
1262 1260
1263 ctx = rule.ctx 1261 ctx = rule.ctx
1264 win.box() 1262 win.box()
1265 1263
1266 maxy, maxx = win.getmaxyx() 1264 maxy, maxx = win.getmaxyx()
1343 b'help': (helplen, maxx), 1341 b'help': (helplen, maxx),
1344 b'main': (mainlen, maxx), 1342 b'main': (mainlen, maxx),
1345 } 1343 }
1346 1344
1347 def render_rules(self, rulesscr): 1345 def render_rules(self, rulesscr):
1348 rules = self.rules
1349 pos = self.pos
1350 selected = self.selected
1351 start = self.modes[MODE_RULES][b'line_offset'] 1346 start = self.modes[MODE_RULES][b'line_offset']
1352 1347
1353 conflicts = [r.ctx for r in rules if r.conflicts] 1348 conflicts = [r.ctx for r in self.rules if r.conflicts]
1354 if len(conflicts) > 0: 1349 if len(conflicts) > 0:
1355 line = b"potential conflict in %s" % b','.join( 1350 line = b"potential conflict in %s" % b','.join(
1356 map(pycompat.bytestr, conflicts) 1351 map(pycompat.bytestr, conflicts)
1357 ) 1352 )
1358 addln(rulesscr, -1, 0, line, curses.color_pair(COLOR_WARN)) 1353 addln(rulesscr, -1, 0, line, curses.color_pair(COLOR_WARN))
1359 1354
1360 for y, rule in enumerate(rules[start:]): 1355 for y, rule in enumerate(self.rules[start:]):
1361 if y >= self.page_height: 1356 if y >= self.page_height:
1362 break 1357 break
1363 if len(rule.conflicts) > 0: 1358 if len(rule.conflicts) > 0:
1364 rulesscr.addstr(y, 0, b" ", curses.color_pair(COLOR_WARN)) 1359 rulesscr.addstr(y, 0, b" ", curses.color_pair(COLOR_WARN))
1365 else: 1360 else:
1366 rulesscr.addstr(y, 0, b" ", curses.COLOR_BLACK) 1361 rulesscr.addstr(y, 0, b" ", curses.COLOR_BLACK)
1367 1362
1368 if y + start == selected: 1363 if y + start == self.selected:
1369 rollcolor = COLOR_ROLL_SELECTED 1364 rollcolor = COLOR_ROLL_SELECTED
1370 addln(rulesscr, y, 2, rule, curses.color_pair(COLOR_SELECTED)) 1365 addln(rulesscr, y, 2, rule, curses.color_pair(COLOR_SELECTED))
1371 elif y + start == pos: 1366 elif y + start == self.pos:
1372 rollcolor = COLOR_ROLL_CURRENT 1367 rollcolor = COLOR_ROLL_CURRENT
1373 addln( 1368 addln(
1374 rulesscr, 1369 rulesscr,
1375 y, 1370 y,
1376 2, 1371 2,
1422 """Change state based on the current character input 1417 """Change state based on the current character input
1423 1418
1424 This takes the current state and based on the current character input from 1419 This takes the current state and based on the current character input from
1425 the user we change the state. 1420 the user we change the state.
1426 """ 1421 """
1427 selected = self.selected
1428 oldpos = self.pos 1422 oldpos = self.pos
1429 rules = self.rules
1430 1423
1431 if ch in (curses.KEY_RESIZE, b"KEY_RESIZE"): 1424 if ch in (curses.KEY_RESIZE, b"KEY_RESIZE"):
1432 return E_RESIZE 1425 return E_RESIZE
1433 1426
1434 lookup_ch = ch 1427 lookup_ch = ch
1440 lookup_ch, KEYTABLE[b'global'].get(lookup_ch) 1433 lookup_ch, KEYTABLE[b'global'].get(lookup_ch)
1441 ) 1434 )
1442 if action is None: 1435 if action is None:
1443 return 1436 return
1444 if action in (b'down', b'move-down'): 1437 if action in (b'down', b'move-down'):
1445 newpos = min(oldpos + 1, len(rules) - 1) 1438 newpos = min(oldpos + 1, len(self.rules) - 1)
1446 self.move_cursor(oldpos, newpos) 1439 self.move_cursor(oldpos, newpos)
1447 if selected is not None or action == b'move-down': 1440 if self.selected is not None or action == b'move-down':
1448 self.swap(oldpos, newpos) 1441 self.swap(oldpos, newpos)
1449 elif action in (b'up', b'move-up'): 1442 elif action in (b'up', b'move-up'):
1450 newpos = max(0, oldpos - 1) 1443 newpos = max(0, oldpos - 1)
1451 self.move_cursor(oldpos, newpos) 1444 self.move_cursor(oldpos, newpos)
1452 if selected is not None or action == b'move-up': 1445 if self.selected is not None or action == b'move-up':
1453 self.swap(oldpos, newpos) 1446 self.swap(oldpos, newpos)
1454 elif action == b'next-action': 1447 elif action == b'next-action':
1455 self.cycle_action(oldpos, next=True) 1448 self.cycle_action(oldpos, next=True)
1456 elif action == b'prev-action': 1449 elif action == b'prev-action':
1457 self.cycle_action(oldpos, next=False) 1450 self.cycle_action(oldpos, next=False)
1458 elif action == b'select': 1451 elif action == b'select':
1459 selected = oldpos if selected is None else None 1452 self.selected = oldpos if self.selected is None else None
1460 self.make_selection(selected) 1453 self.make_selection(self.selected)
1461 elif action == b'goto' and int(ch) < len(rules) and len(rules) <= 10: 1454 elif action == b'goto' and int(ch) < len(self.rules) <= 10:
1462 newrule = next((r for r in rules if r.origpos == int(ch))) 1455 newrule = next((r for r in self.rules if r.origpos == int(ch)))
1463 self.move_cursor(oldpos, newrule.pos) 1456 self.move_cursor(oldpos, newrule.pos)
1464 if selected is not None: 1457 if self.selected is not None:
1465 self.swap(oldpos, newrule.pos) 1458 self.swap(oldpos, newrule.pos)
1466 elif action.startswith(b'action-'): 1459 elif action.startswith(b'action-'):
1467 self.change_action(oldpos, action[7:]) 1460 self.change_action(oldpos, action[7:])
1468 elif action == b'showpatch': 1461 elif action == b'showpatch':
1469 self.change_mode(MODE_PATCH if curmode != MODE_PATCH else prevmode) 1462 self.change_mode(MODE_PATCH if curmode != MODE_PATCH else prevmode)
1547 if self.selected: 1540 if self.selected:
1548 self.make_selection(newpos) 1541 self.make_selection(newpos)
1549 1542
1550 def change_action(self, pos, action): 1543 def change_action(self, pos, action):
1551 """Change the action state on the given position to the new action""" 1544 """Change the action state on the given position to the new action"""
1552 rules = self.rules 1545 assert 0 <= pos < len(self.rules)
1553 assert 0 <= pos < len(rules) 1546 self.rules[pos].action = action
1554 rules[pos].action = action
1555 1547
1556 def cycle_action(self, pos, next=False): 1548 def cycle_action(self, pos, next=False):
1557 """Changes the action state the next or the previous action from 1549 """Changes the action state the next or the previous action from
1558 the action list""" 1550 the action list"""
1559 rules = self.rules 1551 assert 0 <= pos < len(self.rules)
1560 assert 0 <= pos < len(rules) 1552 current = self.rules[pos].action
1561 current = rules[pos].action
1562 1553
1563 assert current in KEY_LIST 1554 assert current in KEY_LIST
1564 1555
1565 index = KEY_LIST.index(current) 1556 index = KEY_LIST.index(current)
1566 if next: 1557 if next: