]> git.notmuchmail.org Git - sup/commitdiff
Added undo for label edit
authorMike Stipicevic <stipim@rpi.edu>
Mon, 16 Feb 2009 05:11:28 +0000 (00:11 -0500)
committerWilliam Morgan <wmorgan-sup@masanjin.net>
Mon, 16 Mar 2009 12:00:00 +0000 (08:00 -0400)
lib/sup/modes/thread-index-mode.rb

index 159839d2d3a08e912e662c9887ab3b19d286b8a5..f28302bb2e49b85ec3fbb735de63c6f14c0ced43 100644 (file)
@@ -509,6 +509,10 @@ EOS
   def edit_labels
     thread = cursor_thread or return
     speciall = (@hidden_labels + LabelManager::RESERVED_LABELS).uniq
+
+    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
@@ -517,6 +521,15 @@ EOS
     thread.labels = keepl + user_labels
     user_labels.each { |l| LabelManager << l }
     update_text_for_line curpos
+
+    undo = lambda{
+      thread.labels = old_labels
+      update_text_for_line pos
+      UpdateManager.relay self, :labeled, thread.first
+    }
+
+    UndoManager.register("labeling thread #{thread.first.id}", undo)
+
     UpdateManager.relay self, :labeled, thread.first
   end
 
@@ -526,8 +539,18 @@ EOS
     
     hl = user_labels.select { |l| @hidden_labels.member? l }
     if hl.empty?
-      threads.each { |t| user_labels.each { |l| t.apply_label l } }
-      user_labels.each { |l| LabelManager << l }
+      undo = threads.map { |t| old_labels = t.labels
+        user_labels.each { |l| t.apply_label l }
+        ## UpdateManager or some other regresh mechanism?
+        UpdateManager.relay self, :labeled, t.first
+        lambda {
+          t.labels = old_labels
+          UpdateManager.relay self, :labeled, t.first
+        }
+      }
+    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!"
     end