X-Git-Url: https://git.cworth.org/git?a=blobdiff_plain;f=lib%2Fsup%2Fmodes%2Finbox-mode.rb;h=ba095dab7c09696f60efb7e68c993d614da9e7b8;hb=d50ad629bc9321980abeaeeebf17a935c300a7b1;hp=c335758b417a9eb4d1f40c5bd27f4ed0218ea116;hpb=15a2c54fc7e7c46ecef2103f303a02f7df6be13a;p=sup diff --git a/lib/sup/modes/inbox-mode.rb b/lib/sup/modes/inbox-mode.rb index c335758..ba095da 100644 --- a/lib/sup/modes/inbox-mode.rb +++ b/lib/sup/modes/inbox-mode.rb @@ -1,4 +1,4 @@ -require 'thread' +require 'sup' module Redwood @@ -6,41 +6,100 @@ class InboxMode < ThreadIndexMode register_keymap do |k| ## overwrite toggle_archived with archive k.add :archive, "Archive thread (remove from inbox)", 'a' - k.add :load_more_threads, "Load #{LOAD_MORE_THREAD_NUM} more threads", 'M' - k.add :reload, "Discard threads and reload", 'R' + k.add :read_and_archive, "Archive thread (remove from inbox) and mark read", 'A' end def initialize - super [:inbox], [:inbox] + super [:inbox, :sent, :draft], { :label => :inbox, :skip_killed => true } + raise "can't have more than one!" if defined? @@instance + @@instance = self end + def is_relevant? m; (m.labels & [:spam, :deleted, :killed, :inbox]) == Set.new([: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 archive - remove_label_and_hide_thread cursor_thread, :inbox + return unless cursor_thread + thread = cursor_thread # to make sure lambda only knows about 'old' cursor_thread + + UndoManager.register "archiving thread" do + thread.apply_label :inbox + add_or_unhide thread.first + end + + cursor_thread.remove_label :inbox + hide_thread cursor_thread regen_text end def multi_archive threads - threads.each { |t| remove_label_and_hide_thread t, :inbox } + UndoManager.register "archiving #{threads.size.pluralize 'thread'}" do + threads.map do |t| + t.apply_label :inbox + add_or_unhide t.first + end + regen_text + end + + threads.each do |t| + t.remove_label :inbox + hide_thread t + end + regen_text + end + + def read_and_archive + return unless cursor_thread + thread = cursor_thread # to make sure lambda only knows about 'old' cursor_thread + + UndoManager.register "reading and archiving thread" do + thread.apply_label :inbox + thread.apply_label :unread + add_or_unhide thread.first + end + + cursor_thread.remove_label :unread + cursor_thread.remove_label :inbox + hide_thread cursor_thread regen_text end - def is_relevant? m; m.has_label? :inbox; end + def multi_read_and_archive threads + old_labels = threads.map { |t| t.labels.dup } - def load_more_threads n=ThreadIndexMode::LOAD_MORE_THREAD_NUM - load_n_threads_background n, :label => :inbox, - :load_killed => false, - :load_spam => false, - :when_done => lambda { |num| - BufferManager.flash "Added #{num} threads." - } + threads.each do |t| + t.remove_label :unread + t.remove_label :inbox + hide_thread t + end + regen_text + + UndoManager.register "reading and archiving #{threads.size.pluralize 'thread'}" do + threads.zip(old_labels).each do |t, l| + t.labels = l + add_or_unhide t.first + end + regen_text + end + + end + + def handle_unarchived_update sender, m + add_or_unhide m + end + + def handle_archived_update sender, m + t = thread_containing(m) or return + hide_thread t + regen_text end - def reload - drop_all_threads - BufferManager.draw_screen - load_more_threads buffer.content_height + def status + super + " #{Index.size} messages in index" end end