forked from apiad/sublime-browser-integration
-
Notifications
You must be signed in to change notification settings - Fork 0
/
browser_integration_main_menu.py
126 lines (104 loc) · 4.47 KB
/
browser_integration_main_menu.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
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
from .browser_integration import *
from .browser_integration_launch import *
from .browser_integration_reload import *
from .browser_integration_navigate import *
from .browser_integration_execute import *
from .browser_integration_jscad import *
from .browser_integration_stylesheets import *
from .browser_integration_select import *
from .browser_integration_selectint import *
from .browser_integration_source import *
from .browser_integration_click import *
from .browser_integration_type import *
from .browser_integration_class import *
from .browser_integration_record import *
from .browser_integration_stop import *
from .browser_integration_play import *
from .browser_integration_localstorage import *
from .browser_integration_quit import *
class BrowserIntegrationMainMenuCommand(sublime_plugin.ApplicationCommand):
def run(self):
main_menu_commands = [
BrowserIntegrationLaunchCommand,
BrowserIntegrationReloadCommand,
BrowserIntegrationNavigateCommand,
("Execute", "Execute snippets of code in the browser.", [
BrowserIntegrationExecuteCommand,
BrowserIntegrationJSCADCommand,
]),
("View", "View and modify text data of current document", [
BrowserIntegrationStylesheetsCommand,
BrowserIntegrationSourceCommand,
BrowserIntegrationLocalstorageCommand,
]),
("Interact", "Interact with the document elements.", [
BrowserIntegrationSelectCommand,
BrowserIntegrationSelectxpathCommand,
BrowserIntegrationSelectintCommand,
BrowserIntegrationClickCommand,
BrowserIntegrationTypeCommand,
BrowserIntegrationClassCommand,
]),
("Macro", "Record and replay browser interaction.", [
BrowserIntegrationRecordCommand,
BrowserIntegrationStopCommand,
BrowserIntegrationPlayCommand,
BrowserIntegrationPlaydelayCommand,
]),
BrowserIntegrationQuitCommand
]
def filter_visible(cmd):
if not isinstance(cmd, tuple):
if cmd.visible():
return cmd
else:
return None
name, desc, submenu = cmd
submenu = [filter_visible(c) for c in submenu
if filter_visible(c)]
if submenu:
return name, desc, submenu
return None
main_menu_commands = [filter_visible(c) for c in main_menu_commands
if filter_visible(c)]
def select_command_func(commands):
def select_command(i):
if i < 0:
return
command = commands[i]
if isinstance(command, tuple):
name, desc, l = command
@async
def quick_panel():
sublime.active_window().show_quick_panel([
[command_name(item)] +
command_description(item).split("\n")
for item in l
], select_command_func(l))
quick_panel()
else:
cmd = command_str(command)
if issubclass(command, sublime_plugin.ApplicationCommand):
sublime.run_command(cmd)
elif issubclass(command, sublime_plugin.WindowCommand):
sublime.active_window().run_command(cmd)
elif issubclass(command, sublime_plugin.TextCommand):
sublime.active_window().active_view().run_command(cmd)
return select_command
def command_str(cls):
name = cls.__name__
return "browser_integration_" + name[18:-7].lower()
def command_name(cls):
if isinstance(cls, tuple):
name, desc, l = cls
return name
return cls.plugin_name
def command_description(cls):
if isinstance(cls, tuple):
name, desc, l = cls
return desc
return cls.plugin_description
sublime.active_window().show_quick_panel([
[command_name(cls)] + command_description(cls).split("\n")
for cls in main_menu_commands
], select_command_func(main_menu_commands))