forked from facelessuser/BracketHighlighter
/
bracket_plugin.py
executable file
·69 lines (53 loc) · 2.19 KB
/
bracket_plugin.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
import sublime
import sys
import os
# Pull in built-in plugin directory
built_in_plugins = os.path.join(sublime.packages_path(), 'BracketHighlighter')
if not built_in_plugins in sys.path:
sys.path.append(built_in_plugins)
class BracketPlugin(object):
def __init__(self, plugin):
self.enabled = False
self.args = plugin['args'] if ("args" in plugin) else {}
self.plugin = None
if 'command' in plugin:
try:
(module_name, class_name) = plugin['command'].split('.')
module = __import__(module_name)
self.plugin = getattr(module, class_name)
self.enabled = True
except Exception:
sublime.error_message('Can not load plugin: ' + plugin['command'])
def is_enabled(self):
return self.enabled
def run_command(self, bracket, content, selection, bracket_type):
self.args['bracket'] = bracket
self.args['content'] = content
self.args['selection'] = selection
plugin = self.plugin(bracket, content, selection, bracket_type)
plugin.run(**self.args)
return plugin.attr.get_attr()
class BracketAttributes(object):
def __init__(self, bracket, content, selection, bracket_type):
self.bracket = bracket
self.content = content
self.selection = selection
self.bracket_type = bracket_type
def set_bracket(self, bracket):
self.bracket = bracket
def set_content(self, content):
self.content = content
def set_selection(self, selection):
self.selection = selection
def get_type(self):
return self.bracket_type
def get_attr(self):
return (self.bracket, self.content, self.selection)
class BracketPluginCommand(object):
def __init__(self, bracket, content, selection, bracket_type):
self.view = sublime.active_window().active_view()
self.attr = BracketAttributes(bracket, content, selection, bracket_type)
def run(self, bracket, content, selection):
pass
# Register sublime commands from built-in plugins
from bracket_plugins.sublime_commands import *