From 1b9094ab7dff39c36c0d2383bb31b8605d4848a7 Mon Sep 17 00:00:00 2001 From: "James E. Blair" Date: Mon, 5 May 2014 11:32:45 -0700 Subject: [PATCH] Fix comment handling when exiting diff view Make sure that the revision row is updated with the current comment count when after leaving the diff view. Also, don't include draft comments in the comment count (they are displayed separately). When exiting the diff view with the esc key while inside of a comment box, be sure to save that comment before leaving. Change-Id: I16fe96dc37101d97317b19fdcc38be6729bed551 --- gertty/mywid.py | 4 ++-- gertty/view/change.py | 24 ++++++++++++++++-------- gertty/view/diff.py | 3 ++- 3 files changed, 20 insertions(+), 11 deletions(-) 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