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
This commit is contained in:
James E. Blair 2014-05-05 11:32:45 -07:00
parent 29e947f8d6
commit 1b9094ab7d
3 changed files with 20 additions and 11 deletions

View File

@ -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):

View File

@ -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

View File

@ -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