-
Notifications
You must be signed in to change notification settings - Fork 14
/
ProjectListener.py
48 lines (34 loc) · 1.29 KB
/
ProjectListener.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
import sublime
import sublime_plugin
import FuzzyFilePath.controller as controller
ID = "ProjectListener"
class ProjectListener(sublime_plugin.EventListener):
""" listens on window changes, delegating events to controller """
previous_project = None
previous_window = None
def on_activated(self, view):
window = view.window()
if not window:
return False
project_id = get_project_id(window)
if self.previous_project != project_id:
if self.previous_project is not None:
self.on_project_activated(view)
self.previous_project = project_id
elif self.previous_window is not sublime.active_window().id():
self.previous_window = sublime.active_window().id()
self.on_window_activated(view)
# project has been refocused
def on_window_activated(self, view):
controller.on_project_focus(view.window())
# another (possible) project has been opened/focused
def on_project_activated(self, view):
window = view.window()
if not window:
return False
controller.on_project_activated(window)
def get_project_id(window):
project_name = window.project_file_name()
if project_name:
return project_name
return window.id()