@@ -306,6 +306,8 @@ const createApplication = (core, proc, win, $content) => {
306
306
const title = core . make ( 'osjs/locale' )
307
307
. translatableFlat ( proc . metadata . title ) ;
308
308
309
+ const { pathJoin} = core . make ( 'osjs/fs' ) ;
310
+ const vfs = core . make ( 'osjs/vfs' ) ;
309
311
const bus = core . make ( 'osjs/event-handler' , 'FileManager' ) ;
310
312
const dialog = createDialog ( bus , core , proc , win ) ;
311
313
const a = app ( state ( bus , core , proc , win ) ,
@@ -314,15 +316,23 @@ const createApplication = (core, proc, win, $content) => {
314
316
$content ) ;
315
317
316
318
const getFileIcon = file => file . icon || core . make ( 'osjs/fs' ) . icon ( file ) ;
317
- const refresh = ( currentFile ) => bus . emit ( 'openDirectory' , currentPath , null , currentFile ) ;
319
+ const refresh = ( fileOrWatch ) => {
320
+ // FIXME This should be implemented a bit better
321
+ if ( fileOrWatch === true && core . config ( 'vfs.watch' ) ) {
322
+ return ;
323
+ }
324
+
325
+ bus . emit ( 'openDirectory' , currentPath , null , fileOrWatch ) ;
326
+ } ;
318
327
319
328
const upload = f => {
320
329
const uploadpath = currentPath . path . replace ( / \/ ? $ / , '/' ) + f . name ;
321
- return core . make ( 'osjs/ vfs' ) . writefile ( { path : uploadpath } , f ) ;
330
+ return vfs . writefile ( { path : uploadpath } , f ) ;
322
331
} ;
323
332
324
333
const _ = core . make ( 'osjs/locale' ) . translate ;
325
334
const __ = core . make ( 'osjs/locale' ) . translatable ( translations ) ;
335
+ const clipboard = core . make ( 'osjs/clipboard' ) ;
326
336
327
337
const createEditMenuItems = ( item , fromContext ) => {
328
338
const isDirectory = item && item . isDirectory ;
@@ -345,24 +355,67 @@ const createApplication = (core, proc, win, $content) => {
345
355
onclick : ( ) => bus . emit ( 'readFile' , item , true )
346
356
} ] ;
347
357
358
+ const clipboardMenu = [
359
+ {
360
+ label : _ ( 'LBL_COPY' ) ,
361
+ disabled : ! isValidFile ,
362
+ onclick : ( ) => clipboard . set ( ( { item} ) , 'filemanager:copy' )
363
+ } ,
364
+ {
365
+ label : _ ( 'LBL_CUT' ) ,
366
+ disabled : ! isValidFile ,
367
+ onclick : ( ) => clipboard . set ( ( { item, callback : ( ) => refresh ( true ) } ) , 'filemanager:move' )
368
+ }
369
+ ] ;
370
+
371
+ if ( ! fromContext ) {
372
+ clipboardMenu . push ( {
373
+ label : _ ( 'LBL_PASTE' ) ,
374
+ disabled : ! clipboard . has ( / ^ f i l e m a n a g e r : / ) ,
375
+ onclick : ( ) => {
376
+ if ( clipboard . has ( / ^ f i l e m a n a g e r : / ) ) {
377
+ const move = clipboard . has ( 'filemanager:move' ) ;
378
+
379
+ // TODO: Error handling
380
+ clipboard . get ( move )
381
+ . then ( ( { item, callback} ) => {
382
+ const dest = { path : pathJoin ( currentPath . path , item . filename ) } ;
383
+
384
+ return ( move
385
+ ? vfs . move ( item , dest )
386
+ : vfs . copy ( item , dest ) )
387
+ . then ( ( ) => {
388
+ refresh ( true ) ;
389
+
390
+ if ( typeof callback === 'function' ) {
391
+ callback ( ) ;
392
+ }
393
+ } ) ;
394
+ } ) ;
395
+ }
396
+ }
397
+ } ) ;
398
+ }
399
+
348
400
const menu = [
349
401
...openMenu ,
350
402
{
351
403
label : _ ( 'LBL_RENAME' ) ,
352
404
disabled : ! isValidFile ,
353
- onclick : ( ) => dialog ( 'rename' , item , ( ) => refresh ( ) )
405
+ onclick : ( ) => dialog ( 'rename' , item , ( ) => refresh ( true ) )
354
406
} ,
355
407
{
356
408
label : _ ( 'LBL_DELETE' ) ,
357
409
disabled : ! isValidFile ,
358
- onclick : ( ) => dialog ( 'delete' , item , ( ) => refresh ( ) )
359
- }
410
+ onclick : ( ) => dialog ( 'delete' , item , ( ) => refresh ( true ) )
411
+ } ,
412
+ ...clipboardMenu
360
413
] ;
361
414
362
415
menu . push ( {
363
416
label : _ ( 'LBL_DOWNLOAD' ) ,
364
417
disabled : ! item || isDirectory || ! isValidFile ,
365
- onclick : ( ) => core . make ( 'osjs/ vfs' ) . download ( item )
418
+ onclick : ( ) => vfs . download ( item )
366
419
} ) ;
367
420
368
421
return menu ;
@@ -397,10 +450,9 @@ const createApplication = (core, proc, win, $content) => {
397
450
let files ;
398
451
399
452
try {
400
- files = await core . make ( 'osjs/vfs' )
401
- . readdir ( file , {
402
- showHiddenFiles : settings . showHiddenFiles
403
- } ) ;
453
+ files = await vfs . readdir ( file , {
454
+ showHiddenFiles : settings . showHiddenFiles
455
+ } ) ;
404
456
} catch ( e ) {
405
457
console . warn ( e ) ;
406
458
a . setPath ( typeof currentPath === 'string' ? currentPath : currentPath . path ) ;
@@ -454,7 +506,7 @@ const createApplication = (core, proc, win, $content) => {
454
506
} ;
455
507
field . click ( ) ;
456
508
} } ,
457
- { label : _ ( 'LBL_MKDIR' ) , onclick : ( ) => dialog ( 'mkdir' , { path : currentPath . path } , ( ) => refresh ( ) ) } ,
509
+ { label : _ ( 'LBL_MKDIR' ) , onclick : ( ) => dialog ( 'mkdir' , { path : currentPath . path } , ( ) => refresh ( true ) ) } ,
458
510
{ label : _ ( 'LBL_QUIT' ) , onclick : ( ) => proc . destroy ( ) }
459
511
] ,
460
512
0 commit comments