]> git.notmuchmail.org Git - sup/commitdiff
Merge commit 'origin/undo-manager'
authorWilliam Morgan <wmorgan-sup@masanjin.net>
Thu, 28 May 2009 14:45:06 +0000 (10:45 -0400)
committerWilliam Morgan <wmorgan-sup@masanjin.net>
Thu, 28 May 2009 14:47:35 +0000 (10:47 -0400)
Conflicts:

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

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

diff --cc README.txt
Simple merge
diff --cc lib/sup.rb
Simple merge
index 56dcdff2df5f139c0129c984b0f02696d6d2cd70,6152666d2e8398e1e76a1d9085b7ac7838965993..e766e2efc7e1a4d261eaf03dc479bc4d7043ec3b
@@@ -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={}
        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
    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