-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathQSSEditor_plugin.py
More file actions
97 lines (78 loc) · 2.95 KB
/
QSSEditor_plugin.py
File metadata and controls
97 lines (78 loc) · 2.95 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
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
from __future__ import absolute_import, print_function
import logging
import os
import sys
import sublime
import sublime_plugin
sys.path.append(os.path.join(os.path.dirname(__file__), 'site-packages'))
from qsseditor.Client import QSSEditorClient
from qsseditor.Utils import PLUGIN_NAME, get_setting, init_log, is_support
class QSSEditorWatcher(sublime_plugin.EventListener):
"""事件监听"""
def on_modified(self, view):
"""
文档被修改
:param view: sublime.View
"""
if not is_support(view.file_name(), view.syntax()):
return
logging.getLogger(PLUGIN_NAME).debug('QSSEditorWatcher::on_modified')
if QSSEditorClient.Client:
QSSEditorClient.Client.applyStyleAsync(view)
def on_load(self, view):
"""
文档被加载
:param view: sublime.View
"""
if not is_support(view.file_name(), view.syntax()):
return
logging.getLogger(PLUGIN_NAME).debug('QSSEditorWatcher::on_load')
if QSSEditorClient.Client:
QSSEditorClient.Client.applyStyleAsync(view)
def on_post_save(self, view):
"""
文档被保存
:param view: sublime.View
"""
if not is_support(view.file_name(), view.syntax()):
return
logging.getLogger(PLUGIN_NAME).debug('QSSEditorWatcher::on_post_save')
if QSSEditorClient.Client:
QSSEditorClient.Client.applyStyleAsync(view)
def on_query_completions(self, view, prefix, locations):
"""
自动补全查询
:param view: sublime.View
:param prefix: 前缀
:param locations: 位置
"""
if not is_support(view.file_name(), view.syntax()):
return
logging.getLogger(PLUGIN_NAME).debug(
'QSSEditorWatcher::on_query_completions: prefix={}, locations={}'.
format(prefix, locations))
if QSSEditorClient.Client:
return QSSEditorClient.Completions
return None
class QssApplyStyleCommand(sublime_plugin.TextCommand):
"""应用样式命令"""
def run(self, edit):
if QSSEditorClient.Client:
QSSEditorClient.Client.applyStyle(self.view)
def is_visible(self):
return is_support(self.view.file_name(), self.view.syntax())
def plugin_loaded():
"""插件被加载"""
if QSSEditorClient.Client is None:
# 只初始化一次
init_log(os.path.join(os.path.dirname(__file__), PLUGIN_NAME + '.log'),
level=getattr(logging, get_setting(None, 'debug_level',
'INFO'), logging.INFO))
QSSEditorClient.Client = QSSEditorClient()
QSSEditorClient.Client.start()
logging.getLogger(PLUGIN_NAME).debug('plugin_loaded')
def plugin_unloaded():
"""插件被卸载"""
if QSSEditorClient.Client:
QSSEditorClient.Client.stop()
logging.getLogger(PLUGIN_NAME).debug('plugin_unloaded')