lib/sup/modes/thread-index-mode.rb in sup-0.12.1 vs lib/sup/modes/thread-index-mode.rb in sup-0.13.0

- old
+ new

@@ -111,21 +111,24 @@ message = "Loading #{num.pluralize 'message body'}..." BufferManager.say(message) do |sid| t.each_with_index do |(m, *o), i| next unless m BufferManager.say "#{message} (#{i}/#{num})", sid if t.size > 1 - m.load_from_source! + m.load_from_source! end end mode = ThreadViewMode.new t, @hidden_labels, self BufferManager.spawn t.subj, mode BufferManager.draw_screen 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 + t.remove_label :unread + Index.save_thread t + update_text_for_line curpos UpdateManager.relay self, :read, t.first when_done.call if when_done end end @@ -159,19 +162,19 @@ select t, b elsif b # no next thread. call the block anyways b.call end end - + def handle_single_message_labeled_update sender, m - ## no need to do anything different here; we don't differentiate + ## no need to do anything different here; we don't differentiate ## messages from their containing threads handle_labeled_update sender, m end def handle_labeled_update sender, m - if(t = thread_containing(m)) + if(t = thread_containing(m)) l = @lines[t] or return update_text_for_line l elsif is_relevant?(m) add_or_unhide m end @@ -271,13 +274,13 @@ t.remove_label :starred UpdateManager.relay self, :unstarred, t.first regen_text end end - end + end - def toggle_starred + def toggle_starred t = cursor_thread or return undo = actually_toggle_starred t UndoManager.register "toggling thread starred status", undo, lambda { Index.save_thread t } update_text_for_line curpos cursor_down @@ -360,11 +363,11 @@ UpdateManager.relay self, :undeleted, t.first end end end - def toggle_archived + def toggle_archived t = cursor_thread or return undo = actually_toggle_archived t UndoManager.register "deleting/undeleting thread #{t.first.id}", undo, lambda { update_text_for_line curpos }, lambda { Index.save_thread t } update_text_for_line curpos @@ -471,34 +474,46 @@ BufferManager.clear @flush_id end ## m-m-m-m-MULTI-KILL def multi_kill threads - UndoManager.register "killing #{threads.size.pluralize 'thread'}" do + UndoManager.register "killing/unkilling #{threads.size.pluralize 'threads'}" do threads.each do |t| - t.remove_label :killed - add_or_unhide t.first + if t.toggle_label :killed + add_or_unhide t.first + else + hide_thread t + end + end.each do |t| + UpdateManager.relay self, :labeled, t.first Index.save_thread t end regen_text end threads.each do |t| - t.apply_label :killed - hide_thread t + if t.toggle_label :killed + hide_thread t + else + add_or_unhide t.first + end + end.each do |t| + # send 'labeled'... this might be more specific + UpdateManager.relay self, :labeled, t.first + Index.save_thread t end + killed, unkilled = threads.partition { |t| t.has_label? :killed }.map(&:size) + BufferManager.flash "#{killed.pluralize 'thread'} killed, #{unkilled} unkilled" regen_text - BufferManager.flash "#{threads.size.pluralize 'thread'} killed." - threads.each { |t| Index.save_thread t } end def cleanup UpdateManager.unregister self if @load_thread - @load_thread.kill + @load_thread.kill BufferManager.clear @mbid if @mbid sleep 0.1 # TODO: necessary? BufferManager.erase_flash end dirty_threads = @mutex.synchronize { (@threads + @hidden_threads.keys).select { |t| t.dirty? } } @@ -510,11 +525,11 @@ t = cursor_thread or return @mutex.synchronize { @tags.toggle_tag_for t } update_text_for_line curpos cursor_down end - + def toggle_tagged_all @mutex.synchronize { @threads.each { |t| @tags.toggle_tag_for t } } regen_text end @@ -540,11 +555,11 @@ old_labels = thread.labels pos = curpos keepl, modifyl = thread.labels.partition { |t| speciall.member? t } - user_labels = BufferManager.ask_for_labels :label, "Labels for thread: ", modifyl, @hidden_labels + user_labels = BufferManager.ask_for_labels :label, "Labels for thread: ", modifyl.sort_by {|x| x.to_s}, @hidden_labels return unless user_labels thread.labels = Set.new(keepl) + user_labels user_labels.each { |l| LabelManager << l } update_text_for_line curpos @@ -753,11 +768,11 @@ end end def update_text_for_line l return unless l # not sure why this happens, but it does, occasionally - + need_update = false @mutex.synchronize do @size_widgets[l] = size_widget_for_thread @threads[l] @date_widgets[l] = date_widget_for_thread @threads[l] @@ -790,12 +805,12 @@ new = {} seen = {} authors = t.map do |m, *o| next unless m && m.from new[m.from] ||= m.has_label?(:unread) - next if seen[m.from.mediumname] - seen[m.from.mediumname] = true + next if seen[m.from] + seen[m.from] = true m.from end.compact result = [] authors.each do |a| @@ -847,11 +862,11 @@ name[0 ... (from_width - cur_width)] else if last name[0 ... (from_width - cur_width)] else - name[0 ... (from_width - cur_width - 1)] + "," + name[0 ... (from_width - cur_width - 1)] + "," end end cur_width += abbrev.display_length @@ -870,31 +885,35 @@ :index_draft_color elsif t.has_label?(:unread) :index_new_color elsif starred :index_starred_color - else + elsif Colormap.sym_is_defined(:index_subject_color) + :index_subject_color + else :index_old_color end size_padding = @size_widget_width - size_widget.display_length size_widget_text = sprintf "%#{size_padding}s%s", "", size_widget date_padding = @date_widget_width - date_widget.display_length date_widget_text = sprintf "%#{date_padding}s%s", "", date_widget - [ + [ [:tagged_color, @tags.tagged?(t) ? ">" : " "], [:date_color, date_widget_text], [:starred_color, (starred ? "*" : " ")], ] + from + [ - [subj_color, size_widget_text], + [:size_widget_color, size_widget_text], [:to_me_color, t.labels.member?(:attachment) ? "@" : " "], [:to_me_color, dp ? ">" : (p ? '+' : " ")], ] + - (t.labels - @hidden_labels).map { |label| [:label_color, "#{label} "] } + + (t.labels - @hidden_labels).sort_by {|x| x.to_s}.map { + |label| [Colormap.sym_is_defined("label_#{label}_color".to_sym) || :label_color, "#{label} "] + } + [ [subj_color, t.subj + (t.subj.empty? ? "" : " ")], [:snippet_color, t.snippet], ] end