]> git.cworth.org Git - sup/commitdiff
refine search by pressing '.' in search-results-mode, thanks to christopher warrington
authorwmorgan <wmorgan@5c8cc53c-5e98-4d25-b20a-d8db53a31250>
Fri, 2 Nov 2007 04:11:36 +0000 (04:11 +0000)
committerwmorgan <wmorgan@5c8cc53c-5e98-4d25-b20a-d8db53a31250>
Fri, 2 Nov 2007 04:11:36 +0000 (04:11 +0000)
git-svn-id: svn://rubyforge.org/var/svn/sup/trunk@659 5c8cc53c-5e98-4d25-b20a-d8db53a31250

bin/sup
lib/sup/modes/search-results-mode.rb

diff --git a/bin/sup b/bin/sup
index 106ea0ef8b8a18710fc0ea9c317c75e4982656bf..6eabf56a9ea044be72022f3925fa6c867a5e34f4 100644 (file)
--- a/bin/sup
+++ b/bin/sup
@@ -218,19 +218,7 @@ begin
         b = bm.spawn_unless_exists("Contact List") { ContactListMode.new }
         b.mode.load_in_background
       when :search
-        text = bm.ask :search, "query: "
-        next unless text && text !~ /^\s*$/
-
-        begin
-          qobj = Index.parse_user_query_string text
-          short_text = text.length < 20 ? text : text[0 ... 20] + "..."
-          log "built query from #{text.inspect}: #{qobj}"
-          mode = SearchResultsMode.new qobj
-          bm.spawn "search: \"#{short_text}\"", mode
-          mode.load_threads :num => mode.buffer.content_height
-        rescue Ferret::QueryParser::QueryParseException => e
-          bm.flash "Couldn't parse query."
-        end
+        SearchResultsMode.spawn_by_query
       when :list_labels
         labels = LabelManager.listable_labels.map { |l| LabelManager.string_for l }
         user_label = bm.ask_with_completions :label, "Show threads with label (enter for listing): ", labels
index 73e98090f1302fc87464b8728550cc94b72c2528..6f0da2f101fa3f9a14a0ca0aa2cff698ec95ab9b 100644 (file)
@@ -6,12 +6,34 @@ class SearchResultsMode < ThreadIndexMode
     super [], { :qobj => @qobj }
   end
 
+  register_keymap do |k|
+    k.add :refine_search, "Refine search", '.'
+  end
+
+  def refine_search
+    SearchResultsMode.spawn_by_query(@qobj.to_s + " ")
+  end
+
   ## a proper is_relevant? method requires some way of asking ferret
   ## if an in-memory object satisfies a query. i'm not sure how to do
   ## that yet. in the worst case i can make an in-memory index, add
   ## the message, and search against it to see if i have > 0 results,
   ## but that seems pretty insane.
 
+  def self.spawn_by_query default=""
+    text = BufferManager.ask :search, "query: ", default
+    return unless text && text !~ /^\s*$/
+
+    begin
+      qobj = Index.parse_user_query_string text
+      short_text = text.length < 20 ? text : text[0 ... 20] + "..."
+      mode = SearchResultsMode.new qobj
+      BufferManager.spawn "search: \"#{short_text}\"", mode
+      mode.load_threads :num => mode.buffer.content_height
+    rescue Ferret::QueryParser::QueryParseException => e
+      BufferManager.flash "Couldn't parse query."
+    end
+  end
 end
 
 end