]> git.cworth.org Git - sup/commitdiff
refactor label tab-completion code to buffer.rb
authorwmorgan <wmorgan@5c8cc53c-5e98-4d25-b20a-d8db53a31250>
Mon, 30 Jul 2007 00:55:15 +0000 (00:55 +0000)
committerwmorgan <wmorgan@5c8cc53c-5e98-4d25-b20a-d8db53a31250>
Mon, 30 Jul 2007 00:55:15 +0000 (00:55 +0000)
git-svn-id: svn://rubyforge.org/var/svn/sup/trunk@511 5c8cc53c-5e98-4d25-b20a-d8db53a31250

doc/TODO
lib/sup/buffer.rb
lib/sup/modes/thread-index-mode.rb

index cdbcf56f572fc6b6325debaee97135b38b526952..3561fc50b8c505f4c17c50390ab7b33bd3f4b97b 100644 (file)
--- a/doc/TODO
+++ b/doc/TODO
@@ -1,5 +1,7 @@
 for next release
 ----------------
+_ BufferManager#ask_for_labels opens up label-list-mode if empty
+_ tab completion for mid-text cursors
 _ forward attachments
 _ messages as attachments
 _ individual labeling in thread-view-mode
index a14c319eb3ddc57cae1fe2dd82b4b6a9d050932c..62b582e958c565d0eb4736486f34d9eb3bf037a5 100644 (file)
@@ -392,6 +392,28 @@ class BufferManager
     answer || []
   end
 
+  ## returns an array of labels
+  def ask_for_labels domain, question, default_labels, forbidden_labels=[]
+    default = default_labels.join(" ")
+    default += " " unless default.empty?
+
+    applyable_labels = (LabelManager.applyable_labels - forbidden_labels).map { |l| LabelManager.string_for l }.sort_by { |s| s.downcase }
+
+    answer = BufferManager.ask_many_with_completions domain, question, applyable_labels, default
+
+    return unless answer
+
+    user_labels = answer.split(/\s+/).map { |l| l.intern }
+    user_labels.each do |l|
+      if forbidden_labels.include?(l) || LabelManager::RESERVED_LABELS.include?(l)
+        BufferManager.flash "'#{l}' is a reserved label!"
+        return
+      end
+    end
+    user_labels
+  end
+
+
   def ask domain, question, default=nil, &block
     raise "impossible!" if @asking
     @asking = true
index 8238534d7c0d65ee467d22447e93ab3391b4e668..a59bad356f28e448d7fb98e2a559dca1673334c7 100644 (file)
@@ -288,23 +288,12 @@ class ThreadIndexMode < LineCursorMode
     thread = @threads[curpos] or return
     speciall = (@hidden_labels + LabelManager::RESERVED_LABELS).uniq
     keepl, modifyl = thread.labels.partition { |t| speciall.member? t }
-    cur_label_string = modifyl.join(" ")
-    cur_label_string += " " unless cur_label_string.empty?
 
-    applyable_labels = (LabelManager.applyable_labels - @hidden_labels).map { |l| LabelManager.string_for l }.sort_by { |s| s.downcase }
+    user_labels = BufferManager.ask_for_labels :label, "Labels for thread: ", modifyl, @hidden_labels
 
-    answer = BufferManager.ask_many_with_completions :label, "Labels for thread: ", applyable_labels, cur_label_string
-
-    return unless answer
-    user_labels = answer.split(/\s+/).map { |l| l.intern }
-    
-    hl = user_labels.select { |l| speciall.member? l }
-    if hl.empty?
-      thread.labels = keepl + user_labels
-      user_labels.each { |l| LabelManager << l }
-    else
-      BufferManager.flash "'#{hl}' is a reserved label!"
-    end
+    return unless user_labels
+    thread.labels = keepl + user_labels
+    user_labels.each { |l| LabelManager << l }
     update_text_for_line curpos
   end