commit c635624809687dc08c1b722c18bd468d60f7c028
parent 04fc9a010f3112bc472294ae38a575a183ce54a4
Author: William Morgan <wmorgan-sup@masanjin.net>
Date: Sat, 2 Feb 2008 16:55:25 -0800
Merge branch 'next' into id-reordering
Diffstat:
6 files changed, 49 insertions(+), 17 deletions(-)
diff --git a/lib/sup/modes/contact-list-mode.rb b/lib/sup/modes/contact-list-mode.rb
@@ -29,7 +29,7 @@ class ContactListMode < LineCursorMode
def initialize mode=:regular
@mode = mode
- @tags = Tagger.new self
+ @tags = Tagger.new self, "contact"
@num = nil
@text = []
super()
diff --git a/lib/sup/modes/scroll-mode.rb b/lib/sup/modes/scroll-mode.rb
@@ -12,7 +12,7 @@ class ScrollMode < Mode
attr_reader :status, :topline, :botline, :leftcol
- COL_JUMP = 4
+ COL_JUMP = 2
register_keymap do |k|
k.add :line_down, "Down one line", :down, 'j', 'J'
diff --git a/lib/sup/modes/thread-index-mode.rb b/lib/sup/modes/thread-index-mode.rb
@@ -16,6 +16,10 @@ EOS
register_keymap do |k|
k.add :load_threads, "Load #{LOAD_MORE_THREAD_NUM} more threads", 'M'
+ k.add_multi "Load all threads (! to confirm) :", '!' do |kk|
+ kk.add :load_all_threads, "Load all threads (may list a _lot_ of threads)", '!'
+ end
+ k.add :cancel_search, "Cancel current search", :ctrl_g
k.add :reload, "Refresh view", '@'
k.add :toggle_archived, "Toggle archived status", 'a'
k.add :toggle_starred, "Star or unstar all messages in thread", '*'
@@ -50,6 +54,8 @@ EOS
@load_thread_opts = load_thread_opts
@hidden_labels = hidden_labels + LabelManager::HIDDEN_RESERVED_LABELS
@date_width = DATE_WIDTH
+
+ @interrupt_search = false
initialize_threads # defines @ts and @ts_mutex
update # defines @text and @lines
@@ -456,16 +462,22 @@ EOS
## TODO: figure out @ts_mutex in this method
def load_n_threads n=LOAD_MORE_THREAD_NUM, opts={}
+ @interrupt_search = false
@mbid = BufferManager.say "Searching for threads..."
+
+ ts_to_load = n
+ ts_to_load = ts_to_load + @ts.size unless n == -1 # -1 means all threads
+
orig_size = @ts.size
last_update = Time.now
- @ts.load_n_threads(@ts.size + n, opts) do |i|
+ @ts.load_n_threads(ts_to_load, opts) do |i|
if (Time.now - last_update) >= 0.25
- BufferManager.say "Loaded #{i.pluralize 'thread'}...", @mbid
+ BufferManager.say "Loaded #{i.pluralize 'thread'} (use ^G to cancel)...", @mbid
update
BufferManager.draw_screen
last_update = Time.now
end
+ break if @interrupt_search
end
@ts.threads.each { |th| th.labels.each { |l| LabelManager << l } }
@@ -485,13 +497,28 @@ EOS
end
end
+ def cancel_search
+ @interrupt_search = true
+ end
+
+ def load_all_threads
+ load_threads :num => -1
+ end
+
def load_threads opts={}
- n = opts[:num] || ThreadIndexMode::LOAD_MORE_THREAD_NUM
+ if opts[:num].nil?
+ n = ThreadIndexMode::LOAD_MORE_THREAD_NUM
+ else
+ n = opts[:num]
+ end
myopts = @load_thread_opts.merge({ :when_done => (lambda do |num|
opts[:when_done].call(num) if opts[:when_done]
+
+ cancelled = @interrupt_search?" (search cancelled by user)":""
+
if num > 0
- BufferManager.flash "Found #{num.pluralize 'thread'}."
+ BufferManager.flash "Found #{num.pluralize 'thread'}#{cancelled}."
else
BufferManager.flash "No matches."
end
diff --git a/lib/sup/modes/thread-view-mode.rb b/lib/sup/modes/thread-view-mode.rb
@@ -318,6 +318,8 @@ EOS
end
end
+ IDEAL_TOP_CONTEXT = 3 # try and give 3 rows of top context
+ IDEAL_LEFT_CONTEXT = 4 # try and give 4 columns of left context
def jump_to_message m, loose_alignment=false
l = @layout[m]
left = l.depth * INDENT_SPACES
@@ -325,19 +327,20 @@ EOS
## jump to the top line
if loose_alignment
- jump_to_line [l.top - 3, 0].max # give 3 lines of top context
+ jump_to_line [l.top - IDEAL_TOP_CONTEXT, 0].max # give 3 lines of top context
else
jump_to_line l.top
end
## jump to the left column
- if loose_alignment
- ## try and give 4 columns of left context, but not if it means that
- ## the right of the message is truncated.
- jump_to_col [[left - 4, rightcol - l.width - 1].min, 0].max
- else
- jump_to_col left
- end
+ ideal_left = left +
+ if loose_alignment
+ -IDEAL_LEFT_CONTEXT + (l.width - buffer.content_width + IDEAL_LEFT_CONTEXT + 1).clamp(0, IDEAL_LEFT_CONTEXT)
+ else
+ 0
+ end
+
+ jump_to_col [ideal_left, 0].max
## either way, move the cursor to the first line
set_cursor_pos l.top
diff --git a/lib/sup/tagger.rb b/lib/sup/tagger.rb
@@ -1,9 +1,11 @@
module Redwood
class Tagger
- def initialize mode
+ def initialize mode, noun="thread", plural_noun=nil
@mode = mode
@tagged = {}
+ @noun = noun
+ @plural_noun = plural_noun || (@noun + "s")
end
def tagged? o; @tagged[o]; end
@@ -21,7 +23,7 @@ class Tagger
return
end
- noun = num_tagged == 1 ? "thread" : "threads"
+ noun = num_tagged == 1 ? @noun : @plural_noun
unless action
c = BufferManager.ask_getch "apply to #{num_tagged} tagged #{noun}:"
diff --git a/lib/sup/thread.rb b/lib/sup/thread.rb
@@ -324,7 +324,7 @@ class ThreadSet
## load in (at most) num number of threads from the index
def load_n_threads num, opts={}
@index.each_id_by_date opts do |mid, builder|
- break if size >= num
+ break if size >= num unless num == -1
next if contains_id? mid
m = builder.call