Posted By

charlesroper on 03/16/07


Tagged

css Bundle e-texteditor


Versions (?)

Who likes this?

1 person have marked this snippet as a favorite

gtcaz


Insert Image


 / Published in: XML
 

  1. <?xml version="1.0" encoding="UTF-8" ?>
  2. <!DOCTYPE plist PUBLIC "-//Apple Computer//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
  3. <plist version="1.0">
  4. <dict>
  5. <key>name</key>
  6. <string>Insert Image</string>
  7. <key>uuid</key>
  8. <string>B1EB3F7A-2989-4E32-A892-83013991F175</string>
  9. <key>input</key>
  10. <string>none</string>
  11. <key>output</key>
  12. <string>afterSelectedText</string>
  13. <key>command</key>
  14. <string>#!/usr/bin/env ruby
  15.  
  16. abort unless ENV[&apos;TM_PROJECT_DIRECTORY&apos;] &amp;&amp; ENV[&apos;TM_FILEPATH&apos;]
  17.  
  18. SUPPORT = ENV[&apos;TM_SUPPORT_PATH&apos;]
  19. DIALOG = SUPPORT + &apos;/bin/CocoaDialog.exe&apos;
  20.  
  21. require &apos;pathname&apos;
  22. require &apos;find&apos;
  23.  
  24. images = []
  25. menu = []
  26.  
  27. # Find all images within a project and stuff them into
  28. # an array (images) of hashes.
  29. Find.find(ENV[&apos;TM_PROJECT_DIRECTORY&apos;]) do |f|
  30. file_name = File.basename(f)
  31. if /\.(gif|jpg|png)$/ =~ file_name
  32. images &lt;&lt; {
  33. :title =&gt; file_name,
  34. :path =&gt; Pathname.new(f).relative_path_from(Pathname.new(ENV[&apos;TM_FILEPATH&apos;]).parent).to_s
  35. }
  36. end
  37. end
  38. abort if images.empty?
  39.  
  40. images = images.sort_by { |image| image[:title] }
  41.  
  42. # If there are less than 10 images within a project, use
  43. # a popup menu; otherwise, use a dropdown.
  44. if images.length &lt; 10 then
  45. images.each_with_index do |image, i|
  46. menu &lt;&lt; %(&quot;&amp;#{i+1} #{image[:title]}&quot; )
  47. end
  48. selected = `\&quot;#{DIALOG}\&quot; menu --items #{menu}`.to_i - 1
  49. else
  50. images.each do |image|
  51. menu &lt;&lt; %(&quot;#{image[:title]}&quot; )
  52. end
  53. text = %{--text &quot;Choose an image&quot;}
  54. button1 = %{--button1 &quot;Cancel&quot;}
  55. button2 = %{--button2 &quot;Select Image&quot;}
  56. result = `\&quot;#{DIALOG}\&quot; dropdown #{button2} #{button1} #{text} --items #{menu}`.split(&quot;\n&quot;)
  57. abort if result[0].to_i == 1
  58. selected = result[1].to_i
  59. end
  60.  
  61. print %{url(#{images[selected][:path]})}
  62. </string>
  63. <key>keyEquivalent</key>
  64. <string>@I</string>
  65. <key>scope</key>
  66. <string>source.css</string>
  67. <key>beforeRunningCommand</key>
  68. <string>saveActiveFile</string>
  69. </dict>
  70. </plist>

Report this snippet  

You need to login to post a comment.