|
1 | 1 | import os |
2 | | -import sublime |
3 | 2 | import re |
| 3 | +import sublime |
4 | 4 | import sublime_plugin |
5 | 5 | import FuzzyFilePath.expression as Context |
6 | 6 | import FuzzyFilePath.common.path as Path |
7 | 7 | from FuzzyFilePath.common.verbose import log |
8 | 8 | import FuzzyFilePath.common.selection as Selection |
| 9 | +import FuzzyFilePath.current_state as state |
| 10 | + |
| 11 | + |
| 12 | +ID = "GotoFile" |
9 | 13 |
|
10 | | -ID = "goto file" |
11 | 14 |
|
12 | 15 | class FfpGotoFileCommand(sublime_plugin.TextCommand): |
13 | | - """ go to file """ |
| 16 | + """ open file under cursor """ |
14 | 17 | def run(self, edit): |
15 | 18 | current_directory = os.path.dirname(self.view.file_name()) |
16 | | - |
17 | 19 | context = Context.get_context(self.view) |
18 | 20 | if context.get("valid") is False: |
19 | 21 | return log(ID, "abort, no valid path given:", context.get("needle")) |
20 | 22 |
|
21 | 23 | path = context.get("needle") |
22 | | - project = state.get_project_directory() |
| 24 | + project_folder = state.get_project_directory() |
23 | 25 |
|
24 | | - if not (path and project): |
25 | | - return log(ID, "path or project invalid", path, project) |
| 26 | + if not (path and project_folder): |
| 27 | + return log(ID, "path or project invalid", path, project_folder) |
26 | 28 |
|
27 | 29 | is_relative = Path.is_relative(path) |
28 | 30 | if is_relative: |
29 | 31 | path = Path.get_absolute_path(current_directory, path) |
30 | | - path = re.sub(project.get_directory(), "", path) |
| 32 | + path = re.sub(project_folder, "", path) |
31 | 33 |
|
32 | 34 | path = re.sub("^[\\\\/\.]", "", path) |
33 | | - files = project.find_file(path) |
| 35 | + files = state.find_file(path) |
34 | 36 |
|
35 | 37 | if len(files) == 0: |
36 | 38 | return log(ID, "failed finding file", path) |
37 | 39 |
|
38 | 40 | if len(files) == 1: |
39 | | - self.open_file(project.get_directory(), files[0]) |
| 41 | + self.open_file(project_folder, files[0]) |
40 | 42 | else: |
41 | 43 | # if javascript, search for index.js |
42 | 44 | current_scope = self.view.scope_name(Selection.get_position(self.view)) |
43 | 45 | if re.search("\.js ", current_scope): |
44 | 46 | for file in files: |
45 | 47 | if "index.js" in file: |
46 | | - return self.open_file(project.get_directory(), file) |
| 48 | + return self.open_file(project_folder, file) |
47 | 49 |
|
48 | 50 | self.files = files |
49 | | - self.project_folder = project.get_directory() |
| 51 | + self.project_folder = project_folder |
50 | 52 | self.view.show_popup_menu(files, self.select_file) |
51 | 53 |
|
52 | 54 | def select_file(self, index): |
|
0 commit comments