lib/sup/modes/thread-index-mode.rb in sup-0.0.4 vs lib/sup/modes/thread-index-mode.rb in sup-0.0.5
- old
+ new
@@ -1,20 +1,24 @@
module Redwood
+## subclasses should implement load_threads
+
class ThreadIndexMode < LineCursorMode
DATE_WIDTH = Time::TO_NICE_S_MAX_LEN
FROM_WIDTH = 15
LOAD_MORE_THREAD_NUM = 20
register_keymap do |k|
+ k.add :load_threads, "Load #{LOAD_MORE_THREAD_NUM} more threads", 'M'
+ k.add :reload, "Discard threads and reload", 'D'
k.add :toggle_archived, "Toggle archived status", 'a'
k.add :toggle_starred, "Star or unstar all messages in thread", '*'
k.add :toggle_new, "Toggle new/read status of all messages in thread", 'N'
k.add :edit_labels, "Edit or add labels for a thread", 'l'
k.add :edit_message, "Edit message (drafts only)", 'e'
k.add :mark_as_spam, "Mark thread as spam", 'S'
- k.add :kill, "Kill thread (never to be seen in inbox again)", 'K'
+ k.add :kill, "Kill thread (never to be seen in inbox again)", '&'
k.add :save, "Save changes now", '$'
k.add :jump_to_next_new, "Jump to next new thread", :tab
k.add :reply, "Reply to a thread", 'r'
k.add :forward, "Forward a thread", 'f'
k.add :toggle_tagged, "Tag/untag current line", 't'
@@ -39,22 +43,31 @@
end
def lines; @text.length; end
def [] i; @text[i]; end
+ def reload
+ drop_all_threads
+ BufferManager.draw_screen
+ load_threads :num => buffer.content_height
+ end
+
## open up a thread view window
- def select
- this_curpos = curpos
- t = @threads[this_curpos]
+ def select t=nil
+ t ||= @threads[curpos]
## TODO: don't regen text completely
Redwood::reporting_thread do
mode = ThreadViewMode.new t, @hidden_labels
BufferManager.spawn t.subj, mode
BufferManager.draw_screen
end
end
+
+ def multi_select threads
+ threads.each { |t| select t }
+ end
def handle_starred_update m
return unless(t = @ts.thread_for m)
@starred_cache[t] = t.has_label? :starred
update_text_for_line @lines[t]
@@ -159,11 +172,11 @@
multi_mark_as_spam [t]
end
def multi_mark_as_spam threads
threads.each do |t|
- t.apply_label :spam
+ t.toggle_label :spam
hide_thread t
end
regen_text
end
@@ -180,19 +193,18 @@
regen_text
end
def save
threads = @threads + @hidden_threads.keys
- mbid = BufferManager.say "Saving threads..."
- threads.each_with_index do |t, i|
- if i % 5 == 0
- BufferManager.say "Saving thread #{i + 1} of #{threads.length}...",
- mbid
+
+ BufferManager.say("Saving threads...") do |say_id|
+ threads.each_with_index do |t, i|
+ next unless t.dirty?
+ BufferManager.say "Saving thread #{i +1} of #{threads.length}...", say_id
+ t.save Index
end
- t.save Index
end
- BufferManager.clear mbid
end
def cleanup
UpdateManager.unregister self
@@ -294,10 +306,14 @@
BufferManager.draw_screen
@ts.size - orig_size
end
def status
- "line #{curpos + 1} of #{lines} #{dirty? ? '*modified*' : ''}"
+ if (l = lines) == 0
+ ""
+ else
+ "line #{curpos + 1} of #{l} #{dirty? ? '*modified*' : ''}"
+ end
end
protected
def cursor_thread; @threads[curpos]; end