@@ -24,25 +24,28 @@ namespace CommandIDs {
24
24
const extension : JupyterFrontEndPlugin < void > = {
25
25
id : 'jupyterlab-python-file' ,
26
26
autoStart : true ,
27
- requires : [ IFileBrowserFactory ] ,
28
- optional : [ ILauncher , IMainMenu , ICommandPalette ] ,
27
+ optional : [ IFileBrowserFactory , ILauncher , IMainMenu , ICommandPalette ] ,
29
28
activate : (
30
29
app : JupyterFrontEnd ,
31
- browserFactory : IFileBrowserFactory ,
32
- launcher : ILauncher ,
30
+ browserFactory : IFileBrowserFactory | null ,
31
+ launcher : ILauncher | null ,
33
32
menu : IMainMenu | null ,
34
33
palette : ICommandPalette
35
34
) => {
36
- const { commands } = app ;
35
+ const { commands, contextMenu } = app ;
37
36
38
37
const command = CommandIDs . createNew ;
39
38
40
39
commands . addCommand ( command , {
41
- label : args => ( args [ 'isPalette' ] ? 'New Python File' : 'Python File' ) ,
40
+ label : args =>
41
+ args [ 'isPalette' ] || args [ 'isContextMenu' ]
42
+ ? 'New Python File'
43
+ : 'Python File' ,
42
44
caption : 'Create a new Python file' ,
43
45
iconClass : args => ( args [ 'isPalette' ] ? '' : ICON_CLASS ) ,
44
46
execute : async args => {
45
- const cwd = args [ 'cwd' ] || browserFactory . defaultBrowser . model . path ;
47
+ const cwd =
48
+ args [ 'cwd' ] ?? browserFactory ?. defaultBrowser . model . path ?? undefined ;
46
49
const model = await commands . execute ( 'docmanager:new-untitled' , {
47
50
path : cwd ,
48
51
type : 'file' ,
@@ -55,6 +58,15 @@ const extension: JupyterFrontEndPlugin<void> = {
55
58
}
56
59
} ) ;
57
60
61
+ // add to the file browser context menu
62
+ const selectorContent = '.jp-DirListing-content' ;
63
+ contextMenu . addItem ( {
64
+ command,
65
+ args : { isContextMenu : true } ,
66
+ selector : selectorContent ,
67
+ rank : 3
68
+ } ) ;
69
+
58
70
// add to the launcher
59
71
if ( launcher ) {
60
72
launcher . add ( {
0 commit comments