From: William Morgan Date: Mon, 18 May 2009 14:22:15 +0000 (-0700) Subject: Merge branch 'undo-manager' into next X-Git-Url: https://git.cworth.org/git?a=commitdiff_plain;h=392847a8e0abba1887ca76e24666eca7492507bd;p=sup Merge branch 'undo-manager' into next Conflicts: lib/sup/modes/thread-index-mode.rb --- 392847a8e0abba1887ca76e24666eca7492507bd diff --cc lib/sup/modes/thread-index-mode.rb index b44dc18,6152666..055484e --- a/lib/sup/modes/thread-index-mode.rb +++ b/lib/sup/modes/thread-index-mode.rb @@@ -448,39 -438,31 +441,42 @@@ EO ## m-m-m-m-MULTI-KILL def multi_kill threads - undo = threads.map do |t| + UndoManager.register "killing #{threads.size.pluralize 'thread'}" do + threads.each do |t| + t.remove_label :killed + add_or_unhide t.first + end + regen_text + end + + threads.each do |t| t.apply_label :killed hide_thread t - thread = t - lambda { thread.remove_label :killed - add_or_unhide thread.first - } end - UndoManager.register("killing #{threads.size} #{threads.size.pluralize 'thread'}", - undo << lambda {regen_text}) + 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 @@@ -553,35 -528,34 +547,39 @@@ 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? - undo = threads.map do |t| - old_labels = t.labels - user_labels.each do |(l, to_remove)| - if to_remove - t.remove_label l - else - t.apply_label l - end - end - ## UpdateManager or some other regresh mechanism? - UpdateManager.relay self, :labeled, t.first - lambda do - t.labels = old_labels - UpdateManager.relay self, :labeled, t.first + 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 ++ user_labels.each do |(l, to_remove)| ++ if to_remove ++ t.remove_label l ++ else ++ t.apply_label l + end + LabelManager << l - UpdateManager.relay self, :labeled, t.first end - user_labels.each { |(l,_)| LabelManager << l } - UndoManager.register("labeling #{threads.size} #{threads.size.pluralize 'thread'}", - undo << lambda { regen_text}) - else - BufferManager.flash "'#{hl}' is a reserved label!" ++ UpdateManager.relay self, :labeled, t.first 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