From b0f595b1c1c4181933929183353a17767517ae2e Mon Sep 17 00:00:00 2001
From: "James E. Blair" <jeblair@us.ibm.com>
Date: Tue, 20 Oct 2015 14:55:25 -0700
Subject: [PATCH] Separate search and refine search commands

Being able to refine a search query is useful, but so is being able
to quickly open a specific change from anywhere.  Separate these
commands.  C-o opens a blank search input; M-o opens a search input
pre-filled with th ecurrent query in list view.

Change-Id: I49d0f076354322a2652de515d476548926a99182
---
 gertty/app.py              | 6 +-----
 gertty/keymap.py           | 2 ++
 gertty/view/change_list.py | 6 ++++++
 3 files changed, 9 insertions(+), 5 deletions(-)

diff --git a/gertty/app.py b/gertty/app.py
index 3da1c2b..60e5925 100644
--- a/gertty/app.py
+++ b/gertty/app.py
@@ -515,11 +515,7 @@ class App(object):
         elif keymap.QUIT in commands:
             self.quit()
         elif keymap.CHANGE_SEARCH in commands:
-            if hasattr(self.loop.widget, 'getQueryString'):
-                default = self.loop.widget.getQueryString()
-            else:
-                default = ''
-            self.searchDialog(default)
+            self.searchDialog('')
         elif keymap.LIST_HELD in commands:
             self.doSearch("is:held")
         elif key in self.config.dashboards:
diff --git a/gertty/keymap.py b/gertty/keymap.py
index c5f0401..1d770a5 100644
--- a/gertty/keymap.py
+++ b/gertty/keymap.py
@@ -35,6 +35,7 @@ TOP_SCREEN = 'top screen'
 HELP = 'help'
 QUIT = 'quit'
 CHANGE_SEARCH = 'change search'
+REFINE_CHANGE_SEARCH = 'refine change search'
 LIST_HELD = 'list held changes'
 # Change screen:
 TOGGLE_REVIEWED = 'toggle reviewed'
@@ -87,6 +88,7 @@ DEFAULT_KEYMAP = {
     HELP: ['f1', '?'],
     QUIT: 'ctrl q',
     CHANGE_SEARCH: 'ctrl o',
+    REFINE_CHANGE_SEARCH: 'meta o',
     LIST_HELD: 'f12',
 
     TOGGLE_REVIEWED: 'v',
diff --git a/gertty/view/change_list.py b/gertty/view/change_list.py
index f1012da..38a1ef8 100644
--- a/gertty/view/change_list.py
+++ b/gertty/view/change_list.py
@@ -178,6 +178,8 @@ class ChangeListView(urwid.WidgetWrap):
              "Toggle the starred flag for the currently selected change"),
             (key(keymap.TOGGLE_MARK),
              "Toggle the process mark for the currently selected change"),
+            (key(keymap.REFINE_CHANGE_SEARCH),
+             "Refine the current search query"),
             (key(keymap.EDIT_TOPIC),
              "Set the topic of the marked changes"),
             (key(keymap.REFRESH),
@@ -559,6 +561,10 @@ class ChangeListView(urwid.WidgetWrap):
             row = self.listbox.body[pos]
             self.app.localCherryPickCommit(row.project_name, row.commit_sha)
             return None
+        if keymap.REFINE_CHANGE_SEARCH in commands:
+            default = self.getQueryString()
+            self.app.searchDialog(default)
+            return None
         return key
 
     def onSelect(self, button, change_key):