-
Notifications
You must be signed in to change notification settings - Fork 7
Expand file tree
/
Copy pathActionsProvider.monkey2
More file actions
470 lines (376 loc) · 14.5 KB
/
ActionsProvider.monkey2
File metadata and controls
470 lines (376 loc) · 14.5 KB
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
Namespace ted2go
Function InitHotkeys()
ActionsProvider.Init()
End
Function ActionById:Action( actionId:String )
Return ActionsProvider.GetAction( actionId )
End
Class ActionsProvider
Function Init()
CreateDefaultActions()
Local pathToJson:=Prefs.HotkeysFilePath
Load( pathToJson )
' save merged version: default+custom
Save( pathToJson )
End
Function GetAction:Action( actionId:String )
Local act:=_actions[actionId]
If act=Null
RuntimeError( "Have no action for actionId="+actionId )
Endif
Return act
End
Function CreateAction:Action( actionId:String,hotKeyString:String )
' todo !!! check for duplicates
Local actionTitle:=ActionTitle.Get( actionId )
Local act:=ActionFromString( actionTitle,hotKeyString )
_actions[actionId]=act
Return act
End
Function Save( pathToJson:String )
Local jobj:=New JsonObject
Local jarr:=New JsonArray
jobj["hotkeys"]=jarr
For Local key:=Eachin _actions.Keys
Local action:=_actions[key]
Local jval:=New JsonObject
jval["id"]=New JsonString( key )
jval["hotkey"]=New JsonString( action.HotKeyText )
jarr.Add( jval )
Next
Local json:=jobj.ToJson()
SaveString( json,pathToJson )
End
Private
Global _actions:=New StringMap<Action>
Function Load( pathToJson:String )
Local jobj:=JsonObject.Load( pathToJson )
If Not jobj Return
Local jarr:=jobj.GetArray( "hotkeys" )
For Local jval:=Eachin jarr
Local jobj2:=jval.ToObject()
Local id:=jobj2["id"].ToString()
Local action:=_actions[id]
If action
' actualize action
Local hotkey:=jobj2["hotkey"].ToString()
Local pair:=HotKeyFromString( hotkey )
action.HotKey=pair.Item1
action.HotKeyModifiers=pair.Item2
Endif
Next
End
Function CreateDefaultActions()
#If __TARGET__="macos"
CreateAction( ActionId.Build,"Ctrl+B" )
CreateAction( ActionId.Run,"Ctrl+R" )
CreateAction( ActionId.Semant,"Ctrl+C" )
CreateAction( ActionId.Debug,"Ctrl+D" )
CreateAction( ActionId.ForceStop,"Ctrl+Shift+R" )
CreateAction( ActionId.ProductSettings,"" )
CreateAction( ActionId.NextError,"F4" )
CreateAction( ActionId.LockBuildFile,"Cmd+L" )
CreateAction( ActionId.UpdateModules,"Cmd+U" )
CreateAction( ActionId.ModuleManager,"" )
CreateAction( ActionId.RebuildDocs,"" )
CreateAction( ActionId.ExpandSelection,"Alt+Up" )
CreateAction( ActionId.ShrinkSelection,"Alt+Down" )
CreateAction( ActionId.WordWrap,"Alt+Z" )
CreateAction( ActionId.DeleteLine,"Ctrl+Shift+K" )
CreateAction( ActionId.DeleteWordForward,"Ctrl+Delete" )
CreateAction( ActionId.DeleteWordBackward,"Ctrl+Backspace" )
CreateAction( ActionId.DeleteToBegin,"Cmd+Backspace" )
CreateAction( ActionId.DeleteToEnd,"Ctrl+K" )
CreateAction( ActionId.MakeLowercase,"Ctrl+Shift+L" )
CreateAction( ActionId.MakeUppercase,"Ctrl+Shift+U" )
CreateAction( ActionId.SwapCase,"" )
CreateAction( ActionId.CommentBlock,"Cmd+'" )
CreateAction( ActionId.UncommentBlock,"Cmd+Shift+'" )
CreateAction( ActionId.NewFile,"Cmd+T" )
CreateAction( ActionId.OpenFile,"Cmd+O" )
CreateAction( ActionId.CloseTab,"Cmd+W" )
CreateAction( ActionId.NextTab,"Ctrl+Tab" )
CreateAction( ActionId.PrevTab,"Ctrl+Shift+Tab" )
CreateAction( ActionId.CloseOtherTabs,"" )
CreateAction( ActionId.CloseAllTabs,"" )
CreateAction( ActionId.CloseTabsToTheRight,"" )
CreateAction( ActionId.Save,"Cmd+S" )
CreateAction( ActionId.SaveAs,"" )
CreateAction( ActionId.SaveAll,"Cmd+Shift+S" )
CreateAction( ActionId.Quit,"Cmd+Q" )
CreateAction( ActionId.Preferences,"Cmd+," )
CreateAction( ActionId.Find,"Cmd+F" )
CreateAction( ActionId.FindNext,"F3" )
CreateAction( ActionId.FindPrev,"Shift+F3" )
CreateAction( ActionId.FindInFiles,"Cmd+Shift+F" )
CreateAction( ActionId.Replace,"Cmd+R" )
CreateAction( ActionId.ReplaceNext,"" )
CreateAction( ActionId.ReplaceAll,"" )
CreateAction( ActionId.FoldCurrent,"Cmd+[" )
CreateAction( ActionId.FoldCurrentAndParent,"Cmd+Alt+[" )
CreateAction( ActionId.FoldAll,"Cmd+Shift+[" )
CreateAction( ActionId.UnfoldCurrent,"Cmd+]" )
CreateAction( ActionId.UnfoldCurrentAndChildren,"Cmd+Alt+]" )
CreateAction( ActionId.UnfoldAll,"Cmd+Shift+]" )
CreateAction( ActionId.JumpBack,"Cmd+Alt+Left" )
CreateAction( ActionId.JumpForward,"Cmd+Alt+Right" )
CreateAction( ActionId.JumpToLine,"Cmd+G" )
CreateAction( ActionId.JumpToDefinition,"Cmd+B" )
CreateAction( ActionId.JumpToNextScope,"Cmd+Alt+Down" )
CreateAction( ActionId.JumpToPrevScope,"Cmd+Alt+Up" )
CreateAction( ActionId.FullscreenWindow,"Cmd+Ctrl+F" )
CreateAction( ActionId.FullscreenEditor,"Cmd+Ctrl+Shift+F" )
CreateAction( ActionId.ZoomIn,"Ctrl+Keypad +" )
CreateAction( ActionId.ZoomOut,"Ctrl+Keypad -" )
CreateAction( ActionId.ZoomDefault,"Ctrl+Keypad 0" )
CreateAction( ActionId.RecentlyViewedFiles,"Cmd+E" )
CreateAction( ActionId.DuplicateBlock,"Cmd+D" )
#Else
CreateAction( ActionId.Build,"F6" )
CreateAction( ActionId.Run,"F5" )
CreateAction( ActionId.Semant,"F7" )
CreateAction( ActionId.Debug,"F8" )
CreateAction( ActionId.ForceStop,"Shift+F5" )
CreateAction( ActionId.ProductSettings,"" )
CreateAction( ActionId.NextError,"F4" )
CreateAction( ActionId.LockBuildFile,"Ctrl+L" )
CreateAction( ActionId.UpdateModules,"Ctrl+U" )
CreateAction( ActionId.ModuleManager,"" )
CreateAction( ActionId.RebuildDocs,"" )
CreateAction( ActionId.ExpandSelection,"Alt+Up" )
CreateAction( ActionId.ShrinkSelection,"Alt+Down" )
CreateAction( ActionId.WordWrap,"Alt+Z" )
CreateAction( ActionId.DeleteLine,"Ctrl+Shift+K" )
CreateAction( ActionId.DeleteWordForward,"Ctrl+Delete" )
CreateAction( ActionId.DeleteWordBackward,"Ctrl+Backspace" )
CreateAction( ActionId.DeleteToBegin,"Ctrl+Shift+Backspace" )
CreateAction( ActionId.DeleteToEnd,"Ctrl+Shift+Delete" )
CreateAction( ActionId.MakeLowercase,"Ctrl+Shift+L" )
CreateAction( ActionId.MakeUppercase,"Ctrl+Shift+U" )
CreateAction( ActionId.SwapCase,"" )
CreateAction( ActionId.CommentBlock,"Ctrl+'" )
CreateAction( ActionId.UncommentBlock,"Ctrl+Shift+'" )
CreateAction( ActionId.NewFile,"Ctrl+N" )
CreateAction( ActionId.OpenFile,"Ctrl+O" )
CreateAction( ActionId.CloseTab,"Ctrl+W" )
CreateAction( ActionId.NextTab,"Ctrl+Tab" )
CreateAction( ActionId.PrevTab,"Ctrl+Shift+Tab" )
CreateAction( ActionId.CloseOtherTabs,"" )
CreateAction( ActionId.CloseAllTabs,"" )
CreateAction( ActionId.CloseTabsToTheRight,"" )
CreateAction( ActionId.Save,"Ctrl+S" )
CreateAction( ActionId.SaveAs,"" )
CreateAction( ActionId.SaveAll,"Ctrl+Shift+S" )
CreateAction( ActionId.Quit,"Alt+F4" )
CreateAction( ActionId.Preferences,"Ctrl+P" )
CreateAction( ActionId.Find,"Ctrl+F" )
CreateAction( ActionId.FindNext,"F3" )
CreateAction( ActionId.FindPrev,"Shift+F3" )
CreateAction( ActionId.FindInFiles,"Ctrl+Shift+F" )
CreateAction( ActionId.Replace,"Ctrl+H" )
CreateAction( ActionId.ReplaceNext,"" )
CreateAction( ActionId.ReplaceAll,"" )
CreateAction( ActionId.FoldCurrent,"Ctrl+[" )
CreateAction( ActionId.FoldCurrentAndParent,"Ctrl+Alt+[" )
CreateAction( ActionId.FoldAll,"Ctrl+Shift+[" )
CreateAction( ActionId.UnfoldCurrent,"Ctrl+]" )
CreateAction( ActionId.UnfoldCurrentAndChildren,"Ctrl+Alt+]" )
CreateAction( ActionId.UnfoldAll,"Ctrl+Shift+]" )
CreateAction( ActionId.JumpBack,"Ctrl+Alt+Left" )
CreateAction( ActionId.JumpForward,"Ctrl+Alt+Right" )
CreateAction( ActionId.JumpToLine,"Ctrl+G" )
CreateAction( ActionId.JumpToDefinition,"F12" )
CreateAction( ActionId.JumpToNextScope,"Alt+Down" )
CreateAction( ActionId.JumpToPrevScope,"Alt+Up" )
CreateAction( ActionId.FullscreenWindow,"F11" )
CreateAction( ActionId.FullscreenEditor,"Shift+F11" )
CreateAction( ActionId.ZoomIn,"Ctrl+Keypad +" )
CreateAction( ActionId.ZoomOut,"Ctrl+Keypad -" )
CreateAction( ActionId.ZoomDefault,"Ctrl+Keypad 0" )
CreateAction( ActionId.RecentlyViewedFiles,"Ctrl+E" )
CreateAction( ActionId.DuplicateBlock,"Ctrl+D" )
#Endif
End
End
Class ActionId Final
Const Build:="build"
Const Run:="run"
Const Semant:="check"
Const Debug:="debug"
Const ForceStop:="force_stop"
Const ProductSettings:="product_settings"
Const NextError:="next_error"
Const LockBuildFile:="lock_build_file"
Const UpdateModules:="update_modules"
Const ModuleManager:="module_manager"
Const RebuildDocs:="rebuild_docs"
Const ExpandSelection:="expand_selection"
Const ShrinkSelection:="shrink_selection"
Const WordWrap:="word_wrap"
Const DeleteLine:="delete_line"
Const DeleteWordForward:="delete_word_forward"
Const DeleteWordBackward:="delete_word_backward"
Const DeleteToBegin:="delete_to_begin"
Const DeleteToEnd:="delete_to_end"
Const MakeLowercase:="make_lowercase"
Const MakeUppercase:="make_uppercase"
Const SwapCase:="swap_case"
Const CommentBlock:="comment_block"
Const UncommentBlock:="uncomment_block"
Const NewFile:="new_file"
Const OpenFile:="open_file"
Const CloseTab:="close_tab"
Const NextTab:="next_tab"
Const PrevTab:="prev_tab"
Const CloseOtherTabs:="close_other_tabs"
Const CloseAllTabs:="close_all_tabs"
Const CloseTabsToTheRight:="close_tabs_to_the_right"
Const Save:="save"
Const SaveAs:="save_as"
Const SaveAll:="save_all"
Const Quit:="quit"
Const Preferences:="preferences"
Const Find:="find"
Const FindNext:="find_next"
Const FindPrev:="find_prev"
Const FindInFiles:="find_in_files"
Const Replace:="replace"
Const ReplaceNext:="replace_next"
Const ReplaceAll:="replace_all"
Const FoldCurrent:="fold_current"
Const FoldCurrentAndParent:="fold_current_and_parent"
Const FoldAll:="fold_all"
Const UnfoldCurrent:="unfold_current"
Const UnfoldCurrentAndChildren:="unfold_current_and_children"
Const UnfoldAll:="unfold_all"
Const JumpBack:="jump_back"
Const JumpForward:="jump_forward"
Const JumpToLine:="jump_to_line"
Const JumpToDefinition:="jump_to_definition"
Const JumpToNextScope:="jump_to_next_scope"
Const JumpToPrevScope:="jump_to_prev_scope"
Const FullscreenWindow:="fullscreen_window"
Const FullscreenEditor:="fullscreen_editor"
Const ZoomIn:="zoom_in"
Const ZoomOut:="zoom_out"
Const ZoomDefault:="zoom_default"
Const RecentlyViewedFiles:="recently_viewed_files"
Const DuplicateBlock:="duplicate_block"
Private
Method New()
End
End
Class ActionTitle Final
Function Get:String( actionId:String )
Return _titles[actionId]
End
Private
Global _titles:=Init()
Function Init:StringMap<String>()
Local map:=New StringMap<String>
map.Add( ActionId.Build,"Build" )
map.Add( ActionId.Run,"Run" )
map.Add( ActionId.Semant,"Check" )
map.Add( ActionId.Debug,"Debug" )
map.Add( ActionId.ForceStop,"Force stop" )
map.Add( ActionId.ProductSettings,"Product settings..." )
map.Add( ActionId.NextError,"Next build error" )
map.Add( ActionId.LockBuildFile,"Lock build file" )
map.Add( ActionId.UpdateModules,"Update / Rebuild modules..." )
map.Add( ActionId.ModuleManager,"Module manager..." )
map.Add( ActionId.RebuildDocs,"Rebuild documentation" )
map.Add( ActionId.ExpandSelection,"Expand selection" )
map.Add( ActionId.ShrinkSelection,"Shrink selection" )
map.Add( ActionId.WordWrap,"Toggle word wrap" )
map.Add( ActionId.DeleteLine,"Delete line" )
map.Add( ActionId.DeleteWordForward,"Delete word forward" )
map.Add( ActionId.DeleteWordBackward,"Delete word backward" )
map.Add( ActionId.DeleteToBegin,"Delete to beginning" )
map.Add( ActionId.DeleteToEnd,"Delete to end" )
map.Add( ActionId.MakeLowercase,"lowercase" )
map.Add( ActionId.MakeUppercase,"UPPERCASE" )
map.Add( ActionId.SwapCase,"Swap case" )
map.Add( ActionId.CommentBlock,"Comment block" )
map.Add( ActionId.UncommentBlock,"Uncomment block" )
map.Add( ActionId.NewFile,"New file" )
map.Add( ActionId.OpenFile,"Open file" )
map.Add( ActionId.CloseTab,"Close tab" )
map.Add( ActionId.NextTab,"Next tab" )
map.Add( ActionId.PrevTab,"Previous tab" )
map.Add( ActionId.CloseOtherTabs,"Close other tabs" )
map.Add( ActionId.CloseAllTabs,"Close all tabs" )
map.Add( ActionId.CloseTabsToTheRight,"Close tabs to the right" )
map.Add( ActionId.Save,"Save" )
map.Add( ActionId.SaveAs,"Save as..." )
map.Add( ActionId.SaveAll,"Save all" )
map.Add( ActionId.Quit,"Quit" )
map.Add( ActionId.Preferences,"Preferences..." )
map.Add( ActionId.Find,"Find..." )
map.Add( ActionId.FindNext,"Find next" )
map.Add( ActionId.FindPrev,"Find previous" )
map.Add( ActionId.FindInFiles,"Find in files..." )
map.Add( ActionId.Replace,"Replace..." )
map.Add( ActionId.ReplaceNext,"Replace next" )
map.Add( ActionId.ReplaceAll,"Replace all" )
map.Add( ActionId.FoldCurrent,"Fold current" )
map.Add( ActionId.FoldCurrentAndParent,"Fold current & parents" )
map.Add( ActionId.FoldAll,"Fold all" )
map.Add( ActionId.UnfoldCurrent,"Unfold current" )
map.Add( ActionId.UnfoldCurrentAndChildren,"Unfold current & children" )
map.Add( ActionId.UnfoldAll,"Unfold all" )
map.Add( ActionId.JumpBack,"Jump back" )
map.Add( ActionId.JumpForward,"Jump forward" )
map.Add( ActionId.JumpToLine,"Goto line" )
map.Add( ActionId.JumpToDefinition,"Goto definition" )
map.Add( ActionId.JumpToNextScope,"Next scope" )
map.Add( ActionId.JumpToPrevScope,"Previous scope" )
map.Add( ActionId.FullscreenWindow,"Fullscreen window" )
map.Add( ActionId.FullscreenEditor,"Fullscreen editor" )
map.Add( ActionId.ZoomIn,"Zoom in" )
map.Add( ActionId.ZoomOut,"Zoom out" )
map.Add( ActionId.ZoomDefault,"Reset zoom" )
map.Add( ActionId.RecentlyViewedFiles,"Recently viewed files..." )
map.Add( ActionId.DuplicateBlock,"Duplicate block" )
Return map
End
Method New()
End
End
Function HotKeyFromString:Tuple2<Key,Modifier>( str:String )
str=str.Trim()
Local endsWithPlus:=str.EndsWith( "+" )
If endsWithPlus Then str=str.Slice( 0,-1 )
Local arr:=str.Split( "+" )
' For Local i:=0 Until arr.Length
' arr[i]=arr[i].Trim()
' Next
Local items:=New StringStack( arr )
Local modifiers:=Modifier.None
If items.Contains( "Shift" )
modifiers|=Modifier.Shift
items.Remove( "Shift" )
Endif
If items.Contains( "Ctrl" )
modifiers|=Modifier.Control
items.Remove( "Ctrl" )
Endif
If items.Contains( "Alt" )
modifiers|=Modifier.Alt
items.Remove( "Alt" )
Endif
If items.Contains( "Cmd" )
modifiers|=Modifier.Gui
items.Remove( "Cmd" )
Endif
Local last:=items.Last
If endsWithPlus Then last+="+"
Local key:=Keyboard.KeyFromName( last )
Return New Tuple2<Key,Modifier>( key,modifiers )
End
Function ActionFromString:Action( title:String,hotKeyString:String )
Local action:=New Action( title )
Local pair:=HotKeyFromString( hotKeyString )
action.HotKey=pair.Item1
action.HotKeyModifiers=pair.Item2
Return action
End