@@ -3,124 +3,12 @@ import {
3
3
JupyterFrontEndPlugin
4
4
} from '@jupyterlab/application' ;
5
5
import { ICommandPalette , ModalCommandPalette } from '@jupyterlab/apputils' ;
6
- import { URLExt , PathExt } from '@jupyterlab/coreutils' ;
6
+ import { PathExt } from '@jupyterlab/coreutils' ;
7
7
import { IDocumentManager } from '@jupyterlab/docmanager' ;
8
- import { ServerConnection } from '@jupyterlab/services' ;
9
8
import { ISettingRegistry } from '@jupyterlab/settingregistry' ;
10
- import { FileBrowser , IDefaultFileBrowser } from '@jupyterlab/filebrowser' ;
9
+ import { IDefaultFileBrowser } from '@jupyterlab/filebrowser' ;
11
10
import { CommandRegistry } from '@lumino/commands' ;
12
- import { ReadonlyPartialJSONObject } from '@lumino/coreutils' ;
13
- import { Message } from '@lumino/messaging' ;
14
- import { ISignal , Signal } from '@lumino/signaling' ;
15
- import { CommandPalette } from '@lumino/widgets' ;
16
-
17
- /** Structure of the JSON response from the server */
18
- interface IQuickOpenResponse {
19
- readonly contents : { [ key : string ] : string [ ] } ;
20
- readonly scanSeconds : number ;
21
- }
22
-
23
- /** Makes a HTTP request for the server-side quick open scan */
24
- async function fetchContents (
25
- path : string ,
26
- excludes : string [ ]
27
- ) : Promise < IQuickOpenResponse > {
28
- const query = excludes
29
- . map ( exclude => {
30
- return 'excludes=' + encodeURIComponent ( exclude ) ;
31
- } )
32
- . join ( '&' ) ;
33
-
34
- const settings = ServerConnection . makeSettings ( ) ;
35
- const fullUrl =
36
- URLExt . join ( settings . baseUrl , 'jupyterlab-quickopen' , 'api' , 'files' ) +
37
- '?' +
38
- query +
39
- '&path=' +
40
- path ;
41
- const response = await ServerConnection . makeRequest (
42
- fullUrl ,
43
- { method : 'GET' } ,
44
- settings
45
- ) ;
46
- if ( response . status !== 200 ) {
47
- throw new ServerConnection . ResponseError ( response ) ;
48
- }
49
- return await response . json ( ) ;
50
- }
51
-
52
- /**
53
- * Shows files nested under directories in the root notebooks directory configured on the server.
54
- */
55
- class QuickOpenWidget extends CommandPalette {
56
- private _pathSelected = new Signal < this, string > ( this ) ;
57
- private _settings : ReadonlyPartialJSONObject ;
58
- private _fileBrowser : FileBrowser ;
59
-
60
- constructor (
61
- defaultBrowser : IDefaultFileBrowser ,
62
- settings : ReadonlyPartialJSONObject ,
63
- options : CommandPalette . IOptions
64
- ) {
65
- super ( options ) ;
66
-
67
- this . id = 'jupyterlab-quickopen' ;
68
- this . title . iconClass = 'jp-SideBar-tabIcon jp-SearchIcon' ;
69
- this . title . caption = 'Quick Open' ;
70
-
71
- this . _settings = settings ;
72
- this . _fileBrowser = defaultBrowser ;
73
- }
74
-
75
- /** Signal when a selected path is activated. */
76
- get pathSelected ( ) : ISignal < this, string > {
77
- return this . _pathSelected ;
78
- }
79
-
80
- /** Current extension settings */
81
- set settings ( settings : ReadonlyPartialJSONObject ) {
82
- this . _settings = settings ;
83
- }
84
-
85
- /**
86
- * Refreshes the widget with the paths of files on the server.
87
- */
88
- protected async onActivateRequest ( msg : Message ) : Promise < void > {
89
- super . onActivateRequest ( msg ) ;
90
-
91
- // Fetch the current contents from the server
92
- const path = this . _settings . relativeSearch
93
- ? this . _fileBrowser . model . path
94
- : '' ;
95
- const response = await fetchContents (
96
- path ,
97
- this . _settings . excludes as string [ ]
98
- ) ;
99
-
100
- // Remove all paths from the view
101
- this . clearItems ( ) ;
102
-
103
- for ( const category in response . contents ) {
104
- for ( const fn of response . contents [ category ] ) {
105
- // Creates commands that are relative file paths on the server
106
- const command = `${ category } /${ fn } ` ;
107
- if ( ! this . commands . hasCommand ( command ) ) {
108
- // Only add the command to the registry if it does not yet exist TODO: Track disposables
109
- // and remove
110
- this . commands . addCommand ( command , {
111
- label : fn ,
112
- execute : ( ) => {
113
- // Emit a selection signal
114
- this . _pathSelected . emit ( command ) ;
115
- }
116
- } ) ;
117
- }
118
- // Make the file visible under its parent directory heading
119
- this . addItem ( { command, category } ) ;
120
- }
121
- }
122
- }
123
- }
11
+ import { QuickOpenWidget } from './quickopen' ;
124
12
125
13
/**
126
14
* Initialization data for the jupyterlab-quickopen extension.
@@ -141,18 +29,18 @@ const extension: JupyterFrontEndPlugin<void> = {
141
29
settingRegistry : ISettingRegistry ,
142
30
defaultFileBrowser : IDefaultFileBrowser
143
31
) => {
144
- console . log ( `Activated extension: ${ extension . id } ` ) ;
145
32
const commands : CommandRegistry = new CommandRegistry ( ) ;
146
33
const settings : ISettingRegistry . ISettings = await settingRegistry . load (
147
34
extension . id
148
35
) ;
149
- const widget : QuickOpenWidget = new QuickOpenWidget (
150
- defaultFileBrowser ,
151
- settings . composite ,
152
- {
153
- commands
154
- }
155
- ) ;
36
+ const widget : QuickOpenWidget = new QuickOpenWidget ( {
37
+ defaultBrowser : defaultFileBrowser ,
38
+ settings : settings . composite ,
39
+ commandPaletteOptions : { commands } ,
40
+ contents : app . serviceManager . contents ,
41
+ // TODO: remove
42
+ useServer : false
43
+ } ) ;
156
44
157
45
// Listen for path selection signals and show the selected files in the appropriate
158
46
// editor/viewer
0 commit comments