]> git.cworth.org Git - sup/commitdiff
improved handling of killing buffers. buffers now check with the mode
authorwmorgan <wmorgan@5c8cc53c-5e98-4d25-b20a-d8db53a31250>
Sun, 10 Dec 2006 19:11:40 +0000 (19:11 +0000)
committerwmorgan <wmorgan@5c8cc53c-5e98-4d25-b20a-d8db53a31250>
Sun, 10 Dec 2006 19:11:40 +0000 (19:11 +0000)
(via #killable?) before killing. inbox-mode always returns false.

also improved ask_yes_or_no. three outputs: yes, no, and nil (cancel).

git-svn-id: svn://rubyforge.org/var/svn/sup/trunk@68 5c8cc53c-5e98-4d25-b20a-d8db53a31250

bin/sup
lib/sup/buffer.rb
lib/sup/mode.rb
lib/sup/modes/edit-message-mode.rb
lib/sup/modes/inbox-mode.rb
lib/sup/modes/resume-mode.rb

diff --git a/bin/sup b/bin/sup
index f8e50b7a591697d6f22e03350ea5e73891e76857..003e8f5b7cc553b3ef8080d94c0f1339dd61a723 100644 (file)
--- a/bin/sup
+++ b/bin/sup
@@ -132,7 +132,7 @@ begin
         when :roll_buffers_backwards
           bm.roll_buffers_backwards
         when :kill_buffer
-          bm.kill_buffer bm.focus_buf unless bm.focus_buf.mode.is_a? InboxMode
+          bm.kill_buffer bm.focus_buf if bm.focus_buf.mode.killable?
         when :list_buffers
           bm.spawn_unless_exists("Buffer List") { BufferListMode.new }
         when :list_contacts
@@ -187,10 +187,12 @@ if $exception
   case $exception
   when IndexError
     $stderr.puts <<EOS
-An error occurred while parsing a message from source "#{$exception.source}".
+An error occurred while parsing a message from source:
+   #{$exception.source}.
 Typically, this means that the source has been modified in some
-way which has rendered the messages invalid. For example, if it's an mbox
-file, you may have read or deleted messages using another client.
+way which has rendered the messages invalid. For example, if it's
+an mbox file, you may have read or deleted messages using another
+mail client.
 
 You must rebuild the index for this source. Please run:
   sup-import --rebuild #{$exception.source}
index 90ce22a1526d6d0d35e7ec1dc25a1027b4317edf..d7a92113293b635bcfe0e49bc1c4d3b417dc0631 100644 (file)
@@ -337,7 +337,15 @@ class BufferManager
   end
 
   def ask_yes_or_no question
-    [?y, ?Y].member? ask_getch(question, "ynYN")
+    r = ask_getch(question, "ynYN")
+    case r
+    when ?y, ?Y
+      true
+    when nil
+      nil
+    else
+      false
+    end
   end
 
   def draw_minibuf
index b90401f1a5a4cafbf4eff76340fbcd6f4862d57a..91bdbe6c059d7791b28832d825fd269809caa600 100644 (file)
@@ -23,6 +23,7 @@ class Mode
     end
   end
 
+  def killable?; true; end
   def draw; end
   def focus; end
   def blur; end
index ec846fee98be4208e70315358de5db2aea35ea07..7e8b99dda331bce257a18a558f67d43c518c5801 100644 (file)
@@ -101,7 +101,7 @@ protected
   end
 
   def send_message
-    return false unless @edited || BufferManager.ask_yes_or_no("message unedited---really send?")
+    return false unless @edited || BufferManager.ask_yes_or_no("Message unedited. Really send?")
 
     raise "no message id!" unless header["Message-Id"]
     date = Time.now
@@ -127,6 +127,7 @@ protected
     DraftManager.write_draft { |f| write_message f, false }
     BufferManager.kill_buffer buffer
     BufferManager.flash "Saved for later editing."
+    true
   end
 
   def sig_lines
index f38847a963a255d3a910f944d61a7467d1758f80..c335758b417a9eb4d1f40c5bd27f4ed0218ea116 100644 (file)
@@ -14,6 +14,8 @@ class InboxMode < ThreadIndexMode
     super [:inbox], [:inbox]
   end
 
+  def killable?; false; end
+
   def archive
     remove_label_and_hide_thread cursor_thread, :inbox
     regen_text
index a1e273c115237e6304d8063d039b6a4f02ac796a..923eb2cb6ad2e44ae66b1a81313c31dce92e2ef3 100644 (file)
@@ -8,26 +8,35 @@ class ResumeMode < ComposeMode
     @header.delete "Date"
     @header["Message-Id"] = gen_message_id # generate a new'n
     regen_text
-    @sent = false
+    @safe = false
+  end
+
+  def killable?
+    unless @safe
+      case BufferManager.ask_yes_or_no "Discard draft?"
+      when true
+        DraftManager.discard @id
+        BufferManager.flash "Draft discarded."
+        true
+      when false
+        BufferManager.flash "Draft saved."
+        true
+      else
+        false
+      end
+    end
   end
 
   def send_message
     if super
       DraftManager.discard @id 
-      @sent = true
+      @safe = true
     end
   end
 
-  def cleanup
-    unless @sent
-      if BufferManager.ask_yes_or_no "discard draft?"
-        DraftManager.discard @id
-        BufferManager.flash "Draft discarded."
-      else
-        BufferManager.flash "Draft saved."
-      end
-      super
-    end
+  def save_as_draft
+    @safe = true
+    DraftManager.discard @id if super
   end
 end