Repository navigation
Expand file tree
/
Copy pathAdd Import.tmCommand
More file actions
69 lines (59 loc) · 1.69 KB
/
Copy pathAdd Import.tmCommand
File metadata and controls
69 lines (59 loc) · 1.69 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>beforeRunningCommand</key>
<string>nop</string>
<key>command</key>
<string>#!/usr/bin/env ruby -wKU
require ENV['TM_BUNDLE_SUPPORT']+'/lib/flex_env'
word = ENV['TM_CURRENT_WORD']
line = ENV['TM_CURRENT_LINE']
doc = STDIN.read.strip
import = SourceTools.find_package(word)
cla = import.split('.').pop()
doc[line] = doc[line].gsub(word, cla)
pkg = /^\s*package\b\s*([\w+\.]*)/
cls = /^\s*(public|final)\s+(final|public)?\s*\bclass\b/
mta = /^\s*\[(Style|Bindable|Event|Embed|SWF)/
pre, imps, post = [], [], []
a = pre
doc.split("\n").each do |line|
a << line
if line =~ pkg
pkg = nil
a = imps
elsif line =~ cls || line =~ mta
cls = nil
a = post
end
end
irgx = /^\s*import\s+#{import.gsub('.', '\.')}/
safe = 0
indent = ""
imps.each_with_index do |line,index|
if line =~ irgx
TextMate.exit_insert_text(cla.sub(word,'')) if word != cla
TextMate.exit_show_tool_tip("#{word} already imported")
elsif line =~ /^(\s*)import\s+/
indent = $1
safe = index
end
end
imps[safe] = "#{imps[safe]}\n#{indent}import #{import};"
TextMate.exit_replace_document( pre.join("\n")+"\n"+imps.join("\n")+"\n"+post.join("\n"))
</string>
<key>input</key>
<string>document</string>
<key>keyEquivalent</key>
<string>@I</string>
<key>name</key>
<string>Import Class</string>
<key>output</key>
<string>discard</string>
<key>scope</key>
<string>source.actionscript.3 meta.package.actionscript.3 meta.class.actionscript.3</string>
<key>uuid</key>
<string>B42093AC-0F65-4760-856C-23E51A54CD84</string>
</dict>
</plist>