@@ -306,6 +306,8 @@ const createApplication = (core, proc, win, $content) => {
306306 const title = core . make ( 'osjs/locale' )
307307 . translatableFlat ( proc . metadata . title ) ;
308308
309+ const { pathJoin} = core . make ( 'osjs/fs' ) ;
310+ const vfs = core . make ( 'osjs/vfs' ) ;
309311 const bus = core . make ( 'osjs/event-handler' , 'FileManager' ) ;
310312 const dialog = createDialog ( bus , core , proc , win ) ;
311313 const a = app ( state ( bus , core , proc , win ) ,
@@ -314,15 +316,23 @@ const createApplication = (core, proc, win, $content) => {
314316 $content ) ;
315317
316318 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+ } ;
318327
319328 const upload = f => {
320329 const uploadpath = currentPath . path . replace ( / \/ ? $ / , '/' ) + f . name ;
321- return core . make ( 'osjs/ vfs' ) . writefile ( { path : uploadpath } , f ) ;
330+ return vfs . writefile ( { path : uploadpath } , f ) ;
322331 } ;
323332
324333 const _ = core . make ( 'osjs/locale' ) . translate ;
325334 const __ = core . make ( 'osjs/locale' ) . translatable ( translations ) ;
335+ const clipboard = core . make ( 'osjs/clipboard' ) ;
326336
327337 const createEditMenuItems = ( item , fromContext ) => {
328338 const isDirectory = item && item . isDirectory ;
@@ -345,24 +355,67 @@ const createApplication = (core, proc, win, $content) => {
345355 onclick : ( ) => bus . emit ( 'readFile' , item , true )
346356 } ] ;
347357
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+
348400 const menu = [
349401 ...openMenu ,
350402 {
351403 label : _ ( 'LBL_RENAME' ) ,
352404 disabled : ! isValidFile ,
353- onclick : ( ) => dialog ( 'rename' , item , ( ) => refresh ( ) )
405+ onclick : ( ) => dialog ( 'rename' , item , ( ) => refresh ( true ) )
354406 } ,
355407 {
356408 label : _ ( 'LBL_DELETE' ) ,
357409 disabled : ! isValidFile ,
358- onclick : ( ) => dialog ( 'delete' , item , ( ) => refresh ( ) )
359- }
410+ onclick : ( ) => dialog ( 'delete' , item , ( ) => refresh ( true ) )
411+ } ,
412+ ...clipboardMenu
360413 ] ;
361414
362415 menu . push ( {
363416 label : _ ( 'LBL_DOWNLOAD' ) ,
364417 disabled : ! item || isDirectory || ! isValidFile ,
365- onclick : ( ) => core . make ( 'osjs/ vfs' ) . download ( item )
418+ onclick : ( ) => vfs . download ( item )
366419 } ) ;
367420
368421 return menu ;
@@ -397,10 +450,9 @@ const createApplication = (core, proc, win, $content) => {
397450 let files ;
398451
399452 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+ } ) ;
404456 } catch ( e ) {
405457 console . warn ( e ) ;
406458 a . setPath ( typeof currentPath === 'string' ? currentPath : currentPath . path ) ;
@@ -454,7 +506,7 @@ const createApplication = (core, proc, win, $content) => {
454506 } ;
455507 field . click ( ) ;
456508 } } ,
457- { label : _ ( 'LBL_MKDIR' ) , onclick : ( ) => dialog ( 'mkdir' , { path : currentPath . path } , ( ) => refresh ( ) ) } ,
509+ { label : _ ( 'LBL_MKDIR' ) , onclick : ( ) => dialog ( 'mkdir' , { path : currentPath . path } , ( ) => refresh ( true ) ) } ,
458510 { label : _ ( 'LBL_QUIT' ) , onclick : ( ) => proc . destroy ( ) }
459511 ] ,
460512
0 commit comments