[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[sup-devel] BRANCH: rerun_crypto_selector



I noticed that if I changed the reply-to selector that my
crypto-selector hook wasn't getting called, so I've made a branch
called rerun_crypto_selector (and merged it to next). From the main
commit message in the branch:

    Re-run the crypto selector hook after message changes.

    The crypto-selector hook will be re-run after the message is edited,
    or after the recipients change due to changing the "Reply to"
    selector in reply-mode. So when the recipients change, the default
    selector will also change.

    However, if the user has manually changed the crypto selector then the
    hook will not be re-run, so as to avoid over-riding the user's choice.

I've also updated the wiki as the headers["to"] bit is sometimes an
array. Working much nicer now. I've pasted in the two patches at the
end for those who like to review them in the email.

Hamish Downer




commit f111201a469fd1c1dccb143e089cc623ce35025d
Author: Hamish Downer <dmishd@gmail.com>
Date:   Tue Feb 8 23:53:13 2011 +0000

    added @changed_by_user to HorizontalSelector

diff --git a/lib/sup/horizontal-selector.rb b/lib/sup/horizontal-selector.rb
index 35a028e..e6ec6dc 100644
--- a/lib/sup/horizontal-selector.rb
+++ b/lib/sup/horizontal-selector.rb
@@ -1,7 +1,7 @@
 module Redwood

 class HorizontalSelector
-  attr_accessor :label
+  attr_accessor :label, :changed_by_user

   def initialize label, vals, labels,
base_color=:horizontal_selector_unselected_color,
selected_color=:horizontal_selector_selected_color
     @label = label
@@ -10,6 +10,7 @@ class HorizontalSelector
     @base_color = base_color
     @selected_color = selected_color
     @selection = 0
+    @changed_by_user = false
   end

   def set_to val; @selection = @vals.index(val) end
@@ -37,10 +38,12 @@ class HorizontalSelector

   def roll_left
     @selection = (@selection - 1) % @labels.length
+    @changed_by_user = true
   end

   def roll_right
     @selection = (@selection + 1) % @labels.length
+    @changed_by_user = true
   end
 end






commit 3cbccb471fc73b1593374ef8efea1a22ba237d89
Author: Hamish Downer <dmishd@gmail.com>
Date:   Wed Feb 9 18:58:30 2011 +0000

    Re-run the crypto selector hook after message changes.

    The crypto-selector hook will be re-run after the message is edited,
    or after the recipients change due to changing the "Reply to"
    selector in reply-mode. So when the recipients change, the default
    selector will also change.

    However, if the user has manually changed the crypto selector then the
    hook will not be re-run, so as to avoid over-riding the user's choice.

diff --git a/lib/sup/modes/edit-message-mode.rb
b/lib/sup/modes/edit-message-mode.rb
index 734a879..6c2d61c 100644
--- a/lib/sup/modes/edit-message-mode.rb
+++ b/lib/sup/modes/edit-message-mode.rb
@@ -179,6 +179,7 @@ EOS
     header, @body = parse_file @file.path
     @header = header - NON_EDITABLE_HEADERS
     handle_new_text @header, @body
+    rerun_crypto_selector_hook
     update

     @edited
@@ -215,6 +216,12 @@ EOS

 protected

+  def rerun_crypto_selector_hook
+    if @crypto_selector && !@crypto_selector.changed_by_user
+      HookManager.run "crypto-mode", :header => @header, :body =>
@body, :crypto_selector => @crypto_selector
+    end
+  end
+
   def mime_encode string
     string = [string].pack('M') # basic quoted-printable
     string.gsub!(/=\n/,'')      # .. remove trailing newline
diff --git a/lib/sup/modes/reply-mode.rb b/lib/sup/modes/reply-mode.rb
index 079e4de..ccdf371 100644
--- a/lib/sup/modes/reply-mode.rb
+++ b/lib/sup/modes/reply-mode.rb
@@ -165,6 +165,7 @@ protected
     if @headers[@type_selector.val] != self.header
       self.header = @headers[@type_selector.val]
       self.body = @bodies[@type_selector.val] unless @edited
+      rerun_crypto_selector_hook
       update
     end
   end
@@ -174,6 +175,7 @@ protected
     if @headers[@type_selector.val] != self.header
       self.header = @headers[@type_selector.val]
       self.body = @bodies[@type_selector.val] unless @edited
+      rerun_crypto_selector_hook
       update
     end
   end
_______________________________________________
Sup-devel mailing list
Sup-devel@rubyforge.org
http://rubyforge.org/mailman/listinfo/sup-devel