@jupyterlab/fileeditor-extension 3.4.1 → 4.0.0-alpha.10
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/lib/commands.d.ts +18 -96
- package/lib/commands.js +281 -253
- package/lib/commands.js.map +1 -1
- package/lib/index.js +141 -7
- package/lib/index.js.map +1 -1
- package/package.json +27 -22
- package/schema/completer.json +14 -0
- package/style/index.css +4 -1
- package/style/index.js +4 -1
package/lib/commands.js
CHANGED
|
@@ -1,9 +1,11 @@
|
|
|
1
1
|
// Copyright (c) Jupyter Development Team.
|
|
2
2
|
// Distributed under the terms of the Modified BSD License.
|
|
3
|
-
import { Clipboard, sessionContextDialogs } from '@jupyterlab/apputils';
|
|
4
|
-
import { CodeEditor } from '@jupyterlab/codeeditor';
|
|
3
|
+
import { Clipboard, MainAreaWidget, sessionContextDialogs } from '@jupyterlab/apputils';
|
|
4
|
+
import { CodeEditor, CodeViewerWidget } from '@jupyterlab/codeeditor';
|
|
5
5
|
import { MarkdownCodeBlocks, PathExt } from '@jupyterlab/coreutils';
|
|
6
|
+
import { nullTranslator } from '@jupyterlab/translation';
|
|
6
7
|
import { consoleIcon, copyIcon, cutIcon, LabIcon, markdownIcon, pasteIcon, redoIcon, textEditorIcon, undoIcon } from '@jupyterlab/ui-components';
|
|
8
|
+
import { toArray } from '@lumino/algorithm';
|
|
7
9
|
const autoClosingBracketsNotebook = 'notebook:toggle-autoclosing-brackets';
|
|
8
10
|
const autoClosingBracketsConsole = 'console:toggle-autoclosing-brackets';
|
|
9
11
|
/**
|
|
@@ -15,13 +17,17 @@ export var CommandIDs;
|
|
|
15
17
|
CommandIDs.createNewMarkdown = 'fileeditor:create-new-markdown-file';
|
|
16
18
|
CommandIDs.changeFontSize = 'fileeditor:change-font-size';
|
|
17
19
|
CommandIDs.lineNumbers = 'fileeditor:toggle-line-numbers';
|
|
20
|
+
CommandIDs.currentLineNumbers = 'fileeditor:toggle-current-line-numbers';
|
|
18
21
|
CommandIDs.lineWrap = 'fileeditor:toggle-line-wrap';
|
|
22
|
+
CommandIDs.currentLineWrap = 'fileeditor:toggle-current-line-wrap';
|
|
19
23
|
CommandIDs.changeTabs = 'fileeditor:change-tabs';
|
|
20
24
|
CommandIDs.matchBrackets = 'fileeditor:toggle-match-brackets';
|
|
25
|
+
CommandIDs.currentMatchBrackets = 'fileeditor:toggle-current-match-brackets';
|
|
21
26
|
CommandIDs.autoClosingBrackets = 'fileeditor:toggle-autoclosing-brackets';
|
|
22
27
|
CommandIDs.autoClosingBracketsUniversal = 'fileeditor:toggle-autoclosing-brackets-universal';
|
|
23
28
|
CommandIDs.createConsole = 'fileeditor:create-console';
|
|
24
29
|
CommandIDs.replaceSelection = 'fileeditor:replace-selection';
|
|
30
|
+
CommandIDs.restartConsole = 'fileeditor:restart-console';
|
|
25
31
|
CommandIDs.runCode = 'fileeditor:run-code';
|
|
26
32
|
CommandIDs.runAllCode = 'fileeditor:run-all';
|
|
27
33
|
CommandIDs.markdownPreview = 'fileeditor:markdown-preview';
|
|
@@ -31,6 +37,9 @@ export var CommandIDs;
|
|
|
31
37
|
CommandIDs.copy = 'fileeditor:copy';
|
|
32
38
|
CommandIDs.paste = 'fileeditor:paste';
|
|
33
39
|
CommandIDs.selectAll = 'fileeditor:select-all';
|
|
40
|
+
CommandIDs.invokeCompleter = 'completer:invoke-file';
|
|
41
|
+
CommandIDs.selectCompleter = 'completer:select-file';
|
|
42
|
+
CommandIDs.openCodeViewer = 'code-viewer:open';
|
|
34
43
|
})(CommandIDs || (CommandIDs = {}));
|
|
35
44
|
/**
|
|
36
45
|
* The name of the factory that creates editor widgets.
|
|
@@ -122,35 +131,10 @@ export var Commands;
|
|
|
122
131
|
/**
|
|
123
132
|
* Wrapper function for adding the default File Editor commands
|
|
124
133
|
*/
|
|
125
|
-
function addCommands(commands, settingRegistry, trans, id, isEnabled, tracker, browserFactory) {
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
addWordWrapCommand(commands, settingRegistry, trans, id, isEnabled);
|
|
130
|
-
addChangeTabsCommand(commands, settingRegistry, trans, id);
|
|
131
|
-
addMatchBracketsCommand(commands, settingRegistry, trans, id, isEnabled);
|
|
132
|
-
addAutoClosingBracketsCommand(commands, settingRegistry, trans, id);
|
|
133
|
-
addReplaceSelectionCommand(commands, tracker, trans, isEnabled);
|
|
134
|
-
addCreateConsoleCommand(commands, tracker, trans, isEnabled);
|
|
135
|
-
addRunCodeCommand(commands, tracker, trans, isEnabled);
|
|
136
|
-
addRunAllCodeCommand(commands, tracker, trans, isEnabled);
|
|
137
|
-
addMarkdownPreviewCommand(commands, tracker, trans);
|
|
138
|
-
// Add a command for creating a new text file.
|
|
139
|
-
addCreateNewCommand(commands, browserFactory, trans);
|
|
140
|
-
// Add a command for creating a new Markdown file.
|
|
141
|
-
addCreateNewMarkdownCommand(commands, browserFactory, trans);
|
|
142
|
-
addUndoCommand(commands, tracker, trans, isEnabled);
|
|
143
|
-
addRedoCommand(commands, tracker, trans, isEnabled);
|
|
144
|
-
addCutCommand(commands, tracker, trans, isEnabled);
|
|
145
|
-
addCopyCommand(commands, tracker, trans, isEnabled);
|
|
146
|
-
addPasteCommand(commands, tracker, trans, isEnabled);
|
|
147
|
-
addSelectAllCommand(commands, tracker, trans, isEnabled);
|
|
148
|
-
}
|
|
149
|
-
Commands.addCommands = addCommands;
|
|
150
|
-
/**
|
|
151
|
-
* Add a command to change font size for File Editor
|
|
152
|
-
*/
|
|
153
|
-
function addChangeFontSizeCommand(commands, settingRegistry, trans, id) {
|
|
134
|
+
function addCommands(commands, settingRegistry, trans, id, isEnabled, tracker, browserFactory, consoleTracker, sessionDialogs) {
|
|
135
|
+
/**
|
|
136
|
+
* Add a command to change font size for File Editor
|
|
137
|
+
*/
|
|
154
138
|
commands.addCommand(CommandIDs.changeFontSize, {
|
|
155
139
|
execute: args => {
|
|
156
140
|
const delta = Number(args['delta']);
|
|
@@ -182,12 +166,9 @@ export var Commands;
|
|
|
182
166
|
}
|
|
183
167
|
}
|
|
184
168
|
});
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
* Add the Line Numbers command
|
|
189
|
-
*/
|
|
190
|
-
function addLineNumbersCommand(commands, settingRegistry, trans, id, isEnabled) {
|
|
169
|
+
/**
|
|
170
|
+
* Add the Line Numbers command
|
|
171
|
+
*/
|
|
191
172
|
commands.addCommand(CommandIDs.lineNumbers, {
|
|
192
173
|
execute: () => {
|
|
193
174
|
config.lineNumbers = !config.lineNumbers;
|
|
@@ -201,12 +182,26 @@ export var Commands;
|
|
|
201
182
|
isToggled: () => config.lineNumbers,
|
|
202
183
|
label: trans.__('Line Numbers')
|
|
203
184
|
});
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
185
|
+
commands.addCommand(CommandIDs.currentLineNumbers, {
|
|
186
|
+
label: trans.__('Show Line Numbers'),
|
|
187
|
+
execute: () => {
|
|
188
|
+
const widget = tracker.currentWidget;
|
|
189
|
+
if (!widget) {
|
|
190
|
+
return;
|
|
191
|
+
}
|
|
192
|
+
const lineNumbers = !widget.content.editor.getOption('lineNumbers');
|
|
193
|
+
widget.content.editor.setOption('lineNumbers', lineNumbers);
|
|
194
|
+
},
|
|
195
|
+
isEnabled,
|
|
196
|
+
isToggled: () => {
|
|
197
|
+
var _a;
|
|
198
|
+
const widget = tracker.currentWidget;
|
|
199
|
+
return (_a = widget === null || widget === void 0 ? void 0 : widget.content.editor.getOption('lineNumbers')) !== null && _a !== void 0 ? _a : false;
|
|
200
|
+
}
|
|
201
|
+
});
|
|
202
|
+
/**
|
|
203
|
+
* Add the Word Wrap command
|
|
204
|
+
*/
|
|
210
205
|
commands.addCommand(CommandIDs.lineWrap, {
|
|
211
206
|
execute: args => {
|
|
212
207
|
config.lineWrap = args['mode'] || 'off';
|
|
@@ -223,12 +218,27 @@ export var Commands;
|
|
|
223
218
|
},
|
|
224
219
|
label: trans.__('Word Wrap')
|
|
225
220
|
});
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
221
|
+
commands.addCommand(CommandIDs.currentLineWrap, {
|
|
222
|
+
label: trans.__('Wrap Words'),
|
|
223
|
+
execute: () => {
|
|
224
|
+
const widget = tracker.currentWidget;
|
|
225
|
+
if (!widget) {
|
|
226
|
+
return;
|
|
227
|
+
}
|
|
228
|
+
const oldValue = widget.content.editor.getOption('lineWrap');
|
|
229
|
+
const newValue = oldValue === 'off' ? 'on' : 'off';
|
|
230
|
+
widget.content.editor.setOption('lineWrap', newValue);
|
|
231
|
+
},
|
|
232
|
+
isEnabled,
|
|
233
|
+
isToggled: () => {
|
|
234
|
+
var _a;
|
|
235
|
+
const widget = tracker.currentWidget;
|
|
236
|
+
return (_a = (widget === null || widget === void 0 ? void 0 : widget.content.editor.getOption('lineWrap')) !== 'off') !== null && _a !== void 0 ? _a : false;
|
|
237
|
+
}
|
|
238
|
+
});
|
|
239
|
+
/**
|
|
240
|
+
* Add command for changing tabs size or type in File Editor
|
|
241
|
+
*/
|
|
232
242
|
commands.addCommand(CommandIDs.changeTabs, {
|
|
233
243
|
label: args => {
|
|
234
244
|
var _a;
|
|
@@ -254,12 +264,9 @@ export var Commands;
|
|
|
254
264
|
return config.insertSpaces === insertSpaces && config.tabSize === size;
|
|
255
265
|
}
|
|
256
266
|
});
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
* Add the Match Brackets command
|
|
261
|
-
*/
|
|
262
|
-
function addMatchBracketsCommand(commands, settingRegistry, trans, id, isEnabled) {
|
|
267
|
+
/**
|
|
268
|
+
* Add the Match Brackets command
|
|
269
|
+
*/
|
|
263
270
|
commands.addCommand(CommandIDs.matchBrackets, {
|
|
264
271
|
execute: () => {
|
|
265
272
|
config.matchBrackets = !config.matchBrackets;
|
|
@@ -273,12 +280,26 @@ export var Commands;
|
|
|
273
280
|
isEnabled,
|
|
274
281
|
isToggled: () => config.matchBrackets
|
|
275
282
|
});
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
283
|
+
commands.addCommand(CommandIDs.currentMatchBrackets, {
|
|
284
|
+
label: trans.__('Match Brackets'),
|
|
285
|
+
execute: () => {
|
|
286
|
+
const widget = tracker.currentWidget;
|
|
287
|
+
if (!widget) {
|
|
288
|
+
return;
|
|
289
|
+
}
|
|
290
|
+
const matchBrackets = !widget.content.editor.getOption('matchBrackets');
|
|
291
|
+
widget.content.editor.setOption('matchBrackets', matchBrackets);
|
|
292
|
+
},
|
|
293
|
+
isEnabled,
|
|
294
|
+
isToggled: () => {
|
|
295
|
+
var _a;
|
|
296
|
+
const widget = tracker.currentWidget;
|
|
297
|
+
return (_a = widget === null || widget === void 0 ? void 0 : widget.content.editor.getOption('matchBrackets')) !== null && _a !== void 0 ? _a : false;
|
|
298
|
+
}
|
|
299
|
+
});
|
|
300
|
+
/**
|
|
301
|
+
* Add the Auto Close Brackets for Text Editor command
|
|
302
|
+
*/
|
|
282
303
|
commands.addCommand(CommandIDs.autoClosingBrackets, {
|
|
283
304
|
execute: args => {
|
|
284
305
|
var _a;
|
|
@@ -319,12 +340,9 @@ export var Commands;
|
|
|
319
340
|
commands.isToggled(autoClosingBracketsNotebook) ||
|
|
320
341
|
commands.isToggled(autoClosingBracketsConsole)
|
|
321
342
|
});
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
* Add the replace selection for text editor command
|
|
326
|
-
*/
|
|
327
|
-
function addReplaceSelectionCommand(commands, tracker, trans, isEnabled) {
|
|
343
|
+
/**
|
|
344
|
+
* Add the replace selection for text editor command
|
|
345
|
+
*/
|
|
328
346
|
commands.addCommand(CommandIDs.replaceSelection, {
|
|
329
347
|
execute: args => {
|
|
330
348
|
var _a, _b;
|
|
@@ -338,12 +356,9 @@ export var Commands;
|
|
|
338
356
|
isEnabled,
|
|
339
357
|
label: trans.__('Replace Selection in Editor')
|
|
340
358
|
});
|
|
341
|
-
|
|
342
|
-
|
|
343
|
-
|
|
344
|
-
* Add the Create Console for Editor command
|
|
345
|
-
*/
|
|
346
|
-
function addCreateConsoleCommand(commands, tracker, trans, isEnabled) {
|
|
359
|
+
/**
|
|
360
|
+
* Add the Create Console for Editor command
|
|
361
|
+
*/
|
|
347
362
|
commands.addCommand(CommandIDs.createConsole, {
|
|
348
363
|
execute: args => {
|
|
349
364
|
const widget = tracker.currentWidget;
|
|
@@ -356,12 +371,27 @@ export var Commands;
|
|
|
356
371
|
icon: consoleIcon,
|
|
357
372
|
label: trans.__('Create Console for Editor')
|
|
358
373
|
});
|
|
359
|
-
|
|
360
|
-
|
|
361
|
-
|
|
362
|
-
|
|
363
|
-
|
|
364
|
-
|
|
374
|
+
/**
|
|
375
|
+
* Restart the Console Kernel linked to the current Editor
|
|
376
|
+
*/
|
|
377
|
+
commands.addCommand(CommandIDs.restartConsole, {
|
|
378
|
+
execute: async () => {
|
|
379
|
+
var _a;
|
|
380
|
+
const current = (_a = tracker.currentWidget) === null || _a === void 0 ? void 0 : _a.content;
|
|
381
|
+
if (!current || consoleTracker === null) {
|
|
382
|
+
return;
|
|
383
|
+
}
|
|
384
|
+
const widget = consoleTracker.find(widget => { var _a; return ((_a = widget.sessionContext.session) === null || _a === void 0 ? void 0 : _a.path) === current.context.path; });
|
|
385
|
+
if (widget) {
|
|
386
|
+
return (sessionDialogs || sessionContextDialogs).restart(widget.sessionContext);
|
|
387
|
+
}
|
|
388
|
+
},
|
|
389
|
+
label: trans.__('Restart Kernel'),
|
|
390
|
+
isEnabled: () => consoleTracker !== null && isEnabled()
|
|
391
|
+
});
|
|
392
|
+
/**
|
|
393
|
+
* Add the Run Code command
|
|
394
|
+
*/
|
|
365
395
|
commands.addCommand(CommandIDs.runCode, {
|
|
366
396
|
execute: () => {
|
|
367
397
|
var _a;
|
|
@@ -416,14 +446,11 @@ export var Commands;
|
|
|
416
446
|
}
|
|
417
447
|
},
|
|
418
448
|
isEnabled,
|
|
419
|
-
label: trans.__('Run Code')
|
|
449
|
+
label: trans.__('Run Selected Code')
|
|
420
450
|
});
|
|
421
|
-
|
|
422
|
-
|
|
423
|
-
|
|
424
|
-
* Add the Run All Code command
|
|
425
|
-
*/
|
|
426
|
-
function addRunAllCodeCommand(commands, tracker, trans, isEnabled) {
|
|
451
|
+
/**
|
|
452
|
+
* Add the Run All Code command
|
|
453
|
+
*/
|
|
427
454
|
commands.addCommand(CommandIDs.runAllCode, {
|
|
428
455
|
execute: () => {
|
|
429
456
|
var _a;
|
|
@@ -457,12 +484,9 @@ export var Commands;
|
|
|
457
484
|
isEnabled,
|
|
458
485
|
label: trans.__('Run All Code')
|
|
459
486
|
});
|
|
460
|
-
|
|
461
|
-
|
|
462
|
-
|
|
463
|
-
* Add markdown preview command
|
|
464
|
-
*/
|
|
465
|
-
function addMarkdownPreviewCommand(commands, tracker, trans) {
|
|
487
|
+
/**
|
|
488
|
+
* Add markdown preview command
|
|
489
|
+
*/
|
|
466
490
|
commands.addCommand(CommandIDs.markdownPreview, {
|
|
467
491
|
execute: () => {
|
|
468
492
|
const widget = tracker.currentWidget;
|
|
@@ -484,12 +508,51 @@ export var Commands;
|
|
|
484
508
|
icon: markdownIcon,
|
|
485
509
|
label: trans.__('Show Markdown Preview')
|
|
486
510
|
});
|
|
487
|
-
|
|
488
|
-
|
|
489
|
-
|
|
490
|
-
|
|
491
|
-
|
|
492
|
-
|
|
511
|
+
/**
|
|
512
|
+
* Add the New File command
|
|
513
|
+
*
|
|
514
|
+
* Defaults to Text/.txt if file type data is not specified
|
|
515
|
+
*/
|
|
516
|
+
commands.addCommand(CommandIDs.createNew, {
|
|
517
|
+
label: args => {
|
|
518
|
+
var _a, _b;
|
|
519
|
+
if (args.isPalette) {
|
|
520
|
+
return (_a = args.paletteLabel) !== null && _a !== void 0 ? _a : trans.__('New Text File');
|
|
521
|
+
}
|
|
522
|
+
return (_b = args.launcherLabel) !== null && _b !== void 0 ? _b : trans.__('Text File');
|
|
523
|
+
},
|
|
524
|
+
caption: args => { var _a; return (_a = args.caption) !== null && _a !== void 0 ? _a : trans.__('Create a new text file'); },
|
|
525
|
+
icon: args => {
|
|
526
|
+
var _a;
|
|
527
|
+
return args.isPalette
|
|
528
|
+
? undefined
|
|
529
|
+
: LabIcon.resolve({
|
|
530
|
+
icon: (_a = args.iconName) !== null && _a !== void 0 ? _a : textEditorIcon
|
|
531
|
+
});
|
|
532
|
+
},
|
|
533
|
+
execute: args => {
|
|
534
|
+
var _a;
|
|
535
|
+
const cwd = args.cwd || browserFactory.defaultBrowser.model.path;
|
|
536
|
+
return createNew(commands, cwd, (_a = args.fileExt) !== null && _a !== void 0 ? _a : 'txt');
|
|
537
|
+
}
|
|
538
|
+
});
|
|
539
|
+
/**
|
|
540
|
+
* Add the New Markdown File command
|
|
541
|
+
*/
|
|
542
|
+
commands.addCommand(CommandIDs.createNewMarkdown, {
|
|
543
|
+
label: args => args['isPalette']
|
|
544
|
+
? trans.__('New Markdown File')
|
|
545
|
+
: trans.__('Markdown File'),
|
|
546
|
+
caption: trans.__('Create a new markdown file'),
|
|
547
|
+
icon: args => (args['isPalette'] ? undefined : markdownIcon),
|
|
548
|
+
execute: args => {
|
|
549
|
+
const cwd = args['cwd'] || browserFactory.defaultBrowser.model.path;
|
|
550
|
+
return createNew(commands, cwd, 'md');
|
|
551
|
+
}
|
|
552
|
+
});
|
|
553
|
+
/**
|
|
554
|
+
* Add undo command
|
|
555
|
+
*/
|
|
493
556
|
commands.addCommand(CommandIDs.undo, {
|
|
494
557
|
execute: () => {
|
|
495
558
|
var _a;
|
|
@@ -515,12 +578,9 @@ export var Commands;
|
|
|
515
578
|
icon: undoIcon.bindprops({ stylesheet: 'menuItem' }),
|
|
516
579
|
label: trans.__('Undo')
|
|
517
580
|
});
|
|
518
|
-
|
|
519
|
-
|
|
520
|
-
|
|
521
|
-
* Add redo command
|
|
522
|
-
*/
|
|
523
|
-
function addRedoCommand(commands, tracker, trans, isEnabled) {
|
|
581
|
+
/**
|
|
582
|
+
* Add redo command
|
|
583
|
+
*/
|
|
524
584
|
commands.addCommand(CommandIDs.redo, {
|
|
525
585
|
execute: () => {
|
|
526
586
|
var _a;
|
|
@@ -546,12 +606,9 @@ export var Commands;
|
|
|
546
606
|
icon: redoIcon.bindprops({ stylesheet: 'menuItem' }),
|
|
547
607
|
label: trans.__('Redo')
|
|
548
608
|
});
|
|
549
|
-
|
|
550
|
-
|
|
551
|
-
|
|
552
|
-
* Add cut command
|
|
553
|
-
*/
|
|
554
|
-
function addCutCommand(commands, tracker, trans, isEnabled) {
|
|
609
|
+
/**
|
|
610
|
+
* Add cut command
|
|
611
|
+
*/
|
|
555
612
|
commands.addCommand(CommandIDs.cut, {
|
|
556
613
|
execute: () => {
|
|
557
614
|
var _a;
|
|
@@ -579,12 +636,9 @@ export var Commands;
|
|
|
579
636
|
icon: cutIcon.bindprops({ stylesheet: 'menuItem' }),
|
|
580
637
|
label: trans.__('Cut')
|
|
581
638
|
});
|
|
582
|
-
|
|
583
|
-
|
|
584
|
-
|
|
585
|
-
* Add copy command
|
|
586
|
-
*/
|
|
587
|
-
function addCopyCommand(commands, tracker, trans, isEnabled) {
|
|
639
|
+
/**
|
|
640
|
+
* Add copy command
|
|
641
|
+
*/
|
|
588
642
|
commands.addCommand(CommandIDs.copy, {
|
|
589
643
|
execute: () => {
|
|
590
644
|
var _a;
|
|
@@ -611,12 +665,9 @@ export var Commands;
|
|
|
611
665
|
icon: copyIcon.bindprops({ stylesheet: 'menuItem' }),
|
|
612
666
|
label: trans.__('Copy')
|
|
613
667
|
});
|
|
614
|
-
|
|
615
|
-
|
|
616
|
-
|
|
617
|
-
* Add paste command
|
|
618
|
-
*/
|
|
619
|
-
function addPasteCommand(commands, tracker, trans, isEnabled) {
|
|
668
|
+
/**
|
|
669
|
+
* Add paste command
|
|
670
|
+
*/
|
|
620
671
|
commands.addCommand(CommandIDs.paste, {
|
|
621
672
|
execute: async () => {
|
|
622
673
|
var _a;
|
|
@@ -637,12 +688,9 @@ export var Commands;
|
|
|
637
688
|
icon: pasteIcon.bindprops({ stylesheet: 'menuItem' }),
|
|
638
689
|
label: trans.__('Paste')
|
|
639
690
|
});
|
|
640
|
-
|
|
641
|
-
|
|
642
|
-
|
|
643
|
-
* Add select all command
|
|
644
|
-
*/
|
|
645
|
-
function addSelectAllCommand(commands, tracker, trans, isEnabled) {
|
|
691
|
+
/**
|
|
692
|
+
* Add select all command
|
|
693
|
+
*/
|
|
646
694
|
commands.addCommand(CommandIDs.selectAll, {
|
|
647
695
|
execute: () => {
|
|
648
696
|
var _a;
|
|
@@ -657,7 +705,34 @@ export var Commands;
|
|
|
657
705
|
label: trans.__('Select All')
|
|
658
706
|
});
|
|
659
707
|
}
|
|
660
|
-
Commands.
|
|
708
|
+
Commands.addCommands = addCommands;
|
|
709
|
+
function addCompleterCommands(commands, editorTracker, manager, translator) {
|
|
710
|
+
const trans = (translator !== null && translator !== void 0 ? translator : nullTranslator).load('jupyterlab');
|
|
711
|
+
commands.addCommand(CommandIDs.invokeCompleter, {
|
|
712
|
+
label: trans.__('Display the completion helper.'),
|
|
713
|
+
execute: () => {
|
|
714
|
+
const id = editorTracker.currentWidget && editorTracker.currentWidget.id;
|
|
715
|
+
if (id) {
|
|
716
|
+
return manager.invoke(id);
|
|
717
|
+
}
|
|
718
|
+
}
|
|
719
|
+
});
|
|
720
|
+
commands.addCommand(CommandIDs.selectCompleter, {
|
|
721
|
+
label: trans.__('Select the completion suggestion.'),
|
|
722
|
+
execute: () => {
|
|
723
|
+
const id = editorTracker.currentWidget && editorTracker.currentWidget.id;
|
|
724
|
+
if (id) {
|
|
725
|
+
return manager.select(id);
|
|
726
|
+
}
|
|
727
|
+
}
|
|
728
|
+
});
|
|
729
|
+
commands.addKeyBinding({
|
|
730
|
+
command: CommandIDs.selectCompleter,
|
|
731
|
+
keys: ['Enter'],
|
|
732
|
+
selector: '.jp-FileEditor .jp-mod-completer-active'
|
|
733
|
+
});
|
|
734
|
+
}
|
|
735
|
+
Commands.addCompleterCommands = addCompleterCommands;
|
|
661
736
|
/**
|
|
662
737
|
* Helper function to check if there is a text selection in the editor
|
|
663
738
|
*/
|
|
@@ -696,54 +771,6 @@ export var Commands;
|
|
|
696
771
|
}
|
|
697
772
|
});
|
|
698
773
|
}
|
|
699
|
-
/**
|
|
700
|
-
* Add the New File command
|
|
701
|
-
*
|
|
702
|
-
* Defaults to Text/.txt if file type data is not specified
|
|
703
|
-
*/
|
|
704
|
-
function addCreateNewCommand(commands, browserFactory, trans) {
|
|
705
|
-
commands.addCommand(CommandIDs.createNew, {
|
|
706
|
-
label: args => {
|
|
707
|
-
var _a, _b;
|
|
708
|
-
if (args.isPalette) {
|
|
709
|
-
return (_a = args.paletteLabel) !== null && _a !== void 0 ? _a : trans.__('New Text File');
|
|
710
|
-
}
|
|
711
|
-
return (_b = args.launcherLabel) !== null && _b !== void 0 ? _b : trans.__('Text File');
|
|
712
|
-
},
|
|
713
|
-
caption: args => { var _a; return (_a = args.caption) !== null && _a !== void 0 ? _a : trans.__('Create a new text file'); },
|
|
714
|
-
icon: args => {
|
|
715
|
-
var _a;
|
|
716
|
-
return args.isPalette
|
|
717
|
-
? undefined
|
|
718
|
-
: LabIcon.resolve({
|
|
719
|
-
icon: (_a = args.iconName) !== null && _a !== void 0 ? _a : textEditorIcon
|
|
720
|
-
});
|
|
721
|
-
},
|
|
722
|
-
execute: args => {
|
|
723
|
-
var _a;
|
|
724
|
-
const cwd = args.cwd || browserFactory.defaultBrowser.model.path;
|
|
725
|
-
return createNew(commands, cwd, (_a = args.fileExt) !== null && _a !== void 0 ? _a : 'txt');
|
|
726
|
-
}
|
|
727
|
-
});
|
|
728
|
-
}
|
|
729
|
-
Commands.addCreateNewCommand = addCreateNewCommand;
|
|
730
|
-
/**
|
|
731
|
-
* Add the New Markdown File command
|
|
732
|
-
*/
|
|
733
|
-
function addCreateNewMarkdownCommand(commands, browserFactory, trans) {
|
|
734
|
-
commands.addCommand(CommandIDs.createNewMarkdown, {
|
|
735
|
-
label: args => args['isPalette']
|
|
736
|
-
? trans.__('New Markdown File')
|
|
737
|
-
: trans.__('Markdown File'),
|
|
738
|
-
caption: trans.__('Create a new markdown file'),
|
|
739
|
-
icon: args => (args['isPalette'] ? undefined : markdownIcon),
|
|
740
|
-
execute: args => {
|
|
741
|
-
const cwd = args['cwd'] || browserFactory.defaultBrowser.model.path;
|
|
742
|
-
return createNew(commands, cwd, 'md');
|
|
743
|
-
}
|
|
744
|
-
});
|
|
745
|
-
}
|
|
746
|
-
Commands.addCreateNewMarkdownCommand = addCreateNewMarkdownCommand;
|
|
747
774
|
/**
|
|
748
775
|
* Wrapper function for adding the default launcher items for File Editor
|
|
749
776
|
*/
|
|
@@ -871,16 +898,37 @@ export var Commands;
|
|
|
871
898
|
/**
|
|
872
899
|
* Wrapper function for adding the default menu items for File Editor
|
|
873
900
|
*/
|
|
874
|
-
function addMenuItems(menu,
|
|
901
|
+
function addMenuItems(menu, tracker, consoleTracker, isEnabled) {
|
|
875
902
|
// Add undo/redo hooks to the edit menu.
|
|
876
|
-
|
|
903
|
+
menu.editMenu.undoers.redo.add({
|
|
904
|
+
id: CommandIDs.redo,
|
|
905
|
+
isEnabled
|
|
906
|
+
});
|
|
907
|
+
menu.editMenu.undoers.undo.add({
|
|
908
|
+
id: CommandIDs.undo,
|
|
909
|
+
isEnabled
|
|
910
|
+
});
|
|
877
911
|
// Add editor view options.
|
|
878
|
-
|
|
912
|
+
menu.viewMenu.editorViewers.toggleLineNumbers.add({
|
|
913
|
+
id: CommandIDs.currentLineNumbers,
|
|
914
|
+
isEnabled
|
|
915
|
+
});
|
|
916
|
+
menu.viewMenu.editorViewers.toggleMatchBrackets.add({
|
|
917
|
+
id: CommandIDs.currentMatchBrackets,
|
|
918
|
+
isEnabled
|
|
919
|
+
});
|
|
920
|
+
menu.viewMenu.editorViewers.toggleWordWrap.add({
|
|
921
|
+
id: CommandIDs.currentLineWrap,
|
|
922
|
+
isEnabled
|
|
923
|
+
});
|
|
879
924
|
// Add a console creator the the file menu.
|
|
880
|
-
|
|
925
|
+
menu.fileMenu.consoleCreators.add({
|
|
926
|
+
id: CommandIDs.createConsole,
|
|
927
|
+
isEnabled
|
|
928
|
+
});
|
|
881
929
|
// Add a code runner to the run menu.
|
|
882
930
|
if (consoleTracker) {
|
|
883
|
-
addCodeRunnersToRunMenu(menu,
|
|
931
|
+
addCodeRunnersToRunMenu(menu, consoleTracker);
|
|
884
932
|
}
|
|
885
933
|
}
|
|
886
934
|
Commands.addMenuItems = addMenuItems;
|
|
@@ -898,84 +946,64 @@ export var Commands;
|
|
|
898
946
|
}
|
|
899
947
|
Commands.addKernelLanguageMenuItems = addKernelLanguageMenuItems;
|
|
900
948
|
/**
|
|
901
|
-
* Add File Editor
|
|
949
|
+
* Add a File Editor code runner to the Run menu
|
|
902
950
|
*/
|
|
903
|
-
function
|
|
904
|
-
|
|
905
|
-
|
|
906
|
-
|
|
907
|
-
|
|
908
|
-
|
|
909
|
-
redo: widget => {
|
|
910
|
-
widget.content.editor.redo();
|
|
911
|
-
}
|
|
951
|
+
function addCodeRunnersToRunMenu(menu, consoleTracker) {
|
|
952
|
+
const isEnabled = (current) => current.context &&
|
|
953
|
+
!!consoleTracker.find(widget => { var _a; return ((_a = widget.sessionContext.session) === null || _a === void 0 ? void 0 : _a.path) === current.context.path; });
|
|
954
|
+
menu.runMenu.codeRunners.restart.add({
|
|
955
|
+
id: CommandIDs.restartConsole,
|
|
956
|
+
isEnabled
|
|
912
957
|
});
|
|
913
|
-
|
|
914
|
-
|
|
915
|
-
|
|
916
|
-
* Add a File Editor editor viewer to the View Menu
|
|
917
|
-
*/
|
|
918
|
-
function addEditorViewerToViewMenu(menu, tracker) {
|
|
919
|
-
menu.viewMenu.editorViewers.add({
|
|
920
|
-
tracker,
|
|
921
|
-
toggleLineNumbers: widget => {
|
|
922
|
-
const lineNumbers = !widget.content.editor.getOption('lineNumbers');
|
|
923
|
-
widget.content.editor.setOption('lineNumbers', lineNumbers);
|
|
924
|
-
},
|
|
925
|
-
toggleWordWrap: widget => {
|
|
926
|
-
const oldValue = widget.content.editor.getOption('lineWrap');
|
|
927
|
-
const newValue = oldValue === 'off' ? 'on' : 'off';
|
|
928
|
-
widget.content.editor.setOption('lineWrap', newValue);
|
|
929
|
-
},
|
|
930
|
-
toggleMatchBrackets: widget => {
|
|
931
|
-
const matchBrackets = !widget.content.editor.getOption('matchBrackets');
|
|
932
|
-
widget.content.editor.setOption('matchBrackets', matchBrackets);
|
|
933
|
-
},
|
|
934
|
-
lineNumbersToggled: widget => widget.content.editor.getOption('lineNumbers'),
|
|
935
|
-
wordWrapToggled: widget => widget.content.editor.getOption('lineWrap') !== 'off',
|
|
936
|
-
matchBracketsToggled: widget => widget.content.editor.getOption('matchBrackets')
|
|
958
|
+
menu.runMenu.codeRunners.run.add({
|
|
959
|
+
id: CommandIDs.runCode,
|
|
960
|
+
isEnabled
|
|
937
961
|
});
|
|
938
|
-
|
|
939
|
-
|
|
940
|
-
|
|
941
|
-
* Add a File Editor console creator to the File menu
|
|
942
|
-
*/
|
|
943
|
-
function addConsoleCreatorToFileMenu(menu, commands, tracker, trans) {
|
|
944
|
-
const createConsole = getCreateConsoleFunction(commands);
|
|
945
|
-
menu.fileMenu.consoleCreators.add({
|
|
946
|
-
tracker,
|
|
947
|
-
createConsoleLabel: (n) => trans.__('Create Console for Editor'),
|
|
948
|
-
createConsole
|
|
962
|
+
menu.runMenu.codeRunners.runAll.add({
|
|
963
|
+
id: CommandIDs.runAllCode,
|
|
964
|
+
isEnabled
|
|
949
965
|
});
|
|
950
966
|
}
|
|
951
|
-
Commands.
|
|
952
|
-
|
|
953
|
-
|
|
954
|
-
|
|
955
|
-
|
|
956
|
-
|
|
957
|
-
|
|
958
|
-
|
|
959
|
-
|
|
960
|
-
|
|
961
|
-
|
|
962
|
-
|
|
963
|
-
|
|
964
|
-
|
|
965
|
-
|
|
966
|
-
|
|
967
|
-
|
|
968
|
-
|
|
969
|
-
|
|
970
|
-
|
|
971
|
-
|
|
972
|
-
|
|
973
|
-
|
|
974
|
-
|
|
975
|
-
|
|
967
|
+
Commands.addCodeRunnersToRunMenu = addCodeRunnersToRunMenu;
|
|
968
|
+
function addOpenCodeViewerCommand(app, editorServices, tracker, trans) {
|
|
969
|
+
const openCodeViewer = async (args) => {
|
|
970
|
+
var _a;
|
|
971
|
+
const func = editorServices.factoryService.newDocumentEditor;
|
|
972
|
+
const factory = options => {
|
|
973
|
+
return func(options);
|
|
974
|
+
};
|
|
975
|
+
// Derive mimetype from extension
|
|
976
|
+
let mimetype = args.mimeType;
|
|
977
|
+
if (!mimetype && args.extension) {
|
|
978
|
+
mimetype = editorServices.mimeTypeService.getMimeTypeByFilePath(`temp.${args.extension.replace(/\\.$/, '')}`);
|
|
979
|
+
}
|
|
980
|
+
const widget = CodeViewerWidget.createCodeViewer({
|
|
981
|
+
factory,
|
|
982
|
+
content: args.content,
|
|
983
|
+
mimeType: mimetype
|
|
984
|
+
});
|
|
985
|
+
widget.title.label = args.label || trans.__('Code Viewer');
|
|
986
|
+
widget.title.caption = widget.title.label;
|
|
987
|
+
// Get the fileType based on the mimetype to determine the icon
|
|
988
|
+
const fileType = toArray(app.docRegistry.fileTypes()).find(fileType => {
|
|
989
|
+
return mimetype ? fileType.mimeTypes.includes(mimetype) : undefined;
|
|
990
|
+
});
|
|
991
|
+
widget.title.icon = (_a = fileType === null || fileType === void 0 ? void 0 : fileType.icon) !== null && _a !== void 0 ? _a : textEditorIcon;
|
|
992
|
+
if (args.widgetId) {
|
|
993
|
+
widget.id = args.widgetId;
|
|
994
|
+
}
|
|
995
|
+
const main = new MainAreaWidget({ content: widget });
|
|
996
|
+
await tracker.add(main);
|
|
997
|
+
app.shell.add(main, 'main');
|
|
998
|
+
return widget;
|
|
999
|
+
};
|
|
1000
|
+
app.commands.addCommand(CommandIDs.openCodeViewer, {
|
|
1001
|
+
label: trans.__('Open Code Viewer'),
|
|
1002
|
+
execute: (args) => {
|
|
1003
|
+
return openCodeViewer(args);
|
|
976
1004
|
}
|
|
977
1005
|
});
|
|
978
1006
|
}
|
|
979
|
-
Commands.
|
|
1007
|
+
Commands.addOpenCodeViewerCommand = addOpenCodeViewerCommand;
|
|
980
1008
|
})(Commands || (Commands = {}));
|
|
981
1009
|
//# sourceMappingURL=commands.js.map
|