forked from xjsender/SublimeApex
-
Notifications
You must be signed in to change notification settings - Fork 0
/
context.py
207 lines (165 loc) · 7.96 KB
/
context.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
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
import sublime
import sublime_plugin
import os
import time
from .salesforce import message
COMPONENT_METADATA_SETTINGS = "component_metadata.sublime-settings"
TOOLING_API_SETTINGS = "toolingapi.sublime-settings"
def get_toolingapi_settings():
"""
Load all settings in toolingapi.sublime-settings
@return: dict that contains all settings
"""
# Load sublime-settings
s = sublime.load_settings(TOOLING_API_SETTINGS)
settings = {}
if not s.has("projects"):
sublime.error_message("You should set your user credentials.")
return
projects = s.get("projects")
default_project = None
default_project_name = None
usernames = []
for project_name in projects.keys():
project_attr = projects[project_name]
if project_attr["default"]:
default_project_name = project_name
default_project = project_attr
default_project["project_name"] = default_project_name
else:
usernames.append(project_attr["username"])
if default_project == None:
sublime.error_message("You should has one default project at least. please check you settings.")
return
# Default Project Part
settings["usernames"] = usernames
settings["default_project"] = default_project
settings["default_project_name"] = default_project_name
# User Settings Part
settings["projects"] = projects
workspace = s.get("workspace") + "/" + default_project_name +\
("-" + time.strftime('%Y%m%d') if s.get("keep_project_name_time_suffix") else "")
settings["workspace"] = workspace
settings["username"] = default_project.get("username")
settings["password"] = default_project["password"]
if "security_token" in default_project:
settings["security_token"] = default_project["security_token"]
else:
settings["security_token"] = ""
login_url = default_project.get("login_url")
settings["login_url"] = login_url
settings["soap_login_url"] = login_url + "/services/Soap/u/v{0}.0".format(s.get("api_version", "28"))
# This flag indicate whether output session id
settings["output_session_info"] = s.get("output_session_info", False)
# Indicate whether keep local change history
settings["keep_local_change_history"] = s.get("keep_local_change_history", True)
# Trace Flag
settings["trace_flag"] = s.get("trace_flag")
# Every time when you save component and error happened, the console will be open.
# When you edit the code according to the error message, this flag used to indicate
# whether the console will be hidden automatically
settings["hidden_console_on_modify"] = s.get("hidden_console_on_modify", True)
# Indicate whether download StaticResource body, it is very time-consuming.
# If you open this functionality and your StaticResources are very large
# It may stop your work
settings["get_static_resource_body"] = s.get("get_static_resource_body", True)
# Set API Version
settings["api_version"] = s.get("api_version", "28")
# Browser Path
settings["default_chrome_path"] = s.get("default_chrome_path")
# Completions Part
settings["disable_fields_completion"] = s.get("disable_fields_completion", False)
settings["disable_keyword_completion"] = s.get("disable_keyword_completion", False)
settings["disable_picklist_value_completion"] = s.get("disable_picklist_value_completion", False)
settings["disable_relationship_completion"] = s.get("disable_relationship_completion", False)
settings["display_field_name_and_label"] = s.get("display_field_name_and_label", True)
settings["excluded_sobjects"] = s.get("excluded_sobjects", [])
# Bulk Api batch size and batch bytes
settings["maximum_batch_size"] = s.get("maximum_batch_size", 10000)
settings["maximum_batch_bytes"] = s.get("maximum_batch_bytes", 100000)
# Log Levels of Anonymous Code
settings["anonymous_log_levels"] = s.get("anonymous_log_levels")
# Deploy Option
settings["deploy_options"] = s.get("deploy_options")
# Workbook columns
settings["workbook_field_describe_columns"] = s.get("workbook_field_describe_columns")
settings["workflow_rule_columns"] = s.get("workflow_rule_columns")
settings["workflow_field_update_columns"] = s.get("workflow_field_update_columns")
settings["workflow_email_alert_columns"] = s.get("workflow_email_alert_columns")
settings["workflow_task_columns"] = s.get("workflow_task_columns")
settings["workflow_outbound_message_columns"] = s.get("workflow_outbound_message_columns")
settings["validation_rule_columns"] = s.get("validation_rule_columns")
# Combine the allowed packages SOQL expression
allowed_packages = s.get("allowed_packages", [])
allowed_packages_soql = '('
for pa in allowed_packages:
allowed_packages_soql += "'%s'" % pa + ","
allowed_packages_soql = allowed_packages_soql[:-1] + ")"
# Populate all global variables
components = s.get("components")
for component_type in components:
component_attribute = components[component_type]
# Combine soql
component_soql = "SELECT Id, Name, " + component_attribute["body"] +\
(", ContentType" if component_type == "StaticResource" else "") +\
" FROM " + component_type +\
" WHERE NamespacePrefix = null " +\
(" OR NamespacePrefix in " + allowed_packages_soql if allowed_packages else "") +\
" ORDER BY Name"
component_attribute["soql"] = component_soql
component_attribute["outputdir"] = workspace + "/" + component_attribute["folder"]
settings[component_type] = component_attribute
settings[component_attribute["extension"]] = component_type
settings[component_attribute["folder"]] = component_type
settings["component_types"] = components.keys()
settings["component_folders"] = [components[ct]["folder"] for ct in components]
settings["component_extensions"] = [components[ct]["extension"] for ct in components]
settings["component_outputdirs"] = [workspace + "/" + components[ct]["folder"] for ct in components]
return settings
def make_dir():
"""
Load settings from toolingapi.sublime-settings and then create project directory
@Return: No return
"""
# Create Components Directory
# I.E. d:/Tooling API/pro-exercise-20130416/ApexClass
component_outputdirs = get_toolingapi_settings()["component_outputdirs"]
for component_outputdir in component_outputdirs:
if not os.path.exists(component_outputdir):
os.makedirs(component_outputdir)
def display_active_project(view):
toolingapi_settings = get_toolingapi_settings()
display_message = "Default Project => " + toolingapi_settings["default_project_name"]
view.set_status('default_project', display_message)
def switch_project(chosen_project):
s = sublime.load_settings(TOOLING_API_SETTINGS)
projects = s.get("projects")
# Set the chosen project as default and others as not default
for project in projects:
project_attr = projects[project]
if chosen_project == project:
project_attr["default"] = True
else:
project_attr["default"] = False
# Save the updated settings
s.set("projects", projects)
sublime.save_settings(TOOLING_API_SETTINGS)
print (message.SEPRATE.format(chosen_project + " is the default project now."))
# Set all active views status with "default project"
for view in sublime.active_window().views():
display_active_project(view)
def add_project_to_workspace(workspace):
"""
Add new project folder to workspace
"""
# Just ST3 supports, ST2 is not
project_data = sublime.active_window().project_data()
if project_data == None: project_data = {}
folders = []
if "folders" in project_data:
folders = project_data["folders"]
folders.append({
"path": workspace
})
project_data["folders"] = folders
sublime.active_window().set_project_data(project_data)