@@ -5,10 +5,22 @@ import {
55 JupyterFrontEnd ,
66 JupyterFrontEndPlugin
77} from '@jupyterlab/application' ;
8- import { IFileBrowserFactory , FileBrowser } from '@jupyterlab/filebrowser' ;
8+ import {
9+ IFileBrowserFactory ,
10+ FileBrowser ,
11+ Uploader
12+ } from '@jupyterlab/filebrowser' ;
913import { ITranslator } from '@jupyterlab/translation' ;
1014import { addJupyterLabThemeChangeListener } from '@jupyter/web-components' ;
11- import { Dialog , showDialog } from '@jupyterlab/apputils' ;
15+ import {
16+ createToolbarFactory ,
17+ IToolbarWidgetRegistry ,
18+ setToolbar ,
19+ Dialog ,
20+ showDialog
21+ } from '@jupyterlab/apputils' ;
22+ import { ISettingRegistry } from '@jupyterlab/settingregistry' ;
23+ import { FilenameSearcher , IScore } from '@jupyterlab/ui-components' ;
1224import { CommandRegistry } from '@lumino/commands' ;
1325import { Panel } from '@lumino/widgets' ;
1426
@@ -25,6 +37,16 @@ namespace CommandIDs {
2537 export const toggleBrowser = 'drives:toggle-main' ;
2638}
2739
40+ /**
41+ * The file browser factory ID.
42+ */
43+ const FILE_BROWSER_FACTORY = 'DriveBrowser' ;
44+
45+ /**
46+ * The class name added to the drive filebrowser filterbox node.
47+ */
48+ const FILTERBOX_CLASS = 'jp-DriveBrowser-filterBox' ;
49+
2850const openDriveDialogPlugin : JupyterFrontEndPlugin < void > = {
2951 id : '@jupyter/drives:widget' ,
3052 description : 'Open a dialog to select drives to be added in the filebrowser.' ,
@@ -136,7 +158,12 @@ const driveFileBrowser: JupyterFrontEndPlugin<void> = {
136158 id : '@jupyter/drives:drives-file-browser' ,
137159 description : 'The drive file browser factory provider.' ,
138160 autoStart : true ,
139- requires : [ IFileBrowserFactory ] ,
161+ requires : [
162+ IFileBrowserFactory ,
163+ IToolbarWidgetRegistry ,
164+ ISettingRegistry ,
165+ ITranslator
166+ ] ,
140167 optional : [
141168 IRouter ,
142169 JupyterFrontEnd . ITreeResolver ,
@@ -146,6 +173,9 @@ const driveFileBrowser: JupyterFrontEndPlugin<void> = {
146173 activate : async (
147174 app : JupyterFrontEnd ,
148175 fileBrowserFactory : IFileBrowserFactory ,
176+ toolbarRegistry : IToolbarWidgetRegistry ,
177+ settingsRegistry : ISettingRegistry ,
178+ translator : ITranslator ,
149179 router : IRouter | null ,
150180 tree : JupyterFrontEnd . ITreeResolver | null ,
151181 labShell : ILabShell | null ,
@@ -170,15 +200,15 @@ const driveFileBrowser: JupyterFrontEndPlugin<void> = {
170200 driveName : drive . name
171201 } ) ;
172202
173- // // Set attributes when adding the browser to the UI
203+ // Set attributes when adding the browser to the UI
174204 driveBrowser . node . setAttribute ( 'role' , 'region' ) ;
175205 driveBrowser . node . setAttribute ( 'aria-label' , 'Drive Browser Section' ) ;
176206
177207 // instate Drive Browser Panel
178208 const drivePanel = new Panel ( ) ;
179209 drivePanel . title . icon = driveBrowserIcon ;
180210 drivePanel . title . iconClass = 'jp-sideBar-tabIcon' ;
181- drivePanel . title . caption = 'Drive FileBrowser ' ;
211+ drivePanel . title . caption = 'Drive File Browser ' ;
182212 drivePanel . id = 'Drive-Browser-Panel' ;
183213
184214 app . shell . add ( drivePanel , 'left' , { rank : 102 } ) ;
@@ -188,6 +218,47 @@ const driveFileBrowser: JupyterFrontEndPlugin<void> = {
188218 }
189219
190220 void Private . restoreBrowser ( driveBrowser , commands , router , tree , labShell ) ;
221+
222+ toolbarRegistry . addFactory (
223+ FILE_BROWSER_FACTORY ,
224+ 'uploader' ,
225+ ( fileBrowser : FileBrowser ) =>
226+ new Uploader ( { model : fileBrowser . model , translator } )
227+ ) ;
228+
229+ toolbarRegistry . addFactory (
230+ FILE_BROWSER_FACTORY ,
231+ 'file-name-searcher' ,
232+ ( fileBrowser : FileBrowser ) => {
233+ const searcher = FilenameSearcher ( {
234+ updateFilter : (
235+ filterFn : ( item : string ) => Partial < IScore > | null ,
236+ query ?: string
237+ ) => {
238+ fileBrowser . model . setFilter ( value => {
239+ return filterFn ( value . name . toLowerCase ( ) ) ;
240+ } ) ;
241+ } ,
242+ useFuzzyFilter : true ,
243+ placeholder : 'Filter files by names' ,
244+ forceRefresh : true
245+ } ) ;
246+ searcher . addClass ( FILTERBOX_CLASS ) ;
247+ return searcher ;
248+ }
249+ ) ;
250+
251+ // connect the filebrowser toolbar to the settings registry for the plugin
252+ setToolbar (
253+ driveBrowser ,
254+ createToolbarFactory (
255+ toolbarRegistry ,
256+ settingsRegistry ,
257+ FILE_BROWSER_FACTORY ,
258+ driveFileBrowser . id ,
259+ translator
260+ )
261+ ) ;
191262 }
192263} ;
193264
0 commit comments