|
1
|
|
|
""" |
|
2
|
|
|
This plugin is the entry point to the smart completion module. |
|
3
|
|
|
|
|
4
|
|
|
Basic functionalities are kontext detection and offer only meaningful auto completion options |
|
5
|
|
|
instead of every of them. |
|
6
|
|
|
""" |
|
7
|
|
|
|
|
8
|
|
|
|
|
9
|
|
|
import re |
|
10
|
|
|
|
|
11
|
|
|
import sublime |
|
12
|
|
|
import sublime_plugin |
|
13
|
|
|
|
|
14
|
|
|
from .completion.completion import ContextSensAutoCompletion |
|
15
|
|
|
|
|
16
|
|
|
|
|
17
|
|
|
class MeterAutoComplete(sublime_plugin.EventListener): |
|
18
|
|
|
# pylint: disable=R0903; Ignore too few methods because we have a super class. |
|
19
|
|
|
""" |
|
20
|
|
|
This class is an implementation of the sublime plugin EventListener. |
|
21
|
|
|
|
|
22
|
|
|
This is a temporary solution for the completion module. |
|
23
|
|
|
It provides some basic smart completions like: |
|
24
|
|
|
|
|
25
|
|
|
* measures |
|
26
|
|
|
* plugins |
|
27
|
|
|
* meters |
|
28
|
|
|
* some attributes |
|
29
|
|
|
""" |
|
30
|
|
|
|
|
31
|
|
|
# only show our completion list because nothing else makes sense in this context |
|
32
|
|
|
flags = sublime.INHIBIT_EXPLICIT_COMPLETIONS | sublime.INHIBIT_WORD_COMPLETIONS |
|
33
|
|
|
scope = "source.rainmeter" |
|
34
|
|
|
|
|
35
|
|
|
comment_exp = re.compile(r'^\s*;.*') |
|
36
|
|
|
meter_exp = re.compile(r'^\s*') |
|
37
|
|
|
|
|
38
|
|
|
completions = [ |
|
39
|
|
|
# measures |
|
40
|
|
|
(re.compile(r'^\s*Measure\s*=\s*'), [ |
|
41
|
|
|
# key, value |
|
42
|
|
|
["Calc", "Calc"], |
|
43
|
|
|
["CPU", "CPU"], |
|
44
|
|
|
["FreeDiskSpace", "FreeDiskSpace"], |
|
45
|
|
|
["Loop", "Loop"], |
|
46
|
|
|
["MediaKey", "MediaKey"], |
|
47
|
|
|
|
|
48
|
|
|
# memory measure |
|
49
|
|
|
["Memory", "Memory"], |
|
50
|
|
|
["PhysicalMemory", "PhysicalMemory"], |
|
51
|
|
|
["SwapMemory", "SwapMemory"], |
|
52
|
|
|
|
|
53
|
|
|
# net measure |
|
54
|
|
|
["NetIn", "NetIn"], |
|
55
|
|
|
["NetOut", "NetOut"], |
|
56
|
|
|
["NetTotal", "NetTotal"], |
|
57
|
|
|
|
|
58
|
|
|
["NowPlaying", "NowPlaying"], |
|
59
|
|
|
["Plugin", "Plugin"], |
|
60
|
|
|
["RecycleManager", "RecycleManager"], |
|
61
|
|
|
["Registry", "Registry"], |
|
62
|
|
|
["Script", "Script"], |
|
63
|
|
|
["String", "String"], |
|
64
|
|
|
["Time", "Time"], |
|
65
|
|
|
["Uptime", "Uptime"], |
|
66
|
|
|
["WebParser", "WebParser"] |
|
67
|
|
|
]), |
|
68
|
|
|
|
|
69
|
|
|
# meters |
|
70
|
|
|
(re.compile(r'^\s*Meter\s*=\s*'), [ |
|
71
|
|
|
# key, value |
|
72
|
|
|
["Bar", "Bar"], |
|
73
|
|
|
["Bitmap", "Bitmap"], |
|
74
|
|
|
["Button", "Button"], |
|
75
|
|
|
["Histogram", "Histogram"], |
|
76
|
|
|
["Image", "Image"], |
|
77
|
|
|
["Line", "Line"], |
|
78
|
|
|
["Rotator", "Rotator"], |
|
79
|
|
|
["Roundline", "Roundline"], |
|
80
|
|
|
["Shape", "Shape"], |
|
81
|
|
|
["String", "String"] |
|
82
|
|
|
]), |
|
83
|
|
|
# general options |
|
84
|
|
|
|
|
85
|
|
|
# bar |
|
86
|
|
|
# bar orientation |
|
87
|
|
|
(re.compile(r'^\s*BarOrientation\s*=\s*'), [ |
|
88
|
|
|
# key, value |
|
89
|
|
|
["Horizontal", "Horizontal"], |
|
90
|
|
|
["Vertical\tDefault", "Vertical"] |
|
91
|
|
|
]), |
|
92
|
|
|
|
|
93
|
|
|
# bar flip |
|
94
|
|
|
(re.compile(r'^\s*Flip\s*=\s*'), [ |
|
95
|
|
|
# key, value |
|
96
|
|
|
["0\tDefault", "0"], |
|
97
|
|
|
["1\tBar is flipped", "1"] |
|
98
|
|
|
]), |
|
99
|
|
|
|
|
100
|
|
|
# bitmap |
|
101
|
|
|
|
|
102
|
|
|
# button |
|
103
|
|
|
# histogram |
|
104
|
|
|
# image |
|
105
|
|
|
# line |
|
106
|
|
|
# rotator |
|
107
|
|
|
# roundline |
|
108
|
|
|
# shape |
|
109
|
|
|
# string |
|
110
|
|
|
|
|
111
|
|
|
# plugins |
|
112
|
|
|
(re.compile(r'^\s*Plugin\s*=\s*'), [ |
|
113
|
|
|
# key, value |
|
114
|
|
|
["ActionTimer", "ActionTimer"], |
|
115
|
|
|
["AdvancedCPU", "AdvancedCPU"], |
|
116
|
|
|
["AudioLevel", "AudioLevel"], |
|
117
|
|
|
["CoreTemp", "CoreTemp"], |
|
118
|
|
|
["FileView", "FileView"], |
|
119
|
|
|
["FolderInfo", "FolderInfo"], |
|
120
|
|
|
["InputText", "InputText"], |
|
121
|
|
|
["iTunes", "iTunesPlugin"], |
|
122
|
|
|
["PerfMon", "PerfMon"], |
|
123
|
|
|
["Ping", "PingPlugin"], |
|
124
|
|
|
["Power", "PowerPlugin"], |
|
125
|
|
|
["Process", "Process"], |
|
126
|
|
|
["Quote", "QuotePlugin"], |
|
127
|
|
|
["ResMon", "ResMon"], |
|
128
|
|
|
["RunCommand", "RunCommand"], |
|
129
|
|
|
["SpeedFan", "SpeedFanPlugin"], |
|
130
|
|
|
["UsageMonitor", "UsageMonitor"], |
|
131
|
|
|
["SysInfo", "SysInfo"], |
|
132
|
|
|
["WiFiStatus", "WiFiStatus"], |
|
133
|
|
|
["Win7Audio", "Win7AudioPlugin"], |
|
134
|
|
|
["WindowMessage", "WindowMessagePlugin"] |
|
135
|
|
|
]), |
|
136
|
|
|
] |
|
137
|
|
|
|
|
138
|
|
|
def on_query_completions(self, view, _, locations): |
|
139
|
|
|
""" |
|
140
|
|
|
Called upon auto completion request. |
|
141
|
|
|
|
|
142
|
|
|
:param view: current view upon the text buffer |
|
143
|
|
|
:param _: unused prefix |
|
144
|
|
|
:param locations: selected regions |
|
145
|
|
|
""" |
|
146
|
|
|
for location in locations: |
|
147
|
|
|
# checks if the current scope is correct |
|
148
|
|
|
# so it is only called in the files with the correct scope |
|
149
|
|
|
# here is scope only rainmeter files |
|
150
|
|
|
if view.match_selector(location, self.scope): |
|
151
|
|
|
# find last occurance of the [] to determine the ini sections |
|
152
|
|
|
line = view.line(location) |
|
153
|
|
|
line_contents = view.substr(line) |
|
154
|
|
|
|
|
155
|
|
|
# starts with Measure, followed by an equal sign |
|
156
|
|
|
for exp, elements in self.completions: |
|
157
|
|
|
if exp.search(line_contents): |
|
158
|
|
|
return elements, self.flags |
|
159
|
|
|
return None |
|
160
|
|
|
|
|
161
|
|
|
|
|
162
|
|
|
class CompletionProxy(sublime_plugin.EventListener): |
|
163
|
|
|
# pylint: disable=R0903; Ignore too few methods because we have a super class. |
|
164
|
|
|
""" |
|
165
|
|
|
Proxy the sublime plugin EventListener to the internal completion module. |
|
166
|
|
|
|
|
167
|
|
|
The module handles all the request and routes them to the correct submodules. |
|
168
|
|
|
This prevents all the single modules from polluting the root directory. |
|
169
|
|
|
""" |
|
170
|
|
|
|
|
171
|
|
|
def __init__(self): |
|
172
|
|
|
"""Initialize the proxy.""" |
|
173
|
|
|
self.proxied_completion = ContextSensAutoCompletion() |
|
174
|
|
|
|
|
175
|
|
|
def on_query_completions(self, view, prefix, locations): |
|
176
|
|
|
"""Pass query completion to proxy.""" |
|
177
|
|
|
return self.proxied_completion.on_query_completions(view, prefix, locations) |
|
178
|
|
|
|