-
Notifications
You must be signed in to change notification settings - Fork 14
/
controller.py
88 lines (64 loc) · 2.23 KB
/
controller.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
import sublime
import FuzzyFilePath.completion as Completion
import FuzzyFilePath.query as Query
import FuzzyFilePath.common.settings as Settings
from FuzzyFilePath.common.verbose import verbose
from FuzzyFilePath.common.verbose import log
import FuzzyFilePath.current_state as state
ID = "Controller"
#init
def plugin_loaded():
""" load settings """
update_settings()
settings_file = sublime.load_settings(Settings.get("ffp_settings_file"))
settings_file.add_on_change("update", update_settings)
def update_settings():
""" restart projectFiles with new plugin and project settings """
# invalidate cache
global scope_cache
scope_cache = {}
Settings.update()
state.enable()
state.update_settings()
#query
def get_filepath_completions(view):
if not state.is_valid():
Query.reset()
return False
verbose(ID, "get filepath completions")
completions = Completion.get_filepaths(view, Query)
if completions and len(completions[0]) > 0:
Completion.start(Query.get_replacements())
view.run_command('_enter_insert_mode') # vintageous
log("{0} completions found".format(len(completions)))
else:
if Query.get_needle() is not None:
sublime.status_message("FFP no filepaths found for '" + Query.get_needle() + "'")
Completion.stop()
Query.reset()
return completions
def on_query_completion_inserted(view, post_remove):
if Completion.is_active():
verbose(ID, "query completion inserted")
Completion.update_inserted_filepath(view, post_remove)
Completion.stop()
def on_query_completion_aborted():
Completion.stop()
#project
def on_project_focus(window):
""" window has gained focus, rebuild file cache (in case files were removed/added) """
verbose(ID, "refocus project")
for folder in window.folders():
state.rebuild_filecache(folder)
def on_project_activated(window):
""" a new project has received focus """
verbose(ID, "activate project")
state.update()
#file
def on_file_created():
""" a new file has been created """
verbose(ID, "file created -- rebuild cache")
state.update()
state.rebuild_filecache()
def on_file_focus(view):
state.update()