]> git.cworth.org Git - sup/commitdiff
add ] as a dispatch-and-previous prefix in thread-view-mode
authorWilliam Morgan <wmorgan-sup@masanjin.net>
Tue, 5 Feb 2008 17:21:03 +0000 (09:21 -0800)
committerWilliam Morgan <wmorgan-sup@masanjin.net>
Tue, 5 Feb 2008 17:44:36 +0000 (09:44 -0800)
lib/sup/modes/thread-index-mode.rb
lib/sup/modes/thread-view-mode.rb

index 23c76c310a40b1fd044aa660e5375f3fd309322f..78babf8eb5d1181790f9f7ccac8da667afea2b6c 100644 (file)
@@ -113,19 +113,28 @@ EOS
     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
index fde979ea9b70e2c55af6476ac7f62af2ecd3050c..559c58ecd35bbf0c27588aaaabf0f86bdfe55aa9 100644 (file)
@@ -63,6 +63,14 @@ EOS
       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
@@ -383,6 +391,12 @@ EOS
   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
@@ -419,15 +433,18 @@ EOS
     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