This repository has been archived by the owner on Jul 11, 2019. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 118
/
Copy pathmavensmate.py
executable file
·1699 lines (1445 loc) · 69.2 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 sublime
import sublime_plugin
import os
import json
import sys
import re
import subprocess
import time
from xml.dom.minidom import parse
import MavensMate.config as config
import MavensMate.util as util
import MavensMate.lib.adapter as mm
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.merge import *
from MavensMate.lib.completioncommon import *
debug = None
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__)), "lib", "apex", "completions.json"))
apex_system_completions = []
for top_level_class_name in apex_completions["publicDeclarations"]["System"].keys():
apex_system_completions.append((top_level_class_name+"\t[Standard Apex Class]", top_level_class_name))
reloader_name = 'MavensMate.lib.reloader'
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
import MavensMate.lib.reloader as reloader
def plugin_loaded():
from package_control import events
settings = sublime.load_settings('mavensmate.sublime-settings')
config.setup_logging()
global debug
debug = config.debug
debug('=============> Starting MavensMate for Sublime Text')
active_window_id = sublime.active_window().id()
printer = PanelPrinter.get(active_window_id)
merge_settings = sublime.load_settings('mavensmate-merge.sublime-settings')
config.settings = settings
config.merge_settings = merge_settings
util.package_check()
package_name = 'MavensMate'
if events.install(package_name):
printer.show()
printer.write('\nWelcome to MavensMate for Sublime Text. In order for this plugin to operate, MavensMate Desktop must be installed and running. Please visit https://github.com/joeferraro/MavensMate/tree/master/docs for more information. Happy Coding!\n')
try:
if settings.get('mm_start_mavensmate_app', False):
util.start_mavensmate_app(printer)
time.sleep(1.5)
if settings.get('mm_ping_mavensmate_server_on_startup', False):
mm.ping_server()
except Exception as e:
printer.show()
message = '[ERROR]: '+str(e)+'\n'
printer.write('\n'+message+'\n')
return
####### <--START--> COMMANDS THAT USE THE MAVENSMATE UI ##########
#displays mavensmate ui
class OpenMavensMateUi(sublime_plugin.ApplicationCommand):
def run(command):
mm.call('open-ui', True, body={'args': { 'ui' : True }})
#opens MavensMate Desktop
class OpenMavensMateApp(sublime_plugin.ApplicationCommand):
def run(command):
active_window_id = sublime.active_window().id()
printer = PanelPrinter.get(active_window_id)
util.start_mavensmate_app(printer)
#opens salesforce setup
class OpenSalesforceOrg(sublime_plugin.ApplicationCommand):
def run(command):
mm.call('open-sfdc', True, body={'args': { 'ui' : True }})
def is_enabled(command):
return util.is_mm_project()
#opens salesforce setup
class OpenSettings(sublime_plugin.ApplicationCommand):
def run(command):
mm.call('open-settings', True, body={'args': { 'ui' : True }})
#displays new project dialog
class NewProjectCommand(sublime_plugin.ApplicationCommand):
def run(command):
mm.call('new-project', True, body={'args': { 'ui' : True }})
#creates a MavensMate project from an existing directory
class CreateMavensMateProject(sublime_plugin.WindowCommand):
def run (self, dirs):
mm.call('new-project-from-existing-directory', False, body={'args': { 'ui': True, 'directory': dirs[0], 'origin': dirs[0] }})
def is_visible(self, dirs):
if dirs != None and type(dirs) is list and len(dirs) > 1:
return False
if util.is_mm_project():
return False
directory = dirs[0]
if not os.path.isfile(os.path.join(directory, "src", "package.xml")):
return False
if not os.path.exists(os.path.join(directory, "src")):
return False
return True
#displays edit project dialog
class EditProjectCommand(sublime_plugin.ApplicationCommand):
def run(command):
mm.call('edit-project', True, body={'args': { 'ui' : True }})
def is_enabled(command):
return util.is_mm_project()
class SalesforceAuthenticationCommand(sublime_plugin.ApplicationCommand):
def run(command):
mm.call('oauth-project', True, body={'args': { 'ui' : True }})
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()
body = {}
try:
if os.path.exists(active_file):
filename, ext = os.path.splitext(os.path.basename(util.get_active_file()))
if ext == '.cls':
body = {
"classes" : [filename]
}
else:
body = {}
else:
body = {}
except:
body = {}
body['args'] = { 'ui' : True }
mm.call('run-tests', True, context=command, body=body)
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', True, body={'args': { 'ui' : True }})
def is_enabled(command):
return util.is_mm_project()
#displays deploy dialog
class DeployToServerCommand(sublime_plugin.ApplicationCommand):
def run(command):
mm.call('deploy', True, body={'args': { 'ui' : True }})
def is_enabled(command):
return util.is_mm_project()
#displays new apex class dialog
class NewApexClassCommand(sublime_plugin.ApplicationCommand):
def run(command):
mm.call('new-metadata', True, body={'args': { 'ui': True, 'type': 'ApexClass' }})
def is_enabled(command):
return util.is_mm_project()
#displays new apex trigger dialog
class NewApexTriggerCommand(sublime_plugin.ApplicationCommand):
def run(command):
mm.call('new-metadata', True, body={'args': { 'ui': True, 'type': 'ApexTrigger' }})
def is_enabled(command):
return util.is_mm_project()
#displays new apex page dialog
class NewApexPageCommand(sublime_plugin.ApplicationCommand):
def run(command):
mm.call('new-metadata', False, body={'args': { 'ui': True, 'type': 'ApexPage' }})
def is_enabled(command):
return util.is_mm_project()
#displays new apex component dialog
class NewApexComponentCommand(sublime_plugin.ApplicationCommand):
def run(command):
mm.call('new-metadata', True, body={'args': { 'ui': True, 'type': 'ApexComponent' }})
def is_enabled(command):
return util.is_mm_project()
#displays new apex component dialog
class NewLightningAppCommand(sublime_plugin.ApplicationCommand):
def run(command):
mm.call('new-lightning-app', True, body={'args': { 'ui' : True }})
def is_enabled(command):
return util.is_mm_project()
#displays new apex component dialog
class NewLightningComponentCommand(sublime_plugin.ApplicationCommand):
def run(command):
mm.call('new-lightning-component', True, body={'args': { 'ui' : True }})
def is_enabled(command):
return util.is_mm_project()
#displays new apex component dialog
class NewLightningEventCommand(sublime_plugin.ApplicationCommand):
def run(command):
mm.call('new-lightning-event', True, body={'args': { 'ui' : True }})
def is_enabled(command):
return util.is_mm_project()
#displays new apex component dialog
class NewLightningInterfaceCommand(sublime_plugin.ApplicationCommand):
def run(command):
mm.call('new-lightning-interface', True, body={'args': { 'ui' : True }})
def is_enabled(command):
return util.is_mm_project()
#displays new apex component dialog
class NewLightningTokens(sublime_plugin.ApplicationCommand):
def run(command):
mm.call('new-lightning-tokens', True, body={'args': { 'ui' : True }})
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):
debug('FORCE COMPILING!')
if files == None:
files = [util.get_active_file()]
body = {
"paths" : files,
"force" : True
}
mm.call('compile-metadata', context=self.window, body=body)
def is_enabled(self):
return util.is_mm_project();
#deploys the currently active file
class ForceCompileFileCommand(sublime_plugin.WindowCommand):
def run(self, paths=None):
debug('FORCE COMPILING!')
if paths == None:
paths = [util.get_active_file()]
body = {
"paths" : paths,
"force" : True
}
mm.call('compile-metadata', context=self.window, body=body)
#handles compiling to server on save
class SaveListener(sublime_plugin.EventListener):
def on_post_save_async(self, view):
settings = sublime.load_settings('mavensmate.sublime-settings')
if settings.get('mm_compile_on_save') == True and util.is_mm_file() == True:
body = {
"paths" : [util.get_active_file()]
}
mm.call('compile-metadata', context=view, body=body)
#deploys the currently active file
class CompileActiveFileCommand(sublime_plugin.WindowCommand):
def run(self):
body = {
"paths" : [util.get_active_file()]
}
mm.call('compile-metadata', context=self, body=body)
def is_enabled(command):
return util.is_mm_file()
def is_visible(command):
return util.is_mm_project()
#deploys the currently active file
class SyncWithServerCommand(sublime_plugin.WindowCommand):
def run(self):
body = {
"path" : util.get_active_file()
}
mm.call('sync-with-server', context=self, body=body)
def is_enabled(command):
return util.is_mm_file()
def is_visible(command):
return util.is_mm_project()
class SyntaxHandler(sublime_plugin.EventListener):
def on_load_async(self, view):
try:
fn = view.file_name()
ext = util.get_file_extension(fn)
if ext == '.cls' or ext == '.trigger':
if "linux" in sys.platform or "darwin" in sys.platform:
view.set_syntax_file(os.path.join("Packages","MavensMate","sublime","lang","Apex.sublime-syntax"))
else:
view.set_syntax_file(os.path.join("Packages/MavensMate/sublime/lang/Apex.sublime-syntax"))
elif ext == '.page' or ext == '.component':
if "linux" in sys.platform or "darwin" in sys.platform:
view.set_syntax_file(os.path.join("Packages","MavensMate","sublime","lang","Visualforce.sublime-syntax"))
else:
view.set_syntax_file(os.path.join("Packages/MavensMate/sublime/lang/Visualforce.sublime-syntax"))
elif ext == '.app' or ext == '.auradoc' or ext == '.cmp' or ext == '.design' or ext == '.tokens' or ext == '.evt':
if "linux" in sys.platform or "darwin" in sys.platform:
view.set_syntax_file(os.path.join("Packages","XML","XML.tmLanguage"))
else:
view.set_syntax_file(os.path.join("Packages/XML/XML.tmLanguage"))
elif ext == '.log' and ('/debug/' in fn or '\\debug\\' in fn or '\\apex-scripts\\log\\' in fn or '/apex-scripts/log/' in fn):
if "linux" in sys.platform or "darwin" in sys.platform:
view.set_syntax_file(os.path.join("Packages","MavensMate","sublime","lang","MMLog.sublime-syntax"))
else:
view.set_syntax_file(os.path.join("Packages/MavensMate/sublime/lang/MMLog.sublime-syntax"))
except:
pass
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
body = {
"paths" : files
}
mm.call('compile-metadata', context=self, body=body)
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.is_mm_file(f):
return True
return False
class RunAllTestsAsyncCommand(sublime_plugin.WindowCommand):
def run(self):
mm.call('run_all_tests', context=self)
def is_enabled(command):
return util.is_mm_project()
#runs apex unit tests using the async api
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':
body = {
"tests" : [filename],
"skipCoverage" : True
}
else:
body = {}
else:
body = {}
except:
body = {}
mm.call('run-tests', context=self, body=body, message="Running Apex unit test(s)...")
def is_enabled(command):
return util.is_apex_class_file()
# 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):
# mm.call('new-apex-script', False, body={ 'name': name }, message='Creating new Apex Script: '+name)
# def is_enabled(command):
# return util.is_mm_project()
#runs apex unit tests using the async api
class RunAsyncApexTestMethodCommand(sublime_plugin.TextCommand):
def run(self, edit):
sublime.active_window().show_input_panel("Comma Delimited Test Method Names", "MyTestMethodName", self.finish, None, None)
def finish(self, test_method_names):
active_file = util.get_active_file()
test_method_names = test_method_names.replace(' ', '')
try:
body = {
"tests" : [
{
"testNameOrPath" : active_file,
"methodNames": test_method_names.split(',')
}
],
"skipCoverage": True
}
except:
body = {}
mm.call('run-test-method', context=self, body=body, message="Running Apex unit test methods: "+test_method_names)
def is_enabled(command):
return util.is_apex_class_file()
#deploys the currently open tabs
class CompileTabsCommand(sublime_plugin.WindowCommand):
def run (self):
body = {
"paths" : util.get_tab_file_names()
}
mm.call('compile-metadata', context=self, body=body)
#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)
def is_enabled(command):
return util.is_mm_project()
class OpenProjectSettingsCommand(sublime_plugin.WindowCommand):
def run(self):
path = os.path.join(util.mm_project_directory(),util.get_project_name()+'.sublime-settings')
sublime.active_window().open_file(path)
def is_enabled(command):
return util.is_mm_project()
class RunApexScriptCommand(sublime_plugin.WindowCommand):
def run(self):
body = {
"paths" : [ util.get_active_file() ]
}
mm.call('run-apex-script', context=self, body=body, message='Running Apex Script: '+os.path.basename(util.get_active_file()))
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):
mm.call('new-apex-script', False, body={ 'name': name }, message='Creating new Apex Script: '+name)
def is_enabled(command):
return util.is_mm_project()
class ExecuteSoqlCommand(sublime_plugin.TextCommand):
def run(self, edit):
sublime.active_window().show_input_panel("SOQL Statement", "SELECT ID FROM Account LIMIT 1", self.finish, None, None)
def finish(self, soql):
mm.call('execute-soql', body={ 'soql': soql }, message='Executing SOQL statement...', callback=self.show_results)
def show_results(self, thread, res):
debug('showing results ...')
debug(res)
new_view = thread.window.new_file()
if "linux" in sys.platform or "darwin" in sys.platform:
new_view.set_syntax_file(os.path.join("Packages","MavensMate","sublime","lang","JSON.tmLanguage"))
else:
new_view.set_syntax_file(os.path.join("Packages/MavensMate/sublime/lang/JSON.tmLanguage"))
new_view.set_scratch(True)
new_view.set_name("SOQL Result")
new_view.run_command('generic_text', {'text': res })
def is_enabled(command):
return util.is_mm_project()
#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:
body = {
'paths': dirs
}
elif files != None and type(files) is list and len(files) > 0:
body = {
'paths': files
}
mm.call('refresh-metadata', context=self, body=body)
def is_visible(self, dirs, files):
return util.is_mm_project()
#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"):
body = {
'paths': [util.get_active_file()]
}
mm.call('refresh-metadata', context=self, body=body)
def is_visible(self):
return util.is_mm_file()
#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()))
body = {
'classes': [filename]
}
mm.call('run-tests', context=self, body=body, message='Running Apex unit test(s)...')
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:
body = {
'classes': files
}
mm.call('run-tests', context=self, body=body, message='Running Apex unit test(s)...')
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):
body = {
'paths': [util.get_active_file()],
'callThrough': True
}
mm.call('open-metadata', context=self, body=body)
def is_visible(self):
return util.is_mm_file()
def is_enabled(self):
return util.is_browsable_file()
#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:
body = {
'paths': files,
'callThrough': True
}
mm.call('open-metadata', context=self, body=body)
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
#deletes selected metadata
class DeleteMetadataCommand(sublime_plugin.WindowCommand):
def run(self, dirs, files):
if dirs != None and len(dirs) > 0:
if sublime.ok_cancel_dialog("Are you sure you want to delete the selected paths from Salesforce?", "Delete"):
body = {
"paths": dirs
}
mm.call('delete-metadata', context=self, body=body)
else:
if sublime.ok_cancel_dialog("Are you sure you want to delete the selected files from Salesforce?", "Delete"):
body = {
"paths": files
}
mm.call('delete-metadata', context=self, body=body)
# def is_visible(self):
# return util.is_mm_file()
# def is_enabled(self):
# return util.is_mm_file()
#deletes selected metadata
class RefreshProjectApexSymbols(sublime_plugin.WindowCommand):
def run(self):
mm.call('index-apex', context=self, message="Refreshing Symbol Tables")
def is_enabled(self):
return util.is_mm_project()
#deletes selected metadata
class RefreshApexSymbols(sublime_plugin.WindowCommand):
def run(self, files):
if files != None and type(files) is list and len(files) == 1:
class_names = []
for f in files:
class_names.append(os.path.basename(f).replace(".json",".cls"))
body = {
"paths" : class_names
}
mm.call('index-apex', context=self, body=body, message="Refreshing Symbol Table(s) for selected Apex Classes")
def is_visible(self, files):
try:
if not util.is_mm_project():
return False
if files != None and type(files) is list and len(files) == 1:
for f in files:
if os.path.join(util.mm_project_directory(),"src","classes") not in f:
return False
if "-meta.xml" in f:
return False
elif files != None and type(files) is list and len(files) == 0:
return False
return True
except:
return False
def is_enabled(self):
return util.is_mm_project()
#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"):
body = {
"paths" : [ active_path ]
}
mm.call('delete-metadata', context=self, body=body)
self.window.run_command("close")
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)
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)
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)
def is_enabled(command):
return util.is_mm_project()
class StartLoggingCommand(sublime_plugin.WindowCommand):
def run(self):
mm.call('start-logging', True)
def is_enabled(self):
return util.is_mm_project()
class StopLoggingCommand(sublime_plugin.WindowCommand):
def run(self):
mm.call('stop-logging', True)
def is_enabled(self):
return util.is_mm_project()
class FlushDebugLogsCommand(sublime_plugin.WindowCommand):
def run(self):
mm.call('flush-logs', True, message='Flushing local debug logs...')
def is_enabled(self):
return util.is_mm_project()
#refreshes the currently active file from the server
class FetchCheckpointsCommand(sublime_plugin.WindowCommand):
def run(self):
mm.call('fetch_checkpoints', True)
def is_enabled(self):
return util.is_mm_project()
#when a class or trigger file is opened, adds execution overlay markers if applicable
class HideApexCheckpoints(sublime_plugin.WindowCommand):
def run(self):
try:
util.clear_marked_line_numbers(self.window.active_view(), "overlay")
except Exception:
debug('error hidding checkpoints')
def is_enabled(self):
return util.is_apex_class_file()
#when a class or trigger file is opened, adds execution overlay markers if applicable
class ShowApexCheckpoints(sublime_plugin.WindowCommand):
def run(self):
debug('attempting to load apex overlays for current file')
try:
active_view = self.window.active_view()
fileName, ext = os.path.splitext(os.path.basename(util.get_active_file()))
if ext == ".cls" or ext == ".trigger":
api_name = fileName
overlays = util.parse_json_from_file(util.mm_project_directory()+"/config/.overlays")
lines = []
for o in overlays:
if o['API_Name'] == api_name:
lines.append(int(o["Line"]))
sublime.set_timeout(lambda: util.mark_overlays(active_view, lines), 10)
except Exception as e:
debug('execution overlay loader error')
debug('', e)
def is_enabled(self):
return util.is_apex_class_file()
#deletes overlays
class DeleteApexCheckpointCommand(sublime_plugin.WindowCommand):
def run(self):
#options = [['Delete All In This File', '*']]
options = []
fileName, ext = os.path.splitext(os.path.basename(util.get_active_file()))
if ext == ".cls" or ext == ".trigger":
self.api_name = fileName
overlays = util.get_execution_overlays(util.get_active_file())
for o in overlays:
options.append(['Line '+str(o["Line"]), str(o["Id"])])
self.results = options
self.window.show_quick_panel(options, self.panel_done, sublime.MONOSPACE_FONT)
def panel_done(self, picked):
if 0 > picked < len(self.results):
return
self.overlay = self.results[picked]
body = {
"id" : self.overlay[1]
}
mm.call('delete_apex_overlay', context=self, body=body, message="Deleting checkpoint...", callback=self.reload)
def reload(self, cmd=None):
debug("Reloading Apex Checkpoints")
cmd.window.run_command("show_apex_checkpoints")
def is_enabled(self):
return util.is_apex_class_file()
#refreshes the currently active file from the server
class IndexApexCheckpointsCommand(sublime_plugin.WindowCommand):
def run(self):
mm.call('index_apex_overlays', False, context=self, callback=self.reload)
def is_enabled(command):
return util.is_mm_project()
def reload(self, cmd=None):
debug("Reloading Apex Checkpoints")
cmd.window.run_command("show_apex_checkpoints")
#gets apex code coverage for the current class
class GetApexCodeCoverageCommand(sublime_plugin.WindowCommand):
def run(self):
body = {
"paths" : [util.get_active_file()]
}
mm.call('get-coverage', True, context=self, message="Retrieving Apex Code Coverage for "+util.get_file_name_no_extension(body["paths"][0]), body=body)
def is_enabled(command):
return util.is_apex_class_or_trigger_file()
#gets apex code coverage for the current class
class HideCoverageCommand(sublime_plugin.WindowCommand):
def run(self):
util.clear_marked_line_numbers(self.window.active_view(), "no_apex_coverage")
def is_enabled(command):
return util.is_apex_class_or_trigger_file()
#refreshes the currently active file from the server
class GetOrgWideTestCoverageCommand(sublime_plugin.WindowCommand):
def run(self):
mm.call('get-coverage', True, context=self, body={'global': True}, message="Retrieving org-wide test coverage...")
def is_enabled(command):
return util.is_mm_project()
#creates a new overlay
class NewApexCheckpoint(sublime_plugin.WindowCommand):
def run(self):
fileName, ext = os.path.splitext(os.path.basename(util.get_active_file()))
if ext == ".cls" or ext == ".trigger":
if ext == '.cls':
self.object_type = 'ApexClass'
else:
self.object_type = 'ApexTrigger'
self.api_name = fileName
number_of_lines = util.get_number_of_lines_in_file(util.get_active_file())
lines = list(range(number_of_lines))
options = []
lines.pop(0)
for l in lines:
options.append(str(l))
self.results = options
self.window.show_quick_panel(options, self.panel_done, sublime.MONOSPACE_FONT)
def panel_done(self, picked):
if 0 > picked < len(self.results):
return
self.line_number = self.results[picked]
#print self.line_number
body = {
"ActionScriptType" : "None",
"Object_Type" : self.object_type,
"API_Name" : self.api_name,
"IsDumpingHeap" : True,
"Iteration" : 1,
"Line" : int(self.line_number)
}
#util.mark_overlay(self.line_number) #cant do this here bc it removes the rest of them
mm.call('new_apex_overlay', context=self, body=body, message="Creating new checkpoint at line "+self.line_number+"...", callback=self.reload)
def reload(self, cmd=None):
debug("Reloading Apex Checkpoints")
cmd.window.run_command("show_apex_checkpoints")
def is_enabled(self):
return util.is_apex_class_file()
#right click context menu support for resource bundle creation
class NewResourceBundleCommand(sublime_plugin.WindowCommand):
def run(self, files, dirs):
if sublime.ok_cancel_dialog("Are you sure you want to create a resource bundle for the selected static resource", "Create Resource Bundle"):
mm.call('new-resource-bundle', True, context=self, message="Creating resource bundle...", body={ "paths": [ files[0] ] })
def is_visible(self, files, dirs):
if not util.is_mm_project():
return False
if dirs != None and type(dirs) is list and len(dirs) > 0:
return False
is_ok = True
if files != None and type(files) is list and len(files) > 0:
for f in files:
basename = os.path.basename(f)
if "." not in basename:
is_ok = False
return
if "." in basename and basename.split(".")[-1] != "resource":
is_ok = False
break
return is_ok
#prompts users to select a static resource to create a resource bundle
class CreateResourceBundleCommand(sublime_plugin.WindowCommand):
def run(self):
srs = []
for dirname in os.listdir(os.path.join(util.mm_project_directory(),"src","staticresources")):
if dirname == '.DS_Store' or dirname == '.' or dirname == '..' or '-meta.xml' in dirname : continue
srs.append(dirname)
self.results = srs
self.window.show_quick_panel(srs, self.panel_done,
sublime.MONOSPACE_FONT)
def is_visible(self):
return util.is_mm_project()
def panel_done(self, picked):
if 0 > picked < len(self.results):
return
static_resource_path = os.path.join(util.mm_project_directory(),"src","staticresources",self.results[picked])
mm.call('new-resource-bundle', True, body={ "paths" : [ static_resource_path ] }, context=self, message="Creating resource bundle...")
#deploys selected resource bundle to the server
class DeployResourceBundleCommand(sublime_plugin.WindowCommand):
def run(self):
self.rbs_map = {}
rbs = []
for dirname in os.listdir(os.path.join(util.mm_project_directory(),"resource-bundles")):
if dirname == '.DS_Store' or dirname == '.' or dirname == '..' : continue
rbs.append(dirname)
self.results = rbs
self.window.show_quick_panel(rbs, self.panel_done,
sublime.MONOSPACE_FONT)
def panel_done(self, picked):
if 0 > picked < len(self.results):
return
bundle_path = os.path.join(util.mm_project_directory(),"resource-bundles",self.results[picked])
mm.call('deploy-resource-bundle', True, body={ "paths": [ bundle_path ] }, context=self, message="Deploying resource bundle...")
#right click context menu support for resource bundle refresh
class RefreshResourceBundleCommand(sublime_plugin.WindowCommand):
def run(self, dirs, files):
if sublime.ok_cancel_dialog("This command will refresh the resource bundle(s) based on your local project's corresponding static resource(s). Do you wish to continue?", "Refresh"):
#TODO: adapter refresh
pass
def is_visible(self, dirs, files):
try:
if files != None and type(files) is list and len(files) > 0:
return False
if not util.is_mm_project():
return False
is_ok = True
if dirs != None and type(dirs) is list and len(dirs) > 0:
for d in dirs:
basename = os.path.basename(d)
if "." not in basename:
is_ok = False
break
if "." in basename and basename.split(".")[-1] != "resource":
is_ok = False
break
return is_ok
except:
return False
#generic handler for writing text to an output panel (sublime text 3 requirement)
class MavensMateOutputText(sublime_plugin.TextCommand):
def run(self, edit, text, *args, **kwargs):