end
def initialize
- super [:inbox], [:inbox]
+ super [:inbox, :sent], { :label => :inbox }
+ raise "can't have more than one!" if defined? @@instance
@@instance = self
end
+ def is_relevant? m; m.has_label? :inbox; end
+
+ ## label-list-mode wants to be able to raise us if the user selects
+ ## the "inbox" label, so we need to keep our singletonness around
def self.instance; @@instance; end
def killable?; false; end
def status
super + " #{Index.size} messages in index"
end
-
- def is_relevant? m; m.has_label? :inbox; end
-
- def load_threads opts={}
- n = opts[:num] || ThreadIndexMode::LOAD_MORE_THREAD_NUM
- load_n_threads_background n, :label => :inbox,
- :when_done => (lambda do |num|
- opts[:when_done].call(num) if opts[:when_done]
- BufferManager.flash "Added #{num} threads."
- end)
- end
end
end
class LabelSearchResultsMode < ThreadIndexMode
def initialize labels
@labels = labels
- super
+ super [], { :labels => @labels }
end
def is_relevant? m; @labels.all? { |l| m.has_label? l }; end
-
- def load_threads opts={}
- n = opts[:num] || ThreadIndexMode::LOAD_MORE_THREAD_NUM
- load_n_threads_background n, :labels => @labels,
- :load_killed => true,
- :load_spam => false,
- :when_done =>(lambda do |num|
- opts[:when_done].call(num) if opts[:when_done]
- if num > 0
- BufferManager.flash "Found #{num} threads"
- else
- BufferManager.flash "No matches"
- end
- end)
- end
end
end
class PersonSearchResultsMode < ThreadIndexMode
def initialize people
@people = people
- super
+ super [], { :participants => @people }
end
def is_relevant? m; @people.any? { |p| m.from == p }; end
-
- def load_threads opts={}
- n = opts[:num] || ThreadIndexMode::LOAD_MORE_THREAD_NUM
- load_n_threads_background n, :participants => @people,
- :load_killed => true,
- :load_spam => false,
- :when_done =>(lambda do |num|
- opts[:when_done].call(num) if opts[:when_done]
- if num > 0
- BufferManager.flash "Found #{num} threads"
- else
- BufferManager.flash "No matches"
- end
- end)
- end
end
end
class SearchResultsMode < ThreadIndexMode
def initialize qobj
@qobj = qobj
- super
+ super [], { :qobj => @qobj, :load_killed => true, :load_spam => false }
end
- ## TODO: think about this
- def is_relevant? m; super; 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 load_threads opts={}
- n = opts[:num] || ThreadIndexMode::LOAD_MORE_THREAD_NUM
- load_n_threads_background n, :qobj => @qobj,
- :load_killed => true,
- :load_spam => false,
- :when_done =>(lambda do |num|
- opts[:when_done].call(num) if opts[:when_done]
- if num > 0
- BufferManager.flash "Found #{num} threads"
- else
- BufferManager.flash "No matches"
- end
- end)
- end
end
end
-require 'thread'
module Redwood
-## subclasses should implement load_threads
+## subclasses should implement:
+## - is_relevant?
+
class ThreadIndexMode < LineCursorMode
DATE_WIDTH = Time::TO_NICE_S_MAX_LEN
FROM_WIDTH = 15
k.add :apply_to_tagged, "Apply next command to all tagged threads", ';'
end
- def initialize required_labels=[], hidden_labels=[]
+ def initialize hidden_labels=[], load_thread_opts={}
super()
@load_thread = nil
- @required_labels = required_labels
+ @load_thread_opts = load_thread_opts
@hidden_labels = hidden_labels + LabelManager::HIDDEN_LABELS
@date_width = DATE_WIDTH
@from_width = FROM_WIDTH
to_load_more do |size|
next if @last_load_more_size == 0
- load_threads :num => size,
+ load_threads :num => 1, :background => false
+ load_threads :num => (size - 1),
:when_done => lambda { |num| @last_load_more_size = num }
- sleep 1.0 # give 'em a chance to load
end
end
end
end
+ def load_threads opts={}
+ n = opts[:num] || ThreadIndexMode::LOAD_MORE_THREAD_NUM
+
+ myopts = @load_thread_opts.merge({ :when_done => (lambda do |num|
+ opts[:when_done].call(num) if opts[:when_done]
+ if num > 0
+ BufferManager.flash "Found #{num} threads"
+ else
+ BufferManager.flash "No matches"
+ end
+ end)})
+
+ if opts[:background]
+ load_n_threads_background n, myopts
+ else
+ load_n_threads n, myopts
+ end
+ end
+
protected
def cursor_thread; @threads[curpos]; end