diff --git a/gertty/mywid.py b/gertty/mywid.py index 7b8492e..e81e0b4 100644 --- a/gertty/mywid.py +++ b/gertty/mywid.py @@ -28,8 +28,8 @@ class TextButton(urwid.Button): def __init__(self, text, on_press=None, user_data=None): super(TextButton, self).__init__('', on_press=on_press, user_data=user_data) - text = urwid.Text(text) - self._w = urwid.AttrMap(text, None, focus_map='focused') + self.text = urwid.Text(text) + self._w = urwid.AttrMap(self.text, None, focus_map='focused') class FixedButton(urwid.Button): def sizing(self): diff --git a/gertty/view/change.py b/gertty/view/change.py index f669b99..44102ca 100644 --- a/gertty/view/change.py +++ b/gertty/view/change.py @@ -161,13 +161,7 @@ class RevisionRow(urwid.WidgetWrap): self.revision_key = revision.key self.project_name = revision.change.project.name self.commit_sha = revision.commit - line = [('revision-name', 'Patch Set %s ' % revision.number), - ('revision-commit', revision.commit)] - if len(revision.pending_comments): - line.append(('revision-drafts', ' (%s drafts)' % len(revision.pending_comments))) - if len(revision.comments): - line.append(('revision-comments', ' (%s inline comments)' % len(revision.comments))) - self.title = mywid.TextButton(line, on_press = self.expandContract) + self.title = mywid.TextButton(u'', on_press = self.expandContract) stats = repo.diffstat(revision.parent, revision.commit) rows = [] total_added = 0 @@ -191,7 +185,6 @@ class RevisionRow(urwid.WidgetWrap): ])) table = urwid.Pile(rows) - focus_map={'revision-button': 'focused-revision-button'} self.review_button = ReviewButton(self) buttons = [self.review_button, @@ -206,9 +199,23 @@ class RevisionRow(urwid.WidgetWrap): self.pile = urwid.Pile([self.title]) self._w = urwid.AttrMap(self.pile, None, focus_map=self.revision_focus_map) self.expanded = False + self.update(revision) if expanded: self.expandContract(None) + def update(self, revision): + line = [('revision-name', 'Patch Set %s ' % revision.number), + ('revision-commit', revision.commit)] + num_drafts = len(revision.pending_comments) + if num_drafts: + line.append(('revision-drafts', ' (%s draft%s)' % ( + num_drafts, num_drafts>1 and 's' or ''))) + num_comments = len(revision.comments) - num_drafts + if num_comments: + line.append(('revision-comments', ' (%s inline comment%s)' % ( + num_comments, num_comments>1 and 's' or ''))) + self.title.text.set_text(line) + def expandContract(self, button): if self.expanded: self.pile.contents.pop() @@ -366,6 +373,7 @@ This Screen expanded=(revno==len(change.revisions)-1)) self.listbox.body.insert(listbox_index, row) self.revision_rows[revision.key] = row + row.update(revision) # Revisions are extremely unlikely to be deleted, skip # that case. listbox_index += 1 diff --git a/gertty/view/diff.py b/gertty/view/diff.py index dc919a7..5df436b 100644 --- a/gertty/view/diff.py +++ b/gertty/view/diff.py @@ -320,7 +320,8 @@ This Screen old_focus = self.listbox.focus r = super(DiffView, self).keypress(size, key) new_focus = self.listbox.focus - if old_focus != new_focus and isinstance(old_focus, DiffCommentEdit): + if (isinstance(old_focus, DiffCommentEdit) and + (old_focus != new_focus or key == 'esc')): self.cleanupEdit(old_focus) return r