1
- import {
2
- JupyterLab , JupyterLabPlugin
3
- } from '@jupyterlab/application' ;
4
- import { ICommandPalette } from '@jupyterlab/apputils' ;
5
- import { ISettingRegistry , URLExt , PathExt } from '@jupyterlab/coreutils' ;
6
- import { IDocumentManager } from '@jupyterlab/docmanager' ;
7
- import { ServerConnection } from '@jupyterlab/services' ;
8
- import { CommandRegistry } from '@phosphor/commands' ;
9
- import { JSONObject } from '@phosphor/coreutils' ;
10
- import { Message } from '@phosphor/messaging' ;
11
- import { ISignal , Signal } from '@phosphor/signaling' ;
12
- import { CommandPalette } from '@phosphor/widgets' ;
1
+ import { ILabShell , JupyterFrontEnd , JupyterFrontEndPlugin } from "@jupyterlab/application" ;
2
+ import { ICommandPalette } from "@jupyterlab/apputils" ;
3
+ import { ISettingRegistry , URLExt , PathExt } from "@jupyterlab/coreutils" ;
4
+ import { IDocumentManager } from "@jupyterlab/docmanager" ;
5
+ import { ServerConnection } from "@jupyterlab/services" ;
6
+ import { CommandRegistry } from "@phosphor/commands" ;
7
+ import { ReadonlyJSONObject } from "@phosphor/coreutils" ;
8
+ import { Message } from "@phosphor/messaging" ;
9
+ import { ISignal , Signal } from "@phosphor/signaling" ;
10
+ import { CommandPalette } from "@phosphor/widgets" ;
13
11
import "../style/index.css" ;
14
12
15
13
/** Structure of the JSON response from the server */
16
14
interface QuickOpenResponse {
17
- readonly contents : { [ key : string ] : string [ ] } ,
18
- readonly scanSeconds : number ,
15
+ readonly contents : { [ key : string ] : string [ ] } ;
16
+ readonly scanSeconds : number ;
19
17
}
20
18
21
-
22
19
/** Makes a HTTP request for the server-side quick open scan */
23
20
async function fetchContents ( excludes : string [ ] ) : Promise < QuickOpenResponse > {
24
- const query = excludes . map ( exclude => {
25
- return 'excludes=' + encodeURIComponent ( exclude ) ;
26
- } ) . join ( '&' ) ;
21
+ const query = excludes
22
+ . map ( exclude => {
23
+ return "excludes=" + encodeURIComponent ( exclude ) ;
24
+ } )
25
+ . join ( "&" ) ;
27
26
28
27
const settings = ServerConnection . makeSettings ( ) ;
29
- const fullUrl = URLExt . join ( settings . baseUrl , ' /api/quickopen' ) + '?' + query ;
30
- const response = await ServerConnection . makeRequest ( fullUrl , { method : ' GET' } , settings ) ;
28
+ const fullUrl = URLExt . join ( settings . baseUrl , " /api/quickopen" ) + "?" + query ;
29
+ const response = await ServerConnection . makeRequest ( fullUrl , { method : " GET" } , settings ) ;
31
30
if ( response . status !== 200 ) {
32
31
throw new ServerConnection . ResponseError ( response ) ;
33
32
}
34
33
return await response . json ( ) ;
35
34
}
36
35
37
-
38
36
/**
39
37
* Shows files nested under directories in the root notebooks directory
40
38
* configured on the server.
41
39
*/
42
40
class QuickOpenWidget extends CommandPalette {
43
41
private _pathSelected = new Signal < this, string > ( this ) ;
44
- private _settings : JSONObject ;
42
+ private _settings : ReadonlyJSONObject ;
45
43
46
44
constructor ( options : CommandPalette . IOptions ) {
47
45
super ( options ) ;
48
46
49
- this . id = ' jupyterlab-quickopen' ;
50
- this . title . iconClass = ' jp-SideBar-tabIcon jp-FaIcon fa fa-search' ;
51
- this . title . caption = ' Quick Open' ;
47
+ this . id = " jupyterlab-quickopen" ;
48
+ this . title . iconClass = " jp-SideBar-tabIcon jp-SearchIcon" ;
49
+ this . title . caption = " Quick Open" ;
52
50
}
53
51
54
52
/** Signal when a selected path is activated. */
@@ -57,7 +55,7 @@ class QuickOpenWidget extends CommandPalette {
57
55
}
58
56
59
57
/** Current extension settings */
60
- set settings ( settings : JSONObject ) {
58
+ set settings ( settings : ReadonlyJSONObject ) {
61
59
this . _settings = settings ;
62
60
}
63
61
@@ -73,11 +71,11 @@ class QuickOpenWidget extends CommandPalette {
73
71
// Remove all paths from the view
74
72
this . clearItems ( ) ;
75
73
76
- for ( let category in response . contents ) {
77
- for ( let fn of response . contents [ category ] ) {
74
+ for ( let category in response . contents ) {
75
+ for ( let fn of response . contents [ category ] ) {
78
76
// Creates commands that are relative file paths on the server
79
77
let command = `${ category } /${ fn } ` ;
80
- if ( ! this . commands . hasCommand ( command ) ) {
78
+ if ( ! this . commands . hasCommand ( command ) ) {
81
79
// Only add the command to the registry if it does not yet exist
82
80
// TODO: Track disposables and remove
83
81
this . commands . addCommand ( command , {
@@ -93,24 +91,23 @@ class QuickOpenWidget extends CommandPalette {
93
91
}
94
92
}
95
93
}
96
-
97
94
}
98
95
99
-
100
96
/**
101
97
* Initialization data for the jupyterlab-quickopen extension.
102
98
*/
103
- const extension : JupyterLabPlugin < void > = {
104
- id : ' @parente/jupyterlab-quickopen:plugin' ,
99
+ const extension : JupyterFrontEndPlugin < void > = {
100
+ id : " @parente/jupyterlab-quickopen:plugin" ,
105
101
autoStart : true ,
106
- requires : [ ICommandPalette , IDocumentManager , ISettingRegistry ] ,
102
+ requires : [ ICommandPalette , IDocumentManager , ILabShell , ISettingRegistry ] ,
107
103
activate : async (
108
- app : JupyterLab ,
104
+ app : JupyterFrontEnd ,
109
105
palette : ICommandPalette ,
110
106
docManager : IDocumentManager ,
111
- settingRegistry : ISettingRegistry ) => {
112
-
113
- window [ 'docManager' ] = docManager ;
107
+ labShell : ILabShell ,
108
+ settingRegistry : ISettingRegistry
109
+ ) => {
110
+ window [ "docManager" ] = docManager ;
114
111
115
112
console . log ( `Activated extension: ${ extension . id } ` ) ;
116
113
const commands : CommandRegistry = new CommandRegistry ( ) ;
@@ -120,29 +117,29 @@ const extension: JupyterLabPlugin<void> = {
120
117
// Listen for path selection signals and show the selected files in the
121
118
// appropriate editor/viewer
122
119
widget . pathSelected . connect ( ( sender : QuickOpenWidget , path : string ) => {
123
- app . shell . collapseLeft ( ) ;
120
+ labShell . collapseLeft ( ) ;
124
121
docManager . openOrReveal ( PathExt . normalize ( path ) ) ;
125
122
} ) ;
126
123
127
124
// Listen for setting changes and apply them to the widget
128
125
widget . settings = settings . composite ;
129
126
settings . changed . connect ( ( settings : ISettingRegistry . ISettings ) => {
130
127
widget . settings = settings . composite ;
131
- } )
128
+ } ) ;
132
129
133
130
// Add a command to activate the quickopen sidebar so that the user can
134
131
// find it in the command palette, assign a hotkey, etc.
135
- const command : string = ' quickopen:activate' ;
132
+ const command : string = " quickopen:activate" ;
136
133
app . commands . addCommand ( command , {
137
- label : ' Quick Open' ,
134
+ label : " Quick Open" ,
138
135
execute : ( ) => {
139
- app . shell . activateById ( widget . id ) ;
136
+ labShell . activateById ( widget . id ) ;
140
137
}
141
138
} ) ;
142
- palette . addItem ( { command, category : ' File Operations' } ) ;
139
+ palette . addItem ( { command, category : " File Operations" } ) ;
143
140
144
141
// Add the quickopen widget as a left sidebar
145
- app . shell . addToLeftArea ( widget , { rank : 1000 } ) ;
142
+ labShell . add ( widget , "left" , { rank : 1000 } ) ;
146
143
}
147
144
} ;
148
145
0 commit comments