lib/sup/modes/thread-index-mode.rb in sup-0.8.1 vs lib/sup/modes/thread-index-mode.rb in sup-0.9

- old
+ new

@@ -1,5 +1,7 @@ +require 'set' + module Redwood ## subclasses should implement: ## - is_relevant? @@ -36,10 +38,11 @@ k.add :toggle_deleted, "Delete/undelete thread", 'd' 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 latest message in a thread", 'r' + k.add :reply_all, "Reply to all participants of the latest message in a thread", 'G' k.add :forward, "Forward latest message in a thread", 'f' k.add :toggle_tagged, "Tag/untag selected thread", 't' k.add :toggle_tagged_all, "Tag/untag all threads", 'T' k.add :tag_matching, "Tag matching threads", 'g' k.add :apply_to_tagged, "Apply next command to all tagged threads", '+', '=' @@ -72,12 +75,11 @@ @save_thread_mutex = Mutex.new @last_load_more_size = nil to_load_more do |size| next if @last_load_more_size == 0 - load_threads :num => 1, :background => false - load_threads :num => (size - 1), + load_threads :num => size, :when_done => lambda { |num| @last_load_more_size = num } end end def unsaved?; dirty? end @@ -107,11 +109,11 @@ end end mode = ThreadViewMode.new t, @hidden_labels, self BufferManager.spawn t.subj, mode BufferManager.draw_screen - mode.jump_to_first_open true + mode.jump_to_first_open BufferManager.draw_screen # lame TODO: make this unnecessary ## the first draw_screen is needed before topline and botline ## are set, and the second to show the cursor having moved update_text_for_line curpos @@ -473,11 +475,11 @@ next if dirty_threads.empty? BufferManager.say("Saving threads...") do |say_id| dirty_threads.each_with_index do |t, i| BufferManager.say "Saving modified thread #{i + 1} of #{dirty_threads.length}...", say_id - t.save Index + t.save_state Index end end end end @@ -529,13 +531,13 @@ pos = curpos keepl, modifyl = thread.labels.partition { |t| speciall.member? t } user_labels = BufferManager.ask_for_labels :label, "Labels for thread: ", modifyl, @hidden_labels - return unless user_labels - thread.labels = keepl + user_labels + + thread.labels = Set.new(keepl) + user_labels user_labels.each { |l| LabelManager << l } update_text_for_line curpos UndoManager.register "labeling thread" do thread.labels = old_labels @@ -566,10 +568,11 @@ else t.apply_label l LabelManager << l end end + UpdateManager.relay self, :labeled, t.first end regen_text UndoManager.register "labeling #{threads.size.pluralize 'thread'}" do @@ -579,19 +582,21 @@ end regen_text end end - def reply + def reply type_arg=nil t = cursor_thread or return m = t.latest_message return if m.nil? # probably won't happen m.load_from_source! - mode = ReplyMode.new m + mode = ReplyMode.new m, type_arg BufferManager.spawn "Reply to #{m.subj}", mode end + def reply_all; reply :all; end + def forward t = cursor_thread or return m = t.latest_message return if m.nil? # probably won't happen m.load_from_source! @@ -622,10 +627,11 @@ BufferManager.say "Loaded #{i.pluralize 'thread'}...", @mbid update BufferManager.draw_screen last_update = Time.now end + ::Thread.pass break if @interrupt_search end @ts.threads.each { |th| th.labels.each { |l| LabelManager << l } } update @@ -754,14 +760,16 @@ buffer.mark_dirty if buffer end def authors; map { |m, *o| m.from if m }.compact.uniq; end - def author_names_and_newness_for_thread t + def author_names_and_newness_for_thread t, limit=nil new = {} - authors = t.map do |m, *o| + authors = Set.new + t.each do |m, *o| next unless m + break if limit and authors.size >= limit name = if AccountManager.is_account?(m.from) "me" elsif t.authors.size == 1 @@ -769,26 +777,27 @@ else m.from.shortname end new[name] ||= m.has_label?(:unread) - name + authors << name end - authors.compact.uniq.map { |a| [a, new[a]] } + authors.to_a.map { |a| [a, new[a]] } end + AUTHOR_LIMIT = 5 def text_for_thread_at line t, size_widget = @mutex.synchronize { [@threads[line], @size_widgets[line]] } date = t.date.to_nice_s starred = t.has_label? :starred ## format the from column cur_width = 0 - ann = author_names_and_newness_for_thread t + ann = author_names_and_newness_for_thread t, AUTHOR_LIMIT from = [] ann.each_with_index do |(name, newness), i| break if cur_width >= from_width last = i == ann.length - 1 @@ -840,13 +849,14 @@ from + [ [subj_color, size_widget_text], [:to_me_color, t.labels.member?(:attachment) ? "@" : " "], [:to_me_color, dp ? ">" : (p ? '+' : " ")], - [subj_color, t.subj + (t.subj.empty? ? "" : " ")], ] + - (t.labels - @hidden_labels).map { |label| [:label_color, "+#{label} "] } + - [[:snippet_color, snippet] + (t.labels - @hidden_labels).map { |label| [:label_color, "#{label} "] } + + [ + [subj_color, t.subj + (t.subj.empty? ? "" : " ")], + [:snippet_color, snippet], ] end def dirty?; @mutex.synchronize { (@hidden_threads.keys + @threads).any? { |t| t.dirty? } } end