-
Notifications
You must be signed in to change notification settings - Fork 5
Expand file tree
/
Copy pathOpenFileList.py
More file actions
65 lines (52 loc) · 2.33 KB
/
OpenFileList.py
File metadata and controls
65 lines (52 loc) · 2.33 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
import sublime, sublime_plugin
import os.path
# Get the views according to the 'list_mode' argument
# on key bindings file (aka keyboard shorcuts)
def getViews(self, list_mode):
if list_mode == "active_group":
views = self.window.views_in_group(self.window.active_group())
if list_mode == "window":
views = self.window.views()
(_, current) = self.window.get_view_index(self.window.active_view())
return views
class OpenFileListCommand(sublime_plugin.WindowCommand):
settings = None
def run(self, list_mode):
# Load settings.
if self.settings == None:
self.settings = sublime.load_settings("OpenFileList.sublime-settings")
# Get the views:
views = getViews(self, list_mode)
# Fallback: if current group has no views,
# then list all views in current window
if len(views) < 1 and self.settings.get('list_by_window_fallback') == True:
views = getViews(self, "window")
names = []
current_index = False
i = -1
for view in views:
i += 1
view_path = view.file_name() or view.name() or 'untitled'
view_name = os.path.basename(view_path)
# If the view id = current view id,
# then save the index of current view:
if view.id() == self.window.active_view().id():
current_index = i
if view.is_dirty():
view_name += " " + self.settings.get('mark_dirty_file_char')
names.append([view_name, view_path])
# Delete current view from arrays:
if current_index is not False and self.settings.get('skip_current_file') == True:
del views[current_index]
del names[current_index]
else:
names[current_index][0] = self.settings.get('mark_current_file_char') + " " + names[current_index][0]
def on_done(index):
if index >= 0:
self.window.focus_view(views[index])
else:
self.window.focus_view(views[current])
if int(sublime.version()) > 3000:
self.window.show_quick_panel(names, on_done, sublime.MONOSPACE_FONT, current, on_done)
else:
self.window.show_quick_panel(names, on_done)