MIN_FROM_WIDTH = 15
LOAD_MORE_THREAD_NUM = 20
+ HookManager.register "index-mode-size-widget", <<EOS
+Generates the per-thread size widget for each thread.
+Variables:
+ thread: The message thread to be formatted.
+EOS
+
register_keymap do |k|
k.add :load_threads, "Load #{LOAD_MORE_THREAD_NUM} more threads", 'M'
k.add :reload, "Refresh view", '@'
@load_thread_opts = load_thread_opts
@hidden_labels = hidden_labels + LabelManager::HIDDEN_RESERVED_LABELS
@date_width = DATE_WIDTH
- @size_width = nil
-
+ @size_widget_width = nil
+ @size_widgets = {}
@tags = Tagger.new self
initialize_threads
def update
## let's see you do THIS in python
@threads = @ts.threads.select { |t| !@hidden_threads[t] }.sort_by { |t| t.date }.reverse
- @size_width = (@threads.max_of { |t| t.size } || 0).num_digits
+ @size_widgets = @threads.map { |t| size_widget_for_thread t }
+ @size_widget_width = @size_widgets.max_of { |w| w.length }
+
regen_text
end
protected
+ def size_widget_for_thread t
+ HookManager.run("index-mode-size-widget", :thread => t) || default_size_widget_for(t)
+ end
+
def cursor_thread; @threads[curpos]; end
def drop_all_threads
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
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)
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)],
] +
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? ? "" : " ")],
] +
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