[sup-talk] [PATCH] Allow multi_edit_labels to remove labels using -lab (the "; l" key binding)

Nicolas Pouillard nicolas.pouillard at gmail.com
Mon Mar 16 14:35:43 EDT 2009


Resent..

---
 lib/sup/modes/thread-index-mode.rb |   19 ++++++++++++++-----
 1 files changed, 14 insertions(+), 5 deletions(-)

diff --git a/lib/sup/modes/thread-index-mode.rb b/lib/sup/modes/thread-index-mode.rb
index 3dd0498..bde61cf 100644
--- a/lib/sup/modes/thread-index-mode.rb
+++ b/lib/sup/modes/thread-index-mode.rb
@@ -448,13 +448,22 @@ EOS
   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 { |t| user_labels.each { |l| t.apply_label l } }
-      user_labels.each { |l| LabelManager << l }
+      threads.each do |t|
+        user_labels.each do |(l, to_remove)|
+          if to_remove
+            t.remove_label l
+          else
+            t.apply_label l
+          end
+        end
+      end
+      user_labels.each { |(l,_)| LabelManager << l }
     else
       BufferManager.flash "'#{hl}' is a reserved label!"
     end

-- 
Nicolas Pouillard


More information about the sup-talk mailing list