class Redwood::EditMessageAsyncMode

Public Class Methods

new(parent_edit_mode, file_path, msg_subject) click to toggle source
Calls superclass method
# File lib/sup/modes/edit_message_async_mode.rb, line 26
def initialize parent_edit_mode, file_path, msg_subject
  @parent_edit_mode = parent_edit_mode
  @file_path = file_path
  @orig_mtime = File.mtime @file_path

  @text = ["ASYNC MESSAGE EDIT",
           "", "Your message with subject:",  msg_subject, "is saved in a file:", "", @file_path, "",
           "You can edit your message in the editor of your choice and continue to",
           "use sup while you edit your message.", "",
           "Press <Enter> to have the file path copied to the clipboard.", "",
           "When you have finished editing, select this buffer and press 'E'.",]
  run_async_hook()
  super()
end

Public Instance Methods

[](i) click to toggle source
# File lib/sup/modes/edit_message_async_mode.rb, line 43
def [] i
  @text[i]
end
killable?() click to toggle source
# File lib/sup/modes/edit_message_async_mode.rb, line 47
def killable?
  if file_being_edited?
    if !BufferManager.ask_yes_or_no("It appears the file is still being edited. Are you sure?")
      return false
    end
  end

  @parent_edit_mode.edit_message_async_resume true
  true
end
lines() click to toggle source
# File lib/sup/modes/edit_message_async_mode.rb, line 41
def lines; @text.length end
unsaved?() click to toggle source
# File lib/sup/modes/edit_message_async_mode.rb, line 58
def unsaved?
  !file_being_edited? && !file_has_been_edited?
end

Protected Instance Methods

edit_finished() click to toggle source
# File lib/sup/modes/edit_message_async_mode.rb, line 64
def edit_finished
  if file_being_edited?
    if !BufferManager.ask_yes_or_no("It appears the file is still being edited. Are you sure?")
      return false
    end
  end

  @parent_edit_mode.edit_message_async_resume
  BufferManager.kill_buffer buffer
  true
end
file_being_edited?() click to toggle source
# File lib/sup/modes/edit_message_async_mode.rb, line 94
def file_being_edited?
  # check for common editor lock files
  vim_lock_file = File.join(File.dirname(@file_path), '.'+File.basename(@file_path)+'.swp')
  emacs_lock_file = File.join(File.dirname(@file_path), '.#'+File.basename(@file_path))

  return true if File.exist?(vim_lock_file) || File.exist?(emacs_lock_file)

  false
end
file_has_been_edited?() click to toggle source
# File lib/sup/modes/edit_message_async_mode.rb, line 104
def file_has_been_edited?
  File.mtime(@file_path) > @orig_mtime
end
path_to_clipboard() click to toggle source
# File lib/sup/modes/edit_message_async_mode.rb, line 76
def path_to_clipboard
  if system("which xsel > /dev/null 2>&1")
    # linux/unix path
    IO.popen('xsel --clipboard --input', 'r+') { |clipboard| clipboard.puts(@file_path) }
    BufferManager.flash "Copied file path to clipboard."
  elsif system("which pbcopy > /dev/null 2>&1")
    # mac path
    IO.popen('pbcopy', 'r+') { |clipboard| clipboard.puts(@file_path) }
    BufferManager.flash "Copied file path to clipboard."
  else
    BufferManager.flash "No way to copy text to clipboard - try installing xsel."
  end
end
run_async_hook() click to toggle source
# File lib/sup/modes/edit_message_async_mode.rb, line 90
def run_async_hook
  HookManager.run("async-edit", {:file_path => @file_path})
end