-
Notifications
You must be signed in to change notification settings - Fork 14
/
Copy pathMagentoOpenCommand.py
39 lines (30 loc) · 1012 Bytes
/
MagentoOpenCommand.py
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
import sublime, sublime_plugin
import os.path
import re
class MagentoOpenCommand(sublime_plugin.TextCommand):
def run(self, edit):
sels = self.view.sel()
if(len(sels) == 1):
text = self.view.substr(sels[0])
if(len(text)):
self.open(self.get_file(text))
def get_file(self, text):
return text.strip().replace('_', '/') + '.php'
def open(self, filePath):
rootDirectories = ['/app/code/core/', '/app/code/community/', '/app/code/local/', '/lib/']
for folder in sublime.active_window().folders():
for root in rootDirectories:
if os.path.isfile(folder+root+filePath):
sublime.active_window().open_file(folder+root+filePath)
return
def is_visible(self):
value = False
for region in self.view.sel():
selText = self.view.substr(region)
if len(selText) == 0:
continue
if self.view.score_selector(region.a, 'source.php') <= 0:
return False
else:
value = value or (re.match("([A-Z][a-zA-Z0-9]+_?)+", self.view.substr(region)) > 0)
return value