11import {
22 JupyterFrontEnd ,
3- JupyterFrontEndPlugin
3+ JupyterFrontEndPlugin ,
44} from "@jupyterlab/application" ;
55import { showErrorMessage } from "@jupyterlab/apputils" ;
66import { URLExt , PathExt } from "@jupyterlab/coreutils" ;
7- import { ISettingRegistry } from ' @jupyterlab/settingregistry' ;
7+ import { ISettingRegistry } from " @jupyterlab/settingregistry" ;
88import { IFileBrowserFactory } from "@jupyterlab/filebrowser" ;
99import { ServerConnection } from "@jupyterlab/services" ;
1010import { each } from "@lumino/algorithm" ;
1111import { IDisposable } from "@lumino/disposable" ;
1212import { Menu } from "@lumino/widgets" ;
13+ import { archiveIcon , unarchiveIcon } from "./icon" ;
1314
1415const DIRECTORIES_URL = "directories" ;
1516const EXTRACT_ARCHVE_URL = "extract-archive" ;
@@ -46,10 +47,7 @@ function downloadArchiveRequest(
4647 const fullurl = new URL ( url ) ;
4748
4849 // Generate a random token.
49- const rand = ( ) =>
50- Math . random ( )
51- . toString ( 36 )
52- . substr ( 2 ) ;
50+ const rand = ( ) => Math . random ( ) . toString ( 36 ) . substr ( 2 ) ;
5351 const token = ( length : number ) =>
5452 ( rand ( ) + rand ( ) + rand ( ) + rand ( ) ) . substr ( 0 , length ) ;
5553
@@ -99,11 +97,13 @@ function extractArchiveRequest(path: string): Promise<void> {
9997 url = fullurl . toString ( ) ;
10098 const request = { method : "GET" } ;
10199
102- return ServerConnection . makeRequest ( url , request , settings ) . then ( response => {
103- if ( response . status !== 200 ) {
104- throw new ServerConnection . ResponseError ( response ) ;
100+ return ServerConnection . makeRequest ( url , request , settings ) . then (
101+ ( response ) => {
102+ if ( response . status !== 200 ) {
103+ throw new ServerConnection . ResponseError ( response ) ;
104+ }
105105 }
106- } ) ;
106+ ) ;
107107}
108108
109109/**
@@ -134,7 +134,7 @@ const extension: JupyterFrontEndPlugin<void> = {
134134 ".tar.bz" ,
135135 ".tar.bz2" ,
136136 ".txz" ,
137- ".tar.xz"
137+ ".tar.xz" ,
138138 ] ;
139139 let archiveFormat : ArchiveFormat ; // Default value read from settings
140140 let followSymlinks : string ; // Default value read from settings
@@ -151,24 +151,24 @@ const extension: JupyterFrontEndPlugin<void> = {
151151
152152 // Create submenus
153153 const archiveFolder = new Menu ( {
154- commands
154+ commands,
155155 } ) ;
156156 archiveFolder . title . label = "Download As" ;
157- archiveFolder . title . iconClass = "jp-MaterialIcon jp-DownloadIcon" ;
157+ archiveFolder . title . icon = archiveIcon ;
158158 const archiveCurrentFolder = new Menu ( {
159- commands
159+ commands,
160160 } ) ;
161161 archiveCurrentFolder . title . label = "Download Current Folder As" ;
162- archiveCurrentFolder . title . iconClass = "jp-MaterialIcon jp-DownloadIcon" ;
162+ archiveCurrentFolder . title . icon = archiveIcon ;
163163
164- [ "zip" , "tar.bz2" , "tar.gz" , "tar.xz" ] . forEach ( format => {
164+ [ "zip" , "tar.bz2" , "tar.gz" , "tar.xz" ] . forEach ( ( format ) => {
165165 archiveFolder . addItem ( {
166166 command : CommandIDs . downloadArchive ,
167- args : { format }
167+ args : { format } ,
168168 } ) ;
169169 archiveCurrentFolder . addItem ( {
170170 command : CommandIDs . downloadArchiveCurrentFolder ,
171- args : { format }
171+ args : { format } ,
172172 } ) ;
173173 } ) ;
174174
@@ -193,26 +193,26 @@ const extension: JupyterFrontEndPlugin<void> = {
193193 selector : selectorOnlyDir ,
194194 rank : 10 ,
195195 type : "submenu" ,
196- submenu : archiveFolder
196+ submenu : archiveFolder ,
197197 } ) ;
198198
199199 archiveCurrentFolderItem = app . contextMenu . addItem ( {
200200 selector : selectorContent ,
201201 rank : 3 ,
202202 type : "submenu" ,
203- submenu : archiveCurrentFolder
203+ submenu : archiveCurrentFolder ,
204204 } ) ;
205205 } else {
206206 archiveFolderItem = app . contextMenu . addItem ( {
207207 command : CommandIDs . downloadArchive ,
208208 selector : selectorOnlyDir ,
209- rank : 10
209+ rank : 10 ,
210210 } ) ;
211211
212212 archiveCurrentFolderItem = app . contextMenu . addItem ( {
213213 command : CommandIDs . downloadArchiveCurrentFolder ,
214214 selector : selectorContent ,
215- rank : 3
215+ rank : 3 ,
216216 } ) ;
217217 }
218218 }
@@ -224,8 +224,8 @@ const extension: JupyterFrontEndPlugin<void> = {
224224 // Load the settings
225225 settingRegistry
226226 . load ( "@hadim/jupyter-archive:archive" )
227- . then ( settings => {
228- settings . changed . connect ( settings => {
227+ . then ( ( settings ) => {
228+ settings . changed . connect ( ( settings ) => {
229229 const newFormat = settings . get ( "format" ) . composite as ArchiveFormat ;
230230 updateFormat ( newFormat , archiveFormat ) ;
231231 followSymlinks = settings . get ( "followSymlinks" ) . composite as string ;
@@ -237,7 +237,7 @@ const extension: JupyterFrontEndPlugin<void> = {
237237 followSymlinks = settings . get ( "followSymlinks" ) . composite as string ;
238238 downloadHidden = settings . get ( "downloadHidden" ) . composite as string ;
239239 } )
240- . catch ( reason => {
240+ . catch ( ( reason ) => {
241241 console . error ( reason ) ;
242242 showErrorMessage (
243243 "Fail to read settings for '@hadim/jupyter-archive:archive'" ,
@@ -247,44 +247,43 @@ const extension: JupyterFrontEndPlugin<void> = {
247247
248248 // Add the 'downloadArchive' command to the file's menu.
249249 commands . addCommand ( CommandIDs . downloadArchive , {
250- execute : args => {
250+ execute : ( args ) => {
251251 const widget = tracker . currentWidget ;
252252 if ( widget ) {
253- each ( widget . selectedItems ( ) , item => {
253+ each ( widget . selectedItems ( ) , ( item ) => {
254254 if ( item . type == "directory" ) {
255255 const format = args [ "format" ] as ArchiveFormat ;
256256 downloadArchiveRequest (
257257 item . path ,
258258 allowedArchiveExtensions . indexOf ( "." + format ) >= 0
259259 ? format
260260 : archiveFormat ,
261- followSymlinks ,
262- downloadHidden
261+ followSymlinks ,
262+ downloadHidden
263263 ) ;
264264 }
265265 } ) ;
266266 }
267267 } ,
268- iconClass : args =>
269- "format" in args ? "" : "jp-MaterialIcon jp-DownloadIcon" ,
270- label : args => {
268+ icon : ( args ) => ( "format" in args ? "" : archiveIcon ) ,
269+ label : ( args ) => {
271270 const format = ( args [ "format" ] as ArchiveFormat ) || "" ;
272271 const label = format . replace ( "." , " " ) . toLocaleUpperCase ( ) ;
273272 return label ? `${ label } Archive` : "Download as an Archive" ;
274- }
273+ } ,
275274 } ) ;
276275
277276 // Add the 'extractArchive' command to the file's menu.
278277 commands . addCommand ( CommandIDs . extractArchive , {
279278 execute : ( ) => {
280279 const widget = tracker . currentWidget ;
281280 if ( widget ) {
282- each ( widget . selectedItems ( ) , item => {
281+ each ( widget . selectedItems ( ) , ( item ) => {
283282 extractArchiveRequest ( item . path ) ;
284283 } ) ;
285284 }
286285 } ,
287- iconClass : "jp-MaterialIcon jp-DownCaretIcon" ,
286+ icon : unarchiveIcon ,
288287 isVisible : ( ) => {
289288 const widget = tracker . currentWidget ;
290289 let visible = false ;
@@ -294,26 +293,27 @@ const extension: JupyterFrontEndPlugin<void> = {
294293 const splitName = basename . split ( "." ) ;
295294 let lastTwoParts = "" ;
296295 if ( splitName . length >= 2 ) {
297- lastTwoParts = "." + splitName . splice ( splitName . length - 2 , 2 ) . join ( "." ) ;
296+ lastTwoParts =
297+ "." + splitName . splice ( splitName . length - 2 , 2 ) . join ( "." ) ;
298298 }
299299 visible =
300- allowedArchiveExtensions . indexOf ( PathExt . extname ( basename ) ) >=
301- 0 || allowedArchiveExtensions . indexOf ( lastTwoParts ) >= 0 ;
300+ allowedArchiveExtensions . indexOf ( PathExt . extname ( basename ) ) >= 0 ||
301+ allowedArchiveExtensions . indexOf ( lastTwoParts ) >= 0 ;
302302 }
303303 return visible ;
304304 } ,
305- label : "Extract Archive"
305+ label : "Extract Archive" ,
306306 } ) ;
307307
308308 app . contextMenu . addItem ( {
309309 command : CommandIDs . extractArchive ,
310310 selector : selectorNotDir ,
311- rank : 10
311+ rank : 10 ,
312312 } ) ;
313313
314314 // Add the 'downloadArchiveCurrentFolder' command to file browser content.
315315 commands . addCommand ( CommandIDs . downloadArchiveCurrentFolder , {
316- execute : args => {
316+ execute : ( args ) => {
317317 const widget = tracker . currentWidget ;
318318 if ( widget ) {
319319 const format = args [ "format" ] as ArchiveFormat ;
@@ -327,17 +327,16 @@ const extension: JupyterFrontEndPlugin<void> = {
327327 ) ;
328328 }
329329 } ,
330- iconClass : args =>
331- "format" in args ? "" : "jp-MaterialIcon jp-DownloadIcon" ,
332- label : args => {
330+ icon : ( args ) => ( "format" in args ? "" : archiveIcon ) ,
331+ label : ( args ) => {
333332 const format = ( args [ "format" ] as ArchiveFormat ) || "" ;
334333 const label = format . replace ( "." , " " ) . toLocaleUpperCase ( ) ;
335334 return label
336335 ? `${ label } Archive`
337336 : "Download Current Folder as an Archive" ;
338- }
337+ } ,
339338 } ) ;
340- }
339+ } ,
341340} ;
342341
343342export default extension ;
0 commit comments