forked from sagold/FuzzyFilePath
-
Notifications
You must be signed in to change notification settings - Fork 0
/
ProjectListener.py
38 lines (27 loc) · 1.18 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
import sublime
import sublime_plugin
from FuzzyFilePath.project.ProjectManager import ProjectManager
from FuzzyFilePath.project.ProjectManager import get_project_folder
ID = "ProjectListener"
class ProjectListener(sublime_plugin.EventListener):
""" listens on window changes, delegating events to project manager """
previous_project = None
previous_window = None
def on_activated(self, view):
window = view.window()
if not window:
return False
project_folder = get_project_folder(window)
if self.previous_project != project_folder:
if self.previous_project is not None:
self.on_project_activated(view)
self.previous_project = project_folder
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):
ProjectManager.update_project(view.window())
# another (possible) project has been opened/focused
def on_project_activated(self, view):
ProjectManager.activate_project(view.window())