-
Notifications
You must be signed in to change notification settings - Fork 14
/
MagentoOpenParentCommand.py
42 lines (31 loc) · 1.15 KB
/
MagentoOpenParentCommand.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
36
37
38
import sublime, sublime_plugin
import os.path
import re
class MagentoOpenParentCommand(sublime_plugin.TextCommand):
def run(self, edit):
text = self.view.substr(sublime.Region(0,self.view.size()))
result = re.search("class\s+?(?:(?:[A-Z][a-zA-Z0-9]+_?)+)\s+?extends\s+?((?:[A-Z][a-zA-Z0-9]+_?)+)", text, re.M | re.U)
if result != None:
parentClass = result.group(1)
if len(parentClass):
self.open(self.get_file(parentClass))
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:
print (folder+root+filePath)
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():
if region.empty():
continue
if self.view.score_selector(region.a, 'source.php') <= 0:
return False
else:
value = True
return value or self.view.score_selector(sublime.Region(0, 100).a, 'source.php') > 0