Class: Redwood::SearchResultsMode

Inherits:
ThreadIndexMode show all
Defined in:
lib/sup/modes/search_results_mode.rb

Constant Summary

Constants inherited from ThreadIndexMode

ThreadIndexMode::DATE_WIDTH, ThreadIndexMode::LOAD_MORE_THREAD_NUM, ThreadIndexMode::MIN_FROM_WIDTH

Instance Attribute Summary

Attributes inherited from LineCursorMode

#curpos

Attributes inherited from ScrollMode

#botline, #leftcol, #status, #topline

Attributes inherited from Mode

#buffer

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from ThreadIndexMode

#[], #actually_toggle_archived, #actually_toggle_deleted, #actually_toggle_spammed, #actually_toggle_starred, #apply_to_tagged, #cancel_search, #cleanup, #contains_thread?, #edit_labels, #edit_message, #flush_index, #forward, #handle_added_update, #handle_deleted_update, #handle_killed_update, #handle_labeled_update, #handle_location_deleted_update, #handle_simple_update, #handle_single_message_deleted_update, #handle_single_message_labeled_update, #handle_spammed_update, #handle_undeleted_update, #handle_unkilled_update, #handle_updated_update, #is_relevant?, #join_threads, #jump_to_next_new, #kill, #launch_another_thread, #launch_next_thread_after, #launch_prev_thread_before, #lines, #load_all_threads, #load_n_threads, #load_n_threads_background, #load_threads, #multi_edit_labels, #multi_join_threads, #multi_kill, #multi_read_and_archive, #multi_select, #multi_toggle_archived, #multi_toggle_deleted, #multi_toggle_new, #multi_toggle_spam, #multi_toggle_starred, #multi_toggle_tagged, #read_and_archive, #reload, #reply, #reply_all, #resize, #select, #status, #tag_matching, #toggle_archived, #toggle_deleted, #toggle_new, #toggle_spam, #toggle_starred, #toggle_tagged, #toggle_tagged_all, #undo, #unsaved?, #update

Methods inherited from LineCursorMode

#cleanup, #draw

Methods inherited from ScrollMode

#at_bottom?, #at_top?, #cancel_search!, #col_jump, #col_left, #col_right, #continue_search_in_buffer, #draw, #ensure_mode_validity, #half_page_down, #half_page_up, #in_search?, #jump_to_col, #jump_to_end, #jump_to_left, #jump_to_line, #jump_to_start, #line_down, #line_up, #page_down, #page_up, #resize, #rightcol, #search_goto_line, #search_goto_pos, #search_in_buffer, #search_start_line

Methods inherited from Mode

#blur, #cancel_search!, #cleanup, #draw, #focus, #handle_input, #help_text, #in_search?, keymap, keymaps, #killable?, load_all_modes, make_name, #name, #pipe_to_process, register_keymap, #resize, #resolve_input, #save_to_file, #status, #unsaved?

Constructor Details

#initialize(query) ⇒ SearchResultsMode

Returns a new instance of SearchResultsMode.



4
5
6
7
# File 'lib/sup/modes/search_results_mode.rb', line 4

def initialize query
  @query = query
  super [], query
end

Class Method Details

.spawn_from_query(text) ⇒ Object

a proper is_relevant? method requires some way of asking the index 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.



41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
# File 'lib/sup/modes/search_results_mode.rb', line 41

def self.spawn_from_query text
  begin
    if SearchManager.predefined_queries.has_key? text
      query = SearchManager.predefined_queries[text]
    else
      query = Index.parse_query(text)
    end
    return unless query
    short_text = text.length < 20 ? text : text[0 ... 20] + "..."
    mode = SearchResultsMode.new query
    BufferManager.spawn "search: \"#{short_text}\"", mode
    mode.load_threads :num => mode.buffer.content_height
  rescue Index::ParseError => e
    BufferManager.flash "Problem: #{e.message}!"
  end
end

Instance Method Details

#refine_searchObject



14
15
16
17
18
# File 'lib/sup/modes/search_results_mode.rb', line 14

def refine_search
  text = BufferManager.ask :search, "refine query: ", (@query[:text] + " ")
  return unless text && text !~ /^\s*$/
  SearchResultsMode.spawn_from_query text
end

#save_searchObject



20
21
22
23
24
25
26
27
28
29
30
31
32
33
# File 'lib/sup/modes/search_results_mode.rb', line 20

def save_search
  name = BufferManager.ask :save_search, "Name this search: "
  return unless name && name !~ /^\s*$/
  name.strip!
  unless SearchManager.valid_name? name
    BufferManager.flash "Not saved: " + SearchManager.name_format_hint
    return
  end
  if SearchManager.all_searches.include? name
    BufferManager.flash "Not saved: \"#{name}\" already exists"
    return
  end
  BufferManager.flash "Search saved as \"#{name}\"" if SearchManager.add name, @query[:text].strip
end