defupload_name_for_file(full_path)require"#{ENV['TM_SUPPORT_PATH']}/lib/dialog.rb"# WordPress automatically places files into dated paths
prefix = mode == 'wp' ? '' : Time.now.strftime('%F_')
file = File.basename(full_path)
suggested_name = prefix + file.gsub(/[]+/, '_')
result = Dialog.request_string(:title => "Upload File", :prompt => "Name to use for uploaded file:", :default => suggested_name)
TextMate.exit_discard if result.nil?
[ result, 'Download: ' + result ]
enddefupload_filerequire"#{ENV['TM_SUPPORT_PATH']}/lib/progress.rb"require"#{ENV['TM_SUPPORT_PATH']}/lib/escape.rb"require"#{ENV['TM_SUPPORT_PATH']}/lib/dialog.rb"require'xmlrpc/base64'
choices = ["Upload File and link","Insert Filepath/Filename"]
item = Dialog.request_item(:title => "Make a selection", :prompt => "What should I do with this file?", :items => choices)
TextMate.exit_discard if item.nil?
item = item.split
case item[0]
when"Insert"
print ENV['TM_DROPPED_FILEPATH']
when"Upload"# Makes sure endpoint is determined and elements are parsed
current_password = password
# The packet we will be constructing
data = {}
full_path = ENV['TM_DROPPED_FILEPATH']
upload_name, title = upload_name_for_file(full_path)
data['name'] = upload_name
data['bits'] = XMLRPC::Base64.new(IO.read(full_path))
TextMate.call_with_progress(:title => "Upload File", :message => "Uploading to Server “#{@host}”…") do
begin
result = client.newMediaObject(self.blog_id, self.username, current_password, data)
url = result['url']
if url
caseENV['TM_SCOPE']
when/\.markdown/
print "[${1:#{CGI::escapeHTML title}}](#{url})"else
print %Q{<a href="#{url}" title="${1:#{CGI::escapeHTML title}}">${2:#{CGI::escapeHTML title}}</a>$0}endelseTextMate.exit_show_tool_tip("Error uploading file.")
endrescueXMLRPC::FaultException => e
TextMate.exit_show_tool_tip("Error uploading file. Check your configuration and try again. " + e)
endendendend