Archive of RubyForge sup-talk mailing list
 help / color / mirror / Atom feed
From: marcus-sup@bar-coded.net (Marcus Williams)
Subject: [sup-talk] [PATCH] Alternative View
Date: Tue, 16 Jun 2009 13:42:08 +0100	[thread overview]
Message-ID: <1245156068-sup-7360@tomsk> (raw)

Adds a keypress to toggle to an alternative view in thread index mode.
By default this removes the date, authors and number of threads from the
view leaving more room for labels/snippets

This view is extendable via the alternative-view-widget hook. An example
hook is included in the contrib/hooks directory that implements the
standard sup view as an example. If you use this example your
alternative view will not look any different to the standard sup view.
It is meant to give you a base point for your edits.
---
 contrib/hooks/alternate-view-widget.rb |   39 ++++++++++++++++++++++
 lib/sup/modes/thread-index-mode.rb     |   56 ++++++++++++++++++-------------
 2 files changed, 71 insertions(+), 24 deletions(-)
 create mode 100644 contrib/hooks/alternate-view-widget.rb

diff --git a/contrib/hooks/alternate-view-widget.rb b/contrib/hooks/alternate-view-widget.rb
new file mode 100644
index 0000000..cf936fd
--- /dev/null
+++ b/contrib/hooks/alternate-view-widget.rb
@@ -0,0 +1,39 @@
+# This hook recreates the standard sup view as the alternate view
+# Note that this will mean there is no difference when toggling 
+# between the standard and alternate views in sup. This is meant to
+# serve as a starting point for your own view
+
+date_width = Time::TO_NICE_S_MAX_LEN
+date = thread.date.to_nice_s
+starred = thread.has_label? :starred
+    
+dp = thread.direct_participants.any? { |p| AccountManager.is_account? p }
+p = dp || thread.participants.any? { |p| AccountManager.is_account? p }
+    
+snippet = thread.snippet + (thread.snippet.empty? ? "" : "...")
+
+subj_color =
+  if thread.has_label?(:draft)
+    :index_draft_color
+  elsif thread.has_label?(:unread)
+    :index_new_color
+  elsif starred
+    :index_starred_color
+  else 
+    :index_old_color
+  end
+
+[ 
+  [:tagged_color, tagged ? ">" : " "],
+  [:none, sprintf("%#{date_width}s", date)],
+     (starred ? [:starred_color, "*"] : [:none, " "]),
+] + from +
+[
+  [subj_color, size_widget_text],
+  [:to_me_color, thread.labels.member?(:attachment) ? "@" : " "],
+  [:to_me_color, dp ? ">" : (p ? '+' : " ")],
+] + (thread.labels - hidden_labels).map { |label| [:label_color, "#{label} "] } +
+[
+  [subj_color, thread.subj + (thread.subj.empty? ? "" : " ")],
+  [:snippet_color, snippet],
+]
diff --git a/lib/sup/modes/thread-index-mode.rb b/lib/sup/modes/thread-index-mode.rb
index 5fa4f4c..9124dbd 100644
--- a/lib/sup/modes/thread-index-mode.rb
+++ b/lib/sup/modes/thread-index-mode.rb
@@ -8,6 +8,15 @@ class ThreadIndexMode < LineCursorMode
   MIN_FROM_WIDTH = 15
   LOAD_MORE_THREAD_NUM = 20
 
+  HookManager.register "alternate-view-widget", <<EOS
+Generates the per-thread view for each thread.
+Variables:
+  thread: The message thread to be formatted.
+  hidden_labels: the hidden label list
+  tagged: true if this thread is tagged
+  from: the sup default from/author list
+  size_widget_text: the size widget text (from hook or default sup size)
+EOS
   HookManager.register "index-mode-size-widget", <<EOS
 Generates the per-thread size widget for each thread.
 Variables:
@@ -45,7 +54,7 @@ EOS
     k.add :apply_to_tagged, "Apply next command to all tagged threads", '+', '='
     k.add :join_threads, "Force tagged threads to be joined into the same thread", '#'
     k.add :undo, "Undo the previous action", 'u'
-    k.add :toggle_minimalist, "Toggle minimalist view", '~'
+    k.add :toggle_alternative_view, "Toggle alternative view", '~'
   end
 
   def initialize hidden_labels=[], load_thread_opts={}
@@ -63,7 +72,7 @@ EOS
     @hidden_labels = hidden_labels + LabelManager::HIDDEN_RESERVED_LABELS
     @date_width = DATE_WIDTH
 
-    @minimal = false
+    @alternative = false
 
     @interrupt_search = false
     
@@ -264,8 +273,8 @@ EOS
     end
   end  
 
-  def toggle_minimalist 
-    @minimal = !@minimal
+  def toggle_alternative_view 
+    @alternative= !@alternative
     regen_text
   end
 
@@ -841,26 +850,8 @@ protected
 
     size_widget_text = sprintf "%#{ @size_widget_width}s", size_widget
 
-
-    if @minimal
-      if size_widget!=""
-        size_widget_text = "+" 
-      else
-        size_widget_text = " " 
-      end
-      line = []
-    else
-      line =  [ 
-                [:tagged_color, @tags.tagged?(t) ? ">" : " "],
-                [:none, sprintf("%#{@date_width}s", date)],
-                (starred ? [:starred_color, "*"] : [:none, " "]),
-              ] + from
-    end
-
-
-    line +
-    [
-      [subj_color, size_widget_text],
+    alternateView = [
+      [subj_color, @alternative?(size_widget!=""?"+":" "):size_widget_text],
       [:to_me_color, t.labels.member?(:attachment) ? "@" : " "],
       [:to_me_color, dp ? ">" : (p ? '+' : " ")],
     ] +
@@ -869,6 +860,23 @@ protected
       [subj_color, t.subj + (t.subj.empty? ? "" : " ")],
       [:snippet_color, snippet],
     ]
+
+    defaultView = [ 
+      [:tagged_color, @tags.tagged?(t) ? ">" : " "],
+      [:none, sprintf("%#{@date_width}s", date)],
+         (starred ? [:starred_color, "*"] : [:none, " "]),
+    ] + from + alternateView
+
+    alternateView = [
+      [:tagged_color, @tags.tagged?(t) ? ">" : " "],
+    ] + alternateView
+
+
+    if @alternative
+      HookManager.run("alternate-view-widget", :thread => t, :hidden_labels => @hidden_labels, :tagged => @tags.tagged?(t)?true:false, :from => from, :size_widget_text => size_widget_text) || alternateView
+    else
+      defaultView
+    end
   end
 
   def dirty?; @mutex.synchronize { (@hidden_threads.keys + @threads).any? { |t| t.dirty? } } end
-- 
1.5.4.1


                 reply	other threads:[~2009-06-16 12:42 UTC|newest]

Thread overview: [no followups] expand[flat|nested]  mbox.gz  Atom feed

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=1245156068-sup-7360@tomsk \
    --to=marcus-sup@bar-coded.net \
    /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