threads.each { |t| select t }
end
- ## this is called by thread-view-modes when the user wants to view
- ## the next thread without going to index-mode. we update the cursor
- ## as a convenience.
+ ## these two methods are called by thread-view-modes when the user
+ ## wants to view the previous/next thread without going back to
+ ## index-mode. we update the cursor as a convenience.
def launch_next_thread_after thread, &b
+ launch_another_thread thread, 1, &b
+ end
+
+ def launch_prev_thread_before thread, &b
+ launch_another_thread thread, -1, &b
+ end
+
+ def launch_another_thread thread, direction, &b
l = @lines[thread] or return
+ target_l = l + direction
t = @mutex.synchronize do
- if l < @threads.length - 1
- set_cursor_pos l + 1 # move out of mutex?
- @threads[l + 1]
+ if target_l >= 0 && target_l < @threads.length
+ @threads[target_l]
end
end
if t # there's a next thread
+ set_cursor_pos target_l # move out of mutex?
select t, b
elsif b # no next thread. call the block anyways
b.call
kk.add :unread_and_next, "Mark this thread as unread, kill buffer, and view next", 'N'
kk.add :do_nothing_and_next, "Kill buffer, and view next", 'n'
end
+
+ k.add_multi "(a)rchive/(d)elete/mark as (s)pam/mark as u(N)read/do (n)othing:", ']' do |kk|
+ kk.add :archive_and_prev, "Archive this thread, kill buffer, and view previous", 'a'
+ kk.add :delete_and_prev, "Delete this thread, kill buffer, and view previous", 'd'
+ kk.add :spam_and_prev, "Mark this thread as spam, kill buffer, and view previous", 's'
+ kk.add :unread_and_prev, "Mark this thread as unread, kill buffer, and view previous", 'N'
+ kk.add :do_nothing_and_prev, "Kill buffer, and view previous", 'n'
+ end
end
## there are a couple important instance variables we hold to format
def unread_and_next; unread_and_then :next end
def do_nothing_and_next; do_nothing_and_then :next end
+ def archive_and_prev; archive_and_then :prev end
+ def spam_and_prev; spam_and_then :prev end
+ def delete_and_prev; delete_and_then :prev end
+ def unread_and_prev; unread_and_then :prev end
+ def do_nothing_and_prev; do_nothing_and_then :prev end
+
def archive_and_then op
dispatch op do
@thread.remove_label :inbox
return if @dying
@dying = true
+ l = lambda do
+ yield if block_given?
+ BufferManager.kill_buffer_safely buffer
+ end
+
case op
when :next
- @index_mode.launch_next_thread_after(@thread) do
- yield if block_given?
- BufferManager.kill_buffer_safely buffer
- end
+ @index_mode.launch_next_thread_after @thread, &l
+ when :prev
+ @index_mode.launch_prev_thread_before @thread, &l
when :kill
- yield if block_given?
- BufferManager.kill_buffer_safely buffer
+ l.call
else
raise ArgumentError, "unknown thread dispatch operation #{op.inspect}"
end