From e71df12a4a504f0ff4c147f29486da737d936fd1 Mon Sep 17 00:00:00 2001 From: wmorgan Date: Wed, 7 Nov 2007 20:03:36 +0000 Subject: [PATCH] applied modified index-mode-size-widget hook from colin bell git-svn-id: svn://rubyforge.org/var/svn/sup/trunk@675 5c8cc53c-5e98-4d25-b20a-d8db53a31250 --- lib/sup/modes/thread-index-mode.rb | 49 +++++++++++++++++++++++++----- 1 file changed, 41 insertions(+), 8 deletions(-) diff --git a/lib/sup/modes/thread-index-mode.rb b/lib/sup/modes/thread-index-mode.rb index 4988c43..a337b9d 100644 --- a/lib/sup/modes/thread-index-mode.rb +++ b/lib/sup/modes/thread-index-mode.rb @@ -8,6 +8,12 @@ class ThreadIndexMode < LineCursorMode MIN_FROM_WIDTH = 15 LOAD_MORE_THREAD_NUM = 20 + HookManager.register "index-mode-size-widget", < t) || default_size_widget_for(t) + end + def cursor_thread; @threads[curpos]; end def drop_all_threads @@ -467,12 +479,19 @@ protected def update_text_for_line l return unless l # not sure why this happens, but it does, occasionally - @text[l] = text_for_thread @threads[l] - buffer.mark_dirty if buffer + @size_widgets[l] = size_widget_for_thread @threads[l] + + ## if the widget size has increased, we need to redraw everyone + if @size_widgets[l].size > @size_widget_width + update + else + @text[l] = text_for_thread_at l + buffer.mark_dirty if buffer + end end def regen_text - @text = @threads.map_with_index { |t, i| text_for_thread t } + @text = @threads.map_with_index { |t, i| text_for_thread_at i } @lines = @threads.map_with_index { |t, i| [t, i] }.to_h buffer.mark_dirty if buffer end @@ -500,7 +519,10 @@ protected authors.compact.uniq.map { |a| [a, new[a]] } end - def text_for_thread t + def text_for_thread_at line + t = @threads[line] + size_widget = @size_widgets[line] + date = t.date.to_nice_s new = t.has_label?(:unread) @@ -550,6 +572,8 @@ protected snippet = t.snippet + (t.snippet.empty? ? "" : "...") + size_widget_text = sprintf "%#{ @size_widget_width}s", size_widget + [ [:tagged_color, @tags.tagged?(t) ? ">" : " "], [:none, sprintf("%#{@date_width}s", date)], @@ -557,7 +581,7 @@ protected ] + from + [ - [subj_color, t.size == 1 ? " " * (@size_width + 2) : sprintf("(%#{@size_width}d)", t.size)], + [subj_color, size_widget_text], [:to_me_color, dp ? " >" : (p ? ' +' : " ")], [subj_color, t.subj + (t.subj.empty? ? "" : " ")], ] + @@ -571,6 +595,15 @@ protected private + def default_size_widget_for t + case t.size + when 1 + "" + else + "(#{t.size})" + end + end + def from_width [(buffer.content_width.to_f * 0.2).to_i, MIN_FROM_WIDTH].max end -- 2.45.2