class Redwood::SearchListMode

Public Class Methods

new() click to toggle source
Calls superclass method Redwood::LineCursorMode.new
# File lib/sup/modes/search_list_mode.rb, line 34
def initialize
  @searches = []
  @text = []
  @unread_only = false
  super
  UpdateManager.register self
  regen_text
end

Public Instance Methods

[](i;) click to toggle source
# File lib/sup/modes/search_list_mode.rb, line 49
def [] i; @text[i] end
cleanup() click to toggle source
Calls superclass method Redwood::LineCursorMode#cleanup
# File lib/sup/modes/search_list_mode.rb, line 43
def cleanup
  UpdateManager.unregister self
  super
end
focus() click to toggle source
# File lib/sup/modes/search_list_mode.rb, line 62
def focus
  reload # make sure unread message counts are up-to-date
end
handle_added_update(sender, m) click to toggle source
# File lib/sup/modes/search_list_mode.rb, line 66
def handle_added_update sender, m
  reload
end
jump_to_next_new() click to toggle source
# File lib/sup/modes/search_list_mode.rb, line 51
def jump_to_next_new
  n = ((curpos + 1) ... lines).find { |i| @searches[i][1] > 0 } || (0 ... curpos).find { |i| @searches[i][1] > 0 }
  if n
    ## jump there if necessary
    jump_to_line n unless n >= topline && n < botline
    set_cursor_pos n
  else
    BufferManager.flash "No saved searches with unread messages."
  end
end
lines() click to toggle source
# File lib/sup/modes/search_list_mode.rb, line 48
def lines; @text.length end

Protected Instance Methods

regen_text() click to toggle source
# File lib/sup/modes/search_list_mode.rb, line 82
def regen_text
  @text = []
  searches = SearchManager.all_searches

  counted = searches.map do |name|
    search_string = SearchManager.search_string_for name
    begin
      if SearchManager.predefined_queries.has_key? search_string
        query = SearchManager.predefined_queries[search_string]
      else
        query = Index.parse_query search_string
      end
      total = Index.num_results_for :qobj => query[:qobj]
      unread = Index.num_results_for :qobj => query[:qobj], :label => :unread
    rescue Index::ParseError => e
      BufferManager.flash "Problem: #{e.message}!"
      total = 0
      unread = 0
    end
    [name, search_string, total, unread]
  end

  if HookManager.enabled? "search-list-filter"
    counts = HookManager.run "search-list-filter", :counted => counted
  else
    counts = counted.sort_by { |n, s, t, u| n.downcase }
  end

  n_width = counts.max_of { |n, s, t, u| n.length }
  tmax    = counts.max_of { |n, s, t, u| t }
  umax    = counts.max_of { |n, s, t, u| u }
  s_width = counts.max_of { |n, s, t, u| s.length }

  if @unread_only
    counts.delete_if { | n, s, t, u | u == 0 }
  end

  @searches = []
  counts.each do |name, search_string, total, unread|
    fmt = HookManager.run "search-list-format", :n_width => n_width, :tmax => tmax, :umax => umax, :s_width => s_width
    if !fmt
      fmt = "%#{n_width + 1}s %5d %s, %5d unread: %s"
    end
    @text << [[(unread == 0 ? :labellist_old_color : :labellist_new_color),
        sprintf(fmt, name, total, total == 1 ? " message" : "messages", unread, search_string)]]
    @searches << [name, unread]
  end

  BufferManager.flash "No saved searches with unread messages!" if counts.empty? && @unread_only
end
reload() click to toggle source
# File lib/sup/modes/search_list_mode.rb, line 77
def reload
  regen_text
  buffer.mark_dirty if buffer
end
toggle_show_unread_only() click to toggle source
# File lib/sup/modes/search_list_mode.rb, line 72
def toggle_show_unread_only
  @unread_only = !@unread_only
  reload
end