Class: Redwood::EditMessageMode
Constant Summary
collapse
%w(From To Cc Bcc Subject)
%w(To Cc Bcc)
%w(Message-Id Date)
Constants inherited
from ScrollMode
ScrollMode::COL_JUMP
Instance Attribute Summary collapse
#curpos
Attributes inherited from ScrollMode
#botline, #leftcol, #topline
Attributes inherited from Mode
#buffer
Instance Method Summary
collapse
#draw
Methods inherited from ScrollMode
#at_bottom?, #at_top?, #cancel_search!, #col_left, #col_right, #continue_search_in_buffer, #draw, #ensure_mode_validity, #in_search?, #jump_to_col, #jump_to_end, #jump_to_left, #jump_to_line, #jump_to_start, #line_down, #line_up, #page_down, #page_up, #resize, #rightcol, #search_goto_line, #search_in_buffer, #search_start_line
Methods inherited from Mode
#blur, #cancel_search!, #cleanup, #draw, #focus, #handle_input, #help_text, #in_search?, load_all_modes, make_name, #name, register_keymap, #resize, #resolve_input, #save_to_file
Constructor Details
Returns a new instance of EditMessageMode.
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
|
# File 'lib/sup/modes/edit-message-mode.rb', line 53
def initialize opts={}
@header = opts.delete(:header) || {}
@header_lines = []
@body = opts.delete(:body) || []
@body += sig_lines if $config[:edit_signature]
@attachments = []
@message_id = "<#{Time.now.to_i}-sup-#{rand 10000}@#{Socket.gethostname}>"
@edited = false
@skip_top_rows = opts[:skip_top_rows] || 0
HookManager.run "before-edit", :header => @header, :body => @body
super opts
regen_text
end
|
Instance Attribute Details
Returns the value of attribute body.
38
39
40
|
# File 'lib/sup/modes/edit-message-mode.rb', line 38
def body
@body
end
|
Returns the value of attribute header.
38
39
40
|
# File 'lib/sup/modes/edit-message-mode.rb', line 38
def
@header
end
|
Returns the value of attribute status.
37
38
39
|
# File 'lib/sup/modes/edit-message-mode.rb', line 37
def status
@status
end
|
Instance Method Details
72
|
# File 'lib/sup/modes/edit-message-mode.rb', line 72
def [] i; @text[i] end
|
#attach_file ⇒ Object
116
117
118
119
120
121
|
# File 'lib/sup/modes/edit-message-mode.rb', line 116
def attach_file
fn = BufferManager.ask_for_filename :attachment, "File name (enter for browser): "
return unless fn
@attachments << Pathname.new(fn)
update
end
|
#delete_attachment ⇒ Object
123
124
125
126
127
128
129
|
# File 'lib/sup/modes/edit-message-mode.rb', line 123
def delete_attachment
i = (curpos - @skip_top_rows) - @attachment_lines_offset
if i >= 0 && i < @attachments.size && BufferManager.ask_yes_or_no("Delete attachment #{@attachments[i]}?")
@attachments.delete_at i
update
end
end
|
86
|
# File 'lib/sup/modes/edit-message-mode.rb', line 86
def edit_cc; edit_field "Cc" end
|
#edit_message ⇒ Object
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
|
# File 'lib/sup/modes/edit-message-mode.rb', line 89
def edit_message
@file = Tempfile.new "sup.#{self.class.name.gsub(/.*::/, '').camel_to_hyphy}"
@file.puts (@header - NON_EDITABLE_HEADERS).first
@file.puts
@file.puts @body
@file.close
editor = $config[:editor] || ENV['EDITOR'] || "/usr/bin/vi"
mtime = File.mtime @file.path
BufferManager.shell_out "#{editor} #{@file.path}"
@edited = true if File.mtime(@file.path) > mtime
return @edited unless @edited
, @body = parse_file @file.path
@header = - NON_EDITABLE_HEADERS
handle_new_text @header, @body
update
@edited
end
|
#edit_message_or_field ⇒ Object
77
78
79
80
81
82
83
|
# File 'lib/sup/modes/edit-message-mode.rb', line 77
def edit_message_or_field
if (curpos - @skip_top_rows) >= @header_lines.length
edit_message
else
edit_field @header_lines[curpos - @skip_top_rows]
end
end
|
#edit_subject ⇒ Object
87
|
# File 'lib/sup/modes/edit-message-mode.rb', line 87
def edit_subject; edit_field "Subject" end
|
85
|
# File 'lib/sup/modes/edit-message-mode.rb', line 85
def edit_to; edit_field "To" end
|
#handle_new_text(header, body) ⇒ Object
75
|
# File 'lib/sup/modes/edit-message-mode.rb', line 75
def handle_new_text , body; end
|
#killable? ⇒ Boolean
112
113
114
|
# File 'lib/sup/modes/edit-message-mode.rb', line 112
def killable?
!edited? || BufferManager.ask_yes_or_no("Discard message?")
end
|
71
|
# File 'lib/sup/modes/edit-message-mode.rb', line 71
def lines; @text.length end
|