@@ -97,6 +97,9 @@ const view = (bus, core, proc, win) => (state, actions) => {
97
97
h ( MenubarItem , {
98
98
onclick : ev => bus . emit ( 'openMenu' , ev , state , actions , { name : 'file' } )
99
99
} , _ ( 'LBL_FILE' ) ) ,
100
+ h ( MenubarItem , {
101
+ onclick : ev => bus . emit ( 'openMenu' , ev , state , actions , { name : 'edit' } )
102
+ } , _ ( 'LBL_EDIT' ) ) ,
100
103
h ( MenubarItem , {
101
104
onclick : ev => bus . emit ( 'openMenu' , ev , state , actions , { name : 'view' } )
102
105
} , _ ( 'LBL_VIEW' ) ) ,
@@ -222,6 +225,10 @@ const actions = (bus, core, proc, win) => ({
222
225
const index = Math . min ( state . history . length - 1 , state . historyIndex + 1 ) ;
223
226
bus . emit ( 'openDirectory' , state . history [ index ] , true ) ;
224
227
return { historyIndex : index } ;
228
+ } ,
229
+
230
+ getSelectedIndex : ( ) => state => {
231
+ return state . fileview . selectedIndex ;
225
232
}
226
233
} ) ;
227
234
@@ -289,6 +296,7 @@ const createDialog = (bus, core, proc, win) => (type, item, cb) => {
289
296
const createApplication = ( core , proc , win , $content ) => {
290
297
const homePath = { path : 'home:/' } ; // FIXME
291
298
let currentPath = proc . args . path ? Object . assign ( { } , homePath , proc . args . path ) : homePath ;
299
+ let currentFile = undefined ;
292
300
293
301
// FIXME
294
302
const settings = {
@@ -313,7 +321,57 @@ const createApplication = (core, proc, win, $content) => {
313
321
return core . make ( 'osjs/vfs' ) . writefile ( { path : uploadpath } , f ) ;
314
322
} ;
315
323
316
- bus . on ( 'selectFile' , file => a . setStatus ( getFileStatus ( file ) ) ) ;
324
+ const _ = core . make ( 'osjs/locale' ) . translate ;
325
+ const __ = core . make ( 'osjs/locale' ) . translatable ( translations ) ;
326
+
327
+ const createEditMenuItems = ( item , fromContext ) => {
328
+ const isDirectory = item && item . isDirectory ;
329
+ // FIXME: Check read-only ?
330
+ const isValidFile = item && [ '..' , '.' ] . indexOf ( item . filename ) === - 1 ;
331
+
332
+ const openMenu = isDirectory
333
+ ? [ {
334
+ label : _ ( 'LBL_GO' ) ,
335
+ disabled : ! item ,
336
+ onclick : ( ) => bus . emit ( 'readFile' , item )
337
+ } ]
338
+ : [ {
339
+ label : _ ( 'LBL_OPEN' ) ,
340
+ disabled : ! item ,
341
+ onclick : ( ) => bus . emit ( 'readFile' , item )
342
+ } , {
343
+ label : __ ( 'LBL_OPEN_WITH' ) ,
344
+ disabled : ! item ,
345
+ onclick : ( ) => bus . emit ( 'readFile' , item , true )
346
+ } ] ;
347
+
348
+ const menu = [
349
+ ...openMenu ,
350
+ {
351
+ label : _ ( 'LBL_RENAME' ) ,
352
+ disabled : ! isValidFile ,
353
+ onclick : ( ) => dialog ( 'rename' , item , ( ) => refresh ( ) )
354
+ } ,
355
+ {
356
+ label : _ ( 'LBL_DELETE' ) ,
357
+ disabled : ! isValidFile ,
358
+ onclick : ( ) => dialog ( 'delete' , item , ( ) => refresh ( ) )
359
+ }
360
+ ] ;
361
+
362
+ menu . push ( {
363
+ label : _ ( 'LBL_DOWNLOAD' ) ,
364
+ disabled : ! item || isDirectory || ! isValidFile ,
365
+ onclick : ( ) => core . make ( 'osjs/vfs' ) . download ( item )
366
+ } ) ;
367
+
368
+ return menu ;
369
+ } ;
370
+
371
+ bus . on ( 'selectFile' , file => {
372
+ currentFile = file ;
373
+ a . setStatus ( getFileStatus ( file ) ) ;
374
+ } ) ;
317
375
bus . on ( 'selectMountpoint' , mount => bus . emit ( 'openDirectory' , { path : mount . root } ) ) ;
318
376
319
377
bus . on ( 'readFile' , ( file , forceDialog ) => {
@@ -376,14 +434,12 @@ const createApplication = (core, proc, win, $content) => {
376
434
377
435
win . setTitle ( `${ title } - ${ path } ` ) ;
378
436
437
+ currentFile = undefined ;
379
438
currentPath = file ;
380
439
proc . args . path = file ;
381
440
} ) ;
382
441
383
442
bus . on ( 'openMenu' , ( ev , state , actions , item ) => {
384
- const _ = core . make ( 'osjs/locale' ) . translate ;
385
- const __ = core . make ( 'osjs/locale' ) . translatable ( translations ) ;
386
-
387
443
const menus = {
388
444
file : [
389
445
{ label : _ ( 'LBL_UPLOAD' ) , onclick : ( ) => {
@@ -402,6 +458,8 @@ const createApplication = (core, proc, win, $content) => {
402
458
{ label : _ ( 'LBL_QUIT' ) , onclick : ( ) => proc . destroy ( ) }
403
459
] ,
404
460
461
+ edit : createEditMenuItems ( currentFile , false ) ,
462
+
405
463
view : [
406
464
{ label : _ ( 'LBL_REFRESH' ) , onclick : ( ) => refresh ( ) } ,
407
465
{ label : __ ( 'LBL_MINIMALISTIC' ) , checked : state . minimalistic , onclick : ( ) => {
@@ -427,41 +485,7 @@ const createApplication = (core, proc, win, $content) => {
427
485
return ;
428
486
}
429
487
430
- const _ = core . make ( 'osjs/locale' ) . translate ;
431
- const __ = core . make ( 'osjs/locale' ) . translatable ( translations ) ;
432
-
433
- const openMenu = item . isDirectory
434
- ? [ {
435
- label : _ ( 'LBL_GO' ) ,
436
- onclick : ( ) => bus . emit ( 'readFile' , item )
437
- } ]
438
- : [ {
439
- label : _ ( 'LBL_OPEN' ) ,
440
- onclick : ( ) => bus . emit ( 'readFile' , item )
441
- } , {
442
- label : __ ( 'LBL_OPEN_WITH' ) ,
443
- onclick : ( ) => bus . emit ( 'readFile' , item , true )
444
- } ] ;
445
-
446
- const menu = [
447
- ...openMenu ,
448
- {
449
- label : _ ( 'LBL_RENAME' ) ,
450
- onclick : ( ) => dialog ( 'rename' , item , ( ) => refresh ( ) )
451
- } ,
452
- {
453
- label : _ ( 'LBL_DELETE' ) ,
454
- onclick : ( ) => dialog ( 'delete' , item , ( ) => refresh ( ) )
455
- }
456
- ] ;
457
-
458
- if ( ! item . isDirectory ) {
459
- menu . push ( {
460
- label : _ ( 'LBL_DOWNLOAD' ) ,
461
- onclick : ( ) => core . make ( 'osjs/vfs' ) . download ( item )
462
- } ) ;
463
- }
464
-
488
+ const menu = createEditMenuItems ( item , true ) ;
465
489
core . make ( 'osjs/contextmenu' ) . show ( {
466
490
position : ev ,
467
491
menu
0 commit comments