From 3c333acd7c2445681a8c11be4446f6331803cba4 Mon Sep 17 00:00:00 2001 From: "James E. Blair" <jeblair@linux.vnet.ibm.com> Date: Mon, 8 Feb 2016 08:03:59 -0800 Subject: [PATCH] Make sorting commands use two two keys And add sort by last seen. As we add more sorting features, they keymap is getting crowded. Since most of the time folks will probably set their preferred sort in the config file, make changing the sort a two-key process. This also lets them be somewhat more intuitive due to reduced collisions. Change-Id: I9e7b23f7036f10525d10268f9b3af8296cabdf69 --- gertty/keymap.py | 8 +++-- gertty/view/change_list.py | 60 +++++++++++++++++++++----------------- 2 files changed, 39 insertions(+), 29 deletions(-) diff --git a/gertty/keymap.py b/gertty/keymap.py index 1731805..c0fe4cb 100644 --- a/gertty/keymap.py +++ b/gertty/keymap.py @@ -65,6 +65,7 @@ EDIT_COMMIT_MESSAGE = 'edit commit message' SUBMIT_CHANGE = 'submit change' SORT_BY_NUMBER = 'sort by number' SORT_BY_UPDATED = 'sort by updated' +SORT_BY_LAST_SEEN = 'sort by last seen' SORT_BY_REVERSE = 'reverse the sort' # Project list screen: TOGGLE_LIST_REVIEWED = 'toggle list reviewed' @@ -128,9 +129,10 @@ DEFAULT_KEYMAP = { EDIT_TOPIC: 'ctrl t', EDIT_COMMIT_MESSAGE: 'ctrl d', SUBMIT_CHANGE: 'ctrl u', - SORT_BY_NUMBER: 'n', - SORT_BY_UPDATED: 'u', - SORT_BY_REVERSE: 'R', + SORT_BY_NUMBER: [['S', 'n']], + SORT_BY_UPDATED: [['S', 'u']], + SORT_BY_LAST_SEEN: [['S', 's']], + SORT_BY_REVERSE: [['S', 'r']], TOGGLE_LIST_REVIEWED: 'l', TOGGLE_LIST_SUBSCRIBED: 'L', diff --git a/gertty/view/change_list.py b/gertty/view/change_list.py index d1d8acb..9aa6ac9 100644 --- a/gertty/view/change_list.py +++ b/gertty/view/change_list.py @@ -434,13 +434,21 @@ class ChangeListView(urwid.WidgetWrap): key = super(ChangeListView, self).keypress(size, key) keys = self.app.input_buffer + [key] commands = self.app.config.keymap.getCommands(keys) + ret = self.handleCommands(commands) + if ret is True: + if keymap.FURTHER_INPUT not in commands: + self.app.clearInputBuffer() + return None + return key + + def handleCommands(self, commands): if keymap.TOGGLE_LIST_REVIEWED in commands: self.unreviewed = not self.unreviewed self.refresh() - return None + return True if keymap.TOGGLE_REVIEWED in commands: if not len(self.listbox.body): - return None + return True pos = self.listbox.focus_position change_key = self.listbox.body[pos].change_key reviewed = self.toggleReviewed(change_key) @@ -457,10 +465,10 @@ class ChangeListView(urwid.WidgetWrap): # changes. self.refresh() self.advance() - return None + return True if keymap.TOGGLE_HIDDEN in commands: if not len(self.listbox.body): - return None + return True pos = self.listbox.focus_position change_key = self.listbox.body[pos].change_key hidden = self.toggleHidden(change_key) @@ -475,10 +483,10 @@ class ChangeListView(urwid.WidgetWrap): # where we're not just popping a row from the list of changes. self.refresh() self.advance() - return None + return True if keymap.TOGGLE_HELD in commands: if not len(self.listbox.body): - return None + return True pos = self.listbox.focus_position change_key = self.listbox.body[pos].change_key self.toggleHeld(change_key) @@ -487,10 +495,10 @@ class ChangeListView(urwid.WidgetWrap): change = session.getChange(change_key) row.update(change, self.categories) self.advance() - return None + return True if keymap.TOGGLE_STARRED in commands: if not len(self.listbox.body): - return None + return True pos = self.listbox.focus_position change_key = self.listbox.body[pos].change_key self.toggleStarred(change_key) @@ -499,10 +507,10 @@ class ChangeListView(urwid.WidgetWrap): change = session.getChange(change_key) row.update(change, self.categories) self.advance() - return None + return True if keymap.TOGGLE_MARK in commands: if not len(self.listbox.body): - return None + return True pos = self.listbox.focus_position change_key = self.listbox.body[pos].change_key row = self.change_rows[change_key] @@ -511,10 +519,10 @@ class ChangeListView(urwid.WidgetWrap): change = session.getChange(change_key) row.update(change, self.categories) self.advance() - return None + return True if keymap.EDIT_TOPIC in commands: self.editTopic() - return None + return True if keymap.REFRESH in commands: if self.project_key: self.app.sync.submitTask( @@ -523,57 +531,57 @@ class ChangeListView(urwid.WidgetWrap): self.app.sync.submitTask( sync.SyncSubscribedProjectsTask(sync.HIGH_PRIORITY)) self.app.status.update() - return None + return True if keymap.REVIEW in commands: rows = [row for row in self.change_rows.values() if row.mark] if not rows: pos = self.listbox.focus_position rows = [self.listbox.body[pos]] self.openReview(rows) - return None + return True if keymap.SORT_BY_NUMBER in commands: if not len(self.listbox.body): - return None + return True self.sort_by = 'number' self.clearChangeList() self.refresh() - return None + return True if keymap.SORT_BY_UPDATED in commands: if not len(self.listbox.body): - return None + return True self.sort_by = 'updated' self.clearChangeList() self.refresh() - return None + return True if keymap.SORT_BY_REVERSE in commands: if not len(self.listbox.body): - return None + return True if self.reverse: self.reverse = False else: self.reverse = True self.clearChangeList() self.refresh() - return None + return True if keymap.LOCAL_CHECKOUT in commands: if not len(self.listbox.body): - return None + return True pos = self.listbox.focus_position row = self.listbox.body[pos] self.app.localCheckoutCommit(row.project_name, row.commit_sha) - return None + return True if keymap.LOCAL_CHERRY_PICK in commands: if not len(self.listbox.body): - return None + return True pos = self.listbox.focus_position row = self.listbox.body[pos] self.app.localCherryPickCommit(row.project_name, row.commit_sha) - return None + return True if keymap.REFINE_CHANGE_SEARCH in commands: default = self.getQueryString() self.app.searchDialog(default) - return None - return key + return True + return False def onSelect(self, button, change_key): try: