Skip to content

Commit 993a548

Browse files
committed
More work on multiselect (#22)
1 parent 7e69378 commit 993a548

File tree

1 file changed

+47
-38
lines changed

1 file changed

+47
-38
lines changed

index.js

+47-38
Original file line numberDiff line numberDiff line change
@@ -345,29 +345,36 @@ const vfsActionFactory = (core, proc, win, dialog, state) => {
345345
.catch(error => dialog('error', error, __('MSG_UPLOAD_ERROR')));
346346
});
347347

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+
};
350353

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+
});
354358

355-
return fn
356-
.then(() => {
359+
return Promise
360+
.all(promises)
361+
.then((results) => {
357362
refresh(true);
358363

359364
if (typeof callback === 'function') {
360365
callback();
361366
}
367+
368+
return results;
362369
})
363370
.catch(error => dialog('error', error, __('MSG_PASTE_ERROR')));
364371
};
365372

366373
return {
367-
download: file => vfs.download(file),
374+
download: files => files.forEach(file => vfs.download(file)),
375+
action,
368376
upload,
369377
refresh,
370-
action,
371378
drop,
372379
readdir,
373380
paste
@@ -380,10 +387,10 @@ const vfsActionFactory = (core, proc, win, dialog, state) => {
380387
const clipboardActionFactory = (core, state, vfs) => {
381388
const clipboard = core.make('osjs/clipboard');
382389

383-
const set = item => clipboard.set(({item}), 'filemanager:copy');
390+
const set = items => clipboard.set(({items}), 'filemanager:copy');
384391

385-
const cut = item => clipboard.set(({
386-
item,
392+
const cut = items => clipboard.set(({
393+
items,
387394
callback: () => vfs.refresh(true)
388395
}), 'filemanager:move');
389396

@@ -420,20 +427,20 @@ const dialogFactory = (core, proc, win) => {
420427
action(() => vfs.mkdir({path: newPath}), value, __('MSG_MKDIR_ERROR'));
421428
}));
422429

423-
const renameDialog = (action, file) => dialog('prompt', {
430+
const renameDialog = (action, files) => files.forEach(file => dialog('prompt', {
424431
message: __('DIALOG_RENAME_MESSAGE', file.filename),
425432
value: file.filename
426433
}, usingPositiveButton(value => {
427434
const idx = file.path.lastIndexOf(file.filename);
428435
const newPath = file.path.substr(0, idx) + value;
429436

430437
action(() => vfs.rename(file, {path: newPath}), value, __('MSG_RENAME_ERROR'));
431-
}));
438+
})));
432439

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(', ')),
435442
}, usingPositiveButton(() => {
436-
action(() => vfs.unlink(file), true, __('MSG_DELETE_ERROR'));
443+
action(() => Promise.all(files.map(f => vfs.unlink(f))), true, __('MSG_DELETE_ERROR'));
437444
}));
438445

439446
const errorDialog = (error, message) => dialog('alert', {
@@ -476,40 +483,42 @@ const menuFactory = (core, proc, win) => {
476483
{label: _('LBL_QUIT'), onclick: () => win.emit('filemanager:menu:quit')}
477484
]);
478485

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];
481490

482-
if (item && isSpecialFile(item.filename)) {
491+
if (items.length === 1 && item && isSpecialFile(item.filename)) {
483492
return [{
484493
label: _('LBL_GO'),
485494
onclick: () => emitter('filemanager:navigate')
486495
}];
487496
}
488497

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));
491500

492-
const openMenu = isDirectory ? [{
501+
const openMenu = items.length === 1 && item.isDirectory ? [{
493502
label: _('LBL_GO'),
494-
disabled: !item,
503+
disabled: !items.length,
495504
onclick: () => emitter('filemanager:navigate')
496505
}] : [{
497506
label: _('LBL_OPEN'),
498-
disabled: !item,
507+
disabled: !items.length,
499508
onclick: () => emitter('filemanager:open')
500509
}, {
501510
label: __('LBL_OPEN_WITH'),
502-
disabled: !item,
511+
disabled: !items.length,
503512
onclick: () => emitter('filemanager:openWith')
504513
}];
505514

506515
const clipboardMenu = [{
507516
label: _('LBL_COPY'),
508-
disabled: !isValidFile,
517+
disabled: !hasValidFile,
509518
onclick: () => emitter('filemanager:menu:copy')
510519
}, {
511520
label: _('LBL_CUT'),
512-
disabled: !isValidFile,
521+
disabled: !hasValidFile,
513522
onclick: () => emitter('filemanager:menu:cut')
514523
}];
515524

@@ -525,18 +534,18 @@ const menuFactory = (core, proc, win) => {
525534
...openMenu,
526535
{
527536
label: _('LBL_RENAME'),
528-
disabled: !isValidFile,
537+
disabled: !hasValidFile,
529538
onclick: () => emitter('filemanager:menu:rename')
530539
},
531540
{
532541
label: _('LBL_DELETE'),
533-
disabled: !isValidFile,
542+
disabled: !hasValidFile,
534543
onclick: () => emitter('filemanager:menu:delete')
535544
},
536545
...clipboardMenu,
537546
{
538547
label: _('LBL_DOWNLOAD'),
539-
disabled: !item || isDirectory || !isValidFile,
548+
disabled: !canDownload,
540549
onclick: () => emitter('filemanager:menu:download')
541550
}
542551
];
@@ -774,8 +783,8 @@ const createWindow = (core, proc) => {
774783
const onContextMenu = ({ev, data}) => createMenu({ev, name: 'edit'}, data, true);
775784
const onReaddirRender = args => wired.setList(args);
776785
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}));
779788
const onHistoryPush = file => wired.history.push(file);
780789
const onHistoryClear = () => wired.history.clear();
781790
const onMenu = (props, args) => createMenu(props, args || state.currentFile);
@@ -786,11 +795,11 @@ const createWindow = (core, proc) => {
786795
const onMenuToggleMinimalistic = () => wired.toggleMinimalistic();
787796
const onMenuShowDate = () => setSetting('showDate', !proc.settings.showDate);
788797
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);
794803
const onMenuPaste = () => clipboard.paste();
795804

796805
return win

0 commit comments

Comments
 (0)