Published in: XML
<?xml version="1.0" encoding="UTF-8" ?> <!DOCTYPE plist PUBLIC "-//Apple Computer//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd"> <plist version="1.0"> <dict> <key>name</key> <string>Insert Image</string> <key>uuid</key> <string>B1EB3F7A-2989-4E32-A892-83013991F175</string> <key>input</key> <string>none</string> <key>output</key> <string>afterSelectedText</string> <key>command</key> <string>#!/usr/bin/env ruby abort unless ENV['TM_PROJECT_DIRECTORY'] && ENV['TM_FILEPATH'] SUPPORT = ENV['TM_SUPPORT_PATH'] DIALOG = SUPPORT + '/bin/CocoaDialog.exe' require 'pathname' require 'find' images = [] menu = [] # Find all images within a project and stuff them into # an array (images) of hashes. Find.find(ENV['TM_PROJECT_DIRECTORY']) do |f| file_name = File.basename(f) if /\.(gif|jpg|png)$/ =~ file_name images << { :title => file_name, :path => Pathname.new(f).relative_path_from(Pathname.new(ENV['TM_FILEPATH']).parent).to_s } end end abort if images.empty? images = images.sort_by { |image| image[:title] } # If there are less than 10 images within a project, use # a popup menu; otherwise, use a dropdown. if images.length < 10 then images.each_with_index do |image, i| menu << %("&#{i+1} #{image[:title]}" ) end selected = `\"#{DIALOG}\" menu --items #{menu}`.to_i - 1 else images.each do |image| menu << %("#{image[:title]}" ) end text = %{--text "Choose an image"} button1 = %{--button1 "Cancel"} button2 = %{--button2 "Select Image"} result = `\"#{DIALOG}\" dropdown #{button2} #{button1} #{text} --items #{menu}`.split("\n") abort if result[0].to_i == 1 selected = result[1].to_i end print %{url(#{images[selected][:path]})} </string> <key>keyEquivalent</key> <string>@I</string> <key>scope</key> <string>source.css</string> <key>beforeRunningCommand</key> <string>saveActiveFile</string> </dict> </plist>
You need to login to post a comment.
