/
commands.py
117 lines (96 loc) · 3.47 KB
/
commands.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
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
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
import sublime
import sublime_plugin
import os
import re
from FolderFiles.folder_files import(FolderFiles, open_file_or_folder_by_panel,
open_folder_by_panel)
try:
from FileList.file_list import open_file, get_short_path
from QuickSearchEnhanced import quick_search
from OpenPath.open_path import open_path
except ImportError as error:
sublime.error_message("Dependency import failed; please read readme for " +
"FolderFiles plugin for installation instructions; to disable this " +
"message remove this plugin; message: " + str(error))
raise error
class FolderFilesHelper(sublime_plugin.TextCommand):
def _get_panels(self):
panel = quick_search.panels.get_current()
folder_files = panel and panel.get_caller('folder_files')
return panel, folder_files
def _get_file_list_panels(self):
panel = quick_search.panels.get_current()
folder_files = panel and panel.get_caller('file_list')
return panel, folder_files
class OpenFolderInList(FolderFilesHelper):
def run(self, edit):
panel, _ = self._get_file_list_panels()
if panel == None:
return
open_file_or_folder_by_panel(panel)
class OpenFileManagerForFolderInList(FolderFilesHelper):
def run(self, edit):
_, folder_files = self._get_panels()
if folder_files == None:
return
open_path(folder_files.get_current_path())
class OpenExactFileInList(FolderFilesHelper):
def run(self, edit):
panel, folder_files = self._get_panels()
if folder_files == None:
return
path = panel.get_current_text()
if path[0:1] != '/':
path = folder_files.get_current_path() + '/' + path
open_file_or_folder_by_panel(panel, path)
class OpenFileInList(FolderFilesHelper):
def run(self, edit):
panel, folder_files = self._get_panels()
if folder_files == None:
return
sublime.active_window().open_file(panel.get_current_value())
class PreviewFileInList(FolderFilesHelper):
def run(self, edit):
panel, folder_files = self._get_panels()
if folder_files == None:
return
sublime.active_window().open_file(panel.get_current_value(),
sublime.TRANSIENT)
class GotoFolderInList(FolderFilesHelper):
def run(self, edit, path):
_, folder_files = self._get_panels()
if folder_files == None:
return
match = re.match(r'\$(\d)', path)
if match != None:
folder_files.goto(self.view.window().folders()[int(match.group(1))])
elif path == '$ROOT':
path = folder_files.get_current_path()
for folder in self.view.window().folders():
if folder == path[0:len(folder)]:
folder_files.goto(folder)
break
elif path == '$UP':
folder_files.goto_up()
elif path == '$DOWN':
folder_files.goto_down()
else:
folder_files.goto(os.path.expanduser(path))
class CreateFolderInList(FolderFilesHelper):
def run(self, edit):
panel = quick_search.panels.get_current()
folder_files = panel and panel.get_caller('folder_files')
if folder_files == None:
return
path = folder_files.get_path() + '/' +panel.get_current_text()
os.mkdir(path)
folder_files.goto(path)
panel.set_text('')
class FindInCurrentFileFolder(FolderFilesHelper):
def run(self, edit):
panel, folder_files = self._get_panels()
panel.close(False, None)
sublime.active_window().focus_view(panel.get_opener())
path, _ = get_short_path(folder_files.get_path())
sublime.active_window().run_command('show_panel', {"panel": "find_in_files",
"where": path + '/'})