]> git.notmuchmail.org Git - sup/commitdiff
Merge branch 'undo-manager' into next
authorWilliam Morgan <wmorgan-sup@masanjin.net>
Mon, 18 May 2009 14:22:15 +0000 (07:22 -0700)
committerWilliam Morgan <wmorgan-sup@masanjin.net>
Mon, 18 May 2009 14:26:29 +0000 (07:26 -0700)
Conflicts:

lib/sup/modes/thread-index-mode.rb

1  2 
lib/sup/modes/thread-index-mode.rb

index b44dc1889f623e30b32ca095cf3c0249cf6b0494,6152666d2e8398e1e76a1d9085b7ac7838965993..055484e838059a8117ef8d0b4b3b79bc9e4f30a4
@@@ -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
    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