-
-
Notifications
You must be signed in to change notification settings - Fork 245
/
bh_swapping.py
executable file
·91 lines (68 loc) · 2.33 KB
/
bh_swapping.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
89
90
91
"""
BracketHighlighter.
Copyright (c) 2013 - 2020 Isaac Muse <[email protected]>
License: MIT
"""
import sublime
import sublime_plugin
from . import bh_wrapping
class SwapBrackets(bh_wrapping.WrapBrackets):
"""
Swap Base Class.
Swap base is derived from the wrap base.
"""
def wrap(self, wrap_entry):
"""Setup for wrapping."""
if wrap_entry < 0:
return
self._style = ["inline"]
self.brackets = self._brackets[wrap_entry]
self.wrap_brackets(0)
class SwapBracketsCommand(sublime_plugin.TextCommand):
"""Swap bracket command."""
def finalize(self, callback):
"""Execute post wrap callback."""
if self.view is not None:
if not self.view.settings().get("bracket_highlighter.busy", False):
callback()
else:
sublime.set_timeout(lambda: self.finalize(callback), 100)
def swap_brackets(self, value):
"""Swap the brackets."""
if value < 0:
return
self.brackets = self.wrap._brackets[value]
self.view.run_command(
"bh_async_key" if self._async else "bh_key",
{
"plugin": {
"type": ["__all__"],
"command": "bh_modules.swapbrackets"
}
}
)
self.view = self.window.active_view()
if self._async:
sublime.set_timeout(lambda: self.finalize(lambda: self.wrap.wrap(value)), 100)
else:
self.finalize(self.wrap.wrap(value))
def run(self, edit, **kwargs):
"""Initiate the swap."""
self._async = kwargs.get('async', False)
self.window = self.view.window()
self.wrap = SwapBrackets(self.view, "bh_swapping.sublime-settings", "swapping")
if len(self.wrap._menu):
self.window.show_quick_panel(
self.wrap._menu,
self.swap_brackets
)
def is_enabled(self, **kwargs):
"""Check if command is enabled."""
settings = self.view.settings()
return bool(
not settings.get('bracket_highlighter.ignore', False) and
(
not settings.get('is_widget') or
sublime.load_settings("bh_core.sublime-settings").get('search_in_widgets', False)
)
)