Archive of RubyForge sup-devel mailing list
 help / color / mirror / Atom feed
From: Tero Tilus <tero@tilus.net>
To: Sup developers <sup-devel@rubyforge.org>
Subject: [sup-devel] [PATCH] I can haz moar hooks: attachment-mentioned, index-mode-date-widget
Date: Fri, 22 Jan 2010 03:32:00 +0200	[thread overview]
Message-ID: <1264123657-sup-4929@tilus.net> (raw)
In-Reply-To: <1261402666-sup-8068@masanjin.net>

[-- Attachment #1: Type: text/plain, Size: 451 bytes --]

William Morgan, 2009-12-21 15:38:
> Reformatted excerpts from Tero Tilus's message of 2009-12-19:
> > The detect-missing-attachment hook is pretty self evident but what you
> > had in mind for the dates?  Formatter for the thread-index-mode date
> > widget maybe?
> 
> Exactly. We already have index-mode-size-widget, so
> index-mode-date-widget would be analogous.

Here they are, finally...

-- 
Tero Tilus ## 050 3635 235 ## http://tero.tilus.net/

[-- Attachment #2: 0001-index-mode-date-widget-hook-for-rendering-dates-in-t.patch --]
[-- Type: application/octet-stream, Size: 4070 bytes --]

From acf0b4d340dd6a00b3f1601687ac8df0fe6943d2 Mon Sep 17 00:00:00 2001
From: Tero Tilus <tero@tilus.net>
Date: Fri, 22 Jan 2010 02:56:17 +0200
Subject: [PATCH] index-mode-date-widget hook for rendering dates in thread index

Signed-off-by: Tero Tilus <tero@tilus.net>
---
 lib/sup/modes/thread-index-mode.rb |   39 ++++++++++++++++++++++++++++-------
 1 files changed, 31 insertions(+), 8 deletions(-)

diff --git a/lib/sup/modes/thread-index-mode.rb b/lib/sup/modes/thread-index-mode.rb
index a6bb2b9..208247c 100644
--- a/lib/sup/modes/thread-index-mode.rb
+++ b/lib/sup/modes/thread-index-mode.rb
@@ -16,6 +16,12 @@ Variables:
   thread: The message thread to be formatted.
 EOS
 
+  HookManager.register "index-mode-date-widget", <<EOS
+Generates the per-thread date widget for each thread.
+Variables:
+  thread: The message thread to be formatted.
+EOS
+
   HookManager.register "mark-as-spam", <<EOS
 This hook is run when a thread is marked as spam
 Variables:
@@ -53,10 +59,12 @@ EOS
   def initialize hidden_labels=[], load_thread_opts={}
     super()
     @mutex = Mutex.new # covers the following variables:
-    @threads = {}
+    @threads = []
     @hidden_threads = {}
     @size_widget_width = nil
-    @size_widgets = {}
+    @size_widgets = []
+    @date_widget_width = nil
+    @date_widgets = []
     @tags = Tagger.new self
 
     ## these guys, and @text and @lines, are not covered
@@ -226,6 +234,8 @@ EOS
       @threads = @ts.threads.select { |t| !@hidden_threads[t] }.sort_by { |t| [t.date, t.first.id] }.reverse
       @size_widgets = @threads.map { |t| size_widget_for_thread t }
       @size_widget_width = @size_widgets.max_of { |w| w.display_length }
+      @date_widgets = @threads.map { |t| date_widget_for_thread t }
+      @date_widget_width = @date_widgets.max_of { |w| w.display_length }
     end
     set_cursor_pos @threads.index(old_cursor_thread)||curpos
 
@@ -719,6 +729,10 @@ protected
     HookManager.run("index-mode-size-widget", :thread => t) || default_size_widget_for(t)
   end
 
+  def date_widget_for_thread t
+    HookManager.run("index-mode-date-widget", :thread => t) || default_date_widget_for(t)
+  end
+
   def cursor_thread; @mutex.synchronize { @threads[curpos] }; end
 
   def drop_all_threads
@@ -734,6 +748,7 @@ protected
       @hidden_threads[t] = true
       @threads.delete_at i
       @size_widgets.delete_at i
+      @date_widgets.delete_at i
       @tags.drop_tag_for t
     end
   end
@@ -745,9 +760,12 @@ protected
 
     @mutex.synchronize do
       @size_widgets[l] = size_widget_for_thread @threads[l]
+      @date_widgets[l] = date_widget_for_thread @threads[l]
 
-      ## if the widget size has increased, we need to redraw everyone
-      need_update = @size_widgets[l].size > @size_widget_width
+      ## if a widget size has increased, we need to redraw everyone
+      need_update = 
+        (@size_widgets[l].size > @size_widget_width) or
+        (@date_widgets[l].size > @date_widget_width)
     end
 
     if need_update
@@ -798,9 +816,9 @@ protected
 
   AUTHOR_LIMIT = 5
   def text_for_thread_at line
-    t, size_widget = @mutex.synchronize { [@threads[line], @size_widgets[line]] }
-
-    date = t.date.to_nice_s
+    t, size_widget, date_widget = @mutex.synchronize do
+      [@threads[line], @size_widgets[line], @date_widgets[line]]
+    end
 
     starred = t.has_label? :starred
 
@@ -851,10 +869,11 @@ protected
     snippet = t.snippet + (t.snippet.empty? ? "" : "...")
 
     size_widget_text = sprintf "%#{ @size_widget_width}s", size_widget
+    date_widget_text = sprintf "%#{ @date_widget_width}s", date_widget
 
     [ 
       [:tagged_color, @tags.tagged?(t) ? ">" : " "],
-      [:date_color, sprintf("%#{@date_width}s", date)],
+      [:date_color, date_widget_text],
       (starred ? [:starred_color, "*"] : [:none, " "]),
     ] +
       from +
@@ -883,6 +902,10 @@ private
     end
   end
 
+  def default_date_widget_for t
+    t.date.to_nice_s
+  end
+
   def from_width
     [(buffer.content_width.to_f * 0.2).to_i, MIN_FROM_WIDTH].max
   end
-- 
1.5.6.5


[-- Attachment #3: 0001-mentions-attachments-hook-to-detect-missing-attachme.patch --]
[-- Type: application/octet-stream, Size: 1269 bytes --]

From 1b3d73a0c2f4a5bc082429d146630403d96764f2 Mon Sep 17 00:00:00 2001
From: Tero Tilus <tero@tilus.net>
Date: Fri, 22 Jan 2010 03:24:03 +0200
Subject: [PATCH] mentions-attachments hook to detect missing attachments

---
 lib/sup/modes/edit-message-mode.rb |   12 +++++++++++-
 1 files changed, 11 insertions(+), 1 deletions(-)

diff --git a/lib/sup/modes/edit-message-mode.rb b/lib/sup/modes/edit-message-mode.rb
index 8849271..8c97302 100644
--- a/lib/sup/modes/edit-message-mode.rb
+++ b/lib/sup/modes/edit-message-mode.rb
@@ -40,6 +40,16 @@ Return value:
 	none
 EOS
 
+  HookManager.register "mentions-attachments", <<EOS
+Detects if given message mentions attachments the way it is probable
+that there should be files attached to the message.
+Variables:
+	header: a hash of headers. See 'signature' hook for documentation.
+	body: an array of lines of body text.
+Return value:
+	True if attachments are mentioned.
+EOS
+
   attr_reader :status
   attr_accessor :body, :header
   bool_reader :edited
@@ -444,7 +454,7 @@ private
   end
 
   def mentions_attachments?
-    @body.any? { |l| l =~ /^[^>]/ && l =~ /\battach(ment|ed|ing|)\b/i }
+    HookManager.run "mentions-attachments", :header => @header, :body => @body
   end
 
   def top_posting?
-- 
1.5.6.5


[-- Attachment #4: Type: text/plain, Size: 143 bytes --]

_______________________________________________
Sup-devel mailing list
Sup-devel@rubyforge.org
http://rubyforge.org/mailman/listinfo/sup-devel

       reply	other threads:[~2010-01-22  1:32 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
     [not found] <1261167840-sup-592@orion>
     [not found] ` <1261179239-sup-9258@tilus.net>
     [not found]   ` <1261246334-sup-1438@masanjin.net>
     [not found]     ` <1261276156-sup-5510@tilus.net>
     [not found]       ` <1261402666-sup-8068@masanjin.net>
2010-01-22  1:32         ` Tero Tilus [this message]
2010-02-04  7:06           ` Tero Tilus
2010-02-22  7:22           ` Rich Lane
2010-02-22  8:07             ` Tero Tilus
2010-02-22  8:09               ` Tero Tilus
2010-02-27  8:11                 ` Rich Lane
2010-02-27  8:16           ` Rich Lane

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1264123657-sup-4929@tilus.net \
    --to=tero@tilus.net \
    --cc=sup-devel@rubyforge.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox