forked from joeferraro/MavensMate-SublimeText
-
Notifications
You must be signed in to change notification settings - Fork 0
/
mavensmate.py
executable file
·1649 lines (1417 loc) · 66.8 KB
/
mavensmate.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
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
# Written by Joe Ferraro (@joeferraro / www.joe-ferraro.com)
import os
import subprocess
import json
import sys
import re
#dist_dir = os.path.dirname(os.path.abspath(__file__))
#sys.path.insert(0, dist_dir)
from xml.dom.minidom import parse, parseString
if sys.version_info >= (3, 0):
# Python 3
import MavensMate.config as config
import MavensMate.util as util
import MavensMate.lib.command_helper as command_helper
import MavensMate.lib.mm_interface as mm
import MavensMate.lib.upgrader as upgrader
import MavensMate.lib.resource_bundle as resource_bundle
import MavensMate.lib.server.lib.server_threaded as server
from MavensMate.lib.printer import PanelPrinter
from MavensMate.lib.threads import ThreadTracker
import MavensMate.lib.parsehelp as parsehelp
import MavensMate.lib.vf as vf
from MavensMate.lib.mm_merge import *
from MavensMate.lib.completioncommon import *
else:
# Python 2
import config
import util
import lib.command_helper as command_helper
import lib.mm_interface as mm
import lib.resource_bundle as resource_bundle
import lib.vf as vf
from lib.printer import PanelPrinter
from lib.threads import ThreadTracker
from lib.mm_merge import *
import sublime
import sublime_plugin
settings = sublime.load_settings('mavensmate.sublime-settings')
sublime_version = int(float(sublime.version()))
completioncommon = imp.load_source("completioncommon", os.path.join(os.path.dirname(os.path.abspath(__file__)), "lib","completioncommon.py"))
apex_completions = util.parse_json_from_file(os.path.join(os.path.dirname(os.path.abspath(__file__)), "support", "lib", "completions.json"))
st_version = 2
# Warn about out-dated versions of ST3
if sublime.version() == '':
st_version = 3
elif int(sublime.version()) > 3000:
st_version = 3
if st_version == 3:
installed_dir, _ = __name__.split('.')
elif st_version == 2:
installed_dir = os.path.basename(os.getcwd())
reloader_name = 'lib.reloader'
# ST3 loads each package as a module, so it needs an extra prefix
if st_version == 3:
reloader_name = 'MavensMate.' + reloader_name
from imp import reload
# Make sure all dependencies are reloaded on upgrade
if reloader_name in sys.modules and sys.version_info >= (3, 0):
reload(sys.modules[reloader_name])
from .lib import reloader
try:
# Python 3
import MavensMate.lib.reloader as reloader
except (ValueError):
# Python 2
import lib.reloader as reloader
def plugin_loaded():
settings = sublime.load_settings('mavensmate.sublime-settings')
merge_settings = sublime.load_settings('mavensmate-merge.sublime-settings')
try:
server.run(port=settings.get('mm_server_port'))
except Exception as e:
print(e)
config.settings = settings
config.merge_settings = merge_settings
util.package_check()
util.start_mavensmate_app()
util.check_for_updates()
util.send_usage_statistics('Startup')
####### <--START--> COMMANDS THAT USE THE MAVENSMATE UI ##########
#displays new project dialog
class NewProjectCommand(sublime_plugin.ApplicationCommand):
def run(command):
util.check_for_workspace()
mm.call('new_project', False)
util.send_usage_statistics('New Project')
#displays edit project dialog
class EditProjectCommand(sublime_plugin.ApplicationCommand):
def run(command):
mm.call('edit_project', False)
util.send_usage_statistics('Edit Project')
def is_enabled(command):
return util.is_mm_project()
#displays unit test dialog
class RunApexUnitTestsCommand(sublime_plugin.ApplicationCommand):
def run(command):
active_file = util.get_active_file()
try:
if os.path.exists(active_file):
filename, ext = os.path.splitext(os.path.basename(util.get_active_file()))
if ext == '.cls':
params = {
"selected" : [filename]
}
else:
params = {}
else:
params = {}
except:
params = {}
mm.call('unit_test', context=command, params=params)
util.send_usage_statistics('Apex Unit Testing')
def is_enabled(command):
return util.is_mm_project()
#launches the execute anonymous UI
class ExecuteAnonymousCommand(sublime_plugin.ApplicationCommand):
def run(command):
mm.call('execute_apex', False)
util.send_usage_statistics('Execute Anonymous')
def is_enabled(command):
return util.is_mm_project()
#displays deploy dialog
class DeployToServerCommand(sublime_plugin.ApplicationCommand):
def run(command):
mm.call('deploy', False)
util.send_usage_statistics('Deploy to Server')
def is_enabled(command):
return util.is_mm_project()
#displays deploy dialog
class NewDebugLogCommand(sublime_plugin.ApplicationCommand):
def run(command):
mm.call('debug_log', True)
util.send_usage_statistics('New Debug Log')
def is_enabled(command):
return util.is_mm_project()
####### <--END--> COMMANDS THAT USE THE MAVENSMATE UI ##########
class MavensStubCommand(sublime_plugin.WindowCommand):
def run(self):
return True
def is_enabled(self):
return False
def is_visible(self):
return not util.is_mm_project();
#deploys the currently active file
class ForceCompileFileMainMenuCommand(sublime_plugin.WindowCommand):
def run(self, files=None):
print('FORCE COMPILING!')
if files == None:
files = [util.get_active_file()]
params = {
"files" : files,
"action" : "overwrite"
}
mm.call('compile', context=self.window, params=params)
def is_enabled(self):
return util.is_mm_project();
#deploys the currently active file
class ForceCompileFileCommand(sublime_plugin.WindowCommand):
def run(self, files=None):
print('FORCE COMPILING!')
if files == None:
files = [util.get_active_file()]
params = {
"files" : files,
"action" : "overwrite"
}
mm.call('compile', context=self.window, params=params)
#deploys the currently active file
class CompileActiveFileCommand(sublime_plugin.WindowCommand):
def run(self):
params = {
"files" : [util.get_active_file()]
}
mm.call('compile', context=self, params=params)
def is_enabled(command):
return util.is_mm_file()
def is_visible(command):
return util.is_mm_project()
#handles compiling to server on save
class RemoteEdit(sublime_plugin.EventListener):
def on_post_save(self, view):
settings = sublime.load_settings('mavensmate.sublime-settings')
if settings.get('mm_compile_on_save') == True and util.is_mm_file() == True:
params = {
"files" : [util.get_active_file()]
}
mm.call('compile', context=view, params=params)
class MenuModifier(sublime_plugin.EventListener):
def on_activated_async(self, view):
view.file_name()
#compiles the selected files
class CompileSelectedFilesCommand(sublime_plugin.WindowCommand):
def run (self, files):
#print files
params = {
"files" : files
}
mm.call('compile', context=self, params=params)
util.send_usage_statistics('Compile Selected Files')
def is_visible(self, files):
return util.is_mm_project()
def is_enabled(self, files):
if files != None and type(files) is list and len(files) > 0:
for f in files:
if util.util.is_mm_file(f):
return True
return False
#displays unit test dialog
class RunAsyncApexTestsCommand(sublime_plugin.WindowCommand):
def run(self):
active_file = util.get_active_file()
try:
if os.path.exists(active_file):
filename, ext = os.path.splitext(os.path.basename(util.get_active_file()))
if ext == '.cls':
params = {
"classes" : [filename]
}
else:
params = {}
else:
params = {}
except:
params = {}
mm.call('test_async', context=self, params=params)
util.send_usage_statistics('Async Apex Test')
def is_enabled(command):
return util.is_apex_class_file()
#deploys the currently open tabs
class CompileTabsCommand(sublime_plugin.WindowCommand):
def run (self):
params = {
"files" : util.get_tab_file_names()
}
mm.call('compile', context=self, params=params)
util.send_usage_statistics('Compile Tabs')
#replaces local copy of metadata with latest server copies
class CleanProjectCommand(sublime_plugin.WindowCommand):
def run(self):
if sublime.ok_cancel_dialog("Are you sure you want to clean this project? All local (non-server) files will be deleted and your project will be refreshed from the server", "Clean"):
mm.call('clean_project', context=self)
util.send_usage_statistics('Clean Project')
def is_enabled(command):
return util.is_mm_project()
#opens a project in the current workspace
class OpenProjectCommand(sublime_plugin.WindowCommand):
def run(self):
util.check_for_workspace()
open_projects = []
try:
for w in sublime.windows():
if len(w.folders()) == 0:
continue;
root = w.folders()[0]
if util.mm_workspace() not in root:
continue
#project_name = root.split("/")[-1]
project_name = util.get_file_name_no_extension(root)
open_projects.append(project_name)
except:
pass
import os
self.dir_map = {}
dirs = []
#print(util.mm_workspace())
workspaces = util.mm_workspace()
if type(workspaces) is not list:
workspaces = [workspaces]
for w in workspaces:
for dirname in os.listdir(w):
if dirname == '.DS_Store' or dirname == '.' or dirname == '..' or dirname == '.logs' : continue
if dirname in open_projects : continue
if not os.path.isdir(os.path.join(w,dirname)) : continue
sublime_project_file = dirname+'.sublime-project'
for project_content in os.listdir(os.path.join(w,dirname)):
if '.' not in project_content: continue
if project_content == '.sublime-project':
sublime_project_file = '.sublime-project'
continue
dirs.append([dirname, "Workspace: "+os.path.basename(w)])
self.dir_map[dirname] = [dirname, sublime_project_file, w]
self.results = dirs
#print(self.results)
self.window.show_quick_panel(dirs, self.panel_done,
sublime.MONOSPACE_FONT)
def panel_done(self, picked):
if 0 > picked < len(self.results):
return
self.picked_project = self.results[picked]
project_file = self.dir_map[self.picked_project[0]][1]
project_name = self.dir_map[self.picked_project[0]][0]
workspace = self.dir_map[self.picked_project[0]][2]
project_file_location = os.path.join(workspace,project_name,project_file)
#print(project_file_location)
if not os.path.isfile(project_file_location):
sublime.message_dialog("Cannot find project file for: "+project_name)
return
settings = sublime.load_settings('mavensmate.sublime-settings')
if sys.platform == 'darwin':
sublime_path = settings.get('mm_plugin_client_location', '/Applications')
if sublime_version >= 3000:
if os.path.exists(os.path.join(sublime_path, 'Sublime Text 3.app')):
subprocess.Popen("'"+sublime_path+"/Sublime Text 3.app/Contents/SharedSupport/bin/subl' --project '"+project_file_location+"'", stdout=subprocess.PIPE, stderr=subprocess.STDOUT, shell=True)
elif os.path.exists(os.path.join(sublime_path, 'Sublime Text.app')):
subprocess.Popen("'"+sublime_path+"/Sublime Text.app/Contents/SharedSupport/bin/subl' --project '"+project_file_location+"'", stdout=subprocess.PIPE, stderr=subprocess.STDOUT, shell=True)
else:
subprocess.Popen("'/Applications/Sublime Text 2.app/Contents/SharedSupport/bin/subl' --project '"+project_file_location+"'", stdout=subprocess.PIPE, stderr=subprocess.STDOUT, shell=True)
elif 'linux' in sys.platform:
subl_location = settings.get('mm_subl_location', '/usr/local/bin/subl')
subprocess.Popen("'{0}' --project '"+project_file_location+"'".format(subl_location), stdout=subprocess.PIPE, stderr=subprocess.STDOUT, shell=True)
else:
subl_location = settings.get('mm_windows_subl_location', '/usr/local/bin/subl')
if not os.path.isfile(subl_location) and "x86" not in subl_location:
subl_location = subl_location.replace("Program Files", "Program Files (x86)")
subprocess.Popen('"{0}" --project "{1}"'.format(subl_location, project_file_location), stdout=subprocess.PIPE, stderr=subprocess.STDOUT, shell=True)
class RunApexScriptCommand(sublime_plugin.WindowCommand):
def run(self):
params = {
"script_name" : os.path.basename(util.get_active_file())
}
mm.call('run_apex_script', context=self, params=params)
util.send_usage_statistics('Run Apex Script')
def is_enabled(command):
try:
return "apex-scripts" in util.get_active_file() and '.cls' in util.get_active_file()
except:
return False
class NewApexScriptCommand(sublime_plugin.TextCommand):
def run(self, edit):
sublime.active_window().show_input_panel("Apex Script Name", "MyScriptName", self.finish, None, None)
def finish(self, name):
if not os.path.exists(os.path.join(util.mm_project_directory(), "apex-scripts")):
os.makedirs(os.path.join(util.mm_project_directory(), "apex-scripts"))
if ".cls" not in name:
name = name + ".cls"
f = open(os.path.join(util.mm_project_directory(), "apex-scripts", name), "w")
f.close()
sublime.active_window().open_file(os.path.join(util.mm_project_directory(), "apex-scripts", name))
def is_enabled(command):
return util.is_mm_project()
#displays new apex class dialog
class NewApexClassCommand(sublime_plugin.TextCommand):
def __init__(self, *args, **kwargs):
sublime_plugin.TextCommand.__init__(self, *args, **kwargs)
self.template_options = None
self.github_templates = None
self.api_name = None
self.github_template = None
def run(self, edit, api_name="MyClass", class_type="default"):
settings = sublime.load_settings('mavensmate.sublime-settings')
use_github = settings.get('mm_use_github_templates', True)
if use_github:
self.template_options = []
self.github_templates = util.parse_templates_package("ApexClass")
for t in self.github_templates:
self.template_options.append([t["name"], t["description"], "Author: "+t["author"]])
sublime.active_window().show_quick_panel(self.template_options, self.on_select_from_github_template)
else:
templates = get_merged_apex_templates("ApexClass")
sublime.active_window().show_input_panel("Apex Class Name, Template "+str(sorted(templates.keys())), api_name+", "+class_type, self.on_input, None, None)
util.send_usage_statistics('New Apex Class')
def on_input(self, input):
api_name, class_type = [x.strip() for x in input.split(',')]
if not check_apex_templates(get_merged_apex_templates("ApexClass"), { "api_name":api_name, "class_type":class_type }, "new_apex_class"):
return
options = {
'metadata_type' : 'ApexClass',
'metadata_name' : api_name,
'apex_class_type' : class_type
}
mm.call('new_metadata', params=options)
def on_select_from_github_template(self, selection):
if selection != -1:
template_name = self.template_options[selection][0]
for t in self.github_templates:
if t["name"] == template_name:
self.github_template = t
break
sublime.active_window().show_input_panel("Apex Class Name", "MyClassName", self.finish_github_template_selection, None, None)
def finish_github_template_selection(self, api_name):
if '.cls' in api_name:
api_name = api_name.replace('.cls', '')
params = {
'metadata_type' : 'ApexClass',
'metadata_name' : api_name,
'github_template' : self.github_template
}
mm.call('new_metadata', params=params)
def is_enabled(self):
return util.is_mm_project()
#displays new apex trigger dialog
class NewApexTriggerCommand(sublime_plugin.TextCommand):
def __init__(self, *args, **kwargs):
sublime_plugin.TextCommand.__init__(self, *args, **kwargs)
self.template_options = None
self.github_templates = None
self.api_name = None
self.github_template = None
def run(self, edit, api_name="MyAccountTrigger", sobject_name="Account", class_type="default"):
settings = sublime.load_settings('mavensmate.sublime-settings')
use_github = settings.get('mm_use_github_templates', True)
if use_github:
self.template_options = []
self.github_templates = util.parse_templates_package("ApexTrigger")
for t in self.github_templates:
self.template_options.append([t["name"], t["description"], "Author: "+t["author"]])
sublime.active_window().show_quick_panel(self.template_options, self.on_select_from_github_template)
else:
templates = get_merged_apex_templates("ApexTrigger")
sublime.active_window().show_input_panel("Apex Trigger Name, SObject Name, Template "+str(sorted(templates.keys())), api_name+", "+sobject_name+", "+class_type, self.on_input, None, None)
util.send_usage_statistics('New Apex Trigger')
def on_input(self, input):
api_name, sobject_name, class_type = [x.strip() for x in input.split(',')]
if not check_apex_templates(get_merged_apex_templates("ApexTrigger"), { "api_name":api_name, "sobject_name":sobject_name, "class_type":class_type }, "new_apex_trigger"):
return
options = {
'metadata_type' : 'ApexTrigger',
'metadata_name' : api_name,
'object_api_name' : sobject_name,
'apex_class_type' : class_type
}
mm.call('new_metadata', params=options)
def on_select_from_github_template(self, selection):
if selection != -1:
template_name = self.template_options[selection][0]
for t in self.github_templates:
if t["name"] == template_name:
self.github_template = t
break
sublime.active_window().show_input_panel("Apex Trigger Name, Trigger Object API Name", "MyTriggerName, Account", self.finish_github_template_selection, None, None)
def finish_github_template_selection(self, api_name):
api_name, sobject_name = [x.strip() for x in api_name.split(',')]
params = {
'metadata_type' : 'ApexTrigger',
'object_api_name' : sobject_name,
'metadata_name' : api_name,
'github_template' : self.github_template
}
mm.call('new_metadata', params=params)
def is_enabled(command):
return util.is_mm_project()
#displays new apex page dialog
class NewApexPageCommand(sublime_plugin.TextCommand):
def __init__(self, *args, **kwargs):
sublime_plugin.TextCommand.__init__(self, *args, **kwargs)
self.template_options = None
self.github_templates = None
self.api_name = None
self.github_template = None
def run(self, edit, api_name="MyPage", class_type="default"):
settings = sublime.load_settings('mavensmate.sublime-settings')
use_github = settings.get('mm_use_github_templates', True)
if use_github:
self.template_options = []
self.github_templates = util.parse_templates_package("ApexPage")
for t in self.github_templates:
self.template_options.append([t["name"], t["description"], "Author: "+t["author"]])
sublime.active_window().show_quick_panel(self.template_options, self.on_select_from_github_template)
else:
sublime.active_window().show_input_panel("Visualforce Page Name, Template", api_name+", "+class_type, self.on_input, None, None)
util.send_usage_statistics('New Visualforce Page')
def on_input(self, input):
api_name, class_type = [x.strip() for x in input.split(',')]
if not check_apex_templates(get_merged_apex_templates("ApexPage"), { "api_name":api_name, "class_type":class_type }, "new_apex_page"):
return
options = {
'metadata_type' : 'ApexPage',
'metadata_name' : api_name,
'apex_class_type' : class_type
}
mm.call('new_metadata', params=options)
def on_select_from_github_template(self, selection):
if selection != -1:
template_name = self.template_options[selection][0]
for t in self.github_templates:
if t["name"] == template_name:
self.github_template = t
break
sublime.active_window().show_input_panel("Visualforce Page Name", "MyVisualforcePageName", self.finish_github_template_selection, None, None)
def finish_github_template_selection(self, api_name):
if '.cls' in api_name:
api_name = api_name.replace('.page', '')
params = {
'metadata_type' : 'ApexPage',
'metadata_name' : api_name,
'github_template' : self.github_template
}
mm.call('new_metadata', params=params)
def is_enabled(command):
return util.is_mm_project()
#displays new apex component dialog
class NewApexComponentCommand(sublime_plugin.TextCommand):
def __init__(self, *args, **kwargs):
sublime_plugin.TextCommand.__init__(self, *args, **kwargs)
self.template_options = None
self.github_templates = None
self.api_name = None
self.github_template = None
def run(self, edit, api_name="MyComponent", class_type="default"):
settings = sublime.load_settings('mavensmate.sublime-settings')
use_github = settings.get('mm_use_github_templates', True)
if use_github:
self.template_options = []
self.github_templates = util.parse_templates_package("ApexComponent")
for t in self.github_templates:
self.template_options.append([t["name"], t["description"], "Author: "+t["author"]])
sublime.active_window().show_quick_panel(self.template_options, self.on_select_from_github_template)
else:
sublime.active_window().show_input_panel("Visualforce Component Name, Template", api_name+", "+class_type, self.on_input, None, None)
util.send_usage_statistics('New Visualforce Component')
def on_input(self, input):
api_name, class_type = [x.strip() for x in input.split(',')]
if not check_apex_templates(get_merged_apex_templates("ApexComponent"), { "api_name":api_name, "class_type":class_type }, "new_apex_component"):
return
options = {
'metadata_type' : 'ApexComponent',
'metadata_name' : api_name,
'apex_class_type' : class_type
}
mm.call('new_metadata', params=options)
def on_select_from_github_template(self, selection):
if selection != -1:
template_name = self.template_options[selection][0]
for t in self.github_templates:
if t["name"] == template_name:
self.github_template = t
break
sublime.active_window().show_input_panel("Visualforce Component Name", "MyComponentName", self.finish_github_template_selection, None, None)
def finish_github_template_selection(self, api_name):
if '.cls' in api_name:
api_name = api_name.replace('.component', '')
params = {
'metadata_type' : 'ApexComponent',
'metadata_name' : api_name,
'github_template' : self.github_template
}
mm.call('new_metadata', params=params)
def is_enabled(command):
return util.is_mm_project()
def check_apex_templates(templates, args, command):
if "class_type" not in args or args["class_type"] not in templates:
sublime.error_message(str(args["class_type"])+" is not a valid template, please choose one of: "+str(sorted(templates.keys())))
sublime.active_window().run_command(command, args)
return False
return True
def get_merged_apex_templates(apex_type):
settings = sublime.load_settings('mavensmate.sublime-settings')
template_map = settings.get('mm_default_apex_templates_map', {})
custom_templates = settings.get('mm_apex_templates_map', {})
if apex_type not in template_map:
return {}
if apex_type in custom_templates:
template_map[apex_type] = dict(template_map[apex_type], **custom_templates[apex_type])
return template_map[apex_type]
#displays mavensmate panel
class ShowDebugPanelCommand(sublime_plugin.WindowCommand):
def run(self):
if util.is_mm_project() == True:
PanelPrinter.get(self.window.id()).show(True)
#hides mavensmate panel
class HideDebugPanelCommand(sublime_plugin.WindowCommand):
def run(self):
if util.is_mm_project() == True:
PanelPrinter.get(self.window.id()).show(False)
#shows mavensmate info modal
class ShowVersionCommand(sublime_plugin.ApplicationCommand):
def run(command):
version = util.get_version_number()
sublime.message_dialog("MavensMate for Sublime Text v"+version+"\n\nMavensMate for Sublime Text is an open source Sublime Text plugin for Force.com development.\n\nhttp://mavensmate.com")
#refreshes selected directory (or directories)
# if src is refreshed, project is "cleaned"
class RefreshFromServerCommand(sublime_plugin.WindowCommand):
def run (self, dirs, files):
if sublime.ok_cancel_dialog("Are you sure you want to overwrite the selected files' contents from Salesforce?", "Refresh"):
if dirs != None and type(dirs) is list and len(dirs) > 0:
params = {
"directories" : dirs
}
elif files != None and type(files) is list and len(files) > 0:
params = {
"files" : files
}
mm.call('refresh', context=self, params=params)
util.send_usage_statistics('Refresh Selected From Server')
def is_visible(self, dirs, files):
return util.is_mm_project()
# def is_enabled(self, dirs, files):
# if dirs != None and type(dirs) is list and len(dirs) > 0:
# for d in dirs:
# if util.is_config.mm_dir(d):
# return True
# if files != None and type(files) is list and len(files) > 0:
# for f in files:
# if util.util.is_mm_file(f):
# return True
# return False
class RefreshActivePropertiesFromServerCommand(sublime_plugin.WindowCommand):
def run (self):
if sublime.ok_cancel_dialog("Are you sure you want to overwrite the selected files' apex properties from Salesforce?", "Refresh Apex Properties"):
params = {
"files" : [util.get_active_file()]
}
mm.call('refresh_properties', context=self, params=params)
util.send_usage_statistics('Refresh Active Properties From Server')
def is_visible(self):
if not util.is_mm_file():
return False
filename = util.get_active_file()
basename = os.path.basename(filename)
data = util.get_apex_file_properties()
if not basename in data:
return True
elif 'conflict' in data[basename] and data[basename]['conflict'] == True:
return True
else:
return False
class RefreshPropertiesFromServerCommand(sublime_plugin.WindowCommand):
def run (self, dirs, files):
if sublime.ok_cancel_dialog("Are you sure you want to overwrite the selected files' apex properties from Salesforce?", "Refresh Apex Properties"):
if dirs != None and type(dirs) is list and len(dirs) > 0:
params = {
"directories" : dirs
}
elif files != None and type(files) is list and len(files) > 0:
params = {
"files" : files
}
mm.call('refresh_properties', context=self, params=params)
util.send_usage_statistics('Refresh Selected Properties From Server')
def is_visible(self, dirs, files):
if not util.is_mm_project():
return False
if files != None and type(files) is list and len(files) > 0:
filename = files[0]
basename = os.path.basename(filename)
data = util.get_apex_file_properties()
if not basename in data:
return True
elif 'conflict' in data[basename] and data[basename]['conflict'] == True:
return True
else:
return False
return True
def is_enabled(self, dirs, files):
if dirs != None and type(dirs) is list and len(dirs) > 0:
for d in dirs:
if util.is_config.mm_dir(d):
return True
if files != None and type(files) is list and len(files) > 0:
for f in files:
if util.util.is_mm_file(f):
return True
return False
#refreshes the currently active file from the server
class RefreshActiveFileCommand(sublime_plugin.WindowCommand):
def run(self):
if sublime.ok_cancel_dialog("Are you sure you want to overwrite this file's contents from Salesforce?", "Refresh"):
params = {
"files" : [util.get_active_file()]
}
mm.call('refresh', context=self, params=params)
util.send_usage_statistics('Refresh Active File From Server')
def is_visible(self):
return util.is_mm_file()
#refreshes the currently active file from the server
class SynchronizeActiveMetadataCommand(sublime_plugin.WindowCommand):
def run(self):
params = {
"files" : [util.get_active_file()]
}
mm.call('synchronize', context=self, params=params)
util.send_usage_statistics('Synchronized Active File to Server')
def is_visible(self):
return util.is_mm_file()
#opens the apex class, trigger, component or page on the server
class SynchronizeSelectedMetadataCommand(sublime_plugin.WindowCommand):
def run (self, dirs, files):
if dirs != None and type(dirs) is list and len(dirs) > 0:
params = {
"directories" : dirs
}
elif files != None and type(files) is list and len(files) > 0:
params = {
"files" : files
}
mm.call('synchronize', context=self, params=params)
util.send_usage_statistics('Synchronized Selected Metadata With Server')
def is_visible(self, dirs, files):
if dirs != None and type(dirs) is list and len(dirs) > 0:
for d in dirs:
if util.is_config.mm_dir(d):
return True
if files != None and type(files) is list and len(files) > 0:
for f in files:
if util.util.is_mm_file(f):
return True
return False
#opens the apex class, trigger, component or page on the server
class RunActiveApexTestsCommand(sublime_plugin.WindowCommand):
def run(self):
filename, ext = os.path.splitext(os.path.basename(util.get_active_file()))
params = {
"selected" : [filename]
}
mm.call('unit_test', context=self, params=params)
util.send_usage_statistics('Run Apex Tests in Active File')
def is_visible(self):
return util.is_apex_class_file()
def is_enabled(self):
return util.is_apex_test_file()
#opens the apex class, trigger, component or page on the server
class RunSelectedApexTestsCommand(sublime_plugin.WindowCommand):
def run(self, files):
if files != None and type(files) is list and len(files) > 0:
params = {
"selected" : []
}
for f in files:
filename, ext = os.path.splitext(os.path.basename(f))
params['selected'].append(filename)
mm.call('unit_test', context=self, params=params)
util.send_usage_statistics('Run Apex Tests in Active File')
def is_visible(self, files):
if files != None and type(files) is list and len(files) > 0:
for f in files:
if util.is_apex_class_file(f):
return True
return False
def is_enabled(self, files):
if files != None and type(files) is list and len(files) > 0:
for f in files:
if util.is_apex_test_file(f): return True
return False
#opens the apex class, trigger, component or page on the server
class OpenActiveSfdcUrlCommand(sublime_plugin.WindowCommand):
def run(self):
params = {
"files" : [util.get_active_file()]
}
mm.call('open_sfdc_url', context=self, params=params)
util.send_usage_statistics('Open Active File On Server')
def is_visible(self):
return util.is_mm_file()
def is_enabled(self):
return util.is_browsable_file()
#opens the WSDL file for apex webservice classes
class OpenActiveSfdcWsdlUrlCommand(sublime_plugin.WindowCommand):
def run(self):
params = {
"files" : [util.get_active_file()],
"type" : "wsdl"
}
mm.call('open_sfdc_url', context=self, params=params)
util.send_usage_statistics('Open Active WSDL File On Server')
def is_visible(self):
return util.is_apex_class_file()
def is_enabled(self):
if util.is_apex_webservice_file():
return True
return False
#opens the apex class, trigger, component or page on the server
class OpenSelectedSfdcUrlCommand(sublime_plugin.WindowCommand):
def run (self, files):
if files != None and type(files) is list and len(files) > 0:
params = {
"files" : files
}
mm.call('open_sfdc_url', context=self, params=params)
util.send_usage_statistics('Open Selected File On Server')
def is_visible(self, files):
if not util.is_mm_project: return False
if files != None and type(files) is list and len(files) > 0:
for f in files:
if util.is_browsable_file(f): return True
return False
#opens the WSDL file for apex webservice classes
class OpenSelectedSfdcWsdlUrlCommand(sublime_plugin.WindowCommand):
def run(self, files):
if files != None and type(files) is list and len(files) > 0:
params = {
"files" : files,
"type" : "wsdl"
}
mm.call('open_sfdc_url', context=self, params=params)
util.send_usage_statistics('Open Selected WSDL File On Server')
def is_visible(self, files):
if files != None and type(files) is list and len(files) > 0:
for f in files:
if util.is_apex_class_file(f):
return True
return False
def is_enabled(self, files):
if files != None and type(files) is list and len(files) > 0:
for f in files:
if util.is_apex_webservice_file(f):
return True
return False
#deletes selected metadata
class DeleteMetadataCommand(sublime_plugin.WindowCommand):
def run(self, files):
if sublime.ok_cancel_dialog("Are you sure you want to delete the selected files from Salesforce?", "Delete"):
params = {
"files" : files
}
mm.call('delete', context=self, params=params)
util.send_usage_statistics('Delete Metadata')
def is_visible(self):
return util.is_mm_file()
def is_enabled(self):
return util.is_mm_file()
#deletes selected metadata
class DeleteActiveMetadataCommand(sublime_plugin.WindowCommand):
def run(self):
active_path = util.get_active_file()
active_file = os.path.basename(active_path)
if sublime.ok_cancel_dialog("Are you sure you want to delete "+active_file+" file from Salesforce?", "Delete"):
params = {
"files" : [active_file]
}
result = mm.call('delete', context=self, params=params)
self.window.run_command("close")
util.send_usage_statistics('Delete Metadata')
def is_enabled(self):
return util.is_mm_file()
def is_visible(self):
return util.is_mm_project()
#attempts to compile the entire project
class CompileProjectCommand(sublime_plugin.WindowCommand):
def run(self):
if sublime.ok_cancel_dialog("Are you sure you want to compile the entire project?", "Compile Project"):
mm.call('compile_project', context=self)
util.send_usage_statistics('Compile Project')
def is_enabled(command):
return util.is_mm_project()
#refreshes the currently active file from the server
class IndexApexFileProperties(sublime_plugin.WindowCommand):
def run(self):
mm.call('index_apex', False, context=self)
util.send_usage_statistics('Index Apex File Properties')
def is_enabled(command):
return util.is_mm_project()
#indexes the meta data based on packages.xml
class IndexMetadataCommand(sublime_plugin.WindowCommand):
def run(self):
mm.call('index_metadata', True, context=self)
util.send_usage_statistics('Index Metadata')
def is_enabled(command):
return util.is_mm_project()
class NewQuickLogCommand(sublime_plugin.WindowCommand):
def run(self):
mm.call('new_quick_log', True)
util.send_usage_statistics('New Quick Log')
#refreshes the currently active file from the server
class FetchLogsCommand(sublime_plugin.WindowCommand):
def run(self):
mm.call('fetch_logs', True)
util.send_usage_statistics('Fetch Apex Logs')
#refreshes the currently active file from the server
class FetchCheckpointsCommand(sublime_plugin.WindowCommand):