-
Notifications
You must be signed in to change notification settings - Fork 3
/
FocusFileOnSidebar.py
57 lines (43 loc) · 1.8 KB
/
FocusFileOnSidebar.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
import sublime
import sublime_plugin
def plugin_loaded():
global close_sidebar_if_opened
global settings
global settings_base
settings = sublime.load_settings("FocusFileOnSidebar.sublime-settings")
settings_base = sublime.load_settings("Preferences.sublime-settings")
plugin_reload()
settings.add_on_change('reload', plugin_reload)
settings_base.add_on_change('focusfileonsidebar-reload', plugin_reload)
def plugin_reload():
global close_sidebar_if_opened
close_sidebar_if_opened = settings_base.get(
'close_sidebar_if_opened', settings.get('close_sidebar_if_opened'))
def plugin_unloaded():
settings.clear_on_change('reload')
settings_base.clear_on_change('focusfileonsidebar-reload')
def refresh_folders(self):
data = get_project_json(self)
set_project_json(self, {})
set_project_json(self, data)
def get_project_json(self):
return self.window.project_data()
def set_project_json(self, data):
return self.window.set_project_data(data)
def reveal_and_focus_in_sidebar(self):
self.window.run_command("reveal_in_side_bar")
self.window.run_command("focus_side_bar")
class FocusFileOnSidebar(sublime_plugin.WindowCommand):
def run(self):
if not self.window.is_sidebar_visible():
refresh_folders(self)
self.window.set_sidebar_visible(True)
# set_project_data is asynchronous so we need settimeout for subsequent commands
sublime.set_timeout_async(lambda: reveal_and_focus_in_sidebar(self), 250)
else:
if close_sidebar_if_opened:
self.window.set_sidebar_visible(False)
refresh_folders(self)
else:
refresh_folders(self)
sublime.set_timeout_async(lambda: reveal_and_focus_in_sidebar(self), 250)