X-Git-Url: https://git.cworth.org/git?a=blobdiff_plain;f=lib%2Fsup%2Fmodes%2Fthread-index-mode.rb;h=177431b5248ea87e84226a5a9b8cac05ff0ef53b;hb=0646c7e1688bf8755e5eb1a97dfa2d787acd1204;hp=e766e2efc7e1a4d261eaf03dc479bc4d7043ec3b;hpb=9478114b592e0ba7917a65804aacd401d21d70c2;p=sup diff --git a/lib/sup/modes/thread-index-mode.rb b/lib/sup/modes/thread-index-mode.rb index e766e2e..177431b 100644 --- a/lib/sup/modes/thread-index-mode.rb +++ b/lib/sup/modes/thread-index-mode.rb @@ -1,3 +1,5 @@ +require 'set' + module Redwood ## subclasses should implement: @@ -74,8 +76,7 @@ EOS @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 @@ -222,7 +223,7 @@ EOS ## let's see you do THIS in python @threads = @ts.threads.select { |t| !@hidden_threads[t] }.sort_by { |t| [t.date, t.first.id] }.reverse @size_widgets = @threads.map { |t| size_widget_for_thread t } - @size_widget_width = @size_widgets.max_of { |w| w.length } + @size_widget_width = @size_widgets.max_of { |w| w.display_length } end regen_text @@ -475,7 +476,7 @@ EOS 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 @@ -531,13 +532,13 @@ EOS 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 #{thread.first.id}" do + UndoManager.register "labeling thread" do thread.labels = old_labels update_text_for_line pos UpdateManager.relay self, :labeled, thread.first @@ -568,6 +569,7 @@ EOS LabelManager << l end end + UpdateManager.relay self, :labeled, t.first end regen_text @@ -624,6 +626,7 @@ EOS 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 } } @@ -756,10 +759,12 @@ protected 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) @@ -771,12 +776,13 @@ protected 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]] } @@ -786,16 +792,16 @@ protected ## 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 abbrev = - if cur_width + name.length > from_width + if cur_width + name.display_length > from_width name[0 ... (from_width - cur_width - 1)] + "." - elsif cur_width + name.length == from_width + elsif cur_width + name.display_length == from_width name[0 ... (from_width - cur_width)] else if last @@ -805,7 +811,7 @@ protected end end - cur_width += abbrev.length + cur_width += abbrev.display_length if last && from_width > cur_width abbrev += " " * (from_width - cur_width) @@ -842,10 +848,11 @@ protected [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