From: William Morgan Date: Thu, 28 May 2009 14:45:06 +0000 (-0400) Subject: Merge commit 'origin/undo-manager' X-Git-Url: https://git.cworth.org/git?a=commitdiff_plain;h=9478114b592e0ba7917a65804aacd401d21d70c2;p=sup Merge commit 'origin/undo-manager' Conflicts: lib/sup/modes/thread-index-mode.rb --- 9478114b592e0ba7917a65804aacd401d21d70c2 diff --cc lib/sup/modes/thread-index-mode.rb index 56dcdff,6152666..e766e2e --- a/lib/sup/modes/thread-index-mode.rb +++ b/lib/sup/modes/thread-index-mode.rb @@@ -42,8 -42,9 +42,9 @@@ EO k.add :toggle_tagged, "Tag/untag selected thread", 't' k.add :toggle_tagged_all, "Tag/untag all threads", 'T' k.add :tag_matching, "Tag matching threads", 'g' - k.add :apply_to_tagged, "Apply next command to all tagged threads", ';' + k.add :apply_to_tagged, "Apply next command to all tagged threads", '+', '=' k.add :join_threads, "Force tagged threads to be joined into the same thread", '#' + k.add :undo, "Undo the previous action", 'u' end def initialize hidden_labels=[], load_thread_opts={} @@@ -384,29 -450,19 +453,30 @@@ t.apply_label :killed hide_thread t end + regen_text - BufferManager.flash "#{threads.size.pluralize 'Thread'} killed." + BufferManager.flash "#{threads.size.pluralize 'thread'} killed." end - def save - dirty_threads = @mutex.synchronize { (@threads + @hidden_threads.keys).select { |t| t.dirty? } } - return if dirty_threads.empty? + def save background=true + if background + Redwood::reporting_thread("saving thread") { actually_save } + else + actually_save + end + end - 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 + def actually_save + @save_thread_mutex.synchronize do + BufferManager.say("Saving contacts...") { ContactManager.instance.save } + dirty_threads = @mutex.synchronize { (@threads + @hidden_threads.keys).select { |t| t.dirty? } } + next if dirty_threads.empty? + + 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 + end end end end @@@ -466,26 -528,34 +547,38 @@@ end def multi_edit_labels threads - user_labels = BufferManager.ask_for_labels :add_labels, "Add labels: ", [], @hidden_labels + user_labels = BufferManager.ask_for_labels :labels, "Add/remove labels (use -label to remove): ", [], @hidden_labels return unless user_labels - - hl = user_labels.select { |l| @hidden_labels.member? l } + + user_labels.map! { |l| (l.to_s =~ /^-/)? [l.to_s.gsub(/^-?/, '').to_sym, true] : [l, false] } + hl = user_labels.select { |(l,_)| @hidden_labels.member? l } - if hl.empty? - threads.each do |t| - user_labels.each do |(l, to_remove)| - if to_remove - t.remove_label l - else - t.apply_label l - end + unless hl.empty? + BufferManager.flash "'#{hl}' is a reserved label!" + return + end + + old_labels = threads.map { |t| t.labels.dup } + + threads.each do |t| - user_labels.each do |l| - t.apply_label l - LabelManager << l - UpdateManager.relay self, :labeled, t.first ++ user_labels.each do |(l, to_remove)| ++ if to_remove ++ t.remove_label l ++ else ++ t.apply_label l ++ LabelManager << l + end end - user_labels.each { |(l,_)| LabelManager << l } - else - BufferManager.flash "'#{hl}' is a reserved label!" end + regen_text + + UndoManager.register "labeling #{threads.size.pluralize 'thread'}" do + threads.zip(old_labels).map do |t, old_labels| + t.labels = old_labels + UpdateManager.relay self, :labeled, t.first + end + regen_text + end end def reply