@@ -345,29 +345,36 @@ const vfsActionFactory = (core, proc, win, dialog, state) => {
345
345
. catch ( error => dialog ( 'error' , error , __ ( 'MSG_UPLOAD_ERROR' ) ) ) ;
346
346
} ) ;
347
347
348
- const paste = ( move , currentPath ) => ( { item, callback} ) => {
349
- const dest = { path : pathJoin ( currentPath . path , item . filename ) } ;
348
+ const paste = ( move , currentPath ) => ( { items, callback} ) => {
349
+ const promises = items . map ( ( item ) => {
350
+ const dest = {
351
+ path : pathJoin ( currentPath . path , item . filename )
352
+ } ;
350
353
351
- const fn = move
352
- ? vfs . move ( item , dest )
353
- : vfs . copy ( item , dest ) ;
354
+ return move
355
+ ? vfs . move ( item , dest )
356
+ : vfs . copy ( item , dest ) ;
357
+ } ) ;
354
358
355
- return fn
356
- . then ( ( ) => {
359
+ return Promise
360
+ . all ( promises )
361
+ . then ( ( results ) => {
357
362
refresh ( true ) ;
358
363
359
364
if ( typeof callback === 'function' ) {
360
365
callback ( ) ;
361
366
}
367
+
368
+ return results ;
362
369
} )
363
370
. catch ( error => dialog ( 'error' , error , __ ( 'MSG_PASTE_ERROR' ) ) ) ;
364
371
} ;
365
372
366
373
return {
367
- download : file => vfs . download ( file ) ,
374
+ download : files => files . forEach ( file => vfs . download ( file ) ) ,
375
+ action,
368
376
upload,
369
377
refresh,
370
- action,
371
378
drop,
372
379
readdir,
373
380
paste
@@ -380,10 +387,10 @@ const vfsActionFactory = (core, proc, win, dialog, state) => {
380
387
const clipboardActionFactory = ( core , state , vfs ) => {
381
388
const clipboard = core . make ( 'osjs/clipboard' ) ;
382
389
383
- const set = item => clipboard . set ( ( { item } ) , 'filemanager:copy' ) ;
390
+ const set = items => clipboard . set ( ( { items } ) , 'filemanager:copy' ) ;
384
391
385
- const cut = item => clipboard . set ( ( {
386
- item ,
392
+ const cut = items => clipboard . set ( ( {
393
+ items ,
387
394
callback : ( ) => vfs . refresh ( true )
388
395
} ) , 'filemanager:move' ) ;
389
396
@@ -420,20 +427,20 @@ const dialogFactory = (core, proc, win) => {
420
427
action ( ( ) => vfs . mkdir ( { path : newPath } ) , value , __ ( 'MSG_MKDIR_ERROR' ) ) ;
421
428
} ) ) ;
422
429
423
- const renameDialog = ( action , file ) => dialog ( 'prompt' , {
430
+ const renameDialog = ( action , files ) => files . forEach ( file => dialog ( 'prompt' , {
424
431
message : __ ( 'DIALOG_RENAME_MESSAGE' , file . filename ) ,
425
432
value : file . filename
426
433
} , usingPositiveButton ( value => {
427
434
const idx = file . path . lastIndexOf ( file . filename ) ;
428
435
const newPath = file . path . substr ( 0 , idx ) + value ;
429
436
430
437
action ( ( ) => vfs . rename ( file , { path : newPath } ) , value , __ ( 'MSG_RENAME_ERROR' ) ) ;
431
- } ) ) ;
438
+ } ) ) ) ;
432
439
433
- const deleteDialog = ( action , file ) => dialog ( 'confirm' , {
434
- message : __ ( 'DIALOG_DELETE_MESSAGE' , file . filename ) ,
440
+ const deleteDialog = ( action , files ) => dialog ( 'confirm' , {
441
+ message : __ ( 'DIALOG_DELETE_MESSAGE' , files . map ( f => f . filename ) . join ( ', ' ) ) ,
435
442
} , usingPositiveButton ( ( ) => {
436
- action ( ( ) => vfs . unlink ( file ) , true , __ ( 'MSG_DELETE_ERROR' ) ) ;
443
+ action ( ( ) => Promise . all ( files . map ( f => vfs . unlink ( f ) ) ) , true , __ ( 'MSG_DELETE_ERROR' ) ) ;
437
444
} ) ) ;
438
445
439
446
const errorDialog = ( error , message ) => dialog ( 'alert' , {
@@ -476,40 +483,42 @@ const menuFactory = (core, proc, win) => {
476
483
{ label : _ ( 'LBL_QUIT' ) , onclick : ( ) => win . emit ( 'filemanager:menu:quit' ) }
477
484
] ) ;
478
485
479
- const createEditMenu = ( item , isContextMenu ) => {
480
- const emitter = name => win . emit ( name , item ) ;
486
+ const createEditMenu = ( items , isContextMenu ) => {
487
+ console . log ( items )
488
+ const emitter = name => win . emit ( name , items ) ;
489
+ const item = items [ items . length - 1 ] ;
481
490
482
- if ( item && isSpecialFile ( item . filename ) ) {
491
+ if ( items . length === 1 && item && isSpecialFile ( item . filename ) ) {
483
492
return [ {
484
493
label : _ ( 'LBL_GO' ) ,
485
494
onclick : ( ) => emitter ( 'filemanager:navigate' )
486
495
} ] ;
487
496
}
488
497
489
- const isValidFile = item && ! isSpecialFile ( item . filename ) ;
490
- const isDirectory = item && item . isDirectory ;
498
+ const canDownload = items . some ( i => ! i . isDirectory && ! isSpecialFile ( i . filename ) ) ;
499
+ const hasValidFile = items . some ( i => ! isSpecialFile ( i . filename ) ) ;
491
500
492
- const openMenu = isDirectory ? [ {
501
+ const openMenu = items . length === 1 && item . isDirectory ? [ {
493
502
label : _ ( 'LBL_GO' ) ,
494
- disabled : ! item ,
503
+ disabled : ! items . length ,
495
504
onclick : ( ) => emitter ( 'filemanager:navigate' )
496
505
} ] : [ {
497
506
label : _ ( 'LBL_OPEN' ) ,
498
- disabled : ! item ,
507
+ disabled : ! items . length ,
499
508
onclick : ( ) => emitter ( 'filemanager:open' )
500
509
} , {
501
510
label : __ ( 'LBL_OPEN_WITH' ) ,
502
- disabled : ! item ,
511
+ disabled : ! items . length ,
503
512
onclick : ( ) => emitter ( 'filemanager:openWith' )
504
513
} ] ;
505
514
506
515
const clipboardMenu = [ {
507
516
label : _ ( 'LBL_COPY' ) ,
508
- disabled : ! isValidFile ,
517
+ disabled : ! hasValidFile ,
509
518
onclick : ( ) => emitter ( 'filemanager:menu:copy' )
510
519
} , {
511
520
label : _ ( 'LBL_CUT' ) ,
512
- disabled : ! isValidFile ,
521
+ disabled : ! hasValidFile ,
513
522
onclick : ( ) => emitter ( 'filemanager:menu:cut' )
514
523
} ] ;
515
524
@@ -525,18 +534,18 @@ const menuFactory = (core, proc, win) => {
525
534
...openMenu ,
526
535
{
527
536
label : _ ( 'LBL_RENAME' ) ,
528
- disabled : ! isValidFile ,
537
+ disabled : ! hasValidFile ,
529
538
onclick : ( ) => emitter ( 'filemanager:menu:rename' )
530
539
} ,
531
540
{
532
541
label : _ ( 'LBL_DELETE' ) ,
533
- disabled : ! isValidFile ,
542
+ disabled : ! hasValidFile ,
534
543
onclick : ( ) => emitter ( 'filemanager:menu:delete' )
535
544
} ,
536
545
...clipboardMenu ,
537
546
{
538
547
label : _ ( 'LBL_DOWNLOAD' ) ,
539
- disabled : ! item || isDirectory || ! isValidFile ,
548
+ disabled : ! canDownload ,
540
549
onclick : ( ) => emitter ( 'filemanager:menu:download' )
541
550
}
542
551
] ;
@@ -774,8 +783,8 @@ const createWindow = (core, proc) => {
774
783
const onContextMenu = ( { ev, data} ) => createMenu ( { ev, name : 'edit' } , data , true ) ;
775
784
const onReaddirRender = args => wired . setList ( args ) ;
776
785
const onRefresh = ( ...args ) => vfs . refresh ( ...args ) ;
777
- const onOpen = file => core . open ( file , { useDefault : true } ) ;
778
- const onOpenWith = file => core . open ( file , { useDefault : true , forceDialog : true } ) ;
786
+ const onOpen = files => files . forEach ( file => core . open ( file , { useDefault : true } ) ) ;
787
+ const onOpenWith = files => files . forEach ( file => core . open ( file , { useDefault : true , forceDialog : true } ) ) ;
779
788
const onHistoryPush = file => wired . history . push ( file ) ;
780
789
const onHistoryClear = ( ) => wired . history . clear ( ) ;
781
790
const onMenu = ( props , args ) => createMenu ( props , args || state . currentFile ) ;
@@ -786,11 +795,11 @@ const createWindow = (core, proc) => {
786
795
const onMenuToggleMinimalistic = ( ) => wired . toggleMinimalistic ( ) ;
787
796
const onMenuShowDate = ( ) => setSetting ( 'showDate' , ! proc . settings . showDate ) ;
788
797
const onMenuShowHidden = ( ) => setSetting ( 'showHiddenFiles' , ! proc . settings . showHiddenFiles ) ;
789
- const onMenuRename = file => dialog ( 'rename' , vfs . action , file ) ;
790
- const onMenuDelete = file => dialog ( 'delete' , vfs . action , file ) ;
791
- const onMenuDownload = ( ... args ) => vfs . download ( ... args ) ;
792
- const onMenuCopy = item => clipboard . set ( item ) ;
793
- const onMenuCut = item => clipboard . cut ( item ) ;
798
+ const onMenuRename = files => dialog ( 'rename' , vfs . action , files ) ;
799
+ const onMenuDelete = files => dialog ( 'delete' , vfs . action , files ) ;
800
+ const onMenuDownload = files => vfs . download ( files ) ;
801
+ const onMenuCopy = items => clipboard . set ( items ) ;
802
+ const onMenuCut = items => clipboard . cut ( items ) ;
794
803
const onMenuPaste = ( ) => clipboard . paste ( ) ;
795
804
796
805
return win
0 commit comments