From cd4336c03f01f6ba58fae14dacc3a86e9d091fc9 Mon Sep 17 00:00:00 2001 From: wmorgan Date: Mon, 30 Jul 2007 00:55:15 +0000 Subject: [PATCH] refactor label tab-completion code to buffer.rb git-svn-id: svn://rubyforge.org/var/svn/sup/trunk@511 5c8cc53c-5e98-4d25-b20a-d8db53a31250 --- doc/TODO | 2 ++ lib/sup/buffer.rb | 22 ++++++++++++++++++++++ lib/sup/modes/thread-index-mode.rb | 19 ++++--------------- 3 files changed, 28 insertions(+), 15 deletions(-) diff --git a/doc/TODO b/doc/TODO index cdbcf56..3561fc5 100644 --- 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 diff --git a/lib/sup/buffer.rb b/lib/sup/buffer.rb index a14c319..62b582e 100644 --- a/lib/sup/buffer.rb +++ b/lib/sup/buffer.rb @@ -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 diff --git a/lib/sup/modes/thread-index-mode.rb b/lib/sup/modes/thread-index-mode.rb index 8238534..a59bad3 100644 --- a/lib/sup/modes/thread-index-mode.rb +++ b/lib/sup/modes/thread-index-mode.rb @@ -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 -- 2.43.0