-
Notifications
You must be signed in to change notification settings - Fork 3
/
redlime.py
66 lines (53 loc) · 2.43 KB
/
redlime.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
#!/usr/bin/env python\n
# -*- coding: utf-8 -*-
import sublime
import sublime_plugin
from .base import * # noqa
from .base.shortcuts_menu import ShortcutsMenu
from .base import utils
class RedlimeViewEvents(sublime_plugin.ViewEventListener):
def on_query_context(self, key, operator, operand, match_all):
if key == 'rl_screen':
if operator == sublime.OP_EQUAL:
if isinstance(operand, list):
return self.view.settings().get('screen', None) in operand
else:
# print(key, operand, type(operand), operand == view.settings().get('screen', None))
return operand == self.view.settings().get('screen', None)
if operator == sublime.OP_NOT_EQUAL:
if isinstance(operand, list):
return self.view.settings().get('screen', None) not in operand
else:
return operand != self.view.settings().get('screen', None)
def on_activated_async(self):
screen = self.view.settings().get('screen')
if not screen or not screen.startswith('redlime'):
return
if screen == 'redlime_query':
is_query = bool(self.view.settings().get('query_params').get('query_id', None))
shortcuts = utils.Shortcuts.shortcuts_issue_list_query() if is_query else utils.Shortcuts.shortcuts_issue_list_project()
cols = utils.Shortcuts.cols_issue_list_query() if is_query else utils.Shortcuts.cols_issue_list_project()
ShortcutsMenu(
self.view,
shortcuts=shortcuts,
cols=cols
)
elif screen == 'redlime_issue':
ShortcutsMenu(
self.view,
shortcuts=utils.Shortcuts.shortcuts_issue_edit(),
cols=utils.Shortcuts.cols_issue_edit()
)
class RedlimeEvents(sublime_plugin.EventListener):
def is_screen_read_only(self, screen, view):
if screen == 'redlime_query':
return True
elif screen == 'redlime_issue' and view.settings().get('redlime_issue_unselectable', True):
return True
return False
def on_selection_modified(self, view):
screen = view.settings().get('screen')
if not screen:
return
if view.is_read_only() and self.is_screen_read_only(screen, view):
view.sel().add(view.line(view.sel()[0].end()))