lib/sup/modes/thread-index-mode.rb in sup-0.10.2 vs lib/sup/modes/thread-index-mode.rb in sup-0.11

- old
+ new

@@ -14,10 +14,16 @@ Generates the per-thread size widget for each thread. Variables: thread: The message thread to be formatted. EOS + HookManager.register "index-mode-date-widget", <<EOS +Generates the per-thread date widget for each thread. +Variables: + thread: The message thread to be formatted. +EOS + HookManager.register "mark-as-spam", <<EOS This hook is run when a thread is marked as spam Variables: thread: The message thread being marked as spam. EOS @@ -51,14 +57,16 @@ end def initialize hidden_labels=[], load_thread_opts={} super() @mutex = Mutex.new # covers the following variables: - @threads = {} + @threads = [] @hidden_threads = {} @size_widget_width = nil - @size_widgets = {} + @size_widgets = [] + @date_widget_width = nil + @date_widgets = [] @tags = Tagger.new self ## these guys, and @text and @lines, are not covered @load_thread = nil @load_thread_opts = load_thread_opts @@ -109,11 +117,11 @@ end end mode = ThreadViewMode.new t, @hidden_labels, self BufferManager.spawn t.subj, mode BufferManager.draw_screen - mode.jump_to_first_open + mode.jump_to_first_open if $config[:jump_to_open_message] 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 @@ -224,10 +232,12 @@ @mutex.synchronize do ## 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.display_length } + @date_widgets = @threads.map { |t| date_widget_for_thread t } + @date_widget_width = @date_widgets.max_of { |w| w.display_length } end set_cursor_pos @threads.index(old_cursor_thread)||curpos regen_text end @@ -649,11 +659,11 @@ def status if (l = lines) == 0 "line 0 of 0" else - "line #{curpos + 1} of #{l} #{dirty? ? '*modified*' : ''}" + "line #{curpos + 1} of #{l}" end end def cancel_search @interrupt_search = true @@ -717,10 +727,14 @@ def size_widget_for_thread t HookManager.run("index-mode-size-widget", :thread => t) || default_size_widget_for(t) end + def date_widget_for_thread t + HookManager.run("index-mode-date-widget", :thread => t) || default_date_widget_for(t) + end + def cursor_thread; @mutex.synchronize { @threads[curpos] }; end def drop_all_threads @tags.drop_all_tags initialize_threads @@ -732,10 +746,11 @@ i = @threads.index(t) or return raise "already hidden" if @hidden_threads[t] @hidden_threads[t] = true @threads.delete_at i @size_widgets.delete_at i + @date_widgets.delete_at i @tags.drop_tag_for t end end def update_text_for_line l @@ -743,13 +758,16 @@ need_update = false @mutex.synchronize do @size_widgets[l] = size_widget_for_thread @threads[l] + @date_widgets[l] = date_widget_for_thread @threads[l] - ## if the widget size has increased, we need to redraw everyone - need_update = @size_widgets[l].size > @size_widget_width + ## if a widget size has increased, we need to redraw everyone + need_update = + (@size_widgets[l].size > @size_widget_width) or + (@date_widgets[l].size > @date_widget_width) end if need_update update else @@ -791,19 +809,29 @@ end result << [name, new[a]] end + if result.size == 1 && (author_and_newness = result.assoc("me")) + unless (recipients = t.participants - t.authors).empty? + result = recipients.collect do |r| + break if limit && result.size >= limit + name = (recipients.size == 1) ? r.mediumname : r.shortname + ["(#{name})", author_and_newness[1]] + end + end + end + result end AUTHOR_LIMIT = 5 def text_for_thread_at line - t, size_widget = @mutex.synchronize { [@threads[line], @size_widgets[line]] } + t, size_widget, date_widget = @mutex.synchronize do + [@threads[line], @size_widgets[line], @date_widgets[line]] + end - 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, AUTHOR_LIMIT @@ -849,14 +877,15 @@ end snippet = t.snippet + (t.snippet.empty? ? "" : "...") size_widget_text = sprintf "%#{ @size_widget_width}s", size_widget + date_widget_text = sprintf "%#{ @date_widget_width}s", date_widget [ [:tagged_color, @tags.tagged?(t) ? ">" : " "], - [:date_color, sprintf("%#{@date_width}s", date)], + [:date_color, date_widget_text], (starred ? [:starred_color, "*"] : [:none, " "]), ] + from + [ [subj_color, size_widget_text], @@ -879,9 +908,13 @@ when 1 "" else "(#{t.size})" end + end + + def default_date_widget_for t + t.date.to_nice_s end def from_width [(buffer.content_width.to_f * 0.2).to_i, MIN_FROM_WIDTH].max end